3 * Jirafeau, your web file repository
4 * Copyright (C) 2015 Jerome Jutteau <j.jutteau@gmail.com>
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.
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.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
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
26 define ('JIRAFEAU_ROOT', dirname (__FILE__
) . '/');
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');
33 global $script_langages;
34 $script_langages = array ('bash' => 'Bash');
36 /* Operations may take a long time.
37 * Be sure PHP's safe mode is off.
43 if ($_SERVER['REQUEST_METHOD'] == "GET" && count ($_GET) == 0)
45 require (JIRAFEAU_ROOT
. 'lib/template/header.php');
50 require (JIRAFEAU_ROOT
. 'lib/template/footer.php');
55 <h2
>Scripting
interface</h2
>
56 <p
>This
interface permits to script your uploads
and downloads
.</p
>
57 <p
>See
<a href
="https://gitlab.com/mojo42/Jirafeau/blob/master/script.php">source code
</a
> of this
interface to get available calls
:)</p
>
58 <p
>Alternatively
, go to
<a href
="<?php echo $cfg['web_root'] . 'script.php?lang=bash'; ?>">this page
</a
> to download a bash script
.</p
>
62 require (JIRAFEAU_ROOT
. 'lib/template/footer.php');
66 /* Lets use interface now. */
67 header('Content-Type: text/plain; charset=utf-8');
77 if (isset ($_FILES['file']) && is_writable (VAR_FILES
)
78 && is_writable (VAR_LINKS
))
80 if (!jirafeau_challenge_upload_ip ($cfg, get_ip_address($cfg)))
86 if (jirafeau_has_upload_password ($cfg) &&
87 (!isset ($_POST['upload_password']) ||
88 !jirafeau_challenge_upload_password ($cfg, $_POST['upload_password'])))
95 if (isset ($_POST['key']))
99 if (!isset ($_POST['time']) ||
!$cfg['availabilities'][$_POST['time']])
101 echo 'Error 4: The parameter time is invalid.';
105 switch ($_POST['time'])
108 $time +
= JIRAFEAU_MINUTE
;
111 $time +
= JIRAFEAU_HOUR
;
114 $time +
= JIRAFEAU_DAY
;
117 $time +
= JIRAFEAU_WEEK
;
120 $time +
= JIRAFEAU_MONTH
;
123 $time +
= JIRAFEAU_QUARTER
;
126 $time +
= JIRAFEAU_YEAR
;
129 $time = JIRAFEAU_INFINITY
;
134 if ($cfg['maximal_upload_size'] > 0 &&
135 $_FILES['file']['size'] > $cfg['maximal_upload_size'] * 1024 * 1024)
137 echo 'Error 5: Your file exceeds the maximum authorized file size.';
141 $res = jirafeau_upload ($_FILES['file'],
142 isset ($_POST['one_time_download']),
143 $key, $time, get_ip_address($cfg),
144 $cfg['enable_crypt'], $cfg['link_name_length']);
146 if (empty($res) ||
$res['error']['has_error'])
148 echo 'Error 6 ' . $res['error']['why'];
151 /* Print direct link. */
153 /* Print delete link. */
155 echo $res['delete_link'];
156 /* Print decrypt key. */
158 echo urlencode($res['crypt_key']);
160 elseif (isset ($_GET['h']))
162 $link_name = $_GET['h'];
164 if (isset ($_POST['key']))
165 $key = $_POST['key'];
167 if (isset ($_GET['d']))
170 if (!preg_match ('/[0-9a-zA-Z_-]+$/', $link_name))
176 $link = jirafeau_get_link ($link_name);
177 if (count ($link) == 0)
182 if (strlen ($d) > 0 && $d == $link['link_code'])
184 jirafeau_delete_link ($link_name);
188 if ($link['time'] != JIRAFEAU_INFINITY
&& time () > $link['time'])
190 jirafeau_delete_link ($link_name);
194 if (strlen ($link['key']) > 0 && md5 ($key) != $link['key'])
200 $p = s2p ($link['md5']);
201 if (!file_exists (VAR_FILES
. $p . $link['md5']))
208 header ('Content-Length: ' . $link['file_size']);
209 header ('Content-Type: ' . $link['mime_type']);
210 header ('Content-Disposition: attachment; filename="' .
211 $link['file_name'] . '"');
213 $r = fopen (VAR_FILES
. $p . $link['md5'], 'r');
216 print fread ($r, 1024);
221 if ($link['onetime'] == 'O')
222 jirafeau_delete_link ($link_name);
225 elseif (isset ($_GET['get_capacity']))
227 echo min (jirafeau_ini_to_bytes (ini_get ('post_max_size')),
228 jirafeau_ini_to_bytes (ini_get ('upload_max_filesize')));
230 elseif (isset ($_GET['get_maximal_upload_size']))
232 echo $cfg['maximal_upload_size'];
234 elseif (isset ($_GET['get_version']))
236 echo JIRAFEAU_VERSION
;
238 elseif (isset ($_GET['lang']))
246 # This script has been auto-generated by Jirafeau but you can still edit options below.
249 proxy
='' # Or set JIRAFEAU_PROXY.
250 url
='<?php echo $cfg['web_root
']; ?>' # Or set JIRAFEAU_URL.
251 time
='<?php echo $cfg['availability_default
']; ?>' # Or set JIRAFEAU_TIME.
252 one_time
='' # Or set JIRAFEAU_ONE_TIME.
253 curl
='' # Or set JIRAFEAU_CURL_PATH.
256 if [ -n
"$JIRAFEAU_PROXY" ]; then
257 proxy
="$JIRAFEAU_PROXY"
260 if [ -n
"$JIRAFEAU_URL" ]; then
264 if [ -z
"$url" ]; then
265 echo "Please set url in script parameters or export JIRAFEAU_URL"
268 if [ -n
"$JIRAFEAU_TIME" ]; then
269 time
="$JIRAFEAU_TIME"
272 if [ -n
"$JIRAFEAU_ONE_TIME" ]; then
276 if [ -z
"$curl" ]; then
277 curl
="$JIRAFEAU_CURL_PATH"
280 if [ -z
"$curl" ] && [ -e
"/usr/bin/curl" ]; then
284 if [ -z
"$curl" ] && [ -e
"/bin/curl.exe" ]; then
288 if [ -z
"$curl" ]; then
289 echo "Please set your curl binary path (by editing this script or export JIRAFEAU_CURL_PATH global variable)."
294 echo "Jirafeau Bash Script <?php echo JIRAFEAU_VERSION; ?>"
295 echo "--------------------------"
300 echo " $0 send FILE [PASSWORD]"
301 echo " $0 get URL [PASSWORD]"
302 echo " $0 delete URL"
304 echo "Global variables to export:"
305 echo " JIRAFEAU_PROXY: Domain and port of proxy server, eg. »proxysever.example.com:3128«"
306 echo " JIRAFEAU_URL : URI to Jirafeau installation with trailing slash, eg. »https://example.com/jirafeau/«"
307 echo " JIRAFEAU_TIME : expiration time, eg. »minute«, »hour«, »day«, »week«, »month«, »quarter«, »year« or »none«"
308 echo " JIRAFEAU_ONE_TIME : self-destroy after first download, eg. »1« to enable or »« (empty) to disable"
309 echo " JIRAFEAU_CURL : alternative path to curl binary"
314 if [ -n
"$proxy" ]; then
319 if [ -n
"$one_time" ]; then
320 options
="$options -F one_time_download=1"
326 options
="$options -F key=$password"
332 if [ "$1" == "send" ]; then
333 if [ ! -f
"$2" ]; then
334 echo "File \"$2\" does not exists."
339 res
=$
($curl -X POST
--http1
.0
$proxy $options \
344 if [[ "$res" == Error
* ]]; then
345 echo "Error while uploading."
350 # Not using head or tail to minimise command dependencies
351 code
=$
(cnt
=0; echo "$res" |
while read l
; do
352 if [[ "$cnt" == "0" ]]; then
357 del_code
=$
(cnt
=0; echo "$res" |
while read l
; do
358 if [[ "$cnt" == "1" ]]; then
365 echo "Download page:"
366 echo " ${url}${downloadpage}?h=$code"
367 echo "Direct download:"
368 echo " ${url}${downloadpage}?h=$code&d=1"
370 echo " ${url}${downloadpage}?h=$code&d=$del_code"
372 echo "Download via API:"
373 echo " ${0} get ${url}${apipage}?h=$code [PASSWORD}"
374 echo "Delete via API:"
375 echo " ${0} delete ${url}${downloadpage}?h=$code&d=$del_code"
377 elif
[ "$1" == "get" ]; then
378 if [ -z
"$password" ]; then
379 $curl $proxy -OJ
"$2"
381 $curl $proxy -OJ
-X POST
-F key
=$password "$2"
383 elif
[ "$1" == "delete" ]; then
395 elseif (isset ($_GET['alias_create']))
397 $ip = get_ip_address($cfg);
398 if (!jirafeau_challenge_upload_ip ($cfg, $ip))
404 if (jirafeau_has_upload_password ($cfg) &&
405 (!isset ($_POST['upload_password']) ||
406 !jirafeau_challenge_upload_password ($cfg, $_POST['upload_password'])))
412 if (!isset ($_POST['alias']) ||
413 !isset ($_POST['destination']) ||
414 !isset ($_POST['password']))
420 echo jirafeau_alias_create ($_POST['alias'],
421 $_POST['destination'],
426 elseif (isset ($_GET['alias_get']))
428 if (!isset ($_POST['alias']))
434 echo jirafeau_alias_get ($_POST['alias']);
437 elseif (isset ($_GET['alias_update']))
439 if (!isset ($_POST['alias']) ||
440 !isset ($_POST['destination']) ||
441 !isset ($_POST['password']))
448 if (isset ($_POST['new_password']))
449 $new_password = $_POST['new_password'];
451 echo jirafeau_alias_update ($_POST['alias'],
452 $_POST['destination'],
455 get_ip_address($cfg));
458 elseif (isset ($_GET['alias_delete']))
460 if (!isset ($_POST['alias']) ||
461 !isset ($_POST['password']))
467 echo jirafeau_alias_delete ($_POST['alias'],
470 /* Initialize an asynchronous upload. */
471 elseif (isset ($_GET['init_async']))
473 if (!jirafeau_challenge_upload_ip ($cfg, get_ip_address($cfg)))
479 if (jirafeau_has_upload_password ($cfg) &&
480 (!isset ($_POST['upload_password']) ||
481 !jirafeau_challenge_upload_password ($cfg, $_POST['upload_password'])))
487 if (!isset ($_POST['filename']))
494 if (isset ($_POST['type']))
495 $type = $_POST['type'];
498 if (isset ($_POST['key']))
499 $key = $_POST['key'];
502 if (!isset ($_POST['time']) ||
!$cfg['availabilities'][$_POST['time']])
508 switch ($_POST['time'])
511 $time +
= JIRAFEAU_MINUTE
;
514 $time +
= JIRAFEAU_HOUR
;
517 $time +
= JIRAFEAU_DAY
;
520 $time +
= JIRAFEAU_WEEK
;
523 $time +
= JIRAFEAU_MONTH
;
526 $time +
= JIRAFEAU_QUARTER
;
529 $time +
= JIRAFEAU_YEAR
;
532 $time = JIRAFEAU_INFINITY
;
535 echo jirafeau_async_init ($_POST['filename'],
537 isset ($_POST['one_time_download']),
540 get_ip_address($cfg));
542 /* Continue an asynchronous upload. */
543 elseif (isset ($_GET['push_async']))
545 if ((!isset ($_POST['ref']))
546 ||
(!isset ($_FILES['data']))
547 ||
(!isset ($_POST['code'])))
551 echo jirafeau_async_push ($_POST['ref'],
554 $cfg['maximal_upload_size']);
557 /* Finalize an asynchronous upload. */
558 elseif (isset ($_GET['end_async']))
560 if (!isset ($_POST['ref'])
561 ||
!isset ($_POST['code']))
564 echo jirafeau_async_end ($_POST['ref'], $_POST['code'], $cfg['enable_crypt'], $cfg['link_name_length']);