diff --git a/config.ini b/config.ini index a908ff8..82fc30d 100644 --- a/config.ini +++ b/config.ini @@ -1,5 +1,6 @@ [html] instance_name = curload +instance_description = curload is a simple file uploading site allowing users to upload files by authenticating using a key. css = index.css javascript = index.js logo = logo.svg diff --git a/config.php b/config.php index 7e2c009..34a96fe 100644 --- a/config.php +++ b/config.php @@ -23,6 +23,7 @@ $replaceOriginal = false; $logoHeaderSize = 16; $dateFormat = "Y/m/d"; $instanceName = "curload"; +$instanceDescription = "curload is a simple file uploading site allowing users to upload files by authenticating using a key."; $cookieName = "speedierocks"; $enableKeys = true; $enableAdminKeys = true; @@ -50,6 +51,7 @@ $storeUploads = $configEntries['store_number_of_uploads']; $logoHeaderSize = $configEntries['logo_header_size']; $dateFormat = $configEntries['date_format']; $instanceName = $configEntries['instance_name']; +$instanceDescription = $configEntries['instance_description']; $publicUploading = $configEntries['public_uploading']; $renameDuplicates = $configEntries['rename_duplicates']; $replaceOriginal = $configEntries['replace_original']; diff --git a/core.php b/core.php index 75b1eb7..45e391d 100644 --- a/core.php +++ b/core.php @@ -10,7 +10,7 @@ function printHeader($html) { $html .= "\n"; $html .= "\n"; $html .= "\t\n"; - $html .= "\t\t\n"; + $html .= "\t\t\n"; $html .= "\t\t\n"; if (file_exists($Icon)) $html .= "\t\t\n"; @@ -21,7 +21,18 @@ function printHeader($html) { $html .= "\t\t
\n"; $html .= "\t\t\t\n"; if (file_exists($Logo)) $html .= "\t\t\t\t\n"; - $html .= "\t\t\t\t$instanceName\n"; + $html .= "\t\t\t\t$instanceName\n"; + + if (!isset($_COOKIE[$cookieName])) { + $html .= "\t\t\t\tLog in\n"; + } else { + $html .= "\t\t\t\tLog out\n"; + } + + if (isset($_COOKIE[$cookieTypeName]) && $_COOKIE[$cookieTypeName] == 2) { + $html .= "\t\t\t\tAdministration\n"; + } + $html .= "\t\t\t\n"; $html .= "\t\t
\n"; $html .= "\t\n"; diff --git a/index.css b/index.css index c588d0a..5704e3d 100644 --- a/index.css +++ b/index.css @@ -8,6 +8,14 @@ width: 100%; } +#title { + color: #f0eee4; +} + +#administration { + color: #ffc0cb; +} + .bar img { float: left; padding-right: 5px; diff --git a/index.php b/index.php index 455ec8a..d0c8f74 100644 --- a/index.php +++ b/index.php @@ -8,12 +8,37 @@ function main() { include "config.php"; include "core.php"; + $Error = ""; $html = ""; + $html = printHeader($html); - $html .= "\t\t\t

speedie's super awesome file uploader junk

\n"; - $html .= "\t\t\t
Select file to upload


\n"; - $html .= "\t\t\t

Max file size: $maxFileSize MB

\n"; + $html .= "\t\t\t

$instanceName

\n"; + $html .= "\t\t\t\t

$instanceDescription\n"; + + if (isset($_REQUEST['e'])) { + $Error = $_REQUEST['e']; + } + + if (isset($_COOKIE[$cookieTypeName])) { + $html .= "\t\t\t

\n"; + $html .= "\t\t\t\t\n"; + $html .= "\t\t\t\t\n"; + $html .= "\t\t\t
\n"; + $html .= "\t\t\t

Max file size: $maxFileSize MB

\n"; + + // error handling + if ($Error == "file") { + $html .= "\t\t\t

No file specified.

\n"; + } else if ($Error == "size") { + $html .= "\t\t\t

File is too big.

\n"; + } else if ($Error == "key") { + $html .= "\t\t\t

Invalid key. WTF?

\n"; + } else if ($Error == "wtf") { + $html .= "\t\t\t

WTF? Try again.

\n"; + } + } + $html .= "\t\t\tsource code\n"; $html = printFooter($html); diff --git a/upload.php b/upload.php index c083257..96f4f9f 100644 --- a/upload.php +++ b/upload.php @@ -7,8 +7,14 @@ include "config.php"; include "create-table.php"; +$WebInterface = 1; + if (isset($_REQUEST['key'])) { $Key = $_REQUEST['key']; + $WebInterface = 0; +} else if (isset($_COOKIE[$cookieName])) { + $Key = $_COOKIE[$cookieName]; + $WebInterface = 1; } else { print "No key specified."; die(); @@ -22,8 +28,13 @@ $keyID = 0; $self = dirname($_SERVER['PHP_SELF']); if (!isset($_FILES['file']['name'])) { - print "You didn't specify a file."; - die(); + if ($WebInterface == 0) { + print "You didn't specify a file."; + die(); + } else { + header("Location: /?e=file"); + die(); + } } // init database @@ -153,14 +164,24 @@ if (!$publicUploading || $publicUploading == "false") { // Not an authorized key if ($Authorized == 0) { - print "Not authorized: Key '$Key' is invalid."; - die(); + if ($WebInterface == 0) { + print "Not authorized: Your key is invalid."; + die(); + } else { + header("Location: /?e=key"); + die(); + } } } if ($_FILES['file']['size'] > $uploadLimit && $uploadLimit > 0) { - print "File is too big. Max file size is $maxFileSize" . "MB"; - die(); + if ($WebInterface == 0) { + print "File is too big. Max file size is $maxFileSize" . "MB"; + die(); + } else { + header("Location: /?e=size"); + die(); + } } // check if file is too big to be uploaded @@ -183,8 +204,13 @@ if (!$replaceOriginal || $replaceOriginal == "false") { } if (file_exists($destinationFile)) { // wtf - print "Failed to upload file."; - die(); + if ($WebInterface == 0) { + print "Upload failed."; + die(); + } else { + header("Location: /?e=wtf"); + die(); + } } } } @@ -196,15 +222,25 @@ if (move_uploaded_file($_FILES['file']['tmp_name'], $destinationFile)) { $DatabaseQuery = $Database->query('SELECT * FROM uploads'); $Database->exec("INSERT INTO uploads(file, uploaddate, keyid, keytype) VALUES('$uploadedFile', '$lastUsed', '$keyID', '$keyType')"); - print "$uploadedFile"; + if ($WebInterface == 0) { + print "$uploadedFile"; + } else { + header("Location: $uploadedFile"); + } if (isset($_REQUEST['web'])) { // redirect back to index - print "

Your link

\n"; + header("Redirect: $uploadedFile"); die(); } } else { - print "Failed to upload file."; - print $_FILES['file']['error']; - die(); + if (file_exists($destinationFile)) { // wtf + if ($WebInterface == 0) { + print "Upload failed."; + die(); + } else { + header("Location: /?e=wtf"); + die(); + } + } } ?>