[Fusionforge-commits] r16034 - in trunk/src/common: account/actions include

Franck VILLAUME nerville at fusionforge.org
Sun Jul 22 10:55:03 CEST 2012


Author: nerville
Date: 2012-07-22 10:55:02 +0200 (Sun, 22 Jul 2012)
New Revision: 16034

Modified:
   trunk/src/common/account/actions/addsshkey.php
   trunk/src/common/include/User.class.php
   trunk/src/common/include/account.php
Log:
implement #27: upload ssh key file

Modified: trunk/src/common/account/actions/addsshkey.php
===================================================================
--- trunk/src/common/account/actions/addsshkey.php	2012-07-22 07:34:06 UTC (rev 16033)
+++ trunk/src/common/account/actions/addsshkey.php	2012-07-22 08:55:02 UTC (rev 16034)
@@ -26,6 +26,7 @@
 require_once $gfcommon.'include/account.php';
 
 $authorized_key = getStringFromRequest('authorized_key');
+$uploaded_filekey = getUploadedFile('uploaded_filekey');
 if (strlen($authorized_key)) {
 	checkKeys($authorized_key);
 	if (!$u->addAuthorizedKey($authorized_key)) {
@@ -35,6 +36,21 @@
 	session_redirect('/account/?&feedback='.urlencode($feedback));
 }
 
+if (!is_uploaded_file($uploaded_filekey['tmp_name'])) {
+	$return_msg = _('Invalid file name.');
+	session_redirect('/account/?&error_msg='.urlencode($return_msg));
+}
+
+$payload = fread(fopen($uploaded_filekey['tmp_name'], 'r'), $uploaded_filekey['size']);
+if (strlen($payload)) {
+	checkKeys($payload);
+	if (!$u->addAuthorizedKey($payload)) {
+		session_redirect('/account/?&error_msg='.urlencode($u->getErrorMessage()));
+	}
+	$feedback = _('SSH Key added successfully.');
+	session_redirect('/account/?&feedback='.urlencode($feedback));
+}
+
 session_redirect('/account/');
 
 ?>
\ No newline at end of file

Modified: trunk/src/common/include/User.class.php
===================================================================
--- trunk/src/common/include/User.class.php	2012-07-22 07:34:06 UTC (rev 16033)
+++ trunk/src/common/include/User.class.php	2012-07-22 08:55:02 UTC (rev 16034)
@@ -1231,6 +1231,13 @@
 		$fingerprint = $returnExecExploded[1];
 		$now = time();
 		$explodedKey = explode(' ', $key);
+		$existingKeys = $this->getAuthorizedKeys();
+		foreach ($existingKeys as $existingKey) {
+			if ($existingKey['fingerprint'] = $fingerprint) {
+				$this->setError(_('SSH Key already in use'));
+				return false;
+			}
+		}
 		$res = db_query_params('insert into sshkeys (userid, fingerprint, upload, sshkey, name, algorithm)
 							values ($1, $2, $3, $4, $5, $6)',
 					array($this->getID(), $fingerprint, $now, $key, $explodedKey[2], $explodedKey[0]));

Modified: trunk/src/common/include/account.php
===================================================================
--- trunk/src/common/include/account.php	2012-07-22 07:34:06 UTC (rev 16033)
+++ trunk/src/common/include/account.php	2012-07-22 08:55:02 UTC (rev 16034)
@@ -319,7 +319,7 @@
 			if ( preg_match("@^(((no-port-forwarding|no-X11-forwarding|no-agent-forwarding|no-pty|command=\"[^\"]+\"|from=\"?[A-Za-z0-9\.-]+\"?),?)*\s+)?ssh-(rsa|dss)\s+[A-Za-z0-9+/]{157,}={0,2}(\s+.*)?$@", $key) === 0 ) { // Warning: we must use === for the test
 				$msg = sprintf(_('The following key has a wrong format: |%s|.  Please, correct it by going back to the previous page.'),
 						htmlspecialchars($key));
-				exit_error($msg, 'my');
+				session_redirect('/account/?&error_msg='.urlencode($msg));
 			}
 		}
 		$key = strtok("\n");




More information about the Fusionforge-commits mailing list