]>
git.p6c8.net - jirafeau.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 global $script_langages;
34 $script_langages = array ('bash' => 'Bash');
36 if ($_SERVER['REQUEST_METHOD'] == "GET" && count ($_GET) == 0)
38 require (JIRAFEAU_ROOT
. 'lib/template/header.php');
42 echo '<div class="info">';
43 echo '<h2>' . t('Welcome to Jirafeau\'s query interface') . '</h2>';
45 echo t('This interface permits to script your uploads and downloads.') .
46 ' ' . t('The instructions above show how to query this interface.');
49 echo '<h3>' . t('Get Jirafeau\'s version') . ':</h3>';
51 echo t('Send a GET query to') . ': <i>' . $web_root . 'script.php</i><br />';
53 echo t('Parameters') . ':<br />';
54 echo "<b>get_version=</b>1<i> (" . t('Required') . ")</i> <br />";
56 echo '<p>' . t('This will return brut text content.') . ' ' .
57 t('First line is the version number.') . '<br /></p>';
59 echo t('Example') . ": <a href=\"" . $web_root . "script.php?get_version=1\">" . $web_root . "script.php?get_version=1</a> ";
62 echo '<h3>' . t('Get server capacity') . ':</h3>';
64 echo t('Send a GET query to') . ': <i>' . $web_root . 'script.php</i><br />';
66 echo t('Parameters') . ':<br />';
67 echo "<b>get_capacity=</b>1<i> (" . t('Required') . ")</i> <br />";
69 echo '<p>' . t('This will return brut text content.') . ' ' .
70 t('First line is the server capacity (in Bytes).') . '<br /></p>';
72 echo t('Example') . ": <a href=\"" . $web_root . "script.php?get_capacity=1\">" . $web_root . "script.php?get_capacity=1</a> ";
75 echo '<h3>' . t('Upload a file') . ':</h3>';
77 echo t('Send a POST query to') . ': <i>' . $web_root . 'script.php</i><br />';
79 echo t('Parameters') . ':<br />';
80 echo "<b>file=</b>C:\\your\\file\\path<i> (" . t('Required') . ")</i> <br />";
81 echo "<b>time=</b>[minute|hour|day|week|month|none]<i> (" . t('Optional') . ', '. t('default: none') . ")</i> <br />";
82 echo "<b>password=</b>your_password<i> (" . t('Optional') . ")</i> <br />";
83 echo "<b>one_time_download=</b>1<i> (" . t('Optional') . ")</i> <br />";
85 echo '<p>' . t('This will return brut text content.') . ' ' .
86 t('First line is the download reference and the second line the delete code.') . '<br /></p>';
88 echo '<h3>' . t('Get a file') . ':</h3>';
90 echo t('Send a GET query to') . ': <i>' . $web_root . 'script.php</i><br />';
92 echo t('Parameters') . ':<br />';
93 echo "<b>h=</b>your_download_reference<i> (" . t('Required') . ")</i> <br />";
96 echo t('If a password has been set, send a POST request with it.');
98 echo t('Parameters') . ':<br />';
99 echo "<b>password=</b>your_password<i> (" . t('Optional') . ")</i> <br />";
102 echo t('Example') . ": <a href=\"" . $web_root . "script.php?h=30ngy0hsDcpfrF8zR7x9iU\">" . $web_root . "script.php?h=30ngy0hsDcpfrF8zR7x9iU</a> ";
105 echo '<h3>' . t('Delete a file') . ':</h3>';
107 echo t('Send a GET query to') . ': <i>' . $web_root . 'script.php</i><br />';
109 echo t('Parameters') . ':<br />';
110 echo "<b>h=</b>your_download_reference<i> (" . t('Required') . ")</i> <br />";
111 echo "<b>d=</b>yout_delete_code<i> (" . t('Required') . ")</i> <br />";
113 echo '<p>' . t('This will return "Ok" if succeded, "Error" otherwhise.') . '<br /></p>';
115 echo t('Example') . ": <a href=\"" . $web_root . "script.php?h=30ngy0hsDcpfrF8zR7x9iU&d=0d210a952\">" . $web_root . "script.php?h=30ngy0hsDcpfrF8zR7x9iU&d=0d210a952</a> ";
118 echo '<h3>' . t('Get a generated scripts') . ':</h3>';
120 echo t('Send a GET query to') . ': <i>' . $web_root . 'script.php</i><br />';
122 echo t('Parameters') . ':<br />';
123 echo "<b>lang=</b>[";
124 foreach ($script_langages as $lang => $name)
126 echo "]<i> (" . t('Required') . ")</i> <br />";
128 echo '<p>' . t('This will return brut text content of the code.') . '<br /></p>';
130 echo t('Example') . ": <br />";
131 foreach ($script_langages as $lang => $name)
132 echo "$name: <a href=\"" . $web_root . "script.php?lang=$lang\">" . $web_root . "script.php?lang=$lang</a> ";
136 require (JIRAFEAU_ROOT
. 'lib/template/footer.php');
140 /* Lets use interface now. */
141 header('Content-Type: text; charset=utf-8');
144 if (isset ($_FILES['file']) && is_writable (VAR_FILES
)
145 && is_writable (VAR_LINKS
))
148 if (isset ($_POST['key']))
149 $key = $_POST['key'];
152 if (!isset ($_POST['time']))
153 $time = JIRAFEAU_INFINITY
;
155 switch ($_POST['time'])
158 $time +
= JIRAFEAU_MINUTE
;
161 $time +
= JIRAFEAU_HOUR
;
164 $time +
= JIRAFEAU_DAY
;
167 $time +
= JIRAFEAU_WEEK
;
170 $time +
= JIRAFEAU_MONTH
;
173 $time = JIRAFEAU_INFINITY
;
176 $res = jirafeau_upload ($_FILES['file'],
177 isset ($_POST['one_time_download']),
178 $key, $time, $_SERVER['REMOTE_ADDR']);
180 if (empty($res) ||
$res['error']['has_error'])
185 /* Print direct link. */
188 /* Print delete link. */
189 echo $res['delete_link'];
191 elseif (isset ($_GET['h']))
193 $link_name = $_GET['h'];
195 if (isset ($_POST['key']))
196 $key = $_POST['key'];
198 if (isset ($_GET['d']))
201 if (!preg_match ('/[0-9a-zA-Z_-]{22}$/', $link_name))
207 $link = jirafeau_get_link ($link_name);
208 if (count ($link) == 0)
213 if (strlen ($d) > 0 && $d == $link['link_code'])
215 jirafeau_delete_link ($link_name);
219 if ($link['time'] != JIRAFEAU_INFINITY
&& time () > $link['time'])
221 jirafeau_delete_link ($link_name);
225 if (strlen ($link['key']) > 0 && md5 ($key) != $link['key'])
230 $p = s2p ($link['md5']);
231 if (!file_exists (VAR_FILES
. $p . $link['md5']))
237 header ('Content-Length: ' . $link['file_size']);
238 header ('Content-Type: ' . $link['mime_type']);
239 header ('Content-Disposition: attachment; filename="' .
240 $link['file_name'] . '"');
241 readfile (VAR_FILES
. $p . $link['md5']);
243 if ($link['onetime'] == 'O')
244 jirafeau_delete_link ($link_name);
247 elseif (isset ($_GET['get_capacity']))
249 echo min (jirafeau_ini_to_bytes (ini_get ('post_max_size')),
250 jirafeau_ini_to_bytes (ini_get ('upload_max_filesize')));
252 elseif (isset ($_GET['get_version']))
254 echo JIRAFEAU_VERSION
;
256 elseif (isset ($_GET['lang']))
264 # This script has been auto-generated by Jirafeau but you can still edit
268 proxy
='' # ex: proxy='proxysever.test.com:3128' or set JIRAFEAU_PROXY global variable
269 url
='<?php echo $cfg['web_root
'] . 'script
.php
'; ?>' # or set JIRAFEAU_URL ex: url='http://mysite/jirafeau/script.php'
270 time
='none' # minute, hour, day, week, month or none. Or set JIRAFEAU_TIME.
271 one_time
='' # ex: one_time="1" or set JIRAFEAU_ONE_TIME.
272 curl
='' # curl path to download or set JIRAFEAU_CURL_PATH.
275 if [ -n
"$JIRAFEAU_PROXY" ]; then
276 proxy
="$JIRAFEAU_PROXY"
279 if [ -n
"$JIRAFEAU_URL" ]; then
283 if [ -z
"$url" ]; then
284 echo "Please set url in script parameters or export JIRAFEAU_URL"
287 if [ -n
"$JIRAFEAU_TIME" ]; then
288 time
="$JIRAFEAU_TIME"
291 if [ -n
"$JIRAFEAU_ONE_TIME" ]; then
295 if [ -z
"$curl" ]; then
296 curl
="$JIRAFEAU_CURL_PATH"
299 if [ -z
"$curl" ] && [ -e
"/usr/bin/curl" ]; then
303 if [ -z
"$curl" ] && [ -e
"/bin/curl.exe" ]; then
307 if [ -z
"$curl" ]; then
308 echo "Please set your curl binary path (by editing this script or export JIRAFEAU_CURL_PATH global variable)."
314 echo " $0 send PATH [PASSWORD]"
315 echo " $0 get URL [PASSWORD]"
316 echo " $0 delete URL"
318 echo "Global variables to export:"
319 echo " JIRAFEAU_PROXY : example: proxysever.test.com:3128"
320 echo " JIRAFEAU_URL : example: http://mysite/jirafeau/script.php"
321 echo " JIRAFEAU_TIME : minute, hour, day, week, month or none"
322 echo " JIRAFEAU_ONE_TIME : set anything or set empty"
323 echo " JIRAFEAU_CURL : path to your curl binary"
328 if [ -n
"$proxy" ]; then
333 if [ -n
"$one_time" ]; then
334 options
="$options -F one_time_download=1"
340 options
="$options -F key=$password"
343 if [ "$1" == "send" ]; then
344 if [ ! -f
"$2" ]; then
345 echo "File \"$2\" does not exists."
350 res
=$
($curl -X POST
--http1
.0
$proxy $options \
355 if [[ "$res" == "Error" ]]; then
356 echo "Error while uploading."
360 # Not using head or tail to minimise command dependencies
361 code
=$
(cnt
=0; echo "$res" |
while read l
; do
362 if [[ "$cnt" == "0" ]]; then
367 del_code
=$
(cnt
=0; echo "$res" |
while read l
; do
368 if [[ "$cnt" == "1" ]]; then
373 echo "${url}?h=$code"
374 echo "${url}?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
patrick-canterino.de