array( 'controller' => 'fileinspector_ui', 'path' => null, 'ui' => 'fileinspector_form_ui', 'uipath' => null ), ); protected $adminMenu = array( 'main/setup' => array('caption'=> LAN_CONFIGURE, 'perm' => 'P'), // 'main/run' => array('caption'=> FR_LAN_2, 'perm' => 'P'), ); protected $adminMenuAliases = array( 'main/edit' => 'main/list' ); protected $menuTitle = FC_LAN_1; protected $adminMenuIcon = 'e-fileinspector-24'; function init() { if(!empty($_GET['viewerror'])) { $file = e107::getSession()->get('fileinspector_error_log_'. $_GET['viewerror']); if(!empty($file)) { $contents = file_get_contents(e_BASE.$file); echo "
".$contents.""; } exit; } if(!empty($_GET['action']) && $_GET['action'] === 'begin') { /** @var file_inspector $fi */ $fi = e107::getSingleton('file_inspector'); $fi->scan_results(); exit(); } } } class fileinspector_ui extends e_admin_ui { protected $pluginTitle = FC_LAN_1; protected $pluginName = 'core'; protected $eventName = 'fileinspector'; protected $table = ''; protected $pid = ''; protected $perPage = 10; protected $batchDelete = true; protected $batchCopy = true; // protected $sortField = 'somefield_order'; // protected $orderStep = 10; // protected $tabs = array('Tabl 1','Tab 2'); // Use 'tab'=>0 OR 'tab'=>1 in the $fields below to enable. protected $listQry = ""; // Example Custom Query. LEFT JOINS allowed. Should be without any Order or Limit. protected $listOrder = ''; protected $fields = array (); protected $fieldpref = array(); protected $prefs = array(); protected $fi; public function init() { // } public function SetupPage() { /** @var file_inspector */ $fi =e107::getSingleton('file_inspector'); return $fi->scan_config(); } public function RunPage() { $this->addTitle(LAN_CONFIGURE); $this->addTitle(LAN_RUN); $frm = $this->getUI(); unset($_GET['mode'],$_GET['action']); $source = e_SELF."?mode=main&action=begin&".http_build_query($_GET); $target = '#results-container'; $interval = 500; $text = $frm->open('runit'); $text .= $frm->progressBar('inspector-progress', 0); // $text .= ''; $text .= ' '.FR_LAN_33.''; $text .= ' '.LAN_CANCEL.''; $text .= $frm->close(); $text .= ""; return $text; } } class fileinspector_form_ui extends e_admin_form_ui { } new fileinspector_admin(); require_once(e_ADMIN."auth.php"); e107::getAdminUI()->runPage(); require_once(e_ADMIN."footer.php"); class file_inspector { const SCAN_ID_PREFIX = 'e107-file-inspector-scan-'; /** @var e_file_inspector */ private $coreImage; private $coreImageVersion; private $root_dir; private $files = array(); private $fileSizes = array(); private $count = array(); /** @deprecated What's this? */ var $results = 0; private $totalFiles = 0; private $progress_units = 0; private $progressPercentage = 0; private $langs = array(); private $lang_short = array(); private $iconTag = array(); private $options = array( 'core' => '', 'type' => 'tree', 'missing' => 0, 'noncore' => 9, 'oldcore' => 0, 'integrity' => 1, 'regex' => 0, 'mod' => '', 'num' => 0, 'line' => 0, 'scan' => null // progress identifier ); /** * @var array */ private $glyph; function setOptions($post) { foreach($this->options as $k=>$v) { if(isset($post[$k])) { $this->options[$k] = $post[$k]; } } } function __construct() { $lng = e107::getLanguage(); $langs = $lng->installed(); $this->setOptions($_GET); $lang_short = array(); foreach($langs as $k=>$val) { if($val == "English") // Core release language, so ignore it. { unset($langs[$k]); continue; } $lang_short[] = $lng->convert($val); } $this->langs = $langs; $this->lang_short = $lang_short; $this->glyph = array( 'folder_close' => array(''), 'folder_up' => array(''), 'folder_root' => array(''), 'warning' => array(''), 'info' => array(''), 'fileinspector' => array(''), 'folder' => array(''), 'folder_check' => array('', FC_LAN_24 ), 'folder_fail' => array('', FC_LAN_25 ), 'folder_uncalc' => array('', FC_LAN_24 ), 'folder_missing' => array('', FC_LAN_26 ), 'folder_warning' => array(''), 'folder_old' => array('', FC_LAN_27 ), 'folder_old_dir' => array(''), 'folder_unknown' => array('', FC_LAN_28 ), 'file_check' => array('', FC_LAN_29), 'file_core' => array('', FC_LAN_30), 'file_fail' => array('', FC_LAN_31 ), 'file_missing' => array('', FC_LAN_32 ), 'file_old' => array('', FC_LAN_33 ), 'file_uncalc' => array('', FC_LAN_34 ), 'file_warning' => array('', FC_LAN_35 ), 'file_unknown' => array('', FC_LAN_36 ), ); foreach($this->glyph as $k=>$v) { $this->iconTag[$k] = $this->glyph[$k][0]; } $e107 = e107::getInstance(); $this->coreImage = e107::getFileInspector('core'); $this->coreImageVersion = $this->coreImage->getCurrentVersion(); $this->root_dir = $e107 -> file_path; if(substr($this->root_dir, -1) == '/') { $this->root_dir = substr($this->root_dir, 0, -1); } if(isset($_POST['core']) && $_POST['core'] == 'integrity_fail_only') { $_POST['integrity'] = TRUE; } if(MAGIC_QUOTES_GPC && vartrue($_POST['regex'])) { $_POST['regex'] = stripslashes($_POST['regex']); } if(!empty($_POST['regex'])) { if($_POST['core'] == 'fail') { $_POST['core'] = 'all'; } $_POST['missing'] = 0; $_POST['integrity'] = 0; } self::pruneOldProgressFiles(); } private function opt($key) { return $this->options[$key]; } // Find the Total number of core files before scanning begins. private function countFiles() { return $this->totalFiles = iterator_count($this->coreImage->getPathIterator($this->coreImageVersion)); } function getLegend() { return $this->glyph; } function renderHelp() { $text = "
".$v." | ".$k." |
".FR_LAN_2." | |||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
".$this->generateScanResultsHtml()."
|
";
}
else
{
$text = " ".FR_LAN_2.""; } $text .= "
"; echo $text; $this->sendProgress($this->totalFiles); self::pruneOldProgressFiles(); } function checksum($filename) { $checksum = md5(str_replace(array(chr(13),chr(10)), "", file_get_contents($filename))); return $checksum; } function parsesize($size, $dec = 0) { $size = $size ? $size : 0; $kb = 1024; $mb = 1024 * $kb; $gb = 1024 * $mb; $tb = 1024 * $gb; if($size < $kb) { return $size." ".CORE_LAN_B; } elseif($size < $mb) { return round($size/$kb)." ".CORE_LAN_KB; } elseif($size < $gb) { return round($size/$mb, $dec)." ".CORE_LAN_MB; } elseif($size < $tb) { return round($size/$gb, $dec)." ".CORE_LAN_GB; } else { return round($size/$tb, $dec)." ".CORE_LAN_TB; } } function regex_match($file) { $file_content = file_get_contents($file); $match = preg_match($_POST['regex'], $file_content); return $match; } function sendProgress($increment=0) { if(empty($this->options['scan'])) { return null; } $this->progress_units = $this->progress_units + $increment; $rand = (int) $this->progress_units; $total = (int) $this->totalFiles; $inc = round(($rand / $total) * 100); if($inc >= 100) { $inc = 100; } if( $this->progressPercentage === $inc) { return null; } $this->progressPercentage = $inc; self::writeScanProgress($this->options['scan'], $this->progressPercentage); return null; } public function exploit_interface() { // global $ns; $ns = e107::getRender(); $query = http_build_query($_POST); $text = " "; $ns->tablerender(FR_LAN_1, $text); } function headerCss() { $pref = e107::getPref(); echo "\n"; $e_js = e107::getJs(); // Core CSS - XXX awaiting for path changes if(!isset($no_core_css) || !$no_core_css) { //echo "\n"; $e_js->otherCSS('{e_WEB_CSS}e107.css'); } if(!deftrue('e_IFRAME') && isset($pref['admincss']) && $pref['admincss']) { $css_file = file_exists(THEME.'admin_'.$pref['admincss']) ? 'admin_'.$pref['admincss'] : $pref['admincss']; //echo "\n"; $e_js->themeCSS($css_file); } elseif(isset($pref['themecss']) && $pref['themecss']) { $css_file = file_exists(THEME.'admin_'.$pref['themecss']) ? 'admin_'.$pref['themecss'] : $pref['themecss']; //echo "\n"; $e_js->themeCSS($css_file); } else { $css_file = file_exists(THEME.'admin_style.css') ? 'admin_style.css' : 'style.css'; //echo "\n"; $e_js->themeCSS($css_file); } $e_js->renderJs('other_css', false, 'css', false); echo "\n\n"; // Core CSS $e_js->renderJs('core_css', false, 'css', false); echo "\n\n"; // Plugin CSS $e_js->renderJs('plugin_css', false, 'css', false); echo "\n\n"; // Theme CSS //echo "\n"; $e_js->renderJs('theme_css', false, 'css', false); echo "\n\n"; // Inline CSS - not sure if this should stay at all! $e_js->renderJs('inline_css', false, 'css', false); echo "\n\n"; $text = " \n"; echo $text; } /** * Get the PHP-standard version of the hash of the relative path * * @todo FIXME performance: This method checksums old files a second time. * @param string $relativePath Relative path to checksum * @param int $validationCode e_file_inspector validation bits * @return false|string */ private function getOldVersionOfPath($relativePath, $validationCode) { $oldVersion = false; if (($validationCode & e_file_inspector::VALIDATED_HASH_EXISTS) && !($validationCode & e_file_inspector::VALIDATED_HASH_CURRENT)) { $dbChecksums = $this->coreImage->getChecksums($relativePath); $actualChecksum = $this->coreImage->checksumPath(e_BASE . $relativePath); $oldVersion = array_search($actualChecksum, $dbChecksums); } return $oldVersion; } private static function writeScanProgress($scanId, $progress) { self::exitOnEvilScanId($scanId); $tmpDir = sys_get_temp_dir(); $progressPath = $tmpDir . "/" . self::SCAN_ID_PREFIX . $scanId; if ($progress >= 100) unlink($progressPath); else file_put_contents($progressPath, $progress); } public static function readScanProgress($scanId) { self::exitOnEvilScanId($scanId); $tmpDir = sys_get_temp_dir(); $progressPath = $tmpDir . "/" . self::SCAN_ID_PREFIX . $scanId; $result = trim(@file_get_contents($progressPath)); if (!strlen($result)) $result = '100'; return $result; } private static function exitOnEvilScanId($scanId) { if (!preg_match('/^[0-9A-F]+$/i', $scanId)) exit(1); } private static function pruneOldProgressFiles() { $tmpDir = sys_get_temp_dir(); $i = new DirectoryIterator($tmpDir); foreach ($i as $fileInfo) { $candidateFileName = $fileInfo->getFilename(); if (substr($candidateFileName, 0, strlen(self::SCAN_ID_PREFIX)) !== self::SCAN_ID_PREFIX) continue; if ($fileInfo->isFile() && time() - $fileInfo->getMTime() > 300) unlink($fileInfo->getRealPath()); } } } /* function fileinspector_adminmenu() //FIXME - has problems when navigation is on the LEFT instead of the right. { $var['setup']['text'] = FC_LAN_11; $var['setup']['link'] = e_SELF."?mode=setup"; $var['run']['text'] = FR_LAN_2; $var['run']['link'] = e_SELF."?mode=run"; $icon = e107::getParser()->toIcon('e-fileinspector-24'); $caption = $icon."".FC_LAN_1.""; e107::getNav()->admin($caption, $_GET['mode'], $var); }*/ function e_help() { // $fi = new file_inspector; $fi = e107::getSingleton('file_inspector'); $list = $fi->getLegend(); $text = ''; foreach($list as $v) { if(!empty($v[1])) { $text .= " ".$v[0]." ".$v[1]." ";
}
}
return array('caption'=>FC_LAN_37, 'text'=>$text);
}
require_once(e_ADMIN.'footer.php');
/*
function headerjs()
{
e107::js('footer', '{e_WEB}/js/core/all.jquery.js', 'jquery', 1);
e107::js('footer', '{e_WEB}js/core/front.jquery.js', 'jquery', 1); // Load all default functions.
$text = e107::getJs()->renderJs('footer', 1, true, true);
$text .= "";
return $text;
}*/
?>
|