]> git.p6c8.net - jirafeau_mojo42.git/blob - script.php
3185de720d5a3b2c188894fc23025b13f941a786
[jirafeau_mojo42.git] / script.php
1 <?php
2 /*
3 * Jirafeau, your web file repository
4 * Copyright (C) 2012 Jerome Jutteau <j.jutteau@gmail.com>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, either version 3 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 /*
21 * This file permits to easyly script file sending, receiving, deleting, ...
22 * If you don't want this feature, you can simply delete this file from your
23 * web directory.
24 */
25
26 define ('JIRAFEAU_ROOT', dirname (__FILE__) . '/');
27
28 require (JIRAFEAU_ROOT . 'lib/config.original.php');
29 require (JIRAFEAU_ROOT . 'lib/settings.php');
30 require (JIRAFEAU_ROOT . 'lib/functions.php');
31 require (JIRAFEAU_ROOT . 'lib/lang.php');
32
33 global $script_langages;
34 $script_langages = array ('bash' => 'Bash');
35
36 /* Operations may take a long time.
37 * Be sure PHP's safe mode is off.
38 */
39 @set_time_limit(0);
40 /* Remove errors. */
41 @error_reporting(0);
42
43 if ($_SERVER['REQUEST_METHOD'] == "GET" && count ($_GET) == 0)
44 {
45 require (JIRAFEAU_ROOT . 'lib/template/header.php');
46 check_errors ($cfg);
47 if (has_error ())
48 {
49 show_errors ();
50 require (JIRAFEAU_ROOT . 'lib/template/footer.php');
51 exit;
52 }
53 echo '<div class="info">';
54 echo '<h2>' . t('Welcome to Jirafeau\'s query interface') . '</h2>';
55 echo '<p>';
56 echo t('This interface permits to script your uploads and downloads.') .
57 ' ' . t('The instructions above show how to query this interface.');
58 echo '</p>';
59
60 echo '<h3>' . t('Get Jirafeau\'s version') . ':</h3>';
61 echo '<p>';
62 echo t('Send a GET query to') . ': <i>' . $web_root . 'script.php</i><br />';
63 echo '<br />';
64 echo t('Parameters') . ':<br />';
65 echo "<b>get_version=</b>1<i> (" . t('Required') . ")</i> <br />";
66 echo '</p>';
67 echo '<p>' . t('This will return brut text content.') . ' ' .
68 t('First line is the version number.') . '<br /></p>';
69 echo '<p>';
70 echo t('Example') . ": <a href=\"" . $web_root . "script.php?get_version=1\">" . $web_root . "script.php?get_version=1</a> ";
71 echo '</p>';
72
73 echo '<h3>' . t('Get server capacity') . ':</h3>';
74 echo '<p>';
75 echo t('Send a GET query to') . ': <i>' . $web_root . 'script.php</i><br />';
76 echo '<br />';
77 echo t('Parameters') . ':<br />';
78 echo "<b>get_capacity=</b>1<i> (" . t('Required') . ")</i> <br />";
79 echo '</p>';
80 echo '<p>' . t('This will return brut text content.') . ' ' .
81 t('First line is the server capacity (in Bytes).') . '<br /></p>';
82 echo '<p>';
83 echo t('Example') . ": <a href=\"" . $web_root . "script.php?get_capacity=1\">" . $web_root . "script.php?get_capacity=1</a> ";
84 echo '</p>';
85
86 echo '<h3>' . t('Upload a file') . ':</h3>';
87 echo '<p>';
88 echo t('Send a POST query to') . ': <i>' . $web_root . 'script.php</i><br />';
89 echo '<br />';
90 echo t('Parameters') . ':<br />';
91 echo "<b>file=</b>C:\\your\\file\\path<i> (" . t('Required') . ")</i> <br />";
92 echo "<b>time=</b>[minute|hour|day|week|month|none]<i> (" . t('Optional') . ', '. t('default: none') . ")</i> <br />";
93 echo "<b>password=</b>your_password<i> (" . t('Optional') . ")</i> <br />";
94 echo "<b>one_time_download=</b>1<i> (" . t('Optional') . ")</i> <br />";
95 echo '</p>';
96 echo '<p>' . t('This will return brut text content.') . ' ' .
97 t('First line is the download reference and the second line the delete code.') . '<br /></p>';
98
99 echo '<h3>' . t('Get a file') . ':</h3>';
100 echo '<p>';
101 echo t('Send a GET query to') . ': <i>' . $web_root . 'script.php</i><br />';
102 echo '<br />';
103 echo t('Parameters') . ':<br />';
104 echo "<b>h=</b>your_download_reference<i> (" . t('Required') . ")</i> <br />";
105 echo '</p>';
106 echo '<p>';
107 echo t('If a password has been set, send a POST request with it.');
108 echo '<br />';
109 echo t('Parameters') . ':<br />';
110 echo "<b>password=</b>your_password<i> (" . t('Optional') . ")</i> <br />";
111 echo '</p>';
112 echo '<p>';
113 echo t('Example') . ": <a href=\"" . $web_root . "script.php?h=30ngy0hsDcpfrF8zR7x9iU\">" . $web_root . "script.php?h=30ngy0hsDcpfrF8zR7x9iU</a> ";
114 echo '</p>';
115
116 echo '<h3>' . t('Delete a file') . ':</h3>';
117 echo '<p>';
118 echo t('Send a GET query to') . ': <i>' . $web_root . 'script.php</i><br />';
119 echo '<br />';
120 echo t('Parameters') . ':<br />';
121 echo "<b>h=</b>your_download_reference<i> (" . t('Required') . ")</i> <br />";
122 echo "<b>d=</b>yout_delete_code<i> (" . t('Required') . ")</i> <br />";
123 echo '</p>';
124 echo '<p>' . t('This will return "Ok" if succeded, "Error" otherwhise.') . '<br /></p>';
125 echo '<p>';
126 echo t('Example') . ": <a href=\"" . $web_root . "script.php?h=30ngy0hsDcpfrF8zR7x9iU&amp;d=0d210a952\">" . $web_root . "script.php?h=30ngy0hsDcpfrF8zR7x9iU&amp;d=0d210a952</a> ";
127 echo '</p>';
128
129 echo '<h3>' . t('Get a generated scripts') . ':</h3>';
130 echo '<p>';
131 echo t('Send a GET query to') . ': <i>' . $web_root . 'script.php</i><br />';
132 echo '<br />';
133 echo t('Parameters') . ':<br />';
134 echo "<b>lang=</b>[";
135 foreach ($script_langages as $lang => $name)
136 echo $lang;
137 echo "]<i> (" . t('Required') . ")</i> <br />";
138 echo '</p>';
139 echo '<p>' . t('This will return brut text content of the code.') . '<br /></p>';
140 echo '<p>';
141 echo t('Example') . ": <br />";
142 foreach ($script_langages as $lang => $name)
143 echo "$name: <a href=\"" . $web_root . "script.php?lang=$lang\">" . $web_root . "script.php?lang=$lang</a> ";
144 echo '</p>';
145
146 echo '<h3>' . t('Initalize a asynchronous transfert') . ':</h3>';
147 echo '<p>';
148 echo t('The goal is to permit to transfert big file, chunk by chunk.') . ' ';
149 echo t('Chunks of data must be sent in order.');
150 echo '</p>';
151 echo '<p>';
152 echo t('Send a GET query to') . ': <i>' . $web_root . 'script.php?init_async</i><br />';
153 echo '<br />';
154 echo t('Parameters') . ':<br />';
155 echo "<b>filename=</b>file_name.ext<i> (" . t('Required') . ")</i> <br />";
156 echo "<b>type=</b>MIME_TYPE<i> (" . t('Optional') . ")</i> <br />";
157 echo "<b>time=</b>[minute|hour|day|week|month|none]<i> (" . t('Optional') . ', '. t('default: none') . ")</i> <br />";
158 echo "<b>password=</b>your_password<i> (" . t('Optional') . ")</i> <br />";
159 echo "<b>one_time_download=</b>1<i> (" . t('Optional') . ")</i> <br />";
160 echo '</p>';
161 echo '<p>' . t('This will return brut text content.') . ' ' .
162 t('First line is the asynchronous transfert reference and the second line the code to use in the next operation.') . '<br /></p>';
163
164 echo '<h3>' . t('Push data during asynchronous transfert') . ':</h3>';
165 echo '<p>';
166 echo t('Send a GET query to') . ': <i>' . $web_root . 'script.php?push_async</i><br />';
167 echo '<br />';
168 echo t('Parameters') . ':<br />';
169 echo "<b>ref=</b>async_reference<i> (" . t('Required') . ")</i> <br />";
170 echo "<b>data=</b>data_chunk<i> (" . t('Required') . ")</i> <br />";
171 echo "<b>code=</b>last_provided_code<i> (" . t('Required') . ")</i> <br />";
172 echo '</p>';
173 echo '<p>' . t('This will return brut text content.') . ' ' .
174 t('Returns the next code to use.') . '<br /></p>';
175
176 echo '<h3>' . t('Finalize asynchronous transfert') . ':</h3>';
177 echo '<p>';
178 echo t('Send a GET query to') . ': <i>' . $web_root . 'script.php?end_async</i><br />';
179 echo '<br />';
180 echo t('Parameters') . ':<br />';
181 echo "<b>ref=</b>async_reference<i> (" . t('Required') . ")</i> <br />";
182 echo "<b>code=</b>last_provided_code<i> (" . t('Required') . ")</i> <br />";
183 echo '</p>';
184 echo '<p>' . t('This will return brut text content.') . ' ' .
185 t('First line is the download reference and the second line the delete code.') . '<br /></p>';
186
187 if ($cfg['enable_blocks'])
188 {
189 echo '<h3>' . t('Create a data block') . ':</h3>';
190 echo '<p>';
191 echo t('This interface permits to create a block of data filled with zeros.') .
192 ' ' . t('You can read selected parts, write (using a code) and delete the block.') .
193 ' ' . t('Blocks may be removed after a month of non usage.');
194 echo '</p>';
195 echo '<p>';
196 echo t('Send a GET query to') . ': <i>' . $web_root . 'script.php?init_block</i><br />';
197 echo '<br />';
198 echo t('Parameters') . ':<br />';
199 echo "<b>size=</b>size_in_bytes<i> (" . t('Required') . ")</i> <br />";
200 echo '</p>';
201 echo '<p>' . t('This will return brut text content.') . ' ' .
202 t('First line is a block id the second line the edit/delete code.') . '<br /></p>';
203
204 echo '<h3>' . t('Get block size') . ':</h3>';
205 echo '<p>';
206 echo t('Send a GET query to') . ': <i>' . $web_root . 'script.php?get_block_size</i><br />';
207 echo '<br />';
208 echo t('Parameters') . ':<br />';
209 echo "<b>id=</b>block_id<i> (" . t('Required') . ")</i> <br />";
210 echo '</p>';
211 echo '<p>' . t('This will return asked data or "Error" string.') . '<br /></p>';
212
213 echo '<h3>' . t('Read data in a block') . ':</h3>';
214 echo '<p>';
215 echo t('Send a GET query to') . ': <i>' . $web_root . 'script.php?read_block</i><br />';
216 echo '<br />';
217 echo t('Parameters') . ':<br />';
218 echo "<b>id=</b>block_id<i> (" . t('Required') . ")</i> <br />";
219 echo "<b>start=</b>byte_position_starting_from_zero<i> (" . t('Required') . ")</i> <br />";
220 echo "<b>length=</b>length_to_read_in_bytes<i> (" . t('Required') . ")</i> <br />";
221 echo '</p>';
222 echo '<p>' . t('This will return asked data or "Error" string.') . '<br /></p>';
223
224 echo '<h3>' . t('Write data in a block') . ':</h3>';
225 echo '<p>';
226 echo t('Send a GET query to') . ': <i>' . $web_root . 'script.php?write_block</i><br />';
227 echo '<br />';
228 echo t('Parameters') . ':<br />';
229 echo "<b>id=</b>block_id<i> (" . t('Required') . ")</i> <br />";
230 echo "<b>code=</b>block_code<i> (" . t('Required') . ")</i> <br />";
231 echo "<b>start=</b>byte_position_starting_from_zero<i> (" . t('Required') . ")</i> <br />";
232 echo "<b>data=</b>data_to_write<i> (" . t('Required') . ")</i> <br />";
233 echo '</p>';
234 echo '<p>' . t('This will return "Ok" or "Error" string.') . '<br /></p>';
235
236 echo '<h3>' . t('Delete a block') . ':</h3>';
237 echo '<p>';
238 echo t('Send a GET query to') . ': <i>' . $web_root . 'script.php?delete_block</i><br />';
239 echo '<br />';
240 echo t('Parameters') . ':<br />';
241 echo "<b>id=</b>block_id<i> (" . t('Required') . ")</i> <br />";
242 echo "<b>code=</b>block_code<i> (" . t('Required') . ")</i> <br />";
243 echo '</p>';
244 echo '<p>' . t('This will return "Ok" or "Error" string.') . '<br /></p>';
245 }
246
247 echo '</div><br />';
248 require (JIRAFEAU_ROOT . 'lib/template/footer.php');
249 exit;
250 }
251
252 /* Lets use interface now. */
253 header('Content-Type: text; charset=utf-8');
254
255 check_errors ($cfg);
256 if (has_error ())
257 {
258 echo "Error";
259 exit;
260 }
261
262 /* Upload file */
263 if (isset ($_FILES['file']) && is_writable (VAR_FILES)
264 && is_writable (VAR_LINKS))
265 {
266 if (strlen ($cfg['upload_password']) > 0 && (!isset ($_POST['upload_password']) || $_POST['upload_password'] != $cfg['upload_password']))
267 {
268 echo "Error";
269 exit;
270 }
271
272 $key = '';
273 if (isset ($_POST['key']))
274 $key = $_POST['key'];
275
276 $time = time ();
277 if (!isset ($_POST['time']))
278 $time = JIRAFEAU_INFINITY;
279 else
280 switch ($_POST['time'])
281 {
282 case 'minute':
283 $time += JIRAFEAU_MINUTE;
284 break;
285 case 'hour':
286 $time += JIRAFEAU_HOUR;
287 break;
288 case 'day':
289 $time += JIRAFEAU_DAY;
290 break;
291 case 'week':
292 $time += JIRAFEAU_WEEK;
293 break;
294 case 'month':
295 $time += JIRAFEAU_MONTH;
296 break;
297 default:
298 $time = JIRAFEAU_INFINITY;
299 break;
300 }
301 $res = jirafeau_upload ($_FILES['file'],
302 isset ($_POST['one_time_download']),
303 $key, $time, $_SERVER['REMOTE_ADDR'],
304 $cfg['enable_crypt'], $cfg['link_name_lenght']);
305
306 if (empty($res) || $res['error']['has_error'])
307 {
308 echo "Error";
309 exit;
310 }
311 /* Print direct link. */
312 echo $res['link'];
313 /* Print delete link. */
314 echo NL;
315 echo $res['delete_link'];
316 /* Print decrypt key. */
317 echo NL;
318 echo urlencode($res['crypt_key']);
319 }
320 elseif (isset ($_GET['h']))
321 {
322 $link_name = $_GET['h'];
323 $key = '';
324 if (isset ($_POST['key']))
325 $key = $_POST['key'];
326 $d = '';
327 if (isset ($_GET['d']))
328 $d = $_GET['d'];
329
330 if (!preg_match ('/[0-9a-zA-Z_-]+$/', $link_name))
331 {
332 echo "Error";
333 exit;
334 }
335
336 $link = jirafeau_get_link ($link_name);
337 if (count ($link) == 0)
338 {
339 echo "Error";
340 exit;
341 }
342 if (strlen ($d) > 0 && $d == $link['link_code'])
343 {
344 jirafeau_delete_link ($link_name);
345 echo "Ok";
346 exit;
347 }
348 if ($link['time'] != JIRAFEAU_INFINITY && time () > $link['time'])
349 {
350 jirafeau_delete_link ($link_name);
351 echo "Error";
352 exit;
353 }
354 if (strlen ($link['key']) > 0 && md5 ($key) != $link['key'])
355 {
356 echo "Error";
357 exit;
358 }
359 $p = s2p ($link['md5']);
360 if (!file_exists (VAR_FILES . $p . $link['md5']))
361 {
362 echo "Error";
363 exit;
364 }
365
366 /* Read file. */
367 header ('Content-Length: ' . $link['file_size']);
368 header ('Content-Type: ' . $link['mime_type']);
369 header ('Content-Disposition: attachment; filename="' .
370 $link['file_name'] . '"');
371
372 $r = fopen (VAR_FILES . $p . $link['md5'], 'r');
373 while (!feof ($r))
374 {
375 print fread ($r, 1024);
376 ob_flush();
377 }
378 fclose ($r);
379
380 if ($link['onetime'] == 'O')
381 jirafeau_delete_link ($link_name);
382 exit;
383 }
384 elseif (isset ($_GET['get_capacity']))
385 {
386 echo min (jirafeau_ini_to_bytes (ini_get ('post_max_size')),
387 jirafeau_ini_to_bytes (ini_get ('upload_max_filesize')));
388 }
389 elseif (isset ($_GET['get_version']))
390 {
391 echo JIRAFEAU_VERSION;
392 }
393 elseif (isset ($_GET['lang']))
394 {
395 $l=$_GET['lang'];
396 if ($l == "bash")
397 {
398 ?>
399 #!/bin/bash
400
401 # This script has been auto-generated by Jirafeau but you can still edit
402 # options below.
403
404 # Config
405 proxy='' # ex: proxy='proxysever.test.com:3128' or set JIRAFEAU_PROXY global variable
406 url='<?php echo $cfg['web_root'] . 'script.php'; ?>' # or set JIRAFEAU_URL ex: url='http://mysite/jirafeau/script.php'
407 time='none' # minute, hour, day, week, month or none. Or set JIRAFEAU_TIME.
408 one_time='' # ex: one_time="1" or set JIRAFEAU_ONE_TIME.
409 curl='' # curl path to download or set JIRAFEAU_CURL_PATH.
410 # End of config
411
412 if [ -n "$JIRAFEAU_PROXY" ]; then
413 proxy="$JIRAFEAU_PROXY"
414 fi
415
416 if [ -n "$JIRAFEAU_URL" ]; then
417 url="$JIRAFEAU_URL"
418 fi
419
420 if [ -z "$url" ]; then
421 echo "Please set url in script parameters or export JIRAFEAU_URL"
422 fi
423
424 if [ -n "$JIRAFEAU_TIME" ]; then
425 time="$JIRAFEAU_TIME"
426 fi
427
428 if [ -n "$JIRAFEAU_ONE_TIME" ]; then
429 one_time='1'
430 fi
431
432 if [ -z "$curl" ]; then
433 curl="$JIRAFEAU_CURL_PATH"
434 fi
435
436 if [ -z "$curl" ] && [ -e "/usr/bin/curl" ]; then
437 curl="/usr/bin/curl"
438 fi
439
440 if [ -z "$curl" ] && [ -e "/bin/curl.exe" ]; then
441 curl="/bin/curl.exe"
442 fi
443
444 if [ -z "$curl" ]; then
445 echo "Please set your curl binary path (by editing this script or export JIRAFEAU_CURL_PATH global variable)."
446 exit
447 fi
448
449 if [ -z "$2" ]; then
450 echo "man:"
451 echo " $0 send PATH [PASSWORD]"
452 echo " $0 get URL [PASSWORD]"
453 echo " $0 delete URL"
454 echo ""
455 echo "Global variables to export:"
456 echo " JIRAFEAU_PROXY : example: proxysever.test.com:3128"
457 echo " JIRAFEAU_URL : example: http://mysite/jirafeau/script.php"
458 echo " JIRAFEAU_TIME : minute, hour, day, week, month or none"
459 echo " JIRAFEAU_ONE_TIME : set anything or set empty"
460 echo " JIRAFEAU_CURL : path to your curl binary"
461
462 exit 0
463 fi
464
465 if [ -n "$proxy" ]; then
466 proxy="-x $proxy"
467 fi
468
469 options=''
470 if [ -n "$one_time" ]; then
471 options="$options -F one_time_download=1"
472 fi
473
474 password=''
475 if [ -n "$3" ]; then
476 password="$3"
477 options="$options -F key=$password"
478 fi
479
480 if [ "$1" == "send" ]; then
481 if [ ! -f "$2" ]; then
482 echo "File \"$2\" does not exists."
483 exit
484 fi
485
486 # Ret result
487 res=$($curl -X POST --http1.0 $proxy $options \
488 -F "time=$time" \
489 -F "file=@$2" \
490 $url)
491
492 if [[ "$res" == "Error" ]]; then
493 echo "Error while uploading."
494 exit
495 fi
496
497 # Not using head or tail to minimise command dependencies
498 code=$(cnt=0; echo "$res" | while read l; do
499 if [[ "$cnt" == "0" ]]; then
500 echo "$l"
501 fi
502 cnt=$(( cnt + 1 ))
503 done)
504 del_code=$(cnt=0; echo "$res" | while read l; do
505 if [[ "$cnt" == "1" ]]; then
506 echo "$l"
507 fi
508 cnt=$(( cnt + 1 ))
509 done)
510 echo "${url}?h=$code"
511 echo "${url}?h=$code&d=$del_code"
512 elif [ "$1" == "get" ]; then
513 if [ -z "$password" ]; then
514 $curl $proxy -OJ "$2"
515 else
516 $curl $proxy -OJ -X POST -F key=$password "$2"
517 fi
518 elif [ "$1" == "delete" ]; then
519 $curl $proxy "$2"
520 fi
521 <?php
522 }
523 else
524 {
525 echo "Error";
526 exit;
527 }
528 }
529 /* Initialize an asynchronous upload. */
530 elseif (isset ($_GET['init_async']))
531 {
532 if (strlen ($cfg['upload_password']) > 0 && (!isset ($_POST['upload_password']) || $_POST['upload_password'] != $cfg['upload_password']))
533 {
534 echo "Error";
535 exit;
536 }
537
538 if (!isset ($_POST['filename']))
539 {
540 echo "Error";
541 exit;
542 }
543
544 $type = '';
545 if (isset ($_POST['type']))
546 $type = $_POST['type'];
547
548 $key = '';
549 if (isset ($_POST['password']))
550 $key = $_POST['password'];
551
552 $time = time ();
553 if (!isset ($_POST['time']))
554 $time = JIRAFEAU_INFINITY;
555 else
556 switch ($_POST['time'])
557 {
558 case 'minute':
559 $time += JIRAFEAU_MINUTE;
560 break;
561 case 'hour':
562 $time += JIRAFEAU_HOUR;
563 break;
564 case 'day':
565 $time += JIRAFEAU_DAY;
566 break;
567 case 'week':
568 $time += JIRAFEAU_WEEK;
569 break;
570 case 'month':
571 $time += JIRAFEAU_MONTH;
572 break;
573 default:
574 $time = JIRAFEAU_INFINITY;
575 break;
576 }
577 echo jirafeau_async_init ($_POST['filename'],
578 $type,
579 isset ($_POST['one_time_download']),
580 $key,
581 $time,
582 $_SERVER['REMOTE_ADDR']);
583 }
584 /* Continue an asynchronous upload. */
585 elseif (isset ($_GET['push_async']))
586 {
587 if ((!isset ($_POST['ref']))
588 || (!isset ($_FILES['data']))
589 || (!isset ($_POST['code'])))
590 echo "Error";
591 else
592 echo jirafeau_async_push ($_POST['ref'], $_FILES['data'], $_POST['code']);
593 }
594 /* Finalize an asynchronous upload. */
595 elseif (isset ($_GET['end_async']))
596 {
597 if (!isset ($_POST['ref'])
598 || !isset ($_POST['code']))
599 echo "Error";
600 else
601 echo jirafeau_async_end ($_POST['ref'], $_POST['code'], $cfg['enable_crypt'], $cfg['link_name_lenght']);
602 }
603 /* Initialize block. */
604 elseif (isset ($_GET['init_block']) && $cfg['enable_blocks'])
605 {
606 if (strlen ($cfg['upload_password']) > 0 && (!isset ($_POST['upload_password']) || $_POST['upload_password'] != $cfg['upload_password']))
607 {
608 echo "Error";
609 exit;
610 }
611
612 if (!isset ($_POST['size']))
613 echo "Error";
614 else
615 echo jirafeau_block_init ($_POST['size']);
616 }
617 /* Get block size. */
618 elseif (isset ($_GET['get_block_size']) && $cfg['enable_blocks'])
619 {
620 if (!isset ($_POST['id']))
621 echo "Error";
622 else
623 echo jirafeau_block_get_size ($_POST['id']);
624 }
625 /* Read data in block. */
626 elseif (isset ($_GET['read_block']) && $cfg['enable_blocks'])
627 {
628 if (!isset ($_POST['id'])
629 || !isset ($_POST['start'])
630 || !isset ($_POST['length']))
631 echo "Error";
632 else
633 jirafeau_block_read ($_POST['id'], $_POST['start'], $_POST['length']);
634 }
635 /* Write data in block. */
636 elseif (isset ($_GET['write_block']) && $cfg['enable_blocks'])
637 {
638 if (!isset ($_POST['id'])
639 || !isset ($_POST['start'])
640 || !isset ($_FILES['data'])
641 || !isset ($_POST['code']))
642 echo "Error";
643 else
644 echo jirafeau_block_write ($_POST['id'], $_POST['start'], $_FILES['data'], $_POST['code']);
645 }
646 /* Delete block. */
647 elseif (isset ($_GET['delete_block']) && $cfg['enable_blocks'])
648 {
649 if (!isset ($_POST['id'])
650 || !isset ($_POST['code']))
651 echo "Error";
652 else
653 echo jirafeau_block_delete ($_POST['id'], $_POST['code']);
654 }
655 else
656 echo "Error";
657 exit;
658 ?>

patrick-canterino.de