PageRenderTime 49ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/web/system/SecurityCenterModule/Controller/AdminController.php

https://github.com/antoniom/core
PHP | 966 lines | 888 code | 25 blank | 53 comment | 14 complexity | 8e29aaf4c55fdff7a2cd39924a0fce5e MD5 | raw file
Possible License(s): GPL-3.0, LGPL-3.0, MIT
  1. <?php
  2. /**
  3. * Copyright Zikula Foundation 2009 - Zikula Application Framework
  4. *
  5. * This work is contributed to the Zikula Foundation under one or more
  6. * Contributor Agreements and licensed to You under the following license:
  7. *
  8. * @license GNU/LGPLv3 (or at your option, any later version).
  9. * @package Zikula
  10. *
  11. * Please see the NOTICE file distributed with this source code for further
  12. * information regarding copyright and licensing.
  13. */
  14. namespace SecurityCenterModule\Controller;
  15. use Zikula_View, LogUtil, SecurityUtil, ModUtil, System, CacheUtil;
  16. use DataUtil, DateUtil, UserUtil;
  17. use SecurityCenterModule\Util as SecurityCenterUtil;
  18. use Zikula\Core\Core;
  19. /**
  20. * SecurityCenter_Controller_Admin class.
  21. */
  22. class AdminController extends \Zikula\Framework\Controller\AbstractController
  23. {
  24. /**
  25. * Post initialise.
  26. *
  27. * @return void
  28. */
  29. protected function postInitialize()
  30. {
  31. // In this controller we do not want caching.
  32. $this->view->setCaching(Zikula_View::CACHE_DISABLED);
  33. }
  34. /**
  35. * The main administration function.
  36. *
  37. * This function is the default function, and is called whenever the
  38. * module is initiated without defining arguments. As such it can
  39. * be used for a number of things, but most commonly it either just
  40. * shows the module menu and returns or calls whatever the module
  41. * designer feels should be the default function (often this is the
  42. * view() function).
  43. *
  44. * @return string HTML string.
  45. */
  46. public function indexAction()
  47. {
  48. // Security check will be done in modifyconfig()
  49. return $this->redirect(ModUtil::url('SecurityCenter', 'admin', 'modifyconfig'));
  50. }
  51. /**
  52. * This is a standard function to modify the configuration parameters of the module.
  53. *
  54. * @return string HTML string.
  55. */
  56. public function modifyconfigAction()
  57. {
  58. // Security check
  59. if (!SecurityUtil::checkPermission('SecurityCenter::', '::', ACCESS_ADMIN)) {
  60. throw new \Zikula\Framework\Exception\ForbiddenException();
  61. }
  62. $this->view->assign('itemsperpage', $this->getVar('itemsperpage'));
  63. $this->view->assign('idshtmlfields', implode(PHP_EOL, System::getVar('idshtmlfields')));
  64. $this->view->assign('idsjsonfields', implode(PHP_EOL, System::getVar('idsjsonfields')));
  65. $this->view->assign('idsexceptions', implode(PHP_EOL, System::getVar('idsexceptions')));
  66. // Return the output that has been generated by this function
  67. return $this->response($this->view->fetch('Admin/modifyconfig.tpl'));
  68. }
  69. /**
  70. * This is a standard function to update the configuration parameters of the
  71. * module given the information passed back by the modification form
  72. * @see Admin/modifyconfig()
  73. *
  74. * @return bool true if successful, false otherwise.
  75. */
  76. public function updateconfigAction()
  77. {
  78. $this->checkCsrfToken();
  79. // Security check
  80. if (!SecurityUtil::checkPermission('SecurityCenter::', '::', ACCESS_ADMIN)) {
  81. throw new \Zikula\Framework\Exception\ForbiddenException();
  82. }
  83. $validates = true;
  84. // Update module variables.
  85. $updatecheck = (int)$this->request->request->get('updatecheck', 0);
  86. System::setVar('updatecheck', $updatecheck);
  87. // if update checks are disabled, reset values to force new update check if re-enabled
  88. if ($updatecheck == 0) {
  89. System::setVar('updateversion', Core::VERSION_NUM);
  90. System::setVar('updatelastchecked', 0);
  91. }
  92. $updatefrequency = (int)$this->request->request->get('updatefrequency', 30);
  93. System::setVar('updatefrequency', $updatefrequency);
  94. $keyexpiry = (int)$this->request->request->get('keyexpiry', 0);
  95. if ($keyexpiry < 0 || $keyexpiry > 3600) {
  96. $keyexpiry = 0;
  97. }
  98. System::setVar('keyexpiry', $keyexpiry);
  99. $sessionauthkeyua = (int)$this->request->request->get('sessionauthkeyua', 0);
  100. System::setVar('sessionauthkeyua', $sessionauthkeyua);
  101. $secure_domain = $this->request->request->get('secure_domain', '');
  102. System::setVar('secure_domain', $secure_domain);
  103. $signcookies = (int)$this->request->request->get('signcookies', 1);
  104. System::setVar('signcookies', $signcookies);
  105. $signingkey = $this->request->request->get('signingkey', '');
  106. System::setVar('signingkey', $signingkey);
  107. $seclevel = $this->request->request->get('seclevel', 'High');
  108. System::setVar('seclevel', $seclevel);
  109. $secmeddays = (int)$this->request->request->get('secmeddays', 7);
  110. if ($secmeddays < 1 || $secmeddays > 365) {
  111. $secmeddays = 7;
  112. }
  113. System::setVar('secmeddays', $secmeddays);
  114. $secinactivemins = (int)$this->request->request->get('secinactivemins', 20);
  115. if ($secinactivemins < 1 || $secinactivemins > 1440) {
  116. $secinactivemins = 7;
  117. }
  118. System::setVar('secinactivemins', $secinactivemins);
  119. $sessionstoretofile = (int)$this->request->request->get('sessionstoretofile', 0);
  120. $sessionsavepath = $this->request->request->get('sessionsavepath', '');
  121. // check session path config is writable (if method is being changed to session file storage)
  122. $cause_logout = false;
  123. $storeTypeCanBeWritten = true;
  124. if ($sessionstoretofile == 1 && !empty($sessionsavepath)) {
  125. // fix path on windows systems
  126. $sessionsavepath = str_replace('\\', '/', $sessionsavepath);
  127. // sanitize the path
  128. $sessionsavepath = trim(stripslashes($sessionsavepath));
  129. // check if sessionsavepath is a dir and if it is writable
  130. // if yes, we need to logout
  131. $cause_logout = (is_dir($sessionsavepath)) ? is_writable($sessionsavepath) : false;
  132. if ($cause_logout == false) {
  133. // an error occured - we do not change the way of storing session data
  134. LogUtil::registerStatus($this->__('Error! Session path not writeable!'));
  135. $storeTypeCanBeWritten = false;
  136. }
  137. }
  138. if ($storeTypeCanBeWritten == true) {
  139. System::setVar('sessionstoretofile', $sessionstoretofile);
  140. System::setVar('sessionsavepath', $sessionsavepath);
  141. }
  142. if ((bool)$sessionstoretofile != (bool)System::getVar('sessionstoretofile')) {
  143. // logout if going from one storage to another one
  144. $cause_logout = true;
  145. }
  146. $gc_probability = (int)$this->request->request->get('gc_probability', 100);
  147. if ($gc_probability < 1 || $gc_probability > 10000) {
  148. $gc_probability = 7;
  149. }
  150. System::setVar('gc_probability', $gc_probability);
  151. $anonymoussessions = (int)$this->request->request->get('anonymoussessions', 1);
  152. System::setVar('anonymoussessions', $anonymoussessions);
  153. $sessionrandregenerate = (int)$this->request->request->get('sessionrandregenerate', 1);
  154. System::setVar('sessionrandregenerate', $sessionrandregenerate);
  155. $sessionregenerate = (int)$this->request->request->get('sessionregenerate', 1);
  156. System::setVar('sessionregenerate', $sessionregenerate);
  157. $sessionregeneratefreq = (int)$this->request->request->get('sessionregeneratefreq', 10);
  158. if ($sessionregeneratefreq < 1 || $sessionregeneratefreq > 100) {
  159. $sessionregeneratefreq = 10;
  160. }
  161. System::setVar('sessionregeneratefreq', $sessionregeneratefreq);
  162. $sessionipcheck = (int)$this->request->request->get('sessionipcheck', 0);
  163. System::setVar('sessionipcheck', $sessionipcheck);
  164. $sessionname = $this->request->request->get('sessionname', 'ZSID');
  165. if (strlen($sessionname) < 3) {
  166. $sessionname = 'ZSID';
  167. }
  168. $sessioncsrftokenonetime = (int)$this->request->request->get('sessioncsrftokenonetime', 0);
  169. System::setVar('sessioncsrftokenonetime', $sessioncsrftokenonetime);
  170. // cause logout if we changed session name
  171. if ($sessionname != System::getVar('sessionname')) {
  172. $cause_logout = true;
  173. }
  174. System::setVar('sessionname', $sessionname);
  175. System::setVar('sessionstoretofile', $sessionstoretofile);
  176. $outputfilter = $this->request->request->get('outputfilter', 0);
  177. System::setVar('outputfilter', $outputfilter);
  178. $useids = (bool)$this->request->request->get('useids', 0);
  179. System::setVar('useids', $useids);
  180. // create tmp directory for PHPIDS
  181. if ($useids == 1) {
  182. $idsTmpDir = CacheUtil::getLocalDir() . '/idsTmp';
  183. if (!file_exists($idsTmpDir)) {
  184. CacheUtil::clearLocalDir('idsTmp');
  185. }
  186. }
  187. $idssoftblock = (bool)$this->request->request->get('idssoftblock', 1);
  188. System::setVar('idssoftblock', $idssoftblock);
  189. $idsmail = (bool)$this->request->request->get('idsmail', 1);
  190. System::setVar('idsmail', $idsmail);
  191. $idsfilter = $this->request->request->get('idsfilter', 'xml');
  192. System::setVar('idsfilter', $idsfilter);
  193. $idsrulepath = $this->request->request->get('idsrulepath', 'config/zikula_default.xml');
  194. $idsrulepath = DataUtil::formatForOS($idsrulepath);
  195. if (is_readable($idsrulepath)) {
  196. System::setVar('idsrulepath', $idsrulepath);
  197. } else {
  198. LogUtil::registerError($this->__f('Error! PHPIDS rule file %s does not exist or is not readable.', $idsrulepath));
  199. $validates = false;
  200. }
  201. $idsimpactthresholdone = (int)$this->request->request->get('idsimpactthresholdone', 1);
  202. System::setVar('idsimpactthresholdone', $idsimpactthresholdone);
  203. $idsimpactthresholdtwo = (int)$this->request->request->get('idsimpactthresholdtwo', 10);
  204. System::setVar('idsimpactthresholdtwo', $idsimpactthresholdtwo);
  205. $idsimpactthresholdthree = (int)$this->request->request->get('idsimpactthresholdthree', 25);
  206. System::setVar('idsimpactthresholdthree', $idsimpactthresholdthree);
  207. $idsimpactthresholdfour = (int)$this->request->request->get('idsimpactthresholdfour', 75);
  208. System::setVar('idsimpactthresholdfour', $idsimpactthresholdfour);
  209. $idsimpactmode = (int)$this->request->request->get('idsimpactmode', 1);
  210. System::setVar('idsimpactmode', $idsimpactmode);
  211. $idshtmlfields = $this->request->request->get('idshtmlfields', '');
  212. $idshtmlfields = explode(PHP_EOL, $idshtmlfields);
  213. $idshtmlarray = array();
  214. foreach ($idshtmlfields as $idshtmlfield) {
  215. $idshtmlfield = trim($idshtmlfield);
  216. if (!empty($idshtmlfield)) {
  217. $idshtmlarray[] = $idshtmlfield;
  218. }
  219. }
  220. System::setVar('idshtmlfields', $idshtmlarray);
  221. $idsjsonfields = $this->request->request->get('idsjsonfields', '');
  222. $idsjsonfields = explode(PHP_EOL, $idsjsonfields);
  223. $idsjsonarray = array();
  224. foreach ($idsjsonfields as $idsjsonfield) {
  225. $idsjsonfield = trim($idsjsonfield);
  226. if (!empty($idsjsonfield)) {
  227. $idsjsonarray[] = $idsjsonfield;
  228. }
  229. }
  230. System::setVar('idsjsonfields', $idsjsonarray);
  231. $idsexceptions = $this->request->request->get('idsexceptions', '');
  232. $idsexceptions = explode(PHP_EOL, $idsexceptions);
  233. $idsexceptarray = array();
  234. foreach ($idsexceptions as $idsexception) {
  235. $idsexception = trim($idsexception);
  236. if (!empty($idsexception)) {
  237. $idsexceptarray[] = $idsexception;
  238. }
  239. }
  240. System::setVar('idsexceptions', $idsexceptarray);
  241. // clear all cache and compile directories
  242. ModUtil::apiFunc('SettingsModule', 'admin', 'clearallcompiledcaches');
  243. // the module configuration has been updated successfuly
  244. if ($validates) {
  245. $this->registerStatus($this->__('Done! Saved module configuration.'));
  246. }
  247. // we need to auto logout the user if they changed from DB to FILE
  248. if ($cause_logout == true) {
  249. UserUtil::logout();
  250. $this->registerStatus($this->__('Session handling variables have changed. You must log in again.'));
  251. $returnPage = urlencode(ModUtil::url('SecurityCenter', 'admin', 'modifyconfig'));
  252. return $this->redirect(ModUtil::url('Users', 'user', 'login', array('returnpage' => $returnPage)));
  253. }
  254. // This function generated no output, and so now it is complete we redirect
  255. // the user to an appropriate page for them to carry on their work
  256. return $this->redirect(ModUtil::url('SecurityCenter', 'admin', 'modifyconfig'));
  257. }
  258. /**
  259. * HTMLPurifier configuration.
  260. *
  261. * @return void
  262. */
  263. public function purifierconfigAction()
  264. {
  265. // Security check
  266. if (!SecurityUtil::checkPermission('SecurityCenter::', '::', ACCESS_ADMIN)) {
  267. throw new \Zikula\Framework\Exception\ForbiddenException();
  268. }
  269. $reset = (bool)($this->request->get('reset', null) == 'default');
  270. $this->view->assign('itemsperpage', $this->getVar('itemsperpage'));
  271. if ($reset) {
  272. $purifierconfig = SecurityCenterUtil::getPurifierConfig(true);
  273. LogUtil::registerStatus($this->__('Default values for HTML Purifier were successfully loaded. Please store them using the "Save" button at the bottom of this page'));
  274. } else {
  275. $purifierconfig = SecurityCenterUtil::getPurifierConfig(false);
  276. }
  277. $purifier = new \HTMLPurifier($purifierconfig);
  278. $config = $purifier->config;
  279. if (is_array($config) && isset($config[0])) {
  280. $config = $config[1];
  281. }
  282. $allowed = \HTMLPurifier_Config::getAllowedDirectivesForForm(true, $config->def);
  283. // list of excluded directives, format is $namespace_$directive
  284. $excluded = array('Cache_SerializerPath');
  285. $purifierAllowed = array();
  286. foreach ($allowed as $allowedDirective) {
  287. list($namespace, $directive) = $allowedDirective;
  288. if (in_array($namespace . '_' . $directive, $excluded)) {
  289. continue;
  290. }
  291. if ($namespace == 'Filter') {
  292. if (
  293. // Do not allow Filter.Custom for now. Causing errors.
  294. // TODO research why Filter.Custom is causing exceptions and correct.
  295. ($directive == 'Custom')
  296. // Do not allow Filter.ExtractStyleBlock* for now. Causing errors.
  297. // TODO Filter.ExtractStyleBlock* requires CSSTidy
  298. || (stripos($directive, 'ExtractStyleBlock') !== false)
  299. ) {
  300. continue;
  301. }
  302. }
  303. $directiveRec = array();
  304. $directiveRec['key'] = $namespace . '.' . $directive;
  305. $def = $config->def->info[$directiveRec['key']];
  306. $directiveRec['value'] = $config->get($directiveRec['key']);
  307. if (is_int($def)) {
  308. $directiveRec['allowNull'] = ($def < 0);
  309. $directiveRec['type'] = abs($def);
  310. } else {
  311. $directiveRec['allowNull'] = (isset($def->allow_null) && $def->allow_null);
  312. $directiveRec['type'] = (isset($def->type) ? $def->type : 0);
  313. if (isset($def->allowed)) {
  314. $directiveRec['allowedValues'] = array();
  315. foreach ($def->allowed as $val => $b) {
  316. $directiveRec['allowedValues'][] = $val;
  317. }
  318. }
  319. }
  320. if (is_array($directiveRec['value'])) {
  321. switch ($directiveRec['type']) {
  322. case \HTMLPurifier_VarParser::LOOKUP:
  323. $value = array();
  324. foreach ($directiveRec['value'] as $val => $b) {
  325. $value[] = $val;
  326. }
  327. $directiveRec['value'] = implode(PHP_EOL, $value);
  328. break;
  329. case \HTMLPurifier_VarParser::ALIST:
  330. $directiveRec['value'] = implode(PHP_EOL, $value);
  331. break;
  332. case \HTMLPurifier_VarParser::HASH:
  333. $value = '';
  334. foreach ($directiveRec['value'] as $i => $v) {
  335. $value .= "{$i}:{$v}" . PHP_EOL;
  336. }
  337. $directiveRec['value'] = $value;
  338. break;
  339. default:
  340. $directiveRec['value'] = '';
  341. }
  342. }
  343. // Editing for only these types is supported
  344. $directiveRec['supported'] = (($directiveRec['type'] == \HTMLPurifier_VarParser::STRING)
  345. || ($directiveRec['type'] == \HTMLPurifier_VarParser::ISTRING)
  346. || ($directiveRec['type'] == \HTMLPurifier_VarParser::TEXT)
  347. || ($directiveRec['type'] == \HTMLPurifier_VarParser::ITEXT)
  348. || ($directiveRec['type'] == \HTMLPurifier_VarParser::INT)
  349. || ($directiveRec['type'] == \HTMLPurifier_VarParser::FLOAT)
  350. || ($directiveRec['type'] == \HTMLPurifier_VarParser::BOOL)
  351. || ($directiveRec['type'] == \HTMLPurifier_VarParser::LOOKUP)
  352. || ($directiveRec['type'] == \HTMLPurifier_VarParser::ALIST)
  353. || ($directiveRec['type'] == \HTMLPurifier_VarParser::HASH));
  354. $purifierAllowed[$namespace][$directive] = $directiveRec;
  355. }
  356. $this->view->assign('purifier', $purifier)
  357. ->assign('purifierTypes', \HTMLPurifier_VarParser::$types)
  358. ->assign('purifierAllowed', $purifierAllowed);
  359. // Return the output that has been generated by this function
  360. return $this->response($this->view->fetch('Admin/purifierconfig.tpl'));
  361. }
  362. /**
  363. * Update HTMLPurifier configuration.
  364. *
  365. * @return void
  366. */
  367. public function updatepurifierconfigAction()
  368. {
  369. $this->checkCsrfToken();
  370. // Security check
  371. if (!SecurityUtil::checkPermission('SecurityCenter::', '::', ACCESS_ADMIN)) {
  372. throw new \Zikula\Framework\Exception\ForbiddenException();
  373. }
  374. // Load HTMLPurifier Classes
  375. $purifier = SecurityCenterUtil::getpurifier();
  376. // Update module variables.
  377. $config = $this->request->request->get('purifierConfig', null);
  378. $config = \HTMLPurifier_Config::prepareArrayFromForm($config, false, true, true, $purifier->config->def);
  379. //echo "\r\n\r\n<pre>" . print_r($config, true) . "</pre>\r\n\r\n";
  380. $allowed = \HTMLPurifier_Config::getAllowedDirectivesForForm(true, $purifier->config->def);
  381. foreach ($allowed as $allowedDirective) {
  382. list($namespace, $directive) = $allowedDirective;
  383. $directiveKey = $namespace . '.' . $directive;
  384. $def = $purifier->config->def->info[$directiveKey];
  385. if (isset($config[$namespace])
  386. && array_key_exists($directive, $config[$namespace])
  387. && is_null($config[$namespace][$directive])) {
  388. unset($config[$namespace][$directive]);
  389. if (count($config[$namespace]) <= 0) {
  390. unset($config[$namespace]);
  391. }
  392. }
  393. if (isset($config[$namespace]) && isset($config[$namespace][$directive])) {
  394. if (is_int($def)) {
  395. $directiveType = abs($def);
  396. } else {
  397. $directiveType = (isset($def->type) ? $def->type : 0);
  398. }
  399. switch ($directiveType) {
  400. case \HTMLPurifier_VarParser::LOOKUP:
  401. $value = explode(PHP_EOL, $config[$namespace][$directive]);
  402. $config[$namespace][$directive] = array();
  403. foreach ($value as $val) {
  404. $val = trim($val);
  405. if (!empty($val)) {
  406. $config[$namespace][$directive][$val] = true;
  407. }
  408. }
  409. if (empty($config[$namespace][$directive])) {
  410. unset($config[$namespace][$directive]);
  411. }
  412. break;
  413. case \HTMLPurifier_VarParser::ALIST:
  414. $value = explode(PHP_EOL, $config[$namespace][$directive]);
  415. $config[$namespace][$directive] = array();
  416. foreach ($value as $val) {
  417. $val = trim($val);
  418. if (!empty($val)) {
  419. $config[$namespace][$directive][] = $val;
  420. }
  421. }
  422. if (empty($config[$namespace][$directive])) {
  423. unset($config[$namespace][$directive]);
  424. }
  425. break;
  426. case \HTMLPurifier_VarParser::HASH:
  427. $value = explode(PHP_EOL, $config[$namespace][$directive]);
  428. $config[$namespace][$directive] = array();
  429. foreach ($value as $val) {
  430. list($i, $v) = explode(':', $val);
  431. $i = trim($i);
  432. $v = trim($v);
  433. if (!empty($i) && !empty($v)) {
  434. $config[$namespace][$directive][$i] = $v;
  435. }
  436. }
  437. if (empty($config[$namespace][$directive])) {
  438. unset($config[$namespace][$directive]);
  439. }
  440. break;
  441. }
  442. }
  443. if (isset($config[$namespace])
  444. && array_key_exists($directive, $config[$namespace])
  445. && is_null($config[$namespace][$directive])) {
  446. unset($config[$namespace][$directive]);
  447. if (count($config[$namespace]) <= 0) {
  448. unset($config[$namespace]);
  449. }
  450. }
  451. }
  452. //echo "\r\n\r\n<pre>" . print_r($config, true) . "</pre>\r\n\r\n"; exit;
  453. $this->setVar('htmlpurifierConfig', serialize($config));
  454. $purifier = SecurityCenterUtil::getpurifier(true);
  455. // clear all cache and compile directories
  456. ModUtil::apiFunc('SettingsModule', 'admin', 'clearallcompiledcaches');
  457. // the module configuration has been updated successfuly
  458. LogUtil::registerStatus($this->__('Done! Saved HTMLPurifier configuration.'));
  459. // This function generated no output, and so now it is complete we redirect
  460. // the user to an appropriate page for them to carry on their work
  461. return $this->redirect(ModUtil::url('SecurityCenter', 'admin', 'modifyconfig'));
  462. }
  463. /**
  464. * Function to view ids log events.
  465. *
  466. * @return string HTML output string.
  467. */
  468. public function viewidslogAction()
  469. {
  470. // Security check
  471. if (!SecurityUtil::checkPermission('SecurityCenter::', '::', ACCESS_EDIT)) {
  472. throw new \Zikula\Framework\Exception\ForbiddenException();
  473. }
  474. // sorting
  475. $sort = $this->request->get('sort', 'date DESC');
  476. $sort_exp = explode(" ", $sort);
  477. $sorting = array($sort_exp[0] => (isset($sort_exp[1]) ? $sort_exp[1] : 'ASC'));
  478. // filtering
  479. $filterdefault = array(
  480. 'uid' => 0,
  481. 'name' => null,
  482. 'tag' => null,
  483. 'value' => null,
  484. 'page' => null,
  485. 'ip' => null,
  486. 'impact' => null
  487. );
  488. $filter = $this->request->get('filter', $filterdefault);
  489. $where = array();
  490. foreach ($filter as $flt_key => $flt_value) {
  491. if (isset($flt_value) && !empty($flt_value)) {
  492. $where[$flt_key] = $flt_value;
  493. }
  494. }
  495. // offset
  496. $startnum = (int)$this->request->get('startnum', 0);
  497. // number of items to show
  498. $pagesize = (int)$this->getVar('pagesize', 25);
  499. // get data
  500. $item_params = array(
  501. 'where' => $where,
  502. 'sorting' => $sorting,
  503. 'limit' => $pagesize,
  504. 'offset' => $startnum
  505. );
  506. $items = ModUtil::apiFunc('SecurityCenterModule', 'admin', 'getAllIntrusions', $item_params);
  507. $data = array();
  508. foreach ($items as $item) {
  509. $dta = $item->toArray();
  510. $dta['username'] = $dta['user']['uname'];
  511. $dta['filters'] = unserialize($dta['filters']);
  512. unset($dta['user']);
  513. $data[] = $dta;
  514. }
  515. // Create output object
  516. $this->view->assign('filter', $filter)
  517. ->assign('sort', $sort)
  518. ->assign('objectArray', $data);
  519. // Assign the values for the smarty plugin to produce a pager.
  520. $pager = array();
  521. $pager['numitems'] = ModUtil::apiFunc('SecurityCenterModule', 'admin', 'countAllIntrusions', $item_params);
  522. $pager['itemsperpage'] = $pagesize;
  523. $this->view->assign('startnum', $startnum)
  524. ->assign('pager', $pager);
  525. $csrftoken = SecurityUtil::generateCsrfToken($this->container, true);
  526. $this->view->assign('csrftoken', $csrftoken);
  527. // fetch output from template
  528. return $this->response($this->view->fetch('Admin/viewidslog.tpl'));
  529. }
  530. /**
  531. * Export ids log.
  532. *
  533. * @return string
  534. */
  535. public function exportidslogAction()
  536. {
  537. // Security check
  538. if (!SecurityUtil::checkPermission('SecurityCenter::', '::', ACCESS_EDIT)) {
  539. throw new \Zikula\Framework\Exception\ForbiddenException();
  540. }
  541. // get input values
  542. $confirmed = (int)$this->request->request->get('confirmed', (isset($args['confirmed']) ? $args['confirmed'] : 0));
  543. if ($confirmed == 1) {
  544. // export the titles ?
  545. $exportTitles = $this->request->request->get('exportTitles', (isset($args['exportTitles']) ? $args['exportTitles'] : null));
  546. $exportTitles = (!isset($exportTitles) || $exportTitles !== '1') ? false : true;
  547. // name of the exported file
  548. $exportFile = $this->request->request->get('exportFile', (isset($args['exportFile']) ? $args['exportFile'] : null));
  549. if (!isset($exportFile) || $exportFile == '') {
  550. $exportFile = 'idslog.csv';
  551. }
  552. if (!strrpos($exportFile, '.csv')) {
  553. $exportFile .= '.csv';
  554. }
  555. // delimeter
  556. $delimiter = $this->request->request->get('delimiter', (isset($args['delimiter']) ? $args['delimiter'] : null));
  557. if (!isset($delimiter) || $delimiter == '') {
  558. $delimiter = 1;
  559. }
  560. switch ($delimiter) {
  561. case 1:
  562. $delimiter = ",";
  563. break;
  564. case 2:
  565. $delimiter = ";";
  566. break;
  567. case 3:
  568. $delimiter = ":";
  569. break;
  570. case 4:
  571. $delimiter = chr(9);
  572. }
  573. // titles
  574. if ($exportTitles == 1) {
  575. $titles = array(
  576. $this->__('Name'),
  577. $this->__('Tag'),
  578. $this->__('Value'),
  579. $this->__('Page'),
  580. $this->__('User Name'),
  581. $this->__('IP'),
  582. $this->__('Impact'),
  583. $this->__('PHPIDS filters used'),
  584. $this->__('Date')
  585. );
  586. } else {
  587. $titles = array();
  588. }
  589. // get data
  590. $item_params = array(
  591. 'sorting' => array('date' => 'DESC')
  592. );
  593. $items = ModUtil::apiFunc('SecurityCenterModule', 'admin', 'getAllIntrusions', $item_params);
  594. $objData = array();
  595. foreach ($items as $item) {
  596. $dta = $item->toArray();
  597. $dta['username'] = $dta['user']['uname'];
  598. $dta['filters'] = unserialize($dta['filters']);
  599. $dta['date'] = $dta['date']->format('Y-m-d H:i:s');
  600. unset($dta['user']);
  601. $objData[] = $dta;
  602. }
  603. $data = array();
  604. $find = array("\r\n", "\n");
  605. $replace = array("", "");
  606. foreach ($objData as $key => $idsdata) {
  607. $filtersused = '';
  608. foreach ($objData[$key]['filters'] as $filter) {
  609. $filtersused .= $filter['id'] . " ";
  610. }
  611. $datarow = array(
  612. $objData[$key]['name'],
  613. $objData[$key]['tag'],
  614. htmlspecialchars(str_replace($find, $replace, $objData[$key]['value']), ENT_COMPAT, 'UTF-8', false),
  615. htmlspecialchars($objData[$key]['page'], ENT_COMPAT, 'UTF-8', false),
  616. $objData[$key]['username'],
  617. $objData[$key]['ip'],
  618. $objData[$key]['impact'],
  619. $filtersused,
  620. $objData[$key]['date']
  621. );
  622. array_push($data, $datarow);
  623. }
  624. // export the csv file
  625. \FileUtil::exportCSV($data, $titles, $delimiter, '"', $exportFile);
  626. }
  627. // fetch output from template
  628. return $this->response($this->view->fetch('Admin/exportidslog.tpl'));
  629. }
  630. /**
  631. * Purge ids log.
  632. *
  633. * @return void
  634. */
  635. public function purgeidslogAction()
  636. {
  637. // Security check
  638. if (!SecurityUtil::checkPermission('SecurityCenter::', '::', ACCESS_DELETE)) {
  639. throw new \Zikula\Framework\Exception\ForbiddenException();
  640. }
  641. $confirmation = $this->request->get('confirmation');
  642. // Check for confirmation
  643. if (empty($confirmation)) {
  644. // No confirmation yet - get one
  645. // Return the output that has been generated by this function
  646. return $this->response($this->view->fetch('Admin/purgeidslog.tpl'));
  647. }
  648. // Confirm authorisation code
  649. $this->checkCsrfToken();
  650. $redirect_url = ModUtil::url('SecurityCenter', 'admin', 'viewidslog');
  651. // delete all entries
  652. if (ModUtil::apiFunc('SecurityCenterModule', 'admin', 'purgeidslog')) {
  653. LogUtil::registerStatus($this->__('Done! Purged IDS Log.'));
  654. }
  655. return $this->redirect($redirect_url);
  656. }
  657. /**
  658. * Display the allowed html form.
  659. *
  660. * @return string html output.
  661. */
  662. public function allowedhtmlAction(array $args = array())
  663. {
  664. // security check
  665. if (!SecurityUtil::checkPermission('SecurityCenter::', '::', ACCESS_ADMIN)) {
  666. throw new \Zikula\Framework\Exception\ForbiddenException();
  667. }
  668. $this->view->assign('htmltags', $this->_gethtmltags())
  669. ->assign('currenthtmltags', System::getVar('AllowableHTML'))
  670. ->assign('htmlentities', System::getVar('htmlentities'));
  671. // check for HTML Purifier outputfilter
  672. $htmlpurifier = (bool)(System::getVar('outputfilter') == 1);
  673. $this->view->assign('htmlpurifier', $htmlpurifier);
  674. $this->view->assign('configurl', ModUtil::url('SecurityCenter', 'admin', 'modifyconfig'));
  675. return $this->response($this->view->fetch('Admin/allowedhtml.tpl'));
  676. }
  677. /**
  678. * Update allowed html settings.
  679. *
  680. * @return mixed true if successful, false if unsuccessful, error string otherwise.
  681. */
  682. public function updateallowedhtmlAction(array $args = array())
  683. {
  684. $this->checkCsrfToken();
  685. // security check
  686. if (!SecurityUtil::checkPermission('SecurityCenter::', '::', ACCESS_ADMIN)) {
  687. throw new \Zikula\Framework\Exception\ForbiddenException();
  688. }
  689. // update the allowed html settings
  690. $allowedhtml = array();
  691. $htmltags = $this->_gethtmltags();
  692. foreach ($htmltags as $htmltag => $usagetag) {
  693. $tagval = (int)$this->request->request->get('htmlallow' . $htmltag . 'tag', 0);
  694. if (($tagval != 1) && ($tagval != 2)) {
  695. $tagval = 0;
  696. }
  697. $allowedhtml[$htmltag] = $tagval;
  698. }
  699. System::setVar('AllowableHTML', $allowedhtml);
  700. // one additonal config var is set on this page
  701. $htmlentities = $this->request->request->get('xhtmlentities', 0);
  702. System::setVar('htmlentities', $htmlentities);
  703. // clear all cache and compile directories
  704. ModUtil::apiFunc('SettingsModule', 'admin', 'clearallcompiledcaches');
  705. // all done successfully
  706. LogUtil::registerStatus($this->__('Done! Saved module configuration.'));
  707. return $this->redirect(ModUtil::url('SecurityCenter', 'admin', 'allowedhtml'));
  708. }
  709. /**
  710. * Utility function to return the list of available tags.
  711. *
  712. * @return string html output.
  713. */
  714. private function _gethtmltags()
  715. {
  716. // Possible allowed HTML tags
  717. return array(
  718. '!--' => 'http://www.w3schools.com/html5/tag_comment.asp',
  719. 'a' => 'http://www.w3schools.com/html5/tag_a.asp',
  720. 'abbr' => 'http://www.w3schools.com/html5/tag_abbr.asp',
  721. 'acronym' => 'http://www.w3schools.com/html5/tag_acronym.asp',
  722. 'address' => 'http://www.w3schools.com/html5/tag_address.asp',
  723. 'applet' => 'http://www.w3schools.com/tags/tag_applet.asp',
  724. 'area' => 'http://www.w3schools.com/html5/tag_area.asp',
  725. 'article' => 'http://www.w3schools.com/html5/tag_article.asp',
  726. 'aside' => 'http://www.w3schools.com/html5/tag_aside.asp',
  727. 'audio' => 'http://www.w3schools.com/html5/tag_audio.asp',
  728. 'b' => 'http://www.w3schools.com/html5/tag_b.asp',
  729. 'base' => 'http://www.w3schools.com/html5/tag_base.asp',
  730. 'basefont' => 'http://www.w3schools.com/tags/tag_basefont.asp',
  731. 'bdo' => 'http://www.w3schools.com/html5/tag_bdo.asp',
  732. 'big' => 'http://www.w3schools.com/tags/tag_font_style.asp',
  733. 'blockquote' => 'http://www.w3schools.com/html5/tag_blockquote.asp',
  734. 'br' => 'http://www.w3schools.com/html5/tag_br.asp',
  735. 'button' => 'http://www.w3schools.com/html5/tag_button.asp',
  736. 'canvas' => 'http://www.w3schools.com/html5/tag_canvas.asp',
  737. 'caption' => 'http://www.w3schools.com/html5/tag_caption.asp',
  738. 'center' => 'http://www.w3schools.com/tags/tag_center.asp',
  739. 'cite' => 'http://www.w3schools.com/html5/tag_phrase_elements.asp',
  740. 'code' => 'http://www.w3schools.com/html5/tag_phrase_elements.asp',
  741. 'col' => 'http://www.w3schools.com/html5/tag_col.asp',
  742. 'colgroup' => 'http://www.w3schools.com/html5/tag_colgroup.asp',
  743. 'command' => 'http://www.w3schools.com/html5/tag_command.asp',
  744. 'datalist' => 'http://www.w3schools.com/html5/tag_datalist.asp',
  745. 'dd' => 'http://www.w3schools.com/html5/tag_dd.asp',
  746. 'del' => 'http://www.w3schools.com/html5/tag_del.asp',
  747. 'details' => 'http://www.w3schools.com/html5/tag_details.asp',
  748. 'dfn' => 'http://www.w3schools.com/html5/tag_phrase_elements.asp',
  749. 'dir' => 'http://www.w3schools.com/tags/tag_dir.asp',
  750. 'div' => 'http://www.w3schools.com/html5/tag_div.asp',
  751. 'dl' => 'http://www.w3schools.com/html5/tag_dl.asp',
  752. 'dt' => 'http://www.w3schools.com/html5/tag_dt.asp',
  753. 'em' => 'http://www.w3schools.com/html5/tag_phrase_elements.asp',
  754. 'embed' => 'http://www.w3schools.com/html5/tag_embed.asp',
  755. 'fieldset' => 'http://www.w3schools.com/html5/tag_fieldset.asp',
  756. 'figcaption' => 'http://www.w3schools.com/html5/tag_figcaption.asp',
  757. 'figure' => 'http://www.w3schools.com/html5/tag_figure.asp',
  758. 'font' => 'http://www.w3schools.com/tags/tag_font.asp',
  759. 'footer' => 'http://www.w3schools.com/html5/tag_footer.asp',
  760. 'form' => 'http://www.w3schools.com/html5/tag_form.asp',
  761. 'h1' => 'http://www.w3schools.com/html5/tag_hn.asp',
  762. 'h2' => 'http://www.w3schools.com/html5/tag_hn.asp',
  763. 'h3' => 'http://www.w3schools.com/html5/tag_hn.asp',
  764. 'h4' => 'http://www.w3schools.com/html5/tag_hn.asp',
  765. 'h5' => 'http://www.w3schools.com/html5/tag_hn.asp',
  766. 'h6' => 'http://www.w3schools.com/html5/tag_hn.asp',
  767. 'header' => 'http://www.w3schools.com/html5/tag_header.asp',
  768. 'hgroup' => 'http://www.w3schools.com/html5/tag_hgroup.asp',
  769. 'hr' => 'http://www.w3schools.com/html5/tag_hr.asp',
  770. 'i' => 'http://www.w3schools.com/html5/tag_i.asp',
  771. 'iframe' => 'http://www.w3schools.com/html5/tag_iframe.asp',
  772. 'img' => 'http://www.w3schools.com/html5/tag_img.asp',
  773. 'input' => 'http://www.w3schools.com/html5/tag_input.asp',
  774. 'ins' => 'http://www.w3schools.com/html5/tag_ins.asp',
  775. 'keygen' => 'http://www.w3schools.com/html5/tag_keygen.asp',
  776. 'kbd' => 'http://www.w3schools.com/html5/tag_phrase_elements.asp',
  777. 'label' => 'http://www.w3schools.com/html5/tag_label.asp',
  778. 'legend' => 'http://www.w3schools.com/html5/tag_legend.asp',
  779. 'li' => 'http://www.w3schools.com/html5/tag_li.asp',
  780. 'map' => 'http://www.w3schools.com/html5/tag_map.asp',
  781. 'mark' => 'http://www.w3schools.com/html5/tag_mark.asp',
  782. 'menu' => 'http://www.w3schools.com/html5/tag_menu.asp',
  783. 'marquee' => '',
  784. 'meter' => 'http://www.w3schools.com/html5/tag_meter.asp',
  785. 'nav' => 'http://www.w3schools.com/html5/tag_nav.asp',
  786. 'nobr' => '',
  787. 'object' => 'http://www.w3schools.com/html5/tag_object.asp',
  788. 'ol' => 'http://www.w3schools.com/html5/tag_ol.asp',
  789. 'optgroup' => 'http://www.w3schools.com/html5/tag_optgroup.asp',
  790. 'option' => 'http://www.w3schools.com/html5/tag_option.asp',
  791. 'output' => 'http://www.w3schools.com/html5/tag_output.asp',
  792. 'p' => 'http://www.w3schools.com/html5/tag_p.asp',
  793. 'param' => 'http://www.w3schools.com/html5/tag_param.asp',
  794. 'pre' => 'http://www.w3schools.com/html5/tag_pre.asp',
  795. 'progress' => 'http://www.w3schools.com/html5/tag_progress.asp',
  796. 'q' => 'http://www.w3schools.com/html5/tag_q.asp',
  797. 'rp' => 'http://www.w3schools.com/html5/tag_rp.asp',
  798. 'rt' => 'http://www.w3schools.com/html5/tag_rt.asp',
  799. 'ruby' => 'http://www.w3schools.com/html5/tag_ruby.asp',
  800. 's' => 'http://www.w3schools.com/tags/tag_strike.asp',
  801. 'samp' => 'http://www.w3schools.com/html5/tag_phrase_elements.asp',
  802. 'script' => 'http://www.w3schools.com/html5/tag_script.asp',
  803. 'section' => 'http://www.w3schools.com/html5/tag_section.asp',
  804. 'select' => 'http://www.w3schools.com/html5/tag_select.asp',
  805. 'small' => 'http://www.w3schools.com/html5/tag_small.asp',
  806. 'source' => 'http://www.w3schools.com/html5/tag_source.asp',
  807. 'span' => 'http://www.w3schools.com/html5/tag_span.asp',
  808. 'strike' => 'http://www.w3schools.com/tags/tag_strike.asp',
  809. 'strong' => 'http://www.w3schools.com/html5/tag_phrase_elements.asp',
  810. 'sub' => 'http://www.w3schools.com/html5/tag_sup.asp',
  811. 'summary' => 'http://www.w3schools.com/html5/tag_summary.asp',
  812. 'sup' => 'http://www.w3schools.com/html5/tag_sup.asp',
  813. 'table' => 'http://www.w3schools.com/html5/tag_table.asp',
  814. 'tbody' => 'http://www.w3schools.com/html5/tag_tbody.asp',
  815. 'td' => 'http://www.w3schools.com/html5/tag_td.asp',
  816. 'textarea' => 'http://www.w3schools.com/html5/tag_textarea.asp',
  817. 'tfoot' => 'http://www.w3schools.com/html5/tag_tfoot.asp',
  818. 'th' => 'http://www.w3schools.com/html5/tag_th.asp',
  819. 'thead' => 'http://www.w3schools.com/html5/tag_thead.asp',
  820. 'time' => 'http://www.w3schools.com/html5/tag_time.asp',
  821. 'tr' => 'http://www.w3schools.com/html5/tag_tr.asp',
  822. 'tt' => 'http://www.w3schools.com/tags/tag_font_style.asp',
  823. 'u' => 'http://www.w3schools.com/tags/tag_u.asp',
  824. 'ul' => 'http://www.w3schools.com/html5/tag_ul.asp',
  825. 'var' => 'http://www.w3schools.com/html5/tag_phrase_elements.asp',
  826. 'video' => 'http://www.w3schools.com/html5/tag_video.asp',
  827. 'wbr' => 'http://www.w3schools.com/html5/tag_wbr.asp');
  828. }
  829. }