[Freeswitch-svn] [commit] r5503 - in freeswitch/trunk/scripts/contrib/trixter/xml-curl: . modules

Freeswitch SVN trixter at freeswitch.org
Fri Jul 6 21:22:20 EDT 2007


Author: trixter
Date: Fri Jul  6 21:22:20 2007
New Revision: 5503

Added:
   freeswitch/trunk/scripts/contrib/trixter/xml-curl/modules/
   freeswitch/trunk/scripts/contrib/trixter/xml-curl/modules/configuration.php
   freeswitch/trunk/scripts/contrib/trixter/xml-curl/modules/dialplan.php
Modified:
   freeswitch/trunk/scripts/contrib/trixter/xml-curl/README
   freeswitch/trunk/scripts/contrib/trixter/xml-curl/curlrouting.php

Log:
module based now for handling requests, better readme, better error control


Modified: freeswitch/trunk/scripts/contrib/trixter/xml-curl/README
==============================================================================
--- freeswitch/trunk/scripts/contrib/trixter/xml-curl/README	(original)
+++ freeswitch/trunk/scripts/contrib/trixter/xml-curl/README	Fri Jul  6 21:22:20 2007
@@ -1 +1,30 @@
+This is an example that will respond to mod_xml_curl requests for information.
+It uses modules, which are contained in the modules subdirectory.  If a module
+(any file ending in .php) is in the dir it will be loaded.  If it registers
+to handle a specific type of xml_curl request, that will be passed to the function named.
+If you dont have a module for a specific type of data, for example directory, then
+a 404 will be returned to FreeSWITCH.  
+
+The module nature allows you to more easily turn on/off different components.  
+
+Its a template based system, which relies on someone authenticating, such as with
+.htaccess.  Their username is used in this default example for their configuration
+files.  This allows for multiple switches to identify themselves uniquely, as well
+as giving you the ability to have different templates for different switches.
+
+
+
+PREREQUISITES
 You will need to get smarty from http://smarty.php.net to make this work
+
+If you install it globally, edit your php.ini to make the Smarty/libs dir as part
+of the search path, otherwise add the following to curlrouting.php near the other 
+ini_set line.  Adjust it to suit your particular setup.
+
+ini_set("include_path",".:/usr/local/lib/php:/usr/share/php:./Smarty-2.6.18/libs");
+
+
+
+You also must create a directory named templates_c where you install this, its a smarty
+requirement for caching templates.  This directory *must* be writable by the webserver
+or Smarty will not properly operate.

Modified: freeswitch/trunk/scripts/contrib/trixter/xml-curl/curlrouting.php
==============================================================================
--- freeswitch/trunk/scripts/contrib/trixter/xml-curl/curlrouting.php	(original)
+++ freeswitch/trunk/scripts/contrib/trixter/xml-curl/curlrouting.php	Fri Jul  6 21:22:20 2007
@@ -1,65 +1,30 @@
 <?php  //  -*- mode:c; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil;  -*-
 Header("Content-type: text/plain");
 
-ini_set("include_path",".:/usr/local/lib/php:/usr/share/php:./Smarty-2.6.18/libs");
+$callBacks = Array();
+ini_set("magic_quotes_gpc","Off");
 include_once('Smarty.class.php');
 
-
-if (isset($_POST['section']) && $_POST['section']=="dialplan") {
-	// create a new smarty object
-	$smarty = new Smarty();
-	$template = 'fail.tpl';
-
-
-	// see if they authenticated via .htaccess
-	if(isset($_SERVER['REMOTE_USER']) && $_SERVER['REMOTE_USER']!="") {
-        // we might check a database for  the route, but in this example we hardcode it
-        $template = 'frompstn.tpl'; // one can exist for each profile or channel type or ...
-
-        $ACTION['javascript']="somethingcool.js";
-        $ACTION['bridge']="sofia/external/".$_POST['destination_number']."@myprovider.tld";
-        $smarty->assign('ACTION',$ACTION);
-
-    } // end - they were logged in
-	$smarty->display($_SERVER['DOCUMENT_ROOT']."/templates/".$_SERVER['REMOTE_USER']."/".$template);
-} else if (isset($_POST['section']) && $_POST['section']=="configuration") {
-		$smarty = new Smarty();
-		$template = $_POST['key_value'].".tpl";
-		switch($_POST['key_value']) {
-        case "conference.conf":
-            // simulate data from a database, perhaps a table with 3 columns did,value,args
-            $digits['pin'] = '1234';
-            $digits['anounce-count'] = '2';
-            $digits['max-mmebers'] = '15';
-            $digits['energy-level'] = '300';
-            $params['0'] = 'event';
-            $params['1'] = 'event';
-            $params['2'] = 'event';
-            $params['3'] = 'event';
-            $params['4'] = 'event';
-            $params['5'] = 'event';
-            $params['6'] = 'event';
-            $params['7'] = 'event';
-            $params['8'] = 'event';
-            $params['9'] = 'event';
-            $params['#'] = 'event';
-            $params['*'] = 'event';
+// load the modules
+$dh = @opendir("./modules") or die("Unable to open modules dir");
+while ($file = readdir($dh)) {
+    if(preg_match("/.*\.php$/i",$file)) {
+        include_once("modules/$file");
+    }
+}
 
 
-            $smarty->assign('CONFNAME',$_POST['conf_name']);
-            $smarty->assign('digits',$digits);
-            $smarty->assign('params',$params);
-		}
-		if($smarty->template_exists($_SERVER['DOCUMENT_ROOT']."/templates/".$_SERVER['REMOTE_USER']."/".$template)) {
-			$smarty->display($_SERVER['DOCUMENT_ROOT']."/templates/".$_SERVER['REMOTE_USER']."/".$template);
-		} else {
-            //			//logCallData();
-			error_log("Unable to locate template $template");
-			$smarty->assign('CONFNAME',$_POST['key_value']);
-			$smarty->display($_SERVER['DOCUMENT_ROOT']."/templates/".$_SERVER['REMOTE_USER']."/default.conf.tpl");
-		}
-} else if (isset($_POST['section']) && $_POST['section']=="directory") {
-    // we dont do anything but you get the idea
+if(isset($_POST['section'])) {
+    if(isset($callBacks[$_POST['section']])) {
+        call_user_func($callBacks[$_POST['section']]);
+        exit;
+    }
 }
+$_SERVER['REMOTE_USER']="switch1";
+$_POST['key_value']='conference.conf';
+call_user_func($callBacks['configuration']);
+//Header("HTTP/1.0 404 Not Found");
+//echo "Not Found";
+exit;
 
 ?>

Added: freeswitch/trunk/scripts/contrib/trixter/xml-curl/modules/configuration.php
==============================================================================
--- (empty file)
+++ freeswitch/trunk/scripts/contrib/trixter/xml-curl/modules/configuration.php	Fri Jul  6 21:22:20 2007
@@ -0,0 +1,46 @@
+<?php  //  -*- mode:c; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil;  -*-
+function configuration()
+{
+    global $_SERVER;
+    global $_POST;
+
+    $smarty = new Smarty();
+    $template = $_POST['key_value'].".tpl";
+    switch($_POST['key_value']) {
+    case "conference.conf":
+        // simulate data from a database, perhaps a table with 3 columns did,value,args
+        $digits['pin'] = '1234';
+        $digits['anounce-count'] = '2';
+        $digits['max-mmebers'] = '15';
+        $digits['energy-level'] = '300';
+        $params['0'] = 'event';
+        $params['1'] = 'event';
+        $params['2'] = 'event';
+        $params['3'] = 'event';
+        $params['4'] = 'event';
+        $params['5'] = 'event';
+        $params['6'] = 'event';
+        $params['7'] = 'event';
+        $params['8'] = 'event';
+        $params['9'] = 'event';
+        $params['#'] = 'event';
+        $params['*'] = 'event';
+
+        $smarty->assign('CONFNAME',$_POST['conf_name']);
+        $smarty->assign('digits',$digits);
+        $smarty->assign('params',$params);
+    }
+    if($smarty->template_exists($_SERVER['DOCUMENT_ROOT'].dirname($_SERVER['PHP_SELF'])."/templates/".$_SERVER['REMOTE_USER']."/".$template)) {
+        $smarty->display($_SERVER['DOCUMENT_ROOT'].dirname($_SERVER['PHP_SELF'])."/templates/".$_SERVER['REMOTE_USER']."/".$template);
+    } else {
+        //			//logCallData();
+        error_log("Unable to locate template $template");
+        $smarty->assign('CONFNAME',$_POST['key_value']);
+        $smarty->display($_SERVER['DOCUMENT_ROOT'].dirname($_SERVER['PHP_SELF'])."/templates/".$_SERVER['REMOTE_USER']."/default.conf.tpl");
+    }
+}
+
+// register the callback
+$callBacks['configuration']='configuration';
+
+?>

Added: freeswitch/trunk/scripts/contrib/trixter/xml-curl/modules/dialplan.php
==============================================================================
--- (empty file)
+++ freeswitch/trunk/scripts/contrib/trixter/xml-curl/modules/dialplan.php	Fri Jul  6 21:22:20 2007
@@ -0,0 +1,29 @@
+<?php  //  -*- mode:c; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil;  -*-
+function dialplan()
+{
+    global $_SERVER;
+
+
+    // create a new smarty object
+	$smarty = new Smarty();
+	$template = 'fail.tpl';
+
+
+	// see if they authenticated via .htaccess
+	if(isset($_SERVER['REMOTE_USER']) && $_SERVER['REMOTE_USER']!="") {
+        // we might check a database for  the route, but in this example we hardcode it
+        $template = 'frompstn.tpl'; // one can exist for each profile or channel type or ...
+
+        $ACTION['javascript']="somethingcool.js";
+        $ACTION['bridge']="sofia/external/".$_POST['destination_number']."@myprovider.tld";
+        $smarty->assign('ACTION',$ACTION);
+
+    } // end - they were logged in
+	$smarty->display($_SERVER['DOCUMENT_ROOT']."/templates/".$_SERVER['REMOTE_USER']."/".$template);
+}
+
+
+// register the callback
+$callBacks['dialplan']='dialplan';
+
+?>



More information about the Freeswitch-svn mailing list