From: Jon Langseth Date: Wed, 18 Jan 2012 16:16:01 +0000 (+0100) Subject: Added domain/list, domain/get_server, domain/set_servers, updated sample SQL data... X-Git-Url: https://git.defcon.no/?a=commitdiff_plain;h=ff9f68b23637a5393ad2d349f4c052e8be084f85;p=hermes Added domain/list, domain/get_server, domain/set_servers, updated sample SQL data to more valid content, added domain-table to config, updated tests ... --- diff --git a/api/domain.php b/api/domain.php new file mode 100644 index 0000000..b91a347 --- /dev/null +++ b/api/domain.php @@ -0,0 +1,99 @@ + 'failed', 'cause' => 'error', 'detail' => 'Database connection failed.')); + exit; +} + +//************************************************************************************* + switch ( $_SERVER['PATH_INFO'] ) + { + case "/list": + // Very simple call: Provide a list of domains registered with kamailio. + $domains = get_domains(); + if ( $domains == -1 ) + print json_encode( array( 'response' => 'failed', 'cause' => 'error', 'detail' => 'Database error.')); + else + print json_encode ( array( 'response' => 'ok', 'list' => $domains ) ); + break; + case "/get_servers": + if ( array_key_exists('domain', $_GET)) + { + $domain = $_GET['domain']; + if ( !$domain || $domain == "" ) + print json_encode ( array( 'response' => 'invalid', 'cause' => 'parameters') ); + + $servers = get_servers( $domain ); + if ( !$servers ) + { + print json_encode( array( 'response' => 'failed', 'cause' => 'nonexistant', 'detail' => 'Servers lookup failed for domain '. $domain ) ); + break; + } + $servers['domain'] = $domain; + print json_encode ( array ( 'response' => 'ok', 'servers' => $servers ) ); + break; + } + print json_encode ( array( 'response' => 'invalid', 'cause' => 'parameters') ); + break; + + case "/set_servers": + if ( array_key_exists('domain', $_GET) + && array_key_exists('registrar', $_GET) + && array_key_exists('r_port', $_GET) + && array_key_exists('proxy', $_GET) + && array_key_exists('p_port', $_GET) + && array_key_exists('prov_url', $_GET)) + { + $domain = $_GET['domain']; + $registrar = $_GET['registrar']; + $r_port = $_GET['r_port']; + $proxy = $_GET['proxy']; + $p_port = $_GET['p_port']; + $prov_url = $_GET['prov_url']; + + if (!($domain && $registrar && $r_port && $proxy && $p_port && $prov_url )) + { + print json_encode ( array( 'response' => 'invalid', 'cause' => 'parameters', 'detail' => 'One or more parameters NULL') ); + break; + } + + if ( ! ( is_numeric( $r_port ) && is_numeric( $p_port ) ) ) + { + print json_encode ( array( 'response' => 'invalid', 'cause' => 'parameters', 'detail' => 'One of the ports is not numeric.') ); + break; + } + + if ( ! set_servers ( $domain, $registrar, $r_port, $proxy, $p_port, $prov_url ) ) + { + print json_encode( array( 'response' => 'failed', 'cause' => 'error', 'detail' => 'Database error.')); + break; + } + + $servers = get_servers( $domain ); + $servers['domain'] = $domain; + print json_encode ( array ( 'response' => 'ok', 'servers' => $servers ) ); + break; + } + print json_encode ( array( 'response' => 'invalid', 'cause' => 'parameters') ); + break; + + + + default: + print json_encode ( array( 'response' => 'invalid') ); + } +//************************************************************************************* +mysql_close( $config['sql_link'] ); +?> diff --git a/api/lib/domain_functions.php b/api/lib/domain_functions.php new file mode 100644 index 0000000..d28c0be --- /dev/null +++ b/api/lib/domain_functions.php @@ -0,0 +1,61 @@ +