[Freeswitch-svn] [commit] r12654 - in freeswitch/trunk/scripts/contrib/swk: . php/xml_curl

FreeSWITCH SVN silik0n at freeswitch.org
Wed Mar 18 02:38:18 PDT 2009


Author: silik0n
Date: Wed Mar 18 04:38:18 2009
New Revision: 12654

Log:
xml_curl of the directory is now working... this means you can manage the users from the UI see the README for installation instructions

Added:
   freeswitch/trunk/scripts/contrib/swk/php/xml_curl/
   freeswitch/trunk/scripts/contrib/swk/php/xml_curl/FSDirectory.php
   freeswitch/trunk/scripts/contrib/swk/php/xml_curl/directory.php
Modified:
   freeswitch/trunk/scripts/contrib/swk/README

Modified: freeswitch/trunk/scripts/contrib/swk/README
==============================================================================
--- freeswitch/trunk/scripts/contrib/swk/README	(original)
+++ freeswitch/trunk/scripts/contrib/swk/README	Wed Mar 18 04:38:18 2009
@@ -23,8 +23,30 @@
 
 make the files in amf-test1/bin-debug available on your webserver and point a browser at it.
 
+copy the php/xml_curl directory to your webserver 
+
+make sure you have mod_xml_curl built and installed and enabled
+	uncomment it in the modules.conf in your source tree
+	uncomment it in your modules.conf.xml in the conf/autoload_configs/modules.conf.xml
+
+
+edit the gateway_url param in conf/autoload_configs/xml_curl.conf.xml to enabale the directory binding
+EXAMPLE:
+	<param name="gateway-url" value="http://localhost/xml_curl/directory.php" bindings="directory"/>
+
+
+rename conf/directory/default.xml to conf/directory/default.xml.NOLOAD
+	this is no longer required as we are now loading the directory using xml_curl
+
+
 If you are developing in flex you need to load the swf from your development webserver so that it can properly locate the service. 
 
-Any questions, feel free to find me as SwK via IRC at #freeswitch on irc.freenode.net
+Any questions, feel free to find me as SwK via IRC at #freeswitch on irc.freenode.net or krice AT freeswitch DOT org
+
 
+TODO:
+Fix Groups and Group Editing
+Fix Conference Controls
+Rework PHP Class Files for both the amfphp service and the xml_curl there is no need to maintain these seperately as they share a fair ammount of code
+anything else I can come up with
 

Added: freeswitch/trunk/scripts/contrib/swk/php/xml_curl/FSDirectory.php
==============================================================================
--- (empty file)
+++ freeswitch/trunk/scripts/contrib/swk/php/xml_curl/FSDirectory.php	Wed Mar 18 04:38:18 2009
@@ -0,0 +1,156 @@
+<?php
+
+/* 
+ * FreeSWITCH AMF-PHP ESL Client Library
+ * Copyright (C) 2009, Ken Rice <krice at tollfreegateway.com>
+ *
+ * Version: MPL 1.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
+ *
+ * The Initial Developer of the Original Code is
+ * Ken Rice <krice at tollfreegateway.com>
+ * Portions created by the Initial Developer are Copyright (C)
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ * 
+ * Ken Rice <krice at tollfreegateway.com>
+ *
+ * freeswitch.php -- Initial Class file for XML_CURL responses for Codename: SHIPMENT
+ *
+ ***************************************************************************************************
+ * 
+ * This Requires the FreeSWITCH ESL Extension to be installed properly on your system.
+ *
+ */
+
+// require_once "ESL.php";
+ 
+class FSDirectory {
+	// var $esl;
+
+	var $dbh;
+
+	public function __construct(){
+		$dbtype='mysql'; 		/* Set the Database type */
+		// $db_hostname = 'localhost'; 	/* Database Server hostname */
+		$db_hostname = '192.168.1.140'; 	/* Database Server hostname */
+		$db_port = '3306';		/* Database Server Port */
+		$db_username = 'root'; 		/* Database Server username */
+		$db_password = 'password'; 	/* Database Server password */
+		$db_database = 'shipment'; 	/* DataBase Name */
+		if ($dbtype == 'mysql') {
+			$pdo_flags =  array(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true,);
+		}
+		$this->dbh = new PDO("$dbtype:host=$db_hostname;port=$db_port;dbname=$db_database", $db_username, $db_password, $pdo_flags);
+		
+	}
+
+        private function getESL() { 
+		$esl_server = "127.0.0.1"; 	/* ESL Server */
+		$esl_port = "8021"; 		/* ESL Port */
+		$esl_secret = "ClueCon"; 	/* ESL Secret */
+		$this->esl = new eslConnection($esl_server, $esl_port, $esl_secret);
+	}
+
+	/*
+	public function getStatus() {
+		$e = $this->esl->sendRecv("api status");
+		$body = $e->getBody();
+		return $body;
+	}
+	*/
+
+	/*** Directory Methods ***/
+	
+	/* Directory Domain Methods */
+	public function getDirDomains(){
+		$query = sprintf("select * from domains");
+		$stmt = $this->dbh->query($query);
+		$results = $stmt->fetchAll();
+		return $results;
+	}
+
+	public function getDirDomainbyName($domain_name){
+		$query = sprintf("select * from domains where name = '%s'", $domain_name);
+		$stmt = $this->dbh->query($query);
+		$results = $stmt->fetchAll();
+		return $results[0];
+	}
+
+	public function getDirDomain($domains_uid){
+		$query = sprintf("select * from domain_params where domains_uid = $domains_uid");
+		$stmt = $this->dbh->query($query);
+		$results['params'] = $stmt->fetchAll();
+		$query = sprintf("select * from domain_variables where domains_uid = $domains_uid");
+		$stmt = $this->dbh->query($query);
+		$results['variables'] = $stmt->fetchAll();
+		return $results;
+	}
+	
+	/* Directory User Methods */
+	public function getDirUser($user_uid){
+		$query = sprintf("select * from user_params where users_uid = $user_uid");
+		$stmt = $this->dbh->query($query);
+		$results['params'] = $stmt->fetchAll();
+		$query = sprintf("select * from user_variables where users_uid = $user_uid");
+		$stmt = $this->dbh->query($query);
+		$results['variables'] = $stmt->fetchAll();
+		return $results;
+	}
+
+	public function getDirUsers($domains_uid){
+		$query = sprintf("select * from users where domains_uid = $domains_uid");
+		$stmt = $this->dbh->query($query);
+		$results = $stmt->fetchAll();
+		return $results;
+	}
+
+	public function getDirUsersByDomainUidByUsername($domain_uid, $user_name){
+		$query = sprintf("select * from users where domains_uid = '%s' and username = '%s'", $domain_uid, $user_name);
+		$stmt = $this->dbh->query($query);
+		$results = $stmt->fetchAll();
+		return $results[0];
+	}
+
+	/* Directory Group Methods */
+	public function getDirGroups($domains_uid){
+		$query = sprintf("select * from groups where domains_uid = $domains_uid");
+		$stmt = $this->dbh->query($query);
+		$results = $stmt->fetchAll();
+		return $results;
+	}
+
+	public function getDirGroup($groups_uid){
+		$query = sprintf("select a.uid as groupMemberUid, a.users_uid as usersUid, b.username as usersUsername from group_members as a, users as b where a.groups_uid = $groups_uid and a.users_uid = b.uid") ;
+		$stmt = $this->dbh->query($query);
+		$results['members'] = $stmt->fetchAll();
+		$query = sprintf("select uid as usersUid, username as usersUsername from users where uid not in (select users_uid from group_members where groups_uid = $groups_uid) and domains_uid = (select domains_uid from groups where uid = $groups_uid)");
+		$stmt = $this->dbh->query($query);
+		$results['nonmembers'] = $stmt->fetchAll();
+		return $results;
+	}
+
+}
+/* For Emacs:
+ * Local Variables:
+ * mode:c
+ * indent-tabs-mode:t
+ * tab-width:4
+ * c-basic-offset:4
+ * End:
+ * For VIM:
+ * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab:
+ */
+?>

Added: freeswitch/trunk/scripts/contrib/swk/php/xml_curl/directory.php
==============================================================================
--- (empty file)
+++ freeswitch/trunk/scripts/contrib/swk/php/xml_curl/directory.php	Wed Mar 18 04:38:18 2009
@@ -0,0 +1,73 @@
+<?
+
+require_once "FSDirectory.php";
+
+
+header ("content-type: text/xml");
+
+foreach ($_REQUEST as $key => $value) {
+	$$key = $value;
+}
+
+$fsd = new FSDirectory();
+
+/* Uncomment and edit for debugging */
+/*
+$section = "directory";
+$tag_name= "domain";
+$key_name ="name";
+$key_value="192.168.1.140";
+$user="1000";
+*/
+if ($section == "directory" && $tag_name == "domain" && $key_name == "name") {
+	$db_domain = $fsd->getDirDomainbyName($key_value);
+} else {
+	printf("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<document type=\"freeswitch/xml\">\n<section name=\"result\">\n".
+    		"<result status=\"not found\" />\n</section>\n</document>");
+	die();
+}
+
+$db_user = $fsd->getDirUsersByDomainUidByUsername($db_domain['uid'], $user);
+
+$db_user_settings = $fsd->getDirUser($db_user['uid']);
+
+$db_groups = $fsd->getDirGroups($db_domain['uid']);
+
+printf(" <?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n");
+printf("   <document type=\"freeswitch/xml\">\n");
+printf("      <section name=\"directory\" description=\"Codename: Shipment Directory\">\n");
+printf("         <domain name=\"%s\">\n", $db_domain['name']);
+printf("           <groups>\n");
+printf("             <group name=\"default\">\n");
+printf("               <users>\n");
+printf("		 <user id=\"%s\" mailbox=\"%s\">\n", $db_user['username'], $db_user['mailbox']);
+printf("		  <params>\n");
+foreach($db_user_settings['params'] as $db_params) {
+	printf("		   <param name=\"%s\" value=\"%s\"/>\n", $db_params['name'], $db_params['value']);
+}
+printf("		  </params>\n");
+printf("		  <variables>\n");
+foreach($db_user_settings['variables'] as $db_variables) {
+	printf("		   <variable name=\"%s\" value=\"%s\"/>\n", $db_variables['name'], $db_variables['value']);
+}
+printf("		  </variables>\n");
+printf("		 </user>\n");
+printf("               </users>\n");
+printf("             </group>\n");
+/*  This is Broken need to talk to someone about this part... maybe I should load this at boot time instead 
+foreach($db_groups as $db_group){
+	$db_members = $fsd->getDirGroup($db_group['uid']);
+	printf("             <group name=\"%s\">\n", $db_group['name']);
+	printf("               <users>\n");
+	foreach($db_members['members'] as $db_member){
+		printf("		 <user id=\"%s\" type=\"pointer\"/>\n", $db_member['usersUsername']);
+	}
+	printf("               </users>\n");
+	printf("             </group>\n");
+}
+*/
+printf("           </groups>\n");
+printf("         </domain>\n");
+printf("      </section>\n");
+printf("   </document>\n");
+?>



More information about the Freeswitch-svn mailing list