root / nephthys_watch.php
View | Annotate | Download (4.9 KB)
| 1 | fff2a093 | Andreas | #!/usr/bin/php
|
|---|---|---|---|
| 2 | fff2a093 | Andreas | <?php
|
| 3 | fff2a093 | Andreas | |
| 4 | fff2a093 | Andreas | /***************************************************************************
|
| 5 | fff2a093 | Andreas | * |
| 6 | 9a37d81c | Andreas | * Nephthys - file sharing management |
| 7 | fff2a093 | Andreas | * Copyright (c) by Andreas Unterkircher, unki@netshadow.at |
| 8 | fff2a093 | Andreas | * |
| 9 | 9a37d81c | Andreas | * This file is part of Nephthys. |
| 10 | 9a37d81c | Andreas | * |
| 11 | 9a37d81c | Andreas | * Nephthys is free software: you can redistribute it and/or modify |
| 12 | fff2a093 | Andreas | * it under the terms of the GNU General Public License as published by |
| 13 | 9a37d81c | Andreas | * the Free Software Foundation, either version 3 of the License, or |
| 14 | 9a37d81c | Andreas | * (at your option) any later version. |
| 15 | fff2a093 | Andreas | * |
| 16 | 9a37d81c | Andreas | * Nephthys is distributed in the hope that it will be useful, |
| 17 | fff2a093 | Andreas | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | fff2a093 | Andreas | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | fff2a093 | Andreas | * GNU General Public License for more details. |
| 20 | fff2a093 | Andreas | * |
| 21 | fff2a093 | Andreas | * You should have received a copy of the GNU General Public License |
| 22 | 9a37d81c | Andreas | * along with Nephthys. If not, see <http://www.gnu.org/licenses/>. |
| 23 | fff2a093 | Andreas | * |
| 24 | fff2a093 | Andreas | ***************************************************************************/ |
| 25 | fff2a093 | Andreas | |
| 26 | fff2a093 | Andreas | if(!isset($_SERVER['argv'])) { |
| 27 | ac5b6e1f | Andreas | die("This script needs to be called from command line."); |
| 28 | fff2a093 | Andreas | } |
| 29 | fff2a093 | Andreas | |
| 30 | ac5b6e1f | Andreas | class NEPHTHYS_WATCH {
|
| 31 | ac5b6e1f | Andreas | |
| 32 | ac5b6e1f | Andreas | private $db;
|
| 33 | ac5b6e1f | Andreas | private $parent;
|
| 34 | ac5b6e1f | Andreas | private $verbose;
|
| 35 | ac5b6e1f | Andreas | |
| 36 | ac5b6e1f | Andreas | /**
|
| 37 | ac5b6e1f | Andreas | * NEPHTHYS_WATCH constructor |
| 38 | ac5b6e1f | Andreas | * |
| 39 | ac5b6e1f | Andreas | * Initialize the NEPHTHYS_WATCH class |
| 40 | ac5b6e1f | Andreas | */ |
| 41 | ac5b6e1f | Andreas | public function __construct() |
| 42 | ac5b6e1f | Andreas | {
|
| 43 | ac5b6e1f | Andreas | require_once "nephthys.class.php"; |
| 44 | ac5b6e1f | Andreas | |
| 45 | ac5b6e1f | Andreas | $nephthys = new NEPHTHYS;
|
| 46 | ac5b6e1f | Andreas | $this->parent =& $nephthys;
|
| 47 | ac5b6e1f | Andreas | $this->db =& $nephthys->db;
|
| 48 | ac5b6e1f | Andreas | |
| 49 | ac5b6e1f | Andreas | $this->verbose = false; |
| 50 | ac5b6e1f | Andreas | |
| 51 | ac5b6e1f | Andreas | $short_options = "";
|
| 52 | ac5b6e1f | Andreas | $short_options.= "h"; /* help */ |
| 53 | ac5b6e1f | Andreas | $short_options.= "v"; /* overwrite */ |
| 54 | ac5b6e1f | Andreas | |
| 55 | ac5b6e1f | Andreas | $long_options = array(
|
| 56 | ac5b6e1f | Andreas | "help",
|
| 57 | ac5b6e1f | Andreas | "verbose",
|
| 58 | ac5b6e1f | Andreas | ); |
| 59 | ac5b6e1f | Andreas | |
| 60 | ac5b6e1f | Andreas | /* command line option specified? */
|
| 61 | ac5b6e1f | Andreas | if(isset($_SERVER['argc']) && $_SERVER['argc'] > 1) { |
| 62 | ac5b6e1f | Andreas | /* validate */
|
| 63 | ac5b6e1f | Andreas | $con = new Console_Getopt;
|
| 64 | ac5b6e1f | Andreas | $args = $con->readPHPArgv(); |
| 65 | ac5b6e1f | Andreas | $options = $con->getopt($args, $short_options, $long_options); |
| 66 | ac5b6e1f | Andreas | |
| 67 | ac5b6e1f | Andreas | if(PEAR::isError($options)) {
|
| 68 | ac5b6e1f | Andreas | die ("Error in command line: " . $options->getMessage() . "\n"); |
| 69 | ac5b6e1f | Andreas | } |
| 70 | fff2a093 | Andreas | |
| 71 | ac5b6e1f | Andreas | foreach($options[0] as $opt) { |
| 72 | ac5b6e1f | Andreas | switch($opt[0]) { |
| 73 | ac5b6e1f | Andreas | case 'h': |
| 74 | ac5b6e1f | Andreas | case '--help': |
| 75 | ac5b6e1f | Andreas | print "nephthys_watch.php - cleanup expired buckets\n" |
| 76 | ac5b6e1f | Andreas | ."http://oss.netshadow.at\n"
|
| 77 | ac5b6e1f | Andreas | ."\n"
|
| 78 | ac5b6e1f | Andreas | ." ./nephthys_watch.php <options>\n"
|
| 79 | ac5b6e1f | Andreas | ."\n"
|
| 80 | ac5b6e1f | Andreas | ." -h ... this help text\n"
|
| 81 | ac5b6e1f | Andreas | ." -v ... be verbose\n"
|
| 82 | ac5b6e1f | Andreas | ."\n";
|
| 83 | ac5b6e1f | Andreas | exit(0); |
| 84 | ac5b6e1f | Andreas | break;
|
| 85 | ac5b6e1f | Andreas | case 'v': |
| 86 | ac5b6e1f | Andreas | case '--verbose': |
| 87 | ac5b6e1f | Andreas | $this->verbose = true; |
| 88 | ac5b6e1f | Andreas | break;
|
| 89 | ac5b6e1f | Andreas | default:
|
| 90 | b340940a | Andreas | $this->parent->_error("invalid option(s) provided. use --help to see possibile options."); |
| 91 | ac5b6e1f | Andreas | exit(1); |
| 92 | ac5b6e1f | Andreas | break;
|
| 93 | fff2a093 | Andreas | } |
| 94 | fff2a093 | Andreas | } |
| 95 | ac5b6e1f | Andreas | } |
| 96 | fff2a093 | Andreas | |
| 97 | ac5b6e1f | Andreas | $this->watch();
|
| 98 | ac5b6e1f | Andreas | |
| 99 | ac5b6e1f | Andreas | } // __construct()
|
| 100 | ac5b6e1f | Andreas | |
| 101 | ac5b6e1f | Andreas | public function watch() |
| 102 | ac5b6e1f | Andreas | {
|
| 103 | ac5b6e1f | Andreas | $nephthys_buckets = new NEPHTHYS_BUCKETS;
|
| 104 | 385f188a | Andreas | $expired_buckets = $nephthys_buckets->get_expired_buckets(); |
| 105 | ac5b6e1f | Andreas | |
| 106 | 385f188a | Andreas | foreach($expired_buckets as $bucket) { |
| 107 | 385f188a | Andreas | |
| 108 | 385f188a | Andreas | $found_error = false;
|
| 109 | 385f188a | Andreas | |
| 110 | 385f188a | Andreas | $bucket_details = $nephthys_buckets->get_bucket_details($bucket); |
| 111 | 385f188a | Andreas | |
| 112 | 385f188a | Andreas | $log_msg = |
| 113 | 385f188a | Andreas | "Bucket: ". $bucket_details->bucket_name .", ". |
| 114 | 385f188a | Andreas | "Owner: ". $this->parent->get_user_name($bucket_details->bucket_owner) .", ". |
| 115 | 385f188a | Andreas | "Expired on: ". date("%c", $bucket_details->bucket_expire) .", "; |
| 116 | 385f188a | Andreas | |
| 117 | 385f188a | Andreas | /* does the bucket-directory still exist? */
|
| 118 | 385f188a | Andreas | if(file_exists($this->parent->cfg->data_path ."/". $bucket_details->bucket_hash)) { |
| 119 | 385f188a | Andreas | /* lets delete the bucket-directory recursivly */
|
| 120 | 385f188a | Andreas | if(!$nephthys_buckets->del_data_directory($bucket_details->bucket_hash)) {
|
| 121 | 385f188a | Andreas | $this->parent->_error("ERROR: Can't delete bucket directory ". $this->parent->cfg->data_path ."/". $bucket_details->bucket_hash ."."); |
| 122 | 385f188a | Andreas | $found_error = true;
|
| 123 | ac5b6e1f | Andreas | } |
| 124 | fff2a093 | Andreas | } |
| 125 | 385f188a | Andreas | else {
|
| 126 | 385f188a | Andreas | $this->parent->_error("WARNING: Bucket directory ". $this->parent->cfg->data_path ."/". $bucket_details->bucket_hash ." no longer exists."); |
| 127 | 385f188a | Andreas | } |
| 128 | 385f188a | Andreas | |
| 129 | 385f188a | Andreas | /* if directory-deletion was successful, delete bucket from database */
|
| 130 | 385f188a | Andreas | if(empty($found_error)) { |
| 131 | 385f188a | Andreas | |
| 132 | 385f188a | Andreas | /* check if deletion on this bucket needs to be notified */
|
| 133 | 385f188a | Andreas | if($bucket_details->bucket_notify_on_expire == 'Y') { |
| 134 | 385f188a | Andreas | $nephthys_buckets->notify_expired_bucket($bucket); |
| 135 | 385f188a | Andreas | } |
| 136 | 385f188a | Andreas | /* delete bucket from database */
|
| 137 | 385f188a | Andreas | $nephthys_buckets->delete_bucket($bucket); |
| 138 | 385f188a | Andreas | |
| 139 | 385f188a | Andreas | if(!empty($this->verbose)) { |
| 140 | 385f188a | Andreas | $log_msg.= "deleted";
|
| 141 | 385f188a | Andreas | } |
| 142 | 385f188a | Andreas | } |
| 143 | 385f188a | Andreas | |
| 144 | 385f188a | Andreas | if(empty($found_error) && !empty($this->verbose)) { |
| 145 | 385f188a | Andreas | $this->parent->_error($log_msg);
|
| 146 | 385f188a | Andreas | } |
| 147 | fff2a093 | Andreas | } |
| 148 | ac5b6e1f | Andreas | |
| 149 | ac5b6e1f | Andreas | } // watch()
|
| 150 | ac5b6e1f | Andreas | |
| 151 | ac5b6e1f | Andreas | } // NEPHTHYS_WATCH
|
| 152 | ac5b6e1f | Andreas | |
| 153 | ac5b6e1f | Andreas | $class = new NEPHTHYS_WATCH;
|
| 154 | fff2a093 | Andreas | |
| 155 | b392cb9b | Andreas | // vim: set filetype=php expandtab softtabstop=3 tabstop=3 shiftwidth=3 autoindent smartindent:
|
| 156 | fff2a093 | Andreas | ?> |