]> git.defcon.no Git - hermes/blobdiff - user.php
Several changes: Parameter-changes to several nodes, stubs added, verification of...
[hermes] / user.php
index ca1595502cac30c623f55e436f6a405aa799047c..f4ca316b89132afab56c5f62c283f17d44a77465 100644 (file)
--- a/user.php
+++ b/user.php
@@ -25,10 +25,28 @@ if ( !$config['sql_link'] )
                        // 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'
@@ -75,8 +93,7 @@ if ( !$config['sql_link'] )
                        /*
                        What to do??
                        Required parameters should be...
-                               username
-                               domain
+                               ( username & domain ) | user
                                displayname
                                email
 
@@ -103,13 +120,29 @@ if ( !$config['sql_link'] )
 
                        */
                        // 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'];
@@ -177,10 +210,9 @@ if ( !$config['sql_link'] )
                case "/add_remote":
                        /*
                        Required parameters should be...
-                               username
-                               password
-                               domain
+                               ( username & domain ) | user
                                displayname
+                               password
                                registrar
                        Optional parameters
                                r_port
@@ -190,6 +222,7 @@ if ( !$config['sql_link'] )
                                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
@@ -214,15 +247,31 @@ if ( !$config['sql_link'] )
 
 
                        // 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;
@@ -233,6 +282,12 @@ if ( !$config['sql_link'] )
                                $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' ));
@@ -268,8 +323,7 @@ if ( !$config['sql_link'] )
                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'
@@ -283,10 +337,28 @@ if ( !$config['sql_link'] )
                        * 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.' ) );
@@ -308,6 +380,86 @@ if ( !$config['sql_link'] )
                                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();