Manpages online

I have a tendency when surfing the net looking at software to try and find manpages online for things I see referenced or feel curious about. I don’t know why, but it seems like I’m constantly typing ‘man somecommand’ into Firefox’s url bar, which will usually find the correct manpage somewhere.

However, for want of consistency and speed, I decided to set up my own solution. I have my web server running PHP and Apach, so I am taking advantage of that. I wrote a small PHP page that checks for the manpage to your command and outputs it if the manpage is found. If it isn’t found, the results of ‘apropos’ are shown to see if you can find the correct command.

The page is quite simple. If no query is in the url, it shows a small text box which you can put your query in:

man1.png

When you put in your query, it shows the manpage:

man2.png

If the manpage is not found, it shows the output of apropos:

man3.png

That’s about all there is to it. It’s a simple tool for a task that bugs me often. If you have PHP installed on your computer you can probably use that and a local file to do the same thing without a webserver.

Source code is below.

Note the following limitations:

  • It can only show the manpages for the commands for programs installed on your computer… This is okay if you have it on your normal computer, but often a server has very different programs installed, and the commands are limited as such. This happens to be very useful when working on your server…
  • PHP’s safe_mode must be off to execute local shell commands.
  • This won’t work on Windows servers for obvious reasons (It uses the nix commands man and apropos).

Here is how to make a bookmarklet so that you can just type ‘man somecommand’ firefox (or any other browser) and get the manpage:

  • Go to ‘Organize Bookmarks’ (FF2) or ‘Show All Bookmarks’ (FF3).
  • Right click or click the button to create a new bookmark.
  • Name it whaever you want.
  • For location, type “http://path/to/server/man.php?man=%s”, replacing apropriate area with the path to your server.
  • Make ‘man’ the keyword for your bookmarklet.
  • Save

Now you can view manpages as much as you want from Firefox!

Just save the following source code in a PHP file and use away.

Source code:

<html>
<head>
<title>Manpage</title>
</head>
<body>
<?php
$man = $_GET['man'];
//echo($hash);
if ($man == null) {
echo('<p>Please enter the command you wish to find the manpage for.</p><form action="man.php" method="get"><p><input type="text" name="man" /><input type="submit" value="man" /></form>');
} else {
//echo($hash);
$command = shell_exec('man "' . $man . '"');
$apropos = shell_exec('apropos "' . $man . '"');
if ($command == null) {
echo('<p>Sorry, there is no manpage for ' . $man . '. Here is the output of apropos to help find the correct command:</p>' . "\n" . '<pre>' . "\n" . $apropos . '</pre>' . "\n");
} else {
echo('<p>The manpage for "' . $man . '" is:' . '</p>' . "\n" . '<pre>' . "\n" . $command . '</pre>' . "\n");
}
}
?>
</body>
</html>

Yeah, it looks bad. But if you copy it, it should paste perfectly, with all of the stuff you can’t see. I would offer a download, but for a file this short it’s overkill.

Licensed under GPL v.3. Do whatever you want to it, improve, modify. If you improve it, be sure to tell me, I’d like to see.

Daniel

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: