X-Git-Url: https://git.p6c8.net/jirafeau_project.git/blobdiff_plain/2a71cdda5bacf89790a214a38174e5ced3ad07c0..8d85f9772ae53ce6a1902a967205f8ff1a290795:/script.php?ds=inline diff --git a/script.php b/script.php index eda2cc9..9bf9578 100755 --- a/script.php +++ b/script.php @@ -30,19 +30,24 @@ 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'); +/* 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 '
'; echo '

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

'; echo '

'; @@ -50,6 +55,19 @@ if ($_SERVER['REQUEST_METHOD'] == "GET" && count ($_GET) == 0) ' ' . t('The instructions above show how to query this interface.'); echo '

'; + echo '

' . t('Get Jirafeau\'s version') . ':

'; + echo '

'; + echo t('Send a GET query to') . ': ' . $web_root . 'script.php
'; + echo '
'; + echo t('Parameters') . ':
'; + echo "get_version=1 (" . t('Required') . ")
"; + echo '

'; + echo '

' . t('This will return brut text content.') . ' ' . + t('First line is the version number.') . '

'; + echo '

'; + echo t('Example') . ": " . $web_root . "script.php?get_version=1 "; + echo '

'; + echo '

' . t('Get server capacity') . ':

'; echo '

'; echo t('Send a GET query to') . ': ' . $web_root . 'script.php
'; @@ -122,6 +140,107 @@ 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.') . '

'; + + if ($cfg['enable_blocks']) + { + echo '

' . t('Create a data block') . ':

'; + echo '

'; + 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 '

'; + echo '

'; + echo t('Send a GET query to') . ': ' . $web_root . 'script.php?init_block
'; + echo '
'; + echo t('Parameters') . ':
'; + echo "size=size_in_bytes (" . t('Required') . ")
"; + echo '

'; + echo '

' . t('This will return brut text content.') . ' ' . + t('First line is a block id the second line the edit/delete code.') . '

'; + + echo '

' . t('Get block size') . ':

'; + echo '

'; + echo t('Send a GET query to') . ': ' . $web_root . 'script.php?get_block_size
'; + echo '
'; + echo t('Parameters') . ':
'; + echo "id=block_id (" . t('Required') . ")
"; + echo '

'; + echo '

' . t('This will return asked data or "Error" string.') . '

'; + + echo '

' . t('Read data in a block') . ':

'; + echo '

'; + echo t('Send a GET query to') . ': ' . $web_root . 'script.php?read_block
'; + echo '
'; + echo t('Parameters') . ':
'; + echo "id=block_id (" . t('Required') . ")
"; + echo "start=byte_position_starting_from_zero (" . t('Required') . ")
"; + echo "length=length_to_read_in_bytes (" . t('Required') . ")
"; + echo '

'; + echo '

' . t('This will return asked data or "Error" string.') . '

'; + + echo '

' . t('Write data in a block') . ':

'; + echo '

'; + echo t('Send a GET query to') . ': ' . $web_root . 'script.php?write_block
'; + echo '
'; + echo t('Parameters') . ':
'; + echo "id=block_id (" . t('Required') . ")
"; + echo "code=block_code (" . t('Required') . ")
"; + echo "start=byte_position_starting_from_zero (" . t('Required') . ")
"; + echo "data=data_to_write (" . t('Required') . ")
"; + echo '

'; + echo '

' . t('This will return "Ok" or "Error" string.') . '

'; + + echo '

' . t('Delete a block') . ':

'; + echo '

'; + echo t('Send a GET query to') . ': ' . $web_root . 'script.php?delete_block
'; + echo '
'; + echo t('Parameters') . ':
'; + echo "id=block_id (" . t('Required') . ")
"; + echo "code=block_code (" . t('Required') . ")
"; + echo '

'; + echo '

' . t('This will return "Ok" or "Error" string.') . '

'; + } echo '

'; require (JIRAFEAU_ROOT . 'lib/template/footer.php'); @@ -225,11 +344,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); @@ -240,6 +367,10 @@ elseif (isset ($_GET['get_capacity'])) echo min (jirafeau_ini_to_bytes (ini_get ('post_max_size')), jirafeau_ini_to_bytes (ini_get ('upload_max_filesize'))); } +elseif (isset ($_GET['get_version'])) +{ + echo JIRAFEAU_VERSION; +} elseif (isset ($_GET['lang'])) { $l=$_GET['lang']; @@ -376,7 +507,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']); +} +/* 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 +?>