Index: freepbx/trunk/amp_conf/bin/freepbx-cron-scheduler.php =================================================================== --- freepbx/trunk/amp_conf/bin/freepbx-cron-scheduler.php (revision 5838) +++ freepbx/trunk/amp_conf/bin/freepbx-cron-scheduler.php (revision 10865) @@ -1,193 +1,12 @@ #!/usr/bin/php -q add_critical('cron_manager', $type, $text, $extended_text); - } - - exit(1); -} - -function debug($text) { - global $debug; - - if ($debug) echo "[DEBUG-preDB] ".$text."\n"; -} - -// bootstrap retrieve_conf by getting the AMPWEBROOT since that is currently where the necessary -// functions.inc.php resides, and then use that parser to properly parse the file and get all -// the defaults as needed. -// -function parse_amportal_conf_bootstrap($filename) { - $file = file($filename); - foreach ($file as $line) { - if (preg_match("/^\s*([\w]+)\s*=\s*\"?([\w\/\:\.\*\%-]*)\"?\s*([;#].*)?/",$line,$matches)) { - $conf[ $matches[1] ] = $matches[2]; - } - } - if ( !isset($conf["AMPWEBROOT"]) || ($conf["AMPWEBROOT"] == "")) { - $conf["AMPWEBROOT"] = "/var/www/html"; - } else { - $conf["AMPWEBROOT"] = rtrim($conf["AMPWEBROOT"],'/'); - } - - return $conf; -} - -/********************************************************************************************************************/ - -// **** Make sure we have STDIN etc - -// from ben-php dot net at efros dot com at php.net/install.unix.commandline -if (version_compare(phpversion(),'4.3.0','<') || !defined("STDIN")) { - define('STDIN',fopen("php://stdin","r")); - define('STDOUT',fopen("php://stdout","r")); - define('STDERR',fopen("php://stderr","r")); - register_shutdown_function( create_function( '' , 'fclose(STDIN); fclose(STDOUT); fclose(STDERR); return true;' ) ); -} - -// **** Make sure we have PEAR's DB.php, and include it - -outn(_("Checking for PEAR DB..")); -if (! @ include('DB.php')) { - out(_("FAILED")); - fatal(_("PEAR Missing"),sprintf(_("PEAR must be installed (requires DB.php). Include path: %s "), ini_get("include_path"))); -} -out(_("OK")); - - -// **** Check for amportal.conf - -outn(sprintf(_("Checking for %s "), $amportalconf)._("..")); -if (!file_exists($amportalconf)) { - fatal(_("amportal.conf access problem: "),sprintf(_("The %s file does not exist, or is inaccessible"), $amportalconf)); -} -out(_("OK")); - -// **** read amportal.conf - -outn(sprintf(_("Bootstrapping %s .."), $amportalconf)); -$amp_conf = parse_amportal_conf_bootstrap($amportalconf); -if (count($amp_conf) == 0) { - fatal(_("amportal.conf parsing failure"),sprintf(_("no entries found in %s"), $amportalconf)); -} -out(_("OK")); - -outn(sprintf(_("Parsing %s .."), $amportalconf)); -require_once($amp_conf['AMPWEBROOT']."/admin/functions.inc.php"); -$amp_conf = parse_amportal_conf($amportalconf); -if (count($amp_conf) == 0) { - fatal(_("amportal.conf parsing failure"),sprintf(_("no entries found in %s"), $amportalconf)); -} -out(_("OK")); - -$asterisk_conf_file = $amp_conf["ASTETCDIR"]."/asterisk.conf"; -outn(sprintf(_("Parsing %s .."), $asterisk_conf_file)); -$asterisk_conf = parse_asterisk_conf($asterisk_conf_file); -if (count($asterisk_conf) == 0) { - fatal(_("asterisk.conf parsing failure"),sprintf(_("no entries found in %s"), $asterisk_conf_file)); -} -out(_("OK")); - -// **** Connect to database - -outn(_("Connecting to database..")); - -# the engine to be used for the SQL queries, -# if none supplied, backfall to mysql -$db_engine = "mysql"; -if (isset($amp_conf["AMPDBENGINE"])){ - $db_engine = $amp_conf["AMPDBENGINE"]; -} - // Define the notification class for logging to the dashboard // $nt = notifications::create($db); - -switch ($db_engine) -{ - case "pgsql": - case "mysql": - /* datasource in in this style: - dbengine://username:password@host/database */ - - $db_user = $amp_conf["AMPDBUSER"]; - $db_pass = $amp_conf["AMPDBPASS"]; - $db_host = $amp_conf["AMPDBHOST"]; - $db_name = $amp_conf["AMPDBNAME"]; - - $datasource = $db_engine.'://'.$db_user.':'.$db_pass.'@'.$db_host.'/'.$db_name; - $db = DB::connect($datasource); // attempt connection - break; - - case "sqlite": - require_once('DB/sqlite.php'); - - if (!isset($amp_conf["AMPDBFILE"])) - fatal(_("AMPDBFILE not setup properly"),sprintf(_("You must setup properly AMPDBFILE in %s "), $amportalconf)); - - if (isset($amp_conf["AMPDBFILE"]) == "") - fatal(_("AMPDBFILE not setup properly"),sprintf(_("AMPDBFILE in %s cannot be blank"), $amportalconf)); - - $DSN = array ( - "database" => $amp_conf["AMPDBFILE"], - "mode" => 0666 - ); - - $db = new DB_sqlite(); - $db->connect( $DSN ); - break; - - case "sqlite3": - if (!isset($amp_conf["AMPDBFILE"])) - fatal("You must setup properly AMPDBFILE in $amportalconf"); - - if (isset($amp_conf["AMPDBFILE"]) == "") - fatal("AMPDBFILE in $amportalconf cannot be blank"); - - require_once('DB/sqlite3.php'); - $datasource = "sqlite3:///" . $amp_conf["AMPDBFILE"] . "?mode=0666"; - $db = DB::connect($datasource); - break; - - default: - fatal( "Unknown SQL engine: [$db_engine]"); -} - -if(DB::isError($db)) { - out(_("FAILED")); - debug($db->userinfo); - fatal(_("database connection failure"),("failed trying to connect to the configured database")); - -} -out(_("OK")); // Check to see if email should be sent