From: Rusty Russell Date: Sat, 8 Nov 2008 14:46:34 +0000 (+1100) Subject: Static generation of web pages. Based on GSoC work, and still needs X-Git-Url: https://git.ozlabs.org/?p=ccan;a=commitdiff_plain;h=ad8da11f6d0664e0fb3c8707a869425088daea7e Static generation of web pages. Based on GSoC work, and still needs more polish (particularly uploading is untested). --- diff --git a/Makefile b/Makefile index 6329f05b..e11ddc27 100644 --- a/Makefile +++ b/Makefile @@ -1,27 +1,74 @@ # Hacky makefile to compile everything and run the tests in some kind of sane order. # V=--verbose for verbose tests. +# This can be overridden on cmdline to generate pages elsewhere. +WEBDIR=webpages/ + CFLAGS=-g -Wall -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-declarations -Werror -Iccan -I. ALL=$(patsubst ccan/%/test, %, $(wildcard ccan/*/test)) ALL_DIRS=$(patsubst %, ccan/%, $(ALL)) ALL_DEPENDS=$(patsubst %, ccan/%/.depends, $(ALL)) -ALL_LIBS=$(patsubst %, ccan/%.o, $(ALL)) +ALL_PAGES=$(patsubst ccan/%, $(WEBDIR)/info/%.html, $(ALL_DIRS)) +DIRECT_TARBALLS=$(patsubst ccan/%, $(WEBDIR)/tarballs/%.tar.bz2, $(ALL_DIRS)) +DEPEND_TARBALLS=$(patsubst ccan/%, $(WEBDIR)/tarballs/with-deps/%.tar.bz2, $(ALL_DIRS)) +WEB_SUBDIRS=$(WEBDIR)/tarballs $(WEBDIR)/tarballs/with-deps $(WEBDIR)/info -libccan.a: $(ALL_LIBS) - $(AR) r $@ $^ +include Makefile-ccan check: $(ALL_DIRS:%=test-%) distclean: clean rm -f $(ALL_DEPENDS) + rm -rf $(WEBDIR) + +webpages: $(WEB_SUBDIRS) $(WEBDIR)/junkcode $(ALL_PAGES) $(WEBDIR)/list.html $(WEBDIR)/index.html $(WEBDIR)/upload.html $(WEBDIR)/example-config.h $(WEBDIR)/ccan.jpg $(DIRECT_TARBALLS) $(DEPEND_TARBALLS) $(WEBDIR)/ccan.tar.bz2 $(WEBDIR)/Makefile-ccan + +$(WEB_SUBDIRS): + mkdir -p $@ + +$(WEBDIR)/junkcode: + cp -a junkcode $@ + +# Override implicit attempt to link directory. +$(ALL_DIRS): + @touch $@ + +$(WEBDIR)/ccan.tar.bz2: + tar cvfj $@ `bzr ls --versioned --kind=file ccan` + +$(ALL_PAGES): tools/doc_extract web/staticmoduleinfo.php + +$(WEBDIR)/list.html: web/staticall.php tools/doc_extract $(DIRECT_TARBALLS) $(DEPEND_TARBALLS) $(WEBDIR)/ccan.tar.bz2 + php5 web/staticall.php ccan/ $(WEBDIR) > $@ + +$(WEBDIR)/upload.html: web/staticupload.php + php5 web/staticupload.php > $@ + +$(WEBDIR)/index.html: web/staticindex.php + php5 web/staticindex.php > $@ + +$(WEBDIR)/example-config.h: config.h + cp $< $@ + +$(WEBDIR)/Makefile-ccan: Makefile-ccan + cp $< $@ + +$(WEBDIR)/ccan.jpg: web/ccan.jpg + cp $< $@ + +$(WEBDIR)/info/%.html: ccan/% ccan/%/test $(WEBDIR)/tarballs/%.tar.bz2 $(WEBDIR)/tarballs/with-deps/%.tar.bz2 + URLPREFIX=../ php5 web/staticmoduleinfo.php ccan/$* > $@ + +$(WEBDIR)/tarballs/%.tar.bz2: ccan/% ccan/%/test + tar -c -v -j -f $@ `bzr ls --versioned --kind=file ccan/$*` + +$(WEBDIR)/tarballs/with-deps/%.tar.bz2: ccan/% ccan/%/test tools/ccan_depends + tar cvfj $@ $$(echo ccan/$* $$(tools/ccan_depends ccan/$*) | xargs -n 1 bzr ls --versioned --kind=file) $(ALL_DEPENDS): %/.depends: tools/ccan_depends tools/ccan_depends $* > $@ || ( rm -f $@; exit 1 ) -$(ALL_LIBS): - $(LD) -r -o $@ $^ /dev/null - test-ccan/%: tools/run_tests ccan/%.o @echo Testing $*... @if tools/run_tests $(V) ccan/$* | grep ^'not ok'; then exit 1; else exit 0; fi @@ -38,10 +85,6 @@ inter-depends: $(ALL_DEPENDS) test-depends: $(ALL_DEPENDS) for f in $(ALL_DEPENDS); do echo test-ccan/`basename \`dirname $$f\``: `sed -n 's,ccan/\(.*\),test-ccan/\1,p' < $$f`; done > $@ -lib-depends: $(foreach D,$(ALL),$(wildcard $D/*.[ch])) - for c in $(ALL); do echo ccan/$$c.o: `ls ccan/$$c/*.c | grep -v /_info.c | sed 's/.c$$/.o/'`; done > $@ - include tools/Makefile -include inter-depends -include test-depends --include lib-depends diff --git a/Makefile-ccan b/Makefile-ccan new file mode 100644 index 00000000..cbd9871c --- /dev/null +++ b/Makefile-ccan @@ -0,0 +1,11 @@ +# Example makefile which makes a "libccan.a" of everything under ccan/ +# You could just do: +# SRCFILES += $(shell find ccan/ -name '[a-z]*.c') + +CFLAGS=-g -O2 -Wall -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-declarations -Werror -Iccan -I. + +CFILES=$(wildcard ccan/*/[a-z]*.c) +OBJFILES=$(CFILES:.c=.o) + +libccan.a: $(OBJFILES) + $(AR) r $@ $^ diff --git a/web/logo.html b/web/logo.html index 7239556c..61c8f7e7 100644 --- a/web/logo.html +++ b/web/logo.html @@ -1,3 +1,8 @@ + ccan @@ -6,10 +11,10 @@ -
- +

Comprehensive C Archieve Network

\ No newline at end of file + diff --git a/web/menulist.html b/web/menulist.html index 7e0232cb..aa5993f5 100644 --- a/web/menulist.html +++ b/web/menulist.html @@ -1,30 +1,26 @@ - + - -
Welcome !
- Login + Upload Code - - Request CCAN account - - - Change CCAN account detail + Download Code - - Upload Code + About - - Search CCAN - - - Logout +
+ + + +

diff --git a/web/static-configuration b/web/static-configuration new file mode 100644 index 00000000..3ff84923 --- /dev/null +++ b/web/static-configuration @@ -0,0 +1,74 @@ +"; + $raw=extract_field($field,$module); + foreach (explode("\n", $raw) as $line) { + if ($line == "") { + switch ($state) { + case "inpara": + $state="endpara"; + $result .= "

"; + break; + } + } else if ($line[0] == " " || $line[0] == "\t") { + switch ($state) { + case "literal": + break; + case "inpara": + $result .= "

"; + case "endpara": + $result .= "
";
+	    $state = "literal";
+	 }
+      } else {
+         switch ($state) {
+	 case "literal":
+	    $result .= "
"; + case "endpara": + $result .= "

"; + $state = "inpara"; + } + } + $result .= $line . "\n"; + } + + switch ($state) { + case "literal": + $result .= ""; + break; + case "inpara": + $result .= "

"; + break; + } + return $result; +} +?> diff --git a/web/staticall.php b/web/staticall.php new file mode 100644 index 00000000..3a6407ff --- /dev/null +++ b/web/staticall.php @@ -0,0 +1,80 @@ + + +

List of all CCAN modules:

+ +

+Note that two downloads are offered: the first includes with all the +other ccan modules this module uses, the second is a standalone +download. +

+ +

+Or you can just download the tarball of everything (K). +

+ + + + + + +read())) { + if ($entry[0] != '.') { + array_push($modules, $entry); + } +} +sort($modules); + +foreach ($modules as $module) { + $summary=extract_field('summary',$argv[1].$module); + $with_deps="$tar_dir/with-deps/$module.tar.bz2"; + $no_deps="$tar_dir/$module.tar.bz2"; + $with_dep_size = round((filesize($argv[2]."/".$with_deps) + 1023) / 1024); + $no_dep_size = round((filesize($argv[2]."/".$no_deps) + 1023) / 1024); + ?> + + + + + + close(); +?> +
NameSummary / Link to detailsDownload
K / + K
+ +

Contents of Junkcode:

+ +(This is contributed code which was dumped here: these gems may need some polishing.) + + + +read())) { + if ($entry[0] != '.') { + array_push($files, $entry); + } +} + +sort($files); +foreach ($files as $file) { + $size = round((filesize($argv[2]."/junkcode/".$file) + 1023) / 1024); + echo "\n"; +} +$d->close(); +?> +
$file (${size}K)
+
+ diff --git a/web/staticindex.php b/web/staticindex.php new file mode 100644 index 00000000..9dace4e7 --- /dev/null +++ b/web/staticindex.php @@ -0,0 +1,77 @@ + + +

The Idea

+ +

+That nice snippets of C code should be moved out of junkcode +directories and exposed to a wider world, where they can become +something useful. +

+ +

+CCAN is loosely modelled after the succesful CPAN project +for Perl code development and sharing. +

+ +

Getting The Code

+ +

+Once you grab some modules, there are two basic +ways to use it: +

    +
  1. Just hack it to compile in your project. + +
  2. Use it in place by giving it a "config.h" (steal + this example) and compiling all the .c + files which don't start with "_" (eg. as in this simple Makefile). +
+

+ +

+There's also a +Bazaar repository for all the CCAN +infrastructure at +http://ccan.ozlabs.org/repo. +

+ +

Module Contributions

+ +

+We welcome new code! The guide to creating new modules is a work in +progress (just copy an existing module), but anyone can +just upload code. +

+ +

+"GPLv2 or later" and supersets thereof (eg. LGPLv2+ or BSD) +licenses preferred. +

+ +

Complaints, Ideas and Infrastructure

+ +

+We have a low volume +mailing list for discussion of CCAN in general, and you're welcome +to join. + +

+ +

+We also have an IRC channel: #ccan on Freenode. +

+ +

+We also have a wiki; feel free to enhance it. +

+ +

+Rusty Russell +

+ +
+ diff --git a/web/staticmoduleinfo.php b/web/staticmoduleinfo.php new file mode 100644 index 00000000..5b16e62d --- /dev/null +++ b/web/staticmoduleinfo.php @@ -0,0 +1,90 @@ + + + + + +
+Browse Source + +Download: +(standalone) +(with all dependencies) +
+ +

+

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Module:

Summary:

Maintainer:

Author:

Dependencies:

 '.$dep.' ';
+        }
+?>

Description:

Example:

Licence:


+ diff --git a/web/staticupload.php b/web/staticupload.php new file mode 100644 index 00000000..d1252e16 --- /dev/null +++ b/web/staticupload.php @@ -0,0 +1,55 @@ + + +

Upload Code

+ + + + + +
+

+Got C code sitting around which might help someone? Put it to work +by uploading here; .tar.gz, .zip or even single C files. +

+ +

+If it has a valid _info.c file and a testsuite, it'll go into the +main repository. Otherwise, it'll go into our "junkcode" area where +people can browse and download it. +

+
+ + + +

+
+

+ + + + + + + + + +
+ Email address: + + +
+ + Choose a file to upload: + +
+
+ +
+ diff --git a/web/upload.php b/web/upload.php index 1a83d958..2c208b47 100644 --- a/web/upload.php +++ b/web/upload.php @@ -7,6 +7,16 @@ include('configuration'); ?>

Upload Code

+ +

Got C code sitting around which might help someone? Put it to work +by uploading here; .tar.gz, .zip or even single C files. +

+ +

If it has a valid _info.c file and a testsuite, it'll go into the +main repository. Otherwise, it'll go into our "junkcode" area where +people can browse and download it. +

+
@@ -14,6 +24,10 @@ include('configuration');
+
+ Email address: + Choose a file to upload: diff --git a/web/uploader.php b/web/uploader.php index 0cb1c184..40e29445 100644 --- a/web/uploader.php +++ b/web/uploader.php @@ -2,173 +2,24 @@ session_start(); include('logo.html'); include('menulist.html'); -include('configuration'); -include('functions.php'); -include('searchengine.php'); +include('static-configuration'); +// We just email notification for now. Auto-analysis RSN. if ($_FILES["uploadedfile"]["error"] > 0) { echo "Error: " . $_FILES["uploadedfile"]["error"] . "
"; exit(); } -//list of file types supported -if($_FILES["uploadedfile"]["type"] == "application/x-gzip" - || $_FILES["uploadedfile"]["type"] == "application/x-tar" - || $_FILES["uploadedfile"]["type"] == "application/x-bzip" - || $_FILES["uploadedfile"]["type"] == "application/zip") { - - $folder = substr($_FILES["uploadedfile"]["name"], 0, strpos($_FILES["uploadedfile"]["name"],'.')); - move_uploaded_file($_FILES["uploadedfile"]["tmp_name"], - $tempfolder . $_FILES["uploadedfile"]["name"]); - - //extracting code - if($_FILES["uploadedfile"]["type"] == "application/zip") - exec('unzip '.$tempfolder.$_FILES["uploadedfile"]["name"].' -d '.$tempfolder, $op, $status); - else - exec('tar -xf '.$tempfolder.$_FILES["uploadedfile"]["name"].' -C '.$tempfolder, $op, $status); - checkerror($status,"Error: cannot extract(tar error)."); +$dest = tempnam($tempfolder, "upload-"); +move_uploaded_file($_FILES["uploadedfile"]["tmp_name"], $dest); - //if user not logged in - if($_SESSION["slogged"] == false) { - //move to temp folder - if (file_exists($temprepo . $folder)) - rmdirr($temprepo.$folder); - rename($tempfolder.$folder, $temprepo.$folder); - - //send mail for review to admins - $subject = "Review: code upload at temporary repository"; - $message = "Some developer has uploaded code who has not logged in.\n\nModule is stored in ". - $temprepo.$folder.".\n\nOutput of ccanlint: \n"; - - $toaddress = getccanadmin($db); - mail($toaddress, $subject, $message, "From: $frommail"); - echo "
Stored to temporary repository. - Mail will be send to admin to get verification of the code."; - unlink($tempfolder.$_FILES["uploadedfile"]["name"]); - exit(); - } +$subject = "CCAN: code upload by '" . $_POST['email'] . "' with name " . $_FILES["uploadedfile"]["name"]; +$message = "File type: ".$_FILES["uploadedfile"]["type"]."\n". + "Size: ".$_FILES["uploadedfile"]["size"]."\n". + "Claimed email: ".$_POST['email']."\n". + "File destination: ".$dest."\n"; - //running ccanlint - exec($ccanlint.$tempfolder.$folder, $score, $status); - - //if not junk code - if($status == 0) { - $rename = $folder; - $exactpath = $repopath . $_SESSION['susername'] .'/'; - - if (file_exists($exactpath)) { - echo "
Your another upload is in progress please wait...
"; - exit(); - } - - //bzr local repo for commit - chdir($repopath); - unset($op); exec($bzr_clone . $_SESSION['susername'], $op, $status); - checkerror($status, "Error: bzr local repo."); - chdir('..'); - - //if module already exist - if (file_exists($exactpath . $ccan_home_dir . $folder)) { - - // if owner is not same - if(!(getowner($ccan_home_dir . $folder, $db) == $_SESSION['susername'])) { - if(!file_exists($repopath . $ccan_home_dir . $folder . '-' . $_SESSION['susername'])) - echo "
". $ccan_home_dir . $folder . - " already exists. Renaming to " . $folder . "-" . $_SESSION['susername'] . "
"; - else - echo "
". $ccan_home_dir . $folder . - "-" . $_SESSION['susername'] . " already exists. Overwriting " . - $folder. "-" . $_SESSION['susername'] . "
"; - $rename = $folder."-".$_SESSION['susername']; - } - - else - echo "
".$repopath. $ccan_home_dir. $folder. - " already exists(uploaded by you). Overwriting ". $repopath. $folder."
"; - - } - - //module not exist. store author to db - else { - storefileowner($ccan_home_dir . $folder, $_SESSION['susername'], $db); - } - - rmdirr($exactpath . $ccan_home_dir . $rename); - rename($tempfolder . $folder, $exactpath . $ccan_home_dir . $rename); - - chdir($exactpath); - unset($op); exec($infotojson . $ccan_home_dir . $rename . " " . $ccan_home_dir. - $rename."/_info.c ". $ccan_home_dir . $rename . "/json_" . $rename . " " - . $_SESSION['susername']. " ../../" . $db, $op, $status); - checkerror($status,"Error: In infotojson."); - - unset($op); exec('bzr add', $op, $status); - checkerror($status,"Error: bzr add error."); - - unset($op); exec('bzr commit --unchanged -m "commiting from ccan web ' . $rename . - " " . $_SESSION['susername'] . '"', $op, $status); - checkerror($status,"Error: bzr commit error."); - - unset($op); exec($bzr_push, $op, $status); - checkerror($status,"Error: bzr push error."); - - unset($op); exec($create_dep_tar . " " . $ccan_home_dir. $rename . " ../../" . - $tar_dir . " ../../" . $db , $op, $status); - checkerror($status,"Error: bzr push error."); - - chdir('../..'); - rmdirr($exactpath); - echo "
Stored to ". $ccan_home_dir . $rename . "
"; - } - - //if junk code (no _info.c etc) - else { - - rmdirr($junkcode.$folder.'-'.$_SESSION['susername']); - rename($tempfolder.$folder, $junkcode.$folder.'-'.$_SESSION['susername']); - - if($score == '') - $msg = 'Below is details for test.'; - - echo "
Score for code is low. - Cannot copy to repository. Moving to ". $junkcode.$folder.'-'. - $_SESSION['susername']."...

". $msg ."

"; - - foreach($score as $disp) - echo "$disp
"; - echo "
"; - - } - unlink($tempfolder.$_FILES["uploadedfile"]["name"]); -} -else { - echo "
File type not supported
"; - exit(); -} - -function checkerror($status, $msg) -{ - if($status != 0) { - echo "
" . $msg . "Contact ccan admin.
"; - exit(); - } -} - -function getowner($filename, $db) -{ - //getting owner of a file stored at db - $handle = sqlite3_open($db) or die("Could not open database"); - $query = "SELECT owner FROM fileowner users where filename=\"$filename\""; - $result = sqlite3_query($handle, $query) or die("Error in query: ".sqlite3_error($handle)); - $row = sqlite3_fetch_array($result); - return $row["owner"]; -} - -function storefileowner($filename, $owner, $db) -{ - //storing owner of a file stored at db - $handle = sqlite3_open($db) or die("Could not open database"); - $query = "insert into fileowner values(\"$filename\", \"$owner\")"; - $result = sqlite3_exec($handle, $query) or die("Error in query: ".sqlite3_error($handle)); -} -?> \ No newline at end of file +mail($ccanadmin, $subject, $message, "From: $frommail"); +echo "
Thanks!
Stored to temporary location. + Mail will be send to admin to get verification of the code."; +?>