IPTables Generator
August 19th, 2008I have written a quick script to help generate IPTables config files..
It can be found here.
Any question, improvements or feature requests, contact me…
I have written a quick script to help generate IPTables config files..
It can be found here.
Any question, improvements or feature requests, contact me…

What I dont understand is that apple advertise their systems have ‘Crash Proof Technology’ and ‘It just works’. My work machine quite often ‘does not work’, namely hangs. However, my vista box at home has been rebooted about 3 times in the last 6 months!
But wait, theres more!
According to Apple, their operating system is always up to date. This is an all-out lie. For example, the recent DNS poisoning exploit was not fixed by Apple until some time after all the other Operating System developers had fixed it [theregister]. You would have thought that it would have been fixed sooner - most of the OS* has been developed in the Open Source community, so they could’ve just nicked someone else’s update and claimed it as their own. Dont get me wrong, I do like Macs, and OSX, but what I cant stand is big corporations like Apple blatantly lying and releasing stuff without testing properly.
In the time I have written this, Apple have probably released 4 new versions of iTunes*, each at nearly 50 megs.
* Perhaps a slight exaggeration
There are quite a lot of quirks that I dont like about Apples OSX operating system, and below are a few scripts I use day to day that seem to be a necessity:
Finding and removing .DS_Store files (which can cause AFP to lock up):
find . -name *.DS_Store -type f -exec rm {} \;
Finding and removing .fstemp files (these get created by homesync on OSX, and when it cant handle locked files, it leaves these behind which cause annoying sync errors)
find ~ -name *.fstemp* -type f -exec rm -fr {} \;
Recursively find and unlock files:
chflags -R nouchg ~/
Find out what applications are making what connections:
sudo lsof -i
I have been working on Trixbox - A free Telephony distro which is powered by Linux, FreePBX (Although now they have unbranded it as FreePBX and fobbing it off as their own), and have some rather childish senior staff.
We finally got it provisioned and plugged into a BT PRI ISDN line. One thing I liked to do was keep an eye on things. In my mind, more information is better than less, so in my lunch hour, I quickly scraped together this little bit of code to show the status of the ZAP trunks coming from a redfone device. It uses AJAX and PHP, and updates every second.
This is your index.html file, which I is my pretty generic AJAX base:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Asterisk Realtime Statistics</title> <script type="text/javascript"> function Ajax(){ var xmlHttp; try{ xmlHttp=new XMLHttpRequest();// Firefox, Opera 8.0+, Safari } catch (e){ try{ xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer } catch (e){ try{ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ alert("WTF..? No AJAX!?"); return false; } } } xmlHttp.onreadystatechange=function(){ if(xmlHttp.readyState==4){ document.getElementById('pending').innerHTML= xmlHttp.responseText; setTimeout('Ajax()',1000); } } xmlHttp.open("GET","http://asterisk.server/_channels.php",true); xmlHttp.send(null); } window.onload=function(){ Ajax(); } </script> <style type="text/css"> <!-- body,td,th { font-family: Geneva, Arial, Helvetica, sans-serif; font-size: 10px; } --> </style></head> <body> <h1>Asterisk Realtime Statistics</h1> Incoming/Outgoing Lines <div id="pending">Please wait..</div> </body> </html>
..and this is your _channels.php:
<?
$socket = fsockopen(.localhost.,.5038., $errno, $errstr, 60);
$response = fread($socket, 8192);
if ($errstr) die($errstr.“\n”.$response);
fputs($socket, “Action: Login\r\n”);
fputs($socket, “UserName: admin\r\n”);
fputs($socket, “Secret: amp111\r\n\r\n”);
$responsee=fread($socket, 8192);
fputs($socket, “Action: Command\r\n”);
fputs($socket, “Command: zap show channels\r\n\r\n”);
while (!eregi(“END COMMAND”,$response)) {
$response=fgets($socket);
$resp.=$response;
}
$resp=explode(“MOH Interpret”,$resp);
$zapchannels= str_replace(“–END COMMAND–”,“”,$resp[1]);
echo $zapchannels;
fclose($socket);
?>
I buggered up my install of Vista after trying out Kalyway with a dual boot system going on.
Subsquently, I buggered up my partition table and marked vista as inactive.
To fix it, I booted up in Recovery mode and used the command prompt:
diskpart (enter)
select disk 0 (enter)
select partition 1 (enter) (nb I have a recovery partition in partition 0, so Vista was 1)
(nb it was either
set active (enter) set active or just active - cant remember..)
exit (enter)
bootrec /fixmbr (enter)
rootrec /fixboot (enter)
Rebooted. All fixed.
Because I did not have an OEM DVD, I installed linux over the top of the HFS partition, and used GRUB, which detected my windows install. When windows started up, I switched the computer off which then gave me the ability to access the Repair mode.
I have spent ages writing a middleman script to pull information from our core database and set up extensions in Asterisk (Trixbox).
I cant give the full script, but the most important things you need to do are:
1) Insert the data into the MySQL tables for FreePBX:
<?php
$query = "INSERT INTO asterisk.sip (id,keyword,data,flags) ";
$query.= "VALUES ('$extension','context','ncos-$ncos','')";
execquery($query,$msql);
$query = "INSERT INTO asterisk.sip (id,keyword,data,flags) ";
$query.= "VALUES ('$extension','account','$extension','')";
execquery($query,$msql);
$query = "INSERT INTO asterisk.sip (id,keyword,data,flags) ";
$query.= "VALUES ('$extension','mailbox','$extension@device','0')";
execquery($query,$msql);
$query = "INSERT INTO asterisk.sip (id,keyword,data,flags) ";
$query.= "VALUES ('$extension','secret','$secret','')";
execquery($query,$msql);
$query = "INSERT INTO asterisk.sip (id,keyword,data,flags) ";
$query.= "VALUES ('$extension','accountcode','','')";
execquery($query,$msql);
$query = "INSERT INTO asterisk.sip (id,keyword,data,flags) ";
$query.= "VALUES ('$extension','port','5060','')";
execquery($query,$msql);
$query = "INSERT INTO asterisk.sip (id,keyword,data,flags) ";
$query.= "VALUES ('$extension','pickupgroup','$pickup','')";
execquery($query,$msql);
$query = "INSERT INTO asterisk.sip (id,keyword,data,flags) ";
$query.= "VALUES ('$extension','callgroup','$pickup','')";
execquery($query,$msql);
$query = "INSERT INTO asterisk.sip (id,keyword,data,flags) ";
$query.= "VALUES ('$extension','disallow','','')";
execquery($query,$msql);
$query = "INSERT INTO asterisk.sip (id,keyword,data,flags) ";
$query.= "VALUES ('$extension','allow','','')";
execquery($query,$msql);
$query = "INSERT INTO asterisk.sip (id,keyword,data,flags) ";
$query.= "VALUES ('$extension','dial','SIP/$extension','')";
execquery($query,$msql);
$query = "INSERT INTO asterisk.sip (id,keyword,data,flags) ";
$query.= "VALUES ('$extension','dtmfmode','rfc2833','')";
execquery($query,$msql);
$query = "INSERT INTO asterisk.sip (id,keyword,data,flags) ";
$query.= "VALUES ('$extension','canreinvite','no','')";
execquery($query,$msql);
$query = "INSERT INTO asterisk.sip (id,keyword,data,flags) ";
$query.= "VALUES ('$extension','qualify','";
if ($phonetype == 'CISCO') { $query.="no"; } else { $query.='yes'; }
$query.= "','')";
execquery($query,$msql);
$query = "INSERT INTO asterisk.sip (id,keyword,data,flags) ";
$query.= "VALUES ('$extension','host','dynamic','')";
execquery($query,$msql);
$query = "INSERT INTO asterisk.sip (id,keyword,data,flags) ";
$query.= "VALUES ('$extension','type','friend','')";
execquery($query,$msql);
$query = "INSERT INTO asterisk.sip (id,keyword,data,flags) ";
$query.= "VALUES ('$extension','nat','";
if ($phonetype == 'CISCO') { $query.="never"; } else { $query.='yes';}
$query.= "','')";
execquery($query,$msql);
$query = "INSERT INTO asterisk.sip (id,keyword,data,flags) ";
$query.= "VALUES ('$extension','callerid','device <".$extension.">','')";
execquery($query,$msql);
$query = "INSERT INTO asterisk.sip (id,keyword,data,flags) ";
$query.= "VALUES ('$extension','record_in','Adhoc','')";
execquery($query,$msql);
$query = "INSERT INTO asterisk.sip (id,keyword,data,flags) ";
$query.= "VALUES ('$extension','record_out','Adhoc','')";
execquery($query,$msql);
?>
2) Enter the details into the Berkeley database:
<?php
$berkeley[]='database put DEVICE '.$extension.'/default_user '.$extension;
$berkeley[]='database put DEVICE '.$extension.'/dial SIP/'.$extension;
$berkeley[]='database put DEVICE '.$extension.'/type fixed';
$berkeley[]='database put DEVICE '.$extension.'/user ';
$berkeley[]='database put DEVICE '.$extension.'/context from-internal';
$berkeley[]='database put AMPUSER '.$extension.'/noanswer ""';
$berkeley[]='database put AMPUSER '.$extension.'/outboundcid ""';
$berkeley[]='database put AMPUSER '.$extension.'/cidname "';
$berkeley[]='database put AMPUSER '.$extension.'/cidnum ';
$berkeley[]='database put AMPUSER '.$extension.'/device ';
$berkeley[]='database put AMPUSER '.$extension.'/context from-internal';
$berkeley[]='database put AMPUSER '.$extension.'/recording out=Adhoc|in=Adhoc';
$berkeley[]='database put AMPUSER '.$extension.'/ringtimer 20';
$berkeley[]='database put AMPUSER '.$extension.'/voicemail ';
?>
3) Get the stuff into the berkeley database:
<?php echo “Connecting to Asterisk manager interface…\n”; $socket = fsockopen(‘localhost’,‘5038′, $errno, $errstr, 60); $response = fread($socket, 8192); if ($errstr) die($errstr.“\n”.$response); fputs($socket, “Action: Login\r\n”); fputs($socket, “UserName: admin\r\n”); fputs($socket, “Secret: amp111\r\n\r\n”); $response=fread($socket, 8192); // read the entire output into $response $count=count($berkeley); echo ‘Total records: ’.$count.“\n\n”; foreach ($berkeley as $command) { $total++; fputs($socket, “Action: Command\r\n”); fputs($socket, “Command: $command\r\n\r\n”); while (!eregi(‘–END COMMAND–’,$response)) { $response=fgets($socket); echo “Remaining: $remain \r”; $resp.=$response; } if (!eregi(‘Successfully’,$resp)) echo “\n Alert: does not specify success\n$resp\n”; $response=”; $resp=”; } echo “Finished.\n”; fputs($socket, “Action: Logoff\r\n\r\n”); $response = @fread($socket, 8192); @fclose($socket); ?>
To help, I can say that the first two sections need to be loops, and the execquery() is just a mysql function to do the query - set up a connection at the start, and in the function use global to use the function. $msql is the handle for the mysql connection.
Damn..
The only night I go out and drink, I get a phone call to come back home.
Well, 5 1/2 weeks early, weighing 5 pounds 13oz, which is pretty good….