PHP

Palladion – Scripting and time stamps.

I like to have Palladion execute scripts overnight and email the results in a CSV. The issue that I faced was that scripts require you to enter a start and end time. Logging in at 10pm to execute a post dial delay script was not an efficient use of my personal time.

I built the following functions to obtain the current time and then obtain the time from 24 hours ago. Then return these into the format that Palladion expects.  You can easily modify the “then()” function to look at a different time range.

import time
import datetime
from time import strptime

def now():
        # This fuction obtains the current time and returns it as a "datetime.datetime" object.
        now = time.gmtime()
        now2 = datetime.datetime(*now[:6])
        return now2

def then():
        # This function obtains the time from 24 hours ago and returns it as a "datetime.datetime" object.
        then1 = time.time()-86000
        then2 = time.gmtime(then1)
        then3 = datetime.datetime(*then2[:6])
        return then3

def run(facade,params): 
        #Script entry point. 
	start_ts = then()
	end_ts = now()
Categories: PHP, SIP, Uncategorized, VOIP | Tags: , | Leave a comment

Web based dig using PHP

Here is something a little different. I attempted to make a very basic web based utility.

The front page utilizes a JavaScript framework from  http://www.prototypejs.org/ by Sam Stephenson to perform from AJAX magic.

Next is a very basic PHP script that executes the dig command from the local server. All of the output from the dig is placed into an array and then printed to the screen.

<-- Begin dig.html -->

<html>
<head>
<script type="text/javascript" src="xajax_core.js"></script>
<script>

function Dig() {
new Ajax.Request("webdig2.php",
{
method: 'post',
postBody: 'T1='+ $F('GetDomain') +'&dropdown='+ $F('options'),

onComplete: ShowDig
});
}

function ShowDig(req){
$('show').innerHTML= req.responseText;
}

</script>
<style type="text/css">
body {
color: green;
background-color: white;
font-size: medium; }
</style>

</head>

<body>

<b>Please enter the domain name. For PTR (Reverse DNS) you must enter the IP address.</b>
<br>
<br>

<form id ="Dig" onsubmit="return false;">
Domain / IP <input type="text" Name="domain" id="GetDomain" />
<select name="dropdown" value="options" id="options">
<option value="ARec">A Record</option>
<option value="CNAME">CNAME Record</option>
<option value="MX">MX Record</option>
<option value="SRV">SRV Record</option>
<option value="PTR">PTR / Reverse DNS</option>
</select>

<input type="submit" value="lookup" onClick="Dig()">

</form>
<br />
<br />
<br />
<br />

<div id="show"> </div>
</body>

</html>

<-- End Dig.html-->>

<-- Begin webdig2.php -->
<?php

import_request_variables('p', 'p_');

function print_r_html ($arr) {
?><pre><?
print_r($arr);
?></pre><?
}

// Define Variables from the form.
$VAR1 = "$p_T1";
$VAR3 = "$p_dropdown";

function ARECORD() {
global $VAR1;
exec("dig $VAR1 A ", $OUT);
for ( $i=0; $i < count($OUT); $i++) {
print_r_html ($OUT[$i]) ;
}
exit;
}

function CNAMERECORD(){
global $VAR1;
exec("dig $VAR1 CNAME ", $OUT);
for ( $i=0; $i < count($OUT); $i++) {
print_r_html ($OUT[$i]) ;
}

exit;
}

function MXRECORD(){
global $VAR1;
exec("dig $VAR1 MX ", $OUT);
for ( $i=0; $i < count($OUT); $i++) {
print_r_html ($OUT[$i]) ;
}

exit;
}

function SRVRECORD(){
global $VAR1;
exec("dig $VAR1 SRV ", $OUT);
for ( $i=0; $i < count($OUT); $i++) {
print_r_html ($OUT[$i]) ;
}

exit;
}

function PTRECORD(){
global $VAR1;
exec("dig -x $VAR1 ", $OUT);
for ( $i=0; $i < count($OUT); $i++) {
print_r_html ($OUT[$i]) ;
}

exit;
}

if ( $VAR3 == "ARec" ) ARECORD ();
if ( $VAR3 == "CNAME" ) CNAMERECORD ();
if ( $VAR3 == "MX" ) MXRECORD ();
if ( $VAR3 == "SRV" ) SRVRECORD ();
if ( $VAR3 == "PTR" ) PTRECORD ();
else;
exit;

?>

<-- End webdig2.php -->
Categories: PHP | Tags: , | 1 Comment

Blog at WordPress.com.