Skip to content

Commit 08c5887

Browse files
author
laking
committed
Implemented passwordless ssh-rsa authentication support.
1 parent 1f751bd commit 08c5887

File tree

11 files changed

+182
-11
lines changed

11 files changed

+182
-11
lines changed

interface/web/client/client_edit.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,17 @@ function onAfterInsert() {
149149
$active = 1;
150150
$language = $app->db->quote($this->dataRecord["language"]);
151151

152+
//Generate ssh-rsa-keys
153+
exec('ssh-keygen -t rsa -C '.$username.'-rsa-key-'.time().' -f /tmp/id_rsa -N ""');
154+
155+
$privatekey = file_get_contents('/tmp/id_rsa');
156+
$publickey = file_get_contents('/tmp/id_rsa.pub');
157+
158+
exec('rm -f /tmp/id_rsa /tmp/id_rsa.pub');
159+
152160
// Create the controlpaneluser for the client
153-
$sql = "INSERT INTO sys_user (username,passwort,modules,startmodule,app_theme,typ,active,language,groups,default_group,client_id)
154-
VALUES ('$username',md5('$password'),'$modules','$startmodule','$usertheme','$type','$active','$language',$groups,$groupid,".$this->id.")";
161+
$sql = "INSERT INTO sys_user (username,passwort,modules,startmodule,app_theme,typ,active,language,groups,default_group,client_id,id_rsa,ssh_rsa)
162+
VALUES ('$username',md5('$password'),'$modules','$startmodule','$usertheme','$type','$active','$language',$groups,$groupid,".$this->id.",'$privatekey','$publickey')";
155163
$app->db->query($sql);
156164

157165
//* If the user who inserted the client is a reseller (not admin), we will have to add this new client group
@@ -214,6 +222,7 @@ function onAfterUpdate() {
214222
$sql = "UPDATE sys_user SET modules = '$modules' WHERE client_id = $client_id";
215223
$app->db->query($sql);
216224
}
225+
217226
/*
218227
* If there is a client-template, process it */
219228
applyClientTemplates($this->id);
@@ -225,4 +234,4 @@ function onAfterUpdate() {
225234
$page = new page_action;
226235
$page->onLoad();
227236

228-
?>
237+
?>

interface/web/sites/form/shell_user.tform.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@
127127
'default' => 'y',
128128
'value' => array(0 => 'n',1 => 'y')
129129
),
130+
'ssh_rsa' => array (
131+
'datatype' => 'VARCHAR',
132+
'formtype' => 'TEXT',
133+
'default' => '',
134+
'value' => '',
135+
'maxlength' => '600'
136+
),
130137
##################################
131138
# ENDE Datatable fields
132139
##################################
@@ -193,4 +200,4 @@
193200
}
194201

195202

196-
?>
203+
?>

interface/web/sites/templates/shell_user_edit.htm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ <h2><tmpl_var name="list_head_txt"></h2>
4343
<label for="quota_size">{tmpl_var name='quota_size_txt'}</label>
4444
<input name="quota_size" id="quota_size" value="{tmpl_var name='quota_size'}" size="7" maxlength="7" type="text" class="textInput formLengthLimit" /><p class="formInputUnity">&nbsp;MB</p>
4545
</div>
46+
<div class="ctrlHolder">
47+
<label for="ssh_rsa">ssh_rsa</label>
48+
<input name="ssh_rsa" id="ssh_rsa" value="" maxlength="600" type="text" class="textInput" />
49+
</div>
4650
<div class="ctrlHolder">
4751
<p class="label">{tmpl_var name='active_txt'}</p>
4852
<div class="multiField">

interface/web/sites/templates/web_domain_ssl.htm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ <h2><tmpl_var name="list_head_txt"></h2>
3333
</div>
3434
<div class="ctrlHolder">
3535
<label for="ssl_request">{tmpl_var name='ssl_request_txt'}</label>
36-
<textarea name="ssl_request" id="ssl_request" rows='10' cols='30'>{tmpl_var name='ssl_request'}</textarea>
36+
<textarea name="ssl_request" id="ssl_request" readonly rows='10' cols='30'>{tmpl_var name='ssl_request'}</textarea>
3737
</div>
3838
<div class="ctrlHolder">
3939
<label for="ssl_cert">{tmpl_var name='ssl_cert_txt'}</label>

interface/web/tools/form/user_settings.tform.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,26 @@
133133
'maxlength' => '2',
134134
'rows' => '',
135135
'cols' => ''
136+
),
137+
'id_rsa' => array (
138+
'datatype' => 'VARCHAR',
139+
'formtype' => 'TEXT',
140+
'default' => '',
141+
'datasource' => array ( 'type' => 'SQL',
142+
'querystring' => 'SELECT id_rsa FROM sys_user WHERE {AUTHSQL}',
143+
'valuefield'=> 'id_rsa'
144+
),
145+
'value' => ''
146+
),
147+
'ssh_rsa' => array (
148+
'datatype' => 'VARCHAR',
149+
'formtype' => 'TEXT',
150+
'default' => '',
151+
'datasource' => array ( 'type' => 'SQL',
152+
'querystring' => 'SELECT ssh_rsa FROM sys_user WHERE {AUTHSQL}',
153+
'valuefield'=> 'ssh_rsa'
154+
),
155+
'value' => ''
136156
)
137157
##################################
138158
# ENDE Datenbankfelder
@@ -141,4 +161,4 @@
141161
);
142162

143163

144-
?>
164+
?>

interface/web/tools/lib/lang/de_usersettings.lng

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ $wb['passwort_txt'] = 'Passwort';
33
$wb['language_txt'] = 'Sprache';
44
$wb['password_mismatch'] = 'Die Passwörter stimmen nicht überein.';
55
$wb['password_strength_txt'] = 'Passwortkomplexität';
6-
$wb['Form to edit the user password and language.'] = 'Formular, um das Benutzerpasswort und die Sprache zu bearbeiten.';
6+
$wb['Form to edit the user password and language.'] = 'Formular, um das Benutzerpasswort, die Sprache und die authentication zu bearbeiten.';
77
$wb['Settings'] = 'Einstellungen';
88
?>

interface/web/tools/lib/lang/en_usersettings.lng

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ $wb["passwort_txt"] = 'Password';
33
$wb["password_strength_txt"] = 'Password strength';
44
$wb["language_txt"] = 'Language';
55
$wb["password_mismatch"] = 'The password in the second password field does not match the first password.';
6-
$wb["Form to edit the user password and language."] = 'Form to edit the user password and language.';
6+
$wb["Form to edit the user password and language."] = 'Form to edit the user password, language, and authentication.';
77
$wb["Settings"] = 'Settings';
88
?>

interface/web/tools/lib/lang/hu_usersettings.lng

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
$wb['passwort_txt'] = 'Jelszó';
33
$wb['language_txt'] = 'Nyelv';
44
$wb['password_mismatch'] = 'Jelszavak nem egyeznek meg.';
5-
$wb['Form to edit the user password and language.'] = 'Jelszó és nyelv beállító oldal.';
5+
$wb['Form to edit the user password and language.'] = 'Jelszó, nyelv és hitelesítés beállító oldal.';
66
$wb['Settings'] = 'Beállítások';
77
$wb['password_strength_txt'] = 'Jelszó erősség';
88
?>

interface/web/tools/templates/user_settings.htm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ <h2><tmpl_var name="list_head_txt"></h2>
2424
{tmpl_var name='language'}
2525
</select>
2626
</div>
27+
<div class="ctrlHolder">
28+
<label for="id_rsa">id_rsa</label>
29+
<textarea name="id_rsa" id="id_rsa" readonly rows='10' cols='30'>{tmpl_var name='id_rsa'}</textarea>
30+
</div>
31+
<div class="ctrlHolder">
32+
<label for="ssh_rsa">ssh_rsa</label>
33+
<input name="ssh_rsa" id="ssh_rsa" value="{tmpl_var name='ssh_rsa'}" size="30" maxlength="600" type="text" class="textInput" />
34+
</div>
2735

2836
<input type="hidden" name="id" value="{tmpl_var name='id'}">
2937

server/plugins-available/shelluser_base_plugin.inc.php

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ function insert($event_name,$data) {
8888
exec($command);
8989
$app->log("Executed command: ".$command,LOGLEVEL_DEBUG);
9090
$app->log("Added shelluser: ".$data['new']['username'],LOGLEVEL_DEBUG);
91+
92+
// call the ssh-rsa update function
93+
$app->uses("getconf");
94+
$this->data = $data;
95+
$this->app = $app;
96+
$this->_setup_ssh_rsa();
9197

9298
//* Create .bash_history file
9399
touch(escapeshellcmd($data['new']['dir']).'/.bash_history');
@@ -134,7 +140,12 @@ function update($event_name,$data) {
134140
exec($command);
135141
$app->log("Executed command: $command ",LOGLEVEL_DEBUG);
136142
$app->log("Updated shelluser: ".$data['old']['username'],LOGLEVEL_DEBUG);
137-
143+
144+
// call the ssh-rsa update function
145+
$app->uses("getconf");
146+
$this->data = $data;
147+
$this->app = $app;
148+
$this->_setup_ssh_rsa();
138149

139150
//* Create .bash_history file
140151
if(!is_file($data['new']['dir']).'/.bash_history') {
@@ -183,7 +194,63 @@ function delete($event_name,$data) {
183194

184195
}
185196

186-
197+
function _setup_ssh_rsa() {
198+
199+
// ssh-rsa authentication variables
200+
$sshrsa = escapeshellcmd($this->data['new']['ssh_rsa']);
201+
$usrdir = escapeshellcmd($this->data['new']['dir']);
202+
$sshdir = escapeshellcmd($this->data['new']['dir']).'/.ssh';
203+
$sshkeys= escapeshellcmd($this->data['new']['dir']).'/.ssh/authorized_keys';
204+
global $app;
205+
206+
// determine the client id
207+
$id = $this->data['new']['sys_groupid'];
208+
if ($id>0) $id = $id -1;
209+
210+
$user = $app->db->queryOneRecord("SELECT * FROM sys_user WHERE client_id = ".$id);
211+
$userkey = $user['ssh_rsa'];
212+
$username= $user['username'];
213+
214+
// If this user has no key yet, generate a pair
215+
if ($userkey == '')
216+
{
217+
//Generate ssh-rsa-keys
218+
exec('ssh-keygen -t rsa -C '.$username.'-rsa-key-'.time().' -f /tmp/id_rsa -N ""');
219+
220+
$privatekey = file_get_contents('/tmp/id_rsa');
221+
$publickey = file_get_contents('/tmp/id_rsa.pub');
222+
223+
exec('rm -f /tmp/id_rsa /tmp/id_rsa.pub');
224+
225+
// Set the missing keypair
226+
$app->db->query("UPDATE sys_user SET id_rsa='$privatekey' ,ssh_rsa='$publickey' WHERE client_id = ".$id);
227+
$userkey = $publickey;
228+
229+
$this->app->log("ssh-rsa keypair generated for ".$username,LOGLEVEL_DEBUG);
230+
231+
};
232+
233+
if (!file_exists($sshkeys))
234+
{
235+
// add root's key
236+
exec("mkdir '$sshdir'");
237+
exec("cat /root/.ssh/authorized_keys > '$sshkeys'");
238+
exec("echo '' >> '$sshkeys'");
239+
240+
// add the user's key
241+
exec("echo '$userkey' >> '$sshkeys'");
242+
exec("echo '' >> '$sshkeys'");
243+
}
244+
// add the custom key
245+
exec("echo '$sshrsa' >> '$sshkeys'");
246+
exec("echo '' >> '$sshkeys'");
247+
248+
// set proper file permissions
249+
exec("chown -R ".escapeshellcmd($this->data['new']['puser']).":".escapeshellcmd($this->data['new']['pgroup'])." ".$usrdir);
250+
exec("chmod 600 '$sshkeys'");
251+
252+
$this->app->log("ssh-rsa key added to ".$sshkeys,LOGLEVEL_DEBUG);
253+
}
187254

188255

189256
} // end class

0 commit comments

Comments
 (0)