@@ -1155,34 +1155,37 @@ public function webdav($event_name,$data) {
11551155 */
11561156 private function _writeHtDigestFile ($ filename , $ username , $ authname , $ pwdhash ) {
11571157 $ changed = false ;
1158- $ in = fopen ($ filename , 'r ' );
1159- $ output = '' ;
1160- /*
1161- * read line by line and search for the username and authname
1162- */
1163- while (preg_match ("/:/ " , $ line = fgets ($ in ))) {
1164- $ line = rtrim ($ line );
1165- $ tmp = explode (': ' , $ line );
1166- if ($ tmp [0 ] == $ username && $ tmp [1 ] == $ authname ) {
1167- /*
1168- * found the user. delete or change it?
1169- */
1170- if ($ pwdhash != '' ) {
1171- $ output .= $ tmp [0 ] . ': ' . $ tmp [1 ] . ': ' . $ pwdhash . "\n" ;
1172- }
1173- $ changed = true ;
1174- }
1175- else {
1176- $ output .= $ line . "\n" ;
1158+ if (is_file ($ filename )) {
1159+ $ in = fopen ($ filename , 'r ' );
1160+ $ output = '' ;
1161+ /*
1162+ * read line by line and search for the username and authname
1163+ */
1164+ while (preg_match ("/:/ " , $ line = fgets ($ in ))) {
1165+ $ line = rtrim ($ line );
1166+ $ tmp = explode (': ' , $ line );
1167+ if ($ tmp [0 ] == $ username && $ tmp [1 ] == $ authname ) {
1168+ /*
1169+ * found the user. delete or change it?
1170+ */
1171+ if ($ pwdhash != '' ) {
1172+ $ output .= $ tmp [0 ] . ': ' . $ tmp [1 ] . ': ' . $ pwdhash . "\n" ;
1173+ }
1174+ $ changed = true ;
1175+ }
1176+ else {
1177+ $ output .= $ line . "\n" ;
1178+ }
11771179 }
1180+ fclose ($ in );
11781181 }
11791182 /*
11801183 * if we didn't change anything, we have to add the new user at the end of the file
11811184 */
11821185 if (!$ changed ) {
11831186 $ output .= $ username . ': ' . $ authname . ': ' . $ pwdhash . "\n" ;
11841187 }
1185- fclose ( $ in );
1188+
11861189
11871190 /*
11881191 * Now lets write the new file
0 commit comments