From 3a17b276638200475d54201fa62566b7440e819a Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 16 Mar 2008 19:58:33 +0000 Subject: --- fs_selfservice/fri/includes/ajax.php | 132 +++++++++ fs_selfservice/fri/includes/asi.php | 156 ++++++++++ fs_selfservice/fri/includes/bootstrap.php | 315 ++++++++++++++++++++ fs_selfservice/fri/includes/common.php | 433 +++++++++++++++++++++++++++ fs_selfservice/fri/includes/crypt.php | 81 +++++ fs_selfservice/fri/includes/database.php | 72 +++++ fs_selfservice/fri/includes/display.php | 222 ++++++++++++++ fs_selfservice/fri/includes/lang.php | 112 +++++++ fs_selfservice/fri/includes/login.php | 477 ++++++++++++++++++++++++++++++ fs_selfservice/fri/includes/main.conf.php | 330 +++++++++++++++++++++ 10 files changed, 2330 insertions(+) create mode 100644 fs_selfservice/fri/includes/ajax.php create mode 100644 fs_selfservice/fri/includes/asi.php create mode 100644 fs_selfservice/fri/includes/bootstrap.php create mode 100644 fs_selfservice/fri/includes/common.php create mode 100644 fs_selfservice/fri/includes/crypt.php create mode 100644 fs_selfservice/fri/includes/database.php create mode 100644 fs_selfservice/fri/includes/display.php create mode 100644 fs_selfservice/fri/includes/lang.php create mode 100644 fs_selfservice/fri/includes/login.php create mode 100644 fs_selfservice/fri/includes/main.conf.php (limited to 'fs_selfservice/fri/includes') diff --git a/fs_selfservice/fri/includes/ajax.php b/fs_selfservice/fri/includes/ajax.php new file mode 100644 index 000000000..fc7961b08 --- /dev/null +++ b/fs_selfservice/fri/includes/ajax.php @@ -0,0 +1,132 @@ + $value) { + $url_args .= $key . "=" . $value . "&"; + } + $url_args = substr($url_args, 0,strlen($url_args)-1); + + $ret = " + "; + + return $ret; +} + + +?> \ No newline at end of file diff --git a/fs_selfservice/fri/includes/asi.php b/fs_selfservice/fri/includes/asi.php new file mode 100644 index 000000000..62f221e2f --- /dev/null +++ b/fs_selfservice/fri/includes/asi.php @@ -0,0 +1,156 @@ +=')) { + stream_set_timeout($fp, 5); + } + else { + socket_set_timeout($fp, 5); + } + $buffer = fgets($fp); + if (!preg_match('/Asterisk Call Manager/i', $buffer)) { + $_SESSION['ari_error'] = _("Asterisk Call Manager not responding") . "
\n"; + return FALSE; + } + else { + $out="Action: Login\r\nUsername: ".$username."\r\nSecret: ".$password."\r\n\r\n"; + fwrite($fp,$out); + $buffer=fgets($fp); + if ($buffer!="Response: Success\r\n") { + $_SESSION['ari_error'] = _("Asterisk authentication failed:") . "
" . $buffer . "
\n"; + return FALSE; + } + else { + $buffers=fgets($fp); // get rid of Message: Authentication accepted + + // connected + $this->socket = $fp; + } + } + } + return TRUE; + } + + /* + * Reloads Asterisk Configuration + */ + function disconnect() { + + if ($this->socket) { + fclose($this->socket); + } + } + + /* + * Reloads Asterisk Configuration + * + * @param $command + * Command to be sent to the asterisk manager interface + * @return $ret + * response from asterisk manager interface + */ + function command($command) { + + $response = ''; + + fwrite($this->socket,$command); + + $count = 0; + while (($buffer = fgets($this->socket)) && (!preg_match('/Response: Follows/i', $buffer))) { + + if ($count>100) { + $_SESSION['ari_error'] = _("Asterisk command not understood") . "
" . $buffer . "
\n"; + return FALSE; + } + $count++; + } + + $count = 0; + while (($buffer = fgets($this->socket)) && (!preg_match('/END COMMAND/i', $buffer))) { + + if (preg_match('/Value/',$buffer)) { + $parts = split(' ',trim($buffer)); + $response = $parts[1]; + } + + if ($count>100) { + $_SESSION['ari_error'] = _("Asterisk command not understood") . "
" . $buffer . "
\n"; + return; + } + $count++; + } + + return $response; + } + + function command2($command) { + + $response = ''; + + fwrite($this->socket,$command); + + $count = 0; + while (($buffer = fgets($this->socket)) && (!preg_match('/Response: Follows/i', $buffer))) { + + if ($count>100) { + $_SESSION['ari_error'] = _("Asterisk command not understood") . "
" . $buffer . "
\n"; + return FALSE; + } + $count++; + } + + $count = 0; + while (($buffer = fgets($this->socket)) && (!preg_match('/END COMMAND/i', $buffer))) { + + if (preg_match('/Value:/',$buffer)) { + $parts = split('Value:',trim($buffer)); + $response = $parts[1]; + } + if ($count>100) { + $_SESSION['ari_error'] = _("Asterisk command not understood") . "
" . $buffer . "
\n"; + return; + } + $count++; + } + + return $response; + } + +} + + +?> \ No newline at end of file diff --git a/fs_selfservice/fri/includes/bootstrap.php b/fs_selfservice/fri/includes/bootstrap.php new file mode 100644 index 000000000..a01a2f5c8 --- /dev/null +++ b/fs_selfservice/fri/includes/bootstrap.php @@ -0,0 +1,315 @@ +3000) { + $_SESSION['ari_error'] + .= _("To many files in $msg_path Not all files processed") . "
"; + return; + } + + if ($recursive_count<$recursive_max && is_dir($msg_path)) { + + $dirCount++; + if ($dirCount>10) { + $_SESSION['ari_error'] + .= sprintf(_("To many directories in %s Not all files processed"),$msg_path) . "
"; + return; + } + + $count = $recursive_count + 1; + $path_files = getFiles($msg_path,$filter,$recursive_max,$count); + $files = array_merge($files,$path_files); + } + else { + $found = 0; + if ($filter) { + if (strpos($msg_path,$filter)) { + $found = 1; + } + } else { + $found = 1; + } + if ($found) { + $files[count($files) + 1] = $msg_path; + } + } + } + } + } + + return $files; +} + +/* Utilities */ + +/** + * Fixes the path for a trailing slash + * + * @param $path + * path to append + * @return $ret + * path to returned + */ +function fixPathSlash($path) { + + $ret = $path; + + $slash = ''; + if (!preg_match('/\/$/',$path)) { + $slash = '/'; + } + $ret .= $slash; + + return $ret; +} + +/** + * Appends folder to end of path + * + * @param $path + * path to append + * @param $folder + * folder to append to path + * @return $ret + * path to returned + */ +function appendPath($path,$folder) { + + $ret = $path; + + $m = ''; + if (!preg_match('/\/$/',$path)) { + $m = '/'; + } + $ret .= $m . $folder; + + return $ret; +} + +/** + * Get Date format + * + * @param $timestamp + * timestamp to be converted + */ +function getDateFormat($timestamp) { + return date('Y-m-d', $timestamp); +} + +/** + * Get time format + * + * @param $timestamp + * timestamp to be converted + */ +function getTimeFormat($timestamp) { + return date('G:i:s', $timestamp); +} + +/* */ + +/** + * Checks ARI dependencies + */ +function checkDependencies() { + + // check for PHP + if (!version_compare(phpversion(), '4.3', '>=')) { + echo _("ARI requires a version of PHP 4.3 or later"); + exit(); + } + + // check for PEAR + $include_path = ini_get('include_path'); + $buf = split(':|,',$include_path); + + $found = 0; + foreach ($buf as $path) { + $path = fixPathSlash($path); + $pear_check_path = $path . "DB.php"; + if (is_file($pear_check_path)) { + $found = 1; + break; + } + } + + if (!$found) { + echo _("PHP PEAR must be installed. Visit http://pear.php.net for help with installation."); + exit(); + } +} + +/** + * Starts the session + */ +function startARISession() { + + if (!isset($_SESSION['ari_user']) ) { + + // start a new session for the user + ini_set('session.name', 'ARI'); // prevent session name clashes + ini_set('session.gc_maxlifetime', '3900'); // make the session timeout a long time + set_time_limit(360); + session_start(); + } +} + +/** + * Bootstrap + * + * Loads critical variables needed for every page request + * + */ +function bootstrap() { + + // set error reporting + error_reporting (E_ALL & ~ E_NOTICE); +} + +/** + * Set HTTP headers in preparation for a page response. + * + * TODO: Figure out caching + */ +function ariPageHeader() { + + bootstrap(); +} + +/** + * Perform end-of-request tasks. + * + * This function sets the page cache if appropriate, and allows modules to + * react to the closing of the page by calling hook_exit(). + */ +function ariPageFooter() { + +} + +/** + * Includes and run functions + */ + +include_once("./includes/lang.php"); +$language = new Language(); +$language->set(); + +checkDependencies(); +startARISession(); +setARIRoot(); + +include_once("./includes/main.conf.php"); +include_once("./version.php"); +include_once("./includes/crypt.php"); +include_once("./includes/login.php"); + + +?> diff --git a/fs_selfservice/fri/includes/common.php b/fs_selfservice/fri/includes/common.php new file mode 100644 index 000000000..caa76c1d6 --- /dev/null +++ b/fs_selfservice/fri/includes/common.php @@ -0,0 +1,433 @@ + + " . $_SESSION['ari_error'] . " + +
"; + unset($_SESSION['ari_error']); + } + + return $ret; +} + +/* + * Checks modules directory, and configuration, and loaded modules + */ +function loadModules() { + + global $ARI_ADMIN_MODULES; + global $ARI_DISABLED_MODULES; + + global $loaded_modules; + + $modules_path = "./modules"; + if (is_dir($modules_path)) { + + $filter = ".module"; + $recursive_max = 1; + $recursive_count = 0; + $files = getFiles($modules_path,$filter,$recursive_max,$recursive_count); + + foreach($files as $key => $path) { + + // build module object + include_once($path); + $path_parts = pathinfo($path); + list($name,$ext) = split("\.",$path_parts['basename']); + + // check for module and get rank + if (class_exists($name)) { + + $module = new $name(); + + // check if admin module + $found = 0; + if ($ARI_ADMIN_MODULES) { + $admin_modules = split(',',$ARI_ADMIN_MODULES); + foreach ($admin_modules as $key => $value) { + if ($name==$value) { + $found = 1; + break; + } + } + } + + // check if disabled module + $disabled = 0; + if ($ARI_DISABLED_MODULES) { + $disabled_modules = split(',',$ARI_DISABLED_MODULES); + foreach ($disabled_modules as $key => $value) { + if ($name==$value) { + $disabled = 1; + break; + } + } + } + + // if not admin module or admin user add to module name to array + if (!$disabled && (!$found || $_SESSION['ari_user']['admin'])) { + $loaded_modules[$name] = $module; + } + } + } + } + else { + $_SESSION['ari_error'] = _("$path not a directory or not readable"); + } +} + +/** + * Builds database connections + */ +function databaseLogon() { + + global $STANDALONE; + + global $ASTERISKMGR_DBHOST; + + global $AMP_FUNCTIONS_FILES; + global $AMPORTAL_CONF_FILE; + + global $LEGACY_AMP_DBENGINE; + global $LEGACY_AMP_DBFILE; + global $LEGACY_AMP_DBHOST; + global $LEGACY_AMP_DBNAME; + + global $ASTERISKCDR_DBENGINE; + global $ASTERISKCDR_DBFILE; + global $ASTERISKCDR_DBHOST; + global $ASTERISKCDR_DBNAME; + + global $ARI_DISABLED_MODULES; + + global $loaded_modules; + + // This variable is a global in the FreePBX function.inc.php but needs to be + // declared here or the is not seen when parse_amprotaconf() is eventually called + // ?php bug? + // + global $amp_conf_defaults; + + // get user + if ($STANDALONE['use']) { + + $mgrhost = $ASTERISKMGR_DBHOST; + $mgruser = $STANDALONE['asterisk_mgruser']; + $mgrpass = $STANDALONE['asterisk_mgrpass']; + + $asteriskcdr_dbengine = $ASTERISKCDR_DBENGINE; + $asteriskcdr_dbfile = $ASTERISKCDR_DBFILE; + $asteriskcdr_dbuser = $STANDALONE['asteriskcdr_dbuser']; + $asteriskcdr_dbpass = $STANDALONE['asteriskcdr_dbpass']; + $asteriskcdr_dbhost = $ASTERISKCDR_DBHOST; + $asteriskcdr_dbname = $ASTERISKCDR_DBNAME; + } + else { + + $include = 0; + $files = split(';',$AMP_FUNCTIONS_FILES); + foreach ($files as $file) { + if (is_file($file)) { + include_once($file); + $include = 1; + } + } + + if ($include) { + $amp_conf = parse_amportal_conf($AMPORTAL_CONF_FILE); + + $mgrhost = $ASTERISKMGR_DBHOST; + $mgruser = $amp_conf['AMPMGRUSER']; + $mgrpass = $amp_conf['AMPMGRPASS']; + + $amp_dbengine = isset($amp_conf["AMPDBENGINE"]) ? $amp_conf["AMPDBENGINE"] : $LEGACY_AMP_DBENGINE; + $amp_dbfile = isset($amp_conf["AMPDBFILE"]) ? $amp_conf["AMPDBFILE"] : $LEGACY_AMP_DBFILE; + $amp_dbuser = $amp_conf["AMPDBUSER"]; + $amp_dbpass = $amp_conf["AMPDBPASS"]; + $amp_dbhost = isset($amp_conf["AMPDBHOST"]) ? $amp_conf["AMPDBHOST"] : $LEGACY_AMP_DBHOST; + $amp_dbname = isset($amp_conf["AMPDBNAME"]) ? $amp_conf["AMPDBNAME"] : $LEGACY_AMP_DBNAME; + + $asteriskcdr_dbengine = $ASTERISKCDR_DBENGINE; + $asteriskcdr_dbfile = $ASTERISKCDR_DBFILE; + $asteriskcdr_dbuser = $amp_conf["AMPDBUSER"]; + $asteriskcdr_dbpass = $amp_conf["AMPDBPASS"]; + $asteriskcdr_dbhost = $ASTERISKCDR_DBHOST; + $asteriskcdr_dbhost = isset($amp_conf["AMPDBHOST"]) ? $amp_conf["AMPDBHOST"] : $ASTERISKCDR_DBHOST; + $asteriskcdr_dbname = $ASTERISKCDR_DBNAME; + + unset($amp_conf); + } + } + + // asterisk manager interface (berkeley database I think) + global $asterisk_manager_interface; + $asterisk_manager_interface = new AsteriskManagerInterface(); + + $success = $asterisk_manager_interface->Connect($mgrhost,$mgruser,$mgrpass); + if (!$success) { + $_SESSION['ari_error'] = + _("ARI does not appear to have access to the Asterisk Manager.") . " ($errno)
" . + _("Check the ARI 'main.conf.php' configuration file to set the Asterisk Manager Account.") . "
" . + _("Check /etc/asterisk/manager.conf for a proper Asterisk Manager Account") . "
" . + _("make sure [general] enabled = yes and a 'permit=' line for localhost or the webserver."); + return FALSE; + } + + // pear interface databases + $db = new Database(); + + // AMP asterisk database + if (!$STANDALONE['use']) { + $_SESSION['dbh_asterisk'] = $db->logon($amp_dbengine, + $amp_dbfile, + $amp_dbuser, + $amp_dbpass, + $amp_dbhost, + $amp_dbname); + if (!isset($_SESSION['dbh_asterisk'])) { + $_SESSION['ari_error'] .= _("Cannot connect to the $amp_dbname database") . "
" . + _("Check AMP installation, asterisk, and ARI main.conf"); + return FALSE; + } + } + + // cdr database + if (in_array('callmonitor',array_keys($loaded_modules))) { + $_SESSION['dbh_cdr'] = $db->logon($asteriskcdr_dbengine, + $asteriskcdr_dbfile, + $asteriskcdr_dbuser, + $asteriskcdr_dbpass, + $asteriskcdr_dbhost, + $asteriskcdr_dbname); + if (!isset($_SESSION['dbh_cdr'])) { + $_SESSION['ari_error'] .= sprintf(_("Cannot connect to the $asteriskcdr_dbname database"),$asteriskcdr_dbname) . "
" . + _("Check AMP installation, asterisk, and ARI main.conf"); + return FALSE; + } + } + + return TRUE; +} + +/** + * Logout if needed for any databases + */ +function databaseLogoff() { + + global $asterisk_manager_interface; + + $asterisk_manager_interface->Disconnect(); +} + +/* + * Checks if user is set and sets + */ +function loginBlock() { + + $login = new Login(); + + if (isset($_REQUEST['logout'])) { + $login->Unauth(); + } + + if (!isset($_SESSION['ari_user'])) { + $login->Auth(); + + } + + if (!isset($_SESSION['ari_user'])) { + + // login form + $ret .= $login->GetForm(); + + return $ret; + } +} + +/* + * Main handler for website + */ +function handleBlock() { + + global $ARI_NO_LOGIN; + + global $loaded_modules; + + // check errors here and in login block + $content .= checkErrorMessage(); + + // check logout + if ($_SESSION['ari_user'] && !$ARI_NO_LOGIN) { + $logout = 1; + } + + // if nothing set goto user default page + if (!isset($_REQUEST['m'])) { + $_REQUEST['m'] = $_SESSION['ari_user']['default_page']; + } + // if not function specified then use display page function + if (!isset($_REQUEST['f'])) { + $_REQUEST['f'] = 'display'; + } + + $m = $_REQUEST['m']; // module + $f = $_REQUEST['f']; // function + $a = $_REQUEST['a']; // action + + // set arguments + $args = array(); + foreach($_REQUEST as $key => $value) { + $args[$key] = $value; + } + + // set rank + $ranked_modules = array(); + foreach ($loaded_modules as $module) { + + $module_methods = get_class_methods($module); // note that PHP4 returns all lowercase + while (list($index, $value) = each($module_methods)) { + $module_methods[strtolower($index)] = strtolower($value); + } + reset($module_methods); + + $rank = 99999; + $rank_function = "rank"; + if (in_array(strtolower($rank_function), $module_methods)) { + $rank = $module->$rank_function(); + } + + $ranked_modules[$rank] = $module; + } + ksort($ranked_modules); + + // process modules + foreach ($ranked_modules as $module) { + + // process module + $name = get_class($module); // note PHP4 returns all lowercase + $module_methods = get_class_methods($module); // note PHP4 returns all lowercase + while (list($index, $value) = each($module_methods)) { + $module_methods[strtolower($index)] = strtolower($value); + } + reset($module_methods); + + // init module + $module->init(); + + // add nav menu items + $nav_menu_function = "navMenu"; + if (in_array(strtolower($nav_menu_function), $module_methods)) { + $nav_menu .= $module->$nav_menu_function($args); + } + + if (strtolower($m)==strtolower($name)) { + + // build sub menu + $subnav_menu_function = "navSubMenu"; + if (in_array(strtolower($subnav_menu_function), $module_methods)) { + $subnav_menu .= $module->$subnav_menu_function($args); + } + + // execute function (usually to build content) + if (in_array(strtolower($f), $module_methods)) { + $content .= $module->$f($args); + } + } + } + + // add logout link + if ($logout != '') { + $nav_menu .= "

" . _("Logout") . "

"; + } + + // error message if no content + if (!$content) { + $content .= _("Page Not Found."); + } + + return array($nav_menu,$subnav_menu,$content); +} + +/* + * Main handler for website + */ +function handler() { + + global $ARI_VERSION; + + // version + $ari_version = $ARI_VERSION; + + // check error + $error = $_SESSION['ari_error']; + + // load modules + loadModules(); + + // login to database + $success = databaseLogon(); + if ($success) { + + // check if login is needed + $content = loginBlock(); + if (!isset($content)) { + list($nav_menu,$subnav_menu,$content) = handleBlock(); + } + } + else { + + $display = new Display(); + + $content .= $display->displayHeaderText("ARI"); + $content .= $display->displayLine(); + $content .= checkErrorMessage(); + } + + // log off any databases needed + databaseLogoff(); + + // check for ajax request and refresh or if not build the page + if (isset($_REQUEST['ajax_refresh']) ) { + + echo " + + + + + "; + } + else { + + // build the page + include_once("./theme/page.tpl.php"); + } +} + +/** + * Includes and run functions + */ + +// create asterisk manager interface singleton +$asterisk_manager_interface = ''; + +// array to keep track of loaded modules +$loaded_modules = array(); + +include_once("./includes/asi.php"); +include_once("./includes/database.php"); +include_once("./includes/display.php"); +include_once("./includes/ajax.php"); + + +?> diff --git a/fs_selfservice/fri/includes/crypt.php b/fs_selfservice/fri/includes/crypt.php new file mode 100644 index 000000000..301d8a840 --- /dev/null +++ b/fs_selfservice/fri/includes/crypt.php @@ -0,0 +1,81 @@ + 0) { + $iv .= chr(mt_rand() & 0xff); + } + return $iv; + } + + /** + * Encrypts string + * - From php.net docs + * + * @param $str + * string to encrypt + * @param $salt + * password to use for encryption + * @param $iv_len + * length of random number + */ + function encrypt($str, $salt, $iv_len = 16) { + + $str .= "\x13"; + $n = strlen($str); + if ($n % 16) $str .= str_repeat("\0", 16 - ($n % 16)); + $i = 0; + $enc_text = $this->getRndIV($iv_len); + $iv = substr($salt ^ $enc_text, 0, 512); + while ($i < $n) { + $block = substr($str, $i, 16) ^ pack('H*', md5($iv)); + $enc_text .= $block; + $iv = substr($block . $iv, 0, 512) ^ $salt; + $i += 16; + } + return urlencode(base64_encode($enc_text)); + } + + /** + * Decrypts string + * - From php.net docs + * + * @param $enc + * encrypted string to decrypt + * @param $salt + * password to use for encryption + * @param $iv_len + * length of random number + */ + function decrypt($enc, $salt, $iv_len = 16) { + + $enc = urldecode(base64_decode($enc)); + $n = strlen($enc); + $i = $iv_len; + $str = ''; + $iv = substr($salt ^ substr($enc, 0, $iv_len), 0, 512); + while ($i < $n) { + $block = substr($enc, $i, 16); + $str .= $block ^ pack('H*', md5($iv)); + $iv = substr($block . $iv, 0, 512) ^ $salt; + $i += 16; + } + return preg_replace('/\\x13\\x00*$/', '', $str); + } +} + + +?> diff --git a/fs_selfservice/fri/includes/database.php b/fs_selfservice/fri/includes/database.php new file mode 100644 index 000000000..ff3d199c0 --- /dev/null +++ b/fs_selfservice/fri/includes/database.php @@ -0,0 +1,72 @@ + 2, + 'portability' => DB_PORTABILITY_LOWERCASE|DB_PORTABILITY_RTRIM|DB_PORTABILITY_DELETE_COUNT|DB_PORTABILITY_NUMROWS|DB_PORTABILITY_ERRORS|DB_PORTABILITY_NULL_TO_EMPTY, + ); + + // attempt connection + $dbh = DB::connect($datasource,$options); + + // if connection failed show error + if(DB::isError($dbh)) { + $_SESSION['ari_error'] .= $dbh->getMessage() . "

"; + return; + } + return $dbh; + } +} + + +?> \ No newline at end of file diff --git a/fs_selfservice/fri/includes/display.php b/fs_selfservice/fri/includes/display.php new file mode 100644 index 000000000..41d8dc5f0 --- /dev/null +++ b/fs_selfservice/fri/includes/display.php @@ -0,0 +1,222 @@ +" . $text . " +
"; + + return $ret; + } + + /** + * displays header line + */ + function displayLine() { + + $ret = " +
+
+
+
+
"; + + return $ret; + } +} + +/** + * DisplaySearch + */ +class DisplaySearch extends Display { + + /** + * Constructor + */ + function DisplaySearch() { + } + + /** + * displays search controls + * + * @param $align + * where to align the control + * @param $q + * search query + * @param $focus + * whether to focus control on this block + */ + function displaySearchBlock($align,$m,$q,$url_opts,$focus) { + + // align + if ($align=='center') { + $alignText = "class='bar_center'"; + } + else { + $alignText = "class='bar_left'"; + } + + // url options + foreach ($url_opts as $key => $value) { + $option_text .= ""; + } + + // build + $ret .= "
+
+ + + " . $option_text . " + + +
+
"; + + if ($focus=="true") { // search block loaded twice usually so only allow javascript to be loaded on the top block + $ret .= ""; + } + + return $ret; + } + + /** + * displays info bar + * + * @param $controls + * controls for the page on the bar + * @param $q + * search query + * @param $start + * start number of current page + * @param $span + * number of items on current page + * @param $total + * total number of records found by current search + */ + function displayInfoBarBlock($controls,$q,$start,$span,$total) { + + if ($total<$span) { + $span = $total; + } + $start_count = ($total>0)?$start+1:$start; + $span_count = ($start+$span>$total)?$total:$start+$span; + + if ($controls) { + $left_text = $controls; + } + elseif ($q != NULL) { + $left_text = "" . _("Searched for") . " " . $q . ""; + } + + if ($span<$total) { + $right_text = "" . sprintf(_("Results %d - %d of %d"),$start_count,$span_count,$total) . ""; + } else { + $right_text = "" . sprintf(_("Results %d"),$total) . ""; + } + + $ret .= " + + + + + + "; + + return $ret; + } + + /** + * displays navigation bar + * + * @param $q + * search query + * @param $start + * start number of current page + * @param $span + * number of items on current page + * @param $total + * total number of records found by current search + */ + function displayNavigationBlock($m,$q,$url_opts,$start,$span,$total) { + + $start = $start=='' ? 0 : $start ; + $span = $span=='' ? 15 : $span ; + + $total_pages = ceil($total/$span); + $start_page = floor($start/$span); + + // if more than ten pages start at this page minus ten otherwise start at zero + $begin = ($start_page>10)?($start_page-10):0; + // if more than ten pages then stop at this page plus ten otherwise stop at last page + $end = ($start_page>8)?($start_page+10):10; + + // url + $unicode_q = urlencode($q); // encode search string + + foreach ($url_opts as $key => $value) { + $option_text .= "&" . $key . "=" . $value; + } + + $url = $_SESSION['ARI_ROOT'] . "?m=" . $m . "&q=" . $unicode_q . $option_text; + + // build + if ($start_page!=0) { + $start_page_text = "" . _("First") . "  + < "; + } + + for($next_page=$begin;($next_page<$total_pages)&&($next_page<$end);$next_page++) { + if ($next_page == $start_page) { + $middle_page_text .= "" . ($next_page+1) . " "; + } else { + $middle_page_text .= "" . ($next_page+1) . " "; + } + } + if ( ($start_page != $total_pages-1) && ($total != 0) ) { + $end_page_text = ">  + " . _("Last") . " "; + } + + $ret .= "
+ " . $start_page_text . " + " . $middle_page_text . " + " . $end_page_text . " +
"; + + return $ret; + } +} + + +?> \ No newline at end of file diff --git a/fs_selfservice/fri/includes/lang.php b/fs_selfservice/fri/includes/lang.php new file mode 100644 index 000000000..b27b8e337 --- /dev/null +++ b/fs_selfservice/fri/includes/lang.php @@ -0,0 +1,112 @@ + + function setCookie(name,value) { + var t = new Date(); + var e = new Date(); + e.setTime(t.getTime() + 365*24*60*60); + document.cookie = name+\"=\"+escape(value) + \";expires=\"+e.toGMTString(); + } + +
+ +
"; + } + + return $langOptions; + } + + +} + + +?> \ No newline at end of file diff --git a/fs_selfservice/fri/includes/login.php b/fs_selfservice/fri/includes/login.php new file mode 100644 index 000000000..826692c29 --- /dev/null +++ b/fs_selfservice/fri/includes/login.php @@ -0,0 +1,477 @@ +decrypt($data,$ARI_CRYPT_PASSWORD)); + $username = $data['username']; + $password = $data['password']; + } + + if (isset($_POST['username']) && + isset($_POST['password'])) { + $username = $_POST['username']; + $password = $_POST['password']; + } + + // init email options array + $voicemail_email = array(); + + // when login, make a new session + if ($username && !$ARI_NO_LOGIN) { + + $auth = false; + + // check admin + if (!$auth) { + if ($username==$ARI_ADMIN_USERNAME && + $password==$ARI_ADMIN_PASSWORD) { + + // authenticated + $auth = true; + + $extension = 'admin'; + $name = 'Administrator'; + $admin = 1; + $admin_callmonitor = 1; + + $default_page = $ARI_DEFAULT_ADMIN_PAGE; + } + } + + // check voicemail login + if (!$auth) { + + if (is_readable($ASTERISK_VOICEMAIL_CONF)) { + + $lines = file($ASTERISK_VOICEMAIL_CONF); + + // look for include files and tack their lines to end of array + foreach ($lines as $key => $line) { + + if (preg_match("/include/i",$line)) { + + $include_filename = ''; + $parts = split(' ',$line); + if (isset($parts[1])) { + $include_filename = trim($parts[1]); + } + + if ($include_filename) { + $path_parts = pathinfo($ASTERISK_VOICEMAIL_CONF); + $include_path = fixPathSlash($path_parts['dirname']) . $include_filename; + foreach (glob($include_path) as $include_file) { + $include_lines = file($include_file); + $lines = array_merge($include_lines,$lines); + } + } + } + } + + // process + foreach ($lines as $key => $line) { + + // check for current context and process + if (preg_match("/\[.*\]/i",$line)) { + $currentContext = trim(preg_replace('/\[|\]/', '', $line)); + } + if ($ASTERISK_VOICEMAIL_CONTEXT && + $currentContext!=$ASTERISK_VOICEMAIL_CONTEXT) { + continue; + } + + // check for user and process + unset($value); + $parts = split('=>',$line); + if (isset($parts[0])) { + $var = $parts[0]; + } + if (isset($parts[1])) { + $value = $parts[1]; + } + $var = trim($var); + if ($var==$username && $value) { + $buf = split(',',$value); + if ($buf[0]==$password) { + + // authenticated + $auth = true; + $extension = $username; + $displayname = $buf[1]; + $vm_password = $buf[0]; + $default_page = $ARI_DEFAULT_USER_PAGE; + $context = $currentContext; + $voicemail_enabled = 1; + $voicemail_email_address = $buf[2]; + $voicemail_pager_address = $buf[3]; + + if ($voicemail_email_address || $voicemail_pager_address) { + $voicemail_email_enable = 1; + } + + $options = split('\|',$buf[4]); + foreach ($options as $option) { + $opt_buf = split('=',$option); + $voicemail_email[$opt_buf[0]] = trim($opt_buf[1]); + } + + $admin = 0; + if ($ARI_ADMIN_EXTENSIONS) { + $extensions = split(',',$ARI_ADMIN_EXTENSIONS); + foreach ($extensions as $key => $value) { + if ($extension==$value) { + $admin = 1; + break 2; + } + } + } + + $admin_callmonitor = 0; + if ($CALLMONITOR_ADMIN_EXTENSIONS) { + $extensions = split(',',$CALLMONITOR_ADMIN_EXTENSIONS); + foreach ($extensions as $key => $value) { + if ($value=='all' || $extension==$value) { + $admin_callmonitor = 1; + break 2; + } + } + } + } + else { + $_SESSION['ari_error'] = "Incorrect Password"; + return; + } + } + } + } + else { + $_SESSION['ari_error'] = "File not readable: " . $ASTERISK_VOICEMAIL_CONF; + return; + } + } + + // check sip login + if (!$auth) { + + foreach($ASTERISK_PROTOCOLS as $protocol => $value) { + + $config_files = split(';',$value['config_files']); + foreach ($config_files as $config_file) { + + if (is_readable($config_file)) { + + $lines = file($config_file); + foreach ($lines as $key => $line) { + + unset($value); + $parts = split('=',$line); + if (isset($parts[0])) { + $var = trim($parts[0]); + } + if (isset($parts[1])) { + $value = trim($parts[1]); + } + if ($var=="username") { + $protocol_username = $value; + } + if ($var=="secret") { + + $protocol_password = $value; + if ($protocol_username==$username && + $protocol_password==$password) { + + // authenticated + $auth = true; + $extension = $username ; + $displayname = $username; + $default_page = $ARI_DEFAULT_ADMIN_PAGE; + + $admin = 0; + if ($ARI_ADMIN_EXTENSIONS) { + $extensions = split(',',$ARI_ADMIN_EXTENSIONS); + foreach ($extensions as $key => $value) { + if ($extension==$value) { + $admin = 1; + break 2; + } + } + } + + $admin_callmonitor = 0; + if ($CALLMONITOR_ADMIN_EXTENSIONS) { + $extensions = split(',',$CALLMONITOR_ADMIN_EXTENSIONS); + foreach ($extensions as $key => $value) { + if ($value=='all' || $extension==$value) { + $admin_callmonitor = 1; + break 2; + } + } + } + } + else if ($protocol_username==$username && + $protocol_password!=$password) { + $_SESSION['ari_error'] = _("Incorrect Password"); + return; + } + } + } + } + } + } + } + + // let user know bad login + if (!$auth) { + $_SESSION['ari_error'] = _("Incorrect Username or Password"); + } + + // if authenticated and user wants to be remembered, set cookie + $remember = ''; + if (isset($_POST['remember'])) { + $remember = $_POST['remember']; + } + if ($auth && $remember) { + + $data = array('username' => $username, 'password' => $password); + $data = $crypt->encrypt(serialize($data),$ARI_CRYPT_PASSWORD); + + $chksum = md5($data); + + $buf = serialize(array($data,$chksum)); + setcookie('ari_auth',$buf,time()+365*24*60*60,'/'); + } + + // set category + if (!$category) { + $category = "general"; + } + + // set context + if (!$context) { + $context = "default"; + } + + // no login user + if ($ARI_NO_LOGIN) { + $extension = 'admin'; + $name = 'Administrator'; + $admin_callmonitor = 1; + $default_page = $ARI_DEFAULT_ADMIN_PAGE; + } + + // get outboundCID if it exists + $outboundCID = $this->getOutboundCID($extension); + + // set + if ($extension) { + $_SESSION['ari_user']['extension'] = $extension; + $_SESSION['ari_user']['outboundCID'] = $outboundCID; + $_SESSION['ari_user']['displayname'] = $displayname; + $_SESSION['ari_user']['voicemail_password'] = $vm_password; + $_SESSION['ari_user']['category'] = $category; + $_SESSION['ari_user']['context'] = $context; + $_SESSION['ari_user']['voicemail_enabled'] = $voicemail_enabled; + $_SESSION['ari_user']['voicemail_email_address'] = $voicemail_email_address; + $_SESSION['ari_user']['voicemail_pager_address'] = $voicemail_pager_address; + $_SESSION['ari_user']['voicemail_email_enable'] = $voicemail_email_enable; + foreach ($voicemail_email as $key => $value) { + $_SESSION['ari_user']['voicemail_email'][$key] = $value; + } + $_SESSION['ari_user']['admin'] = $admin; + $_SESSION['ari_user']['admin_callmonitor'] = $admin_callmonitor; + $_SESSION['ari_user']['default_page'] = $default_page; + + // force the session data saved + session_write_close(); + } + } + } + + /* + * Gets user outbound caller id + * + * @param $exten + * Extension to get information about + * @return $ret + * outbound caller id + */ + function getOutboundCID($extension) { + + global $asterisk_manager_interface; + + $ret = ''; + $response = $asterisk_manager_interface->Command2("Action: Command\r\nCommand: database get AMPUSER $extension/outboundcid\r\n\r\n"); + if ($response) { + + $posLeft = strpos( $response, "<")+strlen("<"); + $posRight = strpos( $response, ">", $posLeft); + $ret = substr( $response,$posLeft,$posRight-$posLeft); + } + return $ret; + } + + /** + * logout + */ + function Unauth() { + unset($_COOKIE["ari_auth"]); + setcookie('ari_auth',"",time(),'/'); + unset($_SESSION['ari_user']); + } + + /** + * Provide a login form for user + * + * @param $request + * Variable to hold data entered into form + */ + function GetForm() { + + global $ARI_NO_LOGIN; + + if ($ARI_NO_LOGIN) { + $ret = ''; + return; + } + + if (isset($_GET['login'])) { + $login = $_GET['login']; + } + + // if user name and password were given, but there was a problem report the error + if ($this->error!='') { + $ret = $this->error; + } + + $language = new Language(); + $display = new Display(NULL); + + // new header + $ret .= $display->DisplayHeaderText(_("Login")); + $ret .= $display->DisplayLine(); + $ret .= checkErrorMessage(); + + $ret .= " + + + + + + + + + + + + + + + + + + + + + + + + +
+ " . _("Login") . ":   + + +
+ " . _("Password") . ":   + + +
+

+
+ + +

" . _("Remember Password") . "

+
+ " . $language->getForm() . " +
 
+ + + + +
" . + _("Use your Voicemail Mailbox and Password") . "
" . + _("This is the same password used for the phone") . "
" . + "
" . + _("For password maintenance or assistance, contact your Phone System Administrator.") . "
" . " +
"; + + $ret .= " + "; + + return $ret; + } + + +} + + +?> \ No newline at end of file diff --git a/fs_selfservice/fri/includes/main.conf.php b/fs_selfservice/fri/includes/main.conf.php new file mode 100644 index 000000000..31592cac6 --- /dev/null +++ b/fs_selfservice/fri/includes/main.conf.php @@ -0,0 +1,330 @@ + -- cgit v1.2.1