]> git.defcon.no Git - hermes/commitdiff
Implemented user/available test-node, added collision-detect to user/add_local and...
authorJon Langseth <jon.langseth@lilug.no>
Tue, 17 Jan 2012 18:57:25 +0000 (19:57 +0100)
committerJon Langseth <jon.langseth@lilug.no>
Tue, 17 Jan 2012 18:57:25 +0000 (19:57 +0100)
api/user.php
doc/api-nodes.txt

index 2830a3ee1040d0b1869c3307778f718c02792304..101431769466154a51dd93381a7c6f445069c81a 100644 (file)
@@ -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;
index 7ea2100d3f80396d4ade386d053f7a2fb23a24c6..a288bbda9639c1f5fa78943b8cf5377769d9e941 100644 (file)
@@ -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 ;)