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; 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_YEAR
;
126 $time = JIRAFEAU_INFINITY
;
131 if ($cfg['maximal_upload_size'] > 0 &&
132 $_FILES['file']['size'] > $cfg['maximal_upload_size'] * 1024 * 1024)
134 echo 'Error 5: Your file exceeds the maximum authorized file size.';
138 $res = jirafeau_upload ($_FILES['file'],
139 isset ($_POST['one_time_download']),
140 $key, $time, get_ip_address($cfg),
141 $cfg['enable_crypt'], $cfg['link_name_length']);
143 if (empty($res) ||
$res['error']['has_error'])
145 echo 'Error 6 ' . $res['error']['why'];
148 /* Print direct link. */
150 /* Print delete link. */
152 echo $res['delete_link'];
153 /* Print decrypt key. */
155 echo urlencode($res['crypt_key']);
157 elseif (isset ($_GET['h']))
159 $link_name = $_GET['h'];
161 if (isset ($_POST['key']))
162 $key = $_POST['key'];
164 if (isset ($_GET['d']))
167 if (!preg_match ('/[0-9a-zA-Z_-]+$/', $link_name))
173 $link = jirafeau_get_link ($link_name);
174 if (count ($link) == 0)
179 if (strlen ($d) > 0 && $d == $link['link_code'])
181 jirafeau_delete_link ($link_name);
185 if ($link['time'] != JIRAFEAU_INFINITY
&& time () > $link['time'])
187 jirafeau_delete_link ($link_name);
191 if (strlen ($link['key']) > 0 && md5 ($key) != $link['key'])
197 $p = s2p ($link['md5']);
198 if (!file_exists (VAR_FILES
. $p . $link['md5']))
205 header ('Content-Length: ' . $link['file_size']);
206 header ('Content-Type: ' . $link['mime_type']);
207 header ('Content-Disposition: attachment; filename="' .
208 $link['file_name'] . '"');
210 $r = fopen (VAR_FILES
. $p . $link['md5'], 'r');
213 print fread ($r, 1024);
218 if ($link['onetime'] == 'O')
219 jirafeau_delete_link ($link_name);
222 elseif (isset ($_GET['get_capacity']))
224 echo min (jirafeau_ini_to_bytes (ini_get ('post_max_size')),
225 jirafeau_ini_to_bytes (ini_get ('upload_max_filesize')));
227 elseif (isset ($_GET['get_maximal_upload_size']))
229 echo $cfg['maximal_upload_size'];
231 elseif (isset ($_GET['get_version']))
233 echo JIRAFEAU_VERSION
;
235 elseif (isset ($_GET['lang']))
243 # This script has been auto-generated by Jirafeau but you can still edit
247 proxy
='' # ex: proxy='proxysever.test.com:3128' or set JIRAFEAU_PROXY global variable
248 url
='<?php echo $cfg['web_root
'] . 'script
.php
'; ?>' # or set JIRAFEAU_URL ex: url='http://mysite/jirafeau/script.php'
249 time
='<?php echo $cfg['availability_default
']; ?>' # minute, hour, day, week, month, year or none. Or set JIRAFEAU_TIME.
250 one_time
='' # ex: one_time="1" or set JIRAFEAU_ONE_TIME.
251 curl
='' # curl path to download 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)."
293 echo " $0 send PATH [PASSWORD]"
294 echo " $0 get URL [PASSWORD]"
295 echo " $0 delete URL"
297 echo "Global variables to export:"
298 echo " JIRAFEAU_PROXY : example: proxysever.test.com:3128"
299 echo " JIRAFEAU_URL : example: http://mysite/jirafeau/script.php"
300 echo " JIRAFEAU_TIME : minute, hour, day, week, year, month or none"
301 echo " JIRAFEAU_ONE_TIME : set anything or set empty"
302 echo " JIRAFEAU_CURL : path to your curl binary"
307 if [ -n
"$proxy" ]; then
312 if [ -n
"$one_time" ]; then
313 options
="$options -F one_time_download=1"
319 options
="$options -F key=$password"
322 if [ "$1" == "send" ]; then
323 if [ ! -f
"$2" ]; then
324 echo "File \"$2\" does not exists."
329 res
=$
($curl -X POST
--http1
.0
$proxy $options \
334 if [[ "$res" == Error
* ]]; then
335 echo "Error while uploading."
340 # Not using head or tail to minimise command dependencies
341 code
=$
(cnt
=0; echo "$res" |
while read l
; do
342 if [[ "$cnt" == "0" ]]; then
347 del_code
=$
(cnt
=0; echo "$res" |
while read l
; do
348 if [[ "$cnt" == "1" ]]; then
353 echo "Download link:"
354 echo "${url}?h=$code"
355 echo "Direct download link:"
356 echo "${url}?h=$code&d=1"
358 echo "${url}?h=$code&d=$del_code"
359 elif
[ "$1" == "get" ]; then
360 if [ -z
"$password" ]; then
361 $curl $proxy -OJ
"$2"
363 $curl $proxy -OJ
-X POST
-F key
=$password "$2"
365 elif
[ "$1" == "delete" ]; then
377 elseif (isset ($_GET['alias_create']))
379 $ip = get_ip_address($cfg);
380 if (!jirafeau_challenge_upload_ip ($cfg, $ip))
386 if (jirafeau_has_upload_password ($cfg) &&
387 (!isset ($_POST['upload_password']) ||
388 !jirafeau_challenge_upload_password ($cfg, $_POST['upload_password'])))
394 if (!isset ($_POST['alias']) ||
395 !isset ($_POST['destination']) ||
396 !isset ($_POST['password']))
402 echo jirafeau_alias_create ($_POST['alias'],
403 $_POST['destination'],
408 elseif (isset ($_GET['alias_get']))
410 if (!isset ($_POST['alias']))
416 echo jirafeau_alias_get ($_POST['alias']);
419 elseif (isset ($_GET['alias_update']))
421 if (!isset ($_POST['alias']) ||
422 !isset ($_POST['destination']) ||
423 !isset ($_POST['password']))
430 if (isset ($_POST['new_password']))
431 $new_password = $_POST['new_password'];
433 echo jirafeau_alias_update ($_POST['alias'],
434 $_POST['destination'],
437 get_ip_address($cfg));
440 elseif (isset ($_GET['alias_delete']))
442 if (!isset ($_POST['alias']) ||
443 !isset ($_POST['password']))
449 echo jirafeau_alias_delete ($_POST['alias'],
452 /* Initialize an asynchronous upload. */
453 elseif (isset ($_GET['init_async']))
455 if (!jirafeau_challenge_upload_ip ($cfg, get_ip_address($cfg)))
461 if (jirafeau_has_upload_password ($cfg) &&
462 (!isset ($_POST['upload_password']) ||
463 !jirafeau_challenge_upload_password ($cfg, $_POST['upload_password'])))
469 if (!isset ($_POST['filename']))
476 if (isset ($_POST['type']))
477 $type = $_POST['type'];
480 if (isset ($_POST['key']))
481 $key = $_POST['key'];
484 if (!isset ($_POST['time']) ||
!$cfg['availabilities'][$_POST['time']])
490 switch ($_POST['time'])
493 $time +
= JIRAFEAU_MINUTE
;
496 $time +
= JIRAFEAU_HOUR
;
499 $time +
= JIRAFEAU_DAY
;
502 $time +
= JIRAFEAU_WEEK
;
505 $time +
= JIRAFEAU_MONTH
;
508 $time +
= JIRAFEAU_YEAR
;
511 $time = JIRAFEAU_INFINITY
;
514 echo jirafeau_async_init ($_POST['filename'],
516 isset ($_POST['one_time_download']),
519 get_ip_address($cfg));
521 /* Continue an asynchronous upload. */
522 elseif (isset ($_GET['push_async']))
524 if ((!isset ($_POST['ref']))
525 ||
(!isset ($_FILES['data']))
526 ||
(!isset ($_POST['code'])))
530 echo jirafeau_async_push ($_POST['ref'],
533 $cfg['maximal_upload_size']);
536 /* Finalize an asynchronous upload. */
537 elseif (isset ($_GET['end_async']))
539 if (!isset ($_POST['ref'])
540 ||
!isset ($_POST['code']))
543 echo jirafeau_async_end ($_POST['ref'], $_POST['code'], $cfg['enable_crypt'], $cfg['link_name_length']);