]>
git.p6c8.net - jirafeau_project.git/blob - script.php
3 * Jirafeau, your web file repository
4 * Copyright (C) 2012 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 <http://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.php');
29 require (JIRAFEAU_ROOT
. 'lib/settings.php');
30 require (JIRAFEAU_ROOT
. 'lib/functions.php');
31 require (JIRAFEAU_ROOT
. 'lib/lang.php');
33 if (file_exists (JIRAFEAU_ROOT
. 'install.php'))
35 header('Content-Type: text; charset=utf-8');
40 global $script_langages;
41 $script_langages = array ('bash' => 'Bash');
43 if ($_SERVER['REQUEST_METHOD'] == "GET" && count ($_GET) == 0)
45 require (JIRAFEAU_ROOT
. 'lib/template/header.php');
46 echo '<div class="info">';
47 echo '<h2>' . t('Welcome to Jirafeau\'s query interface') . '</h2>';
49 echo t('This interface permits to script your uploads and downloads.') .
50 ' ' . t('The instructions above show how to query this interface.');
53 echo '<h3>' . t('Get server capacity') . ':</h3>';
55 echo t('Send a GET query to') . ': <i>' . $web_root . 'script.php</i><br />';
57 echo t('Parameters') . ':<br />';
58 echo "<b>get_capacity=</b>1<i> (" . t('Required') . ")</i> <br />";
60 echo '<p>' . t('This will return brut text content.') . ' ' .
61 t('First line is the server capacity (in Bytes).') . '<br /></p>';
63 echo t('Example') . ": <a href=\"" . $web_root . "script.php?get_capacity=1\">" . $web_root . "script.php?get_capacity=1</a> ";
66 echo '<h3>' . t('Upload a file') . ':</h3>';
68 echo t('Send a POST query to') . ': <i>' . $web_root . 'script.php</i><br />';
70 echo t('Parameters') . ':<br />';
71 echo "<b>file=</b>C:\\your\\file\\path<i> (" . t('Required') . ")</i> <br />";
72 echo "<b>time=</b>[minute|hour|day|week|month|none]<i> (" . t('Optional') . ', '. t('default: none') . ")</i> <br />";
73 echo "<b>password=</b>your_password<i> (" . t('Optional') . ")</i> <br />";
74 echo "<b>one_time_download=</b>1<i> (" . t('Optional') . ")</i> <br />";
76 echo '<p>' . t('This will return brut text content.') . ' ' .
77 t('First line is the download reference and the second line the delete code.') . '<br /></p>';
79 echo '<h3>' . t('Get a file') . ':</h3>';
81 echo t('Send a GET query to') . ': <i>' . $web_root . 'script.php</i><br />';
83 echo t('Parameters') . ':<br />';
84 echo "<b>h=</b>your_download_reference<i> (" . t('Required') . ")</i> <br />";
87 echo t('If a password has been set, send a POST request with it.');
89 echo t('Parameters') . ':<br />';
90 echo "<b>password=</b>your_password<i> (" . t('Optional') . ")</i> <br />";
93 echo t('Example') . ": <a href=\"" . $web_root . "script.php?h=30ngy0hsDcpfrF8zR7x9iU\">" . $web_root . "script.php?h=30ngy0hsDcpfrF8zR7x9iU</a> ";
96 echo '<h3>' . t('Delete a file') . ':</h3>';
98 echo t('Send a GET query to') . ': <i>' . $web_root . 'script.php</i><br />';
100 echo t('Parameters') . ':<br />';
101 echo "<b>h=</b>your_download_reference<i> (" . t('Required') . ")</i> <br />";
102 echo "<b>d=</b>yout_delete_code<i> (" . t('Required') . ")</i> <br />";
104 echo '<p>' . t('This will return "Ok" if succeded, "Error" otherwhise.') . '<br /></p>';
106 echo t('Example') . ": <a href=\"" . $web_root . "script.php?h=30ngy0hsDcpfrF8zR7x9iU&d=0d210a952\">" . $web_root . "script.php?h=30ngy0hsDcpfrF8zR7x9iU&d=0d210a952</a> ";
109 echo '<h3>' . t('Get a generated scripts') . ':</h3>';
111 echo t('Send a GET query to') . ': <i>' . $web_root . 'script.php</i><br />';
113 echo t('Parameters') . ':<br />';
114 echo "<b>lang=</b>[";
115 foreach ($script_langages as $lang => $name)
117 echo "]<i> (" . t('Required') . ")</i> <br />";
119 echo '<p>' . t('This will return brut text content of the code.') . '<br /></p>';
121 echo t('Example') . ": <br />";
122 foreach ($script_langages as $lang => $name)
123 echo "$name: <a href=\"" . $web_root . "script.php?lang=$lang\">" . $web_root . "script.php?lang=$lang</a> ";
127 require (JIRAFEAU_ROOT
. 'lib/template/footer.php');
131 /* Lets use interface now. */
132 header('Content-Type: text; charset=utf-8');
135 if (isset ($_FILES['file']) && is_writable (VAR_FILES
)
136 && is_writable (VAR_LINKS
))
139 if (isset ($_POST['key']))
140 $key = $_POST['key'];
143 if (!isset ($_POST['time']))
144 $time = JIRAFEAU_INFINITY
;
146 switch ($_POST['time'])
149 $time +
= JIRAFEAU_MINUTE
;
152 $time +
= JIRAFEAU_HOUR
;
155 $time +
= JIRAFEAU_DAY
;
158 $time +
= JIRAFEAU_WEEK
;
161 $time +
= JIRAFEAU_MONTH
;
164 $time = JIRAFEAU_INFINITY
;
167 $res = jirafeau_upload ($_FILES['file'],
168 isset ($_POST['one_time_download']),
169 $key, $time, $_SERVER['REMOTE_ADDR']);
171 if (empty($res) ||
$res['error']['has_error'])
176 /* Print direct link. */
179 /* Print delete link. */
180 echo $res['delete_link'];
182 elseif (isset ($_GET['h']))
184 $link_name = $_GET['h'];
186 if (isset ($_POST['key']))
187 $key = $_POST['key'];
189 if (isset ($_GET['d']))
192 if (!preg_match ('/[0-9a-zA-Z_-]{22}$/', $link_name))
198 $link = jirafeau_get_link ($link_name);
199 if (count ($link) == 0)
204 if (strlen ($d) > 0 && $d == $link['link_code'])
206 jirafeau_delete_link ($link_name);
210 if ($link['time'] != JIRAFEAU_INFINITY
&& time () > $link['time'])
212 jirafeau_delete_link ($link_name);
216 if (strlen ($link['key']) > 0 && md5 ($key) != $link['key'])
221 $p = s2p ($link['md5']);
222 if (!file_exists (VAR_FILES
. $p . $link['md5']))
228 header ('Content-Length: ' . $link['file_size']);
229 header ('Content-Type: ' . $link['mime_type']);
230 header ('Content-Disposition: attachment; filename="' .
231 $link['file_name'] . '"');
232 readfile (VAR_FILES
. $p . $link['md5']);
234 if ($link['onetime'] == 'O')
235 jirafeau_delete_link ($link_name);
238 elseif (isset ($_GET['get_capacity']))
240 echo min (jirafeau_ini_to_bytes (ini_get ('post_max_size')),
241 jirafeau_ini_to_bytes (ini_get ('upload_max_filesize')));
243 elseif (isset ($_GET['lang']))
251 # This script has been auto-generated by Jirafeau but you can still edit
255 proxy
='' # ex: proxy='proxysever.test.com:3128' or set JIRAFEAU_PROXY global variable
256 url
='<?php echo $cfg['web_root
'] . 'script
.php
'; ?>' # or set JIRAFEAU_URL ex: url='http://mysite/jirafeau/script.php'
257 time
='none' # minute, hour, day, week, month or none. Or set JIRAFEAU_TIME.
258 one_time
='' # ex: one_time="1" or set JIRAFEAU_ONE_TIME.
259 curl
='' # curl path to download or set JIRAFEAU_CURL_PATH.
262 if [ -n
"$JIRAFEAU_PROXY" ]; then
263 proxy
="$JIRAFEAU_PROXY"
266 if [ -n
"$JIRAFEAU_URL" ]; then
270 if [ -z
"$url" ]; then
271 echo "Please set url in script parameters or export JIRAFEAU_URL"
274 if [ -n
"$JIRAFEAU_TIME" ]; then
275 time
="$JIRAFEAU_TIME"
278 if [ -n
"$JIRAFEAU_ONE_TIME" ]; then
282 if [ -z
"$curl" ]; then
283 curl
="$JIRAFEAU_CURL_PATH"
286 if [ -z
"$curl" ] && [ -e
"/usr/bin/curl" ]; then
290 if [ -z
"$curl" ] && [ -e
"/bin/curl.exe" ]; then
294 if [ -z
"$curl" ]; then
295 echo "Please set your curl binary path (by editing this script or export JIRAFEAU_CURL_PATH global variable)."
301 echo " $0 send PATH [PASSWORD]"
302 echo " $0 get URL [PASSWORD]"
303 echo " $0 delete URL"
305 echo "Global variables to export:"
306 echo " JIRAFEAU_PROXY : example: proxysever.test.com:3128"
307 echo " JIRAFEAU_URL : example: http://mysite/jirafeau/script.php"
308 echo " JIRAFEAU_TIME : minute, hour, day, week, month or none"
309 echo " JIRAFEAU_ONE_TIME : set anything or set empty"
310 echo " JIRAFEAU_CURL : path to your curl binary"
315 if [ -n
"$proxy" ]; then
320 if [ -n
"$one_time" ]; then
321 options
="$options -F one_time_download=1"
327 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."
347 # Not using head or tail to minimise command dependencies
348 code
=$
(cnt
=0; echo "$res" |
while read l
; do
349 if [[ "$cnt" == "0" ]]; then
354 del_code
=$
(cnt
=0; echo "$res" |
while read l
; do
355 if [[ "$cnt" == "1" ]]; then
360 echo "${url}?h=$code"
361 echo "${url}?h=$code&d=$del_code"
362 elif
[ "$1" == "get" ]; then
363 if [ -z
"$password" ]; then
364 $curl $proxy -OJ
"$2"
366 $curl $proxy -OJ
-X POST
-F key
=$password "$2"
368 elif
[ "$1" == "delete" ]; then
patrick-canterino.de