]>
git.defcon.no Git - hermes/blob - api/domain.php
b91a347bf602dfa1280593f914da22ac88bd4a31
2 require_once('config.php');
3 require_once('lib/common_functions.php');
4 require_once('lib/db_functions.php');
5 require_once('lib/domain_functions.php');
7 $config = get_config();
9 $config['sql_link'] = @mysql_connect
(
10 $config['sql_server'],
11 $config['sql_username'],
12 $config['sql_password']
14 if ( !$config['sql_link'] )
16 print json_encode( array( 'response' => 'failed', 'cause' => 'error', 'detail' => 'Database connection failed.'));
20 //*************************************************************************************
21 switch ( $_SERVER['PATH_INFO'] )
24 // Very simple call: Provide a list of domains registered with kamailio.
25 $domains = get_domains();
27 print json_encode( array( 'response' => 'failed', 'cause' => 'error', 'detail' => 'Database error.'));
29 print json_encode ( array( 'response' => 'ok', 'list' => $domains ) );
32 if ( array_key_exists('domain', $_GET))
34 $domain = $_GET['domain'];
35 if ( !$domain ||
$domain == "" )
36 print json_encode ( array( 'response' => 'invalid', 'cause' => 'parameters') );
38 $servers = get_servers( $domain );
41 print json_encode( array( 'response' => 'failed', 'cause' => 'nonexistant', 'detail' => 'Servers lookup failed for domain '. $domain ) );
44 $servers['domain'] = $domain;
45 print json_encode ( array ( 'response' => 'ok', 'servers' => $servers ) );
48 print json_encode ( array( 'response' => 'invalid', 'cause' => 'parameters') );
52 if ( array_key_exists('domain', $_GET)
53 && array_key_exists('registrar', $_GET)
54 && array_key_exists('r_port', $_GET)
55 && array_key_exists('proxy', $_GET)
56 && array_key_exists('p_port', $_GET)
57 && array_key_exists('prov_url', $_GET))
59 $domain = $_GET['domain'];
60 $registrar = $_GET['registrar'];
61 $r_port = $_GET['r_port'];
62 $proxy = $_GET['proxy'];
63 $p_port = $_GET['p_port'];
64 $prov_url = $_GET['prov_url'];
66 if (!($domain && $registrar && $r_port && $proxy && $p_port && $prov_url ))
68 print json_encode ( array( 'response' => 'invalid', 'cause' => 'parameters', 'detail' => 'One or more parameters NULL') );
72 if ( ! ( is_numeric( $r_port ) && is_numeric( $p_port ) ) )
74 print json_encode ( array( 'response' => 'invalid', 'cause' => 'parameters', 'detail' => 'One of the ports is not numeric.') );
78 if ( ! set_servers ( $domain, $registrar, $r_port, $proxy, $p_port, $prov_url ) )
80 print json_encode( array( 'response' => 'failed', 'cause' => 'error', 'detail' => 'Database error.'));
84 $servers = get_servers( $domain );
85 $servers['domain'] = $domain;
86 print json_encode ( array ( 'response' => 'ok', 'servers' => $servers ) );
89 print json_encode ( array( 'response' => 'invalid', 'cause' => 'parameters') );
95 print json_encode ( array( 'response' => 'invalid') );
97 //*************************************************************************************
98 mysql_close( $config['sql_link'] );