]>
git.defcon.no Git - hermes/blob - api/domain.php
7c8a797b6067dd84339ad9a08032a7b6d61e3966
2 require_once('config.php');
3 require_once('lib/auth_base.php');
4 require_once('lib/common_functions.php');
5 require_once('lib/db_functions.php');
6 require_once('lib/domain_functions.php');
8 $config = get_config();
10 $config['sql_link'] = @mysql_connect
(
11 $config['sql_server'],
12 $config['sql_username'],
13 $config['sql_password']
15 if ( !$config['sql_link'] )
17 print json_encode( array( 'response' => 'failed', 'cause' => 'error', 'detail' => 'Database connection failed.'));
23 //*************************************************************************************
24 switch ( $_SERVER['PATH_INFO'] )
27 // Very simple call: Provide a list of domains registered with kamailio.
28 $domains = get_domains();
30 print json_encode( array( 'response' => 'failed', 'cause' => 'error', 'detail' => 'Database error.'));
32 print json_encode ( array( 'response' => 'ok', 'list' => $domains ) );
35 if ( array_key_exists('domain', $_GET))
37 $domain = $_GET['domain'];
38 if ( !$domain ||
$domain == "" )
39 print json_encode ( array( 'response' => 'invalid', 'cause' => 'parameters') );
41 $servers = get_servers( $domain );
44 print json_encode( array( 'response' => 'failed', 'cause' => 'nonexistant', 'detail' => 'Servers lookup failed for domain '. $domain ) );
47 $servers['domain'] = $domain;
48 print json_encode ( array ( 'response' => 'ok', 'servers' => $servers ) );
51 print json_encode ( array( 'response' => 'invalid', 'cause' => 'parameters') );
55 if ( array_key_exists('domain', $_GET)
56 && array_key_exists('registrar', $_GET)
57 && array_key_exists('r_port', $_GET)
58 && array_key_exists('proxy', $_GET)
59 && array_key_exists('p_port', $_GET)
60 && array_key_exists('prov_url', $_GET))
62 $domain = $_GET['domain'];
63 $registrar = $_GET['registrar'];
64 $r_port = $_GET['r_port'];
65 $proxy = $_GET['proxy'];
66 $p_port = $_GET['p_port'];
67 $prov_url = $_GET['prov_url'];
69 if (!($domain && $registrar && $r_port && $proxy && $p_port && $prov_url ))
71 print json_encode ( array( 'response' => 'invalid', 'cause' => 'parameters', 'detail' => 'One or more parameters NULL') );
75 if ( ! ( is_numeric( $r_port ) && is_numeric( $p_port ) ) )
77 print json_encode ( array( 'response' => 'invalid', 'cause' => 'parameters', 'detail' => 'One of the ports is not numeric.') );
81 if ( ! set_servers ( $domain, $registrar, $r_port, $proxy, $p_port, $prov_url ) )
83 print json_encode( array( 'response' => 'failed', 'cause' => 'error', 'detail' => 'Database error.'));
87 $servers = get_servers( $domain );
88 $servers['domain'] = $domain;
89 print json_encode ( array ( 'response' => 'ok', 'servers' => $servers ) );
92 print json_encode ( array( 'response' => 'invalid', 'cause' => 'parameters') );
98 print json_encode ( array( 'response' => 'invalid') );
100 //*************************************************************************************
101 mysql_close( $config['sql_link'] );