X-Git-Url: https://git.p6c8.net/jirafeau.git/blobdiff_plain/18c82ef56dce9c9eb30b0f2318024d320d878a47..c4b50888f400fd7e0442431e859010450b55af4b:/script.php?ds=inline

diff --git a/script.php b/script.php
index 1d11050..2409f1b 100755
--- a/script.php
+++ b/script.php
@@ -33,12 +33,21 @@ 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);
+
 if ($_SERVER['REQUEST_METHOD'] == "GET" && count ($_GET) == 0)
 {
     require (JIRAFEAU_ROOT . 'lib/template/header.php');
     check_errors ();
     if (has_error ())
+    {
         show_errors ();
+        require (JIRAFEAU_ROOT . 'lib/template/footer.php');
+        exit;
+    }
     echo '<div class="info">';
     echo '<h2>' . t('Welcome to Jirafeau\'s query interface') . '</h2>';
     echo '<p>';
@@ -131,6 +140,107 @@ if ($_SERVER['REQUEST_METHOD'] == "GET" && count ($_GET) == 0)
     foreach ($script_langages as $lang => $name)
         echo "$name: <a href=\"" . $web_root . "script.php?lang=$lang\">" . $web_root . "script.php?lang=$lang</a> ";
     echo '</p>';
+    
+    echo '<h3>' . t('Initalize a asynchronous transfert') . ':</h3>';
+    echo '<p>';
+    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 '</p>';
+    echo '<p>';
+    echo t('Send a GET query to') . ': <i>' . $web_root . 'script.php?init_async</i><br />';
+    echo '<br />';
+    echo t('Parameters') . ':<br />';
+    echo "<b>filename=</b>file_name.ext<i> (" . t('Required') . ")</i> <br />";
+    echo "<b>type=</b>MIME_TYPE<i> (" . t('Optional') . ")</i> <br />";
+    echo "<b>time=</b>[minute|hour|day|week|month|none]<i> (" . t('Optional') . ', '. t('default: none') . ")</i> <br />";
+    echo "<b>password=</b>your_password<i> (" . t('Optional') . ")</i> <br />";
+    echo "<b>one_time_download=</b>1<i> (" . t('Optional') . ")</i> <br />";
+    echo '</p>';
+    echo '<p>' . 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.') . '<br /></p>';
+
+    echo '<h3>' . t('Push data during asynchronous transfert') . ':</h3>';
+    echo '<p>';
+    echo t('Send a GET query to') . ': <i>' . $web_root . 'script.php?push_async</i><br />';
+    echo '<br />';
+    echo t('Parameters') . ':<br />';
+    echo "<b>ref=</b>async_reference<i> (" . t('Required') . ")</i> <br />";
+    echo "<b>data=</b>data_chunk<i> (" . t('Required') . ")</i> <br />";
+    echo "<b>code=</b>last_provided_code<i> (" . t('Required') . ")</i> <br />";
+    echo '</p>';
+    echo '<p>' . t('This will return brut text content.') . ' ' .
+         t('Returns the next code to use.') . '<br /></p>';
+
+    echo '<h3>' . t('Finalize asynchronous transfert') . ':</h3>';
+    echo '<p>';
+    echo t('Send a GET query to') . ': <i>' . $web_root . 'script.php?end_async</i><br />';
+    echo '<br />';
+    echo t('Parameters') . ':<br />';
+    echo "<b>ref=</b>async_reference<i> (" . t('Required') . ")</i> <br />";
+    echo "<b>code=</b>last_provided_code<i> (" . t('Required') . ")</i> <br />";
+    echo '</p>';
+    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');
@@ -140,6 +250,13 @@ if ($_SERVER['REQUEST_METHOD'] == "GET" && count ($_GET) == 0)
 /* Lets use interface now. */
 header('Content-Type: text; charset=utf-8');
 
+check_errors ();
+if (has_error ())
+{
+    echo "Error";
+    exit;
+}
+
 /* Upload file */
 if (isset ($_FILES['file']) && is_writable (VAR_FILES)
     && is_writable (VAR_LINKS))
@@ -175,7 +292,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'])
     {
@@ -184,9 +302,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']))
 {
@@ -234,11 +355,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);
@@ -389,7 +518,121 @@ fi
         exit;
     }
 }
+/* Initialize an asynchronous upload. */
+elseif (isset ($_GET['init_async']))
+{
+    if (!isset ($_POST['filename']))
+    {
+        echo "Error";
+        exit;
+    }
+
+    $type = '';
+    if (isset ($_POST['type']))
+        $type = $_POST['type'];
+    
+    $key = '';
+    if (isset ($_POST['password']))
+        $key = $_POST['password'];
+
+    $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']);
+}
+/* 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;
-?>
\ No newline at end of file
+?>