]> git.defcon.no Git - hermes/blob - api/domain.php
Added domain/list, domain/get_server, domain/set_servers, updated sample SQL data...
[hermes] / api / domain.php
1 <?php
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');
6
7 $config = get_config();
8
9 $config['sql_link'] = @mysql_connect(
10 $config['sql_server'],
11 $config['sql_username'],
12 $config['sql_password']
13 );
14 if ( !$config['sql_link'] )
15 {
16 print json_encode( array( 'response' => 'failed', 'cause' => 'error', 'detail' => 'Database connection failed.'));
17 exit;
18 }
19
20 //*************************************************************************************
21 switch ( $_SERVER['PATH_INFO'] )
22 {
23 case "/list":
24 // Very simple call: Provide a list of domains registered with kamailio.
25 $domains = get_domains();
26 if ( $domains == -1 )
27 print json_encode( array( 'response' => 'failed', 'cause' => 'error', 'detail' => 'Database error.'));
28 else
29 print json_encode ( array( 'response' => 'ok', 'list' => $domains ) );
30 break;
31 case "/get_servers":
32 if ( array_key_exists('domain', $_GET))
33 {
34 $domain = $_GET['domain'];
35 if ( !$domain || $domain == "" )
36 print json_encode ( array( 'response' => 'invalid', 'cause' => 'parameters') );
37
38 $servers = get_servers( $domain );
39 if ( !$servers )
40 {
41 print json_encode( array( 'response' => 'failed', 'cause' => 'nonexistant', 'detail' => 'Servers lookup failed for domain '. $domain ) );
42 break;
43 }
44 $servers['domain'] = $domain;
45 print json_encode ( array ( 'response' => 'ok', 'servers' => $servers ) );
46 break;
47 }
48 print json_encode ( array( 'response' => 'invalid', 'cause' => 'parameters') );
49 break;
50
51 case "/set_servers":
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))
58 {
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'];
65
66 if (!($domain && $registrar && $r_port && $proxy && $p_port && $prov_url ))
67 {
68 print json_encode ( array( 'response' => 'invalid', 'cause' => 'parameters', 'detail' => 'One or more parameters NULL') );
69 break;
70 }
71
72 if ( ! ( is_numeric( $r_port ) && is_numeric( $p_port ) ) )
73 {
74 print json_encode ( array( 'response' => 'invalid', 'cause' => 'parameters', 'detail' => 'One of the ports is not numeric.') );
75 break;
76 }
77
78 if ( ! set_servers ( $domain, $registrar, $r_port, $proxy, $p_port, $prov_url ) )
79 {
80 print json_encode( array( 'response' => 'failed', 'cause' => 'error', 'detail' => 'Database error.'));
81 break;
82 }
83
84 $servers = get_servers( $domain );
85 $servers['domain'] = $domain;
86 print json_encode ( array ( 'response' => 'ok', 'servers' => $servers ) );
87 break;
88 }
89 print json_encode ( array( 'response' => 'invalid', 'cause' => 'parameters') );
90 break;
91
92
93
94 default:
95 print json_encode ( array( 'response' => 'invalid') );
96 }
97 //*************************************************************************************
98 mysql_close( $config['sql_link'] );
99 ?>