diff options
author | Eudyptula <eitan@mosenkis.net> | 2009-08-04 17:58:55 -0400 |
---|---|---|
committer | Eudyptula <eitan@mosenkis.net> | 2009-08-04 17:58:55 -0400 |
commit | d3da989d3e2d2cb03cdc4bd2e23783f716ef5035 (patch) | |
tree | 2f9f8c413d2800a3f72282dec0f86170a00ff4f6 | |
parent | Add visibility column to builds, configurations (diff) | |
download | ingenue-d3da989d3e2d2cb03cdc4bd2e23783f716ef5035.tar.gz ingenue-d3da989d3e2d2cb03cdc4bd2e23783f716ef5035.tar.bz2 ingenue-d3da989d3e2d2cb03cdc4bd2e23783f716ef5035.zip |
Widespread cleanup - moved $conf, $death into $S; $S is given as arg to init_x() and body_x(); $request removed in favor of $_REQUEST; query() replaces $S[pdo]->query(); etc.
72 files changed, 297 insertions, 504 deletions
diff --git a/backend/backend.php b/backend/backend.php index 343be9f..5090c63 100755 --- a/backend/backend.php +++ b/backend/backend.php @@ -8,7 +8,7 @@ if (isset($opts['f'])) { case -1: die("Failed to fork"); case 0: - $conf['debug']=false; + $S['conf']['debug']=false; break; default: die(); @@ -49,19 +49,19 @@ declare(ticks=1); require_once(SHARED.'/include/dbinit.php'); while (true) { // TODO check first for builds that need to be resumed (and figure out how to resume things) - $S['pdo']->query('LOCK TABLES `builds` WRITE'); - $r=$S['pdo']->query('SELECT * FROM `builds` WHERE `status`=-128 ORDER BY `ctime` ASC LIMIT 1'); + query('LOCK TABLES `builds` WRITE'); + $r=query('SELECT * FROM `builds` WHERE `status`=-128 ORDER BY `ctime` ASC LIMIT 1'); if ($r->rowCount()) { $build=new sql_build($r->fetch(PDO::FETCH_ASSOC)); $build->start=time(); $build->status=-1; $build->write(); - $S['pdo']->query('UNLOCK TABLES'); + query('UNLOCK TABLES'); debug('Starting build id='.$build->id); $file=null; try { - if ($conf['split_setup']) { - $opt=new sql_buildopt($build->id, 'backend', $conf['backend_id']); + if ($S['conf']['split_setup']) { + $opt=new sql_buildopt($build->id, 'backend', $S['conf']['backend_id']); $opt->write(); unset($opt); } @@ -75,7 +75,7 @@ while (true) { require_once(BACKEND."/bundlers/{$opts['bundler']}.php"); $proc='bundle_'.$opts['bundler']; $file=$proc($image, $workdir, $opts); - if (!$conf['debug']) { + if (!$S['conf']['debug']) { execute_command('Delete work directory', 'rm -rf "'.$workdir.'"'); } } catch (Exception $e) { @@ -83,13 +83,13 @@ while (true) { log_msg('Caught exception: '.$e->getMessage()); $build->status=126; $owner=$build->get_owner(); - xhtmlemail('"'.$owner->name.'" <'.$owner->email.'>', null, $conf['title'].' build failed', 'Your build has failed. You can find more information at <a href="'.url("build/$build->id").'">'.url("build/$build->id").'</a>'); + xhtmlemail('"'.$owner->name.'" <'.$owner->email.'>', null, $S['conf']['title'].' build failed', 'Your build has failed. You can find more information at <a href="'.url("build/$build->id").'">'.url("build/$build->id").'</a>'); } $build->finish=time(); debug('Finished with build id='.$build->id); if (isset($file)) { debug("Completed build successfully"); - if ($conf['split_setup']) { + if ($S['conf']['split_setup']) { $build->status=-127; $build->write(); $key=randstring(30); @@ -104,7 +104,7 @@ while (true) { )); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); $result=curl_exec($c); - if ($conf['debug'] && is_string($result)) { + if ($S['conf']['debug'] && is_string($result)) { debug($result); } if ($result === false || strpos($result, 'Upload successful') === false) { @@ -120,12 +120,12 @@ while (true) { $ext=substr($base, strpos($base, '.')); rename($file, COMPLETED.'/build-'.$build->id.$ext); } - xhtmlemail('"'.$owner->name.'" <'.$owner->email.'>', null, $conf['title'].' build finished', 'Your build has completed successfully. You can find more information and download the completed image at <a href="'.url("build/$build->id").'">'.url("build/$build->id").'</a>'); + xhtmlemail('"'.$owner->name.'" <'.$owner->email.'>', null, $S['conf']['title'].' build finished', 'Your build has completed successfully. You can find more information and download the completed image at <a href="'.url("build/$build->id").'">'.url("build/$build->id").'</a>'); } $build->write(); unset($build); } else { - $S['pdo']->query('UNLOCK TABLES'); + query('UNLOCK TABLES'); } // log_msg('Sleeping...', false); sleep(5); diff --git a/backend/functions/get_pkgdirs.php b/backend/functions/get_pkgdirs.php index 1f39420..b441f38 100644 --- a/backend/functions/get_pkgdirs.php +++ b/backend/functions/get_pkgdirs.php @@ -1,12 +1,12 @@ <?php function get_pkgdirs($dir=null) { - global $conf; + global $S; if ($dir===null) { - $dir=$conf['pkgdir_root']; + $dir=$S['conf']['pkgdir_root']; } if (is_file($dir.'/Packages')) { // We assume that a dir with a Packages file will not contain other complete ppkgdirs - return array(substr($dir, strlen($conf['pkgdir_root'])+1)); + return array(substr($dir, strlen($S['conf']['pkgdir_root'])+1)); } else { $return=array(); foreach (glob ($dir.'/*', GLOB_ONLYDIR) as $subdir) { diff --git a/backend/modules/gentoo_catalyst/build.php b/backend/modules/gentoo_catalyst/build.php deleted file mode 100644 index 80746b2..0000000 --- a/backend/modules/gentoo_catalyst/build.php +++ /dev/null @@ -1,71 +0,0 @@ -<?php -function gentoo_catalyst_build(&$build, &$opts, &$W) { - global $conf, $profile; - $profile=new sql_gentoo_profile($opts['profile']); - $headers=$profile->get_headers(); - $arch=explode(' ', $headers['accept_keywords']); - $arch=$arch[0]; - if (substr($arch, 0, 1) == '~') - $arch=substr($arch, 1); -// $C=$W.'/config_root'; - makedirs('catalyst_tmp', 'snapshot_cache'); - $catalyst=array( - 'digests' => '', - 'contents' => '', - 'distdir' => '', - // 'envscript' => '', - 'hash_function' => 'crc32', - 'options' => 'pkgcache metadata_overlay seedcache snapcache', - 'portdir' => $conf['portdir'], - 'sharedir' => '/usr/lib/catalyst', // This may not work on all systems - 'snapshotcache' => "$W/snapshot_cache", - 'storedir' => "$W/catalyst_tmp" - ); - $ctc=fopen("$W/catalyst.conf", 'w'); - foreach ($catalyst as $name => $val) { - fputs($ctc, "$name=\"$val\"\n"); - } - fclose($ctc); - // TODO - stages 1-3 first, only do stage4 if we have extra packages to install - $spec=array( - 'subarch' => $arch, - 'version_stamp' => gmdate('Ymd-His'), - 'target' => 'stage4', - 'rel_type' => 'default', - 'profile' => $headers['profile'], - 'snapshot' => gmdate('Ymd'), - 'source_subpath' => 'default', // FIXME - 'portage_confdir' => '', - 'portage_overlay' => '', - 'pkgcache_path' => "$W/pkgcache", - 'kerncache_path' => '', - 'stage4/use' => $headers['use'], - 'stage4/packages' => $opts['install_packages'], - 'stage4/fsscript' => '', - 'stage4/splash_theme' => '', - 'stage4/gk_mainargs' => '', - 'stage4/linuxrc' => '', - 'stage4/motd' => '', -// 'stage4/modblacklist' => '8139cp', // Not recognized by catalyst - 'stage4/rcadd' => '', - 'stage4/rcdel' => '', - 'stage4/root_overlay' => '', - 'stage4/xinitrc' => '', - 'stage4/users' => '', - 'boot/kernel' => '', - 'stage4/unmerge' => '', - 'stage4/empty' => '/var/tmp /var/cache /var/db /var/empty /var/lock /var/log /var/run /var/spool /var/state /tmp /usr/portage /usr/share/man /usr/share/info /usr/share/unimaps /usr/include /usr/share/zoneinfo /usr/share/dict /usr/share/doc /usr/share/ss /usr/share/state /usr/share/texinfo /usr/lib/python2.2 /usr/lib/portage /usr/share/gettext /usr/share/i18n /usr/share/rfc /usr/lib/X11/config /usr/lib/X11/etc /usr/lib/X11/doc /usr/src /usr/share/doc /usr/share/man /root/.ccache /etc/cron.daily /etc/cron.hourly /etc/cron.monthly /etc/cron.weekly /etc/logrotate.d /etc/rsync /usr/lib/awk /usr/lib/ccache /usr/lib/gcc-config /usr/lib/nfs /usr/local /usr/diet/include /usr/diet/man /usr/share/consolefonts/partialfonts /usr/share/consoletrans /usr/share/emacs /usr/share/gcc-data /usr/share/genkernel /etc/splash/gentoo /etc/splash/emergence /usr/share/gnuconfig /usr/share/lcms /usr/share/locale /etc/skel', - 'stage4/rm' => '/lib/*.a /usr/lib/*.a /usr/lib/gcc-lib/*/*/libgcj* /etc/dispatch-conf.conf /etc/etc-update.conf /etc/*- /etc/issue* /etc/make.conf /etc/man.conf /etc/*.old /root/.viminfo /usr/sbin/fb* /usr/sbin/fsck.cramfs /usr/sbin/fsck.minix /usr/sbin/mkfs.minix /usr/sbin/mkfs.bfs /usr/sbin/mkfs.cramfs /lib/security/pam_access.so /lib/security/pam_chroot.so /lib/security/pam_debug.so /lib/security/pam_ftp.so /lib/security/pam_issue.so /lib/security/pam_mail.so /lib/security/pam_motd.so /lib/security/pam_mkhomedir.so /lib/security/pam_postgresok.so /lib/security/pam_rhosts_auth.so /lib/security/pam_userdb.so /usr/share/consolefonts/1* /usr/share/consolefonts/7* /usr/share/consolefonts/8* /usr/share/consolefonts/9* /usr/share/consolefonts/A* /usr/share/consolefonts/C* /usr/share/consolefonts/E* /usr/share/consolefonts/G* /usr/share/consolefonts/L* /usr/share/consolefonts/M* /usr/share/consolefonts/R* /usr/share/consolefonts/a* /usr/share/consolefonts/c* /usr/share/consolefonts/dr* /usr/share/consolefonts/g* /usr/share/consolefonts/i* /usr/share/consolefonts/k* /usr/share/consolefonts/l* /usr/share/consolefonts/r* /usr/share/consolefonts/s* /usr/share/consolefonts/t* /usr/share/consolefonts/v* /etc/splash/livecd-2006.1/16* /etc/splash/livecd-2006.1/12* /etc/splash/livecd-2006.1/6* /etc/splash/livecd-2006.1/8* /etc/splash/livecd-2006.1/images/silent-16* /etc/splash/livecd-2006.1/images/silent-12* /etc/splash/livecd-2006.1/images/silent-6* /etc/splash/livecd-2006.1/images/silent-8* /etc/splash/livecd-2006.1/images/verbose-16* /etc/splash/livecd-2006.1/images/verbose-12* /etc/splash/livecd-2006.1/images/verbose-6* /etc/splash/livecd-2006.1/images/verbose-8* /etc/make.conf.example /etc/make.globals /etc/resolv.conf' - ); - $specfile=fopen("$W/stage4.spec", 'w'); - foreach ($spec as $name => $val) { - if (strlen($val)) - fputs($specfile, "$name: $val\n"); - } - fclose($specfile); - $pkgdir=$spec['pkgcache_path'].'/'.$spec['rel_type'].'/'.$spec['target'].'-'.$spec['version_stamp']; - makedir(dirname($pkgdir)); - symlink($pkgdir, $profile->pkgdir); - execute_command('Running Catalyst for build stage 4', "catalyst -c '$W/catalyst.conf' -f '$W/stage4.spec'"); -} -?> diff --git a/backend/modules/gentoo_catalyst/catalyst.conf b/backend/modules/gentoo_catalyst/catalyst.conf deleted file mode 100644 index ba5505b..0000000 --- a/backend/modules/gentoo_catalyst/catalyst.conf +++ /dev/null @@ -1,79 +0,0 @@ -# /etc/catalyst/catalyst.conf - -# Simple desriptions of catalyst settings. Please refer to the online -# documentation for more information. - -# Creates a .DIGESTS file containing the hash output from any of the supported -# options below. Adding them all may take a long time. -# Supported options: sha1, sha224, ripemd128, ripemd320, sha384, crc32, -# ripemd256, sha256, sha512, ripemd160, md5 -digests="md5 sha1" - -# Creates a .CONTENTS file listing the contents of the file. Pick from any of -# the supported options below: -# auto - strongly recommended -# tar-tv - does 'tar tvf FILE' -# tar-tvz - does 'tar tvzf FILE' -# tar-tvy - does 'tar tvyf FILE' -# isoinfo-l - does 'isoinfo -l -i FILE' -# isoinfo-f - does 'isoinfo -f -i FILE' -# 'isoinfo-f' is the only option not chosen by the automatic algorithm. -# If this variable is empty, no .CONTENTS will be generated at all. -contents="auto" - -# distdir specifies where your distfiles are located. This setting should -# work fine for most default installations. -distdir="/usr/portage/distfiles" - -# envscript allows users to set options such as http proxies, MAKEOPTS, -# GENTOO_MIRRORS, or any other environment variables needed for building. -# The envscript file sets environment variables like so: -# export FOO="bar" -envscript="/etc/catalyst/catalystrc" - -# Internal hash function catalyst should use for things like autoresume, -# seedcache, etc. The default and fastest is crc32. You should not ever need -# to change this unless your OS does not support it. -# Supported options: sha1, sha224, ripemd128, ripemd320, sha384, crc32, -# ripemd256, sha256, sha512, ripemd160, md5 -hash_function="crc32" - -# options set different build-time options for catalyst. Some examples are: -# autoresume = Attempt to resume a failed build, clear the autoresume flags with -# the -a option to the catalyst cmdline. -p will clear the autoresume flags -# as well as your pkgcache and kerncache -# ( This option is not fully tested, bug reports welcome ) -# ccache = enables build time ccache support (highly recommended) -# distcc = enable distcc support for building. You have to set distcc_hosts in -# your spec file. -# icecream = enables icecream compiler cluster support for building -# kerncache = keeps a tbz2 of your built kernel and modules (useful if your -# build stops in livecd-stage2) -# metadata_overlay = enabled the metadata_overlay cache module in portage, which -# uses the in-tree metadata -# pkgcache = keeps a tbz2 of every built package (useful if your build stops -# prematurely) -# seedcache = use the build output of a previous target if it exists to speed up -# the copy -# snapcache = cache the snapshot so that it can be bind-mounted into the chroot. -# WARNING: moving parts of the portage tree from within fsscript *will* break -# your cache. The cache is unlinked before any empty or rm processing, though. -# -# (These options can be used together) -options="autoresume kerncache metadata_overlay pkgcache seedcache snapcache" - -# portdir specifies the source portage tree used by the snapshot target. -portdir="/usr/portage" - -# sharedir specifies where all of the catalyst runtime executables are. Most -# users do not need to change this. -sharedir="/usr/lib64/catalyst" - -# snapshot_cache specifies where the snapshots will be cached to if snapcache is -# enabled in the options. -snapshot_cache="/var/tmp/catalyst/snapshot_cache" - -# storedir specifies where catalyst will store everything that it builds, and -# also where it will put its temporary files and caches. -storedir="/var/tmp/catalyst" - diff --git a/backend/modules/gentoo_catalyst/catalystrc b/backend/modules/gentoo_catalyst/catalystrc deleted file mode 100644 index 581772d..0000000 --- a/backend/modules/gentoo_catalyst/catalystrc +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -# This is an example catalystrc. As such, it doesn't actually *do* anything. - -# Uncomment the following to increase the number of threads used to compile. -# export MAKEOPTS="-j16" - diff --git a/backend/modules/gentoo_portage/base-system.php b/backend/modules/gentoo_portage/base-system.php index 35dc91e..a940c87 100644 --- a/backend/modules/gentoo_portage/base-system.php +++ b/backend/modules/gentoo_portage/base-system.php @@ -8,7 +8,7 @@ if ($opts['basesystem'] == 'manual' && $opts['prunepkgs']) { throw_exception('Base system autoprune not implemented - need package list'); $keep=explode(' ', $keep_pkgs); $remove=array(); - $r=$S['pdo']->query('SELECT * FROM `gentoo_basepkgs` WHERE `profile`='.$profile->id); + $r=query('SELECT * FROM `gentoo_basepkgs` WHERE `profile`='.$profile->id); while ($pkg=$r->fetch(PDO::FETCH_ASSOC)) { $pkg=$pkg['pkg']; if (($i=array_search($pkg, $keep)) === false) diff --git a/backend/modules/gentoo_portage/build.php b/backend/modules/gentoo_portage/build.php index aef8bde..5c1a1fd 100644 --- a/backend/modules/gentoo_portage/build.php +++ b/backend/modules/gentoo_portage/build.php @@ -2,13 +2,13 @@ require_once(dirname(__FILE__).'/packages.php'); // __DIR__ 5.3.0 // This is the main function that carries out a build from start to finish function gentoo_portage_build(&$build, &$opts, &$W) { - global $conf; + global $S; $profile=new sql_gentoo_profile($opts['profile']); $headers=$profile->get_headers(); $I="$W/image"; $extra=explode(' ', $opts['options']); require(dirname(__FILE__).'/setup.php'); // __DIR__ in 5.3.0 - if ($conf['debug']) + if ($S['conf']['debug']) execute_command_with_env('Log portage setup', 'emerge --info', $prtg_cfgrt); require(dirname(__FILE__).'/base-system.php'); // __DIR__ 5.3.0 if (in_array('pruneinit', $extra)) diff --git a/backend/modules/gentoo_portage/packages.php b/backend/modules/gentoo_portage/packages.php index 234186c..cfbb71d 100644 --- a/backend/modules/gentoo_portage/packages.php +++ b/backend/modules/gentoo_portage/packages.php @@ -1,7 +1,7 @@ <?php function portage_install($pkgs, $desc=null, $opts=null, $use=null) { - global $prtg_cfgrt, $conf; - $opts=$conf['emerge_default_opts'].' '.($opts === null?'-K -n --root-deps=rdeps':$opts); + global $prtg_cfgrt, $S; + $opts=$S['conf']['emerge_default_opts'].' '.($opts === null?'-K -n --root-deps=rdeps':$opts); if (!$pkgs) return; if (!is_array($pkgs)) $pkgs=explode(' ', $pkgs); diff --git a/backend/modules/gentoo_portage/setup.php b/backend/modules/gentoo_portage/setup.php index d946b81..6e8bf03 100644 --- a/backend/modules/gentoo_portage/setup.php +++ b/backend/modules/gentoo_portage/setup.php @@ -4,7 +4,7 @@ $C=$W.'/config_root'; makedirs($I, $C, "$W/log", "$W/tmp"); log_status("Making symlink $C/etc -> .", symlink('.', "$C/etc")); $makeconf=array( - 'pkgdir' => $conf['pkgdir_root'].'/'.$profile->pkgdir, + 'pkgdir' => $S['conf']['pkgdir_root'].'/'.$profile->pkgdir, 'chost' => $headers['chost'], 'accept_keywords' => $headers['accept_keywords'], 'root' => $I, @@ -18,7 +18,7 @@ foreach ($makeconf as $name => $val) unset($makeconf); log_status('Writing '.$C.'/make.conf', file_put_contents($C.'/etc/make.conf', $contents)); unset($contents); -log_status('Making make.profile symlink to '.$conf['portdir'].'/profiles/'.$headers['profile'], symlink($conf['portdir'].'/profiles/'.$headers['profile'], $C.'/etc/make.profile')); +log_status('Making make.profile symlink to '.$S['conf']['portdir'].'/profiles/'.$headers['profile'], symlink($S['conf']['portdir'].'/profiles/'.$headers['profile'], $C.'/etc/make.profile')); global $prtg_cfgrt; $prtg_cfgrt=array('PORTAGE_CONFIGROOT' => $C); end_internal_task(0); @@ -1,7 +1,6 @@ >=dev-lang/php-5.2.2 USE=pdo hash pcntl pcre cli pdo mysqli apache2 curl ctype reflection -sys-apps/fakeroot ? +>=virtual/mysql-5 sys-apps/portage # In case you use paludis -www-servers/apache APACHE2_MODULES=rewrite? -sys-fs/squashfs-tools(-4.0?) +www-servers/apache APACHE2_MODULES=rewrite +>=sys-fs/squashfs-tools-4 JFFS2: sys-fs/mtd-utils -EXT2: sys-fs/genext2fs diff --git a/frontend/classes/forms.php b/frontend/classes/forms.php index 39843e9..daa95cf 100644 --- a/frontend/classes/forms.php +++ b/frontend/classes/forms.php @@ -10,8 +10,7 @@ abstract class form_element { echo "$this->label: "; } public function process() { - global $request; - return isset($request[$this->htmlname])?$request[$this->htmlname]:false; + return isset($_REQUEST[$this->htmlname])?$_REQUEST[$this->htmlname]:false; } public function verify($val) { return $val !== false; @@ -47,10 +46,9 @@ class select extends form_element { echo "<br/>\n"; } public function process() { - global $request; $vals=array_keys($this->options); - if (isset($request[$this->htmlname]) && is_numeric($request[$this->htmlname]) && isset($vals[$request[$this->htmlname]])) { - return $vals[$request[$this->htmlname]]; + if (isset($_REQUEST[$this->htmlname]) && is_numeric($_REQUEST[$this->htmlname]) && isset($vals[$_REQUEST[$this->htmlname]])) { + return $vals[$_REQUEST[$this->htmlname]]; } else return false; } public function verify($val) { @@ -90,11 +88,10 @@ class checkbox_array extends form_element { } } public function process() { - global $request; $val=array(); - if (isset($request[$this->htmlname])) { + if (isset($_REQUEST[$this->htmlname])) { $vals=array_keys($this->array); - foreach ($request[$this->htmlname] as $i => $null) { + foreach ($_REQUEST[$this->htmlname] as $i => $null) { $val[]=$vals[$i]; } } @@ -122,9 +119,9 @@ class checkbox_array extends form_element { class layered_checkbox_array extends checkbox_array { private $depth=0, $path_delims=array('', '/', '-'); function __construct($htmlname, $label, &$array, $delim=' ', $metadata) { - parent::__construct($htmlname, $label, &$array, $delim); + parent::__construct($htmlname, $label, $array, $delim); $this->metadata=$metadata; - for ($i=current(&$array); is_array($i); $i=current($i)) $this->depth++; + for ($i=current($array); is_array($i); $i=current($i)) $this->depth++; global $S; if (!in_array('lca', $S['scripts'])) { $S['scripts'][]='lca'; @@ -153,7 +150,7 @@ class layered_checkbox_array extends checkbox_array { } private function r_output(&$array, $depth=0, $path=null, $name=null) { static $uid=0, $ucid=0; - $conf=&$this->metadata[0]; + $S['conf']=&$this->metadata[0]; if ($depth == 0) { $search=$autosize=0; for ($i=1; $i<count($this->metadata); $i++) { @@ -166,18 +163,18 @@ class layered_checkbox_array extends checkbox_array { } } if ($search) { - if (!isset($conf['id'])) { - $conf['id']=self::b36($uid++); + if (!isset($S['conf']['id'])) { + $S['conf']['id']=self::b36($uid++); } - echo 'Search: <input id="'.$conf['id'].'-q" onkeyup="lca_search(this.value, document.getElementById(\''.$conf['id'].'\'), 0, '.$this->depth.')" /> <a href="javascript:q=document.getElementById(\''.$conf['id'].'-q\'); q.value=\'\'; q.onkeyup()">Clear</a> <a href="javascript:lca_show_checked(document.getElementById(\''.$conf['id'].'\'), 0, '.$this->depth.'); undefined">Show checked</a><br/>'."\n"; + echo 'Search: <input id="'.$S['conf']['id'].'-q" onkeyup="lca_search(this.value, document.getElementById(\''.$S['conf']['id'].'\'), 0, '.$this->depth.')" /> <a href="javascript:q=document.getElementById(\''.$S['conf']['id'].'-q\'); q.value=\'\'; q.onkeyup()">Clear</a> <a href="javascript:lca_show_checked(document.getElementById(\''.$S['conf']['id'].'\'), 0, '.$this->depth.'); undefined">Show checked</a><br/>'."\n"; } - echo '<div class="lca'.(isset($conf['autosize'])?' autosize" style="font-size: '.pow(1.15, $autosize)*100.0.'%':'').'" id="'.$conf['id'].'">'."\n"; + echo '<div class="lca'.(isset($S['conf']['autosize'])?' autosize" style="font-size: '.pow(1.15, $autosize)*100.0.'%':'').'" id="'.$S['conf']['id'].'">'."\n"; foreach ($array as $name => &$val) { $this->r_output($val, $depth+1, $name, $name); $uid++; } echo '<h3 style="display: none">No results</h3></div>'; - echo "<script type=\"text/javascript\">\n<!--\nif (lca_show_checked(document.getElementById('{$conf['id']}'), 0, $this->depth) == 0) lca_search(document.getElementById('{$conf['id']}-q').value, document.getElementById('{$conf['id']}'), 0, $this->depth);\n-->\n</script>\n"; + echo "<script type=\"text/javascript\">\n<!--\nif (lca_show_checked(document.getElementById('{$S['conf']['id']}'), 0, $this->depth) == 0) lca_search(document.getElementById('{$S['conf']['id']}-q').value, document.getElementById('{$S['conf']['id']}'), 0, $this->depth);\n-->\n</script>\n"; } else { $meta=$this->metadata[$depth]; if (isset($meta['tag'])) { @@ -214,8 +211,7 @@ class layered_checkbox_array extends checkbox_array { } else { $meta=$this->metadata[$depth]; if (isset($meta['checkbox'])) { - global $request; - if (isset($request[$this->htmlname][self::b36($ucid)])) { + if (isset($_REQUEST[$this->htmlname][self::b36($ucid)])) { $r[]=$this->format_label($array, $meta['checkbox'], $path, $name); } $ucid++; diff --git a/frontend/classes/pdo.php b/frontend/classes/pdo.php deleted file mode 100644 index daf71ba..0000000 --- a/frontend/classes/pdo.php +++ /dev/null @@ -1,8 +0,0 @@ -<?php -class pdo_debug extends PDO { - function query($q, $a1=null, $a2=null, $a3=null) { - debug('pdo::query', $q); - return parent::query($q, $a1, $a2, $a3); - } -} -?> diff --git a/frontend/classes/wizard.php b/frontend/classes/wizard.php index 4d0d7b7..de37e72 100644 --- a/frontend/classes/wizard.php +++ b/frontend/classes/wizard.php @@ -1,6 +1,6 @@ <?php class wizard_step { - var $configuration, $module, $step, $title, $next, $data=array(); + public $configuration, $module, $step, $title, $next, $data=array(); function __construct(&$c, $step, $noload=false) { $this->configuration=&$c; $this->module=new module($c->module); @@ -16,13 +16,13 @@ class wizard_step { $this->next=isset($next)?$next:($this->step == $this->module->numsteps?null:$step+1); } public function output($rw=true) { - global $conf; + global $S; echo "<div class=\"wizard\" id=\"step$this->step\">"; if ($rw) echo '<form action="'.url('config/'.$this->configuration->id).'" method="post"><a style="float: right" href="'.url('config/'.$this->configuration->id.'/status').'">Status</a>'; if ($rw) { echo '<h3>Step '.$this->step.': '.$this->title."</h3>\n"; - $scale=$conf['progressbar_width']/$this->module->numsteps; + $scale=$S['conf']['progressbar_width']/$this->module->numsteps; echo '<img src="'.url('images/full.gif').'" style="border-left: 1px solid black; border-top: 1px solid black; border-bottom: 1px solid black; width: '.$this->step*$scale.'px; height: 15px" /><img src="'.url('images/empty.gif').'" style="border-right: 1px solid black; border-top: 1px solid black; border-bottom: 1px solid black; width: '.(count($this->module->steps)-$this->step)*$scale.'px; height: 15px" /><br/>'."\n"; $this->echo_buttons(); } @@ -43,8 +43,7 @@ class wizard_step { echo '</div>'."\n"; } public function process() { - global $request; - if (!isset($request['wizard_submit'][$this->step])) { + if (!isset($_REQUEST['wizard_submit'][$this->step])) { return $this->step; } $result=$this->next; @@ -91,9 +90,6 @@ class wizard_step { private function layered_checkbox_array($optname, $htmlname, $label, &$array, $delim=' ', $metadata) { $this->data[]=array(new layered_checkbox_array($htmlname, $label, $array, $delim, $metadata), $optname); } - private function query($q) { - return $GLOBALS['S']['pdo']->query($q); - } private function set_opt($opt, $val) { return $this->configuration->set_opt($opt, $val); } diff --git a/frontend/css/debug.css b/frontend/css/debug.css index 38c6774..7f49bd5 100644 --- a/frontend/css/debug.css +++ b/frontend/css/debug.css @@ -1,4 +1,4 @@ -<?php if ($conf['debug']) { ?> +<?php if ($S['conf']['debug']) { ?> div#debug { font-family: monospace; background-color: white; diff --git a/frontend/css/general.css b/frontend/css/general.css index df0d3a6..4638de5 100644 --- a/frontend/css/general.css +++ b/frontend/css/general.css @@ -104,7 +104,7 @@ hr { .pointer { cursor: pointer; } -<?php if ($conf['debug']) { ?> +<?php if ($S['conf']['debug']) { ?> html { margin-bottom: 2em; } diff --git a/frontend/functions/onshutdown.php b/frontend/functions/onshutdown.php index 60c2cb4..f144275 100644 --- a/frontend/functions/onshutdown.php +++ b/frontend/functions/onshutdown.php @@ -1,17 +1,17 @@ <?php function onshutdown($footerloc, $headerloc) { - global $S, $request, $conf, $death; + global $S; if (isset($S) && is_array($S) && !$S['notemplates']) { require_once($headerloc); - if ($death) { - echo $death; + if ($S['death']) { + echo $S['death']; } require_once($footerloc); - } elseif (isset($conf) && isset($S) && is_array($S) && isset($request) && isset($request['ajax'])) { - if (isset($death)) { - echo '<death_message>'.$death.'</death_message>'; + } elseif (isset($S['conf']) && isset($S) && is_array($S) && isset($_REQUEST) && isset($_REQUEST['ajax'])) { + if (isset($S['death'])) { + echo '<death_message>'.$S['death'].'</death_message>'; } - if ($conf['debug']) { + if ($S['conf']['debug']) { foreach ($S['debug'] as $row) { list($type, $text)=$row; echo '<debug>'; diff --git a/frontend/functions/r_stripslashes.php b/frontend/functions/r_stripslashes.php index 8d6dccb..a0679f0 100644 --- a/frontend/functions/r_stripslashes.php +++ b/frontend/functions/r_stripslashes.php @@ -3,11 +3,10 @@ function r_stripslashes(&$array) { debug('r_stripslashes', print_r($array, true)); foreach ($array as $key => $value) { if (is_array($value)) { - $array[$key]=r_stripslashes($value); + r_stripslashes($value); } elseif (is_string($value)) { $array[$key]=stripslashes($value); } } - return $array; } ?> diff --git a/frontend/include/error_handling.php b/frontend/include/error_handling.php index 82f6122..5f616ee 100644 --- a/frontend/include/error_handling.php +++ b/frontend/include/error_handling.php @@ -1,12 +1,12 @@ <?php function exception_handler($e) { - global $death; + global $S; $trace=array(); foreach ($e->getTrace() as $t) { $trace[]='<b>'.$t['function'].'</b>(<b>'.htmlentities(implode(', ', $t['args'])).'</b>) at <b>'.$t['file'].'</b> line <b>'.$t['line'].'</b><br/>'; } $trace=implode(' from<br/>', $trace); - $death.=print_error('Uncaught '.get_class($e).': '.$e->getMessage(), 'Thrown at:<br/>'.$trace); + $S['death'].=print_error('Uncaught '.get_class($e).': '.$e->getMessage(), 'Thrown at:<br/>'.$trace); } set_exception_handler('exception_handler'); // Directly copied from PHP Manual -> Language Reference -> Predefined Exceptions -> ErrorException @@ -14,7 +14,7 @@ function exception_error_handler($errno, $errstr, $errfile, $errline ) { if ((error_reporting() & $errno) == 0) { // Don't report errors that aren't supposed to be reported return; } - global $death; + global $S; $errtypes=array( E_ERROR => 'Fatal Error', E_WARNING => 'Warning', @@ -54,7 +54,7 @@ function exception_error_handler($errno, $errstr, $errfile, $errline ) { } $trace.='from <b>'.(isset($t['function'])?(isset($t['class'])?$t['class'].$t['type']:'').$t['function'].'</b>'.(isset($t['args'])?'(<b>'.htmlentities(implode(', ', $t['args'])).'</b>)':''):(isset($t['args'])?'Included file(s) '.implode(', ', $t['args']):'')).(isset($t['file'])?' at <b>'.$t['file'].'</b>'.(isset($t['line'])?' line <b>'.$t['line'].'</b>':''):'').'<br/>'; } - $death.=print_error($type, $errstr.'<br/>'.$trace); + $S['death'].=print_error($type, $errstr.'<br/>'.$trace); } set_error_handler("exception_error_handler"); ?> diff --git a/frontend/include/footer.php b/frontend/include/footer.php index 96ba9b9..9b42bcc 100644 --- a/frontend/include/footer.php +++ b/frontend/include/footer.php @@ -1,19 +1,19 @@ </div><div id="bottom" class="box"> <?php -global $conf, $S; +global $S; if (isset($S['start'])) { $diff=round(microtime(true)-$S['start'], 3); echo 'Execution took '.$diff.' seconds.<br/>'."\n"; } echo /*'© Eitan Mosenkis '.date('Y').*/'</div>'; -if ($conf['debug']) { +if ($S['conf']['debug']) { echo '<br/><div id="debug"><div class="heading" onclick="toggledebugbox()">Debug (<span id="debugcount">'.$S['debugrow'].'</span>) <span id="debugactions">[<a href="javascript:cleardebug()" id="debugclear">Clear</a>] [<a href="javascript:closedebug()" id="debugclose">X</a>]</span></div><div id="debugbox">'./*$state->debug.*/'</div></div>'."\n"; echo '<script type="text/javascript"> <!-- toggledebugbox();'."\n"; foreach ($S['debug'] as $row) { list($type, $text)=$row; - $text=str_replace(array('"', "\r", "\n", "\t"), array('\"', '\\r', '\\n', '\\t'), $text); + $text=str_replace(array('\\', '"', "\r", "\n", "\t"), array('\\\\', '\"', '\\r', '\\n', '\\t'), $text); // $text used to have htmlentities() run on it, but that killed the SQL output tables if ($type == null) { echo 'debug("'.$text.'");'."\n"; diff --git a/frontend/include/header.php b/frontend/include/header.php index c11c480..6e57d43 100644 --- a/frontend/include/header.php +++ b/frontend/include/header.php @@ -9,11 +9,11 @@ echo xmlheader(); <link rel="shortcut icon" href="<?php echo url('images/favicon.ico'); ?>" /> <link rel="icon" href="<?php echo url('images/favicon.png'); ?>" type="image/gif" /> <title><?php -echo ($S['title'] != null?$S['title'].' | ':'').$conf['title']; +echo ($S['title'] != null?$S['title'].' | ':'').$S['conf']['title']; ?></title> <?php $scripts=array('GetXmlHttpObject', 'url', 'ajax'); -if ($conf['debug']) { +if ($S['conf']['debug']) { array_unshift($scripts, 'debug'); } foreach (array_merge($S['scripts'], $scripts) as $script) { @@ -40,9 +40,9 @@ echo '<li><a href="'.url('create').'">New configuration</a></li>'; echo '<li><a href="'.url('configurations').'">My configurations</a></li>'; echo '<li><a href="'.url('builds').'">My builds</a></li>'; if (isset($S['user'])) { - if ($conf['invite'] && ($S['user']->has_flag('a') || $conf['invite'] != 'admin')) + if ($S['conf']['invite'] && ($S['user']->has_flag('a') || $S['conf']['invite'] != 'admin')) echo '<li><a href="'.url('invite').'">Invite</a></li>'; -} elseif ($conf['registration']) +} elseif ($S['conf']['registration']) echo '<li><a href="'.url('register').'">Register</a>'; ?> </ul> @@ -54,7 +54,7 @@ if (isset($S['user'])) { $links['logout'.(strlen($S['request'])?'/'.$S['request']:'')]='Logout'; } else { $links['login'.(strlen($S['request'])?'/'.$S['request']:'')]='Login'; - if ($conf['registration']) $links['register']='Register'; + if ($S['conf']['registration']) $links['register']='Register'; } foreach ($links as $url => $text) { $links[$url]='<a href="'.url($url).'">'.htmlentities($text).'</a>'; @@ -64,8 +64,8 @@ if (isset($S['user'])) { </div> <div id="main" class="box"> <?php - if (isset($death)) { - echo $death; - $death=''; + if (isset($S['death'])) { + echo $S['death']; + $S['death']=''; } ?> diff --git a/frontend/include/setup.php b/frontend/include/setup.php index 2239c6c..825d759 100644 --- a/frontend/include/setup.php +++ b/frontend/include/setup.php @@ -3,6 +3,7 @@ if (!isset($S)) { $S=array(); } $S=array_merge($S, array( + 'death' => '', 'request' => $_GET['req'], 'notemplates' => false, 'title' => null, @@ -17,17 +18,17 @@ $S=array_merge($S, array( 'sql' => null )); unset($_REQUEST['req'], $_GET['req']); -$S['cookie_dir']=substr($conf['url'], strpos($conf['url'], '/', 8)).'/'; +$S['cookie_dir']=substr($S['conf']['url'], strpos($S['conf']['url'], '/', 8)).'/'; require_once(SHARED.'/include/dbinit.php'); -if (isset($_COOKIE[$conf['cookiename']])) { - $cookie=$_COOKIE[$conf['cookiename']]; - debug('session', 'cookie received '.$conf['cookiename'].'='.htmlentities($cookie)); +if (isset($_COOKIE[$S['conf']['cookiename']])) { + $cookie=$_COOKIE[$S['conf']['cookiename']]; + debug('session', 'cookie received '.$S['conf']['cookiename'].'='.htmlentities($cookie)); if (preg_match('/[a-z0-9]{30}/', $cookie)) { - $r=$S['pdo']->query('SELECT * FROM `sessions` WHERE `id`="'.$cookie.'"'); + $r=query('SELECT * FROM `sessions` WHERE `id`="'.$cookie.'"'); if ($r->rowCount()) { $S['session']=new sql_session($r->fetch(PDO::FETCH_ASSOC)); if ($S['session']->atime+$S['session']->expire < time()) { - setcookie($conf['cookiename'], '', 1, $S['cookie_dir'], '', false, true); + setcookie($S['conf']['cookiename'], '', 1, $S['cookie_dir'], '', false, true); $S['sesion']->delete(); unset($S['session']); } else { @@ -35,11 +36,11 @@ if (isset($_COOKIE[$conf['cookiename']])) { $S['session']->write(); $S['user']=new sql_user($S['session']->user); debug('session', 'sessionid='.$S['session']->id.', email='.$S['user']->email); - setcookie($conf['cookiename'], $S['session']->id, time()+$conf['sessionlength'], $S['cookie_dir'], '', false, true); + setcookie($S['conf']['cookiename'], $S['session']->id, time()+$S['conf']['sessionlength'], $S['cookie_dir'], '', false, true); } } else { debug('session', 'session not found'); - setcookie($conf['cookiename'], '', 1, $S['cookie_dir'], '', false, true); + setcookie($S['conf']['cookiename'], '', 1, $S['cookie_dir'], '', false, true); } } else { debug('session', 'session id invalid'); diff --git a/frontend/index.php b/frontend/index.php index a103dd9..1c1ea7d 100644 --- a/frontend/index.php +++ b/frontend/index.php @@ -1,12 +1,11 @@ <?php define('E_DEFAULT', error_reporting(E_ALL|E_STRICT)); -date_default_timezone_set('UTC'); require_once('../shared/include/includes.php'); require_once('include/error_handling.php'); +register_shutdown_function('onshutdown', realpath('include/footer.php'), realpath('include/header.php')); // Needed to ensure that errors are printed require_once('include/constants.php'); require_once('include/setup.php'); -register_shutdown_function('onshutdown', realpath('include/footer.php'), realpath('include/header.php')); -$request=get_magic_quotes_gpc()?r_stripslashes($_REQUEST):$_REQUEST; +if (get_magic_quotes_gpc()) r_stripslashes($_REQUEST); $routing=fopen('routing.csv', 'r'); for ($line=fgets($routing, 32768); !feof($routing); $line=fgets($routing, 32768)) { $line=trim($line, "\r\n"); @@ -28,12 +27,12 @@ for ($line=fgets($routing, 32768); !feof($routing); $line=fgets($routing, 32768) fclose($routing); for ($i=0; $i < count($vars); $i++) { if (strpos($vars[$i],'=')) { - $request[substr($vars[$i],0,strpos($vars[$i],'='))]=substr($vars[$i],strpos($vars[$i],'=')+1); + $_REQUEST[substr($vars[$i],0,strpos($vars[$i],'='))]=substr($vars[$i],strpos($vars[$i],'=')+1); } else { if ($i+1 > count($matches)-1) { debug('routing',print_error('Routing failure','Trying to set request variable "'.$vars[$i].'" but ran out of matches (page='.$dest.')')); } else { - $request[$vars[$i]]=$matches[$i+1]; + $_REQUEST[$vars[$i]]=$matches[$i+1]; } } } @@ -46,7 +45,7 @@ for ($line=fgets($routing, 32768); !feof($routing); $line=fgets($routing, 32768) $dest=str_replace(array('/', '-'), '_', $dest); $initfunc='init_'.$dest; if (function_exists($initfunc)) { - $value=$initfunc(); + $value=$initfunc($S); if ($value === null) { break; } elseif (is_array($value)) { @@ -73,7 +72,7 @@ for ($line=fgets($routing, 32768); !feof($routing); $line=fgets($routing, 32768) } $bodyfunc='body_'.str_replace('/','_',$dest); if (function_exists($bodyfunc)) { - $bodyresult=$bodyfunc(); + $bodyresult=$bodyfunc($S); if ($bodyresult !== null) { require($bodyresult); } diff --git a/frontend/js/ajax.js.php b/frontend/js/ajax.js.php index b34af86..d2bb137 100644 --- a/frontend/js/ajax.js.php +++ b/frontend/js/ajax.js.php @@ -26,7 +26,7 @@ function makepostdata(data) { function doajaxrequest(page,data,callback) { requestnum=ajaxrequestnum++; content=makepostdata(data); -<?php if ($conf['debug']) { ?> +<?php if ($S['conf']['debug']) { ?> debug('ajax:'+requestnum,'Sending to '+url(page)+':<br/>'+content); <?php } ?> httpobj=GetXmlHttpObject(); @@ -38,7 +38,7 @@ function doajaxrequest(page,data,callback) { if (this.readyState==4 || this.readyState=="complete") { if (this.responseXML != null && this.responseXML.documentElement.nodeName==page.replace('/','')+'response') { xml=this.responseXML.documentElement; - <?php if ($conf['debug']) { ?> + <?php if ($S['conf']['debug']) { ?> debug('ajax:'+requestnum, 'Got response:<br/><pre>'+this.responseText.replace(/</g, '<').replace(/>/g, '>')+'</pre>'); if (debugenabled) { for (var i=0; i<xml.getElementsByTagName('debug').length; i++) { @@ -54,7 +54,7 @@ function doajaxrequest(page,data,callback) { } <?php } ?> callback(xml); - <?php if ($conf['debug']) { ?> + <?php if ($S['conf']['debug']) { ?> } else { if (this.responseText.length == 0) { debug('ajax'+requestnum, 'zero-length response received'); @@ -81,12 +81,12 @@ function XMLtoHTML(xml, notrecursive) { html.className=attr.value; } else if (attr.name.match(/^on/)) { var handlerfunc=new Function('event', attr.value); - <?php if ($conf['debug']) { ?> + <?php if ($S['conf']['debug']) { ?> debug('XMLtoHTML', 'setting '+xml.nodeName+(xml.id?'#'+xml.id:'')+'.'+attr.name+':'+"\r\n"+handlerfunc); <?php } ?> html[attr.name]=handlerfunc; } else { - <?php if ($conf['debug']) { ?> + <?php if ($S['conf']['debug']) { ?> debug('XMLtoHTML', 'setting '+xml.nodeName+(xml.attributes.getNamedItem('id')?'#'+xml.attributes.getNamedItem('id').value:'')+'.'+attr.name+'='+attr.value); <?php } ?> html.setAttribute(attr.name, attr.value); diff --git a/frontend/js/debug.js.php b/frontend/js/debug.js.php index cc28959..39b9681 100644 --- a/frontend/js/debug.js.php +++ b/frontend/js/debug.js.php @@ -1,5 +1,5 @@ <?php // vim:filetype=javascript -if ($conf['debug']) { ?> +if ($S['conf']['debug']) { ?> var debugrow=0; var debugenabled=1; var debug_queue=[]; diff --git a/frontend/js/url.js.php b/frontend/js/url.js.php index a1b2b93..18dacc8 100644 --- a/frontend/js/url.js.php +++ b/frontend/js/url.js.php @@ -1,5 +1,5 @@ <?php // vim:filetype=javascript // Equivalent to php function of the same name ?> function url (relative) { - return "<?php echo $conf['url'] ?>/"+relative; + return "<?php echo $S['conf']['url'] ?>/"+relative; } diff --git a/frontend/modules/gentoo/step1.php b/frontend/modules/gentoo/step1.php index 297f7c0..67ebd71 100644 --- a/frontend/modules/gentoo/step1.php +++ b/frontend/modules/gentoo/step1.php @@ -1,6 +1,6 @@ <?php $opts=array(); -$r=$this->query('SELECT * FROM `gentoo_profiles` WHERE `flags` NOT LIKE "%d%"'); +$r=query('SELECT * FROM `gentoo_profiles` WHERE `flags` NOT LIKE "%d%"'); while ($profile=$r->fetch(PDO::FETCH_ASSOC)) { $profile=new sql_gentoo_profile($profile); $display=$profile->name?$profile->name:($profile->pkgdir?$profile->pkgdir:'/'); diff --git a/frontend/modules/gentoo/step2.php b/frontend/modules/gentoo/step2.php index 8eed939..1800255 100644 --- a/frontend/modules/gentoo/step2.php +++ b/frontend/modules/gentoo/step2.php @@ -4,7 +4,7 @@ $profile=new sql_gentoo_profile($this->get_opt('profile')); $this->checkbox_array('options', 'options', 'Configuration options', array('timezone' => 'Select timezone', 'dev-manager' => 'Select /dev manager', 'pruneinit' => 'Remove enabled-by-default init scripts')); $this->select('basesystem', 'basesystem', 'Base system', array('stage3' => 'Stage3 Tarball', 'autoprune' => 'Remove all non-vital packages', 'manual' => 'Manually select packages to remove from stage3')); $pkgsets=array(); -$r=$S['pdo']->query('SELECT * FROM `gentoo_pkgsets` WHERE `profile`='.$profile->id); +$r=query('SELECT * FROM `gentoo_pkgsets` WHERE `profile`='.$profile->id); while ($pkgset=$r->fetch(PDO::FETCH_ASSOC)) { $pkgset=new sql_gentoo_pkgset($pkgset); $pkgsets[$pkgset->id]=$pkgset->name; diff --git a/frontend/modules/gentoo/step3.php b/frontend/modules/gentoo/step3.php index dd2d72c..7074049 100644 --- a/frontend/modules/gentoo/step3.php +++ b/frontend/modules/gentoo/step3.php @@ -20,7 +20,7 @@ if (strlen($pkgsets=$this->get_opt('pkgsets'))) { } } if (in_array('pruneinit', $opts)) { - $r=$S['pdo']->query('SELECT * FROM `gentoo_baseinit` WHERE `profile`='.$profile->id.' ORDER BY `name`, `runlevel`'); + $r=query('SELECT * FROM `gentoo_baseinit` WHERE `profile`='.$profile->id.' ORDER BY `name`, `runlevel`'); $scripts=array(); while ($script=$r->fetch(PDO::FETCH_ASSOC)) { $script=new sql_gentoo_baseinit($script); @@ -29,7 +29,7 @@ if (in_array('pruneinit', $opts)) { $this->checkbox_array('pruneinit', 'pruneinit', 'Remove the following init scripts', $scripts); } if ($this->get_opt('basesystem') == 'manual') { - $r=$S['pdo']->query('SELECT * FROM `gentoo_basepkgs` WHERE `profile`='.$profile->id.' ORDER BY `pkg`'); + $r=query('SELECT * FROM `gentoo_basepkgs` WHERE `profile`='.$profile->id.' ORDER BY `pkg`'); $pkgs=array(); while ($pkg=$r->fetch(PDO::FETCH_ASSOC)) { $pkg=$pkg['pkg']; diff --git a/frontend/modules/gentoo_catalyst.info.alpha b/frontend/modules/gentoo_catalyst.info.alpha deleted file mode 100644 index 4803759..0000000 --- a/frontend/modules/gentoo_catalyst.info.alpha +++ /dev/null @@ -1,4 +0,0 @@ -<?php -$name='Gentoo Catalyst'; -require(dirname(__FILE__).'/gentoo_common.php'); -?> diff --git a/frontend/pages/404.php b/frontend/pages/404.php index ffc3b79..fc614c5 100644 --- a/frontend/pages/404.php +++ b/frontend/pages/404.php @@ -3,8 +3,7 @@ function init_404() { header('HTTP/1.0 404 Not Found', true, 404); return array('title' => '404: Not Found'); } -function body_404() { - global $S, $conf; - echo print_error('Page Not Found!','The page you are trying to reach, <i>'.$conf['url'].'/'.$S['request'].'</i> does not exist.'); +function body_404(&$S) { + echo print_error('Page Not Found!','The page you are trying to reach, <i>'.$S['conf']['url'].'/'.$S['request'].'</i> does not exist.'); } ?> diff --git a/frontend/pages/builds/delete.php b/frontend/pages/builds/delete.php index cf6c6d4..51aa9cf 100644 --- a/frontend/pages/builds/delete.php +++ b/frontend/pages/builds/delete.php @@ -1,16 +1,14 @@ <?php -function init_builds_delete() { - global $S, $request; +function init_builds_delete(&$S) { if (!isset($S['user'])) return 'login'; - if (!(isset($request['build']) && strlen($request['build']) == 6 && ctype_alnum($request['build']))) return '404'; - $r=$S['pdo']->query('SELECT * FROM `builds` WHERE `id`="'.$request['build'].'"'); + if (!(isset($_REQUEST['build']) && strlen($_REQUEST['build']) == 6 && ctype_alnum($_REQUEST['build']))) return '404'; + $r=query('SELECT * FROM `builds` WHERE `id`="'.$_REQUEST['build'].'"'); if ($r->rowCount() == 0) return '404'; $S['build']=new sql_build($r->fetch(PDO::FETCH_ASSOC)); if (!owner_or_admin($S['build']->id)) return '404'; return array('title' => 'Delete Build'); } -function body_builds_delete() { - global $S; +function body_builds_delete(&$S) { if ($S['build']->status >= 0 || $S['build']->status == -128) { $S['build']->delete(); echo print_success('Build deleted.'); diff --git a/frontend/pages/builds/download.php b/frontend/pages/builds/download.php index c40606d..411efbf 100644 --- a/frontend/pages/builds/download.php +++ b/frontend/pages/builds/download.php @@ -1,14 +1,13 @@ <?php -function init_builds_download() { - global $S, $request; +function init_builds_download(&$S) { if (!isset($S['user'])) { return 'login'; } - if (!(isset($request['build']) && strlen($request['build']) == 6 && ctype_alnum($request['build']))) { + if (!(isset($_REQUEST['build']) && strlen($_REQUEST['build']) == 6 && ctype_alnum($_REQUEST['build']))) { debug('builds_download', 'No build or badly formatted build requested'); return '404'; } - $r=$S['pdo']->query('SELECT * FROM `builds` WHERE `id`="'.$request['build'].'"'); + $r=query('SELECT * FROM `builds` WHERE `id`="'.$_REQUEST['build'].'"'); if ($r->rowCount() == 0) { debug('builds_download', 'build not found or not owned by user'); return '404'; @@ -41,8 +40,7 @@ function init_builds_download() { header('Content-Transfer-Encoding: binary'); header('Content-Disposition: attachment; filename="'.(isset($build->name) && strlen($build->name)?str_replace('"', '\"', $build->name):'ingenue-'.$build->id).$ext); } -function body_builds_download() { - global $S; +function body_builds_download(&$S) { readfile($S['builds_download']['file']); // Log the download to db after sending data so hopefully HEAD requests won't artificially inflate the # of dls $S['builds_download']['dl']->write(); diff --git a/frontend/pages/builds/history.php b/frontend/pages/builds/history.php index cd8e581..c9789e3 100644 --- a/frontend/pages/builds/history.php +++ b/frontend/pages/builds/history.php @@ -1,11 +1,10 @@ <?php -function init_builds_history() { - global $S, $request; +function init_builds_history(&$S) { if (!isset($S['user'])) return 'login'; - if (!(isset($request['build']) && strlen($request['build']) == 6 && ctype_alnum($request['build']))) { + if (!(isset($_REQUEST['build']) && strlen($_REQUEST['build']) == 6 && ctype_alnum($_REQUEST['build']))) { return '404'; } - $r=$S['pdo']->query('SELECT * FROM `builds` WHERE `id`="'.$request['build'].'"'); + $r=query('SELECT * FROM `builds` WHERE `id`="'.$_REQUEST['build'].'"'); if (!$r->rowCount()) return '404'; $S['builds_history']['build']=new sql_build($r->fetch(PDO::FETCH_ASSOC)); if ($S['builds_history']['build']->visibility == 'private' && !owner_or_admin($S['builds_history']['build']->id)) { @@ -13,11 +12,10 @@ function init_builds_history() { } return array('title' => 'Download History'); } -function body_builds_history() { - global $S; +function body_builds_history(&$S) { $build=&$S['builds_history']['build']; echo $build->display(); - $r=$S['pdo']->query('SELECT * FROM `downloads` WHERE `build`="'.$build->id.'" ORDER BY `time` DESC'); + $r=query('SELECT * FROM `downloads` WHERE `build`="'.$build->id.'" ORDER BY `time` DESC'); while ($download=$r->fetch(PDO::FETCH_ASSOC)) { $download=new sql_download($download); $user=$download->get_user(); diff --git a/frontend/pages/builds/index.php b/frontend/pages/builds/index.php index 4b6b7c8..adc6566 100644 --- a/frontend/pages/builds/index.php +++ b/frontend/pages/builds/index.php @@ -1,12 +1,10 @@ <?php -function init_builds_index() { - global $S; +function init_builds_index(&$S) { if (!isset($S['user'])) return 'login'; return array('title' => 'My Builds'); } -function body_builds_index() { - global $S; - $r=$S['pdo']->query('SELECT * FROM `builds` WHERE `owner`='.$S['user']->id.' ORDER BY `ctime` IS NULL ASC, `ctime` ASC, `status` DESC'); +function body_builds_index(&$S) { + $r=query('SELECT * FROM `builds` WHERE `owner`='.$S['user']->id.' ORDER BY `ctime` IS NULL ASC, `ctime` ASC, `status` DESC'); if ($r->rowCount() == 0) { echo print_warning('No builds found.'); } diff --git a/frontend/pages/builds/log.php b/frontend/pages/builds/log.php index 699887f..078b816 100644 --- a/frontend/pages/builds/log.php +++ b/frontend/pages/builds/log.php @@ -1,23 +1,21 @@ <?php -function init_builds_log() { - global $S, $request; +function init_builds_log(&$S) { $S['title']='Log Viewer'; if (!isset($S['user'])) return 'login'; - if (!(isset($request['build']) && strlen($request['build']) == 6 && ctype_alnum($request['build']))) return '404'; - $r=$S['pdo']->query('SELECT * FROM `builds` WHERE `id`="'.$request['build'].'"'); + if (!(isset($_REQUEST['build']) && strlen($_REQUEST['build']) == 6 && ctype_alnum($_REQUEST['build']))) return '404'; + $r=query('SELECT * FROM `builds` WHERE `id`="'.$_REQUEST['build'].'"'); if ($r->rowCount()) { $S['builds_log']=new sql_build($r->fetch(PDO::FETCH_ASSOC)); if ($S['builds_log']->visibility == 'private' && !owner_or_admin($S['builds_log']->owner)) return '404'; } else return '404'; - if (isset($request['task']) && is_numeric($request['task'])) + if (isset($_REQUEST['task']) && is_numeric($_REQUEST['task'])) return 'builds/task'; } -function body_builds_log() { - global $S; +function body_builds_log(&$S) { $build=&$S['builds_log']; echo $build->display(); - $r=$S['pdo']->query('SELECT * FROM `tasks` WHERE `build`="'.$build->id.'" ORDER BY `order` ASC'); + $r=query('SELECT * FROM `tasks` WHERE `build`="'.$build->id.'" ORDER BY `order` ASC'); if ($r->rowCount() == 0) { echo '<b>No tasks found.</b>'; } diff --git a/frontend/pages/builds/task.php b/frontend/pages/builds/task.php index ff3dd3f..0197372 100644 --- a/frontend/pages/builds/task.php +++ b/frontend/pages/builds/task.php @@ -1,39 +1,37 @@ <?php -function init_builds_task() { - global $S, $request; +function init_builds_task(&$S) { if (!isset($S['user'])) return 'login'; - if (!(isset($S['builds_log']) && isset($request['task']) && is_numeric($request['task']))) return 'builds/log'; - $r=$S['pdo']->query('SELECT * FROM `tasks` WHERE `build`="'.$S['builds_log']->id.'" AND `order`='.$request['task']); + if (!(isset($S['builds_log']) && isset($_REQUEST['task']) && is_numeric($_REQUEST['task']))) return 'builds/log'; + $r=query('SELECT * FROM `tasks` WHERE `build`="'.$S['builds_log']->id.'" AND `order`='.$_REQUEST['task']); if ($r->rowCount()) { $S['builds_task']=new sql_task($r->fetch(PDO::FETCH_ASSOC)); } else return '404'; } -function body_builds_task() { - global $S, $request, $conf; +function body_builds_task(&$S) { $task=&$S['builds_task']; echo '<div style="font-size: 130%">'.$task->display().'</div>'; echo '<a href="'.url("build/$task->build").'">Back</a><br/>'; - $page=isset($request['page']) && is_numeric($request['page'])?$request['page']:1; - $count=$S['pdo']->query('SELECT COUNT(*) FROM `buildlogs` WHERE `build`=\''.$task->build.'\' AND `task`='.$task->order)->fetch(PDO::FETCH_COLUMN); + $page=isset($_REQUEST['page']) && is_numeric($_REQUEST['page'])?$_REQUEST['page']:1; + $count=query('SELECT COUNT(*) FROM `buildlogs` WHERE `build`=\''.$task->build.'\' AND `task`='.$task->order)->fetch(PDO::FETCH_COLUMN); $pager=''; - if ($count > $conf['logview_max']) { + if ($count > $S['conf']['logview_max']) { $pager='<form action="'.url("build/$task->build/$task->order").'" method="post" onsubmit="window.location.href=\''.url("build/$task->build/$task->order").'/\'+this.page.value; return false">Page: '; if ($page > 1) { $pager.='<input type="button" value="<<" onclick="this.form.page.value='.($page-1).'; this.form.onsubmit()" /> '."\n"; } $pager.='<select name="page">'; - for ($i=1; ($i-1)*$conf['logview_max']<$count; $i++) { + for ($i=1; ($i-1)*$S['conf']['logview_max']<$count; $i++) { $pager.="<option value=\"$i\"".($i==$page?'selected="selected"':'').">$i</option>\n"; } $pager.='</select> <input type="submit" value="Go" />'; - if ($page*$conf['logview_max']<$count) { + if ($page*$S['conf']['logview_max']<$count) { $pager.=' <input type="button" value=">>" onclick="this.form.page.value='.($page+1).'; this.form.onsubmit()" />'."\n"; } $pager.='</form>'; echo $pager; } - $r=$S['pdo']->query('SELECT * FROM `buildlogs` WHERE `build`=\''.$task->build.'\' AND `task`='.$task->order.' ORDER BY `order` ASC LIMIT '.$conf['logview_max'].' OFFSET '.($page-1)*$conf['logview_max']); + $r=query('SELECT * FROM `buildlogs` WHERE `build`=\''.$task->build.'\' AND `task`='.$task->order.' ORDER BY `order` ASC LIMIT '.$S['conf']['logview_max'].' OFFSET '.($page-1)*$S['conf']['logview_max']); if ($r->rowCount()) { echo '<div style="font-family: monospace">'; $ansi=new ansi_to_html(); diff --git a/frontend/pages/configurations/manager.php b/frontend/pages/configurations/manager.php index dfd8322..6396aaa 100644 --- a/frontend/pages/configurations/manager.php +++ b/frontend/pages/configurations/manager.php @@ -1,20 +1,18 @@ <?php -function init_configurations_manager() { - global $S; +function init_configurations_manager(&$S) { if (!isset($S['user'])) { return 'login'; } return array('title' => 'Manage Configurations'); } -function body_configurations_manager() { - global $S, $request, $conf; +function body_configurations_manager(&$S) { echo '<h3>Configurations Manager</h3>'; - if (isset($request['build']) && isset($request['configuration'])) { - $c=new sql_configuration($request['configuration']); + if (isset($_REQUEST['build']) && isset($_REQUEST['configuration'])) { + $c=new sql_configuration($_REQUEST['configuration']); if ($c->owner!=$S['user']->id) { echo print_error('You do not have permission to build this configuration.'); } else { - $name=isset($request['name'])?$request['name']:null; + $name=isset($_REQUEST['name'])?$_REQUEST['name']:null; $build=$c->build($name); if (is_object($build)) echo print_success('Submitted for build - <a href="'.url("build/$build->id").'">Logs</a>'); @@ -22,12 +20,12 @@ function body_configurations_manager() { echo print_error('Invalid configuration', 'Your configuration could not be submitted for build. Please return to <a href="'.url("config/$c->id/$build").'">step '.$build.'</a> and continue configuration from there.'); } } - $r=$S['pdo']->query('SELECT * FROM `configurations` WHERE `owner`='.$S['user']->id); + $r=query('SELECT * FROM `configurations` WHERE `owner`='.$S['user']->id); if ($r->rowCount() == 0) { echo print_warning('You have no configurations.').'<a href="'.url('create').'">Create a configuration</a>'; return; } - echo '<form action="'.url('configurations').'" method="post"><table><tr><th>ID</th><th>Name</th>'.(count($conf['modules']) > 1?'<th>Module</th>':'').'<th>Status</th><th>Options</th><th>Builds</th></tr>'."\n"; + echo '<form action="'.url('configurations').'" method="post"><table><tr><th>ID</th><th>Name</th>'.(count($S['conf']['modules']) > 1?'<th>Module</th>':'').'<th>Status</th><th>Options</th><th>Builds</th></tr>'."\n"; $ready=0; while($c=$r->fetch(PDO::FETCH_ASSOC)) { $c=new sql_configuration($c); @@ -39,7 +37,7 @@ function body_configurations_manager() { echo $c->id; } echo '</td><td>'.(isset($c->name) && strlen($c->name)?htmlentities($c->name):'<i>Unnamed</i>').'</td><td>'; - if (count($conf['modules']) > 1) { + if (count($S['conf']['modules']) > 1) { echo "$c->module</td><td>"; } if ($c->status > 0) { diff --git a/frontend/pages/configurations/status.php b/frontend/pages/configurations/status.php index d27efd4..f0ba8d5 100644 --- a/frontend/pages/configurations/status.php +++ b/frontend/pages/configurations/status.php @@ -1,13 +1,12 @@ <?php -function init_configurations_status() { - global $S, $request; +function init_configurations_status(&$S) { if (!isset($S['user'])) { return 'login'; } - if (!(isset($request['configuration']) && strlen($request['configuration']) == 6 && ctype_alnum($request['configuration']))) { + if (!(isset($_REQUEST['configuration']) && strlen($_REQUEST['configuration']) == 6 && ctype_alnum($_REQUEST['configuration']))) { return '404'; } - $r=$S['pdo']->query('SELECT * FROM `configurations` WHERE `id`=\''.$request['configuration'].'\''); + $r=query('SELECT * FROM `configurations` WHERE `id`=\''.$_REQUEST['configuration'].'\''); if ($r->rowCount() == 0) { return '404'; } @@ -17,8 +16,7 @@ function init_configurations_status() { } return array('title' => 'Status'); } -function body_configurations_status() { - global $S; +function body_configurations_status(&$S) { $c=&$S['status']['configuration']; $module=new module($c->module); $status=true; diff --git a/frontend/pages/configurations/wizard.php b/frontend/pages/configurations/wizard.php index 947e321..33b9949 100644 --- a/frontend/pages/configurations/wizard.php +++ b/frontend/pages/configurations/wizard.php @@ -1,17 +1,16 @@ <?php -function init_configurations_wizard() { - global $S, $request, $conf; +function init_configurations_wizard(&$S) { if (!isset($S['user'])) { return 'login'; } - if (isset($request['configuration']) && strlen($request['configuration']) == 6 && ctype_alnum($request['configuration'])) { - $S['wizard']['configuration']=new sql_configuration($request['configuration']); + if (isset($_REQUEST['configuration']) && strlen($_REQUEST['configuration']) == 6 && ctype_alnum($_REQUEST['configuration'])) { + $S['wizard']['configuration']=new sql_configuration($_REQUEST['configuration']); $configuration=&$S['wizard']['configuration']; if ($configuration->owner != $S['user']->id) { return '404'; } - if (isset($request['wizard_submit'])) { - $steps=array_keys($request['wizard_submit']); + if (isset($_REQUEST['wizard_submit'])) { + $steps=array_keys($_REQUEST['wizard_submit']); $step=$steps[0]; wizard_load_step($step); debug('wizard', "processing $configuration->module step $step"); @@ -28,16 +27,17 @@ function init_configurations_wizard() { $configuration->write(); wizard_load_step($result); } - } elseif (isset($request['step']) && ctype_alnum($request['step'])) { - wizard_load_step($request['step']); + } elseif (isset($_REQUEST['step']) && ctype_alnum($_REQUEST['step'])) { + wizard_load_step($_REQUEST['step']); } elseif ($configuration->status > 0) { wizard_load_step($configuration->status); } - } elseif (isset($request['init'])) { + } elseif (isset($_REQUEST['init'])) { $S['wizard']['configuration']=new sql_configuration(); $configuration=&$S['wizard']['configuration']; - $configuration->name=$request['name']; - $mod=isset($request['mod']) && isset($conf['modules'][$request['mod']])?$conf['modules'][$request['mod']]:$conf['modules'][0]; + $configuration->name=$_REQUEST['name']; + $configuration->visibility='public'; + $mod=isset($_REQUEST['mod']) && isset($S['conf']['modules'][$_REQUEST['mod']])?$S['conf']['modules'][$_REQUEST['mod']]:$S['conf']['modules'][0]; $configuration->module=$mod; $configuration->init(); debug('wizard', "Module: $mod"); @@ -49,8 +49,7 @@ function init_configurations_wizard() { return array('title' => 'Create'); } } -function body_configurations_wizard() { - global $S, $conf; +function body_configurations_wizard(&$S) { if (isset($S['wizard']['configuration'])) { $configuration=&$S['wizard']['configuration']; if (isset($S['wizard']['step'])) @@ -59,10 +58,10 @@ function body_configurations_wizard() { echo print_success('Config finished!', '<form action="'.url('configurations').'" method="post"><input type="hidden" name="configuration" value="'.$configuration->id.'" />Name (optional): <input name="name" value="'.($configuration->name?htmlentities($configuration->name):'').'" /> <input type="submit" name="build" value="Build" /></form>'); } else { echo '<form action="'.url('create').'" method="post"><h3>Request an image built</h3>Name of your configuration (optional): <input name="name" /><br/>'; - if (count($conf['modules']) > 1) { + if (count($S['conf']['modules']) > 1) { echo 'Module: <select name="mod">'; $i=0; - foreach ($conf['modules'] as $mod) { + foreach ($S['conf']['modules'] as $mod) { $mod=new module($mod); echo '<option value="'.$i++.'">'.htmlentities($mod->name).'</option>'; } diff --git a/frontend/pages/invite.php b/frontend/pages/invite.php index 69047ab..8603906 100644 --- a/frontend/pages/invite.php +++ b/frontend/pages/invite.php @@ -1,16 +1,14 @@ <?php -function init_invite() { - global $S, $conf; - if (!$conf['invite']) return '404'; +function init_invite(&$S) { + if (!$S['conf']['invite']) return '404'; if (!isset($S['user'])) return 'login'; - if ($conf['invite'] == 'admin' && !$S['user']->has_flag('a')) return '404'; + if ($S['conf']['invite'] == 'admin' && !$S['user']->has_flag('a')) return '404'; return array('title' => 'Invite'); } -function body_invite() { - global $S, $request, $conf; - if (isset($request['emails'])) { +function body_invite(&$S) { + if (isset($_REQUEST['emails'])) { echo '<h3>Inviting Users</h3>'; - $emails=explode("\n", $request['emails']); + $emails=explode("\n", $_REQUEST['emails']); foreach ($emails as $email) { // TODO proper checking that user and registrationtoken don't exist for this email to avoid errors $email=trim($email); @@ -26,7 +24,7 @@ function body_invite() { $token->expire=time()+24*3600; // 24 hour shelf life (we're not checking currently) $token->owner=$S['user']->id; $token->write(); - xhtmlemail($email, null, $conf['title'].' invitation', htmlentities($S['user']->name).' has invited you to create an account for '.$conf['title'].'. To create an account, click this link: <a href="'.url('register/'.$token->id).'">'.url('register/'.$token->id).'</a>'); + xhtmlemail($email, null, $S['conf']['title'].' invitation', htmlentities($S['user']->name).' has invited you to create an account for '.$S['conf']['title'].'. To create an account, click this link: <a href="'.url('register/'.$token->id).'">'.url('register/'.$token->id).'</a>'); echo 'Invited '.htmlentities($email).'<br/>'; } echo '<a href="'.url('invite').'">Send more invitations</a>'; diff --git a/frontend/pages/login.php b/frontend/pages/login.php index 13eeb0a..953d2c4 100644 --- a/frontend/pages/login.php +++ b/frontend/pages/login.php @@ -1,12 +1,11 @@ <?php -function init_login() { - global $S, $request, $conf; +function init_login(&$S) { if (isset($S['user'])) { - // Should we let you continue to $request['go'] instead? + // Should we let you continue to $_REQUEST['go'] instead? return 'welcome'; } else { - if (isset($request['email']) && isset($request['password'])) { - $r=$S['pdo']->query('SELECT * FROM `users` WHERE `email`='.$S['pdo']->quote($request['email']).' AND `passhash`="'.sha1($request['password']).'"'); + if (isset($_REQUEST['email']) && isset($_REQUEST['password'])) { + $r=query('SELECT * FROM `users` WHERE `email`='.$S['pdo']->quote($_REQUEST['email']).' AND `passhash`="'.sha1($_REQUEST['password']).'"'); if ($r->rowCount()) { $S['user']=new sql_user($r->fetch(PDO::FETCH_ASSOC)); $S['login.result']=sql_session::create(); @@ -17,10 +16,9 @@ function init_login() { return array('title' => 'Login'); } } -function body_login() { - global $request, $S; +function body_login(&$S) { if (substr($S['request'], 0, 5) != 'login') { - $request['go']=$S['request']; + $_REQUEST['go']=$S['request']; echo print_warning('Please sign in to access this page.'); } if (isset($S['login.result'])) { @@ -28,15 +26,15 @@ function body_login() { echo print_error('An error occurred while signing you in.'); } elseif ($S['login.result']) { echo print_success('Welcome, '.$S['user']->name); - echo '<a href="'.url(isset($request['go'])?$request['go']:'').'">Continue</a>'; + echo '<a href="'.url(isset($_REQUEST['go'])?$_REQUEST['go']:'').'">Continue</a>'; die; } else { echo print_error('Your email and password combination was not recognized.'); } } echo '<h3>Login</h3><form action="'.url('login').'" method="post">'; - if (isset($request['go'])) { - echo '<input type="hidden" name="go" value="'.htmlentities($request['go']).'" />'; + if (isset($_REQUEST['go'])) { + echo '<input type="hidden" name="go" value="'.htmlentities($_REQUEST['go']).'" />'; } echo 'Email: <input name="email" /><br/>Password: <input type="password" name="password" /><br/><input type="submit" value="Submit" /></form>'; } diff --git a/frontend/pages/logout.php b/frontend/pages/logout.php index 6eccd3d..71f8c11 100644 --- a/frontend/pages/logout.php +++ b/frontend/pages/logout.php @@ -1,12 +1,11 @@ <?php -function init_logout() { - global $S, $conf, $request; +function init_logout(&$S) { if (isset($S['session'])) { $S['session']->delete(); } - setcookie($conf['cookiename'], '', 1, $S['cookie_dir'], '', false, true); - if (isset($request['go'])) { - header('Location: '.url($request['go'])); + setcookie($S['conf']['cookiename'], '', 1, $S['cookie_dir'], '', false, true); + if (isset($_REQUEST['go'])) { + header('Location: '.url($_REQUEST['go'])); } } function body_logout() { diff --git a/frontend/pages/passthrough.php b/frontend/pages/passthrough.php index e444aa2..40ee579 100644 --- a/frontend/pages/passthrough.php +++ b/frontend/pages/passthrough.php @@ -1,11 +1,10 @@ <?php -function init_passthrough() { - global $S, $request; - if (strpos('../',$request['dir'].'/'.$request['file']) !== false || !file_exists($request['dir'].'/'.$request['file']) && !file_exists($request['dir'].'/'.$request['file'].'.php')) { - debug('passthrough','File not found '.$request['dir'].'/'.$request['file']); +function init_passthrough(&$S) { + if (strpos('../',$_REQUEST['dir'].'/'.$_REQUEST['file']) !== false || !file_exists($_REQUEST['dir'].'/'.$_REQUEST['file']) && !file_exists($_REQUEST['dir'].'/'.$_REQUEST['file'].'.php')) { + debug('passthrough','File not found '.$_REQUEST['dir'].'/'.$_REQUEST['file']); return '404'; } - switch (strtolower($request['ext'])) { + switch (strtolower($_REQUEST['ext'])) { // http://www.w3schools.com/media/media_mimeref.asp case 'mp3': contenttype('audio/mpeg'); @@ -46,37 +45,36 @@ function init_passthrough() { contenttype('application/bzip2'); break; default: - debug('passthrough', 'Unknown extension '.$request['ext']); + debug('passthrough', 'Unknown extension '.$_REQUEST['ext']); return '404'; } // Set filesize if we're working with a static file (needed for normal download and streaming behavior) - if (strtolower($request['ext']) != 'php' && file_exists($request['dir'].'/'.$request['file'])) { - header('Content-Length: '.filesize($request['dir'].'/'.$request['file'])); + if (strtolower($_REQUEST['ext']) != 'php' && file_exists($_REQUEST['dir'].'/'.$_REQUEST['file'])) { + header('Content-Length: '.filesize($_REQUEST['dir'].'/'.$_REQUEST['file'])); } // Force browser to download, possibly set dynamic filename, passed by previous page or by HTTP request (taken from the PHP manual on readfile() - if (isset($request['download']) && $request['download']) { + if (isset($_REQUEST['download']) && $_REQUEST['download']) { header('Content-Description: File Transfer'); header('Content-Transfer-Encoding: binary'); - if (isset($request['download_name']) && strlen($request['download_name']) > 0) { - header('Content-Disposition: attachment; filename="'.str_replace('"','\'', $request['download_name']).'"'); + if (isset($_REQUEST['download_name']) && strlen($_REQUEST['download_name']) > 0) { + header('Content-Disposition: attachment; filename="'.str_replace('"','\'', $_REQUEST['download_name']).'"'); } else { header('Content-Disposition: attachment'); } } $S['notemplates']=true; } -function body_passthrough() { - global $request; - if (strtolower($request['ext']) == 'php') { - $_SERVER['PHP_SELF']=substr($_SERVER['PHP_SELF'],0,strlen($_SERVER['PHP_SELF'])-strlen('main.php')).$request['dir'].'/'.$request['file']; - unset($GLOBALS['S'], $GLOBALS['request'], $GLOBALS['conf']); - chdir($request['dir']); +function body_passthrough(&$S) { + if (strtolower($_REQUEST['ext']) == 'php') { + $_SERVER['PHP_SELF']=substr($_SERVER['PHP_SELF'],0,strlen($_SERVER['PHP_SELF'])-strlen('main.php')).$_REQUEST['dir'].'/'.$_REQUEST['file']; + unset($GLOBALS['S']); + chdir($_REQUEST['dir']); error_reporting(E_DEFAULT); - return $request['file']; - } elseif (file_exists($request['dir'].'/'.$request['file'])) { - readfile($request['dir'].'/'.$request['file']); + return $_REQUEST['file']; + } elseif (file_exists($_REQUEST['dir'].'/'.$_REQUEST['file'])) { + readfile($_REQUEST['dir'].'/'.$_REQUEST['file']); } else { - return $request['dir'].'/'.$request['file'].'.php'; + return $_REQUEST['dir'].'/'.$_REQUEST['file'].'.php'; } } ?> diff --git a/frontend/pages/register.php b/frontend/pages/register.php index 1f76c69..441269c 100644 --- a/frontend/pages/register.php +++ b/frontend/pages/register.php @@ -1,22 +1,21 @@ <?php -function init_register() { - global $S, $request, $conf; +function init_register(&$S) { if (isset($S['user'])) { header('Location: '.url()); return 'welcome'; } - if (isset($request['token']) && preg_match('/^[a-zA-Z0-9]{30}$/', $request['token'])) { - $r=$S['pdo']->query('SELECT * FROM `registrationtokens` WHERE `id`=\''.$request['token'].'\''); + if (isset($_REQUEST['token']) && preg_match('/^[a-zA-Z0-9]{30}$/', $_REQUEST['token'])) { + $r=query('SELECT * FROM `registrationtokens` WHERE `id`=\''.$_REQUEST['token'].'\''); if ($r->rowCount()) { $S['register.token']=new sql_registrationtoken($r->fetch(PDO::FETCH_ASSOC)); - if (isset($request['password'])) { + if (isset($_REQUEST['password'])) { $S['register.fail']=''; - if (!isset($request['name']) || !Validate::username($request['name'])) + if (!isset($_REQUEST['name']) || !Validate::username($_REQUEST['name'])) $S['register.fail'].=print_warning('The username you entered is invalid. Names must be at least two characters long and may contain alphanumeric characters, period, space, underscore, and dash.'); - if (!isset($request['password']) || strlen($request['password']) <= 4) + if (!isset($_REQUEST['password']) || strlen($_REQUEST['password']) <= 4) $S['register.fail'].=print_warning('Please enter a password at least five characters long.'); if ($S['register.fail']=='') { - $S['user']=new sql_user(null, $S['register.token']->email, $request['name'], sha1($request['password']), ''); + $S['user']=new sql_user(null, $S['register.token']->email, $_REQUEST['name'], sha1($_REQUEST['password']), ''); $S['user']->write(); $S['register.token']->delete(); unset($S['register.token']); @@ -24,38 +23,37 @@ function init_register() { } } } - } elseif (!$conf['registration']) return '404'; + } elseif (!$S['conf']['registration']) return '404'; return array('title' => 'Register'); } -function body_register() { - global $S, $request, $conf; +function body_register(&$S) { if (isset($S['user'])) echo print_success('Account creation complete.'); - elseif (isset($request['email'])) { - if (!Validate::email($request['email'])) + elseif (isset($_REQUEST['email'])) { + if (!Validate::email($_REQUEST['email'])) echo print_warning('The email address you entered is invalid.').'<a href="javascript:history.go(-1)">Back</a>'; // 5.3.0 - goto print form else { - if ($S['pdo']->query('SELECT COUNT(*) FROM `users` WHERE `email`='.$S['pdo']->quote($request['email']))->fetch(PDO::FETCH_COLUMN)) + if (query('SELECT COUNT(*) FROM `users` WHERE `email`='.$S['pdo']->quote($_REQUEST['email']))->fetch(PDO::FETCH_COLUMN)) echo print_warning('An account already exists with this email address.').'<a href="'.url('login').'">Login</a>'; else { - if ($token=$S['pdo']->query('SELECT * FROM `registrationtokens` WHERE `email`='.$S['pdo']->quote($request['email']))->fetch(PDO::FETCH_ASSOC)) { + if ($token=query('SELECT * FROM `registrationtokens` WHERE `email`='.$S['pdo']->quote($_REQUEST['email']))->fetch(PDO::FETCH_ASSOC)) { echo print_warning('A confirmation email has already been sent to this email address... sending another email.'); $token=new sql_registrationtoken($token); } else { $token=sql_registrationtoken::create(); - $token->email=$request['email']; + $token->email=$_REQUEST['email']; } $token->expire=time()+24*3600; // 24 Hours before expiration (not implemented) $token->write(); - xhtmlemail($request['email'], null, $conf['title'].' account creation', 'To complete your account registration, click this link: <a href="'.url('register/'.$token->id).'">'.url('register/'.$token->id).'</a>.'); - echo print_success('You will receive an email soon at '.htmlentities($request['email']).' with instructions to finish creating your account.'); + xhtmlemail($_REQUEST['email'], null, $S['conf']['title'].' account creation', 'To complete your account registration, click this link: <a href="'.url('register/'.$token->id).'">'.url('register/'.$token->id).'</a>.'); + echo print_success('You will receive an email soon at '.htmlentities($_REQUEST['email']).' with instructions to finish creating your account.'); } } } elseif (isset($S['register.token'])) { if (isset($S['register.fail'])) echo $S['register.fail']; - echo '<h3>Register</h3><form action="'.url('register').'" method="post"><input type="hidden" name="token" value="'.$request['token'].'" />Display name: <input name="name" /><br/>Password: <input type="password" name="password" /><br/><input type="submit" value="Create Account" /></form>'; + echo '<h3>Register</h3><form action="'.url('register').'" method="post"><input type="hidden" name="token" value="'.$_REQUEST['token'].'" />Display name: <input name="name" /><br/>Password: <input type="password" name="password" /><br/><input type="submit" value="Create Account" /></form>'; } else echo '<h3>Register</h3><form action="'.url('register').'" method="post"> E-mail: <input name="email" /><br/> diff --git a/frontend/pages/stylesheet.php b/frontend/pages/stylesheet.php index 82a7f68..58087a1 100644 --- a/frontend/pages/stylesheet.php +++ b/frontend/pages/stylesheet.php @@ -1,10 +1,8 @@ <?php function init_stylesheet() { - global $state; contenttype('text/css'); } -function body_stylesheet() { - global $conf; +function body_stylesheet(&$S) { foreach (glob('css/*.css') as $file) { require($file); } diff --git a/frontend/pages/upload.php b/frontend/pages/upload.php index 04f8036..5f71eb3 100644 --- a/frontend/pages/upload.php +++ b/frontend/pages/upload.php @@ -1,18 +1,17 @@ <?php -function init_upload() { - global $S, $request; - if (!(isset($request['build'], $request['key'], $_FILES['file']) && preg_match('/^[a-zA-Z0-9]{6}$/', $request['build']) && preg_match('/^[a-zA-Z0-9]{30}$/', $request['key']))) { +function init_upload(&$S) { + if (!(isset($_REQUEST['build'], $_REQUEST['key'], $_FILES['file']) && preg_match('/^[a-zA-Z0-9]{6}$/', $_REQUEST['build']) && preg_match('/^[a-zA-Z0-9]{30}$/', $_REQUEST['key']))) { debug('upload', 'missing or malformed input'); return '404'; } - $r=$S['pdo']->query('SELECT * FROM `builds` WHERE `id`="'.$request['build'].'"'); + $r=query('SELECT * FROM `builds` WHERE `id`="'.$_REQUEST['build'].'"'); if ($r->rowCount() == 0) { debug('upload', 'build not found'); return '404'; } $build=new sql_build($r->fetch(PDO::FETCH_ASSOC)); $opts=$build->get_opts(); - if (!(isset($opts['uploadkey']) && $opts['uploadkey'] == $request['key'])) { + if (!(isset($opts['uploadkey']) && $opts['uploadkey'] == $_REQUEST['key'])) { debug('upload', 'invalid upload key'); return '404'; } diff --git a/frontend/pages/welcome.php b/frontend/pages/welcome.php index 4b727e3..2de99a1 100644 --- a/frontend/pages/welcome.php +++ b/frontend/pages/welcome.php @@ -1,13 +1,11 @@ <?php -function init_welcome() { - global $S; +function init_welcome(&$S) { $S['title']='Welcome'; } -function body_welcome() { - global $S; +function body_welcome(&$S) { echo '<h2>Welcome</h2>'; echo '<div class="box"><h3>Most Popular Downloads</h3>'; - $r=$S['pdo']->query('SELECT `build` FROM `downloads` GROUP BY `build` ORDER BY COUNT(*) DESC LIMIT 3'); + $r=query('SELECT `build` FROM `downloads` GROUP BY `build` ORDER BY COUNT(*) DESC LIMIT 3'); if ($r->rowCount()) { while ($build=$r->fetch(PDO::FETCH_COLUMN)) { $build=new sql_build($build); @@ -18,7 +16,7 @@ function body_welcome() { } echo '</div>'; echo '<div class="box"><h3>Recently Downloaded</h3>'; - $r=$S['pdo']->query('SELECT * FROM `downloads` ORDER BY `time` DESC LIMIT 3'); + $r=query('SELECT * FROM `downloads` ORDER BY `time` DESC LIMIT 3'); if ($r->rowCount()) { while ($download=$r->fetch(PDO::FETCH_ASSOC)) { $download=new sql_download($download); @@ -29,7 +27,7 @@ function body_welcome() { } echo '</div>'; echo '<div class="box"><h3>Recently Built</h3>'; - $r=$S['pdo']->query('SELECT * FROM `builds` WHERE `status`="finished/success" ORDER BY `finish` DESC LIMIT 3'); + $r=query('SELECT * FROM `builds` WHERE `status`="finished/success" ORDER BY `finish` DESC LIMIT 3'); if ($r->rowCount()) { while ($build=$r->fetch(PDO::FETCH_ASSOC)) { $build=new sql_build($build); diff --git a/gentoo_setup.php b/gentoo_setup.php index 657aa91..29f56d6 100644 --- a/gentoo_setup.php +++ b/gentoo_setup.php @@ -1,12 +1,12 @@ <?php $profiles=array(); foreach (get_pkgdirs() as $dir) { - echo 'Creating profile for '.$conf['pkgdir_root'].'/'.$dir.'...'; + echo 'Creating profile for '.$S['conf']['pkgdir_root'].'/'.$dir.'...'; $profiles[]=new sql_gentoo_profile(); $profile=&$profiles[count($profiles)-1]; $profile->pkgdir=$dir; echo "done\n"; - echo 'Loading data from '.$conf['pkgdir_root'].'/'.$dir.'/Packages...'; + echo 'Loading data from '.$S['conf']['pkgdir_root'].'/'.$dir.'/Packages...'; $profile->read_Packages(); $profile->read_pkgsets(); echo "done\n"; diff --git a/lib/bkisofs-cli.c b/lib/bkisofs-cli.c index ee0a3a4..201d57d 100644 --- a/lib/bkisofs-cli.c +++ b/lib/bkisofs-cli.c @@ -26,8 +26,8 @@ int main( int argv, char** argc) * the functions were successful or not */ int rc; - if(argv < 5) { - puts("Usage: ingenue-bkisofs <in.iso> <out.iso> <action1> <arg1> [<arg2>] [<action2> <arg2> [etc.]]\nValid actions:\n\tadd <path> <source>\n\treplace <path> <source>\n\tdelete <path>\n\textract <path> <destination>\n\tprint\n\twrite <filename>"); + if(argv < 3) { + puts("Usage: ingenue-bkisofs <in.iso> <action1> <arg1> [<arg2>] [<action2> <arg2> [etc.]]\nValid actions:\n\tadd <path> <source>\n\treplace <path> <source>\n\tdelete <path>\n\tvolname <name>\n\tpublisher <name>\n\textract <path> <destination>\n\tprint\n\twrite <filename>"); exit(1); } @@ -95,6 +95,10 @@ int main( int argv, char** argc) rc = bk_extract_as(&volInfo, argc[i+1], argc[i+2][0]?argc[i+2]:"/", slash+1, true, NULL); } i+=2; + } else if (strcmp(argc[i], "volname") == 0) { + rc=bk_set_vol_name(&volInfo, argc[i++]); + } else if (strcmp(argc[i], "publisher") == 0) { + rc=bk_set_publisher(&volInfo, argc[i++]); } if (rc <= 0) fatalError(bk_get_error_string(rc)); diff --git a/pkglist.php b/pkglist.php index 65cbfa9..2307fe1 100755 --- a/pkglist.php +++ b/pkglist.php @@ -3,8 +3,7 @@ require_once(dirname(__FILE__).'/shared/include/includes.php'); // USE __DIR__ in 5.3.0 require_once(SHARED.'/config.php'); require_once(SHARED.'/include/dbinit.php'); -$pdo=&$S['pdo']; -$r=$pdo->query('SELECT * FROM `gentoo_profiles`'.(isset($argv[1])?' WHERE `name` LIKE "%'.$argv[1].'%" OR `pkgdir` LIKE "%'.$argv[1].'%"':'')); +$r=query('SELECT * FROM `gentoo_profiles`'.(isset($argv[1])?' WHERE `name` LIKE "%'.$argv[1].'%" OR `pkgdir` LIKE "%'.$argv[1].'%"':'')); while ($p=$r->fetch(PDO::FETCH_ASSOC)) { $p=new sql_gentoo_profile($p); echo ($p->name?$p->name:$p->pkgdir)."\n"; @@ -1,19 +1,15 @@ #!/usr/bin/php <?php require_once(dirname(__FILE__).'/shared/include/includes.php'); // USE __DIR__ in 5.3.0 -function echo_and_query($q) { - global $S; - echo $q."\n"; - return $S['pdo']->query($q); -} +$S['conf']['debug']=true; $interactive=posix_isatty(STDIN); $opts=getopt('R'); -$S['pdo']=new PDO('mysql:host='.$conf['sqlhost'], $conf['sqluser'], $conf['sqlpass']); +$S['pdo']=new PDO('mysql:host='.$S['conf']['sqlhost'], $S['conf']['sqluser'], $S['conf']['sqlpass']); if (isset($opts['R'])) { - echo_and_query('DROP DATABASE IF EXISTS `'.$conf['sqldb'].'`'); + query('DROP DATABASE IF EXISTS `'.$S['conf']['sqldb'].'`'); } -echo_and_query('CREATE DATABASE IF NOT EXISTS `'.$conf['sqldb'].'`'); // We can add charset and collate here if we want -echo_and_query('USE `'.$conf['sqldb'].'`'); +query('CREATE DATABASE IF NOT EXISTS `'.$S['conf']['sqldb'].'`'); // We can add charset and collate here if we want +query('USE `'.$S['conf']['sqldb'].'`'); sql_row_obj::set_pdo_obj($S['pdo']); foreach (get_declared_classes() as $class) { if (!is_subclass_of($class, 'sql_row_obj')) { @@ -24,9 +20,9 @@ foreach (get_declared_classes() as $class) { unset($r); $o=new $class(); // TODO this will be static once 5.3.0 is out if (isset($opts['R'])) { - echo_and_query($o->drop_table()); + query($o->drop_table()); } - echo_and_query($o->create_table()); + query($o->create_table()); } do { if ($user->email) { diff --git a/shared/classes/0sql_row_obj.php b/shared/classes/0sql_row_obj.php index 239dae3..4efacbd 100644 --- a/shared/classes/0sql_row_obj.php +++ b/shared/classes/0sql_row_obj.php @@ -285,8 +285,6 @@ abstract class sql_row_obj { // If the name of this class changes, it must be up if (!array_key_exists($name, $this->db_values) || $this->values[$name] !== $this->db_values[$name]) { $sql_val=$col->sql_value($this->values[$name]); if (is_array($sql_val)) { - //echo $name."\n"; - print_r($sql_val); throw new Exception('Failed to write '.get_class($this).' object to table `'.$this->table.'` because column `'.$name.'` ('.$sql_val['description'].') '.$sql_val['reason'].' (value: '.$sql_val['value'].')'); } if (++$i > 1) { diff --git a/shared/classes/1conf_build_common.php b/shared/classes/1conf_build_common.php index f5721a4..af20eba 100644 --- a/shared/classes/1conf_build_common.php +++ b/shared/classes/1conf_build_common.php @@ -26,7 +26,7 @@ abstract class conf_build_common extends sql_row_obj { global $S; if (!isset($this->opt_cache)) { $this->opt_cache=array(); - $r=$S['pdo']->query('SELECT * FROM `'.$this->info['optstable'].'` WHERE `'.$this->info['self'].'`="'.$this->id.'"'); + $r=query('SELECT * FROM `'.$this->info['optstable'].'` WHERE `'.$this->info['self'].'`="'.$this->id.'"'); while ($opt=$r->fetch(PDO::FETCH_ASSOC)) { $this->opt_cache[$opt['name']]=new $this->info['optsclass']($opt); } @@ -59,7 +59,7 @@ abstract class conf_build_common extends sql_row_obj { while (true) { $id=randstring(6); debug("Trying id=$id..."); - $r=$S['pdo']->query('SELECT `id` FROM `'.$this->table.'` WHERE `id`="'.$id.'"'); + $r=query('SELECT `id` FROM `'.$this->table.'` WHERE `id`="'.$id.'"'); if ($r->rowCount() == 0) { break; } diff --git a/shared/classes/build.php b/shared/classes/build.php index db12801..7230673 100644 --- a/shared/classes/build.php +++ b/shared/classes/build.php @@ -60,8 +60,8 @@ class sql_build extends conf_build_common { $html='<div class="build"><span class="name">'.(isset($this->name) && strlen($this->name)?htmlentities($this->name):'Unnamed Build').'</span> '; $links=array(); if ($this->status == -128) { - $total=$S['pdo']->query('SELECT COUNT(*) FROM `builds` WHERE `status`=-128')->fetch(PDO::FETCH_COLUMN); - $num=$S['pdo']->query('SELECT COUNT(*) FROM `builds` WHERE `status`=-128 AND `ctime` <= '.$this->ctime)->fetch(PDO::FETCH_COLUMN); + $total=query('SELECT COUNT(*) FROM `builds` WHERE `status`=-128')->fetch(PDO::FETCH_COLUMN); + $num=query('SELECT COUNT(*) FROM `builds` WHERE `status`=-128 AND `ctime` <= '.$this->ctime)->fetch(PDO::FETCH_COLUMN); $html.="<span class=\"status queued\">[Queued ($num/$total)]</span>"; } elseif ($this->status == -127) { $html.='<span class="status successful">[uploading]</span>'; @@ -74,7 +74,7 @@ class sql_build extends conf_build_common { $links['Build Log']="build/$this->id"; } } elseif ($this->status == 0) { - $r=$S['pdo']->query('SELECT COUNT(*) as `count`, MAX(`time`) as `time` FROM `downloads` WHERE `build`="'.$this->id.'"')->fetch(PDO::FETCH_ASSOC); + $r=query('SELECT COUNT(*) as `count`, MAX(`time`) as `time` FROM `downloads` WHERE `build`="'.$this->id.'"')->fetch(PDO::FETCH_ASSOC); $d=($perms && $r['count']?'<a href="'.url("build/$this->id/history").'">':'').$r['count'].' download'.($r['count'] != 1?'s':'').($r['count']?($perms?'</a>':'').'<br/><span class="time">(last at '.date($format, $r['time']).')</span>':''); $html.='<span class="downloads">'.$d.'</span><span class="status successful">[successful]</span>'; $links['Download image']="build/$this->id/download"; @@ -125,15 +125,15 @@ class sql_build extends conf_build_common { global $S; static $cache; if (!isset($cache)) - $cache=$S['pdo']->query('SELECT COUNT(`order`) FROM `tasks` WHERE `start` IS NULL AND `build`="'.$this->id.'"')->fetch(PDO::FETCH_COLUMN); + $cache=query('SELECT COUNT(`order`) FROM `tasks` WHERE `start` IS NULL AND `build`="'.$this->id.'"')->fetch(PDO::FETCH_COLUMN); return $cache; } public function delete() { global $S; - $S['pdo']->query('DELETE FROM `buildlogs` WHERE `build`="'.$this->id.'"'); - $S['pdo']->query('DELETE FROM `tasks` WHERE `build`="'.$this->id.'"'); - $S['pdo']->query('DELETE FROM `buildopts` WHERE `build`="'.$this->id.'"'); - $S['pdo']->query('DELETE FROM `downloads` WHERE `build`="'.$this->id.'"'); + query('DELETE FROM `buildlogs` WHERE `build`="'.$this->id.'"'); + query('DELETE FROM `tasks` WHERE `build`="'.$this->id.'"'); + query('DELETE FROM `buildopts` WHERE `build`="'.$this->id.'"'); + query('DELETE FROM `downloads` WHERE `build`="'.$this->id.'"'); foreach (glob(COMPLETED."/build-.$this->id.*") as $file) unlink($file); parent::delete(); diff --git a/shared/classes/configuration.php b/shared/classes/configuration.php index c6d5766..c7795f4 100644 --- a/shared/classes/configuration.php +++ b/shared/classes/configuration.php @@ -48,6 +48,7 @@ class sql_configuration extends conf_build_common { } } $build=new sql_build(); + $build->visibility='public'; $build->init(); $build->name=$name; $build->module=$this->module; @@ -65,7 +66,7 @@ class sql_configuration extends conf_build_common { // Returns an array of the IDs of all the builds that report this configuration as their source public function get_builds() { global $S; - $r=$S['pdo']->query('SELECT `build` FROM `buildopts` WHERE `name`="configuration" AND `value`="'.$this->id.'"'); + $r=query('SELECT `build` FROM `buildopts` WHERE `name`="configuration" AND `value`="'.$this->id.'"'); if ($r->rowCount()) { $builds=array(); while ($b=$r->fetch(PDO::FETCH_COLUMN)) { diff --git a/shared/classes/gentoo_package.php b/shared/classes/gentoo_package.php index 2c06a26..01d6da4 100644 --- a/shared/classes/gentoo_package.php +++ b/shared/classes/gentoo_package.php @@ -88,7 +88,7 @@ class sql_gentoo_package extends sql_row_obj { } if ($name != '*') $c[]='`name`="'.$name.'"'; $c=implode(' AND ', $c); - $r=$S['pdo']->query('SELECT * FROM `gentoo_packages` WHERE '.$c); + $r=query('SELECT * FROM `gentoo_packages` WHERE '.$c); while ($pkg=$r->fetch(PDO::FETCH_ASSOC)) { $pkg=new sql_gentoo_package($pkg); if (!$pkg->is_masked()) diff --git a/shared/classes/gentoo_profile.php b/shared/classes/gentoo_profile.php index 7184aad..d7726f8 100644 --- a/shared/classes/gentoo_profile.php +++ b/shared/classes/gentoo_profile.php @@ -55,8 +55,8 @@ class sql_gentoo_profile extends sql_row_obj { } // Reads the data from the Packages file in $this->pkgdir public function read_Packages($update_pkgs=false, $verbose=false) { - global $conf; - if (!is_readable($file="{$conf['pkgdir_root']}/$this->pkgdir/Packages")) { + global $S; + if (!is_readable($file="{$S['conf']['pkgdir_root']}/$this->pkgdir/Packages")) { throw_exception("Packages file doesn't exist for pkgdir $this->pkgdir"); } $file=fopen($file, 'r'); @@ -104,7 +104,7 @@ class sql_gentoo_profile extends sql_row_obj { $u=$d=$t=0; if ($update_pkgs) { global $S; - $r=$S['pdo']->query('SELECT * FROM `gentoo_packages` WHERE `profile`='.$this->id); + $r=query('SELECT * FROM `gentoo_packages` WHERE `profile`='.$this->id); while ($pkg=$r->fetch(PDO::FETCH_ASSOC)) { $pkg=new sql_gentoo_package($pkg); if (isset($p[$pkg->bcat][$pkg->lcat][$pkg->name][$pkg->version])) { @@ -152,7 +152,7 @@ class sql_gentoo_profile extends sql_row_obj { $name=array_shift($pkgs); $obj=new sql_gentoo_pkgset(); if ($update) { - $r=$S['pdo']->query('SELECT * FROM `gentoo_pkgsets` WHERE `profile`='.$this->id.' AND `name`="'.$name.'" LIMIT 1'); + $r=query('SELECT * FROM `gentoo_pkgsets` WHERE `profile`='.$this->id.' AND `name`="'.$name.'" LIMIT 1'); if ($r->rowCount()) $obj->from_array($r->fetch(PDO::FETCH_ASSOC), true); } @@ -169,13 +169,13 @@ class sql_gentoo_profile extends sql_row_obj { } } if ($update) - $S['pdo']->query('DELETE FROM `gentoo_pkgsets` WHERE `profile`='.$this->id.($exists?' AND `id` NOT IN ('.implode(',', $exists).')':'')); + query('DELETE FROM `gentoo_pkgsets` WHERE `profile`='.$this->id.($exists?' AND `id` NOT IN ('.implode(',', $exists).')':'')); } public function read_stage3($update=false) { global $S; if ($update) { - $S['pdo']->query('DELETE FROM `gentoo_basepkgs` WHERE `profile`='.$this->id); - $S['pdo']->query('DELETE FROM `gentoo_baseinit` WHERE `profile`='.$this->id); + query('DELETE FROM `gentoo_basepkgs` WHERE `profile`='.$this->id); + query('DELETE FROM `gentoo_baseinit` WHERE `profile`='.$this->id); } $file=realpath(CACHE.'/stage3/'.$this->stage3); if (!is_readable($file)) return false; @@ -198,7 +198,7 @@ class sql_gentoo_profile extends sql_row_obj { public function &get_packages($omit_masked=false, $trim=null) { global $S; $skip_masked=!in_array('masked', $trim); - $r=$S['pdo']->query('SELECT * FROM `gentoo_packages` WHERE `profile`='.$this->id); + $r=query('SELECT * FROM `gentoo_packages` WHERE `profile`='.$this->id); $p=array(); while ($pkg=$r->fetch(PDO::FETCH_ASSOC)) { $pkg=new sql_gentoo_package($pkg); diff --git a/shared/classes/registrationtoken.php b/shared/classes/registrationtoken.php index 9f331ae..93fe4e6 100644 --- a/shared/classes/registrationtoken.php +++ b/shared/classes/registrationtoken.php @@ -33,7 +33,7 @@ class sql_registrationtoken extends sql_row_obj { $id=null; do { $id=randstring(30); - if ($S['pdo']->query('SELECT COUNT(*) FROM `registrationtokens` WHERE `id`=\''.$id.'\'')->fetch(PDO::FETCH_COLUMN)) + if (query('SELECT COUNT(*) FROM `registrationtokens` WHERE `id`=\''.$id.'\'')->fetch(PDO::FETCH_COLUMN)) $id=null; } while ($id==null); return new sql_registrationtoken($id, null, null, null); diff --git a/shared/classes/session.php b/shared/classes/session.php index e422b21..1233a71 100644 --- a/shared/classes/session.php +++ b/shared/classes/session.php @@ -33,18 +33,18 @@ class sql_session extends sql_row_obj { ); // Creates a new session for the user at $S['user'] with a unique id, sends a cookie to the user and returns true for success, false for failure static function create() { - global $S, $conf; + global $S; $id=null; while (!$id) { $id=randstring(30); - $r=$S['pdo']->query('SELECT * FROM `sessions` WHERE `id`="'.$id.'"'); + $r=query('SELECT * FROM `sessions` WHERE `id`="'.$id.'"'); if ($r->rowCount()) { $id=null; } } - $S['session']=new sql_session($id, $S['user']->id, time(), $conf['sessionlength']); - debug('setcookie', $conf['cookiename'].'='.$id); - if (setcookie($conf['cookiename'], $S['session']->id, time()+$conf['sessionlength'], $S['cookie_dir'], '', false, true)) { + $S['session']=new sql_session($id, $S['user']->id, time(), $S['conf']['sessionlength']); + debug('setcookie', $S['conf']['cookiename'].'='.$id); + if (setcookie($S['conf']['cookiename'], $S['session']->id, time()+$S['conf']['sessionlength'], $S['cookie_dir'], '', false, true)) { $S['session']->write(); return true; } else { diff --git a/shared/classes/task.php b/shared/classes/task.php index cdcd15c..d763107 100644 --- a/shared/classes/task.php +++ b/shared/classes/task.php @@ -73,7 +73,7 @@ class sql_task extends sql_row_obj { $html.='<span class="status running">[running]</span> <span class="time">Running for <span class="time">'.display_time(time()-$this->start).'</span></span>'; } } else { - $num=$S['pdo']->query('SELECT COUNT(*) FROM `tasks` WHERE `builds`="'.$this->build.'" AND `start` IS NULL AND `order` <= '.$this->order)->fetch(PDO::FETCH_ASSOC); + $num=query('SELECT COUNT(*) FROM `tasks` WHERE `builds`="'.$this->build.'" AND `start` IS NULL AND `order` <= '.$this->order)->fetch(PDO::FETCH_ASSOC); $html.="<span class=\"status queued\">[queued $num/".$build->queued_tasks()."]</span>"; } $html.='</div></div>'; diff --git a/shared/classes/validate.php b/shared/classes/validate.php index c409db4..6c6f479 100644 --- a/shared/classes/validate.php +++ b/shared/classes/validate.php @@ -37,8 +37,8 @@ class Validate { } } // Checking DNS to make sure the domain is real is total overkill - global $conf; - if ($conf['check_email_dns'] && $isValid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A"))) { + global $S; + if ($S['conf']['check_email_dns'] && $isValid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A"))) { // domain not found in DNS $isValid = false; } diff --git a/shared/functions/debug.php b/shared/functions/debug.php index 4231e21..8a054f9 100644 --- a/shared/functions/debug.php +++ b/shared/functions/debug.php @@ -1,7 +1,7 @@ <?php function debug ($type, $text=null) { - global $conf, $S; - if ($conf['debug']) { + global $S; + if ($S['conf']['debug']) { if ($text===null) { $text=$type; $type=null; diff --git a/shared/functions/get_timezones.php b/shared/functions/get_timezones.php index 4c495cd..12ccc81 100644 --- a/shared/functions/get_timezones.php +++ b/shared/functions/get_timezones.php @@ -1,23 +1,23 @@ <?php function &get_timezones($dir=null) { - global $conf; + global $S; static $results; if ($dir == null) { if (isset($results)) return $results; $results=array(); - $dir=realpath($conf['timezone_root']); + $dir=realpath($S['conf']['timezone_root']); } foreach (glob($dir.'/*') as $file) { if (is_dir($file) && !is_link($file)) get_timezones($file); else { - $file=substr($file, strlen($conf['timezone_root'])+1); + $file=substr($file, strlen($S['conf']['timezone_root'])+1); if ($file != 'zone.tab') $results[$file]=str_replace('_', ' ', $file); } } - if ($dir == $conf['timezone_root']) { + if ($dir == $S['conf']['timezone_root']) { natsort($results); } return $results; diff --git a/shared/functions/load_config.php b/shared/functions/load_config.php index eb07879..a212b16 100644 --- a/shared/functions/load_config.php +++ b/shared/functions/load_config.php @@ -5,7 +5,7 @@ function load_config() { $modules=explode(' ', $modules); foreach (explode(' ', 'title url sqlhost sqluser sqlpass sqldb debug modules bundlers cookiename sessionlength mod_rewrite timezone_root emailfrom check_email_dns split_setup registration invite logview_max progressbar_width pkgdir_root emerge_default_opts portdir backend_id') as $var) { if (isset($$var)) { - $GLOBALS['conf'][$var]=$$var; + $GLOBALS['S']['conf'][$var]=$$var; } } } diff --git a/shared/functions/query.php b/shared/functions/query.php new file mode 100644 index 0000000..d92ee0f --- /dev/null +++ b/shared/functions/query.php @@ -0,0 +1,8 @@ +<?php +function query($q) { + debug('query', $q); + // 5.3.0: func_get_args() can be used directly in call_user_func_array() + $args=func_get_args(); + return call_user_func_array(array(&$GLOBALS['S']['pdo'], 'query'), $args); +} +?> diff --git a/shared/functions/url.php b/shared/functions/url.php index f2ff5ba..0234b2b 100644 --- a/shared/functions/url.php +++ b/shared/functions/url.php @@ -1,23 +1,23 @@ <?php // Makes all URLs absolute function url($url='') { - global $conf; + global $S; if (strlen($url) == 0) { - return $conf['url'].($conf['mod_rewrite']?'':'/index.php'); + return $S['conf']['url'].($S['conf']['mod_rewrite']?'':'/index.php'); } elseif (substr($url, 0, 7) == 'http://') { return $url; } - if ($conf['mod_rewrite']) { - return $conf['url'].'/'.$url; + if ($S['conf']['mod_rewrite']) { + return $S['conf']['url'].'/'.$url; } else { if (strpos($url, '?')) { $q=substr($url, strpos($url, '?')+1); $url=substr($url, 0, strpos($url, '?')); } if (strlen($url)) { - return $conf['url'].'/index.php?req='.$url.(isset($q)?'&'.$q:''); + return $S['conf']['url'].'/index.php?req='.$url.(isset($q)?'&'.$q:''); } else { - return $conf['url'].'/index.php?'.$q; + return $S['conf']['url'].'/index.php?'.$q; } } } diff --git a/shared/functions/xhtmlemail.php b/shared/functions/xhtmlemail.php index 2e71388..d4924f7 100644 --- a/shared/functions/xhtmlemail.php +++ b/shared/functions/xhtmlemail.php @@ -1,14 +1,14 @@ <?php // Sends an XHTML email with the appropriate headers and the necessary opening and closing for an XHTML document function xhtmlemail($to,$from,$subj,$cont,$inheads=null) { - global $conf; + global $S; if ($from===null) { - $from=$conf['emailfrom']; + $from=$S['conf']['emailfrom']; } $heads='MIME-Version: 1.0' . "\r\n"; $heads.='Content-type: text/html; charset=utf-8' . "\r\n"; $heads.='From: '.$from."\r\n"; - $heads.='X-Mailer: PHP/'.$conf['title']."\r\n"; + $heads.='X-Mailer: PHP/'.$S['conf']['title']."\r\n"; if ($inheads!==null) { $heads.=$inheads."\r\n"; } diff --git a/shared/include/dbinit.php b/shared/include/dbinit.php index e52498a..45b7eb7 100644 --- a/shared/include/dbinit.php +++ b/shared/include/dbinit.php @@ -1,11 +1,8 @@ <?php -require_once(dirname(__FILE__).'/../config.php'); // Use __DIR__ in 5.3.0 -$pdoclass=(class_exists('pdo_debug')?'pdo_debug':'PDO'); try { - $S['pdo']=new $pdoclass('mysql:dbname='.$conf['sqldb'].';host='.$conf['sqlhost'], $conf['sqluser'], $conf['sqlpass'], array(PDO::ATTR_PERSISTENT => true)); + $S['pdo']=new PDO('mysql:dbname='.$S['conf']['sqldb'].';host='.$S['conf']['sqlhost'], $S['conf']['sqluser'], $S['conf']['sqlpass'], array(PDO::ATTR_PERSISTENT => true)); } catch (Exception $e) { die(print_error('Database connection failure.', $e->getMessage())); } -unset($pdoclass); sql_row_obj::set_pdo_obj($S['pdo']); ?> diff --git a/shared/include/includes.php b/shared/include/includes.php index bfd358d..8a75b58 100644 --- a/shared/include/includes.php +++ b/shared/include/includes.php @@ -1,4 +1,5 @@ <?php +date_default_timezone_set('UTC'); require_once(dirname(__FILE__).'/paths.php'); // USE __dir__ in 5.3.0 // Load functions and classes from the shared directory and either foreground or background foreach (array('functions', 'classes') as $type) { @@ -1,7 +1,7 @@ Write a live git ebuild Add a profiles management page/backend utility Add cleanup functions to the frontend and backend (tasks dir in backend containing scripts that can be launched through frontend) -Move bundler selection out of gentoo module +*** Move bundler selection out of gentoo module *** Only offer bundlers that will work - profiles without CD in map file can't make livecd, installcd, etc. Allow config viewing for builds, not just configurations Add `flags` column to configurations, builds, use it to implement public and private things @@ -13,3 +13,4 @@ Add ability to trim the stage3 to a minimum set of packages automatically (cache Add option to add arbitrary runscripts Add option to upload a kernel Add option to upload an arbitrary tar.gz/bz2 to be unzipped over the finished image +*** Go through Gentoo install guide and make sure everything is covered *** diff --git a/update_gentoo_profiles.php b/update_gentoo_profiles.php index e9f3ead..3f3cb3f 100755 --- a/update_gentoo_profiles.php +++ b/update_gentoo_profiles.php @@ -3,13 +3,12 @@ require_once(dirname(__FILE__).'/shared/include/includes.php'); // USE __DIR__ in 5.3.0 require_once(SHARED.'/config.php'); require_once(SHARED.'/include/dbinit.php'); -$pdo=&$S['pdo']; $profiles=array(); -$r=$pdo->query('SELECT * FROM `gentoo_profiles`'.(isset($argv[1])?' WHERE `name` LIKE "%'.$argv[1].'%" OR `pkgdir` LIKE "%'.$argv[1].'%"':'')); +$r=query('SELECT * FROM `gentoo_profiles`'.(isset($argv[1])?' WHERE `name` LIKE "%'.$argv[1].'%" OR `pkgdir` LIKE "%'.$argv[1].'%"':'')); while ($p=$r->fetch(PDO::FETCH_ASSOC)) { $profiles[$p['id']]=new sql_gentoo_profile($p); $profile=&$profiles[$p['id']]; - echo "Updating from {$conf['pkgdir_root']}/$profile->pkgdir/Packages...\n"; + echo "Updating from {$S['conf']['pkgdir_root']}/$profile->pkgdir/Packages...\n"; list($new, $updated, $deleted, $total)=$profile->read_Packages(true, true); echo "Packages: $new new, $updated updated, $deleted deleted, $total total.\n"; echo 'Updating package sets...'; diff --git a/update_sql_classes.php b/update_sql_classes.php index ddef0b1..90a1d96 100755 --- a/update_sql_classes.php +++ b/update_sql_classes.php @@ -42,8 +42,7 @@ function write_table_class_to_file($table, $class, $file) { fputs($stream, "?>\n"); fclose($stream); } -$pdo=&$S['pdo']; -$r=$pdo->query('SHOW TABLES'); +$r=query('SHOW TABLES'); $tables=$r->fetchAll(PDO::FETCH_COLUMN); $check_existing=prompt_bool('Check existing classes for changes from the database?'); foreach ($tables as $i => $table) { |