]> git.p6c8.net - jirafeau.git/blob - index.php
Add langage support (french) and automatic langage selection
[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 define ('DEBUG', true);
22
23 require (JIRAFEAU_ROOT . 'lib/lang.php');
24 require (JIRAFEAU_ROOT . 'lib/config.php');
25 require (JIRAFEAU_ROOT . 'lib/settings.php');
26 require (JIRAFEAU_ROOT . 'lib/functions.php');
27
28 /* check if the destination dirs are writable */
29 $writable = is_writable (VAR_FILES) && is_writable (VAR_LINKS);
30
31 $res = array ();
32 if ($writable && isset ($_POST['jirafeau']))
33 {
34
35 $key = $_POST['key'];
36
37 $time = time ();
38 switch ($_POST['time'])
39 {
40 case 'minute':
41 $time += JIRAFEAU_MINUTE;
42 break;
43 case 'hour':
44 $time += JIRAFEAU_HOUR;
45 break;
46 case 'day':
47 $time += JIRAFEAU_DAY;
48 break;
49 case 'week':
50 $time += JIRAFEAU_WEEK;
51 break;
52 case 'month':
53 $time += JIRAFEAU_MONTH;
54 break;
55 default:
56 $time = JIRAFEAU_INFINITY;
57 break;
58 }
59
60 $res =
61 jirafeau_upload ($_FILES['file'], isset ($_POST['one_time_download']),
62 $key, $time, $cfg, $_SERVER['REMOTE_ADDR']);
63 }
64
65 if (file_exists (JIRAFEAU_ROOT . 'install.php')
66 && !file_exists (JIRAFEAU_ROOT.'lib/config.local.php'))
67 {
68 header('Location: install.php');
69 exit;
70 }
71
72 require (JIRAFEAU_ROOT.'lib/template/header.php');
73
74 /* Checking for errors. */
75 if (!is_writable (VAR_FILES))
76 add_error (_('The file directory is not writable!'), VAR_FILES);
77
78 if (!is_writable (VAR_LINKS))
79 add_error (_('The link directory is not writable!'), VAR_LINKS);
80
81 /* Check if the install.php script is still in the directory. */
82 if (file_exists (JIRAFEAU_ROOT . 'install.php'))
83 add_error (_('Installer script still present'),
84 _('Please make sure to delete the installer script ' .
85 '"install.php" before continuing.'));
86
87 if (!has_error () && !empty ($res))
88 {
89 if ($res['error']['has_error'])
90 add_error (_('An error occurred.'), $res['error']['why']);
91 else
92 {
93 $link = $cfg['web_root'];
94 $delete_link = $cfg['web_root'];
95
96 if ($cfg['rewrite'])
97 {
98 $link .= 'file-'.$res['link'];
99 $delete_link .=
100 'file-'.$res['link'].'-delete-'.$res['delete_link'];
101 }
102 else
103 {
104 /* h because 'h' looks like a jirafeau ;) */
105 $link .= 'file.php?h='.$res['link'];
106 $delete_link .=
107 'file.php?h='.$res['link'].'&amp;d='.$res['delete_link'];
108 }
109
110 echo '<div class="message">'.NL;
111 echo '<p>'._('File uploaded! Copy the following URL to get it:').
112 '<br />' . NL;
113 echo '<a href="'.$link.'">'.$link.'</a>' . NL;
114
115 if ($time != JIRAFEAU_INFINITY)
116 {
117 echo '<br />'._('This file is valid until the following date:') .
118 '<br /><strong>' . strftime ('%c', $time) . '</strong>';
119 }
120
121 echo '</p></div>';
122
123 echo '<div class="message">' . NL;
124 echo '<p>' . _('Keep the following URL to delete it:') . '<br />' . NL;
125 echo '<a href="' . $delete_link . '">' . $delete_link . '</a>' . NL;
126 echo '</p></div>';
127 }
128 }
129
130 if (has_error ())
131 show_errors ();
132
133 if (!has_error () && $writable)
134 {
135 ?><div id = "upload">
136 <form enctype = "multipart/form-data" action = "
137 <?php echo $cfg['web_root']; ?>" method =
138 "post"> <div><input type = "hidden" name = "jirafeau" value = "
139 <?php echo JIRAFEAU_VERSION; ?>" /></div> <fieldset>
140 <legend><?php echo _('Upload a file');
141 ?></legend> <p><input type = "file" name = "file" size =
142 "30" /></p> <p class =
143 "config"><?php printf (_('Maximum file size: %dMB'),
144 jirafeau_get_max_upload_size () / (1024 *
145 1024));
146 ?></p> <p><input type = "submit" value =
147 "<?php echo _('Send'); ?>" /></p>
148 <hr /><div id = "moreoptions"> <p><label><input type =
149 "checkbox" name =
150 "one_time_download" /><?php echo _('One time download');
151 ?></label></p> <p><label for = "input_key"
152 ><?php echo _('Password:');
153 ?></label> <input type = "text" name = "key" id = "input_key" /></p>
154 <p><label for = "select_time"
155 ><?php echo _('Time limit:');
156 ?></label>
157 <select name = "time" id = "select_time">
158 <option value = "none"><?php echo _('None');
159 ?></option> <option value = "minute"><?php echo _('One minute');
160 ?></option> <option value = "hour"><?php echo _('One hour');
161 ?></option> <option value = "day"><?php echo _('One day');
162 ?></option> <option value = "week"><?php echo _('One week');
163 ?></option> <option value = "month"><?php echo _('One month');
164 ?></option>
165 </select> </p> </div> </fieldset> </form> </div> <?php
166 }
167
168 require (JIRAFEAU_ROOT.'lib/template/footer.php');
169 ?>

patrick-canterino.de