]>
git.defcon.no Git - hermes/blob - phone.php
2 require_once('config.php');
3 require_once('lib/user_functions.php');
4 require_once('lib/common_functions.php');
5 require_once('lib/db_functions.php');
6 require_once('lib/phone_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.'));
21 //*************************************************************************************
22 switch ( $_SERVER['PATH_INFO'] )
25 // Required GET parameters:
26 // user: authentication username, SIP-username without domain component
27 // domain: Domain/realm of the user. username + '@' + domain == SIP address.
28 if ( array_key_exists( 'mac', $_GET) )
31 $relations = get_phone_users ( $mac );
34 print json_encode( array( 'response' => 'ok', 'list' => $relations ));
36 else print json_encode( array ( 'response' => 'failed', 'cause' => 'nonexistant', 'detail' => 'No results.'));
38 else if ( array_key_exists( 'user', $_GET ) )
40 $user = split_sipaddress($_GET['user']);
43 print json_encode ( array( 'response' => 'failed', 'cause' => 'nonexistant', 'detail' => 'Invalid SIP address') );
46 list ( $username, $domain ) = $user;
47 $userdata = get_user_phones( $username, $domain );
50 print json_encode( array( 'response' => 'ok', 'list' => $userdata ));
52 else print json_encode( array ( 'response' => 'failed', 'cause' => 'nonexistant', 'detail' => 'No results.'));
56 print json_encode ( array( 'response' => 'invalid') );
59 // List all (distinct) phone MAC-adresses registered...
61 if ( array_key_exists('search', $_GET ) )
62 $search = $_GET['search'];
64 $phones = list_phones( $search );
65 print json_encode( array( 'response' => 'ok', 'list' => $phones ));
71 mac The MAC-address of the phone to add an entry for
73 user A registered username on user@domain form (SIP address)
75 username A registered username, combines with:
76 domain A valid domain .. to form a registered user@domain combo :)
79 if ( array_key_exists('mac', $_GET ) &&
80 ( array_key_exists('user', $_GET) ||
81 ( array_key_exists('username', $_GET) && array_key_exists('domain', $_GET ))))
85 if ( array_key_exists('username', $_GET) )
87 $username = $_GET['username'];
88 $domain = $_GET['domain'];
92 $user = split_sipaddress($_GET['user']);
95 print json_encode ( array( 'response' => 'failed', 'cause' => 'invalid', 'detail' => 'Invalid SIP address') );
98 list ( $username, $domain ) = $user;
100 $mac = clean_mac($_GET['mac']);
103 print json_encode ( array( 'response' => 'failed', 'cause' => 'invalid', 'detail' => 'No valid MAC address given.') );
107 if ( !is_provision_user ( $username, $domain ) )
109 print json_encode( array ( 'response' => 'failed', 'cause' => 'nonexistant', 'detail' => 'User not registered.'));
112 $phones = get_user_phones ( $username, $domain);
113 if ( $phones && in_array( $mac, $phones ) )
115 print json_encode( array ( 'response' => 'failed', 'cause' => 'exists', 'detail' => 'This phone and user combination is already configured..'));
118 $res = add_phone_user ( $mac, $username, $domain );
121 print json_encode( array ( 'response' => 'failed', 'cause' =>'dbfail', 'detail' => 'Failed to add phone to database.'));
126 print json_encode( array ( 'response' => 'ok', 'data' => array (
127 'mac' => $mac, 'username' => $username, 'domain' => $domain) ));
133 print json_encode ( array( 'response' => 'invalid') );
141 mac The MAC-address of the phone to add an entry for
143 user A registered username on user@domain form (SIP address)
145 username A registered username, combines with:
146 domain A valid domain .. to form a registered user@domain combo :)
149 if ( array_key_exists('mac', $_GET ) &&
150 ( array_key_exists('user', $_GET) ||
151 ( array_key_exists('username', $_GET) && array_key_exists('domain', $_GET ))))
155 if ( array_key_exists('username', $_GET) )
157 $username = $_GET['username'];
158 $domain = $_GET['domain'];
162 $user = split_sipaddress($_GET['user']);
165 print json_encode ( array( 'response' => 'failed', 'cause' => 'invalid', 'detail' => 'Invalid SIP address') );
168 list ( $username, $domain ) = $user;
170 $mac = clean_mac($_GET['mac']);
173 print json_encode ( array( 'response' => 'failed', 'cause' => 'invalid', 'detail' => 'No valid MAC address given.') );
177 $phones = get_user_phones ( $username, $domain);
178 if ( ! $phones ||
!in_array( $mac, $phones ) )
180 print json_encode( array ( 'response' => 'failed', 'cause' => 'nonexistant', 'detail' => 'Unable to locate requested combination'));
183 $res = delete_phone_user ( $mac, $username, $domain );
186 print json_encode( array ( 'response' => 'failed', 'cause' =>'dbfail', 'detail' => 'Failed to remove phone from database.'));
191 print json_encode( array ( 'response' => 'ok' ));
197 print json_encode ( array( 'response' => 'invalid') );
202 print json_encode ( array( 'response' => 'invalid') );
204 mysql_close( $config['sql_link'] );