| 1 |
<?php |
|---|
| 2 |
function vmailadmin_get_title($action, $context="", $account="") { |
|---|
| 3 |
$title = "<h3>" . _("Voicemail Administration") . "<br /> "; |
|---|
| 4 |
switch ($action) { |
|---|
| 5 |
case "tz": |
|---|
| 6 |
$title .= _("Timezone Definitions"); |
|---|
| 7 |
break; |
|---|
| 8 |
case "bsettings": |
|---|
| 9 |
if (!empty($account)) { |
|---|
| 10 |
$title .= _("Basic Settings For: ") . " $account ($context)"; |
|---|
| 11 |
} else { |
|---|
| 12 |
$title .= _("Basic settings view is for individual accounts."); |
|---|
| 13 |
} |
|---|
| 14 |
break; |
|---|
| 15 |
case "settings": |
|---|
| 16 |
if (!empty($account)) { |
|---|
| 17 |
$title .= _("Advanced Settings For: ") . " $account ($context)"; |
|---|
| 18 |
} else { |
|---|
| 19 |
$title .= _("System Settings"); |
|---|
| 20 |
} |
|---|
| 21 |
break; |
|---|
| 22 |
case "usage": |
|---|
| 23 |
if (!empty($account)) { |
|---|
| 24 |
$title .= _("Usage Statistics For: ") . " $account ($context)"; |
|---|
| 25 |
} else { |
|---|
| 26 |
$title .= _("System Usage Statistics"); |
|---|
| 27 |
} |
|---|
| 28 |
break; |
|---|
| 29 |
default: |
|---|
| 30 |
$title .= " " . _("Invalid Action"); |
|---|
| 31 |
break; |
|---|
| 32 |
} |
|---|
| 33 |
$title .= "</h3>"; |
|---|
| 34 |
return $title; |
|---|
| 35 |
} |
|---|
| 36 |
function vmailadmin_get_scope($extension) { |
|---|
| 37 |
if (!empty($extension)) { |
|---|
| 38 |
return "account"; |
|---|
| 39 |
} else { |
|---|
| 40 |
return "system"; |
|---|
| 41 |
} |
|---|
| 42 |
} |
|---|
| 43 |
function vmailadmin_update_settings($action, $context="", $extension="", $args=null) { |
|---|
| 44 |
global $astman; |
|---|
| 45 |
global $tz_settings; |
|---|
| 46 |
global $gen_settings; |
|---|
| 47 |
/* Ensure we get the most up-to-date voicemail.conf data. */ |
|---|
| 48 |
$vmconf = voicemail_getVoicemail(); |
|---|
| 49 |
if ($vmconf !== null) { |
|---|
| 50 |
switch ($action) { |
|---|
| 51 |
case "tz": |
|---|
| 52 |
/* First update all zonemessages opts that are already in vmconf */ |
|---|
| 53 |
foreach ($vmconf["zonemessages"] as $key => $val) { |
|---|
| 54 |
$id = "tz__$key"; |
|---|
| 55 |
$vmconf["zonemessages"][$key] = isset($args[$id])?$args[$id]:$vmconf["zonemessages"][$key]; |
|---|
| 56 |
/* Bad to have empty fields in vmconf. */ |
|---|
| 57 |
/* And remove deleted fields, too. */ |
|---|
| 58 |
if (empty($vmconf["zonemessages"][$key]) || ($args["tzdel__$key"] == "true")) { |
|---|
| 59 |
unset($vmconf["zonemessages"][$key]); |
|---|
| 60 |
} |
|---|
| 61 |
/* Add new field, if one was specified */ |
|---|
| 62 |
if (!empty($args["tznew_name"]) && !empty($args["tznew_def"])) { |
|---|
| 63 |
$vmconf["zonemessages"][$args["tznew_name"]] = $args["tznew_def"]; |
|---|
| 64 |
} |
|---|
| 65 |
unset($args[$id]); |
|---|
| 66 |
} |
|---|
| 67 |
/* Next record any new zonemessages opts that were on the page but not already in vmconf. */ |
|---|
| 68 |
foreach ($tz_settings as $key) { |
|---|
| 69 |
$id = "tz__$key"; |
|---|
| 70 |
if (isset($args[$id]) && !empty($args[$id])) { |
|---|
| 71 |
$vmconf["zonemessages"][$key] = $args[$id]; |
|---|
| 72 |
} |
|---|
| 73 |
} |
|---|
| 74 |
break; |
|---|
| 75 |
case "settings": |
|---|
| 76 |
if (empty($extension) && $action == "settings") { |
|---|
| 77 |
/* First update all general opts that are already in vmconf */ |
|---|
| 78 |
foreach ($vmconf["general"] as $key => $val) { |
|---|
| 79 |
$id = "gen__$key"; |
|---|
| 80 |
$vmconf["general"][$key] = isset($args[$id])?$args[$id]:$vmconf["general"][$key]; |
|---|
| 81 |
/* Bad to have empty fields in vmconf. */ |
|---|
| 82 |
if (empty($vmconf["general"][$key])) { |
|---|
| 83 |
unset($vmconf["general"][$key]); |
|---|
| 84 |
} |
|---|
| 85 |
unset($args[$id]); |
|---|
| 86 |
} |
|---|
| 87 |
/* Next record any new general opts that were on the page but not already in vmconf. */ |
|---|
| 88 |
foreach ($gen_settings as $key => $descrip) { |
|---|
| 89 |
$id = "gen__$key"; |
|---|
| 90 |
if (isset($args[$id]) && !empty($args[$id])) { |
|---|
| 91 |
$vmconf["general"][$key] = $args[$id]; |
|---|
| 92 |
} |
|---|
| 93 |
} |
|---|
| 94 |
} else if (!empty($extension)) { |
|---|
| 95 |
global $acct_settings; /* We need this to know the type for each option (text value or flag) */ |
|---|
| 96 |
/* Delete user's old settings. */ |
|---|
| 97 |
voicemail_mailbox_del($extension); |
|---|
| 98 |
/* Prepare values for user's new settings. */ |
|---|
| 99 |
/* Each voicemail account has a line in voicemail.conf like this: */ |
|---|
| 100 |
/* extension => password,name,email,pager,options */ |
|---|
| 101 |
/* Take care of password, name, email and pager. */ |
|---|
| 102 |
$pwd = isset($args["acct__pwd"])?$args["acct__pwd"]:""; |
|---|
| 103 |
unset($args["acct__pwd"]); |
|---|
| 104 |
if (isset($args["acct__name"]) && $args["acct__name"] != "") { |
|---|
| 105 |
$name = $args["acct__name"]; |
|---|
| 106 |
} else { |
|---|
| 107 |
$this_exten = core_users_get($extension); |
|---|
| 108 |
$name = $this_exten["name"]; |
|---|
| 109 |
} |
|---|
| 110 |
unset($args["acct__name"]); |
|---|
| 111 |
$email = isset($args["acct__email"])?$args["acct__email"]:""; |
|---|
| 112 |
unset($args["acct__email"]); |
|---|
| 113 |
$pager = isset($args["acct__pager"])?$args["acct__pager"]:""; |
|---|
| 114 |
unset($args["acct__pager"]); |
|---|
| 115 |
|
|---|
| 116 |
/* Now handle the options. */ |
|---|
| 117 |
$options = array(); |
|---|
| 118 |
foreach ($acct_settings as $key => $descrip) { |
|---|
| 119 |
$id = "acct__$key"; |
|---|
| 120 |
if (isset($args[$id]) && !empty($args[$id]) && $args[$id] != "undefined") { |
|---|
| 121 |
$options[$key] = $args[$id]; |
|---|
| 122 |
} |
|---|
| 123 |
} |
|---|
| 124 |
/* Remove call me num from options - that is set in ast db */ |
|---|
| 125 |
unset($options["callmenum"]); |
|---|
| 126 |
/* New account values to vmconf */ |
|---|
| 127 |
$vmconf[$context][$extension] = array( |
|---|
| 128 |
"mailbox" => $extension, |
|---|
| 129 |
"pwd" => $pwd, |
|---|
| 130 |
"name" => $name, |
|---|
| 131 |
"email" => $email, |
|---|
| 132 |
"pager" => $pager, |
|---|
| 133 |
"options" => $options |
|---|
| 134 |
); |
|---|
| 135 |
$callmenum = (isset($args["acct__callmenum"]) && !empty($args["acct__callmenum"]))?$args["acct__callmenum"]:$extension; |
|---|
| 136 |
// Save call me num. |
|---|
| 137 |
$cmd = "database put AMPUSER $extension/callmenum $callmenum"; |
|---|
| 138 |
$astman->send_request("Command", array("Command" => $cmd)); |
|---|
| 139 |
} |
|---|
| 140 |
break; |
|---|
| 141 |
case "bsettings": |
|---|
| 142 |
if (!empty($extension)) { |
|---|
| 143 |
/* Get user's old settings, since we are only replacing the basic settings. */ |
|---|
| 144 |
$vmbox = voicemail_mailbox_get($extension); |
|---|
| 145 |
/* Delete user's old settings. */ |
|---|
| 146 |
voicemail_mailbox_del($extension); |
|---|
| 147 |
|
|---|
| 148 |
/* Prepare values for user's new BASIC settings. */ |
|---|
| 149 |
/* Each voicemail account has a line in voicemail.conf like this: */ |
|---|
| 150 |
/* extension => password,name,email,pager,options */ |
|---|
| 151 |
/* Take care of password, name, email and pager. */ |
|---|
| 152 |
$pwd = isset($args["acct__pwd"])?$args["acct__pwd"]:""; |
|---|
| 153 |
unset($args["acct__pwd"]); |
|---|
| 154 |
if (isset($args["acct__name"]) && $args["acct__name"] != "") { |
|---|
| 155 |
$name = $args["acct__name"]; |
|---|
| 156 |
} else { |
|---|
| 157 |
$this_exten = core_users_get($extension); |
|---|
| 158 |
$name = $this_exten["name"]; |
|---|
| 159 |
} |
|---|
| 160 |
unset($args["acct__name"]); |
|---|
| 161 |
$email = isset($args["acct__email"])?$args["acct__email"]:""; |
|---|
| 162 |
unset($args["acct__email"]); |
|---|
| 163 |
$pager = isset($args["acct__pager"])?$args["acct__pager"]:""; |
|---|
| 164 |
unset($args["acct__pager"]); |
|---|
| 165 |
|
|---|
| 166 |
/* THESE ARE COMING FROM THE USER'S OLD SETTINGS. */ |
|---|
| 167 |
$options = $vmbox["options"]; /* An array */ |
|---|
| 168 |
/* Update the four options listed on the "bsettings" page as needed. */ |
|---|
| 169 |
$basic_opts_list = array("attach", "saycid", "envelope", "delete"); |
|---|
| 170 |
foreach ($basic_opts_list as $basic_opt) { |
|---|
| 171 |
$id = "acct__" . $basic_opt; |
|---|
| 172 |
if (isset($args[$id]) && !empty($args[$id]) && $args[$id] != "undefined") { |
|---|
| 173 |
$options[$basic_opt] = $args[$id]; |
|---|
| 174 |
} else if ($args[$id] == "undefined") { |
|---|
| 175 |
unset($options[$basic_opt]); |
|---|
| 176 |
} |
|---|
| 177 |
} |
|---|
| 178 |
/* Remove call me num from options - that is set in ast db. Should not be here anyway, since options are coming from the old settings... */ |
|---|
| 179 |
unset($options["callmenum"]); |
|---|
| 180 |
/* New account values to vmconf */ |
|---|
| 181 |
$vmconf[$context][$extension] = array( |
|---|
| 182 |
"mailbox" => $extension, |
|---|
| 183 |
"pwd" => $pwd, |
|---|
| 184 |
"name" => $name, |
|---|
| 185 |
"email" => $email, |
|---|
| 186 |
"pager" => $pager, |
|---|
| 187 |
"options" => $options |
|---|
| 188 |
); |
|---|
| 189 |
$callmenum = (isset($args["acct__callmenum"]) && !empty($args["acct__callmenum"]))?$args["acct__callmenum"]:$extension; |
|---|
| 190 |
// Save call me num. |
|---|
| 191 |
$cmd = "database put AMPUSER $extension/callmenum $callmenum"; |
|---|
| 192 |
$astman->send_request("Command", array("Command" => $cmd)); |
|---|
| 193 |
} |
|---|
| 194 |
break; |
|---|
| 195 |
default: |
|---|
| 196 |
return false; |
|---|
| 197 |
} |
|---|
| 198 |
voicemail_saveVoicemail($vmconf); |
|---|
| 199 |
$astman->send_request("Command", array("Command" => "reload app_voicemail.so")); |
|---|
| 200 |
return true; |
|---|
| 201 |
} |
|---|
| 202 |
return false; |
|---|
| 203 |
} |
|---|
| 204 |
|
|---|
| 205 |
function vmailadmin_get_settings($vmconf, $action, $extension="") { |
|---|
| 206 |
$settings = array(); |
|---|
| 207 |
switch ($action) { |
|---|
| 208 |
case "tz": |
|---|
| 209 |
if (is_array($vmconf) && is_array($vmconf["zonemessages"])) { |
|---|
| 210 |
foreach ($vmconf["zonemessages"] as $key => $val) { |
|---|
| 211 |
$settings[$key] = $val; |
|---|
| 212 |
} |
|---|
| 213 |
} |
|---|
| 214 |
break; |
|---|
| 215 |
case "bsettings": |
|---|
| 216 |
case "settings": |
|---|
| 217 |
/* Settings can apply to system-wide settings OR to account-specific settings. */ |
|---|
| 218 |
/* Specifying a context and extension indicates account-specific settings are being requested. */ |
|---|
| 219 |
if (!empty($extension)) { |
|---|
| 220 |
$vmbox = voicemail_mailbox_get($extension); |
|---|
| 221 |
if ($vmbox !== null) { |
|---|
| 222 |
$settings["enabled"] = true; |
|---|
| 223 |
} else { |
|---|
| 224 |
$settings["enabled"] = false; |
|---|
| 225 |
} |
|---|
| 226 |
$settings["vmcontext"] = $c = isset($vmbox["vmcontext"])?$vmbox["vmcontext"]:"default"; |
|---|
| 227 |
$settings["pwd"] = isset($vmbox["pwd"])?$vmbox["pwd"]:""; |
|---|
| 228 |
$settings["name"] = (isset($vmbox["name"]) && $vmbox["name"] != "")?$vmbox["name"]:""; |
|---|
| 229 |
if ($settings["name"] == "") { |
|---|
| 230 |
$this_exten = core_users_get($extension); |
|---|
| 231 |
$settings["name"] = $this_exten["name"]; |
|---|
| 232 |
} |
|---|
| 233 |
$settings["email"] = isset($vmbox["email"])?$vmbox["email"]:""; |
|---|
| 234 |
$settings["pager"] = isset($vmbox["pager"])?$vmbox["pager"]:""; |
|---|
| 235 |
$options = isset($vmbox["options"])?$vmbox["options"]:array(); |
|---|
| 236 |
foreach ($options as $key => $val) { |
|---|
| 237 |
$settings[$key] = $val; |
|---|
| 238 |
} |
|---|
| 239 |
|
|---|
| 240 |
/* Get Call Me number */ |
|---|
| 241 |
global $astman; |
|---|
| 242 |
$cmd = "database get AMPUSER $extension/callmenum"; |
|---|
| 243 |
$callmenum = ""; |
|---|
| 244 |
$results = $astman->send_request("Command", array("Command" => $cmd)); |
|---|
| 245 |
if (is_array($results)) |
|---|
| 246 |
{ |
|---|
| 247 |
foreach ($results as $results_elem) |
|---|
| 248 |
{ |
|---|
| 249 |
if (preg_match('/Value: [^\s]*/', $results_elem, $matches) > 0) |
|---|
| 250 |
{ |
|---|
| 251 |
$parts = split(' ', trim($matches[0])); |
|---|
| 252 |
$callmenum = $parts[1]; |
|---|
| 253 |
break; |
|---|
| 254 |
} |
|---|
| 255 |
} |
|---|
| 256 |
} |
|---|
| 257 |
$settings["callmenum"] = $callmenum; |
|---|
| 258 |
/* End - Call Me number obtained */ |
|---|
| 259 |
} else { |
|---|
| 260 |
if (is_array($vmconf) && is_array($vmconf["general"])) { |
|---|
| 261 |
$settings = $vmconf["general"]; |
|---|
| 262 |
} |
|---|
| 263 |
} |
|---|
| 264 |
break; |
|---|
| 265 |
default: |
|---|
| 266 |
break; |
|---|
| 267 |
} |
|---|
| 268 |
return $settings; |
|---|
| 269 |
} |
|---|
| 270 |
function vmailadmin_update_usage($vmail_info, $context="", $extension="", $args) { |
|---|
| 271 |
global $vmail_root; |
|---|
| 272 |
$take_action = false; |
|---|
| 273 |
if (isset($args["del_msgs"]) && $args["del_msgs"] == "true") { |
|---|
| 274 |
$msg = true; |
|---|
| 275 |
$take_action = true; |
|---|
| 276 |
} else { |
|---|
| 277 |
$msg = false; |
|---|
| 278 |
} |
|---|
| 279 |
if (isset($args["del_names"]) && $args["del_names"] == "true") { |
|---|
| 280 |
$name = true; |
|---|
| 281 |
$take_action = true; |
|---|
| 282 |
} else { |
|---|
| 283 |
$name = false; |
|---|
| 284 |
} |
|---|
| 285 |
if (isset($args["del_unavail"]) && $args["del_unavail"] == "true") { |
|---|
| 286 |
$unavail = true; |
|---|
| 287 |
$take_action = true; |
|---|
| 288 |
} else { |
|---|
| 289 |
$unavail = false; |
|---|
| 290 |
} |
|---|
| 291 |
if (isset($args["del_busy"]) && $args["del_busy"] == "true") { |
|---|
| 292 |
$busy = true; |
|---|
| 293 |
$take_action = true; |
|---|
| 294 |
} else { |
|---|
| 295 |
$busy = false; |
|---|
| 296 |
} |
|---|
| 297 |
if (isset($args["del_temp"]) && $args["del_temp"] == "true") { |
|---|
| 298 |
$temp = true; |
|---|
| 299 |
$take_action = true; |
|---|
| 300 |
} else { |
|---|
| 301 |
$temp = false; |
|---|
| 302 |
} |
|---|
| 303 |
if (isset($args["del_abandoned"]) && $args["del_abandoned"] == "true") { |
|---|
| 304 |
$abandoned = true; |
|---|
| 305 |
$take_action = true; |
|---|
| 306 |
} else { |
|---|
| 307 |
$abandoned = false; |
|---|
| 308 |
} |
|---|
| 309 |
if (!$take_action) { |
|---|
| 310 |
return; |
|---|
| 311 |
} |
|---|
| 312 |
$vmail_path = $vmail_root; |
|---|
| 313 |
$scope = "system"; |
|---|
| 314 |
if (!empty($extension) && !empty($context)) { |
|---|
| 315 |
$scope = "account"; |
|---|
| 316 |
} |
|---|
| 317 |
|
|---|
| 318 |
switch ($scope) { |
|---|
| 319 |
case "system": |
|---|
| 320 |
if ($msg) { |
|---|
| 321 |
exec ("rm -f $vmail_root/*/*/*/msg*"); |
|---|
| 322 |
} |
|---|
| 323 |
foreach ($vmail_info["contexts"] as $c) { |
|---|
| 324 |
vmailadmin_del_greeting_files($vmail_root, $c, "", $name, $unavail, $busy, $temp, $abandoned); |
|---|
| 325 |
} |
|---|
| 326 |
break; |
|---|
| 327 |
case "account": |
|---|
| 328 |
if (isset($vmail_info["activated_info"][$extension]) && $vmail_info["activated_info"][$extension] == $context) { |
|---|
| 329 |
$vmail_path = $vmail_root . "/" . $context . "/" . $extension; |
|---|
| 330 |
if ($msg) { |
|---|
| 331 |
exec ("rm -f $vmail_path/*/msg*"); |
|---|
| 332 |
} |
|---|
| 333 |
vmailadmin_del_greeting_files($vmail_root, $context, $extension, $name, $unavail, $busy, $temp, $abandoned); |
|---|
| 334 |
} |
|---|
| 335 |
break; |
|---|
| 336 |
} |
|---|
| 337 |
} |
|---|
| 338 |
function vmailadmin_del_greeting_files($vmail_root, $context="", $exten="", $name=false, $unavail=false, $busy=false, $temp=false, $abandoned=false) { |
|---|
| 339 |
$path = $vmail_root; |
|---|
| 340 |
if (!empty($context) && !empty($exten)) { |
|---|
| 341 |
$path .= "/" . $context . "/" . $exten; |
|---|
| 342 |
$ab_name_cmd = "ls $path/greet.tmp.*"; |
|---|
| 343 |
$ab_temp_cmd = "ls $path/temp.tmp.*"; |
|---|
| 344 |
$ab_busy_cmd = "ls $path/busy.tmp.*"; |
|---|
| 345 |
$ab_unavail_cmd = "ls $path/unavail.tmp.*"; |
|---|
| 346 |
$name_cmd = "ls $path/greet.*"; |
|---|
| 347 |
$unavail_cmd = "ls $path/unavail.*"; |
|---|
| 348 |
$busy_cmd = "ls $path/busy.*"; |
|---|
| 349 |
$temp_cmd = "ls $path/temp.*"; |
|---|
| 350 |
} else { |
|---|
| 351 |
$ab_name_cmd = "ls $path/*/*/greet.tmp.*"; |
|---|
| 352 |
$ab_temp_cmd = "ls $path/*/*/temp.tmp.*"; |
|---|
| 353 |
$ab_busy_cmd = "ls $path/*/*/busy.tmp.*"; |
|---|
| 354 |
$ab_unavail_cmd = "ls $path/*/*/unavail.tmp.*"; |
|---|
| 355 |
$name_cmd = "ls $path/*/*/greet.*"; |
|---|
| 356 |
$unavail_cmd = "ls $path/*/*/unavail.*"; |
|---|
| 357 |
$busy_cmd = "ls $path/*/*/busy.*"; |
|---|
| 358 |
$temp_cmd = "ls $path/*/*/temp.*"; |
|---|
| 359 |
} |
|---|
| 360 |
|
|---|
| 361 |
if (is_dir($path)) { |
|---|
| 362 |
if ($abandoned) { |
|---|
| 363 |
/* First handle abandoned greetings. Delete abandoned greetings that are at least a day old. */ |
|---|
| 364 |
$ab_names = vmailadmin_get_ab_greetings("greet", $ab_name_cmd); |
|---|
| 365 |
$ab_temps = vmailadmin_get_ab_greetings("temp", $ab_temp_cmd); |
|---|
| 366 |
$ab_busys = vmailadmin_get_ab_greetings("busy", $ab_busy_cmd); |
|---|
| 367 |
$ab_unavails = vmailadmin_get_ab_greetings("unavail", $ab_unavail_cmd); |
|---|
| 368 |
$ab_greetings = array_merge($ab_names, $ab_temps, $ab_busys, $ab_unavails); |
|---|
| 369 |
$current_time = time(); |
|---|
| 370 |
$one_day = 24 * 60 * 60; |
|---|
| 371 |
foreach ($ab_greetings as $greeting_path) { |
|---|
| 372 |
if (time() - filemtime($greeting_path) > $one_day) { |
|---|
| 373 |
exec("rm -f $greeting_path"); |
|---|
| 374 |
} |
|---|
| 375 |
} |
|---|
| 376 |
} |
|---|
| 377 |
if ($name) { |
|---|
| 378 |
$names = vmailadmin_get_greetings("greet", $name_cmd); |
|---|
| 379 |
} |
|---|
| 380 |
if ($unavail) { |
|---|
| 381 |
$unavails = vmailadmin_get_greetings("unavail", $unavail_cmd); |
|---|
| 382 |
} |
|---|
| 383 |
if ($busy) { |
|---|
| 384 |
$busys = vmailadmin_get_greetings("busy", $busy_cmd); |
|---|
| 385 |
} |
|---|
| 386 |
if ($temp) { |
|---|
| 387 |
$temps = vmailadmin_get_greetings("temp", $temp_cmd); |
|---|
| 388 |
} |
|---|
| 389 |
$greetings = array_merge($names, $temps, $busys, $unavails); |
|---|
| 390 |
if (!empty($greetings)) { |
|---|
| 391 |
foreach ($greetings as $greeting_path) { |
|---|
| 392 |
exec ("rm -f $greeting_path"); |
|---|
| 393 |
} |
|---|
| 394 |
} |
|---|
| 395 |
} |
|---|
| 396 |
} |
|---|
| 397 |
function vmailadmin_get_storage($path) { |
|---|
| 398 |
$cmd = escapeshellcmd("du -khs $path"); |
|---|
| 399 |
$storage_result = array(); |
|---|
| 400 |
$matches = array(); |
|---|
| 401 |
exec($cmd, $storage_result); |
|---|
| 402 |
if (preg_match("/[0-9]*\.*[0-9]*[a-zA-Z]*/", $storage_result[0], $matches) > 0) { |
|---|
| 403 |
$storage = $matches[0]; |
|---|
| 404 |
unset($matches); |
|---|
| 405 |
$matches = array(); |
|---|
| 406 |
# Expecting storage value as #.#U where # = number, . = dot, and U = units (e.g. M, K, etc.) |
|---|
| 407 |
# Massage the string so that there is a space between the number value and character(s) |
|---|
| 408 |
# denoting the unit |
|---|
| 409 |
# |
|---|
| 410 |
# Extract the numeric part. /[0-9]*\.*[0-9]*[a-zA-Z]*/ |
|---|
| 411 |
if (preg_match("/[0-9]*\.*[0-9]*/", $storage, $matches)) { |
|---|
| 412 |
$st_num = $matches[0]; |
|---|
| 413 |
} else { |
|---|
| 414 |
$st_num = "0"; |
|---|
| 415 |
} |
|---|
| 416 |
unset($matches); |
|---|
| 417 |
$matches = array(); |
|---|
| 418 |
if (preg_match("/[a-zA-Z]+$/", $storage, $matches)) { |
|---|
| 419 |
$st_unit = $matches[0]; |
|---|
| 420 |
} else { |
|---|
| 421 |
$st_unit = ""; |
|---|
| 422 |
} |
|---|
| 423 |
# reset $storage to new string |
|---|
| 424 |
$storage = $st_num . " " . $st_unit; |
|---|
| 425 |
} else { |
|---|
| 426 |
$storage = "unknown"; |
|---|
| 427 |
} |
|---|
| 428 |
return $storage; |
|---|
| 429 |
} |
|---|
| 430 |
function vmailadmin_get_usage($vmail_info, $scope, &$acts_total, &$acts_act, &$acts_unact, &$disabled_count, |
|---|
| 431 |
&$msg_total, &$msg_in, &$msg_other, |
|---|
| 432 |
&$name, &$unavail, &$busy, &$temp, &$abandoned, |
|---|
| 433 |
&$storage, |
|---|
| 434 |
$context="", $extension="") { |
|---|
| 435 |
global $vmail_root; |
|---|
| 436 |
$msg_total = 0; |
|---|
| 437 |
$msg_in = 0; |
|---|
| 438 |
$msg_other = 0; |
|---|
| 439 |
$name = 0; |
|---|
| 440 |
$unavail = 0; |
|---|
| 441 |
$busy = 0; |
|---|
| 442 |
$temp = 0; |
|---|
| 443 |
$abandoned = 0; |
|---|
| 444 |
switch ($scope) { |
|---|
| 445 |
case "system": |
|---|
| 446 |
$acts_act = sizeof($vmail_info["activated_info"]); |
|---|
| 447 |
$acts_unact = sizeof($vmail_info["unactivated_info"]); |
|---|
| 448 |
$disabled_count = sizeof($vmail_info["disabled_list"]); |
|---|
| 449 |
$acts_total = $acts_act + $acts_unact + $disabled_count; |
|---|
| 450 |
$storage = vmailadmin_get_storage($vmail_root); |
|---|
| 451 |
foreach ($vmail_info["contexts"] as $c) { |
|---|
| 452 |
$count_msg_in = 0; |
|---|
| 453 |
$count_msg_oth = 0; |
|---|
| 454 |
$count_name = 0; |
|---|
| 455 |
$count_unavail = 0; |
|---|
| 456 |
$count_busy = 0; |
|---|
| 457 |
$count_temp = 0; |
|---|
| 458 |
$count_abandon = 0; |
|---|
| 459 |
$vmail_path = $vmail_root . "/" . $c; |
|---|
| 460 |
vmailadmin_file_usage($vmail_path, $count_msg_in, $count_msg_oth, $count_name, $count_unavail, $count_busy, $count_temp, $count_abandon); |
|---|
| 461 |
$msg_in += $count_msg_in; |
|---|
| 462 |
$msg_other += $count_msg_oth; |
|---|
| 463 |
$name += $count_name; |
|---|
| 464 |
$unavail += $count_unavail; |
|---|
| 465 |
$busy += $count_busy; |
|---|
| 466 |
$temp += $count_temp; |
|---|
| 467 |
$abandoned += $count_abandon; |
|---|
| 468 |
|
|---|
| 469 |
} |
|---|
| 470 |
$msg_total = $msg_in + $msg_other; |
|---|
| 471 |
break; |
|---|
| 472 |
case "account": |
|---|
| 473 |
if (isset($vmail_info["activated_info"][$extension]) && $vmail_info["activated_info"][$extension] == $context) { |
|---|
| 474 |
$vmail_path = $vmail_root . "/" . $context . "/" . $extension; |
|---|
| 475 |
vmailadmin_file_usage($vmail_path, $msg_in, $msg_other, $name, $unavail, $busy, $temp, $abandoned, true); |
|---|
| 476 |
$storage = vmailadmin_get_storage($vmail_path); |
|---|
| 477 |
$msg_total = $msg_in + $msg_other; |
|---|
| 478 |
$acts_act = 1; |
|---|
| 479 |
$acts_unact = 0; |
|---|
| 480 |
} else { |
|---|
| 481 |
$acts_unact = 1; |
|---|
| 482 |
} |
|---|
| 483 |
break; |
|---|
| 484 |
default: |
|---|
| 485 |
break; |
|---|
| 486 |
} |
|---|
| 487 |
} |
|---|
| 488 |
function vmailadmin_file_usage($path, &$inmsg_cnt, &$othmsg_cnt, &$greet_cnt, &$unavail_cnt, &$busy_cnt, &$temp_cnt, &$abandoned_cnt, $acct_flag=false) { |
|---|
| 489 |
if ($acct_flag) { /* account-specific; account included in path passed in */ |
|---|
| 490 |
# greetings, all |
|---|
| 491 |
$greet_cmd = "ls $path/greet.*"; |
|---|
| 492 |
$unavail_cmd = "ls $path/unavail.*"; |
|---|
| 493 |
$busy_cmd = "ls $path/busy.*"; |
|---|
| 494 |
$temp_cmd = "ls $path/temp.*"; |
|---|
| 495 |
|
|---|
| 496 |
# abandoned greetings |
|---|
| 497 |
$agreet_cmd = "ls $path/greet.tmp.*"; |
|---|
| 498 |
$aunavail_cmd = "ls $path/unavail.tmp.*"; |
|---|
| 499 |
$abusy_cmd = "ls $path/busy.tmp.*"; |
|---|
| 500 |
$atemp_cmd = "ls $path/temp.tmp.*"; |
|---|
| 501 |
|
|---|
| 502 |
# inbox messages |
|---|
| 503 |
$inmsg_cmd = "ls $path/INBOX/msg*.txt"; |
|---|
| 504 |
|
|---|
| 505 |
# all messages |
|---|
| 506 |
$allmsg_cmd = "ls $path/*/msg*.txt"; |
|---|
| 507 |
} else { /* system-wide */ |
|---|
| 508 |
# greetings, all |
|---|
| 509 |
$greet_cmd = "ls $path/*/greet.*"; |
|---|
| 510 |
$unavail_cmd = "ls $path/*/unavail.*"; |
|---|
| 511 |
$busy_cmd = "ls $path/*/busy.*"; |
|---|
| 512 |
$temp_cmd = "ls $path/*/temp.*"; |
|---|
| 513 |
|
|---|
| 514 |
# abandoned greetings |
|---|
| 515 |
$agreet_cmd = "ls $path/*/greet.tmp.*"; |
|---|
| 516 |
$aunavail_cmd = "ls $path/*/unavail.tmp.*"; |
|---|
| 517 |
$abusy_cmd = "ls $path/*/busy.tmp.*"; |
|---|
| 518 |
$atemp_cmd = "ls $path/*/temp.tmp.*"; |
|---|
| 519 |
|
|---|
| 520 |
# inbox messages |
|---|
| 521 |
$inmsg_cmd = "ls $path/*/INBOX/msg*.txt"; |
|---|
| 522 |
|
|---|
| 523 |
# all messages |
|---|
| 524 |
$allmsg_cmd = "ls $path/*/*/msg*.txt"; |
|---|
| 525 |
} |
|---|
| 526 |
|
|---|
| 527 |
if (is_dir($path)) { |
|---|
| 528 |
$greet_cnt = vmailadmin_count_greetings("greet", $greet_cmd); |
|---|
| 529 |
$temp_cnt = vmailadmin_count_greetings("temp", $temp_cmd); |
|---|
| 530 |
$busy_cnt = vmailadmin_count_greetings("busy", $busy_cmd); |
|---|
| 531 |
$unavail_cnt = vmailadmin_count_greetings("unavail", $unavail_cmd); |
|---|
| 532 |
|
|---|
| 533 |
|
|---|
| 534 |
$agreet_cnt = vmailadmin_count_ab_greetings("greet", $agreet_cmd); |
|---|
| 535 |
$aunavail_cnt = vmailadmin_count_ab_greetings("unavail", $aunavail_cmd); |
|---|
| 536 |
$abusy_cnt = vmailadmin_count_ab_greetings("busy", $abusy_cmd); |
|---|
| 537 |
$atemp_cnt = vmailadmin_count_ab_greetings("temp", $atemp_cmd); |
|---|
| 538 |
|
|---|
| 539 |
|
|---|
| 540 |
$inmsg_cnt = vmailadmin_count_msg($inmsg_cmd); |
|---|
| 541 |
$allmsg_cnt = vmailadmin_count_msg($allmsg_cmd); |
|---|
| 542 |
|
|---|
| 543 |
$othmsg_cnt = $allmsg_cnt - $inmsg_cnt; |
|---|
| 544 |
$abandoned_cnt = $agreet_cnt + $abusy_cnt + $atemp_cnt + $aunavail_cnt; |
|---|
| 545 |
|
|---|
| 546 |
} |
|---|
| 547 |
|
|---|
| 548 |
} |
|---|
| 549 |
function vmailadmin_strip_exten_from_greet_path($greet_path) { |
|---|
| 550 |
$path_array = explode("/", $greet_path); |
|---|
| 551 |
$n = sizeof($path_array); |
|---|
| 552 |
$exten = $path_array[$n-2]; |
|---|
| 553 |
return $exten; |
|---|
| 554 |
} |
|---|
| 555 |
function vmailadmin_count_greetings($greeting, $cmd) { |
|---|
| 556 |
/* get a list of all greeting files */ |
|---|
| 557 |
$file_list = vmailadmin_get_greetings($greeting, $cmd); |
|---|
| 558 |
$greet_list = array(); |
|---|
| 559 |
/* greeting can be in multiple formats, making file count greater than greeting */ |
|---|
| 560 |
/* count, so make array with one entry for each extension that has the greeting */ |
|---|
| 561 |
foreach ($file_list as $greeting_file) { |
|---|
| 562 |
$greet_list[vmailadmin_strip_exten_from_greet_path($greeting_file)] = true; |
|---|
| 563 |
} |
|---|
| 564 |
return sizeof($greet_list); |
|---|
| 565 |
} |
|---|
| 566 |
function vmailadmin_get_greetings($greeting, $cmd) { |
|---|
| 567 |
$results = array(); |
|---|
| 568 |
$greet_list = array(); |
|---|
| 569 |
exec($cmd, $results); |
|---|
| 570 |
/* filter out abandoned greeting recordings */ |
|---|
| 571 |
foreach ($results as $r) { |
|---|
| 572 |
$pat = "/.*" . $greeting . "\.tmp\..+/"; |
|---|
| 573 |
if (!preg_match($pat, $r)) |
|---|
| 574 |
$greet_list[] = $r; |
|---|
| 575 |
} |
|---|
| 576 |
return $greet_list; |
|---|
| 577 |
} |
|---|
| 578 |
function vmailadmin_count_ab_greetings($greeting, $cmd) { |
|---|
| 579 |
$file_list = vmailadmin_get_ab_greetings($greeting, $cmd); |
|---|
| 580 |
$greet_list = array(); |
|---|
| 581 |
/* greeting can be in multiple formats, making file count greater than greeting */ |
|---|
| 582 |
/* count, so make array with one entry for each extension that has the greeting */ |
|---|
| 583 |
foreach ($file_list as $greeting_file) { |
|---|
| 584 |
$greet_list[vmailadmin_strip_exten_from_greet_path($greeting_file)] = true; |
|---|
| 585 |
} |
|---|
| 586 |
return sizeof($greet_list); |
|---|
| 587 |
} |
|---|
| 588 |
function vmailadmin_get_ab_greetings($greeting, $cmd) { |
|---|
| 589 |
$results = array(); |
|---|
| 590 |
$greet_list = array(); |
|---|
| 591 |
exec($cmd, $results); |
|---|
| 592 |
foreach ($results as $r) { |
|---|
| 593 |
$greet_list[] = $r; |
|---|
| 594 |
} |
|---|
| 595 |
return $greet_list; |
|---|
| 596 |
} |
|---|
| 597 |
function vmailadmin_count_msg($msg_cmd) { |
|---|
| 598 |
$results = array(); |
|---|
| 599 |
$msg_cnt = 0; |
|---|
| 600 |
exec($msg_cmd, $results); |
|---|
| 601 |
/* Message can be recorded in multiple formats, but there is always one text */ |
|---|
| 602 |
/* file for each message, so count the text files. */ |
|---|
| 603 |
foreach ($results as $r) { |
|---|
| 604 |
if (preg_match("/.+\/msg[0-9][0-9][0-9][0-9]\.txt\/{0,1}/", $r)) { |
|---|
| 605 |
$msg_cnt++; |
|---|
| 606 |
} |
|---|
| 607 |
} |
|---|
| 608 |
return $msg_cnt; |
|---|
| 609 |
} |
|---|
| 610 |
function vmailadmin_get_greeting_timestamps($name=0, $unavail=0, $busy=0, $temp=0, $context="", $extension="") { |
|---|
| 611 |
global $vmail_root; |
|---|
| 612 |
if ($context == "" || $extension == "") { |
|---|
| 613 |
return null; |
|---|
| 614 |
} |
|---|
| 615 |
$vmail_path = $vmail_root . "/$context/$extension"; |
|---|
| 616 |
$ts["name"] = 0; |
|---|
| 617 |
$ts["unavail"] = 0; |
|---|
| 618 |
$ts["busy"] = 0; |
|---|
| 619 |
$ts["temp"] = 0; |
|---|
| 620 |
if ($name) { |
|---|
| 621 |
$listing = array(); |
|---|
| 622 |
exec("ls $vmail_path/greet.*", $listing); |
|---|
| 623 |
foreach ($listing as $entry) { |
|---|
| 624 |
if (!preg_match("/greet\.tmp\..+/", $entry)) { |
|---|
| 625 |
$ts["name"] = date("Y-m-d", filemtime("$entry")); |
|---|
| 626 |
break; |
|---|
| 627 |
} |
|---|
| 628 |
} |
|---|
| 629 |
} |
|---|
| 630 |
if ($unavail) { |
|---|
| 631 |
$listing = array(); |
|---|
| 632 |
exec("ls $vmail_path/unavail.*", $listing); |
|---|
| 633 |
foreach ($listing as $entry) { |
|---|
| 634 |
if (!preg_match("/unavail\.tmp\..+/", $entry)) { |
|---|
| 635 |
$ts["unavail"] = date("Y-m-d", filemtime("$entry")); |
|---|
| 636 |
break; |
|---|
| 637 |
} |
|---|
| 638 |
} |
|---|
| 639 |
} |
|---|
| 640 |
if ($busy) { |
|---|
| 641 |
$listing = array(); |
|---|
| 642 |
exec("ls $vmail_path/busy.*", $listing); |
|---|
| 643 |
foreach ($listing as $entry) { |
|---|
| 644 |
if (!preg_match("/busy\.tmp\..+/", $entry)) { |
|---|
| 645 |
$ts["busy"] = date("Y-m-d", filemtime("$entry")); |
|---|
| 646 |
break; |
|---|
| 647 |
} |
|---|
| 648 |
} |
|---|
| 649 |
} |
|---|
| 650 |
if ($temp) { |
|---|
| 651 |
$listing = array(); |
|---|
| 652 |
exec("ls $vmail_path/temp.*", $listing); |
|---|
| 653 |
foreach ($listing as $entry) { |
|---|
| 654 |
if (!preg_match("/temp\.tmp\..+/", $entry)) { |
|---|
| 655 |
$ts["temp"] = date("Y-m-d", filemtime("$entry")); |
|---|
| 656 |
break; |
|---|
| 657 |
} |
|---|
| 658 |
} |
|---|
| 659 |
} |
|---|
| 660 |
return $ts; |
|---|
| 661 |
} |
|---|
| 662 |
?> |
|---|