1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-01 04:10:38 +02:00

fileinspector - code-cleanup, no functional changes

Reformatting, syntax, spacing, tabs, etc.
This commit is contained in:
Tijn Kuyper
2019-11-05 14:28:34 +01:00
parent 25715754d0
commit e021c52db1

View File

@@ -23,54 +23,62 @@ if (!getperms('Y'))
e107::redirect('admin');
exit;
}
$error_handler->debug = FALSE;
//require_once(e_HANDLER.'form_handler.php');
$DOCS_DIRECTORY = $HELP_DIRECTORY; // Give a sensible, albeit probably invalid, value
if(substr($HELP_DIRECTORY,-5,5) == 'help/')
{
$DOCS_DIRECTORY = substr($HELP_DIRECTORY,0,-5); // Whatever $HELP_DIRECTORY is set to, assume docs are in a subdirectory called 'help' off it
}
$maindirs = array('admin' => $ADMIN_DIRECTORY, 'files' => $FILES_DIRECTORY, 'images' => $IMAGES_DIRECTORY, 'themes' => $THEMES_DIRECTORY, 'plugins' => $PLUGINS_DIRECTORY, 'handlers' => $HANDLERS_DIRECTORY, 'languages' => $LANGUAGES_DIRECTORY, 'downloads' => $DOWNLOADS_DIRECTORY, 'docs' => $DOCS_DIRECTORY);
foreach ($maindirs as $maindirs_key => $maindirs_value) {
$maindirs = array(
'admin' => $ADMIN_DIRECTORY,
'files' => $FILES_DIRECTORY,
'images' => $IMAGES_DIRECTORY,
'themes' => $THEMES_DIRECTORY,
'plugins' => $PLUGINS_DIRECTORY,
'handlers' => $HANDLERS_DIRECTORY,
'languages' => $LANGUAGES_DIRECTORY,
'downloads' => $DOWNLOADS_DIRECTORY,
'docs' => $DOCS_DIRECTORY
);
foreach ($maindirs as $maindirs_key => $maindirs_value)
{
$coredir[$maindirs_key] = substr($maindirs_value, 0, -1);
}
require_once('core_image.php');
//$rs = new form;
set_time_limit(18000);
$e_sub_cat = 'fileinspector';
if(isset($_GET['scan']))
{
session_write_close();
while (@ob_end_clean());
//header("Content-type: text/html; charset=".CHARSET, true);
//$css_file = file_exists(e_THEME.$pref['admintheme'].'/'.$pref['admincss']) ? e_THEME.$pref['admintheme'].'/'.$pref['admincss'] : e_THEME.$pref['admintheme'].'/'.$pref['admincss'];
// $fi = new file_inspector;
$fi = e107::getSingleton('file_inspector');
echo "<!DOCTYPE html>
<html>
<head>
<title>Results</title>
<script type='text/javascript' src='https://cdn.jsdelivr.net/jquery/2.1.4/jquery.min.js'></script>
".$fi->headerCss()." ".headerjs()."
<body style='height:100%;background-color:#2F2F2F'>\n";
// define('e_IFRAME', true);
// require_once(e_ADMIN."auth.php");
// echo "<br />loading..";
// echo "..";
@@ -89,7 +97,8 @@ if(isset($_GET['scan']))
// require_once(e_ADMIN."footer.php");
echo "</body></html>";
echo "</body>
</html>";
exit();
@@ -99,10 +108,6 @@ else
// $fi = new file_inspector;
$fi = e107::getSingleton('file_inspector');
require_once(e_ADMIN.'auth.php');
@@ -129,7 +134,6 @@ else
class file_inspector {
var $root_dir;
@@ -143,7 +147,6 @@ class file_inspector {
private $langs = array();
private $lang_short = array();
private $excludeFiles = array( '.', '..','/','.svn', 'CVS' ,'Thumbs.db', '.git');
private $knownSecurityIssues = array('htmlarea', 'e107_docs/docs.php');
@@ -164,7 +167,6 @@ class file_inspector {
'line' => 0
);
function setOptions($post)
{
foreach($this->options as $k=>$v)
@@ -174,13 +176,10 @@ class file_inspector {
$this->options[$k] = $post[$k];
}
}
}
function __construct()
{
$lng = e107::getLanguage();
$langs = $lng->installed();
@@ -190,6 +189,7 @@ class file_inspector {
}
$lang_short = array();
foreach($langs as $k=>$val)
{
if($val == "English") // Core release language, so ignore it.
@@ -204,9 +204,6 @@ class file_inspector {
$this->langs = $langs;
$this->lang_short = $lang_short;
//TODO LAN
$this->glyph = array(
'folder_close' => array('<i class="fa fa-times-circle-o"></i>'),
'folder_up' => array('<i class="fa fa-folder-open-o"></i>'),
@@ -233,25 +230,20 @@ class file_inspector {
'file_uncalc' => array('<i class="fa fa-file-o " ></i>', FC_LAN_34 ),
'file_warning' => array('<i class="fa fa-file text-warning" ></i>', FC_LAN_35 ),
'file_unknown' => array('<i class="fa fa-file-o text-primary" ></i>', FC_LAN_36 ),
);
foreach($this->glyph as $k=>$v)
{
$this->iconTag[$k] = $this->glyph[$k][0];
}
global $e107, $core_image;
//$this->totalFiles = count($core_image,COUNT_RECURSIVE);
$this->countFiles($core_image);
$this->root_dir = $e107 -> file_path;
if(substr($this->root_dir, -1) == '/')
{
$this->root_dir = substr($this->root_dir, 0, -1);
@@ -267,10 +259,13 @@ class file_inspector {
$_POST['regex'] = stripslashes($_POST['regex']);
}
if ($_POST['regex']) {
if ($_POST['core'] == 'fail') {
if($_POST['regex'])
{
if($_POST['core'] == 'fail')
{
$_POST['core'] = 'all';
}
$_POST['missing'] = 0;
$_POST['integrity'] = 0;
}
@@ -296,7 +291,6 @@ class file_inspector {
{
$this->totalFiles++;
}
}
}
@@ -309,21 +303,19 @@ class file_inspector {
}
return $key;
}
public function getLegend()
{
return $this->glyph;
}
function renderHelp()
{
$text = "<table>";
foreach($this->iconTag as $k=>$v)
{
$text .= "<tr><td>".$v."</td><td>".$k."</td></tr>";
@@ -336,20 +328,15 @@ class file_inspector {
function scan_config()
{
$frm = e107::getForm();
$ns = e107::getRender();
$pref = e107::pref('core');
if($_GET['mode'] == 'run')
{
return;
}
$tab = array();
$head = "<div>
@@ -383,7 +370,6 @@ class file_inspector {
</tr>";
$text .= "<tr>
<td style='width: 35%'>
".LAN_SHOW." ".FC_LAN_13.":
@@ -415,9 +401,6 @@ class file_inspector {
</td>
</tr>";
$text .= "<tr>
<td style='width: 35%'>
".FC_LAN_8.":
@@ -431,7 +414,6 @@ class file_inspector {
$tab['basic'] = array('caption'=>LAN_OPTIONS, 'text'=>$text);
if($pref['developer']) {
$text2 = "<table class='table adminlist'>";
@@ -472,13 +454,9 @@ class file_inspector {
$tab['advanced'] = array('caption'=>FC_LAN_17, 'text'=>$text2);
}
$tabText = e107::getForm()->tabs($tab);
$foot = "
<div class='buttons-bar center'>
".$frm->admin_button('scan', LAN_GO, 'other')."
@@ -494,9 +472,8 @@ class file_inspector {
function scan($dir, $image)
{
$handle = opendir($dir.'/');
while (false !== ($readdir = readdir($handle)))
{
@@ -515,16 +492,22 @@ class file_inspector {
}
closedir($handle);
if (isset($dirs)) {
if(isset($dirs))
{
ksort($dirs);
foreach ($dirs as $dir_path => $dir_list) {
foreach ($dirs as $dir_path => $dir_list)
{
$list[$dir_list] = ($set = $this->scan($dir_path, $image[$dir_list])) ? $set : array();
}
}
if (isset($files)) {
if(isset($files))
{
ksort($files);
foreach ($files as $file_name => $file_list) {
foreach ($files as $file_name => $file_list)
{
$list[$file_name] = $file_list;
}
}
@@ -580,10 +563,12 @@ class file_inspector {
unset ($childOut);
$parent_expand = false;
if(substr($dir, -1) == '/')
{
$dir = substr($dir, 0, -1);
}
$dir_id = dechex(crc32($dir));
$this->files[$dir_id]['.']['level'] = $level;
$this->files[$dir_id]['.']['parent'] = $this->parent;
@@ -591,29 +576,29 @@ class file_inspector {
$directory = $level ? basename($dir) : SITENAME;
$level++;
//
$this->sendProgress(vartrue($this->count['core']['num']),$this->totalFiles,FR_LAN_1);
foreach ($list as $key => $value)
{
// $dir_icon = 'fileinspector'; // default as unknown
$this->parent = $dir_id;
// Entry is a subdirectory - recurse another level
if(is_array($value))
{ // Entry is a subdirectory - recurse another level
{
$path = $dir.'/'.$key;
$child_open = false;
$child_end = true;
$dir_icon = 'folder_check';
$sub_text .= $this->inspect($value, $deprecated[$key], $level, $path, $child_end, $child_expand);
$tree_end = false;
if($child_expand)
{
$parent_expand = true;
$last_expand = true;
}
}
else
{
@@ -623,29 +608,35 @@ class file_inspector {
$fid = strtolower($key);
$this->files[$dir_id][$fid]['file'] = ($_POST['type'] == 'tree') ? $key : $path;
// We're checking a file here
if(($this->files[$dir_id][$fid]['size'] = filesize($path)) !== false)
{ // We're checking a file here
{
// Look at core files
if($this->opt('core') != 'none')
{ // Look at core files
{
$this->count['core']['num']++;
$this->count['core']['size'] += $this->files[$dir_id][$fid]['size'];
// TODO Max out of Memory when used
if($_POST['regex']) // Developer prefs activated - search file contents according to regex
{ // TODO Max out of Memory when used
$file_content = file($path); // Get contents of file
{
// Get contents of file
$file_content = file($path);
if(($this->files[$dir_id][$fid]['size'] = filesize($path)) !== FALSE)
{
// Search string found - add file to list
if($this->files[$dir_id][$fid]['lines'] = preg_grep("#".$_POST['regex']."#".$_POST['mod'], $file_content))
{ // Search string found - add file to list
{
$this->files[$dir_id][$fid]['file'] = ($_POST['type'] == 'tree') ? $key : $path;
$this->files[$dir_id][$fid]['icon'] = 'file_core';
$dir_icon = 'fileinspector';
$parent_expand = TRUE;
$this->results++;
}
// Search string not found - discard from list
else
{ // Search string not found - discard from list
{
unset($this->files[$dir_id][$fid]);
$known[$dir_id][$fid] = true;
$dir_icon = ($dir_icon == 'fileinspector') ? 'folder_unknown': $dir_icon ;
@@ -654,8 +645,9 @@ class file_inspector {
}
else
{
// Actually check file integrity
if($this->opt('integrity'))
{ // Actually check file integrity
{
switch ($this_action = $this->check_action($dir,$key))
{
case 'ignore' :
@@ -682,7 +674,6 @@ class file_inspector {
{
unset($this->files[$dir_id][$fid]);
$known[$dir_id][$fid] = true;
}
}
break;
@@ -690,10 +681,10 @@ class file_inspector {
case 'nocalc' :
$this->count['uncalculable']['num']++;
$this->count['uncalculable']['size'] += $this->files[$dir_id][$fid]['size'];
if($this->opt('core') != 'fail')
{
$this->files[$dir_id][$fid]['icon'] = 'file_uncalc';
}
else
{
@@ -703,8 +694,9 @@ class file_inspector {
break;
}
}
// Just identify as core file
else
{ // Just identify as core file
{
$this->files[$dir_id][$fid]['icon'] = 'file_core';
}
}
@@ -743,9 +735,6 @@ class file_inspector {
if($this->opt('noncore') || $this->opt('oldcore'))
{
if(!$handle = opendir($dir.'/'))
{
//e107::getMessage()->addInfo("Couldn't Open : ".$dir);
@@ -758,7 +747,6 @@ class file_inspector {
if(!in_array($readdir,$this->excludeFiles) && (strpos('._', $readdir) === false))
{
if(is_dir($dir.'/'.$readdir))
{
if(!isset($list[$readdir]) && ($level > 1 || $readdir == 'e107_install'))
@@ -773,17 +761,11 @@ class file_inspector {
$last_expand = true;
}
}
}
else
{
if($this->opt('nolang') && !empty($langs) && !empty($lang_short)) // Hide Non-core Languages.
{
// PHP Lang files.
$lreg = "/[\/_](".implode("|",$langs).")/";
if(preg_match($lreg, $dir.'/'.$readdir))
@@ -885,7 +867,9 @@ class file_inspector {
}
}
}
} else if ($this->opt('core') == 'none') {
}
elseif($this->opt('core') == 'none')
{
unset($this->files[$dir_id][$aid]);
}
}
@@ -959,9 +943,10 @@ class file_inspector {
function scan_results()
{
global $ns, $rs, $core_image, $deprecated_image;
$scan_text = $this -> inspect($core_image, $deprecated_image, 0, $this -> root_dir);
global $core_image, $deprecated_image;
$ns = e107::getRender();
$scan_text = $this->inspect($core_image, $deprecated_image, 0, $this->root_dir);
$this->sendProgress($this->totalFiles,$this->totalFiles,' &nbsp; &nbsp; &nbsp;');
@@ -1165,8 +1150,6 @@ class file_inspector {
}
function renderRow($stext)
{
@@ -1228,16 +1211,12 @@ class file_inspector {
function create_image($dir) {
function create_image($dir)
{
global $core_image, $deprecated_image,$coredir;
foreach ($coredir as $trim_key => $trim_dirs) {
foreach ($coredir as $trim_key => $trim_dirs)
{
$search[$trim_key] = "'".$trim_dirs."'";
$replace[$trim_key] = "\$coredir['".$trim_key."']";
}
@@ -1394,8 +1373,6 @@ class file_inspector {
}
echo "<div style='display:block;position:absolute;top:20px;width:100%;'>
<div style='width:700px;position:relative;margin-left:auto;margin-right:auto;text-align:center'>";
@@ -1473,7 +1450,6 @@ class file_inspector {
}
if(!deftrue('e_IFRAME') && isset($pref['admincss']) && $pref['admincss'])
{
$css_file = file_exists(THEME.'admin_'.$pref['admincss']) ? 'admin_'.$pref['admincss'] : $pref['admincss'];
@@ -1539,9 +1515,6 @@ class file_inspector {
}
}
function fileinspector_adminmenu() //FIXME - has problems when navigation is on the LEFT instead of the right.
@@ -1580,8 +1553,6 @@ function e_help()
}
require_once(e_ADMIN.'footer.php');
function headerjs()