| 1 |
#!/usr/bin/php -q |
|---|
| 2 |
<?php |
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
$bootstrap_settings['freepbx_auth'] = false; |
|---|
| 23 |
if (!@include_once(getenv('FREEPBX_CONF') ? getenv('FREEPBX_CONF') : '/etc/freepbx.conf')) { |
|---|
| 24 |
@include_once('/etc/asterisk/freepbx.conf'); |
|---|
| 25 |
} |
|---|
| 26 |
|
|---|
| 27 |
if(!isset($amp_conf)) { |
|---|
| 28 |
|
|---|
| 29 |
// initialize FreePBX in pre-2.9 fashion |
|---|
| 30 |
initLegacyFreePBX(); |
|---|
| 31 |
} |
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
$sql = "DELETE FROM smartroute_currentcalls WHERE calldate < DATE_SUB(NOW(), INTERVAL 1 HOUR)"; |
|---|
| 41 |
$db->query($sql); |
|---|
| 42 |
|
|---|
| 43 |
exit(0); |
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
function initLegacyFreePBX() { |
|---|
| 53 |
global $amportalconf; |
|---|
| 54 |
global $db_engine; |
|---|
| 55 |
global $amp_conf; |
|---|
| 56 |
global $asterisk_conf; |
|---|
| 57 |
global $db; |
|---|
| 58 |
global $amp_conf_defaults; |
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
define("AMP_CONF", "/etc/amportal.conf"); |
|---|
| 62 |
$amportalconf = AMP_CONF; |
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
// from ben-php dot net at efros dot com at php.net/install.unix.commandline |
|---|
| 67 |
if (version_compare(phpversion(),'4.3.0','<') || !defined("STDIN")) { |
|---|
| 68 |
define('STDIN',fopen("php://stdin","r")); |
|---|
| 69 |
define('STDOUT',fopen("php://stdout","r")); |
|---|
| 70 |
define('STDERR',fopen("php://stderr","r")); |
|---|
| 71 |
register_shutdown_function( create_function( '' , 'fclose(STDIN); fclose(STDOUT); fclose(STDERR); return true;' ) ); |
|---|
| 72 |
} |
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
outn(_("Checking for PEAR DB..")); |
|---|
| 77 |
if (! @ include('DB.php')) { |
|---|
| 78 |
out(_("FAILED")); |
|---|
| 79 |
fatal(_("PEAR Missing"),sprintf(_("PEAR must be installed (requires DB.php). Include path: %s "), ini_get("include_path"))); |
|---|
| 80 |
} |
|---|
| 81 |
out(_("OK")); |
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
outn(sprintf(_("Checking for %s "), $amportalconf)._("..")); |
|---|
| 86 |
if (!file_exists($amportalconf)) { |
|---|
| 87 |
fatal(_("amportal.conf access problem: "),sprintf(_("The %s file does not exist, or is inaccessible"), $amportalconf)); |
|---|
| 88 |
} |
|---|
| 89 |
out(_("OK")); |
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
outn(sprintf(_("Bootstrapping %s .."), $amportalconf)); |
|---|
| 94 |
$amp_conf = parse_amportal_conf_bootstrap($amportalconf); |
|---|
| 95 |
if (count($amp_conf) == 0) { |
|---|
| 96 |
fatal(_("amportal.conf parsing failure"),sprintf(_("no entries found in %s"), $amportalconf)); |
|---|
| 97 |
} |
|---|
| 98 |
out(_("OK")); |
|---|
| 99 |
|
|---|
| 100 |
outn(sprintf(_("Parsing %s .."), $amportalconf)); |
|---|
| 101 |
require_once($amp_conf['AMPWEBROOT']."/admin/functions.inc.php"); |
|---|
| 102 |
$amp_conf = parse_amportal_conf($amportalconf); |
|---|
| 103 |
if (count($amp_conf) == 0) { |
|---|
| 104 |
fatal(_("amportal.conf parsing failure"),sprintf(_("no entries found in %s"), $amportalconf)); |
|---|
| 105 |
} |
|---|
| 106 |
out(_("OK")); |
|---|
| 107 |
|
|---|
| 108 |
$asterisk_conf_file = $amp_conf["ASTETCDIR"]."/asterisk.conf"; |
|---|
| 109 |
outn(sprintf(_("Parsing %s .."), $asterisk_conf_file)); |
|---|
| 110 |
$asterisk_conf = parse_asterisk_conf($asterisk_conf_file); |
|---|
| 111 |
if (count($asterisk_conf) == 0) { |
|---|
| 112 |
fatal(_("asterisk.conf parsing failure"),sprintf(_("no entries found in %s"), $asterisk_conf_file)); |
|---|
| 113 |
} |
|---|
| 114 |
out(_("OK")); |
|---|
| 115 |
|
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 |
outn(_("Connecting to database..")); |
|---|
| 119 |
|
|---|
| 120 |
|
|---|
| 121 |
# if none supplied, backfall to mysql |
|---|
| 122 |
$db_engine = "mysql"; |
|---|
| 123 |
if (isset($amp_conf["AMPDBENGINE"])){ |
|---|
| 124 |
$db_engine = $amp_conf["AMPDBENGINE"]; |
|---|
| 125 |
} |
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 |
// |
|---|
| 129 |
$nt = notifications::create($db); |
|---|
| 130 |
|
|---|
| 131 |
switch ($db_engine) |
|---|
| 132 |
{ |
|---|
| 133 |
case "pgsql": |
|---|
| 134 |
case "mysql": |
|---|
| 135 |
|
|---|
| 136 |
dbengine://username:password@host/database */ |
|---|
| 137 |
|
|---|
| 138 |
$db_user = $amp_conf["AMPDBUSER"]; |
|---|
| 139 |
$db_pass = $amp_conf["AMPDBPASS"]; |
|---|
| 140 |
$db_host = $amp_conf["AMPDBHOST"]; |
|---|
| 141 |
$db_name = $amp_conf["AMPDBNAME"]; |
|---|
| 142 |
|
|---|
| 143 |
$datasource = $db_engine.'://'.$db_user.':'.$db_pass.'@'.$db_host.'/'.$db_name; |
|---|
| 144 |
$db = DB::connect($datasource); |
|---|
| 145 |
break; |
|---|
| 146 |
|
|---|
| 147 |
case "sqlite": |
|---|
| 148 |
require_once('DB/sqlite.php'); |
|---|
| 149 |
|
|---|
| 150 |
if (!isset($amp_conf["AMPDBFILE"])) |
|---|
| 151 |
fatal(_("AMPDBFILE not setup properly"),sprintf(_("You must setup properly AMPDBFILE in %s "), $amportalconf)); |
|---|
| 152 |
|
|---|
| 153 |
if (isset($amp_conf["AMPDBFILE"]) == "") |
|---|
| 154 |
fatal(_("AMPDBFILE not setup properly"),sprintf(_("AMPDBFILE in %s cannot be blank"), $amportalconf)); |
|---|
| 155 |
|
|---|
| 156 |
$DSN = array ( |
|---|
| 157 |
"database" => $amp_conf["AMPDBFILE"], |
|---|
| 158 |
"mode" => 0666 |
|---|
| 159 |
); |
|---|
| 160 |
|
|---|
| 161 |
$db = new DB_sqlite(); |
|---|
| 162 |
$db->connect( $DSN ); |
|---|
| 163 |
break; |
|---|
| 164 |
|
|---|
| 165 |
case "sqlite3": |
|---|
| 166 |
if (!isset($amp_conf["AMPDBFILE"])) |
|---|
| 167 |
fatal("You must setup properly AMPDBFILE in $amportalconf"); |
|---|
| 168 |
|
|---|
| 169 |
if (isset($amp_conf["AMPDBFILE"]) == "") |
|---|
| 170 |
fatal("AMPDBFILE in $amportalconf cannot be blank"); |
|---|
| 171 |
|
|---|
| 172 |
require_once('DB/sqlite3.php'); |
|---|
| 173 |
$datasource = "sqlite3:///" . $amp_conf["AMPDBFILE"] . "?mode=0666"; |
|---|
| 174 |
$db = DB::connect($datasource); |
|---|
| 175 |
break; |
|---|
| 176 |
|
|---|
| 177 |
default: |
|---|
| 178 |
fatal( "Unknown SQL engine: [$db_engine]"); |
|---|
| 179 |
} |
|---|
| 180 |
|
|---|
| 181 |
if(DB::isError($db)) { |
|---|
| 182 |
out(_("FAILED")); |
|---|
| 183 |
debug($db->userinfo); |
|---|
| 184 |
fatal(_("database connection failure"),("failed trying to connect to the configured database")); |
|---|
| 185 |
|
|---|
| 186 |
} |
|---|
| 187 |
out(_("OK")); |
|---|
| 188 |
} |
|---|
| 189 |
|
|---|
| 190 |
|
|---|
| 191 |
|
|---|
| 192 |
|
|---|
| 193 |
|
|---|
| 194 |
|
|---|
| 195 |
if (!function_exists('_')) { |
|---|
| 196 |
function _($str) { |
|---|
| 197 |
return $str; |
|---|
| 198 |
} |
|---|
| 199 |
} |
|---|
| 200 |
|
|---|
| 201 |
if (!function_exists('out')) { |
|---|
| 202 |
function out($text) { |
|---|
| 203 |
|
|---|
| 204 |
} |
|---|
| 205 |
} |
|---|
| 206 |
|
|---|
| 207 |
if (!function_exists('outn')) { |
|---|
| 208 |
function outn($text) { |
|---|
| 209 |
|
|---|
| 210 |
} |
|---|
| 211 |
} |
|---|
| 212 |
|
|---|
| 213 |
if (!function_exists('error')) { |
|---|
| 214 |
function error($text) { |
|---|
| 215 |
echo "[ERROR] ".$text."\n"; |
|---|
| 216 |
} |
|---|
| 217 |
} |
|---|
| 218 |
|
|---|
| 219 |
if (!function_exists('fatal')) { |
|---|
| 220 |
function fatal($text, $extended_text="", $type="FATAL") { |
|---|
| 221 |
global $db; |
|---|
| 222 |
|
|---|
| 223 |
echo "[$type] ".$text." ".$extended_text."\n"; |
|---|
| 224 |
|
|---|
| 225 |
if(!DB::isError($db)) { |
|---|
| 226 |
$nt = notifications::create($db); |
|---|
| 227 |
$nt->add_critical('cron_manager', $type, $text, $extended_text); |
|---|
| 228 |
} |
|---|
| 229 |
|
|---|
| 230 |
exit(1); |
|---|
| 231 |
} |
|---|
| 232 |
} |
|---|
| 233 |
|
|---|
| 234 |
if (!function_exists('debug')) { |
|---|
| 235 |
function debug($text) { |
|---|
| 236 |
global $debug; |
|---|
| 237 |
|
|---|
| 238 |
if ($debug) echo "[DEBUG-preDB] ".$text."\n"; |
|---|
| 239 |
} |
|---|
| 240 |
} |
|---|
| 241 |
|
|---|
| 242 |
|
|---|
| 243 |
|
|---|
| 244 |
|
|---|
| 245 |
|
|---|
| 246 |
function parse_amportal_conf_bootstrap($filename) { |
|---|
| 247 |
$file = file($filename); |
|---|
| 248 |
foreach ($file as $line) { |
|---|
| 249 |
if (preg_match("/^\s*([\w]+)\s*=\s*\"?([\w\/\:\.\*\%-]*)\"?\s*([;#].*)?/",$line,$matches)) { |
|---|
| 250 |
$conf[ $matches[1] ] = $matches[2]; |
|---|
| 251 |
} |
|---|
| 252 |
} |
|---|
| 253 |
if ( !isset($conf["AMPWEBROOT"]) || ($conf["AMPWEBROOT"] == "")) { |
|---|
| 254 |
$conf["AMPWEBROOT"] = "/var/www/html"; |
|---|
| 255 |
} else { |
|---|
| 256 |
$conf["AMPWEBROOT"] = rtrim($conf["AMPWEBROOT"],'/'); |
|---|
| 257 |
} |
|---|
| 258 |
|
|---|
| 259 |
return $conf; |
|---|
| 260 |
} |
|---|
| 261 |
|
|---|
| 262 |
|
|---|
| 263 |
|
|---|
| 264 |
|
|---|
| 265 |
?> |
|---|