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.
--- /dev/null
+#!/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
+++ /dev/null
-#!/usr/bin/env tclsh
-# $Id$
# $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
+ }
+}
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
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"
}
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\">"
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