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

patrick-canterino.de