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
>
61 require (JIRAFEAU_ROOT
. 'lib/template/footer.php');
65 /* Lets use interface now. */
66 header('Content-Type: text; charset=utf-8');
76 if (isset ($_FILES['file']) && is_writable (VAR_FILES
)
77 && is_writable (VAR_LINKS
))
79 if (!jirafeau_challenge_upload_ip ($cfg, get_ip_address($cfg)))
85 if (jirafeau_has_upload_password ($cfg) &&
86 (!isset ($_POST['upload_password']) ||
87 !jirafeau_challenge_upload_password ($cfg, $_POST['upload_password'])))
94 if (isset ($_POST['key']))
98 if (!isset ($_POST['time']) ||
!$cfg['availabilities'][$_POST['time']])
104 switch ($_POST['time'])
107 $time +
= JIRAFEAU_MINUTE
;
110 $time +
= JIRAFEAU_HOUR
;
113 $time +
= JIRAFEAU_DAY
;
116 $time +
= JIRAFEAU_WEEK
;
119 $time +
= JIRAFEAU_MONTH
;
122 $time +
= JIRAFEAU_YEAR
;
125 $time = JIRAFEAU_INFINITY
;
130 if ($cfg['maximal_upload_size'] > 0 &&
131 $_FILES['file']['size'] > $cfg['maximal_upload_size'] * 1024 * 1024)
137 $res = jirafeau_upload ($_FILES['file'],
138 isset ($_POST['one_time_download']),
139 $key, $time, get_ip_address($cfg),
140 $cfg['enable_crypt'], $cfg['link_name_length']);
142 if (empty($res) ||
$res['error']['has_error'])
147 /* Print direct link. */
149 /* Print delete link. */
151 echo $res['delete_link'];
152 /* Print decrypt key. */
154 echo urlencode($res['crypt_key']);
156 elseif (isset ($_GET['h']))
158 $link_name = $_GET['h'];
160 if (isset ($_POST['key']))
161 $key = $_POST['key'];
163 if (isset ($_GET['d']))
166 if (!preg_match ('/[0-9a-zA-Z_-]+$/', $link_name))
172 $link = jirafeau_get_link ($link_name);
173 if (count ($link) == 0)
178 if (strlen ($d) > 0 && $d == $link['link_code'])
180 jirafeau_delete_link ($link_name);
184 if ($link['time'] != JIRAFEAU_INFINITY
&& time () > $link['time'])
186 jirafeau_delete_link ($link_name);
190 if (strlen ($link['key']) > 0 && md5 ($key) != $link['key'])
196 $p = s2p ($link['md5']);
197 if (!file_exists (VAR_FILES
. $p . $link['md5']))
204 header ('Content-Length: ' . $link['file_size']);
205 header ('Content-Type: ' . $link['mime_type']);
206 header ('Content-Disposition: attachment; filename="' .
207 $link['file_name'] . '"');
209 $r = fopen (VAR_FILES
. $p . $link['md5'], 'r');
212 print fread ($r, 1024);
217 if ($link['onetime'] == 'O')
218 jirafeau_delete_link ($link_name);
221 elseif (isset ($_GET['get_capacity']))
223 echo min (jirafeau_ini_to_bytes (ini_get ('post_max_size')),
224 jirafeau_ini_to_bytes (ini_get ('upload_max_filesize')));
226 elseif (isset ($_GET['get_maximal_upload_size']))
228 echo $cfg['maximal_upload_size'];
230 elseif (isset ($_GET['get_version']))
232 echo JIRAFEAU_VERSION
;
234 elseif (isset ($_GET['lang']))
242 # This script has been auto-generated by Jirafeau but you can still edit
246 proxy
='' # ex: proxy='proxysever.test.com:3128' or set JIRAFEAU_PROXY global variable
247 url
='<?php echo $cfg['web_root
'] . 'script
.php
'; ?>' # or set JIRAFEAU_URL ex: url='http://mysite/jirafeau/script.php'
248 time
='none' # minute, hour, day, week, month, year or none. Or set JIRAFEAU_TIME.
249 one_time
='' # ex: one_time="1" or set JIRAFEAU_ONE_TIME.
250 curl
='' # curl path to download or set JIRAFEAU_CURL_PATH.
253 if [ -n
"$JIRAFEAU_PROXY" ]; then
254 proxy
="$JIRAFEAU_PROXY"
257 if [ -n
"$JIRAFEAU_URL" ]; then
261 if [ -z
"$url" ]; then
262 echo "Please set url in script parameters or export JIRAFEAU_URL"
265 if [ -n
"$JIRAFEAU_TIME" ]; then
266 time
="$JIRAFEAU_TIME"
269 if [ -n
"$JIRAFEAU_ONE_TIME" ]; then
273 if [ -z
"$curl" ]; then
274 curl
="$JIRAFEAU_CURL_PATH"
277 if [ -z
"$curl" ] && [ -e
"/usr/bin/curl" ]; then
281 if [ -z
"$curl" ] && [ -e
"/bin/curl.exe" ]; then
285 if [ -z
"$curl" ]; then
286 echo "Please set your curl binary path (by editing this script or export JIRAFEAU_CURL_PATH global variable)."
292 echo " $0 send PATH [PASSWORD]"
293 echo " $0 get URL [PASSWORD]"
294 echo " $0 delete URL"
296 echo "Global variables to export:"
297 echo " JIRAFEAU_PROXY : example: proxysever.test.com:3128"
298 echo " JIRAFEAU_URL : example: http://mysite/jirafeau/script.php"
299 echo " JIRAFEAU_TIME : minute, hour, day, week, year, month or none"
300 echo " JIRAFEAU_ONE_TIME : set anything or set empty"
301 echo " JIRAFEAU_CURL : path to your curl binary"
306 if [ -n
"$proxy" ]; then
311 if [ -n
"$one_time" ]; then
312 options
="$options -F one_time_download=1"
318 options
="$options -F key=$password"
321 if [ "$1" == "send" ]; then
322 if [ ! -f
"$2" ]; then
323 echo "File \"$2\" does not exists."
328 res
=$
($curl -X POST
--http1
.0
$proxy $options \
333 if [[ "$res" == "Error" ]]; then
334 echo "Error while uploading."
338 # Not using head or tail to minimise command dependencies
339 code
=$
(cnt
=0; echo "$res" |
while read l
; do
340 if [[ "$cnt" == "0" ]]; then
345 del_code
=$
(cnt
=0; echo "$res" |
while read l
; do
346 if [[ "$cnt" == "1" ]]; then
351 echo "${url}?h=$code"
352 echo "${url}?h=$code&d=$del_code"
353 elif
[ "$1" == "get" ]; then
354 if [ -z
"$password" ]; then
355 $curl $proxy -OJ
"$2"
357 $curl $proxy -OJ
-X POST
-F key
=$password "$2"
359 elif
[ "$1" == "delete" ]; then
371 elseif (isset ($_GET['alias_create']))
373 $ip = get_ip_address($cfg);
374 if (!jirafeau_challenge_upload_ip ($cfg, $ip))
380 if (jirafeau_has_upload_password ($cfg) &&
381 (!isset ($_POST['upload_password']) ||
382 !jirafeau_challenge_upload_password ($cfg, $_POST['upload_password'])))
388 if (!isset ($_POST['alias']) ||
389 !isset ($_POST['destination']) ||
390 !isset ($_POST['password']))
396 echo jirafeau_alias_create ($_POST['alias'],
397 $_POST['destination'],
402 elseif (isset ($_GET['alias_get']))
404 if (!isset ($_POST['alias']))
410 echo jirafeau_alias_get ($_POST['alias']);
413 elseif (isset ($_GET['alias_update']))
415 if (!isset ($_POST['alias']) ||
416 !isset ($_POST['destination']) ||
417 !isset ($_POST['password']))
424 if (isset ($_POST['new_password']))
425 $new_password = $_POST['new_password'];
427 echo jirafeau_alias_update ($_POST['alias'],
428 $_POST['destination'],
431 get_ip_address($cfg));
434 elseif (isset ($_GET['alias_delete']))
436 if (!isset ($_POST['alias']) ||
437 !isset ($_POST['password']))
443 echo jirafeau_alias_delete ($_POST['alias'],
446 /* Initialize an asynchronous upload. */
447 elseif (isset ($_GET['init_async']))
449 if (!jirafeau_challenge_upload_ip ($cfg, get_ip_address($cfg)))
455 if (jirafeau_has_upload_password ($cfg) &&
456 (!isset ($_POST['upload_password']) ||
457 !jirafeau_challenge_upload_password ($cfg, $_POST['upload_password'])))
463 if (!isset ($_POST['filename']))
470 if (isset ($_POST['type']))
471 $type = $_POST['type'];
474 if (isset ($_POST['key']))
475 $key = $_POST['key'];
478 if (!isset ($_POST['time']) ||
!$cfg['availabilities'][$_POST['time']])
484 switch ($_POST['time'])
487 $time +
= JIRAFEAU_MINUTE
;
490 $time +
= JIRAFEAU_HOUR
;
493 $time +
= JIRAFEAU_DAY
;
496 $time +
= JIRAFEAU_WEEK
;
499 $time +
= JIRAFEAU_MONTH
;
502 $time +
= JIRAFEAU_YEAR
;
505 $time = JIRAFEAU_INFINITY
;
508 echo jirafeau_async_init ($_POST['filename'],
510 isset ($_POST['one_time_download']),
513 get_ip_address($cfg));
515 /* Continue an asynchronous upload. */
516 elseif (isset ($_GET['push_async']))
518 if ((!isset ($_POST['ref']))
519 ||
(!isset ($_FILES['data']))
520 ||
(!isset ($_POST['code'])))
524 echo jirafeau_async_push ($_POST['ref'],
527 $cfg['maximal_upload_size']);
530 /* Finalize an asynchronous upload. */
531 elseif (isset ($_GET['end_async']))
533 if (!isset ($_POST['ref'])
534 ||
!isset ($_POST['code']))
537 echo jirafeau_async_end ($_POST['ref'], $_POST['code'], $cfg['enable_crypt'], $cfg['link_name_length']);