if (!isset ($_POST['key']))
{
require (JIRAFEAU_ROOT.'lib/template/header.php');
- echo '<div id = "upload">' .
+ echo '<div>' .
'<form action = "' . $_SERVER['REQUEST_URI'] . '" ' .
'method = "post" id = "submit">'; ?>
<input type = "hidden" name = "jirafeau" value = "<?php echo JIRAFEAU_VERSION ?>"/><?php
if ($cfg['download_page'] && !$password_challenged && !$button_download && !$button_preview)
{
require (JIRAFEAU_ROOT.'lib/template/header.php');
- echo '<div id = "upload">' .
+ echo '<div>' .
'<form action = "' . $_SERVER['REQUEST_URI'] . '" ' .
'method = "post" id = "submit">'; ?>
<input type = "hidden" name = "jirafeau" value = "<?php echo JIRAFEAU_VERSION ?>"/><?php
<?php
/*
* Jirafeau, your web file repository
- * Copyright (C) 2008 Julien "axolotl" BERNARD <axolotl@magieeternelle.org>
* Copyright (C) 2012 Jerome Jutteau <j.jutteau@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
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 '<div class="message">'.NL;
- echo '<p>' . t('File uploaded! Copy the following URL to get it') .
- ':<br />' . NL;
- echo '<a href="'.$link.'">'.$link.'</a>' . NL;
-
- if ($time != JIRAFEAU_INFINITY)
- {
- echo '<br />' . t('This file is valid until the following date') .
- ':<br /><strong>' . strftime ('%c', $time) . '</strong>';
- }
-
- echo '</p></div>';
-
- echo '<div class="message">' . NL;
- echo '<p>' . t('Keep the following URL to delete it at any moment') . ':<br />' . NL;
- echo '<a href="' . $delete_link . '">' . $delete_link . '</a>' . NL;
- echo '</p></div>';
- }
-}
-
+check_errors ();
if (has_error ())
show_errors ();
-if (!has_error () && $writable)
-{
- ?><div id = "upload">
- <form enctype = "multipart/form-data" action = "
- <?php echo $cfg['web_root']; ?>" method =
- "post"> <div><input type = "hidden" name = "jirafeau" value = "
- <?php echo JIRAFEAU_VERSION; ?>" /></div> <fieldset>
- <legend><?php echo t('Upload a file');
- ?></legend> <p><input type = "file" name = "file" size =
- "30" /></p> <p class =
- "config"><?php printf ('%s: %s', t('Maximum file size'),
- jirafeau_get_max_upload_size ());
- ?></p><p>
- <input type = "submit" id='send' value ="<?php echo t('Send'); ?>"
+?>
+<div id="upload_finished">
+ <p>
+ <?php echo t('File uploaded! Copy the following URL to get it') ?>:
+ <br />
+ <a id="upload_link" href=""></a>
+ <br />
+ </p>
+
+ <p>
+ <?php echo t('Keep the following URL to delete it at any moment'); ?>:
+ <br />
+ <a id="delete_link" href=""></a>
+ </p>
+
+ <p id="validity">
+ <?php echo t('This file is valid until the following date'); ?>:
+ <br /><strong><div id="date"></div></strong>
+ </p>
+</div>
+
+<div id="uploading">
+ <p>
+ <?php echo t ('Uploading ...'); ?><div id="uploaded_percentage"></div>
+ </p>
+</div>
+
+<div id="upload">
+ <legend>
+ <?php echo t('Select a file'); ?> :
+ </legend>
+ <p>
+ <input type="file" id="file_select" size="30"
+ onchange="
+ document.getElementById('options').style.display = '';
+ document.getElementById('send').style.display = '';
+ "/>
+ </p>
+ <p class="config">
+ <?php echo t('Maximum file size') . ': ' . jirafeau_get_max_upload_size (); ?>
+ </p>
+ <p>
+ <input type="submit" id="send" value="<?php echo t('Send'); ?>"
onclick="
- document.getElementById('send').value='<?php echo t ('Uploading ...'); ?>';
- document.getElementById('send').submit ();
- document.getElementById('send').disabled='true';
+ document.getElementById('upload').style.display = 'none';
+ document.getElementById('uploading').style.display = '';
+ start_upload('<?php echo $cfg['web_root']; ?>');
"/>
- </p><hr /><div id = "moreoptions"> <p><label><input type =
- "checkbox" name =
- "one_time_download" /><?php echo t('One time download');
- ?></label></p><br/><p><label for = "input_key"
- ><?php echo t('Password') . ':';
- ?></label><input type = "text" name = "key" id = "input_key" /></p>
- <p><label for = "select_time"
- ><?php echo t('Time limit') . ':';
- ?></label>
- <select name = "time" id = "select_time">
- <option value = "none"><?php echo t('None');
- ?></option> <option value = "minute"><?php echo t('One minute');
- ?></option> <option value = "hour"><?php echo t('One hour');
- ?></option> <option value = "day"><?php echo t('One day');
- ?></option> <option value = "week"><?php echo t('One week');
- ?></option> <option value = "month"><?php echo t('One month');
- ?></option>
- </select> </p> </div> </fieldset> </form> </div> <?php
-}
-
-require (JIRAFEAU_ROOT.'lib/template/footer.php');
-?>
+ </p>
+ <div id="options">
+ <table id="option_table">
+ <tr>
+ <td><?php echo t('One time download'); ?>:</td>
+ <td><input type="checkbox" id="one_time_download" /></td>
+ </tr>
+ <tr>
+ <td><label for="input_key"><?php echo t('Password') . ':'; ?></label></td>
+ <td><input type="text" name="key" id="input_key" /></td>
+ </tr>
+ <tr>
+ <td><label for="select_time"><?php echo t('Time limit') . ':'; ?></label></td>
+ <td><select name="time" id="select_time">
+ <option value="none"><?php echo t('None'); ?></option>
+ <option value = "minute"><?php echo t('One minute'); ?></option>
+ <option value = "hour"><?php echo t('One hour'); ?></option>
+ <option value = "day"><?php echo t('One day'); ?></option>
+ <option value = "week"><?php echo t('One week'); ?></option>
+ <option value = "month"><?php echo t('One month');?></option>
+ </select></td>
+ </tr>
+ </table>
+ </div>
+</div>
+<script lang="Javascript">
+ document.getElementById('uploading').style.display = 'none';
+ document.getElementById('upload_finished').style.display = 'none';
+ document.getElementById('options').style.display = 'none';
+ document.getElementById('send').style.display = 'none';
+</script>
+<?php require (JIRAFEAU_ROOT . 'lib/template/footer.php'); ?>
--- /dev/null
+/*
+ * Jirafeau, your web file repository
+ * Copyright (C) 2012 Jerome Jutteau <j.jutteau@gmail.com>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+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
}
}
+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.
$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',
'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',
<link href="<?php echo $web_root . 'media/' . $style . '/style.css.php'; ?>" rel="stylesheet" type="text/css" />
</head>
<body>
-
+<script language="Javascript" src="lib/functions.js"></script>
<div id="content">
<h1><a href="<?php echo $web_root; ?>"><?php echo t('Jirafeau, your web file repository'); ?></a></h1>
.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;
+}
require (JIRAFEAU_ROOT . 'lib/functions.php');\r
require (JIRAFEAU_ROOT . 'lib/lang.php');\r
\r
-if (file_exists (JIRAFEAU_ROOT . 'install.php'))\r
-{\r
- header('Content-Type: text; charset=utf-8');\r
- echo "Error";\r
- exit;\r
-}\r
-\r
global $script_langages;\r
$script_langages = array ('bash' => 'Bash');\r
\r
if ($_SERVER['REQUEST_METHOD'] == "GET" && count ($_GET) == 0)\r
{\r
require (JIRAFEAU_ROOT . 'lib/template/header.php');\r
+ check_errors ();\r
+ if (has_error ())\r
+ show_errors ();\r
echo '<div class="info">';\r
echo '<h2>' . t('Welcome to Jirafeau\'s query interface') . '</h2>';\r
echo '<p>';\r