X-Git-Url: https://git.p6c8.net/jirafeau_mojo42.git/blobdiff_plain/db5c05cc01e7874e0a7fc7518782ab37b39911a8..e4f9c92ff84f6146aaf1244147082efd57e289f6:/script.php
diff --git a/script.php b/script.php
old mode 100755
new mode 100644
index 6fd8626..09c7a8c
--- a/script.php
+++ b/script.php
@@ -25,7 +25,7 @@
define ('JIRAFEAU_ROOT', dirname (__FILE__) . '/');
-require (JIRAFEAU_ROOT . 'lib/config.php');
+require (JIRAFEAU_ROOT . 'lib/config.original.php');
require (JIRAFEAU_ROOT . 'lib/settings.php');
require (JIRAFEAU_ROOT . 'lib/functions.php');
require (JIRAFEAU_ROOT . 'lib/lang.php');
@@ -33,10 +33,17 @@ require (JIRAFEAU_ROOT . 'lib/lang.php');
global $script_langages;
$script_langages = array ('bash' => 'Bash');
+/* Operations may take a long time.
+ * Be sure PHP's safe mode is off.
+ */
+@set_time_limit(0);
+/* Remove errors. */
+@error_reporting(0);
+
if ($_SERVER['REQUEST_METHOD'] == "GET" && count ($_GET) == 0)
{
require (JIRAFEAU_ROOT . 'lib/template/header.php');
- check_errors ();
+ check_errors ($cfg);
if (has_error ())
{
show_errors ();
@@ -135,6 +142,47 @@ if ($_SERVER['REQUEST_METHOD'] == "GET" && count ($_GET) == 0)
foreach ($script_langages as $lang => $name)
echo "$name: " . $web_root . "script.php?lang=$lang ";
echo '
';
+
+ echo '' . t('Initalize a asynchronous transfert') . ':
';
+ echo '';
+ echo t('The goal is to permit to transfert big file, chunk by chunk.') . ' ';
+ echo t('Chunks of data must be sent in order.');
+ echo '
';
+ echo '';
+ echo t('Send a GET query to') . ': ' . $web_root . 'script.php?init_async
';
+ echo '
';
+ echo t('Parameters') . ':
';
+ echo "filename=file_name.ext (" . t('Required') . ")
";
+ echo "type=MIME_TYPE (" . t('Optional') . ")
";
+ echo "time=[minute|hour|day|week|month|none] (" . t('Optional') . ', '. t('default: none') . ")
";
+ echo "password=your_password (" . t('Optional') . ")
";
+ echo "one_time_download=1 (" . t('Optional') . ")
";
+ echo '
';
+ echo '' . t('This will return brut text content.') . ' ' .
+ t('First line is the asynchronous transfert reference and the second line the code to use in the next operation.') . '
';
+
+ echo '' . t('Push data during asynchronous transfert') . ':
';
+ echo '';
+ echo t('Send a GET query to') . ': ' . $web_root . 'script.php?push_async
';
+ echo '
';
+ echo t('Parameters') . ':
';
+ echo "ref=async_reference (" . t('Required') . ")
";
+ echo "data=data_chunk (" . t('Required') . ")
";
+ echo "code=last_provided_code (" . t('Required') . ")
";
+ echo '
';
+ echo '' . t('This will return brut text content.') . ' ' .
+ t('Returns the next code to use.') . '
';
+
+ echo '' . t('Finalize asynchronous transfert') . ':
';
+ echo '';
+ echo t('Send a GET query to') . ': ' . $web_root . 'script.php?end_async
';
+ echo '
';
+ echo t('Parameters') . ':
';
+ echo "ref=async_reference (" . t('Required') . ")
";
+ echo "code=last_provided_code (" . t('Required') . ")
";
+ echo '
';
+ echo '' . t('This will return brut text content.') . ' ' .
+ t('First line is the download reference and the second line the delete code.') . '
';
echo '
';
require (JIRAFEAU_ROOT . 'lib/template/footer.php');
@@ -144,10 +192,25 @@ if ($_SERVER['REQUEST_METHOD'] == "GET" && count ($_GET) == 0)
/* Lets use interface now. */
header('Content-Type: text; charset=utf-8');
+check_errors ($cfg);
+if (has_error ())
+{
+ echo "Error";
+ exit;
+}
+
/* Upload file */
if (isset ($_FILES['file']) && is_writable (VAR_FILES)
&& is_writable (VAR_LINKS))
{
+ if (jirafeau_has_upload_password ($cfg) &&
+ (!isset ($_POST['upload_password']) ||
+ !jirafeau_challenge_upload_password ($cfg, $_POST['upload_password'])))
+ {
+ echo "Error";
+ exit;
+ }
+
$key = '';
if (isset ($_POST['key']))
$key = $_POST['key'];
@@ -179,7 +242,8 @@ if (isset ($_FILES['file']) && is_writable (VAR_FILES)
}
$res = jirafeau_upload ($_FILES['file'],
isset ($_POST['one_time_download']),
- $key, $time, $_SERVER['REMOTE_ADDR']);
+ $key, $time, $_SERVER['REMOTE_ADDR'],
+ $cfg['enable_crypt'], $cfg['link_name_lenght']);
if (empty($res) || $res['error']['has_error'])
{
@@ -188,9 +252,12 @@ if (isset ($_FILES['file']) && is_writable (VAR_FILES)
}
/* Print direct link. */
echo $res['link'];
- echo NL;
/* Print delete link. */
+ echo NL;
echo $res['delete_link'];
+ /* Print decrypt key. */
+ echo NL;
+ echo urlencode($res['crypt_key']);
}
elseif (isset ($_GET['h']))
{
@@ -202,7 +269,7 @@ elseif (isset ($_GET['h']))
if (isset ($_GET['d']))
$d = $_GET['d'];
- if (!preg_match ('/[0-9a-zA-Z_-]{22}$/', $link_name))
+ if (!preg_match ('/[0-9a-zA-Z_-]+$/', $link_name))
{
echo "Error";
exit;
@@ -238,11 +305,19 @@ elseif (isset ($_GET['h']))
exit;
}
+ /* Read file. */
header ('Content-Length: ' . $link['file_size']);
header ('Content-Type: ' . $link['mime_type']);
header ('Content-Disposition: attachment; filename="' .
$link['file_name'] . '"');
- readfile (VAR_FILES . $p . $link['md5']);
+
+ $r = fopen (VAR_FILES . $p . $link['md5'], 'r');
+ while (!feof ($r))
+ {
+ print fread ($r, 1024);
+ ob_flush();
+ }
+ fclose ($r);
if ($link['onetime'] == 'O')
jirafeau_delete_link ($link_name);
@@ -393,7 +468,83 @@ fi
exit;
}
}
+/* Initialize an asynchronous upload. */
+elseif (isset ($_GET['init_async']))
+{
+ if (jirafeau_has_upload_password ($cfg) &&
+ (!isset ($_POST['upload_password']) ||
+ !jirafeau_challenge_upload_password ($cfg, $_POST['upload_password'])))
+ {
+ echo "Error";
+ exit;
+ }
+
+ if (!isset ($_POST['filename']))
+ {
+ echo "Error";
+ exit;
+ }
+
+ $type = '';
+ if (isset ($_POST['type']))
+ $type = $_POST['type'];
+
+ $key = '';
+ if (isset ($_POST['key']))
+ $key = $_POST['key'];
+
+ $time = time ();
+ if (!isset ($_POST['time']))
+ $time = JIRAFEAU_INFINITY;
+ else
+ 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;
+ }
+ echo jirafeau_async_init ($_POST['filename'],
+ $type,
+ isset ($_POST['one_time_download']),
+ $key,
+ $time,
+ $_SERVER['REMOTE_ADDR']);
+}
+/* Continue an asynchronous upload. */
+elseif (isset ($_GET['push_async']))
+{
+ if ((!isset ($_POST['ref']))
+ || (!isset ($_FILES['data']))
+ || (!isset ($_POST['code'])))
+ echo "Error";
+ else
+ echo jirafeau_async_push ($_POST['ref'], $_FILES['data'], $_POST['code']);
+}
+/* Finalize an asynchronous upload. */
+elseif (isset ($_GET['end_async']))
+{
+ if (!isset ($_POST['ref'])
+ || !isset ($_POST['code']))
+ echo "Error";
+ else
+ echo jirafeau_async_end ($_POST['ref'], $_POST['code'], $cfg['enable_crypt'], $cfg['link_name_lenght']);
+}
else
echo "Error";
exit;
-?>
\ No newline at end of file
+?>