summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEudyptula <eitan@mosenkis.net>2009-07-20 16:13:47 -0400
committerEudyptula <eitan@mosenkis.net>2009-07-20 16:13:47 -0400
commit6f995b43606448b7f615353a542a08e23613919b (patch)
tree6c8dcd8637124ffd83594f35b7c352a402b77128 /frontend
parentAdded metadata back to log viewer (diff)
downloadingenue-6f995b43606448b7f615353a542a08e23613919b.tar.gz
ingenue-6f995b43606448b7f615353a542a08e23613919b.tar.bz2
ingenue-6f995b43606448b7f615353a542a08e23613919b.zip
Converted backend status to TINYINT; First try at logging non-execution messages; Added download history page; Only show links from builds that the user has perms to access
Diffstat (limited to 'frontend')
-rw-r--r--frontend/include/header.php4
-rw-r--r--frontend/pages/builds/download.php50
-rw-r--r--frontend/pages/builds/history.php27
-rw-r--r--frontend/pages/downloadimage.php49
-rw-r--r--frontend/routing.csv3
5 files changed, 81 insertions, 52 deletions
diff --git a/frontend/include/header.php b/frontend/include/header.php
index d4f9bea..c11c480 100644
--- a/frontend/include/header.php
+++ b/frontend/include/header.php
@@ -35,9 +35,9 @@ if (isset($S['head'])) {
<h1><a href="<?php echo url(); ?>"><img src="<?php echo url('images/ingenue.png'); ?>" alt="Ingenue" /></a></h1>
<ul>
<?php
-echo '<li><a href="'.url().'">Home</a></li>';
+//echo '<li><a href="'.url().'">Home</a></li>';
echo '<li><a href="'.url('create').'">New configuration</a></li>';
-echo '<li><a href="'.url('configurations').'">Manage configurations</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'))
diff --git a/frontend/pages/builds/download.php b/frontend/pages/builds/download.php
new file mode 100644
index 0000000..8ce338c
--- /dev/null
+++ b/frontend/pages/builds/download.php
@@ -0,0 +1,50 @@
+<?php
+function init_builds_download() {
+ global $S, $request;
+ if (!isset($S['user'])) {
+ return 'login';
+ }
+ 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'].'"');
+ if ($r->rowCount() == 0) {
+ debug('builds_download', 'build not found or not owned by user');
+ return '404';
+ }
+ $build=new sql_build($r->fetch(PDO::FETCH_ASSOC));
+ if (!owner_or_admin($build->owner)) {
+ debug('builds_download', 'Permission denied');
+ return '404';
+ }
+ $files=glob(COMPLETED.'/build-'.$build->id.'.*');
+ if (count($files)) {
+ if (count($files) > 1) {
+ debug('builds_download', 'extraneous file(s) found - don\'t know which to give them');
+ return '404';
+ }
+ $S['builds_download']['file']=$files[0];
+ if (!is_readable($S['builds_download']['file'])) {
+ debug('builds_download', 'found file, but no read perms');
+ return '404';
+ }
+ $ext=substr($S['builds_download']['file'], strpos($S['builds_download']['file'], '.'));
+ } else {
+ debug('builds_download', 'image file not found');
+ return '404';
+ }
+ $S['builds_download']['dl']=new sql_download($build->id, $S['user']->id, time());
+ contenttype('application/octet-stream');
+ header('Content-Length: '.filesize($S['builds_download']['file']));
+ header('Content-Description: File Transfer');
+ 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;
+ readfile($S['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
new file mode 100644
index 0000000..0ddcbff
--- /dev/null
+++ b/frontend/pages/builds/history.php
@@ -0,0 +1,27 @@
+<?php
+function init_builds_history() {
+ global $S, $request;
+ 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 (!$r->rowCount()) return '404';
+ $S['builds_history']['build']=new sql_build($r->fetch(PDO::FETCH_ASSOC));
+ if (!owner_or_admin($S['builds_history']['build']->id)) {
+ return '404';
+ }
+ return array('title' => 'Download History');
+}
+function body_builds_history() {
+ global $S;
+ $build=&$S['builds_history']['build'];
+ echo $build->display();
+ $r=$S['pdo']->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();
+ echo '<p>Downloaded <code>'.date('D j M Y G:i:s T', $download->time).'</code> by <b>'.$user->name.'</b></p>'."\n";
+ }
+}
+?>
diff --git a/frontend/pages/downloadimage.php b/frontend/pages/downloadimage.php
deleted file mode 100644
index 2234a10..0000000
--- a/frontend/pages/downloadimage.php
+++ /dev/null
@@ -1,49 +0,0 @@
-<?php
-function init_downloadimage() {
- global $S, $request;
- if (!isset($S['user'])) {
- return 'login';
- }
- if (!(isset($request['build']) && strlen($request['build']) == 6 && ctype_alnum($request['build']))) {
- debug('downlaodimage', 'No build or badly formatted build requested');
- return '404';
- }
- $r=$S['pdo']->query('SELECT * FROM `builds` WHERE `id`="'.$request['build'].'"');
- if ($r->rowCount() == 0) {
- debug('downloadimage', 'build not found or not owned by user');
- return '404';
- }
- $build=new sql_build($r->fetch(PDO::FETCH_ASSOC));
- if (!owner_or_admin($build->owner)) {
- debug('downloadimage', 'Permission denied');
- return '404';
- }
- $files=glob(COMPLETED.'/build-'.$build->id.'.*');
- if (count($files)) {
- if (count($files) > 1) {
- debug('downloadimage', 'extraneous file(s) found - don\'t know which to give them');
- return '404';
- }
- $S['file']=$files[0];
- if (!is_readable($S['file'])) {
- debug('downloadimage', 'found file, but no read perms');
- return '404';
- }
- $ext=substr($S['file'], strpos($S['file'], '.'));
- } else {
- debug('downloadimage', 'image file not found');
- return '404';
- }
- $dl=new sql_download($build->id, $S['user']->id, time());
- $dl->write();
- contenttype('application/octet-stream');
- header('Content-Length: '.filesize($S['file']));
- header('Content-Description: File Transfer');
- 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_downloadimage() {
- global $S;
- readfile($S['file']);
-}
-?>
diff --git a/frontend/routing.csv b/frontend/routing.csv
index 7312364..3a93c19 100644
--- a/frontend/routing.csv
+++ b/frontend/routing.csv
@@ -24,7 +24,8 @@
^config/([a-zA-Z0-9]{6})/status$ configurations/status configuration
^configurations$ configurations/manager
# Download finished image
-^download/([a-zA-Z0-9]{6})$ downloadimage build
+^download/([a-zA-Z0-9]{6})$ builds/download build
+^download/([a-zA-Z0-9]{6})/history$ builds/history build
# Session
^login$ login
^login/(.+)$ login go