From: Jerome Jutteau Date: Thu, 31 Jan 2013 22:14:14 +0000 (+0100) Subject: use scripting interface to send files X-Git-Tag: 1.1~220 X-Git-Url: https://git.p6c8.net/jirafeau_mojo42.git/commitdiff_plain/18c82ef56dce9c9eb30b0f2318024d320d878a47?ds=inline use scripting interface to send files --- diff --git a/file.php b/file.php index 0a1554c..bb97570 100644 --- a/file.php +++ b/file.php @@ -101,7 +101,7 @@ if (!empty ($link['key'])) if (!isset ($_POST['key'])) { require (JIRAFEAU_ROOT.'lib/template/header.php'); - echo '
' . + echo '
' . '
'; ?> ' . + echo '
' . ''; ?> * Copyright (C) 2012 Jerome Jutteau * * This program is free software: you can redistribute it and/or modify @@ -23,153 +22,89 @@ require (JIRAFEAU_ROOT . 'lib/config.php'); require (JIRAFEAU_ROOT . 'lib/settings.php'); require (JIRAFEAU_ROOT . 'lib/functions.php'); require (JIRAFEAU_ROOT . 'lib/lang.php'); - -if (file_exists (JIRAFEAU_ROOT . 'install.php') - && !file_exists (JIRAFEAU_ROOT . 'lib/config.local.php')) -{ - header('Location: install.php'); - exit; -} - -/* check if the destination dirs are writable */ -$writable = is_writable (VAR_FILES) && is_writable (VAR_LINKS); - -$res = array (); -if ($writable && isset ($_POST['jirafeau']) && isset ($_FILES['file']) - && isset ($_POST['time'])) -{ - if (!isset ($_POST['key'])) - $key = ''; - else - $key = $_POST['key']; - - $time = time (); - switch ($_POST['time']) - { - case 'minute': - $time += JIRAFEAU_MINUTE; - break; - case 'hour': - $time += JIRAFEAU_HOUR; - break; - case 'day': - $time += JIRAFEAU_DAY; - break; - case 'week': - $time += JIRAFEAU_WEEK; - break; - case 'month': - $time += JIRAFEAU_MONTH; - break; - default: - $time = JIRAFEAU_INFINITY; - break; - } - - $res = - jirafeau_upload ($_FILES['file'], isset ($_POST['one_time_download']), - $key, $time, $_SERVER['REMOTE_ADDR']); -} - require (JIRAFEAU_ROOT . 'lib/template/header.php'); -/* Checking for errors. */ -if (!is_writable (VAR_FILES)) - add_error (t('The file directory is not writable!'), VAR_FILES); - -if (!is_writable (VAR_LINKS)) - add_error (t('The link directory is not writable!'), VAR_LINKS); - -/* Check if the install.php script is still in the directory. */ -if (file_exists (JIRAFEAU_ROOT . 'install.php')) - add_error (t('Installer script still present'), - t('Please make sure to delete the installer script ' . - '"install.php" before continuing.')); - -if (!has_error () && !empty ($res)) -{ - if ($res['error']['has_error']) - add_error (t('An error occurred.'), $res['error']['why']); - else - { - $link = $cfg['web_root']; - $delete_link = $cfg['web_root']; - - if ($cfg['rewrite']) - { - $link .= 'file-'.$res['link']; - $delete_link .= - 'file-'.$res['link'].'-delete-'.$res['delete_link']; - } - else - { - /* h because 'h' looks like a jirafeau ;) */ - $link .= 'file.php?h='.$res['link']; - $delete_link .= - 'file.php?h='.$res['link'].'&d='.$res['delete_link']; - } - - echo '
'.NL; - echo '

' . t('File uploaded! Copy the following URL to get it') . - ':
' . NL; - echo ''.$link.'' . NL; - - if ($time != JIRAFEAU_INFINITY) - { - echo '
' . t('This file is valid until the following date') . - ':
' . strftime ('%c', $time) . ''; - } - - echo '

'; - - echo '
' . NL; - echo '

' . t('Keep the following URL to delete it at any moment') . ':
' . NL; - echo '' . $delete_link . '' . NL; - echo '

'; - } -} - +check_errors (); if (has_error ()) show_errors (); -if (!has_error () && $writable) -{ - ?>
-
-

- +

+

+ : +
+ +
+

+ +

+ : +
+ +

+ +

+ : +

+

+
+ +
+

+

+

+
+ +
+ + : + +

+ +

+

+ +

+

+ -



-

-

+

+
+ + + + + + + + + + + + + +
:
+
+
+ + diff --git a/lib/functions.js b/lib/functions.js new file mode 100755 index 0000000..15ae08c --- /dev/null +++ b/lib/functions.js @@ -0,0 +1,113 @@ +/* + * Jirafeau, your web file repository + * Copyright (C) 2012 Jerome Jutteau + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +function show_link (url, reference, delete_code, date) +{ + var download_link = url + 'file.php?h=' + reference; + var delete_link = download_link + '&d=' + delete_code; + var delete_link_href = download_link + '&d=' + delete_code; + document.getElementById('upload_link').innerHTML = download_link; + document.getElementById('upload_link').href = download_link; + document.getElementById('delete_link').innerHTML = delete_link; + document.getElementById('delete_link').href = delete_link_href; + if (date) + { + document.getElementById('date').innerHTML = date; + document.getElementById('validity').style.display = ''; + } + else + document.getElementById('validity').style.display = 'none'; + + + document.getElementById('uploading').style.display = 'none'; + document.getElementById('upload').style.display = 'none'; + document.getElementById('upload_finished').style.display = ''; +} + +function upload_progress (e) +{ + if (!e.lengthComputable) + return; + /* Show the user the operation do not reach 100%, the server need time + * to give a response before providing the link. + */ + var p = Math.round (e.loaded * 99 / e.total); + document.getElementById('uploaded_percentage').innerHTML = p.toString() + '%'; +} + +function upload_failed (e) +{ + /* Todo: Considere showing a error div. */ + alert ('Sorry, upload failed'); +} + +function upload (url, file, time, password, one_time) +{ + var req = new XMLHttpRequest (); + req.upload.addEventListener("progress", upload_progress, false); + req.addEventListener("error", upload_failed, false); + req.addEventListener("abort", upload_failed, false); + req.onreadystatechange = function () + { + if (req.readyState == 4 && req.status == 200) + { + var res = req.responseText; + if (res == "Error") + return; + res = res.split ("\n"); + if (time != 'none') + { + var d = new Date(); + if (time == 'minute') + d.setSeconds (d.getSeconds() + 60); + else if (time == 'hour') + d.setSeconds (d.getSeconds() + 3600); + else if (time == 'day') + d.setSeconds (d.getSeconds() + 86400); + else if (time == 'week') + d.setSeconds (d.getSeconds() + 604800); + else if (time == 'month') + d.setSeconds (d.getSeconds() + 2419200); + show_link (url, res[0], res[1], d.toString()); + } + else + show_link (url, res[0], res[1]); + } + } + req.open ("POST", url + 'script.php' , true); + + var form = new FormData(); + form.append ("file", file); + if (time) + form.append ("time", time); + if (password) + form.append ("key", password); + if (one_time) + form.append ("one_time_download", '1'); + req.send (form); +} + +function start_upload (url) +{ + upload (url, + document.getElementById('file_select').files[0], + document.getElementById('select_time').value, + document.getElementById('input_key').value, + document.getElementById('one_time_download').checked + ); +} \ No newline at end of file diff --git a/lib/functions.php b/lib/functions.php index e48534e..898b6fc 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -451,6 +451,32 @@ show_errors () } } +function check_errors () +{ + if (file_exists (JIRAFEAU_ROOT . 'install.php') + && !file_exists (JIRAFEAU_ROOT . 'lib/config.local.php')) + { + header('Location: install.php'); + exit; + } + + /* check if the destination dirs are writable */ + $writable = is_writable (VAR_FILES) && is_writable (VAR_LINKS); + + /* Checking for errors. */ + if (!is_writable (VAR_FILES)) + add_error (t('The file directory is not writable!'), VAR_FILES); + + if (!is_writable (VAR_LINKS)) + add_error (t('The link directory is not writable!'), VAR_LINKS); + + /* Check if the install.php script is still in the directory. */ + if (file_exists (JIRAFEAU_ROOT . 'install.php')) + add_error (t('Installer script still present'), + t('Please make sure to delete the installer script ' . + '"install.php" before continuing.')); +} + /** * Read link informations * @return array containing informations. diff --git a/lib/lang/fr.php b/lib/lang/fr.php index ed3110b..b25bd6c 100755 --- a/lib/lang/fr.php +++ b/lib/lang/fr.php @@ -20,7 +20,7 @@ $tr = array ( /* index.php */ 'Jirafeau, your web file repository' => 'Jirafeau, votre dépot de fichiers', - 'Upload a file' => 'Envoyer un fichier', + 'Select a file' => 'Sélectionnez un fichier', 'Send' => 'Envoyer', 'Uploading ...' => 'Envoie ...', 'One time download' => 'Téléchargement unique', @@ -35,8 +35,8 @@ $tr = array ( 'One day' => 'Une journée', 'One week' => 'Une semaine', 'One month' => 'Un mois', - 'The file directory is not writable!' => 'Le dossier \'file\' ne peut être écrit.', - 'The link directory is not writable!' => 'Le dossier \'link\' ne peut être écrit.', + 'The file directory is not writable' => 'Le dossier \'file\' ne peut être écrit.', + 'The link directory is not writable' => 'Le dossier \'link\' ne peut être écrit.', 'Installer script still present' => 'Le script d\'installation est toujours présent', 'Please make sure to delete the installer script "install.php" before continuing.' => 'Assurez vous de supprimer le fichier "install.php" avant de continuer.', 'An error occurred.' => 'Une erreur s\'est produite', diff --git a/lib/template/header.php b/lib/template/header.php index 53c8a0e..264cf34 100644 --- a/lib/template/header.php +++ b/lib/template/header.php @@ -29,6 +29,6 @@ else - +

diff --git a/media/industrial/style.css.php b/media/industrial/style.css.php index cb03725..2474b11 100755 --- a/media/industrial/style.css.php +++ b/media/industrial/style.css.php @@ -156,4 +156,28 @@ input:hover { .info p { margin-left: 5%; margin-right: 5%; -} \ No newline at end of file +} + +#upload { + text-align: center; + width: 30em; + background: #E2f5ff; + border: 2px solid #02233f; + margin: auto; +} + +#uploading { + text-align: center; + width: 30em; + background: #E2f5ff; + border: 2px solid #02233f; + margin: auto; +} + +#upload_finished { + text-align: center; + width: 60em; + background: #E2f5ff; + border: 2px solid #02233f; + margin: auto; +} diff --git a/script.php b/script.php index 8968aac..1d11050 100755 --- a/script.php +++ b/script.php @@ -30,19 +30,15 @@ require (JIRAFEAU_ROOT . 'lib/settings.php'); require (JIRAFEAU_ROOT . 'lib/functions.php'); require (JIRAFEAU_ROOT . 'lib/lang.php'); -if (file_exists (JIRAFEAU_ROOT . 'install.php')) -{ - header('Content-Type: text; charset=utf-8'); - echo "Error"; - exit; -} - global $script_langages; $script_langages = array ('bash' => 'Bash'); if ($_SERVER['REQUEST_METHOD'] == "GET" && count ($_GET) == 0) { require (JIRAFEAU_ROOT . 'lib/template/header.php'); + check_errors (); + if (has_error ()) + show_errors (); echo '
'; echo '

' . t('Welcome to Jirafeau\'s query interface') . '

'; echo '

';