X-Git-Url: https://git.p6c8.net/jirafeau_project.git/blobdiff_plain/3d9792a36b5bb18d24216eea4b0ad402358db997..e4f9c92ff84f6146aaf1244147082efd57e289f6:/script.php

diff --git a/script.php b/script.php
old mode 100755
new mode 100644
index 1d420b6..09c7a8c
--- a/script.php
+++ b/script.php
@@ -36,12 +36,14 @@ require (JIRAFEAU_ROOT . 'lib/lang.php');
 /* Operations may take a long time.
  * Be sure PHP's safe mode is off.
  */
- set_time_limit(0);
+@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 ();
@@ -182,66 +184,6 @@ if ($_SERVER['REQUEST_METHOD'] == "GET" && count ($_GET) == 0)
     echo '<p>' . t('This will return brut text content.') . ' ' .
          t('First line is the download reference and the second line the delete code.') . '<br /></p>';
 
-    if ($cfg['enable_blocks'])
-    {
-        echo '<h3>' . t('Create a data block') . ':</h3>';
-        echo '<p>';
-        echo t('This interface permits to create a block of data filled with zeros.') .
-            ' ' . t('You can read selected parts, write (using a code) and delete the block.') .
-            ' ' . t('Blocks may be removed after a month of non usage.');
-        echo '</p>';
-        echo '<p>';
-        echo t('Send a GET query to') . ': <i>' . $web_root . 'script.php?init_block</i><br />';
-        echo '<br />';
-        echo t('Parameters') . ':<br />';
-        echo "<b>size=</b>size_in_bytes<i> (" . t('Required') . ")</i> <br />";
-        echo '</p>';
-        echo '<p>' . t('This will return brut text content.') . ' ' .
-             t('First line is a block id the second line the edit/delete code.') . '<br /></p>';
-
-        echo '<h3>' . t('Get block size') . ':</h3>';
-        echo '<p>';
-        echo t('Send a GET query to') . ': <i>' . $web_root . 'script.php?get_block_size</i><br />';
-        echo '<br />';
-        echo t('Parameters') . ':<br />';
-        echo "<b>id=</b>block_id<i> (" . t('Required') . ")</i> <br />";
-        echo '</p>';
-        echo '<p>' . t('This will return asked data or "Error" string.') . '<br /></p>';
-
-        echo '<h3>' . t('Read data in a block') . ':</h3>';
-        echo '<p>';
-        echo t('Send a GET query to') . ': <i>' . $web_root . 'script.php?read_block</i><br />';
-        echo '<br />';
-        echo t('Parameters') . ':<br />';
-        echo "<b>id=</b>block_id<i> (" . t('Required') . ")</i> <br />";
-        echo "<b>start=</b>byte_position_starting_from_zero<i> (" . t('Required') . ")</i> <br />";
-        echo "<b>length=</b>length_to_read_in_bytes<i> (" . t('Required') . ")</i> <br />";
-        echo '</p>';
-        echo '<p>' . t('This will return asked data or "Error" string.') . '<br /></p>';
-
-        echo '<h3>' . t('Write data in a block') . ':</h3>';
-        echo '<p>';
-        echo t('Send a GET query to') . ': <i>' . $web_root . 'script.php?write_block</i><br />';
-        echo '<br />';
-        echo t('Parameters') . ':<br />';
-        echo "<b>id=</b>block_id<i> (" . t('Required') . ")</i> <br />";
-        echo "<b>code=</b>block_code<i> (" . t('Required') . ")</i> <br />";
-        echo "<b>start=</b>byte_position_starting_from_zero<i> (" . t('Required') . ")</i> <br />";
-        echo "<b>data=</b>data_to_write<i> (" . t('Required') . ")</i> <br />";
-        echo '</p>';
-        echo '<p>' . t('This will return "Ok" or "Error" string.') . '<br /></p>';
-
-        echo '<h3>' . t('Delete a block') . ':</h3>';
-        echo '<p>';
-        echo t('Send a GET query to') . ': <i>' . $web_root . 'script.php?delete_block</i><br />';
-        echo '<br />';
-        echo t('Parameters') . ':<br />';
-        echo "<b>id=</b>block_id<i> (" . t('Required') . ")</i> <br />";
-        echo "<b>code=</b>block_code<i> (" . t('Required') . ")</i> <br />";
-        echo '</p>';
-        echo '<p>' . t('This will return "Ok" or "Error" string.') . '<br /></p>';
-    }
-
     echo '</div><br />';
     require (JIRAFEAU_ROOT . 'lib/template/footer.php');
     exit;
@@ -250,7 +192,7 @@ if ($_SERVER['REQUEST_METHOD'] == "GET" && count ($_GET) == 0)
 /* Lets use interface now. */
 header('Content-Type: text; charset=utf-8');
 
-check_errors ();
+check_errors ($cfg);
 if (has_error ())
 {
     echo "Error";
@@ -261,6 +203,14 @@ if (has_error ())
 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'];
@@ -521,6 +471,14 @@ fi
 /* 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";
@@ -532,8 +490,8 @@ elseif (isset ($_GET['init_async']))
         $type = $_POST['type'];
     
     $key = '';
-    if (isset ($_POST['password']))
-        $key = $_POST['password'];
+    if (isset ($_POST['key']))
+        $key = $_POST['key'];
 
     $time = time ();
     if (!isset ($_POST['time']))
@@ -586,52 +544,6 @@ elseif (isset ($_GET['end_async']))
     else
         echo jirafeau_async_end ($_POST['ref'], $_POST['code'], $cfg['enable_crypt'], $cfg['link_name_lenght']);
 }
-/* Initialize block. */
-elseif (isset ($_GET['init_block']) && $cfg['enable_blocks'])
-{
-    if (!isset ($_POST['size']))
-        echo "Error";
-    else
-        echo jirafeau_block_init ($_POST['size']);
-}
-/* Get block size. */
-elseif (isset ($_GET['get_block_size']) && $cfg['enable_blocks'])
-{
-    if (!isset ($_POST['id']))
-        echo "Error";
-    else
-        echo jirafeau_block_get_size ($_POST['id']);
-}
-/* Read data in block. */
-elseif (isset ($_GET['read_block']) && $cfg['enable_blocks'])
-{
-    if (!isset ($_POST['id'])
-        || !isset ($_POST['start'])
-        || !isset ($_POST['length']))
-        echo "Error";
-    else
-        jirafeau_block_read ($_POST['id'], $_POST['start'], $_POST['length']);
-}
-/* Write data in block. */
-elseif (isset ($_GET['write_block']) && $cfg['enable_blocks'])
-{
-    if (!isset ($_POST['id'])
-        || !isset ($_POST['start'])
-        || !isset ($_FILES['data'])
-        || !isset ($_POST['code']))
-        echo "Error";
-    else
-        echo jirafeau_block_write ($_POST['id'], $_POST['start'], $_FILES['data'], $_POST['code']);
-}
-/* Delete block. */
-elseif (isset ($_GET['delete_block']) && $cfg['enable_blocks'])
-{
-    if (!isset ($_POST['id'])
-        || !isset ($_POST['code']))
-        echo "Error";
-    else
-        echo jirafeau_block_delete ($_POST['id'], $_POST['code']);
-}
 else
     echo "Error";
 exit;