// Required GET parameters:
// user: authentication username, SIP-username without domain component
// domain: Domain/realm of the user. username + '@' + domain == SIP address.
- if ( array_key_exists( 'username', $_GET) && array_key_exists( 'domain', $_GET ) )
+
+ if ( array_key_exists('user', $_GET) ||
+ ( array_key_exists('username', $_GET) && array_key_exists('domain', $_GET )))
{
- $username = $_GET['username'];
- $domain = $_GET['domain'];
+ $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;
+ }
+
// Now, do funky stuff.
/*
Test if user exists in both 'kamailio.subscribers' and 'provision.users'
/*
What to do??
Required parameters should be...
- username
- domain
+ ( username & domain ) | user
displayname
email
*/
// Test required parameters:
- if ( array_key_exists( 'username', $_GET)
- && array_key_exists( 'domain', $_GET )
+ if (
+ ( ( array_key_exists( 'username', $_GET) && array_key_exists( 'domain', $_GET ) ) || array_key_exists('user', $_GET) )
&& array_key_exists( 'displayname', $_GET )
&& array_key_exists( 'email', $_GET ) )
{
- $username = $_GET['username'];
- $domain = $_GET['domain'];
+ $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;
+ }
+
$password = generate_password();
$displayname = $_GET['displayname'];
$email = $_GET['email'];
case "/add_remote":
/*
Required parameters should be...
- username
- password
- domain
+ ( username & domain ) | user
displayname
+ password
registrar
Optional parameters
r_port
dialplan
linetext
+ Verify that the domain is not a local kamailio domain (REMOTE user..)
Verify that the username+domain is not already registered in 'provision.users'.
* If r_port is empty, set to 5060
* If proxy/port is empty, set to registrar/port
// Test required parameters:
- if ( array_key_exists( 'username', $_GET)
- && array_key_exists( 'password', $_GET )
+ if (
+ ( ( array_key_exists( 'username', $_GET) && array_key_exists( 'domain', $_GET ) ) || array_key_exists('user', $_GET) )
&& array_key_exists( 'displayname', $_GET )
- && array_key_exists( 'domain', $_GET )
+ && array_key_exists( 'password', $_GET )
&& array_key_exists( 'registrar', $_GET ) )
{
- $username = $_GET['username'];
+ $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;
+ }
+
$password = $_GET['password'];
- $domain = $_GET['domain'];
$displayname = $_GET['displayname'];
$registrar = $_GET['registrar'];
$r_port = ( array_key_exists('r_port', $_GET) ) ? $_GET['r_port'] : 5060;
$dialplan = ( array_key_exists('dialplan', $_GET) ) ? $_GET['dialplan'] : $config['standard_dialplan'];
$linetext = ( array_key_exists('linetext', $_GET) ) ? $_GET['linetext'] : $username . '@' . $domain;
+ if ( is_kamailio_domain( $domain ) )
+ {
+ print json_encode ( array( 'response' => 'failed', 'cause' => 'domain', 'detail' => 'The selected domain is local, cannot add remote user' ));
+ break;
+ }
+
if ( is_provision_user ( $username, $domain ) )
{
print json_encode ( array( 'response' => 'failed', 'cause' => 'exists', 'detail' => 'User already exists in provisioning configuration' ));
case "/remove":
/*
Required parameters should be...
- username
- domain
+ ( username & domain ) | user
* Verify that no associations/relations exist in 'provision.phones'
* Verify that the user exists in 'provision.users'
* If no such user exists, return 'response' => 'failed' with 'cause' => 'nonexistant'
* On other failures, return 'response' => 'failed' with 'cause' => 'error' (may set 'detail' => 'message')
*/
- if ( array_key_exists( 'username', $_GET) && array_key_exists( 'domain', $_GET ) )
+ if ( ( array_key_exists( 'username', $_GET) && array_key_exists( 'domain', $_GET ) )
+ || array_key_exists('user', $_GET) )
+
{
- $username = $_GET['username'];
- $domain = $_GET['domain'];
+ $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 ( get_user_phones ( $username, $domain ) )
{
print json_encode( array( 'response' => 'failed', 'cause' => 'inuse', 'detail' => 'User has associated provisioning. Remove and retry.' ) );
break;
}
+ print json_encode ( array( 'response' => 'invalid') );
+ break;
+ case "/change_pw":
+ /*
+ Required parameters should be...
+ ( username & domain ) | user
+
+ * Verify that no associations/relations exist in 'provision.phones'
+ * Verify that the user exists ...
+ * Test to see of user exists in 'provision.users'
+ * Test to see of user exists in 'kamailio.subscriber'.
+ * If no such user exists, return 'response' => 'failed' with 'cause' => 'nonexistant'
+ * Update user passwords in 'provision' and 'kamailio' as appropriate
+ * On other failures, return 'response' => 'failed' with 'cause' => 'error' (may set 'detail' => 'message')
+ */
+ 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;
+ }
+ print json_encode ( array( 'response' => 'failed', 'cause' => 'notimplemented', 'detail' => 'Requested feature valid, but not implemented' ) );
+ }
+ else
+ print json_encode( array( 'response' => 'invalid', 'cause' => 'parameters' ) );
+ break;
+
+ case "/update":
+ /*
+ Required parameters should be...
+ ( username & domain ) | user
+
+ * Verify that no associations/relations exist in 'provision.phones'
+ * Verify that the user exists ...
+ * Test to see of user exists in 'provision.users'
+ * Test to see of user exists in 'kamailio.subscriber'.
+ * If no such user exists, return 'response' => 'failed' with 'cause' => 'nonexistant'
+ * Get update parameters, and change as appropriate ;)
+ * On other failures, return 'response' => 'failed' with 'cause' => 'error' (may set 'detail' => 'message')
+ */
+ 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;
+ }
+ print json_encode ( array( 'response' => 'failed', 'cause' => 'notimplemented', 'detail' => 'Requested feature valid, but not implemented' ) );
+ }
+ else
+ print json_encode( array( 'response' => 'invalid', 'cause' => 'parameters' ) );
break;
case "/gen_pw":
print generate_password();