summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEudyptula <eitan@mosenkis.net>2009-07-02 18:01:25 -0400
committerEudyptula <eitan@mosenkis.net>2009-07-02 18:01:25 -0400
commit2c1a22a8eeea460db4cb326554ba7da5a37a5324 (patch)
tree8d112eb07b6135ceaca02490156bf762e9fa2edd /frontend
parentAdded support for EXT2 and JFFS2 images (diff)
downloadingenue-2c1a22a8eeea460db4cb326554ba7da5a37a5324.tar.gz
ingenue-2c1a22a8eeea460db4cb326554ba7da5a37a5324.tar.bz2
ingenue-2c1a22a8eeea460db4cb326554ba7da5a37a5324.zip
Backend can upload finished images; caches state after emerge system completes
Diffstat (limited to 'frontend')
-rwxr-xr-xfrontend/.htaccess5
-rw-r--r--frontend/pages/404.php2
-rw-r--r--frontend/pages/upload.php40
-rw-r--r--frontend/routing.csv2
4 files changed, 46 insertions, 3 deletions
diff --git a/frontend/.htaccess b/frontend/.htaccess
index 0fa2f57..c1804b1 100755
--- a/frontend/.htaccess
+++ b/frontend/.htaccess
@@ -1,4 +1,5 @@
+php_value upload_max_filesize 1073741824
+php_value post_max_size 1073742848
RewriteEngine On
-#RewriteRule ^(recordings/[0-9]+\.mp3)$ $1 [L]
-RewriteRule ^(tmp(/.*)?)$ $1 [L]
+#RewriteRule ^(tmp(/.*)?)$ $1 [L]
RewriteRule ^(?!main.php)(.*)$ index.php?req=$1&%{QUERY_STRING}
diff --git a/frontend/pages/404.php b/frontend/pages/404.php
index c81af31..e19c818 100644
--- a/frontend/pages/404.php
+++ b/frontend/pages/404.php
@@ -2,7 +2,7 @@
function init_404() {
global $S;
$S['title']='404: Not Found';
- header('HTTP/1.0 404 Not Found');
+ header('HTTP/1.0 404 Not Found', true, 404);
}
function body_404() {
global $S;
diff --git a/frontend/pages/upload.php b/frontend/pages/upload.php
new file mode 100644
index 0000000..0c5ceb3
--- /dev/null
+++ b/frontend/pages/upload.php
@@ -0,0 +1,40 @@
+<?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']))) {
+ debug('upload', 'missing or malformed input');
+ return '404';
+ }
+ $r=$S['pdo']->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_buildopts();
+ if (!(isset($opts['uploadkey']) && $opts['uploadkey'] == $request['key'])) {
+ debug('upload', 'invalid upload key');
+ return '404';
+ }
+ debug('upload', 'error code: '.$_FILES['file']['error']);
+ if ($_FILES['file']['error'] != UPLOAD_ERR_OK) {
+ return '404';
+ }
+ debug('upload', 'Got uploaded file '.$_FILES['file']['name'].' at '.$_FILES['file']['tmp_name']);
+ $name=basename($_FILES['file']['name']);
+ $ext=substr($name, strpos($name, '.'));
+ debug('upload', $_FILES['file']['tmp_name'].' -> '.COMPLETED."/build-$build->id$ext");
+ if (!is_writable(COMPLETED)) {
+ debug('upload', 'Web server needs write permissions for '.COMPLETED);
+ return '404';
+ }
+ if (!move_uploaded_file($_FILES['file']['tmp_name'], COMPLETED."/build-$build->id$ext")) {
+ debug('Move file failed');
+ return '404';
+ }
+ return array('title' => 'Upload Successful');
+}
+function body_upload() {
+ echo print_success('Upload successful');
+}
+?>
diff --git a/frontend/routing.csv b/frontend/routing.csv
index bbec7d7..4b77f29 100644
--- a/frontend/routing.csv
+++ b/frontend/routing.csv
@@ -39,5 +39,7 @@
#^(xinha(?=/)[0-9a-zA-Z-_./]*).(?<=/)([0-9a-zA-Z-_.]+\.([a-zA-Z0-9]+))$ passthrough dir file ext
# CSS
^style.css$ stylesheet
+# Backend access only
+^backend/upload_image$ upload
# This is the catch-all - never remove it
^ 404