Squid cachemgr.cgi UI hack

Squid has a little system statistics viewer built-in:

The cache manager (cachemgr.cgi) is a CGI utility for displaying statistics about the squid process as it runs. The cache manager is a convenient way to manage the cache and view statistics without logging into the server.
(from Squid FAQ)

The only thing is … it’s so ugly! It uses plain HTML and cannot be customized, the FAQ says. However, there is a way to do it:

  1. copy cachemgr.cgi to cachemgr2.cgi so if you do something wrong, the original is not lost.
  2. open the CGI file in a text-editor. I used vi, but if you’re not used to working with it, use something else (emacs?).
  3. in the binary file, look for some text portions that look like HTML code
  4. while keeping in mind that the # of characters should remain the same, change the <title> and <style> to something that suits you. You will have to do this at 2 locations in the file: one for the homepage template and one for the other pages’ template.
  5. suggestion: just let the CGI use a style.css file that you drop into the same folder.
    <link rel="stylesheet" type="text/css" href="style.css" mce_href="style.css" /> and fill up with spaces to keep the same # characters
  6. verify that the cachemgr and the cachemgr2 have the same # bytes
  7. now use cachemgr2 to display your statistics.
  8. I did something a bit different (I wanted to use the CSS of my own website), so I ‘ll show you the difference between the two versions.
    In order to get to the following comparison, I did a strings cachemgr.cgi > cachemgr.txt to extract only the text parts, and I did a diff cachemgr.txt cachemgr2.txt to compare both files. You cannot do a file comparison of 2 binary files.

    < <HTML><HEAD><TITLE>Cache Manager Interface</TITLE>
    < <STYLE type="text/css"><!-- BODY{background-color:#ffffff;font-family:verdana,sans-serif} --></STYLE></HEAD>
    > <HTML><HEAD><TITLE>Cache Manager (pforret)</TITLE>
    > <link rel="stylesheet" type="text/css" href="http://www.forret.com/forret/forret.css" mce_href="http://www.forret.com/forret/forret.css" /> </HEAD>
    < <STYLE type="text/css"><!-- BODY{background-color:#ffffff;font-family:verdana,sans-serif} TABLE{background-color:#333333;border:0pt;padding:0pt}TH,TD{background-color:#ffffff}--></STYLE>
    > <link rel="stylesheet" type=text/css href="http://www.forret.com/forret/forret.css" mce_href="http://www.forret.com/forret/forret.css"><!-- TABLE{background-color:#333333;border:0pt;padding:0pt} TH,TD{background-color:#ffffff}--></STYLE>

    1 thought on “Squid cachemgr.cgi UI hack”

    1. or you could edit the cachemgr.c file that compiles into the cgi as much as you like then compile it.

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    This site uses Akismet to reduce spam. Learn how your comment data is processed.