'failed', 'cause' => 'error', 'detail' => 'Database connection failed.')); exit; } token_auth(); //************************************************************************************* 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'] ); ?>