require_once('lib/common_functions.php');
require_once('lib/db_functions.php');
require_once('lib/phone_functions.php');
+require_once('lib/alias_functions.php');
$config = get_config();
print json_encode ( array( 'response' => 'failed', 'cause' => 'exists', 'detail' => 'User already exists as a Kamailio subscriber' ));
break;
}
+ if ( alias_exists ( $username, $domain ) )
+ {
+ print json_encode ( array( 'response' => 'failed', 'cause' => 'exists', 'detail' => 'Username exists as an alias' ));
+ break;
+ }
+
$kam_res = add_kamailio_subscriber( $username, $domain, $password, $email );
if ( !$kam_res )
{
break;
}
+ // Should be impossible to hit this test, all aliases are required to be local.
+ if ( alias_exists ( $username, $domain ) )
+ {
+ print json_encode ( array( 'response' => 'failed', 'cause' => 'exists', 'detail' => 'Username exists as an alias' ));
+ break;
+ }
+
+
$pro_res = add_provision_user( $username, $password, $domain, $authid, $registrar, $r_port, $proxy, $p_port, $displayname, $dialplan, $linetext );
if ( !$pro_res )
{
else
print json_encode( array( 'response' => 'invalid', 'cause' => 'parameters' ) );
break;
+ case "/available":
+ if ( ( array_key_exists( 'username', $_GET) && array_key_exists( 'domain', $_GET ) )
+ || array_key_exists('user', $_GET) )
+
+ {
+ $username = "";
+ $domain = "";
+ if ( array_key_exists('username', $_GET) )
+ {
+ $username = $_GET['username'];
+ $domain = $_GET['domain'];
+ }
+ else
+ {
+ $user = split_sipaddress($_GET['user']);
+ if ( !$user )
+ {
+ print json_encode ( array( 'response' => 'failed', 'cause' => 'invalid', 'detail' => 'Invalid SIP address') );
+ break;
+ }
+ list ( $username, $domain ) = $user;
+ }
+ if ( is_provision_user ( $username, $domain ) )
+ {
+ print json_encode ( array( 'response' => 'failed', 'cause' => 'exists', 'detail' => 'User already exists in provisioning configuration' ));
+ break;
+ }
+ if ( is_kamailio_subscriber ( $username, $domain ) )
+ {
+ print json_encode ( array( 'response' => 'failed', 'cause' => 'exists', 'detail' => 'User already exists as a Kamailio subscriber' ));
+ break;
+ }
+ if ( alias_exists ( $username, $domain ) )
+ {
+ print json_encode ( array( 'response' => 'failed', 'cause' => 'exists', 'detail' => 'Username exists as an alias' ));
+ break;
+ }
+ print json_encode( array ( 'response' => 'ok', 'cause' => 'nonexistant', 'detail' => '' . $username . '@' . $domain . ' does not exist.'));
+
+ }
+ else
+ print json_encode( array( 'response' => 'invalid', 'cause' => 'parameters' ) );
+ break;
case "/gen_pw":
print generate_password();
break;
Returns 'ok' on success.
+user/available?username=foo&domain=bar
+user/available?user=foo@bar.bz
+ Tests an address to see if it is available.
+
+ Returns 'ok' with 'cause' = 'nonexistant' if the address is available.
+
+ Returns 'failed' with 'cause' = 'exists' if the address is in use.
+
user/gen_pw
Test-node, generates a random password on the same form as that used by
user/add_local. May be used with the to-be-implemented change_pw node.
authentication-mechanism :)
-Add collision prevention for users, make sure that no user can be added when the user
-address would overlap/collide with a valid alias-address
-
Change all GET to POST
Implement test-tool for POST-based communication ;)