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