logo
members lotus mg pics linux hacks links contact
How to show PHP source code | RSS for NINAN | ADSL Fix

How to show PHP source code
To format PHP code to be shown via HTML run php -s -q source.php > output.html. Handy!


RSS Feed for NINAN

NOTE: This script is now pretty much redundant. I have worked with the NINAN developers and RSS support is now included in the NINAN application!

A handy php script for NINAN that generates an RSS feed that can be added as a live bookmark to Firefox. It'll show you how quick your downloads are going ;)

NOTE: You need to be using a MySQL database with NINAN, not the built-in Java one. Sorry!

<?php

$db
= mysql_connect("db-host", "ninan", "ninan-db-password");
mysql_select_db("ninan",$db);

$sql="SELECT SUM(THREADSPEED) from THREADSTATUS";
$result = @mysql_query($sql, $db);

?>
<rss version="2.0">
<channel>
        <title>NINAN Stats</title>
        <link>http://ninan.sf.net</link>
        <description>stats from NINAN</description>
        <language>en-gb</language>
        <lastBuildDate><?echo(exec ("/bin/date -R"));?></lastBuildDate>
        <copyright>jeff@potchin.co.uk</copyright>
        <docs>http://www.potchin.co.uk/</docs>
        <ttl>5</ttl>
<item>
<title><?
    
if (exec("ps -ef | grep nina[n] | wc -l")){
    while (
$row = mysql_fetch_array($result)) {
    echo
"Ninan now @ ". round($row[0], 1) ."KB/sec.";
    }}
    else{echo
"Ninan DEAD!";}
?></title>
        <description>Ninan Speed</description>
        <link>http://ninan-host:9090/ninan/secure/index.jsp</link>
</item>
</channel>
</rss>

and here's how it looks in Firefox...


Fixing my ADSL Line
Another quick little scrip that I've knocked up. For some reason, known only by BT, my ADSL connection randomly loses sync and the ADSL service needs to be restarted. This is a bit tricky when I'm not at home, so I made a script that's run regualrly from cron. It checks that the line is in sync, if it isn't then it automatically restarts the necessary services .
<?
$status_tabbed 
exec("/usr/bin/cnxadslstatus | grep NO | wc -l");
$status =  trim($status_tabbed);
//echo $status;
if ($status){
    echo(
exec ("date +\"%T %a %D\""));
    echo 
"\nADSL Line Lost Sync, killing pppd...";
    
exec("kill `ps -ef | grep ppp[d] | awk '{print $2}'`");
    echo 
"\npppd killed, stopping ADSL service...";
    
sleep(10);
    
exec("/sbin/service cnxadslctl stop");
    echo 
"\nADSL service stopped, restarting now...";
    
exec("/sbin/service cnxadslctl start");
    echo 
"\nADSL service restarted, restarting network";
    
exec ("/sbin/service network restart");
    echo 
"\nNetwork back online, reconfiguring firewall...";
        
exec ("/sbin/service shorewall restart");
    echo 
"\nADSL should be back online, woohoo!\n";
    echo(
exec ("date +\"%T %a %D\""));
    die();
}
?>

potchin [v]: To alter excessively or needlessly
  Server up 79 days 5 hrs 59 mins