Subversion Repositories Koakuma

Rev

Rev 11 | Rev 13 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 11 Rev 12
Line 1... Line 1...
1
#!/usr/bin/env tclsh
1
#!/usr/bin/env tclsh
2
# $Id: koakuma.cgi.in 11 2024-10-02 00:56:50Z nishi $
2
# $Id: koakuma.cgi.in 12 2024-10-02 03:25:33Z nishi $
3
 
3
 
4
set KOAKUMA_VERSION "1.00"
4
set KOAKUMA_VERSION "1.00"
5
set components ""
5
set components ""
6
 
6
 
7
proc exiting {code} {
7
proc exiting {code} {
Line 183... Line 183...
183
proc close_projects {} {
183
proc close_projects {} {
184
	file delete "@@PREFIX@@/lib/koakuma/db/projects.lock"
184
	file delete "@@PREFIX@@/lib/koakuma/db/projects.lock"
185
}
185
}
186
 
186
 
187
proc start_html {title has_toc} {
187
proc start_html {title has_toc} {
188
	global toc
188
	global toc env
189
	rputs	"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">"
189
	rputs	"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">"
190
	rputs	"<html>"
190
	rputs	"<html>"
191
	rputs	"	<head>"
191
	rputs	"	<head>"
192
	rputs	"		<meta http-equiv=\"Content-Type\" content=\"text/html;charset=UTF-8\">"
192
	rputs	"		<meta http-equiv=\"Content-Type\" content=\"text/html;charset=UTF-8\">"
193
	rputs	"		<title>$title - Koakuma</title>"
193
	rputs	"		<title>$title - Koakuma</title>"
Line 199... Line 199...
199
	rputs	"		</a>"
199
	rputs	"		</a>"
200
	rputs	"		<div id=\"space\"></div>"
200
	rputs	"		<div id=\"space\"></div>"
201
	rputs	"		<div id=\"title\">"
201
	rputs	"		<div id=\"title\">"
202
	rputs	"			Koakuma"
202
	rputs	"			Koakuma"
203
	rputs	"		</div>"
203
	rputs	"		</div>"
-
 
204
	rputs	"		<a href=\"$env(SCRIPT_NAME)\">Root</a>"
204
	rputs	"		<div id=\"clearfix\"></div>"
205
	rputs	"		<div id=\"clearfix\"></div>"
205
	if { "$has_toc" == "1" } {
206
	if { "$has_toc" == "1" } {
206
		rputs	"		<div id=\"toc\">"
207
		rputs	"		<div id=\"toc\">"
207
		rputs	"			<div id=\"toctitle\">TOC</div>"
208
		rputs	"			<div id=\"toctitle\">TOC</div>"
208
		foreach sect $toc {
209
		foreach sect $toc {
Line 245... Line 246...
245
if { [catch {
246
if { [catch {
246
	set path "[regsub -all {/+} "$env(PATH_INFO)" "/"]"
247
	set path "[regsub -all {/+} "$env(PATH_INFO)" "/"]"
247
	if { [regexp {^/rpc(/.*)?$} "$path"] } {
248
	if { [regexp {^/rpc(/.*)?$} "$path"] } {
248
		rputs "Content-Type: application/json"
249
		rputs "Content-Type: application/json"
249
	} else {
250
	} else {
-
 
251
		if { ![regexp {/$} "$env(PATH_INFO)"] } {
-
 
252
			puts "Status: 301 Moved Permanently"
-
 
253
			puts "Location: $env(SCRIPT_NAME)$env(PATH_INFO)/"
-
 
254
			puts ""
-
 
255
			exiting 0
-
 
256
		}
250
		rputs "Content-Type: text/html"
257
		rputs "Content-Type: text/html"
251
	}
258
	}
252
	if { "$path" == "/" } {
259
	if { "$path" == "/" } {
253
		add_toc "Tcl Information"
260
		add_toc "Tcl Information"
254
		tputs	"<table border=\"0\">"
261
		tputs	"<table border=\"0\">"
Line 307... Line 314...
307
			keyVersion {valueString "$KOAKUMA_VERSION"}
314
			keyVersion {valueString "$KOAKUMA_VERSION"}
308
		}
315
		}
309
		if { "$api" == "" || "$api" == "/" } {
316
		if { "$api" == "" || "$api" == "/" } {
310
			rputs ""
317
			rputs ""
311
			rputs "[$doc asJSON]"
318
			rputs "[$doc asJSON]"
-
 
319
		} elseif { "$api" == "/launch-job" } {
-
 
320
			if { [catch {dom parse -json "$data" clidoc}] } {
-
 
321
				rputs "Status: 400 Bad Request"
-
 
322
				$doc appendFromScript {
-
 
323
					keyError {valueString "Bad JSON"}
-
 
324
				}
-
 
325
			} else {
-
 
326
				set projname "[$clidoc selectNodes "string(/name)"]"
-
 
327
				set builddesc "[$clidoc selectNodes "string(/description)"]"
-
 
328
				if { "$projname" == "" || "$builddesc" == "" } {
-
 
329
					rputs "Status: 400 Bad Request"
-
 
330
					$doc appendFromScript {
-
 
331
						keyError {valueString "Required field missing"}
-
 
332
					}
-
 
333
				} else {
-
 
334
					set has_name 0
-
 
335
					open_projects
-
 
336
					scan_projects {
-
 
337
						upvar 1 has_name has_name
-
 
338
						upvar 1 projname projname
-
 
339
						if { "$name" == "$projname" } {
-
 
340
							set has_name 1
-
 
341
							break
-
 
342
						}
-
 
343
					}
-
 
344
					close_projects
-
 
345
					if { $has_name == 0 } {
-
 
346
						rputs "Status: 400 Bad Request"
-
 
347
						$doc appendFromScript {
-
 
348
							keyError {valueString "Project does not exist"}
-
 
349
						}
-
 
350
					} else {
-
 
351
					}
-
 
352
				}
-
 
353
			}
-
 
354
			rputs ""
-
 
355
			rputs "[$doc asJSON]"
312
		} elseif { "$api" == "/create-project" } {
356
		} elseif { "$api" == "/create-project" } {
313
			if { [catch {dom parse -json "$data" clidoc}] } {
357
			if { [catch {dom parse -json "$data" clidoc}] } {
314
				rputs "Status: 400 Bad Request"
358
				rputs "Status: 400 Bad Request"
315
				$doc appendFromScript {
359
				$doc appendFromScript {
316
					keyError {valueString "Bad JSON"}
360
					keyError {valueString "Bad JSON"}
Line 384... Line 428...
384
			rputs "Status: 404 Not Found"
428
			rputs "Status: 404 Not Found"
385
			rputs ""
429
			rputs ""
386
			rputs "[$doc asJSON]"
430
			rputs "[$doc asJSON]"
387
		}
431
		}
388
	} elseif { [regexp {^/project/[^/]+.*$} "$path"] } {
432
	} elseif { [regexp {^/project/[^/]+.*$} "$path"] } {
389
		regexp {^/project/([^/]+).*$} "$path" -> projname
433
		regexp {^/project/([^/]+)(.*)$} "$path" -> projname projpath
390
		open_projects
434
		open_projects
391
		set has_project [project_exists "$projname"]
435
		set has_project [project_exists "$projname"]
392
		close_projects
436
		close_projects
393
		
437
		
394
		if { "$has_project" != "" } {
438
		if { "$has_project" != "" } {
-
 
439
			if { "$projpath" == "" || "$projpath" == "/" } {
395
			add_toc "Description"
440
				add_toc "Description"
396
			tputs "[html_escape "$has_project"]"
441
				tputs "[html_escape "$has_project"]"
397
			add_toc "Details"
442
				add_toc "Details"
398
			tputs	"<table border=\"0\">"
443
				tputs	"<table border=\"0\">"
399
			tputs	"	<tr>"
444
				tputs	"	<tr>"
400
			tputs	"		<th>"
445
				tputs	"		<th>"
401
			tputs	"			Last run"
446
				tputs	"			Last run"
402
			tputs	"		</th>"
447
				tputs	"		</th>"
403
			tputs	"		<td>"
448
				tputs	"		<td>"
404
			if { [file exists "@@PREFIX@@/lib/koakuma/db/data/$projname/lastrun"] } {
449
				if { [file exists "@@PREFIX@@/lib/koakuma/db/data/$projname/lastrun"] } {
-
 
450
					set fid [open "@@PREFIX@@/lib/koakuma/db/data/$projname/lastrun" "r"]
-
 
451
					set date "[clock format "[gets $fid]" -format "%a %b %d %H:%M:%S %Z %Y"]"
-
 
452
					close $fid
-
 
453
					tputs "$date"
-
 
454
				} else {
-
 
455
					tputs "No builds yet"
-
 
456
				}
-
 
457
				tputs	"			"
-
 
458
				tputs	"		</td>"
-
 
459
				tputs	"	</tr>"
-
 
460
				tputs	"	<tr>"
-
 
461
				tputs	"		<th>"
-
 
462
				tputs	"			Last successful run"
-
 
463
				tputs	"		</th>"
-
 
464
				tputs	"		<td>"
-
 
465
				if { [file exists "@@PREFIX@@/lib/koakuma/db/data/$projname/lastsuccessfulrun"] } {
-
 
466
					set fid [open "@@PREFIX@@/lib/koakuma/db/data/$projname/lastsuccessfulrun" "r"]
-
 
467
					set date "[clock format "[gets $fid]" -format "%a %b %d %H:%M:%S %Z %Y"]"
-
 
468
					close $fid
-
 
469
					tputs "$date"
-
 
470
				} else {
-
 
471
					tputs "No successful builds yet"
-
 
472
				}
-
 
473
				tputs	"			"
-
 
474
				tputs	"		</td>"
-
 
475
				tputs	"	</tr>"
-
 
476
				tputs	"</table>"
-
 
477
				add_toc "Build details"
-
 
478
	
-
 
479
				rputs ""
-
 
480
				start_html "Project: $projname" 1
-
 
481
				rputs "$content"
-
 
482
				end_html 1
405
			} else {
483
			} else {
406
				tputs "Was never ran"
484
				tputs "I could not find the endpoint you were finding."
407
			}
-
 
408
			tputs	"			"
-
 
409
			tputs	"		</td>"
-
 
410
			tputs	"	</tr>"
-
 
411
			tputs	"</table>"
-
 
412
 
485
 
-
 
486
				rputs "Status: 404 Not Found"
413
			rputs ""
487
				rputs ""
414
			start_html "Project: $projname" 1
488
				start_html "Project: $projname" 1
415
			rputs "$content"
489
				rputs "$content"
416
			end_html 1
490
				end_html 1
-
 
491
			}
417
		} else {
492
		} else {
418
			tputs "I could not find the project you were finding."
493
			tputs "I could not find the project you were finding."
419
 
494
 
420
			rputs "Status: 404 Not Found"
495
			rputs "Status: 404 Not Found"
421
			rputs ""
496
			rputs ""