support.inc.php.svn-base
来自「PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。」· SVN-BASE 代码 · 共 836 行 · 第 1/2 页
SVN-BASE
836 行
/** * Get disk usage * * @param string $path */ private function capture_df($path) { $df = KTUtil::findCommand('externalBinary/df', 'df'); if (!file_exists($df) || !is_executable($df)) { return; } $df = popen($df, 'r'); $content = fread($df, 10240); pclose($df); file_put_contents($path . '/df.txt', $content); } /** * Get php info * * @param string $filename */ private function capture_phpinfo($filename) { ob_start(); phpinfo(); $phpinfo = ob_get_clean(); file_put_contents($filename, $phpinfo); } /** * Helper table to get schema * * @param string $folder * @return string */ private function capture_table_schema($folder) { $tables = array(); $sql = 'show tables'; $results = DBUtil::getResultArray($sql); foreach($results as $rec) { $rec = array_values($rec); $tablename = $rec[0]; $sql = "show create table $tablename"; $sql = DBUtil::getOneResultKey($sql,'Create Table'); file_put_contents($folder . '/' . $tablename . '.sql.txt', $sql); $sql = strtolower($sql); if (strpos($sql, 'innodb') === false) $this->noninnodb[] = $tablename; else $this->innodb[] = $tablename; $tables[] = $tablename; } return $tables; } /** * Get database schema * * @param string $folder * @param string $suffix * @return array */ private function capture_db_schema($folder, $suffix='') { $schema_folder = $folder . '/' . $suffix . 'schema'; mkdir($schema_folder); return $this->capture_table_schema($schema_folder); } /** * Get list of plugins * * @param string $filename */ private function capture_plugins($filename) { $sql = 'select namespace,path, disabled, unavailable,friendly_name from plugins'; $result = DBUtil::getResultArray($sql); $plugins = "<h1>Plugin Status Report</h1>"; $plugins .= '<table border=1 cellpadding=0 cellspacing=0u >'; $plugins .= '<tr><th>Display Name<th>Availability<th>Namespace<th>Path'; foreach($result as $rec) { $fileexists = file_exists(KT_DIR . '/' . $rec['path'])?'':'<font color="red">'; $status = ($rec['disabled'] == 0)?'<font color="green">':'<font color="orange">'; $unavailable = ($rec['unavailable'] == 0)?'available':'<font color="orange">unavailable'; $plugins .= '<tr>'; $plugins .= '<td>' . $status . $rec['friendly_name']; $plugins .= '<td>' . $unavailable; $plugins .= '<td>' . $rec['namespace']; $plugins .= '<td>' . $fileexists . $rec['path'] . "\r\n"; } $plugins .= '</table>'; $plugins .= '<br>Plugin name is <font color=green>green</font> if enabled and <font color=orange>orange</font> if disabled .'; $plugins .= '<br>Availability indicates that KnowledgeTree has detected the plugin not to be available.'; $plugins .= '<br>Path is coloured <font color=red>red</font> if the plugin file cannot be resolved. If the path is not resolved, it should be flagged unavailable.'; file_put_contents($filename, $plugins); } /** * Make a zseq report * * @param string $tables * @param string $filename */ private function capture_zseqs($tables, $filename) { $zseqs = '<h1>Table Counter Report</h1>'; $zseqs .= '<table border=1 cellpadding=0 cellspacing=0>'; $zseqs .= '<tr><td>Table<td>Max ID<td>ZSEQ<td>Status'; foreach($tables as $ztablename) { if (substr($ztablename, 0, 5) != 'zseq_') { continue; } $tablename = substr($ztablename, 5); $sql = "SELECT max(id) as maxid FROM $tablename"; $maxid = DBUtil::getOneResultKey($sql, 'maxid'); $sql = "SELECT id FROM $ztablename"; $zseqid = DBUtil::getOneResultKey($sql, 'id'); $note = (is_null($maxid) || $maxid <= $zseqid)?'OK':'FAIL'; if ($note == 'FAIL' && $maxid > $zseqid) { $note = 'COUNTER PROBLEM! maxid should be less than or equal to zseq'; } if (PEAR::isError($maxid)) { $maxid = '??'; $note = "STRANGE - DB ERROR ON $tablename"; } if (PEAR::isError($zseqid)) { $zseqid = '??'; $note = "STRANGE - DB ERROR ON $ztablename"; } if (is_null($maxid)) { $maxid='empty'; } if (is_null($zseqid)) { $zseqid='empty'; $note = "STRANGE - ZSEQ SHOULD NOT BE EMPTY ON $ztablename"; } $zseqs .= "<tr><td>$tablename<td>$maxid<td>$zseqid<td>$note\r\n"; } $zseqs .= "</table>"; file_put_contents($filename, $zseqs); } /** * Get log files * * @param string $path */ private function capture_logs($path) { $path = $path . '/logs'; mkdir($path); $this->capture_kt_log($path); $this->capture_apache_log($path); $this->capture_php_log($path); $this->capture_mysql_log($path); } /** * Get Php log file. KT makes a php_error_log when tweak setting is enabled. * * @param string $path */ private function capture_php_log($path) { $config = KTConfig::getSingleton(); $logdir = $config->get('urls/logDirectory'); $logfile = $logdir . '/php_error_log'; if (file_exists($logfile)) { copy($logfile, $path . '/php-error_log.txt'); } } /** * Get mysql log from stack. It is difficult to resolve otherwise. * * @param string $path */ private function capture_mysql_log($path) { $stack_path = realpath(KT_DIR . '/../mysql/data'); if ($stack_path === false || !is_dir($stack_path)) { return; } $dh = opendir($stack_path); while (($filename = readdir($dh)) !== false) { if (substr($filename, -4) == '.log' && strpos($filename, 'err') !== false) { copy($stack_path . '/' . $filename, $path . '/mysql-' . $filename); } } closedir($dh); } /** * Get Apache log file from stack. It is difficult to resolve otherwise. * * @param string $path */ private function capture_apache_log($path) { $stack_path = realpath(KT_DIR . '/../apache2/logs'); if ($stack_path === false || !is_dir($stack_path)) { return; } $dh = opendir($stack_path); while (($filename = readdir($dh)) !== false) { if (substr($filename, -4) == '.log' && strpos($filename, 'err') !== false) { copy($stack_path . '/' . $filename, $path . '/apache-' . $filename); } } closedir($dh); } /** * Get KT log file. * * @param string $path */ private function capture_kt_log($path) { $date = date('Y-m-d'); $config = KTConfig::getSingleton(); $logdir = $config->get('urls/logDirectory'); $dh = opendir($logdir); while (($filename = readdir($dh)) !== false) { if (substr($filename,0,14) != 'log-' . $date) { continue; } copy($logdir . '/' . $filename, $path . '/kt-' . $filename); } closedir($dh); } /** * Get some basic info on Linux if possible. Get cpuinfo, loadavg, meminfo * * @param string $path */ private function get_sysinfo($path) { if (!OS_UNIX && !is_dir('/proc')) { return; } $path .= '/sysinfo'; mkdir($path); $this->get_sysinfo_file('cpuinfo', $path); $this->get_sysinfo_file('loadavg', $path); $this->get_sysinfo_file('meminfo', $path); } /** * Helper to get linux sysinfo * * @param string $filename * @param string $path */ private function get_sysinfo_file($filename, $path) { if (!is_readable('/proc/' . $filename)) { return; } $content = file_get_contents('/proc/' . $filename); file_put_contents($path . '/' . $filename . '.txt', $content); } /** * Helper to create the index file for the support archive. * * @param string $title * @param string $path * @param boolean $relative * @return string */ private function get_index_contents($title, $path, $relative = true) { if (!is_dir($path)) { return ''; } $contents = array(); $dh = opendir($path); while (($filename = readdir($dh)) !== false) { if (substr($filename,0,1) == '.') continue; $fullname = $path . '/' . $filename; if (!file_exists($fullname) || is_dir($fullname)) { continue; } $contents[] = $fullname; } closedir($dh); sort($contents); $html = $title; if (empty($contents)) { $html .= 'There is no content for this section.'; return $html; } $dir = ''; if ($relative) $dir = basename($path) . '/'; foreach($contents as $filename) { $corename = basename($filename); $ext = pathinfo($corename, PATHINFO_EXTENSION); $basename = substr($corename, 0, -strlen($ext)-1); $html .= "<a href=\"$dir$corename\">$basename</a><br>"; } return $html; } /** * Create the support archvie index.htm * * @param string $path */ private function create_index($path) { $contents = $this->get_index_contents('<h1>Support Info</h1><br>', $path, false); $contents .= $this->get_index_contents('<h2>System Info</h2>', $path . '/sysinfo'); $contents .= $this->get_index_contents('<h2>Logs</h2>', $path . '/logs'); $contents .= $this->get_index_contents('<h2>Schema</h2>', $path . '/schema'); file_put_contents($path . '/index.htm', $contents); } /** * Get list of tables based on InnoDB * * @param string $path */ private function create_storage_engine($path) { $html = '<h1>Table Storage Engines<h1>'; $html .= '<table>'; $html .= '<tr><td valign=top>'; $html .= '<h2>InnoDB</h2>'; foreach($this->innodb as $tablename) { $html .= "$tablename<br>"; } $html .= '<td valign=top>'; $html .= '<h2>Non-InnoDB</h2>'; foreach($this->noninnodb as $tablename) { $html .= "$tablename<br>"; } $html .= '</table>'; file_put_contents($path . '/tablestorage.htm', $html); }}?>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?