From: Nishi Date: Tue, 1 Oct 2024 14:31:23 +0000 (+0000) Subject: stuff X-Git-Url: https://git.chaotic.ninja/gitweb/nishi/?a=commitdiff_plain;h=57e060657d481a389667d4b8a8876c26379685b2;p=koakuma.git stuff git-svn-id: file:///raid/svn-personal/koakuma/trunk@3 219d0f9c-2d94-d447-890a-813e76b88fe9 --- diff --git a/Component/vcs_cvs.tcl b/Component/vcs_cvs.tcl new file mode 100644 index 0000000..da85380 --- /dev/null +++ b/Component/vcs_cvs.tcl @@ -0,0 +1,17 @@ +# $Id$ +lappend components "CVS" "CVS Integration" "1.00" + +proc CVS_info {} { + regexp {[0-9]+\.[0-9]+\.[0-9]+} "[exec cvs --version]" version + add_toc2 "CVS" + tputs "" + tputs " " + tputs " " + tputs " " + tputs " " + tputs "
" + tputs " Version" + tputs " " + tputs " $version" + tputs "
" +} diff --git a/Component/vcs_svn.tcl b/Component/vcs_svn.tcl new file mode 100644 index 0000000..a2a7cde --- /dev/null +++ b/Component/vcs_svn.tcl @@ -0,0 +1,17 @@ +# $Id$ +lappend components "Subversion" "Subversion Integration" "1.00" + +proc Subversion_info {} { + regexp {[0-9]+\.[0-9]+\.[0-9]+} "[exec svn --version]" version + add_toc2 "Subversion" + tputs "" + tputs " " + tputs " " + tputs " " + tputs " " + tputs "
" + tputs " Version" + tputs " " + tputs " $version" + tputs "
" +} diff --git a/Components/vcs_cvs.tcl b/Components/vcs_cvs.tcl deleted file mode 100644 index 7dd8e10..0000000 --- a/Components/vcs_cvs.tcl +++ /dev/null @@ -1,2 +0,0 @@ -# $Id$ -lappend components "CVS" "CVS Integration" "1.00" diff --git a/Components/vcs_svn.tcl b/Components/vcs_svn.tcl deleted file mode 100644 index 58cadf0..0000000 --- a/Components/vcs_svn.tcl +++ /dev/null @@ -1,2 +0,0 @@ -# $Id$ -lappend components "Subversion" "Subversion Integration" "1.00" diff --git a/Makefile b/Makefile index 9f254a5..706ec0a 100644 --- a/Makefile +++ b/Makefile @@ -5,17 +5,26 @@ REPLACE = sed "s%@@PREFIX@@%$(PREFIX)%g" .PHONY: install -install: Components/* Tool/* koakuma.cgi.in - mkdir -p $(PREFIX)/lib/koakuma/components/ +install: Component/* Tool/* Utility/* 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/ mkdir -p $(PREFIX)/etc/koakuma/ mkdir -p $(PREFIX)/lib/koakuma/cgi-bin/ mkdir -p $(PREFIX)/bin/ - cp -rf Components/* $(PREFIX)/lib/koakuma/components/ + mkdir -p $(PREFIX)/lib/koakuma/db + if [ ! -e "$(PREFIX)/lib/koakuma/db/projects.db" ] ; then echo "" > $(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/ 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/launch-job + @echo + @echo Make sure $(PREFIX)/lib/koakuma/db is writable by your HTTPd user. + @echo By default, Koakuma stock Apache config uses $(PREFIX)/etc/koakuma/passwd + @echo for authentication. diff --git a/README b/README index dab9c8e..0a85044 100644 --- a/README +++ b/README @@ -1,2 +1,5 @@ Koakuma is a simple autobuild script. -Requires Tcl8.6, and Tcllib. +Requires: + - Tcl8.6 + - Tcllib + - tDOM: https://wiki.tcl-lang.org/page/tDOM diff --git a/Tool/create-task b/Tool/create-project similarity index 100% rename from Tool/create-task rename to Tool/create-project diff --git a/Utility/rpc.tcl b/Utility/rpc.tcl new file mode 100644 index 0000000..fbbab2d --- /dev/null +++ b/Utility/rpc.tcl @@ -0,0 +1 @@ +# $Id$ diff --git a/apache.conf.in b/apache.conf.in index b4fb8a6..817411c 100644 --- a/apache.conf.in +++ b/apache.conf.in @@ -9,6 +9,15 @@ DocumentRoot @@PREFIX@@/lib/koakuma/htdocs Options +ExecCGI Require all granted + + AuthType basic + AuthName "Koakuma RPC" + AuthUserFile @@PREFIX@@/etc/koakuma/passwd + Require valid-user + + + Require all granted + ScriptAlias /koakuma @@PREFIX@@/lib/koakuma/cgi-bin/koakuma.cgi RewriteEngine on diff --git a/koakuma.cgi.in b/koakuma.cgi.in index bea049e..74251e2 100644 --- a/koakuma.cgi.in +++ b/koakuma.cgi.in @@ -8,11 +8,18 @@ proc exiting {code} { exit $code } +proc loop_components {run} { + global components + foreach {name description version} $components { + eval $run + } +} + proc crash {reason} { global components KOAKUMA_VERSION puts stderr "----- Start Koakuma Crash dump log -----" puts stderr "Included components:" - foreach {name description version} $components { + loop_components { puts stderr " $name: $description, version $version" } puts stderr "Reason: $reason" @@ -36,20 +43,256 @@ proc crash {reason} { exiting 1 } -foreach path [glob @@PREFIX@@/lib/koakuma/components/*.tcl] { - source "$path" +if { ![info exists env(PATH_INFO)] } { + puts "Status: 301 Moved Permanently" + puts "Location: $env(SCRIPT_NAME)/" + puts "" + exiting 0 } -proc start_html {title} { - puts "" - puts "" - puts " " - puts " " - puts " $title - Koakuma" - puts " " - puts " " +if { [catch { + package require tdom +}] } { + crash "Failed to load tDOM" } -proc end_html {} { - puts " " - puts "" + +if { [catch { + foreach path [glob @@PREFIX@@/lib/koakuma/component/*.tcl] { + source "$path" + } +}] } { + crash "Could not load components" +} + +set toc "" +set result "" +set content "" + +proc rputs {data} { + global result + if { "$result" == "" } { + set result "$data" + } else { + set result "$result\n$data" + } +} + +proc tputs {data} { + global content + if { "$content" == "" } { + set content "$data" + } else { + set content "$content\n$data" + } +} + +proc html_escape {data} { + return "[regsub -all {&} "[regsub -all {>} "[regsub -all {<} "$data" "<"]" ">"]" "&"]" +} + +proc open_projects {} { + while 1 { + if { ![info exists "@@PREFIX@@/lib/koakuma/db/projects.lock"] } { + break + } + set fid [open "@@PREFIX@@/lib/koakuma/db/projects.lock" "w"] + if { ![info exists "/proc/[gets $fid line]"] } { + close $fid + break + } + after 10 + close $fid + } + set fid [open "@@PREFIX@@/lib/koakuma/db/projects.lock" "w"] + puts $fid "[pid]" + close $fid +} + +proc scan_projects {run} { + set fid [open "@@PREFIX@@/lib/koakuma/db/projects.db" "r"] + set content "" + while { [gets $fid line] >= 0 } { + if { "$content" == "" } { + set content "$line" + } else { + set content "$content\n$line" + } + } + close $fid + set dom [dom parse "$content"] + set doc [$dom documentElement] + foreach elem [$doc selectNodes "/projects/project"] { + set name "[$elem selectNodes "string(name)"]" + set description "[$elem selectNodes "string(description)"]" + eval $run + } +} + +proc project_exists {projname} { + set desc "" + scan_projects { + upvar 1 desc desc + upvar 1 projname projname + if { "$name" == "$projname" } { + set desc "$description" + break + } + } + return "$desc" +} + +proc close_projects {} { + file delete "@@PREFIX@@/lib/koakuma/db/projects.lock" +} + +proc start_html {title has_toc} { + global toc + rputs "" + rputs "" + rputs " " + rputs " " + rputs " $title - Koakuma" + rputs " " + rputs " " + rputs " " + rputs " " + rputs " \"Koakuma" + rputs " " + rputs "
" + rputs "
" + rputs " Koakuma" + rputs "
" + rputs "
" + if { "$has_toc" == "1" } { + rputs "
" + rputs "
TOC
" + foreach sect $toc { + if { "[string range "[regsub -all { } "$sect" "-"]" 0 0]" == "-" } { + rputs "[regsub {^-} "$sect" ""]
" + } else { + rputs "$sect
" + } + } + rputs "
" + } + if { "$has_toc" == "1" } { + rputs "
" + } else { + rputs "
" + } + rputs "

$title

" +} +proc end_html {has_toc} { + global KOAKUMA_VERSION + rputs "
" + rputs "
" + rputs " Powered by Koakuma $KOAKUMA_VERSION" + rputs " " + rputs "" +} + +proc add_toc {data} { + global toc + tputs "

# $data

" + lappend toc "$data" +} + +proc add_toc2 {data} { + global toc + tputs "

# $data

" + lappend toc "-$data" +} + +if { [catch { + set path "[regsub -all {/+} "$env(PATH_INFO)" "/"]" + rputs "Content-Type: text/html" + if { "$path" == "/" } { + add_toc "Tcl Information" + tputs "" + tputs " " + tputs " " + tputs " " + tputs " " + tputs " " + tputs " " + tputs " " + tputs " " + tputs "
" + tputs " Version" + tputs " " + tputs " $tcl_version" + tputs "
" + tputs " Platform" + tputs " " + tputs " $tcl_platform(os)/$tcl_platform(machine) $tcl_platform(osVersion)" + tputs "
" + add_toc "Components" + loop_components { + if { [llength [info procs "${name}_info"]] > 0 } { + ${name}_info + } + } + set has_projects 0 + add_toc "Projects" + open_projects + scan_projects { + upvar 1 has_projects has_projects + if { "$has_projects" == "0" } { + set has_projects 1 + tputs "" + } + tputs "" + tputs " " + tputs " " + tputs "" + } + close_projects + if { "$has_projects" == "1" } { + tputs "
$name$description
" + } else { + tputs "No projects have been added, yet." + } + + rputs "" + start_html "Main" 1 + rputs "$content" + end_html 1 + } elseif { [regexp {^/rpc.*$} "$path"] } { + } elseif { [regexp {^/project/[^/]+.*$} "$path"] } { + regexp {^/project/([^/]+).*$} "$path" -> projname + open_projects + set has_project [project_exists "$projname"] + close_projects + + if { "$has_project" != "" } { + add_toc "Description" + tputs "[html_escape "$has_project"]" + + rputs "" + start_html "Project: $projname" 1 + rputs "$content" + end_html 1 + } else { + tputs "I could not find the project you were finding." + + rputs "Status: 404 Not Found" + rputs "" + start_html "Not Found" 0 + rputs "$content" + end_html 0 + } + } else { + tputs "I could not find the content you were finding." + + rputs "Status: 404 Not Found" + rputs "" + start_html "Not Found" 0 + rputs "$content" + end_html 0 + } +}] } { + crash "Could not render the HTML" +} else { + puts "$result" } +exiting 0 diff --git a/style.css b/style.css new file mode 100644 index 0000000..34271aa --- /dev/null +++ b/style.css @@ -0,0 +1,92 @@ +/* $Id$ */ + +#gomain { + position: absolute; + left: 50px; +} + +html { + font-family: sans-serif; + color: #606080; +} + +h1 { + font-family: sans-serif; + border: solid 1px #606080; + padding: 5px; +} + +h2 { + background-color: #606080; + color: #ffffff; + padding: 5px; + padding-left: 25px; +} + +h3 { + background-color: #f0f0f0; + color: #606080; + padding: 5px; + padding-left: 10px; +} + +hr { + border: solid 1px #606080; +} + +table { + border: solid 1px #606080; + width: 100%; + padding: 5px; +} + +th { + text-align: left; + width: 20%; +} + +#space { + height: 152px; +} + +#title { + padding: 5px; + background-color: #606080; + color: #ffffff; + font-size: 30px; + text-align: right; + padding-right: 25%; +} + +#toctitle { + font-size: 30px; + background-color: #f8f8f8; +} + +.shiftlink { + margin-left: 10px; +} + +#clearfix { + clear: both; +} + +#doc { + padding-right: 14em; +} + +a { + color: #8080f0; +} + +a:visited { + color: #a0a0a0; +} + +#toc { + float: right; + width: 13em; + padding: 5px; + background-color: #f0f0f0; + margin-top: 20px; +}