]> git.p6c8.net - jirafeau_mojo42.git/blob - pub/index.php
Initial commit: Jiraph 0.5 (stable) project
[jirafeau_mojo42.git] / pub / index.php
1 <?php
2 /*
3 * Jyraphe, your web file repository
4 * Copyright (C) 2008 Julien "axolotl" BERNARD <axolotl@magieeternelle.org>
5 *
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.
10 *
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.
15 *
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/>.
18 */
19
20 define('JYRAPHE_ROOT', dirname(__FILE__) . '/');
21 define('DEBUG', true);
22
23 require(JYRAPHE_ROOT . 'lib/config.php');
24 require(JYRAPHE_ROOT . 'lib/settings.php');
25 require(JYRAPHE_ROOT . 'lib/functions.php');
26
27 /* check if the destination dirs are writable */
28 $writable = is_writable(VAR_FILES) && is_writable(VAR_LINKS) && is_writable(VAR_TRASH);
29
30 $res = array();
31 if($writable && isset($_POST['jyraphe'])) {
32
33 $key = $_POST['key'];
34
35 $time = time();
36 switch($_POST['time']) {
37 case 'minute':
38 $time += JYRAPHE_MINUTE;
39 break;
40 case 'hour':
41 $time += JYRAPHE_HOUR;
42 break;
43 case 'day':
44 $time += JYRAPHE_DAY;
45 break;
46 case 'week':
47 $time += JYRAPHE_WEEK;
48 break;
49 case 'month':
50 $time += JYRAPHE_MONTH;
51 break;
52 default:
53 $time = JYRAPHE_INFINITY;
54 break;
55 }
56
57 $res = jyraphe_upload($_FILES['file'], isset($_POST['one_time_download']), $key, $time, $cfg);
58 }
59
60 require(JYRAPHE_ROOT . 'lib/template/header.php');
61
62 /* Checking for errors. */
63 if(!is_writable(VAR_FILES)) {
64 add_error (_('The file directory is not writable!'), VAR_FILES);
65 }
66
67 if(!is_writable(VAR_LINKS)) {
68 add_error (_('The link directory is not writable!'), VAR_LINKS);
69 }
70
71 if(!is_writable(VAR_TRASH)) {
72 add_error (_('The trash directory is not writable!'), VAR_TRASH);
73 }
74
75 /* Check if the install.php script is still in the directory. */
76 if (file_exists(JYRAPHE_ROOT . 'install.php')) {
77 add_error (_('Installer script still present'),
78 _('Please make sure to delete the installer script "install.php" before continuing.'));
79 }
80
81 if(!has_error() && !empty($res)) {
82 if($res['error']['has_error']) {
83 add_error (_('An error occurred.'), $res['error']['why']);
84 } else {
85 $link = $cfg['web_root'];
86 if($cfg['rewrite']) {
87 $link .= 'file-' . $res['link'];
88 } else {
89 $link .= 'file.php?h=' . $res['link']; // h because 'h' looks like a jyraphe ;)
90 }
91 echo '<div class="message">' . NL;
92 echo '<p>' . _('File uploaded! Copy the following URL to get it:') . '<br />' . NL;
93 echo '<a href="' . $link . '">' . $link . '</a>' . NL;
94
95 if($time != JYRAPHE_INFINITY) {
96 echo '<br />' . _('This file is valid until the following date:') . '<br /><strong>' . strftime('%c' ,$time) . '</strong>';
97 }
98
99 echo '</p></div>';
100 }
101 }
102
103 if(has_error ()) {
104 show_errors ();
105 }
106
107 if(!has_error () && $writable) {
108 ?>
109
110 <div id="upload">
111 <form enctype="multipart/form-data" action="<?php echo $cfg['web_root']; ?>" method="post">
112 <div><input type="hidden" name="jyraphe" value="<?php echo JYRAPHE_VERSION; ?>" /></div>
113 <fieldset>
114 <legend><?php echo _('Upload a file'); ?></legend>
115 <p><input type="file" name="file" size="30" /></p>
116 <p class="config"><?php printf(_('Maximum file size: %dMB'), jyraphe_get_max_upload_size()/(1024*1024)); ?></p>
117 <p><input type="submit" value="<?php echo _('Send in the binary chaos'); ?>" /></p>
118
119 <hr />
120
121 <div id="moreoptions">
122 <p><label><input type="checkbox" name="one_time_download" /> <?php echo _('One time download'); ?></label></p>
123 <p><label for="input_key"><?php echo _('File key:'); ?></label> <input type="text" name="key" id="input_key" /></p>
124 <p><label for="select_time"><?php echo _('Time limit:'); ?></label>
125 <select name="time" id="select_time">
126 <option value="none"><?php echo _('None'); ?></option>
127 <option value="minute"><?php echo _('One minute'); ?></option>
128 <option value="hour"><?php echo _('One hour'); ?></option>
129 <option value="day"><?php echo _('One day'); ?></option>
130 <option value="week"><?php echo _('One week'); ?></option>
131 <option value="month"><?php echo _('One month'); ?></option>
132 </select>
133 </p>
134 </div>
135 </fieldset>
136 </form>
137 </div>
138
139 <?php
140 }
141
142 require(JYRAPHE_ROOT . 'lib/template/footer.php');
143 ?>

patrick-canterino.de