16 * Authenticate user and register user information into a session
20 global $ARI_ADMIN_USERNAME;
21 global $ARI_ADMIN_PASSWORD;
22 global $ARI_ADMIN_EXTENSIONS;
23 global $ARI_CRYPT_PASSWORD;
24 global $ASTERISK_VOICEMAIL_CONF;
25 global $ASTERISK_VOICEMAIL_CONTEXT;
26 global $ASTERISK_VOICEMAIL_PATH;
27 global $ASTERISK_PROTOCOLS;
28 global $CALLMONITOR_ADMIN_EXTENSIONS;
30 global $ARI_DEFAULT_ADMIN_PAGE;
31 global $ARI_DEFAULT_USER_PAGE;
41 $voicemail_enabled = '';
42 $voicemail_email_address = '';
43 $voicemail_pager_address = '';
44 $voicemail_email_enable = '';
46 $admin_callmonitor = '';
52 // get the ari authentication cookie
55 if (isset($_COOKIE['ari_auth'])) {
56 $buf = unserialize($_COOKIE['ari_auth']);
57 list($data,$chksum) = $buf;
59 if (md5($data) == $chksum) {
60 $data = unserialize($crypt->decrypt($data,$ARI_CRYPT_PASSWORD));
61 $username = $data['username'];
62 $password = $data['password'];
65 if (isset($_POST['username']) &&
66 isset($_POST['password'])) {
67 $username = $_POST['username'];
68 $password = $_POST['password'];
71 // init email options array
72 $voicemail_email = array();
74 // when login, make a new session
75 if ($username && !$ARI_NO_LOGIN) {
81 if ($username==$ARI_ADMIN_USERNAME &&
82 $password==$ARI_ADMIN_PASSWORD) {
88 $name = 'Administrator';
90 $admin_callmonitor = 1;
92 $default_page = $ARI_DEFAULT_ADMIN_PAGE;
96 // check voicemail login
99 if (is_readable($ASTERISK_VOICEMAIL_CONF)) {
101 $lines = file($ASTERISK_VOICEMAIL_CONF);
103 // look for include files and tack their lines to end of array
104 foreach ($lines as $key => $line) {
106 if (preg_match("/include/i",$line)) {
108 $include_filename = '';
109 $parts = split(' ',$line);
110 if (isset($parts[1])) {
111 $include_filename = trim($parts[1]);
114 if ($include_filename) {
115 $path_parts = pathinfo($ASTERISK_VOICEMAIL_CONF);
116 $include_path = fixPathSlash($path_parts['dirname']) . $include_filename;
117 foreach (glob($include_path) as $include_file) {
118 $include_lines = file($include_file);
119 $lines = array_merge($include_lines,$lines);
126 foreach ($lines as $key => $line) {
128 // check for current context and process
129 if (preg_match("/\[.*\]/i",$line)) {
130 $currentContext = trim(preg_replace('/\[|\]/', '', $line));
132 if ($ASTERISK_VOICEMAIL_CONTEXT &&
133 $currentContext!=$ASTERISK_VOICEMAIL_CONTEXT) {
137 // check for user and process
139 $parts = split('=>',$line);
140 if (isset($parts[0])) {
143 if (isset($parts[1])) {
147 if ($var==$username && $value) {
148 $buf = split(',',$value);
149 if ($buf[0]==$password) {
153 $extension = $username;
154 $displayname = $buf[1];
155 $vm_password = $buf[0];
156 $default_page = $ARI_DEFAULT_USER_PAGE;
157 $context = $currentContext;
158 $voicemail_enabled = 1;
159 $voicemail_email_address = $buf[2];
160 $voicemail_pager_address = $buf[3];
162 if ($voicemail_email_address || $voicemail_pager_address) {
163 $voicemail_email_enable = 1;
166 $options = split('\|',$buf[4]);
167 foreach ($options as $option) {
168 $opt_buf = split('=',$option);
169 $voicemail_email[$opt_buf[0]] = trim($opt_buf[1]);
173 if ($ARI_ADMIN_EXTENSIONS) {
174 $extensions = split(',',$ARI_ADMIN_EXTENSIONS);
175 foreach ($extensions as $key => $value) {
176 if ($extension==$value) {
183 $admin_callmonitor = 0;
184 if ($CALLMONITOR_ADMIN_EXTENSIONS) {
185 $extensions = split(',',$CALLMONITOR_ADMIN_EXTENSIONS);
186 foreach ($extensions as $key => $value) {
187 if ($value=='all' || $extension==$value) {
188 $admin_callmonitor = 1;
195 $_SESSION['ari_error'] = "Incorrect Password";
202 $_SESSION['ari_error'] = "File not readable: " . $ASTERISK_VOICEMAIL_CONF;
210 foreach($ASTERISK_PROTOCOLS as $protocol => $value) {
212 $config_files = split(';',$value['config_files']);
213 foreach ($config_files as $config_file) {
215 if (is_readable($config_file)) {
217 $lines = file($config_file);
218 foreach ($lines as $key => $line) {
221 $parts = split('=',$line);
222 if (isset($parts[0])) {
223 $var = trim($parts[0]);
225 if (isset($parts[1])) {
226 $value = trim($parts[1]);
228 if ($var=="username") {
229 $protocol_username = $value;
231 if ($var=="secret") {
233 $protocol_password = $value;
234 if ($protocol_username==$username &&
235 $protocol_password==$password) {
239 $extension = $username ;
240 $displayname = $username;
241 $default_page = $ARI_DEFAULT_ADMIN_PAGE;
244 if ($ARI_ADMIN_EXTENSIONS) {
245 $extensions = split(',',$ARI_ADMIN_EXTENSIONS);
246 foreach ($extensions as $key => $value) {
247 if ($extension==$value) {
254 $admin_callmonitor = 0;
255 if ($CALLMONITOR_ADMIN_EXTENSIONS) {
256 $extensions = split(',',$CALLMONITOR_ADMIN_EXTENSIONS);
257 foreach ($extensions as $key => $value) {
258 if ($value=='all' || $extension==$value) {
259 $admin_callmonitor = 1;
265 else if ($protocol_username==$username &&
266 $protocol_password!=$password) {
267 $_SESSION['ari_error'] = _("Incorrect Password");
277 // let user know bad login
279 $_SESSION['ari_error'] = _("Incorrect Username or Password");
283 $freeside = new FreesideSelfService();
284 $domain = 'svc_phone';
285 $response = $freeside->login( array(
286 'username' => strtolower($username),
288 'password' => strtolower($password),
290 error_log("[login] received response from freeside: $response");
291 $error = $response['error'];
293 if ( ! $error && $response['session_id'] ) {
295 // sucessful freeside login
296 error_log("[login] logged into freeside with session_id=$session_id");
298 // store session id in your session store, to be used for other calls
299 //$fs_session_id = $response['session_id'];
300 $_SESSION['freeside_session_id'] = $response['session_id'];
302 $customer_info = $freeside->customer_info( array(
303 'session_id' => $_SESSION['freeside_session_id'] ,
305 //XXX error checking here too
306 $displayname = $customer_info['name'];
311 error_log("[login] error logging into freeside: $error");
315 // display error message to user
316 $_SESSION['ari_error'] = _("Incorrect Username or Password");
320 // if authenticated and user wants to be remembered, set cookie
322 if (isset($_POST['remember'])) {
323 $remember = $_POST['remember'];
325 if ($auth && $remember) {
327 $data = array('username' => $username, 'password' => $password);
328 $data = $crypt->encrypt(serialize($data),$ARI_CRYPT_PASSWORD);
330 $chksum = md5($data);
332 $buf = serialize(array($data,$chksum));
333 setcookie('ari_auth',$buf,time()+365*24*60*60,'/');
338 $category = "general";
343 $context = "default";
348 $extension = 'admin';
349 $name = 'Administrator';
350 $admin_callmonitor = 1;
351 $default_page = $ARI_DEFAULT_ADMIN_PAGE;
354 // get outboundCID if it exists
355 $outboundCID = $this->getOutboundCID($extension);
359 $_SESSION['ari_user']['extension'] = $extension;
360 $_SESSION['ari_user']['outboundCID'] = $outboundCID;
361 $_SESSION['ari_user']['displayname'] = $displayname;
362 $_SESSION['ari_user']['voicemail_password'] = $vm_password;
363 $_SESSION['ari_user']['category'] = $category;
364 $_SESSION['ari_user']['context'] = $context;
365 $_SESSION['ari_user']['voicemail_enabled'] = $voicemail_enabled;
366 $_SESSION['ari_user']['voicemail_email_address'] = $voicemail_email_address;
367 $_SESSION['ari_user']['voicemail_pager_address'] = $voicemail_pager_address;
368 $_SESSION['ari_user']['voicemail_email_enable'] = $voicemail_email_enable;
369 foreach ($voicemail_email as $key => $value) {
370 $_SESSION['ari_user']['voicemail_email'][$key] = $value;
372 $_SESSION['ari_user']['admin'] = $admin;
373 $_SESSION['ari_user']['admin_callmonitor'] = $admin_callmonitor;
374 $_SESSION['ari_user']['default_page'] = $default_page;
376 // force the session data saved
377 session_write_close();
383 * Gets user outbound caller id
386 * Extension to get information about
390 function getOutboundCID($extension) {
392 global $asterisk_manager_interface;
395 $response = $asterisk_manager_interface->Command2("Action: Command\r\nCommand: database get AMPUSER $extension/outboundcid\r\n\r\n");
398 $posLeft = strpos( $response, "<")+strlen("<");
399 $posRight = strpos( $response, ">", $posLeft);
400 $ret = substr( $response,$posLeft,$posRight-$posLeft);
409 unset($_COOKIE["ari_auth"]);
410 setcookie('ari_auth',"",time(),'/');
411 unset($_SESSION['ari_user']);
415 * Provide a login form for user
418 * Variable to hold data entered into form
422 global $ARI_NO_LOGIN;
429 if (isset($_GET['login'])) {
430 $login = $_GET['login'];
433 // if user name and password were given, but there was a problem report the error
434 if ($this->error!='') {
438 $language = new Language();
439 $display = new Display(NULL);
442 $ret .= $display->DisplayHeaderText(_("Login"));
443 $ret .= $display->DisplayLine();
444 $ret .= checkErrorMessage();
448 <form id='login' name='login' action=" . $_SESSION['ARI_ROOT'] . " method='POST'>
451 <small><small>" . _("Login") . ": </small></small>
454 <input type='text' name='username' value='" . $login . "' maxlength=20 tabindex=1>
459 <small><small>" . _("Password") . ": </small></small>
462 <input type='password' name='password' maxlength=20 tabindex=2>
468 <input type='submit' name='btnSubmit' value='" . _("Submit") . "' tabindex=3></small></small></p>
473 <input type='checkbox' name='remember'>
476 <p class='small'>" . _("Remember Password") . "</p>
483 " . $language->getForm() . "
486 <tr><td> </td></tr>
488 <table id='login_text'>
491 _("Use your <b>Voicemail Mailbox and Password</b>") . "<br>" .
492 _("This is the same password used for the phone") . "<br>" .
494 _("For password maintenance or assistance, contact your Phone System Administrator.") . "<br>" . "
500 <script type='text/javascript'>
502 if (document.login) {
503 document.login.username.focus();