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
25 define ('JIRAFEAU_ROOT', dirname (__FILE__
) . '/');
27 require (JIRAFEAU_ROOT
. 'lib/settings.php');
28 require (JIRAFEAU_ROOT
. 'lib/functions.php');
29 require (JIRAFEAU_ROOT
. 'lib/lang.php');
31 global $script_langages;
32 $script_langages = array ('bash' => 'Bash');
34 /* Operations may take a long time.
35 * Be sure PHP's safe mode is off.
41 if ($_SERVER['REQUEST_METHOD'] == "GET" && count ($_GET) == 0)
43 require (JIRAFEAU_ROOT
. 'lib/template/header.php');
48 require (JIRAFEAU_ROOT
. 'lib/template/footer.php');
53 <h2
>Scripting
interface</h2
>
54 <p
>This
interface permits to script your uploads
and downloads
.</p
>
55 <p
>See
<a href
="https://gitlab.com/mojo42/Jirafeau/blob/master/script.php">source code
</a
> of this
interface to get available calls
:)</p
>
56 <p
>Alternatively
, go to
<a href
="<?php echo $cfg['web_root'] . 'script.php?lang=bash'; ?>">this page
</a
> to download a bash script
.</p
>
60 require (JIRAFEAU_ROOT
. 'lib/template/footer.php');
64 /* Lets use interface now. */
65 header('Content-Type: text/plain; charset=utf-8');
75 if (isset ($_FILES['file']) && is_writable (VAR_FILES
)
76 && is_writable (VAR_LINKS
))
78 if (!jirafeau_challenge_upload_ip ($cfg, get_ip_address($cfg)))
84 if (jirafeau_has_upload_password ($cfg) &&
85 (!isset ($_POST['upload_password']) ||
86 !jirafeau_challenge_upload_password ($cfg, $_POST['upload_password'])))
93 if (isset ($_POST['key']))
97 if (!isset ($_POST['time']) ||
!$cfg['availabilities'][$_POST['time']])
99 echo 'Error 4: The parameter time is invalid.';
103 switch ($_POST['time'])
106 $time +
= JIRAFEAU_MINUTE
;
109 $time +
= JIRAFEAU_HOUR
;
112 $time +
= JIRAFEAU_DAY
;
115 $time +
= JIRAFEAU_WEEK
;
118 $time +
= JIRAFEAU_MONTH
;
121 $time +
= JIRAFEAU_QUARTER
;
124 $time +
= JIRAFEAU_YEAR
;
127 $time = JIRAFEAU_INFINITY
;
132 if ($cfg['maximal_upload_size'] > 0 &&
133 $_FILES['file']['size'] > $cfg['maximal_upload_size'] * 1024 * 1024)
135 echo 'Error 5: Your file exceeds the maximum authorized file size.';
139 $res = jirafeau_upload ($_FILES['file'],
140 isset ($_POST['one_time_download']),
141 $key, $time, get_ip_address($cfg),
142 $cfg['enable_crypt'], $cfg['link_name_length']);
144 if (empty($res) ||
$res['error']['has_error'])
146 echo 'Error 6 ' . $res['error']['why'];
149 /* Print direct link. */
151 /* Print delete link. */
153 echo $res['delete_link'];
154 /* Print decrypt key. */
156 echo urlencode($res['crypt_key']);
158 elseif (isset ($_GET['h']))
160 $link_name = $_GET['h'];
162 if (isset ($_POST['key']))
163 $key = $_POST['key'];
165 if (isset ($_GET['d']))
168 if (!preg_match ('/[0-9a-zA-Z_-]+$/', $link_name))
174 $link = jirafeau_get_link ($link_name);
175 if (count ($link) == 0)
180 if (strlen ($d) > 0 && $d == $link['link_code'])
182 jirafeau_delete_link ($link_name);
186 if ($link['time'] != JIRAFEAU_INFINITY
&& time () > $link['time'])
188 jirafeau_delete_link ($link_name);
192 if (strlen ($link['key']) > 0 && md5 ($key) != $link['key'])
198 $p = s2p ($link['md5']);
199 if (!file_exists (VAR_FILES
. $p . $link['md5']))
206 header ('Content-Length: ' . $link['file_size']);
207 header ('Content-Type: ' . $link['mime_type']);
208 header ('Content-Disposition: attachment; filename="' .
209 $link['file_name'] . '"');
211 $r = fopen (VAR_FILES
. $p . $link['md5'], 'r');
214 print fread ($r, 1024);
219 if ($link['onetime'] == 'O')
220 jirafeau_delete_link ($link_name);
223 elseif (isset ($_GET['get_capacity']))
225 echo min (jirafeau_ini_to_bytes (ini_get ('post_max_size')),
226 jirafeau_ini_to_bytes (ini_get ('upload_max_filesize')));
228 elseif (isset ($_GET['get_maximal_upload_size']))
230 echo $cfg['maximal_upload_size'];
232 elseif (isset ($_GET['get_version']))
234 echo JIRAFEAU_VERSION
;
236 elseif (isset ($_GET['lang']))
244 # This script has been auto-generated by Jirafeau but you can still edit options below.
247 proxy
='' # Or set JIRAFEAU_PROXY.
248 url
='<?php echo $cfg['web_root
']; ?>' # Or set JIRAFEAU_URL.
249 time
='<?php echo $cfg['availability_default
']; ?>' # Or set JIRAFEAU_TIME.
250 one_time
='' # Or set JIRAFEAU_ONE_TIME.
251 curl
='' # Or set JIRAFEAU_CURL_PATH.
254 if [ -n
"$JIRAFEAU_PROXY" ]; then
255 proxy
="$JIRAFEAU_PROXY"
258 if [ -n
"$JIRAFEAU_URL" ]; then
262 if [ -z
"$url" ]; then
263 echo "Please set url in script parameters or export JIRAFEAU_URL"
266 if [ -n
"$JIRAFEAU_TIME" ]; then
267 time
="$JIRAFEAU_TIME"
270 if [ -n
"$JIRAFEAU_ONE_TIME" ]; then
274 if [ -z
"$curl" ]; then
275 curl
="$JIRAFEAU_CURL_PATH"
278 if [ -z
"$curl" ] && [ -e
"/usr/bin/curl" ]; then
282 if [ -z
"$curl" ] && [ -e
"/bin/curl.exe" ]; then
286 if [ -z
"$curl" ]; then
287 echo "Please set your curl binary path (by editing this script or export JIRAFEAU_CURL_PATH global variable)."
292 echo "Jirafeau Bash Script <?php echo JIRAFEAU_VERSION; ?>"
293 echo "--------------------------"
298 echo " $0 send FILE [PASSWORD]"
299 echo " $0 get URL [PASSWORD]"
300 echo " $0 delete URL"
302 echo "Global variables to export:"
303 echo " JIRAFEAU_PROXY: Domain and port of proxy server, eg. »proxysever.example.com:3128«"
304 echo " JIRAFEAU_URL : URI to Jirafeau installation with trailing slash, eg. »https://example.com/jirafeau/«"
305 echo " JIRAFEAU_TIME : expiration time, eg. »minute«, »hour«, »day«, »week«, »month«, »quarter«, »year« or »none«"
306 echo " JIRAFEAU_ONE_TIME : self-destroy after first download, eg. »1« to enable or »« (empty) to disable"
307 echo " JIRAFEAU_CURL : alternative path to curl binary"
312 if [ -n
"$proxy" ]; then
317 if [ -n
"$one_time" ]; then
318 options
="$options -F one_time_download=1"
324 options
="$options -F key=$password"
330 if [ "$1" == "send" ]; then
331 if [ ! -f
"$2" ]; then
332 echo "File \"$2\" does not exists."
337 res
=$
($curl -X POST
--http1
.0
$proxy $options \
342 if [[ "$res" == Error
* ]]; then
343 echo "Error while uploading."
348 # Not using head or tail to minimise command dependencies
349 code
=$
(cnt
=0; echo "$res" |
while read l
; do
350 if [[ "$cnt" == "0" ]]; then
355 del_code
=$
(cnt
=0; echo "$res" |
while read l
; do
356 if [[ "$cnt" == "1" ]]; then
363 echo "Download page:"
364 echo " ${url}${downloadpage}?h=$code"
365 echo "Direct download:"
366 echo " ${url}${downloadpage}?h=$code&d=1"
368 echo " ${url}${downloadpage}?h=$code&d=$del_code"
370 echo "Download via API:"
371 echo " ${0} get ${url}${apipage}?h=$code [PASSWORD}"
372 echo "Delete via API:"
373 echo " ${0} delete ${url}${downloadpage}?h=$code&d=$del_code"
375 elif
[ "$1" == "get" ]; then
376 if [ -z
"$password" ]; then
377 $curl $proxy -OJ
"$2"
379 $curl $proxy -OJ
-X POST
-F key
=$password "$2"
381 elif
[ "$1" == "delete" ]; then
393 elseif (isset ($_GET['alias_create']))
395 $ip = get_ip_address($cfg);
396 if (!jirafeau_challenge_upload_ip ($cfg, $ip))
402 if (jirafeau_has_upload_password ($cfg) &&
403 (!isset ($_POST['upload_password']) ||
404 !jirafeau_challenge_upload_password ($cfg, $_POST['upload_password'])))
410 if (!isset ($_POST['alias']) ||
411 !isset ($_POST['destination']) ||
412 !isset ($_POST['password']))
418 echo jirafeau_alias_create ($_POST['alias'],
419 $_POST['destination'],
424 elseif (isset ($_GET['alias_get']))
426 if (!isset ($_POST['alias']))
432 echo jirafeau_alias_get ($_POST['alias']);
435 elseif (isset ($_GET['alias_update']))
437 if (!isset ($_POST['alias']) ||
438 !isset ($_POST['destination']) ||
439 !isset ($_POST['password']))
446 if (isset ($_POST['new_password']))
447 $new_password = $_POST['new_password'];
449 echo jirafeau_alias_update ($_POST['alias'],
450 $_POST['destination'],
453 get_ip_address($cfg));
456 elseif (isset ($_GET['alias_delete']))
458 if (!isset ($_POST['alias']) ||
459 !isset ($_POST['password']))
465 echo jirafeau_alias_delete ($_POST['alias'],
468 /* Initialize an asynchronous upload. */
469 elseif (isset ($_GET['init_async']))
471 if (!jirafeau_challenge_upload_ip ($cfg, get_ip_address($cfg)))
477 if (jirafeau_has_upload_password ($cfg) &&
478 (!isset ($_POST['upload_password']) ||
479 !jirafeau_challenge_upload_password ($cfg, $_POST['upload_password'])))
485 if (!isset ($_POST['filename']))
492 if (isset ($_POST['type']))
493 $type = $_POST['type'];
496 if (isset ($_POST['key']))
497 $key = $_POST['key'];
500 if (!isset ($_POST['time']) ||
!$cfg['availabilities'][$_POST['time']])
506 switch ($_POST['time'])
509 $time +
= JIRAFEAU_MINUTE
;
512 $time +
= JIRAFEAU_HOUR
;
515 $time +
= JIRAFEAU_DAY
;
518 $time +
= JIRAFEAU_WEEK
;
521 $time +
= JIRAFEAU_MONTH
;
524 $time +
= JIRAFEAU_QUARTER
;
527 $time +
= JIRAFEAU_YEAR
;
530 $time = JIRAFEAU_INFINITY
;
533 echo jirafeau_async_init ($_POST['filename'],
535 isset ($_POST['one_time_download']),
538 get_ip_address($cfg));
540 /* Continue an asynchronous upload. */
541 elseif (isset ($_GET['push_async']))
543 if ((!isset ($_POST['ref']))
544 ||
(!isset ($_FILES['data']))
545 ||
(!isset ($_POST['code'])))
549 echo jirafeau_async_push ($_POST['ref'],
552 $cfg['maximal_upload_size']);
555 /* Finalize an asynchronous upload. */
556 elseif (isset ($_GET['end_async']))
558 if (!isset ($_POST['ref'])
559 ||
!isset ($_POST['code']))
562 echo jirafeau_async_end ($_POST['ref'], $_POST['code'], $cfg['enable_crypt'], $cfg['link_name_length']);