root / nephthys_buckets.php
View | Annotate | Download (27.6 KB)
| 1 | <?php
|
|---|---|
| 2 | |
| 3 | /***************************************************************************
|
| 4 | * |
| 5 | * Nephthys - file sharing management |
| 6 | * Copyright (c) by Andreas Unterkircher, unki@netshadow.at |
| 7 | * |
| 8 | * This file is part of Nephthys. |
| 9 | * |
| 10 | * Nephthys is free software: you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation, either version 3 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * Nephthys is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with Nephthys. If not, see <http://www.gnu.org/licenses/>. |
| 22 | * |
| 23 | ***************************************************************************/ |
| 24 | |
| 25 | class NEPHTHYS_BUCKETS {
|
| 26 | |
| 27 | private $db;
|
| 28 | private $parent;
|
| 29 | private $tmpl;
|
| 30 | private $id;
|
| 31 | private $avail_buckets = Array();
|
| 32 | private $buckets = Array();
|
| 33 | |
| 34 | /**
|
| 35 | * NEPHTHYS_BUCKET constructor |
| 36 | * |
| 37 | * Initialize the NEPHTHYS_BUCKET class |
| 38 | */ |
| 39 | public function __construct($id = NULL) |
| 40 | {
|
| 41 | global $nephthys;
|
| 42 | $this->parent =& $nephthys;
|
| 43 | $this->db =& $nephthys->db;
|
| 44 | $this->tmpl =& $nephthys->tmpl;
|
| 45 | |
| 46 | if(!empty($id)) |
| 47 | $this->id = $id;
|
| 48 | |
| 49 | $this->tmpl->register_block("bucket_list", array(&$this, "smarty_bucket_list")); |
| 50 | |
| 51 | $query_str = "
|
| 52 | SELECT |
| 53 | b.bucket_idx as bucket_idx, |
| 54 | b.bucket_name as bucket_name, |
| 55 | b.bucket_sender as bucket_sender, |
| 56 | b.bucket_receiver as bucket_receiver, |
| 57 | b.bucket_hash as bucket_hash, |
| 58 | b.bucket_created as bucket_created, |
| 59 | b.bucket_expire as bucket_expire, |
| 60 | b.bucket_note as bucket_note, |
| 61 | b.bucket_owner as bucket_owner, |
| 62 | b.bucket_active as bucket_active, |
| 63 | b.bucket_notified as bucket_notified, |
| 64 | b.bucket_notify_on_expire as bucket_notify_on_expire |
| 65 | FROM |
| 66 | nephthys_buckets b |
| 67 | ";
|
| 68 | |
| 69 | /* get the current sort-order */
|
| 70 | $column = $this->parent->get_sort_column('buckets'); |
| 71 | $order = $this->parent->get_sort_order('buckets'); |
| 72 | |
| 73 | // if sort should happen on bucket-owners, sort by the real
|
| 74 | // user_name instead of the user_idx (which is stored in
|
| 75 | // bucket_owner).
|
| 76 | if($column == 'bucket_owner') { |
| 77 | |
| 78 | $query_str.= "
|
| 79 | LEFT OUTER JOIN |
| 80 | nephthys_users u |
| 81 | ON |
| 82 | b.bucket_owner=u.user_idx |
| 83 | ";
|
| 84 | |
| 85 | /* equipped with just user privileges, show only personal buckets */
|
| 86 | if(!$this->parent->check_privileges('admin') && |
| 87 | !$this->parent->check_privileges('manager') && |
| 88 | isset($_SESSION['login_idx'])) { |
| 89 | $query_str.= "WHERE b.bucket_owner LIKE '". $_SESSION['login_idx'] ."'"; |
| 90 | } |
| 91 | |
| 92 | $query_str.= "
|
| 93 | ORDER BY |
| 94 | u.user_name ". $order;
|
| 95 | } |
| 96 | else {
|
| 97 | |
| 98 | /* equipped with just user privileges, show only personal buckets */
|
| 99 | if(!$this->parent->check_privileges('admin') && |
| 100 | !$this->parent->check_privileges('manager') && |
| 101 | isset($_SESSION['login_idx'])) { |
| 102 | $query_str.= "WHERE b.bucket_owner LIKE '". $_SESSION['login_idx'] ."'"; |
| 103 | } |
| 104 | |
| 105 | $query_str.= "
|
| 106 | ORDER BY |
| 107 | ". $column ." ". $order; |
| 108 | } |
| 109 | |
| 110 | $res_buckets = $nephthys->db->db_query($query_str); |
| 111 | |
| 112 | $cnt_buckets = 0;
|
| 113 | |
| 114 | while($bucket = $res_buckets->fetchrow()) {
|
| 115 | $this->avail_buckets[$cnt_buckets] = $bucket->bucket_idx;
|
| 116 | $this->buckets[$bucket->bucket_idx] = $bucket;
|
| 117 | $cnt_buckets++; |
| 118 | } |
| 119 | |
| 120 | $this->tmpl->assign('user_has_buckets', $cnt_buckets); |
| 121 | |
| 122 | } // __construct()
|
| 123 | |
| 124 | /* interface output */
|
| 125 | public function show() |
| 126 | {
|
| 127 | if(!$this->parent->is_logged_in()) { |
| 128 | $this->parent->_error($this->parent->_("##MANAGE_USERS##") ." - ". $this->parent->_("##NOT_ALLOWED##")); |
| 129 | return 0; |
| 130 | } |
| 131 | if(!isset($_GET['mode'])) |
| 132 | $_GET['mode'] = "show"; |
| 133 | if(!isset($_GET['idx']) || |
| 134 | (isset($_GET['idx']) && !is_numeric($_GET['idx']))) |
| 135 | $_GET['idx'] = 0; |
| 136 | |
| 137 | switch($_GET['mode']) { |
| 138 | case 'receive': |
| 139 | $this->tmpl->assign('bucket_owner', $_SESSION['login_idx']); |
| 140 | $this->tmpl->assign('bucket_expire', $this->parent->get_user_expire($_SESSION['login_idx'])); |
| 141 | return $this->tmpl->fetch('receive_form.tpl'); |
| 142 | case 'send': |
| 143 | $this->tmpl->assign('bucket_owner', $_SESSION['login_idx']); |
| 144 | $this->tmpl->assign('bucket_expire', $this->parent->get_user_expire($_SESSION['login_idx'])); |
| 145 | return $this->tmpl->fetch('send_form.tpl'); |
| 146 | case 'edit': |
| 147 | return $this->showEdit($_GET['idx']); |
| 148 | break;
|
| 149 | case 'notify': |
| 150 | return $this->notify(); |
| 151 | break;
|
| 152 | } |
| 153 | |
| 154 | } // show()
|
| 155 | |
| 156 | /**
|
| 157 | * display a page containing bucket info |
| 158 | * |
| 159 | * this function returns a page containing information |
| 160 | * about the requested (or previously created) bucket. |
| 161 | * |
| 162 | * @return string |
| 163 | */ |
| 164 | public function showBucket() |
| 165 | {
|
| 166 | if(!$this->parent->is_logged_in()) { |
| 167 | $this->parent->_error($this->parent->_("##MANAGE_USERS##") ." - ". $this->parent->_("##NOT_ALLOWED##")); |
| 168 | return 0; |
| 169 | } |
| 170 | |
| 171 | if(!isset($_GET['idx']) || empty($_GET['idx']) || |
| 172 | !is_numeric($_GET['idx']))
|
| 173 | return;
|
| 174 | |
| 175 | if($bucket = $this->db->db_fetchSingleRow(" |
| 176 | SELECT * |
| 177 | FROM |
| 178 | nephthys_buckets |
| 179 | WHERE |
| 180 | bucket_idx LIKE '". $_GET['idx'] ."'")) { |
| 181 | |
| 182 | $this->tmpl->assign('bucket_idx', $bucket->bucket_idx); |
| 183 | $this->tmpl->assign('bucket_name', $this->parent->unescape($bucket->bucket_name)); |
| 184 | $this->tmpl->assign('bucket_expire', $this->parent->get_user_expire($_SESSION['login_idx'])); |
| 185 | |
| 186 | if($bucket->bucket_expire != "-1") |
| 187 | $bucket_expire = $bucket->bucket_created + ($bucket->bucket_expire*86400);
|
| 188 | |
| 189 | $bucket_ftp = $this->parent->get_url('ftp', $bucket->bucket_hash); |
| 190 | $bucket_webdav = $this->parent->get_url('dav', $bucket->bucket_hash); |
| 191 | $bucket_webdav_vista = $this->parent->get_url('dav_vista', $bucket->bucket_hash); |
| 192 | |
| 193 | if($bucket->bucket_expire != "-1") |
| 194 | $this->tmpl->assign('bucket_expire', strftime("%Y-%m-%d", $bucket_expire)); |
| 195 | else
|
| 196 | $this->tmpl->assign('bucket_expire', $this->parent->_('##NEVER##')); |
| 197 | |
| 198 | $this->tmpl->assign('bucket_receiver', $this->parent->unescape($bucket->bucket_receiver)); |
| 199 | $this->tmpl->assign('bucket_webdav_path', $bucket_webdav); |
| 200 | $this->tmpl->assign('bucket_webdav_path_vista', $bucket_webdav_vista); |
| 201 | $this->tmpl->assign('bucket_ftp_path', $bucket_ftp); |
| 202 | |
| 203 | return $this->tmpl->fetch('saved_bucket.tpl'); |
| 204 | |
| 205 | } |
| 206 | |
| 207 | return;
|
| 208 | |
| 209 | } // showBucket()
|
| 210 | |
| 211 | /**
|
| 212 | * get bucket information & details |
| 213 | * |
| 214 | * this function returns informations about the requested |
| 215 | * bucket. how much diskspace it uses, ... |
| 216 | * |
| 217 | * @return string |
| 218 | */ |
| 219 | public function get_bucket_info() |
| 220 | {
|
| 221 | if(!($bucket = $this->get_bucket_details($this->id))) |
| 222 | return "unkown bucket"; |
| 223 | |
| 224 | $bucket_path = $this->parent->cfg->data_path
|
| 225 | ."/"
|
| 226 | . $bucket->bucket_hash; |
| 227 | |
| 228 | if(($used_diskspace = $this->parent->get_used_diskspace($bucket_path)) === false) { |
| 229 | return "Can not locate bucket in filesystem to get used diskspace"; |
| 230 | } |
| 231 | |
| 232 | $bucket_size = $this->parent->get_unit($used_diskspace);
|
| 233 | $bucket_details = $this->parent->get_dir_info($bucket_path);
|
| 234 | |
| 235 | $this->tmpl->assign('count_files', $bucket_details['files']); |
| 236 | $this->tmpl->assign('count_dirs', $bucket_details['dirs']); |
| 237 | $this->tmpl->assign('bucket_size', $bucket_size); |
| 238 | if($bucket_details['last_mod'] > 0) { |
| 239 | $this->tmpl->assign('bucket_last_mod', strftime("%c", $bucket_details['last_mod'])); |
| 240 | } |
| 241 | |
| 242 | $body = $this->tmpl->fetch('bucket_info.tpl'); |
| 243 | |
| 244 | return $body;
|
| 245 | |
| 246 | } // get_bucket_info()
|
| 247 | |
| 248 | public function notify() |
| 249 | {
|
| 250 | if(!($bucket = $this->get_bucket_details($this->id))) |
| 251 | return;
|
| 252 | |
| 253 | $bucket->bucket_sender = $this->parent->unescape($bucket->bucket_sender, false); |
| 254 | $bucket->bucket_receiver = $this->parent->unescape($bucket->bucket_receiver, false); |
| 255 | |
| 256 | /* the bucket sender */
|
| 257 | $sender = $bucket->bucket_sender; |
| 258 | $sender_text = $bucket->bucket_sender; |
| 259 | |
| 260 | /* if a bucket receiver has been specified, send mail to the receiver
|
| 261 | and in CC also to the sender |
| 262 | */ |
| 263 | if(isset($bucket->bucket_receiver) && !empty($bucket->bucket_receiver)) { |
| 264 | $receiver = Array($bucket->bucket_receiver, $bucket->bucket_sender); |
| 265 | $receiver_text = $bucket->bucket_receiver; |
| 266 | } |
| 267 | else {
|
| 268 | $receiver = Array($bucket->bucket_sender); |
| 269 | $receiver_text = $bucket->bucket_sender; |
| 270 | } |
| 271 | |
| 272 | $ftp_url = $this->parent->get_url('ftp', $bucket->bucket_hash); |
| 273 | $http_url = $this->parent->get_url('dav', $bucket->bucket_hash); |
| 274 | |
| 275 | if($bucket->bucket_expire != -1) { |
| 276 | $bucket_expire = $bucket->bucket_created + ($bucket->bucket_expire*86400);
|
| 277 | $bucket_expire = strftime("%d. %b. %Y", $bucket_expire);
|
| 278 | } |
| 279 | else {
|
| 280 | $bucket_expire = "never";
|
| 281 | } |
| 282 | |
| 283 | /* prepare the mail headers */
|
| 284 | $header['From'] = $sender_text;
|
| 285 | $header['To'] = $receiver_text;
|
| 286 | $header['Subject'] = "File sharing information"; |
| 287 | $header['Content-Type'] = "text/plain; charset=UTF-8"; |
| 288 | /* if a bucket receiver has been specified, send mail to the receiver
|
| 289 | and in CC also to the sender |
| 290 | */ |
| 291 | if(isset($bucket->bucket_receiver) && !empty($bucket->bucket_receiver)) |
| 292 | $header['CC'] = $bucket->bucket_sender;
|
| 293 | |
| 294 | |
| 295 | /* prepare the notification text out of the smarty template */
|
| 296 | $text = new NEPHTHYS_TMPL($this->parent); |
| 297 | $text->assign('bucket_sender', $sender_text);
|
| 298 | $text->assign('bucket_receiver', $receiver_text);
|
| 299 | |
| 300 | /* if the user has updated his profile with the full name, use it, otherwise
|
| 301 | take the login name instead. |
| 302 | */ |
| 303 | if($this->parent->get_user_fullname($bucket->bucket_owner)) |
| 304 | $text->assign('bucket_sender_name', $this->parent->get_user_fullname($bucket->bucket_owner)); |
| 305 | else
|
| 306 | $text->assign('bucket_sender_name', $this->parent->get_user_name($bucket->bucket_owner)); |
| 307 | |
| 308 | $text->assign('bucket_ftp_url', $ftp_url);
|
| 309 | $text->assign('bucket_http_url', $http_url);
|
| 310 | $text->assign('bucket_servername', $this->parent->cfg->servername); |
| 311 | $text->assign('bucket_expire', $bucket_expire);
|
| 312 | $text->assign('bucket_hash', $bucket->bucket_hash);
|
| 313 | |
| 314 | /* if a bucket description has been specified, assign it to the template */
|
| 315 | if(isset($bucket->bucket_note) && !empty($bucket->bucket_note)) { |
| 316 | $bucket->bucket_note = $this->parent->unescape($bucket->bucket_note, false); |
| 317 | $text->assign('bucket_note', $bucket->bucket_note);
|
| 318 | } |
| 319 | |
| 320 | /* now translate the template and return the result as a string */
|
| 321 | $body = $text->fetch('notify.tpl');
|
| 322 | |
| 323 | // if you want to use php's own mail() function, remove the
|
| 324 | // comment from the next two lines and wipe out the sendmail
|
| 325 | // lines below.
|
| 326 | // $mailer =& Mail::factory('mail');
|
| 327 | // $status = $mailer->send($receiver, $header, $body);
|
| 328 | |
| 329 | // usually this do not need to be set.
|
| 330 | // $params['sendmail_path'] = '/usr/bin/sendmail';
|
| 331 | $params['sendmail_arg'] = '-f'. $sender; |
| 332 | |
| 333 | $mailer =& Mail::factory('sendmail', $params);
|
| 334 | $status = $mailer->send($receiver, $header, $body); |
| 335 | |
| 336 | if(PEAR::isError($status)) {
|
| 337 | return $status->getMessage();
|
| 338 | } |
| 339 | |
| 340 | /* set a flag in the database, that the bucket has been notified */
|
| 341 | $this->db->db_query(" |
| 342 | UPDATE nephthys_buckets |
| 343 | SET |
| 344 | bucket_notified='Y' |
| 345 | WHERE |
| 346 | bucket_idx LIKE '". $this->id ."' |
| 347 | ");
|
| 348 | |
| 349 | return "ok;". $this->parent->_("##NOTIFY_SUCCESS##"); |
| 350 | |
| 351 | } // notify()
|
| 352 | |
| 353 | /**
|
| 354 | * notify expired bucket |
| 355 | * |
| 356 | * this bucket notifies the bucket-owner about expiring buckets |
| 357 | * @param int $bucket_idx |
| 358 | */ |
| 359 | public function notify_expired_bucket($bucket_idx) |
| 360 | {
|
| 361 | $bucket = $this->get_bucket_details($bucket_idx);
|
| 362 | |
| 363 | $owner_email = $this->parent->get_user_email($bucket->bucket_owner);
|
| 364 | $owner_email = $this->parent->unescape($owner_email, false); |
| 365 | |
| 366 | /* the bucket sender */
|
| 367 | if(isset($this->parent->cfg->system_mail)) { |
| 368 | $sender = $this->parent->cfg->system_mail;
|
| 369 | $sender_text = $this->parent->cfg->system_mail;
|
| 370 | } |
| 371 | else {
|
| 372 | $sender = $owner_email; |
| 373 | $sender_text = $owner_email; |
| 374 | } |
| 375 | |
| 376 | /* the bucket receiver */
|
| 377 | $receiver = Array($owner_email); |
| 378 | $receiver_text = $owner_email; |
| 379 | |
| 380 | /* prepare the mail headers */
|
| 381 | $header['From'] = $sender_text;
|
| 382 | $header['To'] = $receiver_text;
|
| 383 | $header['Subject'] = "Your Nephthys bucket has expired"; |
| 384 | $header['Content-Type'] = "text/plain; charset=UTF-8"; |
| 385 | |
| 386 | /* prepare the notification text out of the Smarty template */
|
| 387 | $text = new NEPHTHYS_TMPL($this->parent); |
| 388 | $text->assign('bucket_name', $bucket->bucket_name);
|
| 389 | |
| 390 | /* now translate the template and return the result as a string */
|
| 391 | $body = $text->fetch('notify_expired.tpl');
|
| 392 | |
| 393 | // if you want to use php's own mail() function, remove the
|
| 394 | // comment from the next two lines and wipe out the sendmail
|
| 395 | // lines below.
|
| 396 | // $mailer =& Mail::factory('mail');
|
| 397 | // $status = $mailer->send($receiver, $header, $body);
|
| 398 | |
| 399 | // usually this do not need to be set.
|
| 400 | // $params['sendmail_path'] = '/usr/bin/sendmail';
|
| 401 | $params['sendmail_arg'] = '-f'. $sender; |
| 402 | |
| 403 | $mailer =& Mail::factory('sendmail', $params);
|
| 404 | $status = $mailer->send($receiver, $header, $body); |
| 405 | |
| 406 | if(PEAR::isError($status)) {
|
| 407 | die($status->getMessage());
|
| 408 | } |
| 409 | |
| 410 | return true; |
| 411 | |
| 412 | } // notify_expired_buckets()
|
| 413 | |
| 414 | public function store() |
| 415 | {
|
| 416 | /* if not a privileged user, then set the email address from his profile */
|
| 417 | if($this->parent->check_privileges('user')) { |
| 418 | $_POST['bucket_sender'] = $this->parent->get_my_email(); |
| 419 | } |
| 420 | /* if not a privilged user, then set the owner to his id */
|
| 421 | if($this->parent->check_privileges('user')) { |
| 422 | $_POST['bucket_owner'] = $_SESSION['login_idx']; |
| 423 | } |
| 424 | |
| 425 | isset($_POST['bucket_new']) && $_POST['bucket_new'] == 1 ? $new = 1 : $new = NULL; |
| 426 | |
| 427 | if(!isset($_POST['bucket_name']) || empty($_POST['bucket_name'])) { |
| 428 | return $this->parent->_("##FAILURE_ENTER_BUCKET_NAME##"); |
| 429 | } |
| 430 | if(!isset($_POST['bucket_sender']) || empty($_POST['bucket_name'])) { |
| 431 | return $this->parent->_("##FAILURE_ENTER_BUCKET_SENDER##"); |
| 432 | } |
| 433 | if(!$this->parent->is_valid_email($_POST['bucket_sender'])) { |
| 434 | return $this->parent->_("##FAILURE_ENTER_VALID_SENDER##"); |
| 435 | } |
| 436 | if(isset($_POST['bucketmode']) && $_POST['bucketmode'] == "receive" && |
| 437 | !isset($_POST['bucket_receiver']) || empty($_POST['bucket_name'])) { |
| 438 | return $this->parent->_("##FAILURE_ENTER_BUCKET_RECEIVER##"); |
| 439 | } |
| 440 | if(isset($_POST['bucketmode']) && $_POST['bucketmode'] == "receive" && |
| 441 | !$this->parent->is_valid_email($_POST['bucket_receiver'])) { |
| 442 | return $this->parent->_("##FAILURE_ENTER_VALID_RECEIVER##"); |
| 443 | } |
| 444 | /* for "send" it's not a must to specify a receiver, anyway, if one is there
|
| 445 | validate it... |
| 446 | */ |
| 447 | if(isset($_POST['bucketmode']) && $_POST['bucketmode'] == "send" && |
| 448 | isset($_POST['bucket_receiver']) && !empty($_POST['bucket_receiver']) && |
| 449 | !$this->parent->is_valid_email($_POST['bucket_receiver'])) { |
| 450 | return $this->parent->_("##FAILURE_ENTER_VALID_RECEIVER##"); |
| 451 | } |
| 452 | |
| 453 | /* first of all we add the email address to the addressbook if requested.
|
| 454 | If after something goes wrong, the address is already in the database |
| 455 | and user saves some keystrokes... |
| 456 | |
| 457 | but only if the "add email to address-book" is checked and a receiver |
| 458 | address has been specified. |
| 459 | */ |
| 460 | if(isset($_POST['bucket_receiver_to_ab']) && |
| 461 | $_POST['bucket_receiver_to_ab'] == 'Y' && |
| 462 | isset($_POST['bucket_receiver']) && |
| 463 | !empty($_POST['bucket_receiver'])) { |
| 464 | $this->parent->add_to_addressbook($_POST['bucket_receiver']); |
| 465 | } |
| 466 | |
| 467 | if(!isset($_POST['bucket_notify_on_expire'])) |
| 468 | $_POST['bucket_notify_on_expire'] = 'N'; |
| 469 | |
| 470 | if(isset($new)) { |
| 471 | |
| 472 | if(isset($_POST['bucket_receiver'])) |
| 473 | $hash = $this->parent->get_sha_hash($_POST['bucket_sender'], $_POST['bucket_receiver']); |
| 474 | else {
|
| 475 | $_POST['bucket_receiver'] = ""; |
| 476 | $hash = $this->parent->get_sha_hash($_POST['bucket_sender']); |
| 477 | } |
| 478 | |
| 479 | $sth = $this->db->db_prepare(" |
| 480 | INSERT INTO nephthys_buckets ( |
| 481 | bucket_idx, |
| 482 | bucket_name, bucket_sender, bucket_receiver, bucket_created, |
| 483 | bucket_expire, bucket_note, bucket_hash, bucket_owner, |
| 484 | bucket_active, bucket_notify_on_expire |
| 485 | ) VALUES ( |
| 486 | NULL, |
| 487 | ?, ?, ?, '". mktime() ."', |
| 488 | ?, ?, '". $hash ."', ?, |
| 489 | 'Y', ? |
| 490 | ) |
| 491 | ");
|
| 492 | |
| 493 | $this->db->db_execute($sth, array( |
| 494 | $_POST['bucket_name'],
|
| 495 | $_POST['bucket_sender'],
|
| 496 | $_POST['bucket_receiver'],
|
| 497 | $_POST['bucket_expire'],
|
| 498 | $_POST['bucket_note'],
|
| 499 | $_POST['bucket_owner'],
|
| 500 | $_POST['bucket_notify_on_expire'],
|
| 501 | )); |
| 502 | |
| 503 | $this->id = $this->db->db_getid(); |
| 504 | $last_id = $this->id;
|
| 505 | |
| 506 | if(!mkdir($this->parent->cfg->data_path ."/". $hash)) { |
| 507 | return "There was a error creating the bucket directory. Contact your administrator!"; |
| 508 | } |
| 509 | |
| 510 | if(isset($_POST['bucketmode']) && $_POST['bucketmode'] == "receive" && |
| 511 | isset($_POST['notifybucket']) && $_POST['notifybucket'] == "true") { |
| 512 | |
| 513 | $this->notify();
|
| 514 | |
| 515 | } |
| 516 | |
| 517 | // Create IE WebDAV-open-HTML file
|
| 518 | $bucket_webdav = $this->parent->get_url('dav', $hash); |
| 519 | $this->tmpl->assign('bucket_webdav_path', $bucket_webdav); |
| 520 | $html_file = $this->tmpl->fetch("ie_webdav.tpl"); |
| 521 | |
| 522 | if($fileh = fopen($this->parent->cfg->data_path ."/". $hash ."/webdav.html", 'w')) { |
| 523 | fwrite($fileh, $html_file); |
| 524 | fclose($fileh); |
| 525 | } |
| 526 | |
| 527 | } |
| 528 | else {
|
| 529 | |
| 530 | $sth = $this->db->db_prepare(" |
| 531 | UPDATE nephthys_buckets |
| 532 | SET |
| 533 | bucket_name=?, |
| 534 | bucket_sender=?, |
| 535 | bucket_receiver=?, |
| 536 | bucket_expire=?, |
| 537 | bucket_note=?, |
| 538 | bucket_owner=?, |
| 539 | bucket_active='Y', |
| 540 | bucket_notify_on_expire=? |
| 541 | WHERE |
| 542 | bucket_idx=? |
| 543 | ");
|
| 544 | |
| 545 | $this->db->db_execute($sth, array( |
| 546 | $_POST['bucket_name'],
|
| 547 | $_POST['bucket_sender'],
|
| 548 | $_POST['bucket_receiver'],
|
| 549 | $_POST['bucket_expire'],
|
| 550 | $_POST['bucket_note'],
|
| 551 | $_POST['bucket_owner'],
|
| 552 | $_POST['bucket_notify_on_expire'],
|
| 553 | $_POST['bucket_idx'],
|
| 554 | )); |
| 555 | |
| 556 | } |
| 557 | |
| 558 | if(!isset($last_id)) |
| 559 | return "ok"; |
| 560 | |
| 561 | return "ok;". $last_id; |
| 562 | |
| 563 | } // store()
|
| 564 | |
| 565 | public function showList() |
| 566 | {
|
| 567 | return $this->tmpl->fetch("bucket_list.tpl"); |
| 568 | |
| 569 | } // showList()
|
| 570 | |
| 571 | /**
|
| 572 | * template function which will be called from the buckets listing template |
| 573 | */ |
| 574 | public function smarty_bucket_list($params, $content, &$smarty, &$repeat) |
| 575 | {
|
| 576 | $index = $this->tmpl->get_template_vars('smarty.IB.bucket_list.index'); |
| 577 | if(!$index) {
|
| 578 | $index = 0;
|
| 579 | } |
| 580 | |
| 581 | if($index < count($this->avail_buckets)) { |
| 582 | |
| 583 | $bucket_idx = $this->avail_buckets[$index];
|
| 584 | $bucket = $this->buckets[$bucket_idx];
|
| 585 | |
| 586 | $user_priv = $this->parent->get_user_priv($_SESSION['login_idx']); |
| 587 | |
| 588 | if($bucket->bucket_expire != "-1") |
| 589 | $bucket_expire = $bucket->bucket_created + ($bucket->bucket_expire*86400);
|
| 590 | $bucket_owner = $this->parent->get_user_name($bucket->bucket_owner);
|
| 591 | $bucket_owner_full = $this->parent->get_user_fullname($bucket->bucket_owner);
|
| 592 | |
| 593 | $bucket_ftp = $this->parent->get_url('ftp', $bucket->bucket_hash); |
| 594 | $bucket_webdav = $this->parent->get_url('dav', $bucket->bucket_hash); |
| 595 | $bucket_webdav_vista = $this->parent->get_url('dav_vista', $bucket->bucket_hash); |
| 596 | |
| 597 | $this->tmpl->assign('bucket_idx', $bucket_idx); |
| 598 | $this->tmpl->assign('bucket_name', $this->parent->unescape($bucket->bucket_name)); |
| 599 | $this->tmpl->assign('bucket_created', strftime("%Y-%m-%d", $bucket->bucket_created)); |
| 600 | if($bucket->bucket_expire != "-1") |
| 601 | $this->tmpl->assign('bucket_expire', strftime("%Y-%m-%d", $bucket_expire)); |
| 602 | else
|
| 603 | $this->tmpl->assign('bucket_expire', $this->parent->_('##NEVER##')); |
| 604 | $this->tmpl->assign('bucket_owner', $this->parent->unescape($bucket_owner)); |
| 605 | $this->tmpl->assign('bucket_owner_full', $this->parent->unescape($bucket_owner_full)); |
| 606 | $this->tmpl->assign('bucket_owner_idx', $bucket->bucket_owner); |
| 607 | $this->tmpl->assign('bucket_receiver', $this->parent->unescape($bucket->bucket_receiver)); |
| 608 | $this->tmpl->assign('bucket_webdav_path', $bucket_webdav); |
| 609 | $this->tmpl->assign('bucket_webdav_path_vista', $bucket_webdav_vista); |
| 610 | $this->tmpl->assign('bucket_ftp_path', $bucket_ftp); |
| 611 | $this->tmpl->assign('bucket_notified', $bucket->bucket_notified); |
| 612 | $this->tmpl->assign('bucket_hash', $bucket->bucket_hash); |
| 613 | |
| 614 | $index++; |
| 615 | $this->tmpl->assign('smarty.IB.bucket_list.index', $index); |
| 616 | $repeat = true;
|
| 617 | } |
| 618 | else {
|
| 619 | $repeat = false;
|
| 620 | } |
| 621 | |
| 622 | return $content;
|
| 623 | |
| 624 | } // smarty_bucket_list()
|
| 625 | |
| 626 | public function delete() |
| 627 | {
|
| 628 | if(isset($_POST['idx']) && is_numeric($_POST['idx'])) { |
| 629 | |
| 630 | /* ensure unprivileged users can only delete their own buckets */
|
| 631 | if($this->parent->check_privileges('user') && !$this->parent->is_bucket_owner($_POST['idx'])) { |
| 632 | return "You are only allowed to delete buckets you own!"; |
| 633 | } |
| 634 | |
| 635 | $hash = $this->get_bucket_hash($_POST['idx']); |
| 636 | |
| 637 | if(!$hash) {
|
| 638 | return "Can't locate hash value of the bucket that was requested to be deleted."; |
| 639 | } |
| 640 | |
| 641 | if(!$this->del_data_directory($hash)) { |
| 642 | $this->parent->_error("Removing bucket directory ". $this->parent->cfg->data_path ."/". $hash ." not possible"); |
| 643 | } |
| 644 | |
| 645 | $this->delete_bucket($_POST['idx']); |
| 646 | } |
| 647 | |
| 648 | print "ok"; |
| 649 | |
| 650 | } // delete()
|
| 651 | |
| 652 | /**
|
| 653 | * return bucket's SHA1 hash |
| 654 | * |
| 655 | * this function will return the SHA1 hash of the |
| 656 | * requested bucket (by database primary key) |
| 657 | */ |
| 658 | private function get_bucket_hash($idx) |
| 659 | {
|
| 660 | if($row = $this->db->db_fetchSingleRow(" |
| 661 | SELECT bucket_hash |
| 662 | FROM nephthys_buckets |
| 663 | WHERE bucket_idx LIKE '". $idx ."' |
| 664 | ")) {
|
| 665 | |
| 666 | if(isset($row->bucket_hash)) |
| 667 | return $row->bucket_hash;
|
| 668 | |
| 669 | } |
| 670 | |
| 671 | return 0; |
| 672 | |
| 673 | } // get_bucket_hash();
|
| 674 | |
| 675 | public function del_data_directory($hash) |
| 676 | {
|
| 677 | /* if something went wrong before, do not delete anything */
|
| 678 | if(!is_string($hash) || empty($hash)) |
| 679 | return false; |
| 680 | |
| 681 | $invalid_path = Array( |
| 682 | "/",
|
| 683 | "/usr",
|
| 684 | "/var",
|
| 685 | "/home",
|
| 686 | "/boot",
|
| 687 | $this->parent->cfg->base_path);
|
| 688 | |
| 689 | /*
|
| 690 | * ensure that this function can not malfunction |
| 691 | */ |
| 692 | if(in_array($this->parent->cfg->data_path, $invalid_path)) |
| 693 | return false; |
| 694 | |
| 695 | if($this->data_directory_exists($hash)) |
| 696 | return $this->parent->deltree($this->parent->cfg->data_path ."/". $hash); |
| 697 | |
| 698 | return false; |
| 699 | |
| 700 | } // del_data_directory()
|
| 701 | |
| 702 | /**
|
| 703 | * check if data directory exists |
| 704 | * |
| 705 | * returns true, if the specified data-directory + hash-named |
| 706 | * directory really exists. |
| 707 | * @param string $hash |
| 708 | * @return bool |
| 709 | */ |
| 710 | private function data_directory_exists($hash) |
| 711 | {
|
| 712 | if(file_exists($this->parent->cfg->data_path ."/". $hash)) |
| 713 | return true; |
| 714 | |
| 715 | return false; |
| 716 | |
| 717 | } // data_directory_exists()
|
| 718 | |
| 719 | /**
|
| 720 | * display interface to create or edit users |
| 721 | * @param int $idx |
| 722 | */ |
| 723 | private function showEdit($idx) |
| 724 | {
|
| 725 | /* If authentication is enabled, check permissions */
|
| 726 | if(!$this->parent->is_logged_in()) { |
| 727 | $this->parent->_error($this->parent->_("##MANAGE_USERS##") ." - ". $this->parent->_("##NOT_ALLOWED##")); |
| 728 | return 0; |
| 729 | } |
| 730 | |
| 731 | if($idx != 0) { |
| 732 | $bucket = $this->db->db_fetchSingleRow(" |
| 733 | SELECT * |
| 734 | FROM nephthys_buckets |
| 735 | WHERE |
| 736 | bucket_idx LIKE '". $idx ."' |
| 737 | ");
|
| 738 | |
| 739 | $this->tmpl->assign('bucket_idx', $idx); |
| 740 | $this->tmpl->assign('bucket_name', $this->parent->unescape($bucket->bucket_name)); |
| 741 | $this->tmpl->assign('bucket_sender', $this->parent->unescape($bucket->bucket_sender)); |
| 742 | $this->tmpl->assign('bucket_receiver', $this->parent->unescape($bucket->bucket_receiver)); |
| 743 | $this->tmpl->assign('bucket_expire', $bucket->bucket_expire); |
| 744 | $this->tmpl->assign('bucket_note', $this->parent->unescape($bucket->bucket_note)); |
| 745 | $this->tmpl->assign('bucket_owner', $this->parent->unescape($bucket->bucket_owner)); |
| 746 | $this->tmpl->assign('bucket_active', $bucket->bucket_active); |
| 747 | $this->tmpl->assign('bucket_notify_on_expire', $bucket->bucket_notify_on_expire); |
| 748 | |
| 749 | } |
| 750 | |
| 751 | return $this->tmpl->fetch("bucket_edit.tpl"); |
| 752 | |
| 753 | } // showEdit()
|
| 754 | |
| 755 | /**
|
| 756 | * get bucket details |
| 757 | * |
| 758 | * this function returns a object containing all |
| 759 | * informations about a bucket-object in database. |
| 760 | * @param int $idx |
| 761 | * @return object |
| 762 | */ |
| 763 | public function get_bucket_details($idx) |
| 764 | {
|
| 765 | if($bucket = $this->db->db_fetchSingleRow(" |
| 766 | SELECT * |
| 767 | FROM |
| 768 | nephthys_buckets |
| 769 | WHERE |
| 770 | bucket_idx='". $idx ."'")) { |
| 771 | |
| 772 | return $bucket;
|
| 773 | |
| 774 | } |
| 775 | |
| 776 | return NULL;
|
| 777 | |
| 778 | } // get_bucket_details()
|
| 779 | |
| 780 | /**
|
| 781 | * get expired buckets |
| 782 | * |
| 783 | * this function will return an array consiting the row id's of all |
| 784 | * expired buckets. |
| 785 | * @return array |
| 786 | */ |
| 787 | public function get_expired_buckets() |
| 788 | {
|
| 789 | |
| 790 | $expired_buckets = Array(); |
| 791 | |
| 792 | /* get all buckets */
|
| 793 | $buckets = $this->db->db_query(" |
| 794 | SELECT |
| 795 | b.bucket_idx as bucket_idx, |
| 796 | b.bucket_expire as bucket_expire, |
| 797 | b.bucket_created as bucket_created |
| 798 | FROM |
| 799 | nephthys_buckets b |
| 800 | INNER JOIN |
| 801 | nephthys_users u |
| 802 | ON |
| 803 | b.bucket_owner=u.user_idx |
| 804 | ");
|
| 805 | |
| 806 | while($bucket = $buckets->fetchRow()) {
|
| 807 | |
| 808 | /* don't care about never-expiring buckets */
|
| 809 | if($bucket->bucket_expire == -1) |
| 810 | continue;
|
| 811 | |
| 812 | /* check if the bucket has expired */
|
| 813 | if(($bucket->bucket_created + ($bucket->bucket_expire * 86400)) <= mktime()) { |
| 814 | array_push($expired_buckets, $bucket->bucket_idx); |
| 815 | } |
| 816 | } |
| 817 | |
| 818 | return $expired_buckets;
|
| 819 | |
| 820 | } // get_expired_buckets()
|
| 821 | |
| 822 | /**
|
| 823 | * delete bucket |
| 824 | * |
| 825 | * this function deletes a bucket ONLY from the database identified |
| 826 | * by its row id. |
| 827 | * @param int $idx |
| 828 | * @return bool |
| 829 | */ |
| 830 | public function delete_bucket($idx) |
| 831 | {
|
| 832 | if($this->db->db_query(" |
| 833 | DELETE FROM |
| 834 | nephthys_buckets |
| 835 | WHERE |
| 836 | bucket_idx LIKE '". $idx ."'")) { |
| 837 | |
| 838 | return true; |
| 839 | |
| 840 | } |
| 841 | |
| 842 | return false; |
| 843 | |
| 844 | } // delete_bucket()
|
| 845 | |
| 846 | } // class NEPHTHYS_BUCKETS
|
| 847 | |
| 848 | // vim: set filetype=php expandtab softtabstop=3 tabstop=3 shiftwidth=3 autoindent smartindent:
|
| 849 | ?> |
| 850 |