/www/administrator/components/com_sh404sef/views/default/view.raw.php

https://github.com/amet17/webstar · PHP · 173 lines · 114 code · 35 blank · 24 comment · 11 complexity · cb7257b7fadb5ce5632c4b33acdf7110 MD5 · raw file

  1. <?php
  2. /**
  3. * SEF module for Joomla!
  4. *
  5. * @author $Author: shumisha $
  6. * @copyright Yannick Gaultier - 2007-2010
  7. * @package sh404SEF-15
  8. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
  9. * @version $Id: view.raw.php 1414 2010-05-23 21:04:41Z silianacom-svn $
  10. */
  11. // Security check to ensure this file is being included by a parent file.
  12. if (!defined('_JEXEC')) die('Direct Access to this location is not allowed.');
  13. jimport( 'joomla.application.component.view');
  14. class Sh404sefViewDefault extends JView {
  15. public function display( $tpl = null) {
  16. $layout = JRequest::getCmd( 'layout', 'default');
  17. switch ($layout) {
  18. case 'secstats':
  19. $this->_doSecStats($tpl);
  20. break;
  21. case 'updates':
  22. $this->_doUpdates($tpl);
  23. break;
  24. default:
  25. $this->_doDefault($tpl);
  26. break;
  27. }
  28. }
  29. private function _doDefault($tpl) {
  30. // declare docoument mime type
  31. $document = &JFactory::getDocument();
  32. $document->setMimeEncoding( 'text/xml');
  33. // call helper to prepare response xml file content
  34. $response = Sh404sefHelperGeneral::prepareAjaxResponse( $this);
  35. // echo it
  36. echo $response;
  37. }
  38. private function _doSecStats($tpl) {
  39. // get configuration object
  40. $sefConfig = & shRouter::shGetConfig();
  41. // push it into to the view
  42. $this->assignRef( 'sefConfig', $sefConfig);
  43. // push security stats into view
  44. $this->_prepareSecStatsData();
  45. // push any message
  46. $error= $this->getError();
  47. if(empty($error)) {
  48. $noMsg= JRequest::getInt('noMsg', 0);
  49. if (empty( $noMsg)) {
  50. $this->assign( 'message', JText16::_( 'COM_SH404SEF_ELEMENT_SAVED'));
  51. }
  52. }
  53. //$this->assign( 'errors', array( 'this is an error'));
  54. parent::display($tpl);
  55. }
  56. private function _prepareSecStatsData() {
  57. $sefConfig = & shRouter::shGetConfig();
  58. // calculate security stats
  59. $default = empty($sefConfig->shSecLastUpdated) ? '- -' : '0';
  60. $shSecStats['curMonth'] = empty($sefConfig->shSecCurMonth) ? $default : $sefConfig->shSecCurMonth;
  61. if (empty($sefConfig->shSecLastUpdated)) {
  62. $shSecStats['lastUpdated'] = $default;
  63. } else {
  64. $shSecStats['lastUpdated'] = date('Y-m-d H:i:s', $sefConfig->shSecLastUpdated);
  65. }
  66. $monthStart = mktime(0,0,0,
  67. empty($sefConfig->shSecLastUpdated) ? 0: intval(date('m', $sefConfig->shSecLastUpdated)),
  68. 1,
  69. empty($sefConfig->shSecLastUpdated) ? 0 : intval(date('Y', $sefConfig->shSecLastUpdated)) );
  70. $hours = $sefConfig->shSecLastUpdated == $monthStart ? 0.0001 : ($sefConfig->shSecLastUpdated - $monthStart)/3600;
  71. $shSecStats['totalAttacks'] = empty($sefConfig->shSecTotalAttacks) ? $default : $sefConfig->shSecTotalAttacks;
  72. $shSecStats['totalAttacksHrs'] = $shSecStats['totalAttacks']/$hours;
  73. $shSecStats['totalConfigVars'] = empty($sefConfig->shSecTotalConfigVars) ? $default : $sefConfig->shSecTotalConfigVars;
  74. $shSecStats['totalConfigVarsHrs'] = $shSecStats['totalConfigVars']/$hours;
  75. $shSecStats['totalBase64'] = empty($sefConfig->shSecTotalBase64) ? $default : $sefConfig->shSecTotalBase64;
  76. $shSecStats['totalBase64Hrs'] = $shSecStats['totalBase64']/$hours;
  77. $shSecStats['totalScripts'] = empty($sefConfig->shSecTotalScripts) ? $default : $sefConfig->shSecTotalScripts;
  78. $shSecStats['totalScriptsHrs'] = $shSecStats['totalScripts']/$hours;
  79. $shSecStats['totalStandardVars'] = empty($sefConfig->shSecTotalStandardVars) ? $default : $sefConfig->shSecTotalStandardVars;
  80. $shSecStats['totalStandardVarsHrs'] = $shSecStats['totalStandardVars']/$hours;
  81. $shSecStats['totalImgTxtCmd'] = empty($sefConfig->shSecTotalImgTxtCmd) ? $default : $sefConfig->shSecTotalImgTxtCmd;
  82. $shSecStats['totalImgTxtCmdHrs'] = $shSecStats['totalImgTxtCmd']/$hours;
  83. $shSecStats['totalIPDenied'] = empty($sefConfig->shSecTotalIPDenied) ? $default : $sefConfig->shSecTotalIPDenied;
  84. $shSecStats['totalIPDeniedHrs'] = $shSecStats['totalIPDenied']/$hours;
  85. $shSecStats['totalUserAgentDenied'] = empty($sefConfig->shSecTotalUserAgentDenied) ? $default : $sefConfig->shSecTotalUserAgentDenied;
  86. $shSecStats['totalUserAgentDeniedHrs'] = $shSecStats['totalUserAgentDenied']/$hours;
  87. $shSecStats['totalFlooding'] = empty($sefConfig->shSecTotalFlooding) ? $default : $sefConfig->shSecTotalFlooding;
  88. $shSecStats['totalFloodingHrs'] = $shSecStats['totalFlooding']/$hours;
  89. $shSecStats['totalPHP'] = empty($sefConfig->shSecTotalPHP) ? $default : $sefConfig->shSecTotalPHP;
  90. $shSecStats['totalPHPHrs'] = $shSecStats['totalPHP']/$hours;
  91. $shSecStats['totalPHPUserClicked'] = empty($sefConfig->shSecTotalPHPUserClicked) ? $default : $sefConfig->shSecTotalPHPUserClicked;
  92. $shSecStats['totalPHPUserClickedHrs'] = $shSecStats['totalPHPUserClicked']/$hours;
  93. if (!empty($sefConfig->shSecTotalAttacks)) {
  94. $shSecStats['totalConfigVarsPct'] = round($sefConfig->shSecTotalConfigVars/$sefConfig->shSecTotalAttacks*100,1);
  95. $shSecStats['totalBase64Pct'] = round($sefConfig->shSecTotalBase64/$sefConfig->shSecTotalAttacks*100,1);
  96. $shSecStats['totalScriptsPct'] = round($sefConfig->shSecTotalScripts/$sefConfig->shSecTotalAttacks*100,1);
  97. $shSecStats['totalStandardVarsPct'] = round($sefConfig->shSecTotalStandardVars/$sefConfig->shSecTotalAttacks*100,1);
  98. $shSecStats['totalImgTxtCmdPct'] = round($sefConfig->shSecTotalImgTxtCmd/$sefConfig->shSecTotalAttacks*100,1);
  99. $shSecStats['totalIPDeniedPct'] = round($sefConfig->shSecTotalIPDenied/$sefConfig->shSecTotalAttacks*100,1);
  100. $shSecStats['totalUserAgentDeniedPct'] = round($sefConfig->shSecTotalUserAgentDenied/$sefConfig->shSecTotalAttacks*100,1);
  101. $shSecStats['totalFloodingPct'] = round($sefConfig->shSecTotalFlooding/$sefConfig->shSecTotalAttacks*100,1);
  102. $shSecStats['totalPHPPct'] = round($sefConfig->shSecTotalPHP/$sefConfig->shSecTotalAttacks*100,1);
  103. $shSecStats['totalPHPUserClickedPct'] = round($sefConfig->shSecTotalPHPUserClicked/$sefConfig->shSecTotalAttacks*100,1);
  104. } else {
  105. $shSecStats['totalConfigVarsPct'] = 0;
  106. $shSecStats['totalBase64Pct'] = 0;
  107. $shSecStats['totalScriptsPct'] = 0;
  108. $shSecStats['totalStandardVarsPct'] = 0;
  109. $shSecStats['totalImgTxtCmdPct'] = 0;
  110. $shSecStats['totalIPDeniedPct'] = 0;
  111. $shSecStats['totalUserAgentDeniedPct'] = 0;
  112. $shSecStats['totalFloodingPct'] = 0;
  113. $shSecStats['totalPHPPct'] = 0;
  114. $shSecStats['totalPHPUserClickedPct'] = 0;
  115. }
  116. $this->assign( 'shSecStats', $shSecStats);
  117. }
  118. private function _doUpdates($tpl) {
  119. // get configuration object
  120. $sefConfig = & shRouter::shGetConfig();
  121. // push it into to the view
  122. $this->assignRef( 'sefConfig', $sefConfig);
  123. // do we force reading updates from server ?
  124. $forced = JRequest::getInt( 'forced', 0);
  125. $versionsInfo = Sh404sefHelperUpdates::getUpdatesInfos( !empty($forced));
  126. // push security stats into view
  127. $this->assign( 'updates', $versionsInfo);
  128. // push any message
  129. $error= $this->getError();
  130. if(empty($error)) {
  131. $noMsg= JRequest::getInt('noMsg', 0);
  132. if (empty( $noMsg)) {
  133. $this->assign( 'message', JText16::_( 'COM_SH404SEF_ELEMENT_SAVED'));
  134. }
  135. }
  136. parent::display($tpl);
  137. }
  138. }