From: Nishi Date: Wed, 2 Oct 2024 03:25:33 +0000 (+0000) Subject: stuff X-Git-Url: https://git.chaotic.ninja/gitweb/nishi/?a=commitdiff_plain;h=c61ea8140cb7c187665fc1ad94b2bd4290742706;p=koakuma.git stuff git-svn-id: file:///raid/svn-personal/koakuma/trunk@12 219d0f9c-2d94-d447-890a-813e76b88fe9 --- diff --git a/Makefile b/Makefile index fb06220..10af425 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ REPLACE = sed "s%@@PREFIX@@%$(PREFIX)%g" .PHONY: install -install: Component/* Tool/* Utility/* koakuma.cgi.in apache.conf.in +install: Component/* Tool/* Utility/* Static/* koakuma.cgi.in apache.conf.in mkdir -p $(PREFIX)/lib/koakuma/component/ mkdir -p $(PREFIX)/lib/koakuma/utility/ mkdir -p $(PREFIX)/lib/koakuma/htdocs/static/ @@ -19,8 +19,7 @@ install: Component/* Tool/* Utility/* koakuma.cgi.in apache.conf.in cp -rf Utility/* $(PREFIX)/lib/koakuma/utility/ $(REPLACE) Tool/create-project.in > $(PREFIX)/bin/create-project $(REPLACE) Tool/launch-job.in > $(PREFIX)/bin/launch-job - cp -rf koakuma.png $(PREFIX)/lib/koakuma/htdocs/static/ - cp style.css $(PREFIX)/lib/koakuma/htdocs/static/ + cp -rf Static/* $(PREFIX)/lib/koakuma/htdocs/static/ $(REPLACE) koakuma.cgi.in > $(PREFIX)/lib/koakuma/cgi-bin/koakuma.cgi $(REPLACE) apache.conf.in > $(PREFIX)/etc/koakuma/apache.conf chmod +x $(PREFIX)/lib/koakuma/cgi-bin/koakuma.cgi diff --git a/Static/continued.png b/Static/continued.png new file mode 100644 index 0000000..a9a7c09 Binary files /dev/null and b/Static/continued.png differ diff --git a/koakuma.png b/Static/koakuma.png similarity index 100% rename from koakuma.png rename to Static/koakuma.png diff --git a/style.css b/Static/style.css similarity index 100% rename from style.css rename to Static/style.css diff --git a/Tool/create-project.in b/Tool/create-project.in index a464d25..d79a79d 100644 --- a/Tool/create-project.in +++ b/Tool/create-project.in @@ -1,19 +1,19 @@ #!/usr/bin/env tclsh # $Id$ package require tdom +foreach path [glob "@@PREFIX@@/lib/koakuma/utility/*.tcl"] { + source $path +} foreach arg $argv { if { [string range "$arg" 0 0] == "-" } { if { "$arg" == "-h" || "$arg" == "--help" } { - puts "Usage: create-project" + puts "Usage: $argv0" puts "You can set the environment variable `KOAKUMA_RPC' to override default RPC URL." - puts "Default: $RPC_URL" + puts "Default: http://127.0.0.1/koakuma/rpc" exit 0 } } } -foreach path [glob "@@PREFIX@@/lib/koakuma/utility/*.tcl"] { - source $path -} ::rpc::init diff --git a/Tool/launch-job.in b/Tool/launch-job.in index 614af38..70d5bca 100644 --- a/Tool/launch-job.in +++ b/Tool/launch-job.in @@ -1,2 +1,62 @@ #!/usr/bin/env tclsh # $Id$ +package require tdom +foreach path [glob "@@PREFIX@@/lib/koakuma/utility/*.tcl"] { + source $path +} +set name "" +set description "" +set dothis "" +foreach arg $argv { + if { [string range "$arg" 0 0] == "-" } { + if { "$arg" == "-h" || "$arg" == "--help" } { + puts "Usage: $argv0 \[-u username\] \[-p password\] \[-R rpc_url\] name description" + puts "You can set the environment variable `KOAKUMA_RPC' to override default RPC URL." + puts "Default: http://127.0.0.1/koakuma/rpc" + exit 0 + } elseif { "$arg" == "-u" } { + set dothis "set-username" + } elseif { "$arg" == "-p" } { + set dothis "set-password" + } elseif { "$arg" == "-R" } { + set dothis "set-rpc" + } + } else { + if { "$dothis" == "set-username" } { + set ::rpc::useranme "$arg" + } elseif { "$dothis" == "set-password" } { + set ::rpc::password "$arg" + } elseif { "$dothis" == "set-rpc" } { + set RPC_URL "$arg" + } elseif { "$name" == "" } { + set name "$arg" + } elseif { "$description" == "" } { + set description "$arg" + } + set dothis "" + } +} + +if { "$name" == "" || "$description" == "" } { + puts "See --help." + exit 1 +} + +dom createNodeCmd -tagName "name" -jsonType NONE elementNode keyName +dom createNodeCmd -tagName "description" -jsonType NONE elementNode keyDescription + +dom createNodeCmd -jsonType STRING textNode valueString + +set doc [dom createDocumentNode] + +$doc appendFromScript { + keyName {valueString "$name"} + keyDescription {valueString "$description"} +} + +set result [::rpc::send "/launch-job" "[$doc asJSON]"] +if { [lindex $result 0] == 200 } { +} else { + set doc [dom parse -json "[lindex $result 1]"] + puts "Error: [$doc selectNodes "string(/error)"]" +} diff --git a/koakuma.cgi.in b/koakuma.cgi.in index e7ee481..f1ac001 100644 --- a/koakuma.cgi.in +++ b/koakuma.cgi.in @@ -185,7 +185,7 @@ proc close_projects {} { } proc start_html {title has_toc} { - global toc + global toc env rputs "" rputs "" rputs " " @@ -201,6 +201,7 @@ proc start_html {title has_toc} { rputs "
" rputs " Koakuma" rputs "
" + rputs " Root" rputs "
" if { "$has_toc" == "1" } { rputs "
" @@ -247,6 +248,12 @@ if { [catch { if { [regexp {^/rpc(/.*)?$} "$path"] } { rputs "Content-Type: application/json" } else { + if { ![regexp {/$} "$env(PATH_INFO)"] } { + puts "Status: 301 Moved Permanently" + puts "Location: $env(SCRIPT_NAME)$env(PATH_INFO)/" + puts "" + exiting 0 + } rputs "Content-Type: text/html" } if { "$path" == "/" } { @@ -309,6 +316,43 @@ if { [catch { if { "$api" == "" || "$api" == "/" } { rputs "" rputs "[$doc asJSON]" + } elseif { "$api" == "/launch-job" } { + if { [catch {dom parse -json "$data" clidoc}] } { + rputs "Status: 400 Bad Request" + $doc appendFromScript { + keyError {valueString "Bad JSON"} + } + } else { + set projname "[$clidoc selectNodes "string(/name)"]" + set builddesc "[$clidoc selectNodes "string(/description)"]" + if { "$projname" == "" || "$builddesc" == "" } { + rputs "Status: 400 Bad Request" + $doc appendFromScript { + keyError {valueString "Required field missing"} + } + } else { + set has_name 0 + open_projects + scan_projects { + upvar 1 has_name has_name + upvar 1 projname projname + if { "$name" == "$projname" } { + set has_name 1 + break + } + } + close_projects + if { $has_name == 0 } { + rputs "Status: 400 Bad Request" + $doc appendFromScript { + keyError {valueString "Project does not exist"} + } + } else { + } + } + } + rputs "" + rputs "[$doc asJSON]" } elseif { "$api" == "/create-project" } { if { [catch {dom parse -json "$data" clidoc}] } { rputs "Status: 400 Bad Request" @@ -386,34 +430,65 @@ if { [catch { rputs "[$doc asJSON]" } } elseif { [regexp {^/project/[^/]+.*$} "$path"] } { - regexp {^/project/([^/]+).*$} "$path" -> projname + regexp {^/project/([^/]+)(.*)$} "$path" -> projname projpath open_projects set has_project [project_exists "$projname"] close_projects if { "$has_project" != "" } { - add_toc "Description" - tputs "[html_escape "$has_project"]" - add_toc "Details" - tputs "" - tputs " " - tputs " " - tputs " " - tputs " " - tputs "
" - tputs " Last run" - tputs " " - if { [file exists "@@PREFIX@@/lib/koakuma/db/data/$projname/lastrun"] } { + if { "$projpath" == "" || "$projpath" == "/" } { + add_toc "Description" + tputs "[html_escape "$has_project"]" + add_toc "Details" + tputs "" + tputs " " + tputs " " + tputs " " + tputs " " + tputs " " + tputs " " + tputs " " + tputs " " + tputs "
" + tputs " Last run" + tputs " " + if { [file exists "@@PREFIX@@/lib/koakuma/db/data/$projname/lastrun"] } { + set fid [open "@@PREFIX@@/lib/koakuma/db/data/$projname/lastrun" "r"] + set date "[clock format "[gets $fid]" -format "%a %b %d %H:%M:%S %Z %Y"]" + close $fid + tputs "$date" + } else { + tputs "No builds yet" + } + tputs " " + tputs "
" + tputs " Last successful run" + tputs " " + if { [file exists "@@PREFIX@@/lib/koakuma/db/data/$projname/lastsuccessfulrun"] } { + set fid [open "@@PREFIX@@/lib/koakuma/db/data/$projname/lastsuccessfulrun" "r"] + set date "[clock format "[gets $fid]" -format "%a %b %d %H:%M:%S %Z %Y"]" + close $fid + tputs "$date" + } else { + tputs "No successful builds yet" + } + tputs " " + tputs "
" + add_toc "Build details" + + rputs "" + start_html "Project: $projname" 1 + rputs "$content" + end_html 1 } else { - tputs "Was never ran" - } - tputs " " - tputs "
" + tputs "I could not find the endpoint you were finding." - rputs "" - start_html "Project: $projname" 1 - rputs "$content" - end_html 1 + rputs "Status: 404 Not Found" + rputs "" + start_html "Project: $projname" 1 + rputs "$content" + end_html 1 + } } else { tputs "I could not find the project you were finding."