Miscellaneous
|
|
|
|
<?php
/***************************************************************************
*
* Author: Carlo Tafuro <carlo.tafuro@poste.it>
*
* Updated: 13:00 CET (GMT + 1.00h) October 15, 2004
*
* Script name: PHPMan2HTML
*
* Description: This script allows you to view man pages through web a browser.
*
***************************************************************************/
// Report all PHP errors
//error_reporting (E_ALL);
define('cat', '/bin/cat'); define('col', '/usr/bin/col'); define('file', '/usr/bin/file'); define('find', '/usr/bin/find'); define('gzip', '/bin/gzip'); define('man', '/usr/bin/man'); define('man2html', '/usr/bin/man2html');
if (empty($_SERVER['QUERY_STRING'])) {
echo '<div align="center">';
echo '<h2>Man Pages</h2>';
echo '<hr>';
echo '<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="5" cellspacing="0">';
echo '<tr>';
echo '<td>1)</td>';
echo '<td><a href="'.$_SERVER['PHP_SELF'].'?section=1">User commands</a></td>';
echo '<td>Those commands that can be executed by the user from within a shell</td>';
echo '</tr>';
echo '<tr>';
echo '<td>2)</td>';
echo '<td><a href="'.$_SERVER['PHP_SELF'].'?section=2">System calls</a></td>';
echo '<td>Those functions which must be performed by the kernel</td>';
echo '</tr>';
echo '<tr>';
echo '<td>3)</td>';
echo '<td><a href="'.$_SERVER['PHP_SELF'].'?section=3">Library functions</a></td>';
echo '<td>Most of the libc functions</td>';
echo '</tr>';
echo '<tr>';
echo '<td>4)</td>';
echo '<td><a href="'.$_SERVER['PHP_SELF'].'?section=4">Special files</a></td>';
echo '<td>Files found in /dev </td></tr>';
echo '<tr>';
echo '<td>5)</td>';
echo '<td><a href="'.$_SERVER['PHP_SELF'].'?section=5">File formats</a></td>';
echo '<td>Files found in /etc </td></tr>';
echo '<tr>';
echo '<td>6)</td>';
echo '<td><a href="'.$_SERVER['PHP_SELF'].'?section=6">Games</a></td>';
echo '<td>-</td>';
echo '</tr>';
echo '<tr>';
echo '<td>7)</td>';
echo '<td><a href="'.$_SERVER['PHP_SELF'].'?section=7">Macro packages and conventions</a></td>';
echo '<td>A description of the standard file system layout, network protocols, ASCII and other character codes, this man page, and other things</td>';
echo '</tr>';
echo '<tr>';
echo '<td>8)</td>';
echo '<td><a href="'.$_SERVER['PHP_SELF'].'?section=8">System management commands</a></td>';
echo '<td>Commands like mount(8), many of which only root can execute.</td>';
echo '</tr>';
echo '</table>';
echo '<hr>';
echo '</div>';
echo 'see: <a href="'.$_SERVER['PHP_SELF'].'?1+man">man(1)</a> <a href="'.$_SERVER['PHP_SELF'].'?7+man">man(7)</a>';
} else {
if ($_GET['section']) {
if (!is_numeric($_GET['section'])) {
$_GET['section'] = '1';
}
$man_path = substr(shell_exec(man.' -w'), 0, -1);
$man_path_array = explode(':', $man_path);
$man_files = '';
while (list (, $curr_man_path) = each ($man_path_array)) {
$man_files .= shell_exec(find.' '.$curr_man_path.' -type f -name "*.'.$_GET['section'].'*"');
}
$man_files = substr($man_files, 0, strrpos($man_files,chr(10)));
$man_files_array = explode(chr(10), $man_files);
while (list (, $curr_man_file) = each ($man_files_array)) {
$page = basename($curr_man_file);
$page = substr($page, 0, strpos($page, '.'.$_GET['section']));
$page_list[$page] = $curr_man_file;
}
ksort($page_list);
reset($page_list);
$i=1;
echo '<h4><a href="'.$_SERVER['PHP_SELF'].'">Return to Main Contents</a></h4>';
echo '<hr>';
echo '<table border="0" cellpadding="0" cellspacing="0" width="100%">';
while (list ($curr_man_page, $curr_man_path) = each ($page_list)) {
echo '<tr>';
echo '<td width="30%">'.$i++.')</td>';
echo '<td width="30%"><a href="'.$_SERVER['PHP_SELF'].'?'.$_GET['section'].'+'.$curr_man_page.'">'.$curr_man_page.'</a></td>';
echo '<td width="40%">'.$curr_man_path.'</td>';
echo '</tr>';
}
echo '</table>';
echo '<hr><h4><a href="'.$_SERVER['PHP_SELF'].'">Return to Main Contents</a></h4>';
} else {
$_SERVER['QUERY_STRING'] = escapeshellcmd(str_replace('+', ' ', $_SERVER['QUERY_STRING']));
$output = shell_exec(file.' -Lb `'.man.' -w '.$_SERVER['QUERY_STRING'].'`');
$type = substr($output, 0, strpos($output,' '));
switch ($type) {
case 'gzip':
$cmd = gzip.' -dc';
break;
case 'troff':
$cmd = cat;
break;
default:
$cmd = cat;
}
$cmd .= ' `'.man.' -w '.$_SERVER['QUERY_STRING'].'` | '.man2html.' -H '.$_SERVER['SERVER_NAME'].' -M '.$_SERVER['PHP_SELF'].' | '.col.' -b';
system($cmd);
}
}
?>
|
|
|
Usage Example
|
|
|
Rate This Script
|
|
|
|