@@ -991,9 +991,11 @@ public function webdav($event_name,$data) {
991991 /*
992992 * Get additional informations
993993 */
994- $ sitedata = $ app ->db ->queryOneRecord ("SELECT document_root, domain FROM web_domain WHERE domain_id = " . $ data ['new ' ]['parent_domain_id ' ]);
994+ $ sitedata = $ app ->db ->queryOneRecord ("SELECT document_root, domain, system_user, system_group FROM web_domain WHERE domain_id = " . $ data ['new ' ]['parent_domain_id ' ]);
995995 $ documentRoot = $ sitedata ['document_root ' ];
996996 $ domain = $ sitedata ['domain ' ];
997+ $ user = $ sitedata ['system_user ' ];
998+ $ group = $ sitedata ['system_group ' ];
997999
9981000 /* Check if this is a chrooted setup */
9991001 if ($ web_config ['website_basedir ' ] != '' && @is_file ($ web_config ['website_basedir ' ].'/etc/passwd ' )) {
@@ -1012,21 +1014,36 @@ public function webdav($event_name,$data) {
10121014 }
10131015
10141016 /*
1015- * The webdav folder (not the root!) has to be owned by the apache-user
1017+ * The webdav - Root needs the group/user as owner and the apache as read and write
10161018 */
1017- exec ('chown ' . escapeshellcmd ($ web_config ['user ' ]) . ': ' . escapeshellcmd ($ web_config ['group ' ]) . ' ' . $ documentRoot . '/webdav/ ' . $ data ['new ' ]['dir ' ] . ' -R ' );
1019+ $ this ->_exec ("chown " . $ user . ': ' . $ group . ' ' . escapeshellcmd ($ documentRoot . '/webdav/ ' ));
1020+ $ this ->_exec ("chmod 770 " . escapeshellcmd ($ documentRoot . '/webdav/ ' ));
10181021
10191022 /*
1020- * Next step is to update the password - file
1023+ * The webdav folder (not the webdav-root!) needs the same (not in ONE step, because the
1024+ * pwd-files are owned by root)
10211025 */
1022- $ this ->_writeHtDigestFile ( $ documentRoot . '/webdav/ ' . $ data ['new ' ]['dir ' ] . '.htdigest ' , $ data ['new ' ]['username ' ], $ data ['new ' ]['dir ' ], $ data ['new ' ]['password ' ]);
1026+ $ this ->_exec ("chown " . $ user . ': ' . $ group . ' ' . escapeshellcmd ($ documentRoot . '/webdav/ ' . $ data ['new ' ]['dir ' ] . ' -R ' ));
1027+ $ this ->_exec ("chmod 770 " . escapeshellcmd ($ documentRoot . '/webdav/ ' . $ data ['new ' ]['dir ' ] . ' -R ' ));
1028+
1029+ /*
1030+ * if the user is active, we have to write/update the password - file
1031+ * if the user is inactive, we have to inactivate the user by removing the user from the file
1032+ */
1033+ if ($ data ['new ' ]['active ' ] == 'y ' ) {
1034+ $ this ->_writeHtDigestFile ( $ documentRoot . '/webdav/ ' . $ data ['new ' ]['dir ' ] . '.htdigest ' , $ data ['new ' ]['username ' ], $ data ['new ' ]['dir ' ], $ data ['new ' ]['password ' ]);
1035+ }
1036+ else {
1037+ /* empty pwd removes the user! */
1038+ $ this ->_writeHtDigestFile ( $ documentRoot . '/webdav/ ' . $ data ['new ' ]['dir ' ] . '.htdigest ' , $ data ['new ' ]['username ' ], $ data ['new ' ]['dir ' ], '' );
1039+ }
10231040
10241041 /*
10251042 * Next step, patch the vhost - file
10261043 */
10271044 $ vhost_file = escapeshellcmd ($ web_config ["vhost_conf_dir " ] . '/ ' . $ domain . '.vhost ' );
10281045 $ this ->_patchVhostWebdav ($ vhost_file , $ documentRoot . '/webdav ' );
1029-
1046+
10301047 /*
10311048 * Last, restart apache
10321049 */
@@ -1049,21 +1066,22 @@ public function webdav($event_name,$data) {
10491066 /*
10501067 * We dont't want to destroy any (transfer)-Data. So we do NOT delete any dir.
10511068 * So the only thing, we have to do, is to delete the user from the password-file
1052- */
1069+ */
10531070 $ this ->_writeHtDigestFile ( $ documentRoot . '/webdav/ ' . $ data ['old ' ]['dir ' ] . '.htdigest ' , $ data ['old ' ]['username ' ], $ data ['old ' ]['dir ' ], '' );
10541071 }
10551072 }
10561073
10571074
10581075 /**
10591076 * This function writes the htdigest - files used by webdav and digest
1077+ * more info: see http://riceball.com/d/node/424
10601078 * @author Oliver Vogel
10611079 * @param string $filename The name of the digest-file
10621080 * @param string $username The name of the webdav-user
10631081 * @param string $authname The name of the realm
1064- * @param string $pwd The password of the user
1082+ * @param string $pwd The password-hash of the user
10651083 */
1066- private function _writeHtDigestFile ($ filename , $ username , $ authname , $ pwd ) {
1084+ private function _writeHtDigestFile ($ filename , $ username , $ authname , $ pwdhash ) {
10671085 $ changed = false ;
10681086 $ in = fopen ($ filename , 'r ' );
10691087 $ output = '' ;
@@ -1079,7 +1097,7 @@ private function _writeHtDigestFile($filename, $username, $authname, $pwd ) {
10791097 * found the user. delete or change it?
10801098 */
10811099 if ($ pwd != '' ) {
1082- $ tmp [2 ] = md5 ( $ username . ' : ' . $ authname . ' : ' . $ pwd ) ;
1100+ $ tmp [2 ] = $ pwdhash ;
10831101 $ output .= $ tmp [0 ] . ': ' . $ tmp [1 ] . ': ' . $ tmp [2 ] . "\n" ;
10841102 }
10851103 $ changed = true ;
0 commit comments