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

patrick-canterino.de