]>
git.defcon.no Git - hermes/blob - phone.php
9437d66b47738961781d344ca57c5fd2172d5573
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( 'username', $_GET) && array_key_exists( 'domain', $_GET ) ) ||
array_key_exists('user', $_GET) )
42 if ( array_key_exists('username', $_GET) )
44 $username = $_GET['username'];
45 $domain = $_GET['domain'];
49 $user = split_sipaddress($_GET['user']);
52 print json_encode ( array( 'response' => 'failed', 'cause' => 'invalid', 'detail' => 'Invalid SIP address') );
55 list ( $username, $domain ) = $user;
58 $userdata = get_user_phones( $username, $domain );
61 print json_encode( array( 'response' => 'ok', 'list' => $userdata ));
63 else print json_encode( array ( 'response' => 'failed', 'cause' => 'nonexistant', 'detail' => 'No results.'));
67 print json_encode ( array( 'response' => 'invalid') );
70 // List all (distinct) phone MAC-adresses registered...
72 if ( array_key_exists('search', $_GET ) )
73 $search = $_GET['search'];
75 $phones = list_phones( $search );
76 print json_encode( array( 'response' => 'ok', 'list' => $phones ));
82 mac The MAC-address of the phone to add an entry for
84 user A registered username on user@domain form (SIP address)
86 username A registered username, combines with:
87 domain A valid domain .. to form a registered user@domain combo :)
90 if ( array_key_exists('mac', $_GET ) &&
91 ( array_key_exists('user', $_GET) ||
92 ( array_key_exists('username', $_GET) && array_key_exists('domain', $_GET ))))
96 if ( array_key_exists('username', $_GET) )
98 $username = $_GET['username'];
99 $domain = $_GET['domain'];
103 $user = split_sipaddress($_GET['user']);
106 print json_encode ( array( 'response' => 'failed', 'cause' => 'invalid', 'detail' => 'Invalid SIP address') );
109 list ( $username, $domain ) = $user;
111 $mac = clean_mac($_GET['mac']);
114 print json_encode ( array( 'response' => 'failed', 'cause' => 'invalid', 'detail' => 'No valid MAC address given.') );
118 if ( !is_provision_user ( $username, $domain ) )
120 print json_encode( array ( 'response' => 'failed', 'cause' => 'nonexistant', 'detail' => 'User not registered.'));
123 $phones = get_user_phones ( $username, $domain);
124 if ( $phones && in_array( $mac, $phones ) )
126 print json_encode( array ( 'response' => 'failed', 'cause' => 'exists', 'detail' => 'This phone and user combination is already configured..'));
129 $res = add_phone_user ( $mac, $username, $domain );
132 print json_encode( array ( 'response' => 'failed', 'cause' =>'dbfail', 'detail' => 'Failed to add phone to database.'));
137 print json_encode( array ( 'response' => 'ok', 'data' => array (
138 'mac' => $mac, 'username' => $username, 'domain' => $domain) ));
144 print json_encode ( array( 'response' => 'invalid') );
152 mac The MAC-address of the phone to add an entry for
154 user A registered username on user@domain form (SIP address)
156 username A registered username, combines with:
157 domain A valid domain .. to form a registered user@domain combo :)
160 if ( array_key_exists('mac', $_GET ) &&
161 ( array_key_exists('user', $_GET) ||
162 ( array_key_exists('username', $_GET) && array_key_exists('domain', $_GET ))))
166 if ( array_key_exists('username', $_GET) )
168 $username = $_GET['username'];
169 $domain = $_GET['domain'];
173 $user = split_sipaddress($_GET['user']);
176 print json_encode ( array( 'response' => 'failed', 'cause' => 'invalid', 'detail' => 'Invalid SIP address') );
179 list ( $username, $domain ) = $user;
181 $mac = clean_mac($_GET['mac']);
184 print json_encode ( array( 'response' => 'failed', 'cause' => 'invalid', 'detail' => 'No valid MAC address given.') );
188 $phones = get_user_phones ( $username, $domain);
189 if ( ! $phones ||
!in_array( $mac, $phones ) )
191 print json_encode( array ( 'response' => 'failed', 'cause' => 'nonexistant', 'detail' => 'Unable to locate requested combination'));
194 $res = delete_phone_user ( $mac, $username, $domain );
197 print json_encode( array ( 'response' => 'failed', 'cause' =>'dbfail', 'detail' => 'Failed to remove phone from database.'));
202 print json_encode( array ( 'response' => 'ok' ));
208 print json_encode ( array( 'response' => 'invalid') );
213 print json_encode ( array( 'response' => 'invalid') );
215 mysql_close( $config['sql_link'] );