]> git.defcon.no Git - hermes/commitdiff
Changed list node to provide more data. Added change_pw functionality/node. Changed...
authorjonl <jonl@sippbx.hig.no>
Mon, 16 Jan 2012 18:24:38 +0000 (19:24 +0100)
committerjonl <jonl@sippbx.hig.no>
Mon, 16 Jan 2012 18:24:38 +0000 (19:24 +0100)
lib/user_functions.php
user.php

index 79445510bd58cb9e96410ffffad1146c42289b12..adad1be740cbc3c0b7472ee137c1d8768debb325 100644 (file)
@@ -79,7 +79,26 @@ function delete_kamailio_subscriber( $username, $domain )
                sql_clean($username),
                sql_clean($domain)
        );
                sql_clean($username),
                sql_clean($domain)
        );
-       if ( ! sql_dbexec( $config['kamailio_db'], $query ) ) return false;
+       if ( sql_dbexec_rows( $config['kamailio_db'], $query) != 1 ) return false;
+       return true;
+}
+
+
+function update_kamailio_pw ( $username, $domain, $password )
+{
+       global $config;
+
+       if ( ! ($username && $domain && $password))
+               return false;
+
+       $query = sprintf("UPDATE %s SET password = '%s' WHERE username = '%s' AND domain = '%s'",
+               $config['kamailio_subscriber_table'],
+               sql_clean($password),
+               sql_clean($username),
+               sql_clean($domain)
+       
+       );
+       if ( sql_dbexec_rows( $config['kamailio_db'], $query) != 1 ) return false;
        return true;
 }
 
        return true;
 }
 
@@ -134,14 +153,32 @@ function delete_provision_user( $username, $domain )
                sql_clean($username),
                sql_clean($domain)
        );
                sql_clean($username),
                sql_clean($domain)
        );
-       if ( ! sql_dbexec( $config['provision_db'], $query ) ) return false;
+       if ( sql_dbexec_rows( $config['provision_db'], $query) != 1 ) return false;
+       return true;
+}
+
+function update_provision_pw ( $username, $domain, $password )
+{
+       global $config;
+
+       if ( ! ($username && $domain && $password))
+               return false;
+
+       $query = sprintf("UPDATE %s SET password = '%s' WHERE username = '%s' AND domain = '%s'",
+               $config['provision_users_table'],
+               sql_clean($password),
+               sql_clean($username),
+               sql_clean($domain)
+       
+       );
+       if ( sql_dbexec_rows( $config['provision_db'], $query) != 1 ) return false;
        return true;
 }
 
 function list_users ( $search = null )
 {
        global $config;
        return true;
 }
 
 function list_users ( $search = null )
 {
        global $config;
-       $query = sprintf("SELECT CONCAT(username, '@', domain) FROM %s ORDER BY username,domain", $config['provision_users_table'] );
+       $query = sprintf("SELECT CONCAT(username, '@', domain), displayname FROM %s ORDER BY username,domain", $config['provision_users_table'] );
 
        if ( array_key_exists ( 'search', $_GET ) )
        {
 
        if ( array_key_exists ( 'search', $_GET ) )
        {
@@ -154,7 +191,7 @@ function list_users ( $search = null )
        $list = array();
        while ( $row = mysql_fetch_row( $result ) )
        {
        $list = array();
        while ( $row = mysql_fetch_row( $result ) )
        {
-               array_push( $list, $row[0] );
+               array_push( $list, array( "user" => $row[0], "displayname" => $row[1] ) );
        }
        return $list;
        print json_encode( array( 'response' => 'ok', 'list' => $list ));
        }
        return $list;
        print json_encode( array( 'response' => 'ok', 'list' => $list ));
index f4ca316b89132afab56c5f62c283f17d44a77465..87dbe53d811cf1cc8858058beea079c75d282bee 100644 (file)
--- a/user.php
+++ b/user.php
@@ -386,6 +386,7 @@ if ( !$config['sql_link'] )
                        /*
                        Required parameters should be...
                                ( username & domain ) | user
                        /*
                        Required parameters should be...
                                ( username & domain ) | user
+                               password
                        
                        * Verify that no associations/relations exist in 'provision.phones'
                        * Verify that the user exists ...
                        
                        * Verify that no associations/relations exist in 'provision.phones'
                        * Verify that the user exists ...
@@ -395,8 +396,9 @@ if ( !$config['sql_link'] )
                        * Update user passwords in 'provision' and 'kamailio' as appropriate
                        * On other failures, return 'response' => 'failed' with 'cause' => 'error' (may set 'detail' => 'message')
                        */
                        * 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) )
+                       if (    array_key_exists('password', $_GET) &&
+                               ( ( array_key_exists( 'username', $_GET) && array_key_exists( 'domain', $_GET ) ) 
+                                       || array_key_exists('user', $_GET) ))
 
                        {
                                $username = "";
 
                        {
                                $username = "";
@@ -416,7 +418,38 @@ if ( !$config['sql_link'] )
                                        }
                                        list ( $username, $domain ) = $user;
                                }
                                        }
                                        list ( $username, $domain ) = $user;
                                }
-                               print json_encode ( array( 'response' => 'failed', 'cause' => 'notimplemented', 'detail' => 'Requested feature valid, but not implemented' ) );
+                               $password = $_GET['password'];
+
+                               // Check compatibility of password? TODO...
+                               // Fetch old password for rollback? TODO...
+                               // Verify that user exists for provisioning
+                               if ( ! is_provision_user( $username, $domain ) )
+                               {
+                                       print json_encode( array ( 'response' => 'failed', 'cause' => 'nonexistant', 'detail' => '' . $username . '@' . $domain . ' does not exist.'));
+                                       break;
+                               }
+                               if ( is_provision_user( $username, $domain ) )
+                               {
+                               print "WTF";
+                                       // Update provisioning password
+                                       if (! update_provision_pw( $username, $domain, $password ) )
+                                       {
+                                               print json_encode( array( 'response' => 'failed', 'cause' => 'dbfail', 'detail' => 'Failed to update provisioning password' ) );
+                                               break;
+                                       }
+                               }
+                               // Check for user in kamailio
+                               if ( is_kamailio_subscriber( $username, $domain ) )
+                               {
+                                       // Update kamailio password
+                                       if (! update_kamailio_pw( $username, $domain, $password ) )
+                                       {
+                                               print json_encode( array( 'response' => 'failed', 'cause' => 'dbfail', 'detail' => 'Failed to update kamailio password' ) );
+                                               break;
+                                       }
+                               }
+                               print json_encode( array ( 'response' => 'ok', 'detail' => 'Password changed for user '.$username.'@'.$domain.'.'));
+                               break;
                        }
                        else 
                                print json_encode( array( 'response' => 'invalid', 'cause' => 'parameters' ) );
                        }
                        else 
                                print json_encode( array( 'response' => 'invalid', 'cause' => 'parameters' ) );