Mod xml curl CGI example
From FreeSWITCH Wiki
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:
1) clean it up.
2) Write sub functions for Error handling and Debugging
3) Write and interface with DB schema (I know this step is hard than it sounds)
4) Make dialplan section more dynamic (ditto)
#!/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 -= 0;
$year += 1900;
$month -= 0;
$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}) || print ERR qq![$month $day $year $hour:$min:$sec] [error] [freeswitch xml] Could not find file : $args{key_value}!;
$DEBUG && print ERR "[$month $day $year $hour:$min:$sec] [error] [freeswitch xml] -----BEGIN DEBUG-----\n";
$DEBUG && print ERR "----ARGS DUMP----\n";
foreach(keys %args)
{
$DEBUG && print ERR $_."->".$args{$_}."\n";
}
$DEBUG && 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") || print ERR qq![$month $day $year $hour:$min:$sec] [error] [freeswitch xml] Could not find file : /etc/freeswitch/dialplan.xml!;
$DEBUG && print ERR "[$month $day $year $hour:$min:$sec] [error] [freeswitch xml] -----BEGIN DEBUG-----\n";
$DEBUG && print ERR "----ARGS DUMP----\n";
foreach(keys %args)
{
$DEBUG && print ERR $_."->".$args{$_}."\n";
}
$DEBUG && 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";
foreach(keys %ENV)
{
$DEBUG && print ERR $_."->".$ENV{$_}."\n";
}
print ERR "----ARGS DUMP----\n";
foreach(keys %args)
{
$DEBUG && print ERR $_."->".$args{$_}."\n";
}
$DEBUG && print ERR "[$month $day $year $hour:$min:$sec] [error] [freeswitch xml] -----END DEBUG-----\n";
}
@file = <FILE>;
close FILE;
#####This where your tags in your templates are replaced with the correct data.
foreach(@file)
{
$_ =~ s/<##IP##>/$ENV{REMOTE_ADDR}/g;
}
print "Content Type: text/xml\n\n";
print @file;
foreach(keys %ENV)
{
$DEBUG && print $_."->".$ENV{$_};
$DEBUG && print "\n";
}
foreach(keys %args)
{
$DEBUG && print $_."->".$args{$_};
$DEBUG && print "\n";
}
close ERR;
exit;
[edit]
See Also
Mod xml curl , Mod xml curl C sharp example , Mod xml curl Ruby dialplan example
Categories: Modules | Curl | Integration
