Added comments
Added comments

--- a/utils/cli_only.php
+++ b/utils/cli_only.php
@@ -1,4 +1,14 @@
 <?php
+/** PHPCredLocker CLI Utility functions
+*
+* Re-Generates Crypto keys and re-encrypts all stored data - Likely to be a long process!
+*
+* Copyright (C) 2014 B Tasker
+* Released under GNU AGPL V3
+* See LICENSE
+*
+*/
+
 
 // Limit to command line usage
 if (!isset($GLOBALS['argv'])){

--- a/utils/rekey.php
+++ b/utils/rekey.php
@@ -28,6 +28,10 @@
 	}
 
 
+
+	/** Write the objects keys to crypto.php
+	*
+	*/
 	function writekeyfile(){
 
 		$fh = fopen('conf/crypto.php','w');
@@ -59,6 +63,7 @@
 	}
 
 
+
 	/** Remove keys for any CredTypes that are no longer in the database
 	*
 	* @arg credtypeids - array
@@ -88,6 +93,9 @@
 
 
 
+/** Utility class
+*
+*/
 class Utils{
 	static function genKey($len){
 	      $newkey = null;
@@ -142,14 +150,20 @@
 }
 
 
-
+// Prepare a few bits
 $db = new BTDB;
 $crypt = new Crypto;
-$currentkeys = new cryptokeyscli(); // We use this object to make sure we've got a copy of the original
+//$currentkeys = new cryptokeyscli(); // We use this object to make sure we've got a copy of the original
 $newkeys = new cryptokeyscli(); // We'll be making the changes in here
 
 
 $keylength = $newkeys->cipher->keyLength;
+
+// TODO: Do we want to let the user change the keylength (and maybe the cipher?)
+
+
+
+		/** User Re-Key */
 
 $output->_("Preparing to Re-Key Users");
 
@@ -221,6 +235,12 @@
 
 
 
+
+
+		/** Credtypes Re-Key */
+
+
+
 // Credtypes are similarly simple, just the name to switch
 
 $output->_("Preparing to Re-Key Credential Types");
@@ -259,6 +279,14 @@
 	$output->_("Aborting");
 	die;
 }
+
+
+
+
+
+
+
+		/** Customers Re-Key */
 
 
 // Customers require a little more work!
@@ -314,6 +342,13 @@
 
 
 
+
+
+
+		/** Groups Re-Key */
+
+
+
 // Groups next, relatively straight forward
 
 $output->_("Preparing to Re-Key Groups");
@@ -353,6 +388,12 @@
 }
 
 
+
+
+
+		/** Credentials Re-Key */
+
+
 // Now the tricky bit... Creds!
 // We already have the credtypes in memory, so we'll work through them one by one.
 
@@ -380,6 +421,8 @@
 
 	$output->_("\tProcessing Credtype ".$credtype->id);
 
+
+	// Work through each of the creds with this credtype
 	foreach ($creds as $cred){
 		$cred->Hash = $crypt->decrypt($cred->Hash,'Cre'.$cred->CredType);
 		$cred->Address = $crypt->decrypt($cred->Address,'Cre'.$cred->CredType);
@@ -389,6 +432,8 @@
 		$ccreds[] = $cred;
 	}
 
+
+	// Process the AutoAuth records if any exist
 	if ($autoauth){
 		$sql = "SELECT * FROM #__AutoAuth";
 		$db->setQuery($sql);
@@ -408,6 +453,8 @@
 	$newkeys->keys->Cre.$credtype->id = Utils::genKey($keylength);
 	$newkeys->writekeyfile();
 
+
+	// Encrypt and save
 	foreach ($ccreds as $cred){
 		$cred->Hash = $crypt->encrypt($cred->Hash,'Cre'.$cred->CredType);
 		$cred->Address = $crypt->encrypt($cred->Address,'Cre'.$cred->CredType);
@@ -437,6 +484,7 @@
 
 }
 
+// Get rid of any defunct keys
 $output->_("Tidying Keys");
 $newkeys->tidyKeys($credtypeids);
 $newkeys->writekeyfile();