@@ -72,23 +72,27 @@ function insert($event_name,$data) {
7272
7373 $ app ->uses ('system ' );
7474
75- // Get the UID of the parent user
76- $ uid = intval ($ app ->system ->getuid ($ data ['new ' ]['puser ' ]));
77- if ($ uid > $ this ->min_uid ) {
78- $ command = 'useradd ' ;
79- $ command .= ' --home ' .escapeshellcmd ($ data ['new ' ]['dir ' ]);
80- $ command .= ' --gid ' .escapeshellcmd ($ data ['new ' ]['pgroup ' ]);
81- $ command .= ' --non-unique ' ;
82- $ command .= ' --password ' .escapeshellcmd ($ data ['new ' ]['password ' ]);
83- $ command .= ' --shell ' .escapeshellcmd ($ data ['new ' ]['shell ' ]);
84- $ command .= ' --uid ' .escapeshellcmd ($ uid );
85- $ command .= ' ' .escapeshellcmd ($ data ['new ' ]['username ' ]);
75+ if ($ app ->system ->is_user ($ data ['new ' ]['puser ' ])) {
76+ // Get the UID of the parent user
77+ $ uid = intval ($ app ->system ->getuid ($ data ['new ' ]['puser ' ]));
78+ if ($ uid > $ this ->min_uid ) {
79+ $ command = 'useradd ' ;
80+ $ command .= ' --home ' .escapeshellcmd ($ data ['new ' ]['dir ' ]);
81+ $ command .= ' --gid ' .escapeshellcmd ($ data ['new ' ]['pgroup ' ]);
82+ $ command .= ' --non-unique ' ;
83+ $ command .= ' --password ' .escapeshellcmd ($ data ['new ' ]['password ' ]);
84+ $ command .= ' --shell ' .escapeshellcmd ($ data ['new ' ]['shell ' ]);
85+ $ command .= ' --uid ' .escapeshellcmd ($ uid );
86+ $ command .= ' ' .escapeshellcmd ($ data ['new ' ]['username ' ]);
8687
87- exec ($ command );
88- $ app ->log ("Added shelluser: " .$ data ['new ' ]['username ' ],LOGLEVEL_DEBUG );
88+ exec ($ command );
89+ $ app ->log ("Added shelluser: " .$ data ['new ' ]['username ' ],LOGLEVEL_DEBUG );
8990
91+ } else {
92+ $ app ->log ("UID = $ uid for shelluser: " .$ data ['new ' ]['username ' ]." not allowed. " ,LOGLEVEL_ERROR );
93+ }
9094 } else {
91- $ app ->log ("UID = $ uid for shelluser : " .$ data ['new ' ]['username ' ]." not allowed . " ,LOGLEVEL_ERROR );
95+ $ app ->log ("Skippung insert of user : " .$ data ['new ' ]['username ' ].", parent user " . $ data [ ' new ' ][ ' puser ' ]. " does not exist . " ,LOGLEVEL_WARN );
9296 }
9397 }
9498
@@ -97,25 +101,34 @@ function update($event_name,$data) {
97101
98102 $ app ->uses ('system ' );
99103
100- // Get the UID of the parent user
101- $ uid = intval ($ app ->system ->getuid ($ data ['new ' ]['puser ' ]));
102- if ($ uid > $ this ->min_uid ) {
103- $ command = 'usermod ' ;
104- $ command .= ' --home ' .escapeshellcmd ($ data ['new ' ]['dir ' ]);
105- $ command .= ' --gid ' .escapeshellcmd ($ data ['new ' ]['pgroup ' ]);
106- // $command .= ' --non-unique ';
107- $ command .= ' --password ' .escapeshellcmd ($ data ['new ' ]['password ' ]);
108- if ($ data ['new ' ]['chroot ' ] != 'jailkit ' ) $ command .= ' --shell ' .escapeshellcmd ($ data ['new ' ]['shell ' ]);
109- // $command .= ' --uid '.escapeshellcmd($uid);
110- $ command .= ' --login ' .escapeshellcmd ($ data ['new ' ]['username ' ]);
111- $ command .= ' ' .escapeshellcmd ($ data ['old ' ]['username ' ]);
112-
113- exec ($ command );
114- // $app->log("Updated shelluser: $command ",LOGLEVEL_DEBUG);
115- $ app ->log ("Updated shelluser: " .$ data ['old ' ]['username ' ],LOGLEVEL_DEBUG );
104+ if ($ app ->system ->is_user ($ data ['new ' ]['puser ' ])) {
105+ // Get the UID of the parent user
106+ $ uid = intval ($ app ->system ->getuid ($ data ['new ' ]['puser ' ]));
107+ if ($ uid > $ this ->min_uid ) {
108+ // Check if the user that we want to update exists, if not, we insert it
109+ if ($ app ->system ->is_user ($ data ['old ' ]['username ' ])) {
110+ $ command = 'usermod ' ;
111+ $ command .= ' --home ' .escapeshellcmd ($ data ['new ' ]['dir ' ]);
112+ $ command .= ' --gid ' .escapeshellcmd ($ data ['new ' ]['pgroup ' ]);
113+ // $command .= ' --non-unique ';
114+ $ command .= ' --password ' .escapeshellcmd ($ data ['new ' ]['password ' ]);
115+ if ($ data ['new ' ]['chroot ' ] != 'jailkit ' ) $ command .= ' --shell ' .escapeshellcmd ($ data ['new ' ]['shell ' ]);
116+ // $command .= ' --uid '.escapeshellcmd($uid);
117+ $ command .= ' --login ' .escapeshellcmd ($ data ['new ' ]['username ' ]);
118+ $ command .= ' ' .escapeshellcmd ($ data ['old ' ]['username ' ]);
116119
120+ exec ($ command );
121+ // $app->log("Updated shelluser: $command ",LOGLEVEL_DEBUG);
122+ $ app ->log ("Updated shelluser: " .$ data ['old ' ]['username ' ],LOGLEVEL_DEBUG );
123+ } else {
124+ // The user does not exist, so we insert it now
125+ $ this ->insert ($ event_name ,$ data );
126+ }
127+ } else {
128+ $ app ->log ("UID = $ uid for shelluser: " .$ data ['new ' ]['username ' ]." not allowed. " ,LOGLEVEL_ERROR );
129+ }
117130 } else {
118- $ app ->log ("UID = $ uid for shelluser : " .$ data ['new ' ]['username ' ]." not allowed . " ,LOGLEVEL_ERROR );
131+ $ app ->log ("Skippung update for user : " .$ data ['new ' ]['username ' ].", parent user " . $ data [ ' new ' ][ ' puser ' ]. " does not exist . " ,LOGLEVEL_WARN );
119132 }
120133 }
121134
@@ -124,17 +137,21 @@ function delete($event_name,$data) {
124137
125138 $ app ->uses ('system ' );
126139
127- // Get the UID of the user
128- $ userid = intval ($ app ->system ->getuid ($ data ['old ' ]['username ' ]));
129- if ($ userid > $ this ->min_uid ) {
130- $ command = 'userdel ' ;
131- $ command .= ' ' .escapeshellcmd ($ data ['old ' ]['username ' ]);
140+ if ($ app ->system ->is_user ($ data ['old ' ]['username ' ])) {
141+ // Get the UID of the user
142+ $ userid = intval ($ app ->system ->getuid ($ data ['old ' ]['username ' ]));
143+ if ($ userid > $ this ->min_uid ) {
144+ $ command = 'userdel ' ;
145+ $ command .= ' ' .escapeshellcmd ($ data ['old ' ]['username ' ]);
132146
133- exec ($ command );
134- $ app ->log ("Deleted shelluser: " .$ data ['old ' ]['username ' ],LOGLEVEL_DEBUG );
147+ exec ($ command );
148+ $ app ->log ("Deleted shelluser: " .$ data ['old ' ]['username ' ],LOGLEVEL_DEBUG );
135149
150+ } else {
151+ $ app ->log ("UID = $ userid for shelluser: " .$ data ['old ' ]['username ' ]." not allowed. " ,LOGLEVEL_ERROR );
152+ }
136153 } else {
137- $ app ->log ("UID = $ userid for shelluser : " .$ data ['new ' ]['username ' ]." not allowed . " ,LOGLEVEL_ERROR );
154+ $ app ->log ("User : " .$ data ['new ' ]['username ' ]." does not exist in in /etc/passwd, skipping delete . " ,LOGLEVEL_WARN );
138155 }
139156
140157 }
0 commit comments