]> Git repositories of Nishi - koakuma.git/commitdiff
stuff
authorNishi <nishi@nishi.boats>
Tue, 1 Oct 2024 15:42:33 +0000 (15:42 +0000)
committerNishi <nishi@nishi.boats>
Tue, 1 Oct 2024 15:42:33 +0000 (15:42 +0000)
git-svn-id: file:///raid/svn-personal/koakuma/trunk@4 219d0f9c-2d94-d447-890a-813e76b88fe9

Makefile
Tool/create-project.in [new file with mode: 0644]
Tool/launch-job [deleted file]
Tool/launch-job.in [moved from Tool/create-project with 100% similarity]
Utility/rpc.tcl
apache.conf.in
koakuma.cgi.in

index 706ec0aa6f186d175a5759eb84b29b21fe953cb6..590a324c1b8eb1ac2282464b100fcc42e302936a 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -16,13 +16,14 @@ install: Component/* Tool/* Utility/* koakuma.cgi.in apache.conf.in
        if [ ! -e "$(PREFIX)/lib/koakuma/db/projects.db" ] ; then echo "<projects></projects>" > $(PREFIX)/lib/koakuma/db/projects.db ; fi
        cp -rf Component/* $(PREFIX)/lib/koakuma/component/
        cp -rf Utility/* $(PREFIX)/lib/koakuma/utility/
-       cp -rf Tool/* $(PREFIX)/bin/
+       $(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/
        $(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
-       chmod +x $(PREFIX)/bin/create-task
+       chmod +x $(PREFIX)/bin/create-project
        chmod +x $(PREFIX)/bin/launch-job
        @echo
        @echo Make sure $(PREFIX)/lib/koakuma/db is writable by your HTTPd user.
diff --git a/Tool/create-project.in b/Tool/create-project.in
new file mode 100644 (file)
index 0000000..76aae3e
--- /dev/null
@@ -0,0 +1,34 @@
+#!/usr/bin/env tclsh
+# $Id$
+set RPC_URL "http://127.0.0.1/koakuma/rpc"
+foreach arg $argv {
+       if { [string range "$arg" 0 0] == "-" } {
+               if { "$arg" == "-h" || "$arg" == "--help" } {
+                       puts "Usage: create-project"
+                       puts "You can set the environment variable `KOAKUMA_RPC' to override default RPC URL."
+                       puts "Default: $RPC_URL"        
+                       exit 0
+               }
+       }
+}
+foreach path [glob "@@PREFIX@@/lib/koakuma/utility/*.tcl"] {
+       source $path
+}
+if { [info exists "env(KOAKUMA_RPC)"] } {
+       set RPC_URL "$env(KOAKUMA_RPC)"
+}
+puts -nonewline "Authentication: "
+set status [::rpc::require-auth]
+if { $status == 1 } {
+       puts "Required"
+       if { ![::rpc::ask-auth] } {
+               puts "Authentication failure"
+               exit 1
+       }
+} elseif { $status < 0 } {
+       puts "Got forbidden, cannot continue"
+       exit 1
+} else {
+       puts "Not required"
+}
+::rpc::send
diff --git a/Tool/launch-job b/Tool/launch-job
deleted file mode 100644 (file)
index 614af38..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/usr/bin/env tclsh
-# $Id$
similarity index 100%
rename from Tool/create-project
rename to Tool/launch-job.in
index fbbab2d1199b1de168c7f25fb5e7eac727b3d066..609782fdd6ba6db91c20dcfec4537a21a94a9080 100644 (file)
@@ -1 +1,49 @@
 # $Id$
+package require http
+package require base64
+package require term::ansi::ctrl::unix
+
+namespace eval rpc {
+       proc require-auth {} {
+               global RPC_URL
+               set tok [::http::geturl "$RPC_URL"]
+               set code [::http::ncode $tok]
+               ::http::cleanup $tok
+               if { $code == 401 } {
+                       return 1
+               } elseif { $code == 403 } {
+                       return -1
+               } else {
+                       return 0
+               }
+       }
+       set username ""
+       set password ""
+       proc ask-auth {} {
+               upvar 1 username username
+               upvar 1 password password
+               puts -nonewline "Username: "
+               flush stdout
+               set username "[gets stdin]"
+               puts -nonewline "Password: "
+               flush stdout
+               exec stty -echo
+               set password "[gets stdin]"
+               exec stty echo
+               puts ""
+
+               set headers ""
+               lappend headers "Authorization"
+               lappend headers "Basic [::base64::encode -wrapchar "" "$username:$password"]"
+
+               global RPC_URL
+               set tok [::http::geturl "$RPC_URL" -headers $headers]
+               set code [::http::ncode $tok]
+               ::http::cleanup $tok
+
+               if { $code == 200 } {
+                       return 1
+               }
+               return 0
+       }
+}
index 817411c02f9d2ac4dd657df44c7b326e8947acb6..76276c2096ce649bf7ebba8d032a69074ba470c9 100644 (file)
@@ -14,9 +14,7 @@ DocumentRoot @@PREFIX@@/lib/koakuma/htdocs
        AuthName "Koakuma RPC"
        AuthUserFile @@PREFIX@@/etc/koakuma/passwd
        Require valid-user
-</Location>
-<Location /koakuma/rpc/prefix>
-       Require all granted
+       Require ip 127.0.0.1 ::1
 </Location>
 ScriptAlias /koakuma @@PREFIX@@/lib/koakuma/cgi-bin/koakuma.cgi
 
index 74251e202de925c091ebd996b52d008ebd1f25e8..9a7aeb681b49f924e864bf77bc0fb2ad60c482af 100644 (file)
@@ -52,6 +52,9 @@ if { ![info exists env(PATH_INFO)] } {
 
 if { [catch {
        package require tdom
+       dom createNodeCmd -tagName "rpc" elementNode rootXML
+       dom createNodeCmd -tagName "version" -jsonType NONE elementNode keyVersion
+       dom createNodeCmd -jsonType STRING textNode valueString
 }] } {
        crash "Failed to load tDOM"
 }
@@ -205,7 +208,11 @@ proc add_toc2 {data} {
 
 if { [catch {
        set path "[regsub -all {/+} "$env(PATH_INFO)" "/"]"
-       rputs "Content-Type: text/html"
+       if { [regexp {^/rpc(/.*)?$} "$path"] } {
+               rputs "Content-Type: application/json"
+       } else {
+               rputs "Content-Type: text/html"
+       }
        if { "$path" == "/" } {
                add_toc "Tcl Information"
                tputs   "<table border=\"0\">"
@@ -257,7 +264,17 @@ if { [catch {
                start_html "Main" 1
                rputs "$content"
                end_html 1
-       } elseif { [regexp {^/rpc.*$} "$path"] } {
+       } elseif { [regexp {^/rpc(/.*)?$} "$path"] } {
+               rputs ""
+               regexp {^/rpc(/.*)?$} "$path" -> api
+               set doc [dom createDocumentNode]
+               set root $doc
+               if { "$api" == "" || "$api" == "/" } {
+                       $root appendFromScript {
+                               keyVersion {valueString "$KOAKUMA_VERSION"}
+                       }
+                       rputs "[$doc asJSON]"
+               }
        } elseif { [regexp {^/project/[^/]+.*$} "$path"] } {
                regexp {^/project/([^/]+).*$} "$path" -> projname
                open_projects