Skip to main content

mod_xml_curl CGI example

About

mod_xml_curl usage example using CGI.

From email list

(James Jones <james _AT_ virtualrealmsoftware.com>):

Here is a little script that I have start to write to use with mod_xml_curl. It is nothing special.
It is really a dirty little script, but it might be helpful in guiding a few people in the right direction.
If you have any question please email me.

Next step for the script

  • Clean it up.
  • Write sub functions for Error handling and Debugging.
  • Write and interface with DB schema (I know this step is hard than it sounds)
  • Make dialplan section more dynamic (ditto)

The script itself

#!/usr/bin/perl

# XML_curl cgi example
#
# Written by outcast aka James Jones <james@virtualrealmsoftware.com>
#
# DISCLAIMER:
#
# This is not a finished product. This is just me playing around with mod_xml_curl.
# I hope you kind of get the idea of what is going on here.
# If not email me. I would be happy to answer any questions.


$DEBUG = 0;
$error_file = "/var/www/logs/freeswitch_config_log";
open(ERR,">>",$error_file);

($sec,$min,$hour,$day,$month,$year) = (localtime) [0,1,2,3,4,5];
$year += 1900;
$month += 1;

if($min < 10) {
$min = "0".$min;
}
if($hour < 10) {
$hour = "0".$hour;
}
$date = "$month-$day-$year";
$curtime = "$date $hour:$min";

if ($ENV{REQUEST_METHOD} eq "POST") {
read(STDIN, $query, $ENV{CONTENT_LENGTH});
}
elsif ($ENV{REQUEST_METHOD} eq "GET") {
$query = $ENV{QUERY_STRING};
}
if ($query) {
@fields = split("&", $query);
foreach (@fields)
{
($type, $arg) = /([^=]+)=(.*)/g;
$arg =~ s/\+/ /g;
$arg =~ s/%([0-9A-H]{2})/pack('C',hex($1))/eg;
$arg =~ s/;.8$//g;
$args{$type} = $arg;
}
}

if($args{section} eq "configuration")
{
open(FILE,"</etc/freeswitch/".$args{key_value}) or print ERR qq![$month $day $year $hour:$min:$sec] [error] [freeswitch xml] Could not find file : $args{key_value}!;
$DEBUG and print ERR "[$month $day $year $hour:$min:$sec] [error] [freeswitch xml] -----BEGIN DEBUG-----\n";
$DEBUG and print ERR "----ARGS DUMP----\n";
while(($k,$v) = each %args)
{
$DEBUG and print ERR "$k->$v\n";
}
$DEBUG and print ERR "[$month $day $year $hour:$min:$sec] [error] [freeswitch xml] -----END DEBUG-----\n";
}
elsif($args{section} eq "dialplan")
{
open(FILE,"</etc/freeswitch/dialplan.xml") or print ERR qq![$month $day $year $hour:$min:$sec] [error] [freeswitch xml] Could not find file : /etc/freeswitch/dialplan.xml!;
$DEBUG and print ERR "[$month $day $year $hour:$min:$sec] [error] [freeswitch xml] -----BEGIN DEBUG-----\n";
$DEBUG and print ERR "----ARGS DUMP----\n";
while(($k,$v) = each %args)
{
$DEBUG and print ERR "$k->$v\n";
}
$DEBUG and print ERR "[$month $day $year $hour:$min:$sec] [error] [freeswitch xml] -----END DEBUG-----\n";
}
else
{
print ERR "[$month $day $year $hour:$min:$sec] [error] [freeswitch xml] -----BEGIN DEBUG-----\n";
while(($k,$v) = each %ENV)
{
$DEBUG and print ERR "$k->$v\n";
}
print ERR "----ARGS DUMP----\n";
while(($k,$v) = each %args)
{
$DEBUG and print ERR "$k->$v\n";
}

$DEBUG and print ERR "[$month $day $year $hour:$min:$sec] [error] [freeswitch xml] -----END DEBUG-----\n";
}


while(<FILE>)
{
#####This where your tags in your templates are replaced with the correct data.
s/<##IP##>/$ENV{REMOTE_ADDR}/g;

print;
}
close FILE;


print "Content Type: text/xml\n\n";
print @file;
while(($k,$v) = each %ENV)
{
$DEBUG and print "$k->$v\n";
}
while(($k,$v) = each %args)
{
$DEBUG and print "$k->$v\n";
}

close ERR;
exit;