-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
417 lines (365 loc) · 18.8 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
<?php
/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4:
Codificación: UTF-8
+----------------------------------------------------------------------+
| Issabel version 0.5 |
| http://www.issabel.org |
+----------------------------------------------------------------------+
| Copyright (c) 2006 Palosanto Solutions S. A. |
+----------------------------------------------------------------------+
| The contents of this file are subject to the General Public License |
| (GPL) Version 2 (the "License"); you may not use this file except in |
| compliance with the License. You may obtain a copy of the License at |
| http://www.opensource.org/licenses/gpl-license.php |
| |
| Software distributed under the License is distributed on an "AS IS" |
| basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See |
| the License for the specific language governing rights and |
| limitations under the License. |
+----------------------------------------------------------------------+
| The Initial Developer of the Original Code is PaloSanto Solutions |
+----------------------------------------------------------------------+
$Id: index.php, Thu 02 Jan 2020 10:38:55 AM EST, nicolas@issabel.com
*/
function spl_issabel_class_autoload($sNombreClase)
{
if (!preg_match('/^\w+$/', $sNombreClase)) return;
$sNombreBase = $sNombreClase.'.class.php';
foreach (explode(':', ini_get('include_path')) as $sDirInclude) {
if (file_exists($sDirInclude.'/'.$sNombreBase)) {
require_once($sNombreBase);
return;
}
}
}
spl_autoload_register('spl_issabel_class_autoload');
// Agregar directorio libs de script a la lista de rutas a buscar para require()
ini_set('include_path', dirname($_SERVER['SCRIPT_FILENAME'])."/libs:".ini_get('include_path'));
include_once("libs/misc.lib.php");
include_once "configs/default.conf.php";
include_once "libs/paloSantoDB.class.php";
include_once "libs/paloSantoMenu.class.php";
include_once "libs/paloSantoNotification.class.php";
include_once("libs/paloSantoACL.class.php");// Don activate unless you know what you are doing. Too risky!
$pp = new IssabelFirstBoot();
load_default_timezone();
session_name("issabelSession");
session_start();
if(isset($_GET['logout']) && $_GET['logout']=='yes') {
$user = isset($_SESSION['issabel_user'])?$_SESSION['issabel_user']:"unknown";
writeLOG("audit.log", "LOGOUT $user: Web Interface logout successful. Accepted logout for $user from $_SERVER[REMOTE_ADDR].");
session_destroy();
session_name("issabelSession");
session_start();
header("Location: index.php");
exit;
}
//cargar el archivo de idioma
load_language();
$lang = get_language();
$it = new RecursiveDirectoryIterator("modules/");
foreach(new RecursiveIteratorIterator($it) as $file) {
if(preg_match("/langmenu\/$lang\.lang/ui",$file)) {
include_once "$file";
global $arrLangMenu;
global $arrLang;
$arrLang = array_merge($arrLang,$arrLangMenu);
}
}
if(file_exists("langmenus/$lang.lang")){
include_once "langmenus/$lang.lang";
global $arrLangMenu;
global $arrLang;
$arrLang = array_merge($arrLang,$arrLangMenu);
}
// cargar traducciones de modulos issabelPBX para menu
$it = new RecursiveDirectoryIterator("admin/modules/");
foreach(new RecursiveIteratorIterator($it) as $file) {
if(preg_match("/titlelang\.php$/ui",$file)) {
include_once $file;
if(isset($modTitle[$lang])) {
foreach($modTitle[$lang] as $title=>$translatedtitle) {
$arrLang[$title]=$translatedtitle;
}
}
}
}
$pdbACL = new paloDB($arrConf['issabel_dsn']['acl']);
$pACL = new paloACL($pdbACL);
if(!empty($pACL->errMsg)) {
echo "ERROR DE DB: $pACL->errMsg <br>";
}
// Load smarty
$smarty = getSmarty($arrConf['mainTheme'], $arrConf['basePath']);
$smarty->assign("ISSABEL_LICENSED", _tr("is licensed under"));
$smarty->assign("LOGIN_INCORRECT", '');
// Two Factor Authentication Check
if(isset($_POST['input_code'])) {
$sec = $pACL->getTwoFactorSecret($_SESSION['2fa_user']);
include('modules/sec_2fa/libs/TwoFactorAuth.class.php');
$tfa = new TwoFactorAuth('Issabel');
$code = $tfa->getCode($sec);
if($_POST['input_code']==$code) {
$iauth = new IssabelAuth();
list($access_token,$refresh_token) = $iauth->acquire_jwt_token($_SESSION['2fa_user'],$_SESSION['2fa_pass']);
$_SESSION['access_token'] = $access_token;
$_SESSION['refresh_token'] = $refresh_token;
$_SESSION['issabel_user'] = $_SESSION['2fa_user'];
$_SESSION['issabel_pass'] = $_SESSION['2fa_pass'];
header("Location: index.php");
$user = urlencode(substr($_SESSION['2fa_user'],0,20));
writeLOG("audit.log", "LOGIN $user: Web Interface login successful. Accepted password for $user from $_SERVER[REMOTE_ADDR] using two factor authentication.");
exit;
} else {
list ($color1,$color2) = $tfa->get_theme_colors();
$oPn = new paloSantoNavigation(array(), $smarty);
$oPn->putHEAD_JQUERY_HTML();
$sCurYear = date('Y');
if ($sCurYear < '2013') $sCurYear = '2013';
$smarty->assign("currentyear", $sCurYear);
$smarty->assign("THEMENAME", 'tenant');
$smarty->assign("WEBPATH", '');
$smarty->assign("SUBMIT", _tr('Submit'));
$smarty->assign("PAGE_NAME", _tr('Two Factor Authentication'));
$smarty->assign("WELCOME", _tr('Welcome to Issabel'));
$smarty->assign("CODE", _tr('Code'));
$smarty->assign("ISSABEL_LICENSED", _tr("is licensed under"));
$smarty->assign("LOGIN_COLOR_1", $color1);
$smarty->assign("LOGIN_COLOR_2", $color2);
$smarty->display("modules/sec_2fa/templates/default/2fa.tpl");
$user = urlencode(substr($_SESSION['2fa_user'],0,20));
writeLOG("audit.log", "LOGIN $user: Authentication Failure to Web Interface login. Failed two factore code for $user from $_SERVER[REMOTE_ADDR].");
die();
}
}
//- 1) SUBMIT. Si se hizo submit en el formulario de ingreso
//- autentico al usuario y lo ingreso a la sesion
if(isset($_POST['submit_login']) and !empty($_POST['input_user'])) {
include('modules/sec_2fa/libs/TwoFactorAuth.class.php');
$pass_md5 = md5($_POST['input_pass']);
if($pACL->authenticateUser($_POST['input_user'], $pass_md5)) {
session_regenerate_id(TRUE);
if(file_exists('modules/sec_2fa/libs/TwoFactorAuth.class.php')) {
$tfa = new TwoFactorAuth('Issabel');
$tfa_enabled = $tfa->is_licensed();
} else {
$tfa_enabled=false;
}
// two factor authentication form, if enabled for user, show it instead of login
if(method_exists($pACL,'getTwoFactorSecret') && $tfa_enabled==true) {
$sec = $pACL->getTwoFactorSecret($_POST['input_user']);
if($sec<>'') {
list ($color1,$color2) = $tfa->get_theme_colors();
$oPn = new paloSantoNavigation(array(), $smarty);
$oPn->putHEAD_JQUERY_HTML();
$_SESSION['2fa_user'] = $_POST['input_user'];
$_SESSION['2fa_pass'] = $pass_md5;
$sCurYear = date('Y');
if ($sCurYear < '2013') $sCurYear = '2013';
$smarty->assign("currentyear", $sCurYear);
$smarty->assign("THEMENAME", 'tenant');
$smarty->assign("WEBPATH", '');
$smarty->assign("SUBMIT", _tr('Submit'));
$smarty->assign("PAGE_NAME", _tr('Two Factor Authentication'));
$smarty->assign("WELCOME", _tr('Welcome to Issabel'));
$smarty->assign("CODE", _tr('Code'));
$smarty->assign("ISSABEL_LICENSED", _tr("is licensed under"));
$smarty->assign("LOGIN_COLOR_1", $color1);
$smarty->assign("LOGIN_COLOR_2", $color2);
$smarty->display("modules/sec_2fa/templates/default/2fa.tpl");
die();
}
}
$iauth = new IssabelAuth();
list($access_token,$refresh_token) = $iauth->acquire_jwt_token($_POST['input_user'],$_POST['input_pass']);
$_SESSION['access_token'] = $access_token;
$_SESSION['refresh_token'] = $refresh_token;
$_SESSION['issabel_user'] = $_POST['input_user'];
$_SESSION['issabel_pass'] = $pass_md5;
header("Location: index.php");
writeLOG("audit.log", "LOGIN $_POST[input_user]: Web Interface login successful. Accepted password for $_POST[input_user] from $_SERVER[REMOTE_ADDR].");
exit;
} else {
$user = urlencode(substr($_POST['input_user'],0,20));
if(!$pACL->getIdUser($_POST['input_user'])) {
writeLOG("audit.log", "LOGIN $user: Authentication Failure to Web Interface login. Invalid user $user from $_SERVER[REMOTE_ADDR].");
} else {
writeLOG("audit.log", "LOGIN $user: Authentication Failure to Web Interface login. Failed password for $user from $_SERVER[REMOTE_ADDR].");
}
$smarty->assign("LOGIN_INCORRECT",_tr('Incorrect username or password. Please try again.'));
}
}
// 2) Autentico usuario
if (isset($_SESSION['issabel_user']) &&
isset($_SESSION['issabel_pass']) &&
$pACL->authenticateUser($_SESSION['issabel_user'], $_SESSION['issabel_pass'])) {
$idUser = $pACL->getIdUser($_SESSION['issabel_user']);
$pMenu = new paloMenu($arrConf['issabel_dsn']['menu']);
$arrMenuFiltered = $pMenu->filterAuthorizedMenus($idUser);
if (!is_array($arrMenuFiltered)) {
die("FATAL: unable to filter module list for user: ".$pMenu->errMsg);
}
verifyTemplate_vm_email(); // para cambiar el template del email ue se envia al recibir un voicemail
//traducir el menu al idioma correspondiente
foreach($arrMenuFiltered as $idMenu=>$arrMenuItem) {
$arrMenuFiltered[$idMenu]['Name'] = _tr($arrMenuItem['Name']);
}
$smarty->assign("WEBPATH", '');
$smarty->assign("WEBCOMMON", 'libs/');
$smarty->assign("THEMENAME", $arrConf['mainTheme']);
/*agregado para register*/
$smarty->assign("Register", _tr("Register"));
$smarty->assign("lblRegisterCm", _tr("Register"));
$smarty->assign("lblRegisteredCm", _tr("Registered"));
$smarty->assign("Registered", _tr("Register"));
$smarty->assign("md_message_title", _tr('md_message_title'));
$sCurYear = date('Y');
if ($sCurYear < '2013') $sCurYear = '2013';
$smarty->assign("currentyear", $sCurYear);
$smarty->assign("LOGOUT", _tr('Logout'));
$smarty->assign("VersionDetails", _tr('VersionDetails'));
$smarty->assign("VersionPackage", _tr('VersionPackage'));
$smarty->assign("AMOUNT_CHARACTERS", _tr("characters left"));
$smarty->assign("SAVE_NOTE", _tr("Save Note"));
$smarty->assign("MSG_SAVE_NOTE", _tr("Saving Note"));
$smarty->assign("MSG_GET_NOTE", _tr("Loading Note"));
$smarty->assign("LBL_NO_STICKY", _tr("Click here to leave a note."));
$smarty->assign("ABOUT_ISSABEL", _tr('About Issabel')." ".$arrConf['issabel_version']);
// notifications
$pNot = new paloNotification($pdbACL);
$notis = $pNot->listPublicNotifications();
if(count($notis)>0) {
$smarty->assign("ANIMATE_NOTIFICATION", "faa-shake animated");
} else {
$smarty->assign("ANIMATE_NOTIFICATION", "");
}
$selectedMenu = getParameter('menu');
// Ejecutar una petición a un módulo global del framework
if (!is_null($selectedMenu) && isset($arrConf['elx_framework_globalmodules']) &&
in_array($selectedMenu, $arrConf['elx_framework_globalmodules']) &&
file_exists("modules/$selectedMenu/index.php")) {
require_once "modules/$selectedMenu/index.php";
echo _moduleContent($smarty, $selectedMenu);
return;
}
/* El módulo pbxadmin que integra a IssabelPBX no construye enlaces con
* parámetros menu, ni con config.php en todos los casos. Por lo tanto, los
* usos sucesivos de enlaces en IssabelPBX embebido requiren recordar que se
* sirven a través de pbxadmin. */
if (empty($selectedMenu) && !empty($_SESSION['menu']))
$selectedMenu = $_SESSION['menu'];
// Inicializa el objeto palosanto navigation
$oPn = new paloSantoNavigation($arrMenuFiltered, $smarty, $selectedMenu);
$selectedMenu = $oPn->getSelectedModule();
$_SESSION['menu'] = $selectedMenu;
// Guardar historial de la navegación
// TODO: también para rawmode=yes ?
putMenuAsHistory($pdbACL, $pACL, $idUser, $selectedMenu);
// Obtener contenido del módulo, si usuario está autorizado a él
$bModuleAuthorized = $pACL->isUserAuthorizedById($idUser, "access", $selectedMenu);
$sModuleContent = ($bModuleAuthorized) ? $oPn->showContent() : '';
// rawmode es un modo de operacion que pasa directamente a la pantalla la salida
// del modulo. Esto es util en ciertos casos.
$rawmode = getParameter("rawmode");
if(isset($rawmode) && $rawmode=='yes') {
echo $sModuleContent;
} else {
$oPn->renderMenuTemplates();
// Generar contenido principal de todos los paneles
$panels = array();
foreach (scandir("panels/") as $panelname) {
if ($panelname != '.' && $panelname != '..' &&
is_dir("panels/$panelname") &&
file_exists("panels/$panelname/index.php")) {
if (file_exists("panels/$panelname/lang/en.lang"))
load_language_module("../panels/$panelname");
require_once "panels/$panelname/index.php";
// No hay soporte de namespace en PHP 5.1, se simula con una clase
$classname = 'Panel_'.ucfirst($panelname);
if (class_exists($classname) && method_exists($classname, 'templateContent')) {
$tc = call_user_func(array($classname, 'templateContent'),
$smarty, $panelname);
if (is_array($tc) && isset($tc['content'])) {
$panels[$panelname] = $tc;
}
}
}
}
$smarty->assign(array(
'LBL_ISSABEL_PANELS_SIDEBAR' => _tr('Panels'),
'ISSABEL_PANELS' => $panels,
));
if (file_exists('themes/'.$arrConf['mainTheme'].'/themesetup.php')) {
require_once('themes/'.$arrConf['mainTheme'].'/themesetup.php');
themeSetup($smarty, $selectedMenu, $pdbACL, $pACL, $idUser);
if(strpos($_SERVER[REQUEST_URI], 'agent_console') == true || strpos($_SERVER[REQUEST_URI], 'myex_config') == true)
{
$webPhoneExtension = $pACL->getUserExtension($_SESSION['issabel_user']);
$dsn1 = generarDSNSistema('asteriskuser', 'asterisk');
$pdbACL1 = new paloDB($dsn1);
$webPhonePassword = $pdbACL1->fetchTable("SELECT data from sip WHERE id = '$webPhoneExtension' AND keyword = 'secret';")[0];
if($webPhoneExtension>0){
echo '<script type="text/javascript">';
echo "localStorage.setItem('mhrgl.com.identity.display_name', $webPhoneExtension);";
echo "localStorage.setItem('mhrgl.com.identity.impi', $webPhoneExtension);";
echo "localStorage.setItem('mhrgl.com.identity.impu', 'sip:'+ $webPhoneExtension+'@'+ window.location.hostname);";
echo "localStorage.setItem('mhrgl.com.identity.password', $webPhonePassword[0]);";
echo "localStorage.setItem('mhrgl.com.identity.realm', window.location.hostname);";
echo "localStorage.setItem('mhrgl.com.expert.disable_video', 'true');";
echo "localStorage.setItem('mhrgl.com.expert.disable_callbtn_options', 'true');";
echo "localStorage.setItem('mhrgl.com.expert.websocket_server_url', 'wss://' + window.location.hostname + ':8089/ws');";
//echo "localStorage.setItem('mhrgl.com.expert.ice_servers', '[]');";
//echo "localStorage.setItem('mhrgl.com.expert.ice_servers', '[{ url: \'turn:' + window.location.hostname + '\', username:\'turn1\', credential:\'turn1\',}]');";
//echo "localStorage.setItem('mhrgl.com.expert.ice_servers', '[{ url: \'stun:' + window.location.hostname + ':3478\'}]');";
//echo "localStorage.setItem('mhrgl.com.expert.ice_servers', '[{ url: \'stun:' + window.location.hostname + '\' }, { url:\'turn:' + window.location.hostname + '\', username:\'turn1\', credential:\'turn1\', credentialType:\'password\' }]');";
echo "localStorage.setItem('mhrgl.com.expert.ice_servers', '[{ url: \'stun:stun.a.google.com:19302\'}]');";
//echo "localStorage.setItem('mhrgl.com.expert.ice_servers', '[{ url:\'turn:' + window.location.hostname + '\', username:\'turn1\', credential:\'turn1\', credentialType:\'password\' }]');";
echo "</script>";
include("webphone/webphone.php");
}
}
}
// La muestra de stickynote está ahora habilitada para todos los temas.
// Se obtiene si ese menu tiene una nota agregada.
$snvars = array('AUTO_POPUP' => 0, 'STATUS_STICKY_NOTE' => 'false');
$statusStickyNote = getStickyNote($pdbACL, $idUser, $selectedMenu);
if ($statusStickyNote['status'] && $statusStickyNote['data'] != "") {
$snvars['STATUS_STICKY_NOTE'] = 'true';
if ($statusStickyNote['popup'] == 1) $snvars['AUTO_POPUP'] = 1;
}
$smarty->assign($snvars);
// Autorizacion
if ($bModuleAuthorized) {
$smarty->assign("CONTENT", $sModuleContent);
$smarty->assign('MENU', (count($arrMenuFiltered) > 0)
? $smarty->fetch("_common/_menu.tpl")
: _tr('No modules'));
}
$smarty->display("_common/index.tpl");
}
} else {
$rawmode = getParameter("rawmode");
if(isset($rawmode) && $rawmode=='yes'){
include_once "libs/paloSantoJSON.class.php";
$jsonObject = new PaloSantoJSON();
$jsonObject->set_status("ERROR_SESSION");
$jsonObject->set_error(_tr("Your session has expired. If you want to do a login please press the button 'Accept'."));
$jsonObject->set_message(null);
Header('Content-Type: application/json');
echo $jsonObject->createJSON();
}
else{
$oPn = new paloSantoNavigation(array(), $smarty);
$oPn->putHEAD_JQUERY_HTML();
$smarty->assign("THEMENAME", $arrConf['mainTheme']);
$smarty->assign("currentyear",date("Y"));
$smarty->assign("PAGE_NAME", _tr('Login page'));
$smarty->assign("WELCOME", _tr('Welcome to Issabel'));
$smarty->assign("ENTER_USER_PASSWORD", _tr('Please enter your username and password'));
$smarty->assign("USERNAME", _tr('Username'));
$smarty->assign("PASSWORD", _tr('Password'));
$smarty->assign("SUBMIT", _tr('Submit'));
$smarty->display("_common/login.tpl");
}
}
?>