6 * The rest Copyright 2002-2005 (c) GForge Team
7 * Copyright (C) 2009 Sylvain Beucler
8 * Copyright 2012, Franck Villaume - TrivialDev
9 * http://fusionforge.org/
11 * This file is part of FusionForge.
13 * FusionForge is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * FusionForge is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 require dirname(__FILE__).'/../../env.inc.php';
29 require_once $gfcommon.'include/pre.php';
30 require $gfcommon.'include/cron_utils.php';
34 $res2 = db_query_params('SELECT sshkey, user_name from sshkeys, users
35 where sshkeys.userid = users.user_id
37 and users.unix_status = $2
38 and sshkeys.deleted = $3
39 and sshkeys.deploy = $4',
40 array('A', 'A', 0, 0));
42 while ($arr = db_fetch_array($res2)) {
43 $username = $arr['user_name'];
44 $key = $arr['sshkey'];
45 if (!exists($keys[$username])) {
46 $keys[$username] = array();
48 $keys[$username][] = $key;
51 function create_authkeys($params) {
52 $ssh_dir = $params['ssh_dir'];
53 $ssh_key = $params['ssh_key'];
54 if (!is_dir($ssh_dir)) {
55 mkdir ($ssh_dir, 0755);
57 $h8 = fopen("$ssh_dir/authorized_keys","w");
58 fwrite($h8,'# This file is automatically generated from your account settings.'."\n");
61 chmod ("$ssh_dir/authorized_keys", 0644);
64 foreach ($keys as $username => $v) {
65 $ssh_key = join("\n", $v);
67 $dir = forge_get_config('homedir_prefix').'/'.$username;
68 if (util_is_root_dir($dir)) {
69 $err .= "Error! homedir_prefix/username Points To Root Directory!";
74 $params['ssh_key'] = str_replace('###',"\n",$ssh_key);
75 $params['ssh_dir'] = forge_get_config('homedir_prefix')."/$username/.ssh";
77 util_sudo_effective_user($username, "create_authkeys", $params);