From 5e06b6865a488899dc997fbd3ee2d22e9c5569f4 Mon Sep 17 00:00:00 2001 From: Jon Langseth Date: Tue, 17 Jan 2012 19:57:25 +0100 Subject: [PATCH] Implemented user/available test-node, added collision-detect to user/add_local and user/add_remote --- api/user.php | 58 +++++++++++++++++++++++++++++++++++++++++++++++ doc/api-nodes.txt | 11 ++++++--- 2 files changed, 66 insertions(+), 3 deletions(-) diff --git a/api/user.php b/api/user.php index 2830a3e..1014317 100644 --- a/api/user.php +++ b/api/user.php @@ -4,6 +4,7 @@ require_once('lib/user_functions.php'); 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(); @@ -177,6 +178,12 @@ if ( !$config['sql_link'] ) 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 ) { @@ -299,6 +306,14 @@ if ( !$config['sql_link'] ) 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 ) { @@ -599,6 +614,49 @@ if ( !$config['sql_link'] ) 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; diff --git a/doc/api-nodes.txt b/doc/api-nodes.txt index 7ea2100..a288bbd 100644 --- a/doc/api-nodes.txt +++ b/doc/api-nodes.txt @@ -85,6 +85,14 @@ user/remove?user=foo@bar.bz 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. @@ -222,9 +230,6 @@ TODO list: 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 ;) -- 2.39.2