5050$ app ->load ('tform_actions ' );
5151
5252class page_action extends tform_actions {
53-
53+
5454 function onShowNew () {
5555 global $ app , $ conf ;
56-
56+
5757 // we will check only users, not admins
5858 if ($ _SESSION ["s " ]["user " ]["typ " ] == 'user ' ) {
5959 if (!$ app ->tform ->checkClientLimit ('limit_webdav_user ' )) {
@@ -63,7 +63,7 @@ function onShowNew() {
6363 $ app ->error ('Reseller: ' .$ app ->tform ->wordbook ["limit_webdav_user_txt " ]);
6464 }
6565 }
66-
66+
6767 parent ::onShowNew ();
6868 }
6969
@@ -72,13 +72,12 @@ function onShowEnd() {
7272 /*
7373 * If the names are restricted -> remove the restriction, so that the
7474 * data can be edited
75- */
76-
75+ */
7776 $ app ->uses ('getconf ' );
7877 $ global_config = $ app ->getconf ->get_global_config ('sites ' );
7978 $ webdavuser_prefix = replacePrefix ($ global_config ['webdavuser_prefix ' ], $ this ->dataRecord );
80-
81- if ($ this ->dataRecord ['username ' ] != "" ){
79+
80+ if ($ this ->dataRecord ['username ' ] != "" ) {
8281 /* REMOVE the restriction */
8382 $ app ->tpl ->setVar ("username " , str_replace ($ webdavuser_prefix , '' , $ this ->dataRecord ['username ' ]));
8483 }
@@ -87,7 +86,7 @@ function onShowEnd() {
8786 } else {
8887 $ app ->tpl ->setVar ("username_prefix " , $ webdavuser_prefix );
8988 }
90-
89+
9190 if ($ this ->id > 0 ) {
9291 //* we are editing a existing record
9392 $ app ->tpl ->setVar ("edit_disabled " , 1 );
@@ -98,102 +97,91 @@ function onShowEnd() {
9897
9998 parent ::onShowEnd ();
10099 }
101-
100+
102101 function onSubmit () {
103102 global $ app , $ conf ;
104-
105- // Get the record of the parent domain
103+
104+ /* Get the record of the parent domain */
106105 $ parent_domain = $ app ->db ->queryOneRecord ("select * FROM web_domain WHERE domain_id = " .intval (@$ this ->dataRecord ["parent_domain_id " ]));
107-
108- // Set a few fixed values
106+
107+ /*
108+ * Set a few fixed values
109+ */
109110 $ this ->dataRecord ["server_id " ] = $ parent_domain ["server_id " ];
110-
111+
112+ /*
113+ * Are there some errors?
114+ */
111115 if (isset ($ this ->dataRecord ['username ' ]) && trim ($ this ->dataRecord ['username ' ]) == '' ) $ app ->tform ->errorMessage .= $ app ->tform ->lng ('username_error_empty ' ).'<br /> ' ;
112116 if (isset ($ this ->dataRecord ['username ' ]) && empty ($ this ->dataRecord ['parent_domain_id ' ])) $ app ->tform ->errorMessage .= $ app ->tform ->lng ('parent_domain_id_error_empty ' ).'<br /> ' ;
113-
117+
114118 parent ::onSubmit ();
115119 }
116-
120+
117121 function onBeforeInsert () {
118122 global $ app , $ conf , $ interfaceConf ;
119123
120124 /*
121125 * If the names should be restricted -> do it!
122- */
123- if ($ app ->tform ->errorMessage == '' ){
124-
126+ */
127+ if ($ app ->tform ->errorMessage == '' ) {
128+
125129 $ app ->uses ('getconf ' );
126130 $ global_config = $ app ->getconf ->get_global_config ('sites ' );
127131 $ webdavuser_prefix = replacePrefix ($ global_config ['webdavuser_prefix ' ], $ this ->dataRecord );
128-
132+
129133 /* restrict the names */
130134 $ this ->dataRecord ['username ' ] = $ webdavuser_prefix . $ this ->dataRecord ['username ' ];
135+
136+ /*
137+ * We shall not save the pwd in plaintext, so we store it as the hash, the apache-moule needs
138+ */
139+ $ hash = md5 ($ this ->dataRecord ["username " ] . ': ' . $ this ->dataRecord ["dir " ] . ': ' . $ this ->dataRecord ["password " ]);
140+ $ this ->dataRecord ["password " ] = $ hash ;
141+
142+ /*
143+ * Get the data of the domain, owning the webdav user
144+ */
145+ $ web = $ app ->db ->queryOneRecord ("SELECT * FROM web_domain WHERE domain_id = " .intval ($ this ->dataRecord ["parent_domain_id " ]));
146+ /* The server is the server of the domain */
147+ $ this ->dataRecord ["server_id " ] = $ web ["server_id " ];
148+ /* The Webdav user shall be owned by the same group then the website */
149+ $ this ->dataRecord ["sys_groupid " ] = $ web ['sys_groupid ' ];
131150 }
151+
132152 parent ::onBeforeInsert ();
133153 }
134-
154+
135155 function onAfterInsert () {
136156 global $ app , $ conf ;
137- /* change pwd here */
138-
139- $ web = $ app ->db ->queryOneRecord ("SELECT * FROM web_domain WHERE domain_id = " .intval ($ this ->dataRecord ["parent_domain_id " ]));
140- $ server_id = $ web ["server_id " ];
141- $ dir = $ web ["document_root " ];
142-
143- // The Webdav user shall be owned by the same group then the website
144- $ sys_groupid = $ web ['sys_groupid ' ];
145-
146- $ sql = "UPDATE webdav_user SET server_id = $ server_id, dir = ' $ dir', sys_groupid = ' $ sys_groupid' WHERE shell_user_id = " .$ this ->id ;
147- $ app ->db ->query ($ sql );
148-
149157 }
150-
158+
151159 function onBeforeUpdate () {
152160 global $ app , $ conf , $ interfaceConf ;
153-
161+
154162 /*
155- * If the names should be restricted -> do it!
163+ * we can not change the username and the dir, so get the "old" - data from the db
164+ * and set it
165+ */
166+ $ data = $ app ->db ->queryOneRecord ("SELECT * FROM webdav_user WHERE webdav_user_id = " .intval ($ this ->id ));
167+ $ this ->dataRecord ["username " ] = $ data ['username ' ];
168+ $ this ->dataRecord ["dir " ] = $ data ['dir ' ];
169+
170+ /*
171+ * We shall not save the pwd in plaintext, so we store it as the hash, the apache-moule
172+ * needs (only if the pwd is changed
156173 */
157- if ($ app ->tform ->errorMessage == '' ) {
158- /*
159- * If the names should be restricted -> do it!
160- */
161- $ app ->uses ('getconf ' );
162- $ global_config = $ app ->getconf ->get_global_config ('sites ' );
163- $ webdavuser_prefix = replacePrefix ($ global_config ['webdavuser_prefix ' ], $ this ->dataRecord );
164-
165- /* restrict the names */
166- $ this ->dataRecord ['username ' ] = $ webdavuser_prefix . $ this ->dataRecord ['username ' ];
174+ if (isset ($ this ->dataRecord ["password " ]) && $ this ->dataRecord ["password " ] != '' ) {
175+ $ hash = md5 ($ this ->dataRecord ["username " ] . ': ' . $ this ->dataRecord ["dir " ] . ': ' . $ this ->dataRecord ["password " ]);
176+ $ this ->dataRecord ["password " ] = $ hash ;
167177 }
178+
179+ parent ::onBeforeUpdate ();
168180 }
169-
181+
170182 function onAfterUpdate () {
171183 global $ app , $ conf ;
172- /* change PWD here */
173-
174- }
175-
176- function getClientName () {
177- global $ app , $ conf ;
178-
179- if ($ _SESSION ["s " ]["user " ]["typ " ] != 'admin ' && !$ app ->auth ->has_clients ($ _SESSION ['s ' ]['user ' ]['userid ' ])) {
180- // Get the group-id of the user
181- $ client_group_id = $ _SESSION ["s " ]["user " ]["default_group " ];
182- } else {
183- // Get the group-id from the data itself
184- $ web = $ app ->db ->queryOneRecord ("SELECT sys_groupid FROM web_domain WHERE domain_id = " .intval ($ this ->dataRecord ['parent_domain_id ' ]));
185- $ client_group_id = $ web ['sys_groupid ' ];
186- }
187- /* get the name of the client */
188- $ tmp = $ app ->db ->queryOneRecord ("SELECT name FROM sys_group WHERE groupid = " . $ client_group_id );
189- $ clientName = $ tmp ['name ' ];
190- if ($ clientName == "" ) $ clientName = 'default ' ;
191- $ clientName = convertClientName ($ clientName );
192-
193- return $ clientName ;
194-
195184 }
196-
197185}
198186
199187$ page = new page_action ;
0 commit comments