Starting work on the build site
This commit is contained in:
7
.hgignore
Normal file
7
.hgignore
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
syntax: glob
|
||||||
|
*.exe
|
||||||
|
*.bak
|
||||||
|
*~
|
||||||
|
*.log
|
||||||
|
lib/source/*
|
||||||
|
lib/signularity_revisions*
|
||||||
30
latest.php
Normal file
30
latest.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// Make sure this is not cached
|
||||||
|
header("Cache-Control: no-cache, must-revalidate");
|
||||||
|
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
|
||||||
|
header("Content-Type: text/plain");
|
||||||
|
|
||||||
|
$chan = "SingularityAlpha";
|
||||||
|
|
||||||
|
if (isset($_GET["chan"])) {
|
||||||
|
$chan = preg_replace("%[^\\w_-]%i", "", $_GET["chan"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$files = glob($chan . "_*.exe");
|
||||||
|
|
||||||
|
if (count($files) === 0) {
|
||||||
|
header("HTTP/1.0 404 Not Found");
|
||||||
|
header("Content-Type: text/plain");
|
||||||
|
print "Requested channel was not found";
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
|
||||||
|
$files = array_reverse($files);
|
||||||
|
$host = $_SERVER['HTTP_HOST'];
|
||||||
|
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
|
||||||
|
$latest = urlencode($files[0]);
|
||||||
|
|
||||||
|
header("Location: http://${host}${uri}/${latest}");
|
||||||
|
?>
|
||||||
|
|
||||||
1
lib/.htaccess
Normal file
1
lib/.htaccess
Normal file
@@ -0,0 +1 @@
|
|||||||
|
deny from all
|
||||||
113
lib/DBH.php
Normal file
113
lib/DBH.php
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class DBH
|
||||||
|
{
|
||||||
|
public
|
||||||
|
$db_name,
|
||||||
|
$db_pass,
|
||||||
|
$db_user,
|
||||||
|
$db_host,
|
||||||
|
$dbh,
|
||||||
|
$last_error = "";
|
||||||
|
|
||||||
|
function log($line)
|
||||||
|
{
|
||||||
|
static $f = false;
|
||||||
|
static $failed = false;
|
||||||
|
|
||||||
|
if ($failed) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$f) {
|
||||||
|
$f = @fopen(SITE_ROOT.'/lib/site.log', 'a');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$f) {
|
||||||
|
$failed = true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@fwrite($f, "[".date('Y-m-d H:i')."] ".$line."\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
function connect($db_name, $db_host, $db_user, $db_pass)
|
||||||
|
{
|
||||||
|
$this->db_name = $db_name;
|
||||||
|
$this->db_pass = $db_pass;
|
||||||
|
$this->db_user = $db_user;
|
||||||
|
$this->db_host = $db_host;
|
||||||
|
|
||||||
|
$this->dbh = @sqlite_popen($db_name, 0666, $error_msg);
|
||||||
|
|
||||||
|
if (!$this->dbh) {
|
||||||
|
DBH::log("[error] connection to database failed: $error_msg");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function query($q)
|
||||||
|
{
|
||||||
|
$res = @sqlite_query($this->dbh, $q, SQLITE_BOTH, $error_msg);
|
||||||
|
|
||||||
|
if (!$res) {
|
||||||
|
DBH::log("[error] ".$q);
|
||||||
|
DBH::log("[error_msg] " . $error_msg);
|
||||||
|
$this->last_error = $error_msg;
|
||||||
|
|
||||||
|
$e = debug_backtrace();
|
||||||
|
$c = count($e);
|
||||||
|
$btr = "";
|
||||||
|
|
||||||
|
for ($i=0; $i<$c; $i++) {
|
||||||
|
$btr .= "{$e[$i]['class']}::{$e[$i]['function']} {$e[$i]['file']}({$e[$i]['line']})\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
DBH::log("[backtrace]\n".$btr);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
if ($res !== TRUE) {
|
||||||
|
$result_id = (int)$res;
|
||||||
|
if (!isset($this->field_desc[$result_id])) {
|
||||||
|
$nf = sqlite_num_fields($res);
|
||||||
|
for ($i=0; $i<$nf; $i++) {
|
||||||
|
$this->field_desc[$result_id][sqlite_field_name($res, $i)] = sqlite_field_name($res, $i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DBH::log("[success] ".$q);
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadFromDbRow(&$obj, $res, $row)
|
||||||
|
{
|
||||||
|
foreach ($row as $symbolicName => $nativeName){
|
||||||
|
if ($nativeName && ($this->field_desc[(int)$res][$symbolicName] == "timestamp" ||
|
||||||
|
$this->field_desc[(int)$res][$symbolicName] == "date")) {
|
||||||
|
$obj->{$symbolicName} = strtotime($nativeName);
|
||||||
|
} else {
|
||||||
|
$obj->{$symbolicName} = $nativeName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function fetchRow($res)
|
||||||
|
{
|
||||||
|
return @sqlite_fetch_array($res);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Local variables:
|
||||||
|
* tab-width: 4
|
||||||
|
* c-basic-offset: 4
|
||||||
|
* End:
|
||||||
|
* vim600: sw=4 ts=4 fdm=marker
|
||||||
|
* vim<600: sw=4 ts=4
|
||||||
|
*/
|
||||||
115
lib/ext_kl.php
Normal file
115
lib/ext_kl.php
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
<?php
|
||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
$php_str_sql_options_array = array(
|
||||||
|
"str_sql_date_format" => "Y-m-d",
|
||||||
|
"str_sql_datetime_format" => "Y-m-d H:i:s",
|
||||||
|
"str_sql_quote_func" => "sqlite_escape_string");
|
||||||
|
/**
|
||||||
|
* This method validates the sql insert string must always be used in conjunction with an insert to the db
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
|
||||||
|
function kl_str_sql()
|
||||||
|
{
|
||||||
|
GLOBAL $php_str_sql_options_array;
|
||||||
|
$f = $php_str_sql_options_array['str_sql_quote_func'];
|
||||||
|
|
||||||
|
$narg = func_num_args();
|
||||||
|
$args = func_get_args();
|
||||||
|
|
||||||
|
if ($narg<1) {
|
||||||
|
trigger_error("At least one parameter required", E_USER_WARNING);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
$offset = 0;
|
||||||
|
$flen = strlen($args[0]);
|
||||||
|
$res = "";
|
||||||
|
$narg = 1;
|
||||||
|
|
||||||
|
while ($offset < $flen) {
|
||||||
|
if (false !== ($pos = strpos($args[0],"!", $offset))) {
|
||||||
|
|
||||||
|
$res .= substr($args[0], $offset, $pos-$offset);
|
||||||
|
|
||||||
|
switch ($args[0][$pos+1]) {
|
||||||
|
|
||||||
|
case 's':
|
||||||
|
if (is_null($args[$narg])) {
|
||||||
|
$res .= 'NULL';
|
||||||
|
} else {
|
||||||
|
$res .= "'".$f($args[$narg])."'";
|
||||||
|
}
|
||||||
|
$narg++;
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
case 'b':
|
||||||
|
if (is_null($args[$narg])) {
|
||||||
|
$res .= 'NULL';
|
||||||
|
} else {
|
||||||
|
$res .= "'".pg_escape_bytea($args[$narg])."'";
|
||||||
|
}
|
||||||
|
$narg++;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'i':
|
||||||
|
if (is_null($args[$narg])) {
|
||||||
|
$res .= 'NULL';
|
||||||
|
} else {
|
||||||
|
$res .= (int)($args[$narg]);
|
||||||
|
}
|
||||||
|
$narg++;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'f':
|
||||||
|
if (is_null($args[$narg])) {
|
||||||
|
$res .= 'NULL';
|
||||||
|
} else {
|
||||||
|
$res .= (double)($args[$narg]);
|
||||||
|
}
|
||||||
|
$narg++;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'd':
|
||||||
|
if (!($args[$narg])) {
|
||||||
|
$res .= 'NULL';
|
||||||
|
} else {
|
||||||
|
$res .= "'".date($php_str_sql_options_array['str_sql_date_format'], $args[$narg])."'";
|
||||||
|
}
|
||||||
|
$narg++;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 't':
|
||||||
|
if (!($args[$narg])) {
|
||||||
|
$res .= 'NULL';
|
||||||
|
} else {
|
||||||
|
$res .= "'".date($php_str_sql_options_array['str_sql_datetime_format'], $args[$narg])."'";
|
||||||
|
}
|
||||||
|
$narg++;
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
default:
|
||||||
|
$res .= "!".$args[0][$pos+1];
|
||||||
|
}
|
||||||
|
$offset = $pos + 2;
|
||||||
|
} else {
|
||||||
|
$res .= substr($args[0], $offset);
|
||||||
|
$offset = $flen;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $res;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Local variables:
|
||||||
|
* tab-width: 4
|
||||||
|
* c-basic-offset: 4
|
||||||
|
* End:
|
||||||
|
* vim600: noet sw=4 ts=4 fdm=marker
|
||||||
|
* vim<600: noet sw=4 ts=4
|
||||||
|
*/
|
||||||
98
lib/import_revs.php
Executable file
98
lib/import_revs.php
Executable file
@@ -0,0 +1,98 @@
|
|||||||
|
#!/usr/bin/php
|
||||||
|
<?php
|
||||||
|
|
||||||
|
if (PHP_SAPI != "cli") {
|
||||||
|
print "Utility script 0x55424523.";
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
|
||||||
|
// create table revs(id integer, hash varchar, author varchar, time timestamp, message text, diff text, primary key(id));
|
||||||
|
// create index hash_index on revs(hash);
|
||||||
|
|
||||||
|
define("SITE_ROOT", dirname(__file__) . "/..");
|
||||||
|
require_once SITE_ROOT . "/lib/init.php";
|
||||||
|
|
||||||
|
function import_rev($id, $hash)
|
||||||
|
{
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
print "Importing revision number $id with hash $hash\n";
|
||||||
|
$log = explode("\n", rtrim(`git log -n1 $hash`));
|
||||||
|
|
||||||
|
$author = "";
|
||||||
|
if (preg_match("|Author:\\s*(.*)|i", $log[1], $m)) {
|
||||||
|
$author = $m[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
$date = "";
|
||||||
|
if (preg_match("|Date:\\s*(.*)|i", $log[2], $m)) {
|
||||||
|
$date = strtotime($m[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$msg = "";
|
||||||
|
$nrLog = count($log);
|
||||||
|
for ($i=4; $i<$nrLog; $i++) {
|
||||||
|
$msg .= substr($log[$i], 4);
|
||||||
|
if ($i<$nrLog-1) {
|
||||||
|
$msg .= "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$DB->query(
|
||||||
|
kl_str_sql(
|
||||||
|
"Insert into revs (id, hash, author, time, message) values (!i, !s, !s, !t, !s)",
|
||||||
|
$id, $hash, $author, $date, $msg));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function update_source()
|
||||||
|
{
|
||||||
|
exec("git reset --hard", $out, $res);
|
||||||
|
if ($res) {
|
||||||
|
DBH::log("Command failed: ", implode("\n", $out));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
exec("git pull", $out, $res);
|
||||||
|
if ($res) {
|
||||||
|
DBH::log("Command failed: ", implode("\n", $out));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
print implode("\n", $out) . "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
chdir(SITE_ROOT . "/lib/source");
|
||||||
|
|
||||||
|
# update_source();
|
||||||
|
|
||||||
|
$revsStr = rtrim(`git rev-list HEAD | tac`);
|
||||||
|
$revs = explode("\n", $revsStr);
|
||||||
|
$nrRevs = count($revs);
|
||||||
|
|
||||||
|
|
||||||
|
$latest = 0;
|
||||||
|
$res = $DB->query("select max(id) as id from revs");
|
||||||
|
if ($row = $DB->fetchRow($res)) {
|
||||||
|
if ($DB->loadFromDbRow($dbLatest, $res, $row)) {
|
||||||
|
$latest = (int)$dbLatest->id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
print "Found $nrRevs revisions\n";
|
||||||
|
print "Latest revision in the database: $latest\n";
|
||||||
|
|
||||||
|
if ($latest < $nrRevs) {
|
||||||
|
for ($rev = $latest + 1; $rev <= $nrRevs; $rev++) {
|
||||||
|
import_rev($rev, $revs[$rev - 1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Local variables:
|
||||||
|
* tab-width: 4
|
||||||
|
* c-basic-offset: 4
|
||||||
|
* End:
|
||||||
|
* vim600: noet sw=4 ts=4 fdm=marker
|
||||||
|
* vim<600: noet sw=4 ts=4
|
||||||
|
*/
|
||||||
90
lib/init.php
Normal file
90
lib/init.php
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
<?php
|
||||||
|
if (!defined('SITE_ROOT')) {
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
error_reporting(E_ALL ^ E_NOTICE);
|
||||||
|
|
||||||
|
if (!extension_loaded('kl')) {
|
||||||
|
require_once SITE_ROOT.'/lib/ext_kl.php';
|
||||||
|
}
|
||||||
|
|
||||||
|
function __autoload($class)
|
||||||
|
{
|
||||||
|
require_once(SITE_ROOT . '/lib/' . $class . '.php');
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Directory relative to server root
|
||||||
|
* No leading or trailing slash.
|
||||||
|
* Example: http://www.example.com/applications/app1/
|
||||||
|
*/
|
||||||
|
|
||||||
|
define('REL_DIR', '');
|
||||||
|
|
||||||
|
if (!defined('URL_ROOT')) {
|
||||||
|
$init_port = "";
|
||||||
|
$init_ssl = strlen($_SERVER["HTTPS"]) > 0 ? true:false;
|
||||||
|
|
||||||
|
$init_url = $init_ssl ? "https://" : "http://";
|
||||||
|
|
||||||
|
if ($init_ssl && $_SERVER['PORT']!=443) {
|
||||||
|
$init_port = $_SERVER['PORT'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$init_ssl && $_SERVER['PORT']!=80) {
|
||||||
|
$init_port = $_SERVER['PORT'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$init_url .= $_SERVER['HTTP_HOST'];
|
||||||
|
|
||||||
|
if ($init_port) {
|
||||||
|
$init_url .= ":" . $init_port;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (defined('REL_DIR') && strlen(REL_DIR)) {
|
||||||
|
$init_url .= '/' . REL_DIR;
|
||||||
|
}
|
||||||
|
|
||||||
|
define ('URL_ROOT', $init_url);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!defined('IMG_ROOT')) {
|
||||||
|
define('IMG_ROOT', URL_ROOT . '/images');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$DB = new DBH();
|
||||||
|
|
||||||
|
$DB_NAME = SITE_ROOT . '/lib/signularity_revisions.db';
|
||||||
|
/* $DB_USER = 'gigaprims';
|
||||||
|
$DB_PASS = 'secrit';
|
||||||
|
$DB_HOST = 'localhost';
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
if (!$DB->connect($DB_NAME, $DB_HOST, $DB_USER, $DB_PASS)) {
|
||||||
|
echo "System is down for mantainence. Please try again later.";
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
$S = new Session();
|
||||||
|
if (!defined('NO_SESSION') && PHP_SAPI != "cli") {
|
||||||
|
$S->check();
|
||||||
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/* Prevent XSS attacks via PHP_SELF */
|
||||||
|
$_SERVER['PHP_SELF'] = htmlspecialchars($_SERVER['PHP_SELF']);
|
||||||
|
/*
|
||||||
|
* Local variables:
|
||||||
|
* tab-width: 4
|
||||||
|
* c-basic-offset: 4
|
||||||
|
* End:
|
||||||
|
* vim600: sw=4 ts=4 fdm=marker
|
||||||
|
* vim<600: sw=4 ts=4
|
||||||
|
*/
|
||||||
|
?>
|
||||||
Reference in New Issue
Block a user