Shout: Fixes to saving device information
authorBen Klang <ben@alkaloid.net>
Sat, 2 Jan 2010 18:07:50 +0000 (13:07 -0500)
committerBen Klang <ben@alkaloid.net>
Sat, 2 Jan 2010 18:07:50 +0000 (13:07 -0500)
* Fix password generation bug in Shout#genDeviceAuth()
* Shorten the generated auth ID for ease of use
* Ensure the device ID gets stored to the SQL backend if changed

shout/lib/Driver/Sql.php
shout/lib/Shout.php

index 7bc69b8..5ee6468 100644 (file)
@@ -140,33 +140,34 @@ class Shout_Driver_Sql extends Shout_Driver
         // See getDevices() for an explanation of these conversions
         $details['alias'] = $details['name'];
         $details['name'] = $details['devid'];
+        unset($details['devid']);
         $details['mailbox'] .= '@' . $context;
 
+        // Prepare the SQL query and arguments
+        $args = array(
+            $details['name'],
+            $context,
+            $details['callerid'],
+            $details['mailbox'],
+            $details['password'],
+            $details['alias'],
+        );
         if (!empty($devid)) {
             // This is an edit
             $details['name'] = $details['devid'];
-            $sql = 'UPDATE %s SET accountcode = ?, callerid = ?, ' .
+            $sql = 'UPDATE %s SET name = ?, accountcode = ?, callerid = ?, ' .
                    'mailbox = ?, secret = ?, alias = ?, canreinvite = "no", ' .
                    'nat = "yes", type = "peer" WHERE name = ?';
+            $args[] = $devid;
         } else {
             // This is an add.  Generate a new unique ID and secret
-            $sql = 'INSERT INTO %s (accountcode, callerid, mailbox, ' .
-                   'secret, alias, name, canreinvite, nat, type) ' .
+            $sql = 'INSERT INTO %s (name, accountcode, callerid, mailbox, ' .
+                   'secret, alias, canreinvite, nat, type) ' .
                    'VALUES (?, ?, ?, ?, ?, ?, "no", "yes", "peer")';
 
         }
-
         $sql = sprintf($sql, $this->_params['table']);
 
-        $args = array(
-            $context,
-            $details['callerid'],
-            $details['mailbox'],
-            $details['password'],
-            $details['alias'],
-            $details['name'],
-        );
-
         $msg = 'SQL query in Shout_Driver_Sql#saveDevice(): ' . $sql;
         Horde::logMessage($msg, __FILE__, __LINE__, PEAR_LOG_DEBUG);
         $sth = $this->_write_db->prepare($sql);
index bce4144..09edcb6 100644 (file)
@@ -155,8 +155,7 @@ class Shout
      */
     static public function genDeviceAuth($context)
     {
-        $devid = uniqid($context);
-        $password = uudecode(md5(uniqid(mt_rand(), true)));
+        $devid = $context . substr(uniqid(), 6);
 
         // This simple password generation algorithm inspired by Jon Haworth
         // http://www.laughing-buddha.net/jon/php/password/