]>
git.defcon.no Git - hermes/blob - alias.php
2 require_once('config.php');
3 require_once('lib/user_functions.php');
4 require_once('lib/number_functions.php');
5 require_once('lib/common_functions.php');
6 require_once('lib/db_functions.php');
7 require_once('lib/alias_functions.php');
9 $config = get_config();
11 $config['sql_link'] = @mysql_connect
(
12 $config['sql_server'],
13 $config['sql_username'],
14 $config['sql_password']
16 if ( !$config['sql_link'] )
18 print json_encode( array( 'response' => 'failed', 'cause' => 'error', 'detail' => 'Database connection failed.'));
22 //*************************************************************************************
23 switch ( $_SERVER['PATH_INFO'] )
28 if ( array_key_exists( 'destination', $_GET)
29 //&& array_key_exists( 'domain', $_GET )
30 && array_key_exists( 'alias_username', $_GET )
31 && array_key_exists( 'alias_domain', $_GET ) )
33 $alias_username = $_GET['alias_username'];
34 $alias_domain = $_GET['alias_domain'];
36 if ( !verify_sipadress($_GET['destination']) )
38 // TODO: Provide a better response..
39 print json_encode ( array( 'response' => 'invalid', 'cause' => 'destination' ) );
42 if ( !verify_sipadress( $alias_username . "@" . $alias_domain) )
44 // TODO: Provide a better response..
45 print json_encode ( array( 'response' => 'invalid', 'cause' => 'alias' ) );
49 list ( $dest_username, $dest_domain ) = split_sipaddress( $_GET['destination']);
51 if ( (!$dest_username)||
(!$dest_domain))
53 // TODO: Provide a better response..
54 print json_encode ( array( 'response' => 'invalid', 'cause' => 'alias' ) );
57 if ( !is_kamailio_domain( $alias_domain ) )
59 print json_encode ( array( 'response' => 'invalid', 'cause' => 'nxdomain' ) );
62 if ( is_kamailio_domain( $dest_domain) && ( !is_kamailio_subscriber($dest_username, $dest_domain) ) )
64 print json_encode( array ( 'response' => 'failed', 'cause' => 'nonexistant', 'detail' => 'Requesting a local alias, but there is no such user'));
67 if ( verify_e164( $alias_username ) && is_kamailio_subscriber($dest_username, $dest_domain) )
69 $t = get_e164_alias( $dest_username, $dest_domain );
72 print json_encode ( array(
73 'response' => 'failed',
75 'detail' => 'User already has E164 number alias',
80 if ( alias_exists ( $alias_username, $alias_domain ) )
82 print json_encode( array ( 'response' => 'failed', 'cause' => 'exists', 'detail' => 'The requested alias is already present.'));
85 if ( add_alias( $alias_username, $alias_domain, $dest_username, $dest_domain ) )
87 print json_encode( array ('response' => 'ok',
88 'alias' => $alias_username . "@" . $alias_domain,
89 'destination' => $dest_username . "@" . $dest_domain ));
92 print json_encode ( array ( 'response' => 'error' ));
97 print json_encode ( array( 'response' => 'invalid') );
101 if ( array_key_exists( 'alias_username', $_GET )
102 && array_key_exists( 'alias_domain', $_GET ) )
104 $alias_username = $_GET['alias_username'];
105 $alias_domain = $_GET['alias_domain'];
107 if ( !verify_sipadress( $alias_username . "@" . $alias_domain) )
109 // TODO: Provide a better response..
110 print json_encode ( array( 'response' => 'invalid', 'cause' => 'address', 'detail' => 'Not a valid SIP address' ) );
113 if ( ! alias_exists ( $alias_username, $alias_domain ) )
115 print json_encode( array ( 'response' => 'failed', 'cause' => 'nonexistant', 'detail' => 'The requested alias does not exist.'));
118 if ( remove_alias( $alias_username, $alias_domain ) )
120 print json_encode( array ('response' => 'ok',
121 'alias' => $alias_username . "@" . $alias_domain));
124 print json_encode ( array ( 'response' => 'error' ));
127 print json_encode ( array( 'response' => 'invalid') );
130 print json_encode ( array( 'response' => 'invalid') );
132 mysql_close( $config['sql_link'] );