]>
git.defcon.no Git - hermes/blob - api/domain.php
3 # Copyright (c) 2012, Gjøvik University College
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are met:
8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above copyright
11 # notice, this list of conditions and the following disclaimer in the
12 # documentation and/or other materials provided with the distribution.
13 # * Neither the name of the Gjøvik University College nor the
14 # names of its contributors may be used to endorse or promote products
15 # derived from this software without specific prior written permission.
17 # THIS SOFTWARE IS PROVIDED BY Gjøvik University College ''AS IS'' AND ANY
18 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 # DISCLAIMED. IN NO EVENT SHALL Gjøvik University College BE LIABLE FOR ANY
21 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 require_once('config.php');
29 require_once('lib/auth_base.php');
30 require_once('lib/common_functions.php');
31 require_once('lib/db_functions.php');
32 require_once('lib/domain_functions.php');
34 $config = get_config();
36 $config['sql_link'] = @mysql_connect
(
37 $config['sql_server'],
38 $config['sql_username'],
39 $config['sql_password']
41 if ( !$config['sql_link'] )
43 print json_encode( array( 'response' => 'failed', 'cause' => 'error', 'detail' => 'Database connection failed.'));
49 //*************************************************************************************
50 switch ( $_SERVER['PATH_INFO'] )
53 // Very simple call: Provide a list of domains registered with kamailio.
54 $domains = get_domains();
56 print json_encode( array( 'response' => 'failed', 'cause' => 'error', 'detail' => 'Database error.'));
58 print json_encode ( array( 'response' => 'ok', 'list' => $domains ) );
61 if ( array_key_exists('domain', $_POST))
63 $domain = $_POST['domain'];
64 if ( !$domain ||
$domain == "" )
65 print json_encode ( array( 'response' => 'invalid', 'cause' => 'parameters') );
67 $servers = get_servers( $domain );
70 print json_encode( array( 'response' => 'failed', 'cause' => 'nonexistant', 'detail' => 'Servers lookup failed for domain '. $domain ) );
73 $servers['domain'] = $domain;
74 print json_encode ( array ( 'response' => 'ok', 'servers' => $servers ) );
77 print json_encode ( array( 'response' => 'invalid', 'cause' => 'parameters') );
81 if ( array_key_exists('domain', $_POST)
82 && array_key_exists('registrar', $_POST)
83 && array_key_exists('r_port', $_POST)
84 && array_key_exists('proxy', $_POST)
85 && array_key_exists('p_port', $_POST)
86 && array_key_exists('prov_url', $_POST))
88 $domain = $_POST['domain'];
89 $registrar = $_POST['registrar'];
90 $r_port = $_POST['r_port'];
91 $proxy = $_POST['proxy'];
92 $p_port = $_POST['p_port'];
93 $prov_url = $_POST['prov_url'];
95 if (!($domain && $registrar && $r_port && $proxy && $p_port && $prov_url ))
97 print json_encode ( array( 'response' => 'invalid', 'cause' => 'parameters', 'detail' => 'One or more parameters NULL') );
101 if ( ! ( is_numeric( $r_port ) && is_numeric( $p_port ) ) )
103 print json_encode ( array( 'response' => 'invalid', 'cause' => 'parameters', 'detail' => 'One of the ports is not numeric.') );
107 if ( ! set_servers ( $domain, $registrar, $r_port, $proxy, $p_port, $prov_url ) )
109 print json_encode( array( 'response' => 'failed', 'cause' => 'error', 'detail' => 'Database error.'));
113 $servers = get_servers( $domain );
114 $servers['domain'] = $domain;
115 print json_encode ( array ( 'response' => 'ok', 'servers' => $servers ) );
118 print json_encode ( array( 'response' => 'invalid', 'cause' => 'parameters') );
124 print json_encode ( array( 'response' => 'invalid') );
126 //*************************************************************************************
127 mysql_close( $config['sql_link'] );