Skip to content

Commit 026b48f

Browse files
committed
Added shelluser creation plugin.
Updated apache ssl cert creation.
1 parent 0a466df commit 026b48f

File tree

7 files changed

+198
-14
lines changed

7 files changed

+198
-14
lines changed

install/sql/ispconfig3.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -533,12 +533,12 @@ CREATE TABLE `shell_user` (
533533
`password` varchar(255) default NULL,
534534
`quota_size` int(11) NOT NULL default '-1',
535535
`active` varchar(255) NOT NULL default 'y',
536-
`uid` varchar(255) NOT NULL default '0',
537-
`gid` varchar(255) NOT NULL default '0',
536+
`puser` varchar(255) default NULL,
537+
`pgroup` varchar(255) default NULL,
538538
`shell` varchar(255) NOT NULL default '/bin/bash',
539539
`dir` varchar(255) default NULL,
540540
PRIMARY KEY (`shell_user_id`)
541-
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
541+
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
542542

543543
--
544544
-- Daten für Tabelle `shell_user`

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@
138138
##################################
139139
# Begin Datatable fields
140140
##################################
141-
'uid' => array (
141+
'puser' => array (
142142
'datatype' => 'VARCHAR',
143143
'formtype' => 'TEXT',
144144
'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY',
@@ -149,7 +149,7 @@
149149
'width' => '30',
150150
'maxlength' => '255'
151151
),
152-
'gid' => array (
152+
'pgroup' => array (
153153
'datatype' => 'VARCHAR',
154154
'formtype' => 'TEXT',
155155
'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY',

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@
288288
'datatype' => 'VARCHAR',
289289
'formtype' => 'SELECT',
290290
'default' => '',
291-
'value' => array('' => 'None', 'save' => 'Save Certificate', 'create' => 'Create Certificate')
291+
'value' => array('' => 'None', 'save' => 'Save Certificate', 'create' => 'Create Certificate','del' => 'Delete Certificate')
292292
),
293293
##################################
294294
# ENDE Datatable fields

interface/web/sites/shell_user_edit.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ function onAfterInsert() {
8181
$web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".intval($this->dataRecord["parent_domain_id"]));
8282
$server_id = $web["server_id"];
8383
$dir = $web["document_root"];
84-
$uid = $web["system_user"];
85-
$gid = $web["system_group"];
84+
$puser = $web["system_user"];
85+
$pgroup = $web["system_group"];
8686

87-
$sql = "UPDATE shell_user SET server_id = $server_id, dir = '$dir', uid = '$uid', gid = '$gid' WHERE shell_user_id = ".$this->id;
87+
$sql = "UPDATE shell_user SET server_id = $server_id, dir = '$dir', puser = '$puser', pgroup = '$pgroup' WHERE shell_user_id = ".$this->id;
8888
$app->db->query($sql);
8989

9090
}

server/conf/vhost.conf.master

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@
5959

6060

6161

62-
<tmpl_if name='ssl' op='==' value='y'>
62+
<tmpl_if name='ssl_enabled'>
63+
64+
<IfModule mod_ssl.c>
6365
###########################################################
6466
# SSL Vhost
6567
###########################################################
@@ -77,6 +79,13 @@
7779
ErrorDocument 405 /error/methodNotAllowed.html
7880
ErrorDocument 500 /error/internalServerError.html
7981
ErrorDocument 503 /error/overloaded.html
82+
83+
SSLEngine on
84+
SSLCertificateFile <tmpl_var name='document_root'>/<tmpl_var name='domain'>.crt
85+
SSLCertificateKeyFile <tmpl_var name='document_root'>/<tmpl_var name='domain'>.key
86+
<tmpl_if name='has_bundle_cert'>
87+
SSLCACertificateFile <tmpl_var name='document_root'>/<tmpl_var name='domain'>.bundle
88+
</tmpl_if>
8089

8190
<tmpl_if name='alias'>
8291
ServerAlias <tmpl_var name='alias'>
@@ -121,5 +130,6 @@
121130
</tmpl_if>
122131

123132
</VirtualHost>
133+
</IfModule>
124134

125135
</tmpl_if>

server/plugins-enabled/apache2_plugin.inc.php

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ function ssl($event_name,$data) {
117117
$key_file2 = escapeshellcmd($key_file2);
118118
$ssl_days = 3650;
119119
$csr_file = escapeshellcmd($csr_file);
120-
$config_file = escapeshellcmd($config_file);
120+
$config_file = escapeshellcmd($ssl_cnf_file);
121121
$crt_file escapeshellcmd($crt_file);
122122

123123
if(is_file($ssl_cnf_file)){
@@ -136,19 +136,42 @@ function ssl($event_name,$data) {
136136
&& openssl rsa -passin pass:$ssl_password \
137137
-in $key_file \
138138
-out $key_file2");
139+
140+
$app->log("Creating SSL Cert for: $domain",LOGLEVEL_DEBUG);
139141
}
140142

141143
exec("chmod 400 $key_file2");
142-
exec("rm -f $config_file");
143-
exec("rm -f $rand_file");
144+
unlink($config_file);
145+
unlink($rand_file);
144146
$ssl_request = file_get_contents($csr_file);
145147
$ssl_cert = file_get_contents($crt_file);
146148
$mod->db->query("UPDATE web_domain SET ssl_request = '$ssl_request', ssl_cert = '$ssl_cert' WHERE domain = '".$data["new"]["domain"]."'");
147149
}
148150

149151
//* Save a SSL certificate to disk
150152
if($data["new"]["ssl_action"] == 'save') {
151-
153+
$ssl_dir = $data["new"]["document_root"]."/ssl";
154+
$domain = $data["new"]["domain"];
155+
$csr_file = $ssl_dir.'/'.$domain.".csr";
156+
$crt_file = $ssl_dir.'/'.$domain.".crt";
157+
$bundle_file = $ssl_dir.'/'.$domain.".bundle";
158+
file_put_contents($csr_file,$data["new"]["ssl_request"]);
159+
file_put_contents($crt_file,$data["new"]["ssl_cert"]);
160+
if(trim($data["new"]["ssl_bundle"]) != '') file_put_contents($bundle_file,$data["new"]["ssl_bundle"]);
161+
$app->log("Saving SSL Cert for: $domain",LOGLEVEL_DEBUG);
162+
}
163+
164+
//* Delete a SSL certificate
165+
if($data["new"]["ssl_action"] == 'del') {
166+
$ssl_dir = $data["new"]["document_root"]."/ssl";
167+
$domain = $data["new"]["domain"];
168+
$csr_file = $ssl_dir.'/'.$domain.".csr";
169+
$crt_file = $ssl_dir.'/'.$domain.".crt";
170+
$bundle_file = $ssl_dir.'/'.$domain.".bundle";
171+
unlink($csr_file);
172+
unlink($crt_file);
173+
unlink($bundle_file);
174+
$app->log("Deleting SSL Cert for: $domain",LOGLEVEL_DEBUG);
152175
}
153176

154177

@@ -267,6 +290,24 @@ function update($event_name,$data) {
267290

268291
$vhost_data = $data["new"];
269292
$vhost_data["web_document_root"] = $data["new"]["document_root"]."/web";
293+
294+
// Check if a SSL cert exists
295+
$ssl_dir = $data["new"]["document_root"]."/ssl";
296+
$domain = $data["new"]["domain"];
297+
$key_file = $ssl_dir.'/'.$domain.".key";
298+
$crt_file = $ssl_dir.'/'.$domain.".crt";
299+
$bundle_file = $ssl_dir.'/'.$domain.".bundle";
300+
301+
if($data["new"]["ssl"] == 'y' && @is_file($crt_file) && @is_file($key_file) {
302+
$vhost_data["ssl_enabled"] = 1;
303+
$app->log("Enable SSL for: $domain",LOGLEVEL_DEBUG);
304+
} else {
305+
$vhost_data["ssl_enabled"] = 0;
306+
$app->log("Disable SSL for: $domain",LOGLEVEL_DEBUG);
307+
}
308+
309+
if(@is_file($bundle_file)) $vhost_data['has_bundle_cert'] = 1;
310+
270311
//$vhost_data["document_root"] = $data["new"]["document_root"]."/web";
271312
$tpl->setVar($vhost_data);
272313

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
<?php
2+
3+
/*
4+
Copyright (c) 2007, Till Brehm, projektfarm Gmbh
5+
All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without modification,
8+
are permitted provided that the following conditions are met:
9+
10+
* Redistributions of source code must retain the above copyright notice,
11+
this list of conditions and the following disclaimer.
12+
* Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
* Neither the name of ISPConfig nor the names of its contributors
16+
may be used to endorse or promote products derived from this software without
17+
specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22+
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26+
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
class apache2_plugin {
32+
33+
var $plugin_name = 'apache2_plugin';
34+
var $class_name = 'apache2_plugin';
35+
36+
37+
/*
38+
This function is called when the plugin is loaded
39+
*/
40+
41+
function onLoad() {
42+
global $app;
43+
44+
/*
45+
Register for the events
46+
*/
47+
48+
$app->plugins->registerEvent('web_domain_insert',$this->plugin_name,'insert');
49+
$app->plugins->registerEvent('web_domain_update',$this->plugin_name,'update');
50+
$app->plugins->registerEvent('web_domain_delete',$this->plugin_name,'delete');
51+
52+
53+
}
54+
55+
56+
function insert($event_name,$data) {
57+
global $app, $conf;
58+
59+
$app->uses('system');
60+
61+
// Get the UID of the parent user
62+
$uid = intval($app->system->getuid($data['new']['puser']));
63+
if($uid > 999) {
64+
$command = 'useradd';
65+
$command .= ' --home '.escapeshellcmd($data['new']['dir']);
66+
$command .= ' --gid '.escapeshellcmd($data['new']['pgroup']);
67+
$command .= ' --non-unique ';
68+
$command .= ' --password '.escapeshellcmd($data['new']['password']);
69+
$command .= ' --shell '.escapeshellcmd($data['new']['shell']);
70+
$command .= ' --uid '.escapeshellcmd($uid);
71+
$command .= ' '.escapeshellcmd($data['new']['username']);
72+
73+
exec($command);
74+
$app->log("Added shelluser: ".$data['new']['username'],LOGLEVEL_DEBUG);
75+
76+
} else {
77+
$app->log("UID = $uid for shelluser:".$data['new']['username']." not allowed.",LOGLEVEL_ERROR);
78+
}
79+
}
80+
81+
function update($event_name,$data) {
82+
global $app, $conf;
83+
84+
$app->uses('system');
85+
86+
// Get the UID of the parent user
87+
$uid = intval($app->system->getuid($data['new']['puser']));
88+
if($uid > 999) {
89+
$command = 'usermod';
90+
$command .= ' --home '.escapeshellcmd($data['new']['dir']);
91+
$command .= ' --gid '.escapeshellcmd($data['new']['pgroup']);
92+
$command .= ' --non-unique ';
93+
$command .= ' --password '.escapeshellcmd($data['new']['password']);
94+
$command .= ' --shell '.escapeshellcmd($data['new']['shell']);
95+
$command .= ' --uid '.escapeshellcmd($uid);
96+
$command .= ' --login '.escapeshellcmd($data['new']['username']);
97+
$command .= ' '.escapeshellcmd($data['old']['username']);
98+
99+
exec($command);
100+
$app->log("Updated shelluser: ".$data['new']['username'],LOGLEVEL_DEBUG);
101+
102+
} else {
103+
$app->log("UID = $uid for shelluser:".$data['new']['username']." not allowed.",LOGLEVEL_ERROR);
104+
}
105+
106+
}
107+
108+
function delete($event_name,$data) {
109+
global $app, $conf;
110+
111+
$app->uses('system');
112+
113+
// Get the UID of the user
114+
$userid = intval($app->system->getuid($data['old']['username']));
115+
if($userid > 999) {
116+
$command = 'userdel';
117+
$command .= ' '.escapeshellcmd($data['old']['username']);
118+
119+
exec($command);
120+
$app->log("Deleted shelluser: ".$data['old']['username'],LOGLEVEL_DEBUG);
121+
122+
} else {
123+
$app->log("UID = $userid for shelluser:".$data['new']['username']." not allowed.",LOGLEVEL_ERROR);
124+
}
125+
126+
}
127+
128+
129+
130+
131+
} // end class
132+
133+
?>

0 commit comments

Comments
 (0)