4 * ssh keys backend migration
6 * Copyright 2012, Franck Villaume - TrivialDev
7 * http://fusionforge.org/
9 * This file is part of FusionForge.
11 * FusionForge is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * FusionForge is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 require_once dirname(__FILE__).'/../common/include/env.inc.php';
27 require_once $gfcommon.'include/pre.php';
28 require_once $gfcommon.'include/User.class.php';
30 ini_set('memory_limit', -1);
31 ini_set('max_execution_time', 0);
33 $res = db_query_params('SELECT authorized_keys, user_id FROM users WHERE authorized_keys != $1', array(''));
35 echo 'UPGRADE ERROR: '.db_error();
40 while($row = db_fetch_array($res)) {
41 $sshKeys = explode('###', $row['authorized_keys']);
42 foreach($sshKeys as $key) {
43 $tempfile = tempnam("/tmp", "migauthkey");
44 $ft = fopen($tempfile, 'w');
47 $returnExec = array();
48 exec("/usr/bin/ssh-keygen -lf ".$tempfile, $returnExec);
50 $returnExecExploded = explode(' ', $returnExec[0]);
51 $fingerprint = $returnExecExploded[1];
53 $explodedKey = explode(' ', $key);
54 $res = db_query_params('insert into sshkeys (userid, fingerprint, upload, sshkey, name, algorithm)
55 values ($1, $2, $3, $4, $5, $6)',
56 array($row['user_id'], $fingerprint, $now, $key, $explodedKey[2], $explodedKey[0]));
58 echo 'UPGRADE ERROR: '.db_error();
63 $res = db_query_params('update users set authorized_keys = $1 where user_id = $2',
64 array('', $row['user_id']));