]> git.p6c8.net - jirafeau.git/blob - index.php
small verification
[jirafeau.git] / index.php
1 <?php
2 /*
3 * Jirafeau, your web file repository
4 * Copyright (C) 2008 Julien "axolotl" BERNARD <axolotl@magieeternelle.org>
5 * Copyright (C) 2012 Jerome Jutteau <j.jutteau@gmail.com>
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20 define ('JIRAFEAU_ROOT', dirname (__FILE__) . '/');
21
22 require (JIRAFEAU_ROOT . 'lib/config.php');
23 require (JIRAFEAU_ROOT . 'lib/settings.php');
24 require (JIRAFEAU_ROOT . 'lib/functions.php');
25 require (JIRAFEAU_ROOT . 'lib/lang.php');
26
27 if (file_exists (JIRAFEAU_ROOT . 'install.php')
28 && !file_exists (JIRAFEAU_ROOT . 'lib/config.local.php'))
29 {
30 header('Location: install.php');
31 exit;
32 }
33
34 /* check if the destination dirs are writable */
35 $writable = is_writable (VAR_FILES) && is_writable (VAR_LINKS);
36
37 $res = array ();
38 if ($writable && isset ($_POST['jirafeau']) && isset ($_FILES['file'])
39 && isset ($_POST['time']))
40 {
41 if (!isset ($_POST['key']))
42 $key = '';
43 else
44 $key = $_POST['key'];
45
46 $time = time ();
47 switch ($_POST['time'])
48 {
49 case 'minute':
50 $time += JIRAFEAU_MINUTE;
51 break;
52 case 'hour':
53 $time += JIRAFEAU_HOUR;
54 break;
55 case 'day':
56 $time += JIRAFEAU_DAY;
57 break;
58 case 'week':
59 $time += JIRAFEAU_WEEK;
60 break;
61 case 'month':
62 $time += JIRAFEAU_MONTH;
63 break;
64 default:
65 $time = JIRAFEAU_INFINITY;
66 break;
67 }
68
69 $res =
70 jirafeau_upload ($_FILES['file'], isset ($_POST['one_time_download']),
71 $key, $time, $_SERVER['REMOTE_ADDR']);
72 }
73
74 require (JIRAFEAU_ROOT . 'lib/template/header.php');
75
76 /* Checking for errors. */
77 if (!is_writable (VAR_FILES))
78 add_error (t('The file directory is not writable!'), VAR_FILES);
79
80 if (!is_writable (VAR_LINKS))
81 add_error (t('The link directory is not writable!'), VAR_LINKS);
82
83 /* Check if the install.php script is still in the directory. */
84 if (file_exists (JIRAFEAU_ROOT . 'install.php'))
85 add_error (t('Installer script still present'),
86 t('Please make sure to delete the installer script ' .
87 '"install.php" before continuing.'));
88
89 if (!has_error () && !empty ($res))
90 {
91 if ($res['error']['has_error'])
92 add_error (t('An error occurred.'), $res['error']['why']);
93 else
94 {
95 $link = $cfg['web_root'];
96 $delete_link = $cfg['web_root'];
97
98 if ($cfg['rewrite'])
99 {
100 $link .= 'file-'.$res['link'];
101 $delete_link .=
102 'file-'.$res['link'].'-delete-'.$res['delete_link'];
103 }
104 else
105 {
106 /* h because 'h' looks like a jirafeau ;) */
107 $link .= 'file.php?h='.$res['link'];
108 $delete_link .=
109 'file.php?h='.$res['link'].'&amp;d='.$res['delete_link'];
110 }
111
112 echo '<div class="message">'.NL;
113 echo '<p>' . t('File uploaded! Copy the following URL to get it') .
114 ':<br />' . NL;
115 echo '<a href="'.$link.'">'.$link.'</a>' . NL;
116
117 if ($time != JIRAFEAU_INFINITY)
118 {
119 echo '<br />' . t('This file is valid until the following date') .
120 ':<br /><strong>' . strftime ('%c', $time) . '</strong>';
121 }
122
123 echo '</p></div>';
124
125 echo '<div class="message">' . NL;
126 echo '<p>' . t('Keep the following URL to delete it at any moment') . ':<br />' . NL;
127 echo '<a href="' . $delete_link . '">' . $delete_link . '</a>' . NL;
128 echo '</p></div>';
129 }
130 }
131
132 if (has_error ())
133 show_errors ();
134
135 if (!has_error () && $writable)
136 {
137 ?><div id = "upload">
138 <form enctype = "multipart/form-data" action = "
139 <?php echo $cfg['web_root']; ?>" method =
140 "post"> <div><input type = "hidden" name = "jirafeau" value = "
141 <?php echo JIRAFEAU_VERSION; ?>" /></div> <fieldset>
142 <legend><?php echo t('Upload a file');
143 ?></legend> <p><input type = "file" name = "file" size =
144 "30" /></p> <p class =
145 "config"><?php printf ('%s: %s', t('Maximum file size'),
146 jirafeau_get_max_upload_size ());
147 ?></p><p>
148 <input type = "submit" id='send' value ="<?php echo t('Send'); ?>"
149 onclick="
150 document.getElementById('send').value='<?php echo t ('Uploading ...'); ?>';
151 document.getElementById('send').submit ();
152 document.getElementById('send').disabled='true';
153 "/>
154 </p><hr /><div id = "moreoptions"> <p><label><input type =
155 "checkbox" name =
156 "one_time_download" /><?php echo t('One time download');
157 ?></label></p><br/><p><label for = "input_key"
158 ><?php echo t('Password') . ':';
159 ?></label><input type = "text" name = "key" id = "input_key" /></p>
160 <p><label for = "select_time"
161 ><?php echo t('Time limit') . ':';
162 ?></label>
163 <select name = "time" id = "select_time">
164 <option value = "none"><?php echo t('None');
165 ?></option> <option value = "minute"><?php echo t('One minute');
166 ?></option> <option value = "hour"><?php echo t('One hour');
167 ?></option> <option value = "day"><?php echo t('One day');
168 ?></option> <option value = "week"><?php echo t('One week');
169 ?></option> <option value = "month"><?php echo t('One month');
170 ?></option>
171 </select> </p> </div> </fieldset> </form> </div> <?php
172 }
173
174 require (JIRAFEAU_ROOT.'lib/template/footer.php');
175 ?>

patrick-canterino.de