diff options
Diffstat (limited to 'frontend/pages/builds')
-rw-r--r-- | frontend/pages/builds/download.php | 50 | ||||
-rw-r--r-- | frontend/pages/builds/history.php | 27 |
2 files changed, 77 insertions, 0 deletions
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"; + } +} +?> |