#!/usr/bin/perl $htpasswdfile="/usr/local/www/offline/autsch/htpasswd"; $method = $ENV{REQUEST_METHOD}; $user = $ENV{REMOTE_USER}; $passwd1 = $ENV{QUERY_passwd1}; $passwd2 = $ENV{QUERY_passwd2}; if ($method ne 'POST') { print "Status: 302\r\n"; print "Content-Type: text/html\r\n"; print "Location: ./\r\n"; print "\r\n"; print "Temporary redirect\n"; print "

Temporary redirect

\n"; print "continue\n"; exit(0); } if ($passwd1 ne $passwd2) { print "Status: 302\r\n"; print "Content-Type: text/html\r\n"; print "Location: changepass-nomatch.html\r\n"; print "\r\n"; print "Temporary redirect\n"; print "

Temporary redirect

\n"; print "continue\n"; exit(0); } srand(time ^ $$); $cryptalpha="./0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; $salt = substr($cryptalpha, rand(64), 1) . substr($cryptalpha, rand(64), 1); $encpwd = crypt($passwd1, $salt); if (!open (IN, "<$htpasswdfile")) { print "Status: 500\r\n"; print "Content-Type: text/html\r\n"; print "\r\n"; print "Server Error\n"; print "

Server Error

\n"; print "Could not open old password file: $!\n"; } if (!open (OUT, ">$htpasswdfile.$$")) { print "Status: 500\r\n"; print "Content-Type: text/html\r\n"; print "\r\n"; print "Server Error\n"; print "

Server Error

\n"; print "Could not open new password file: $!\n"; exit(0); } while () { ($fileuser, $fileencpwd) = split(/[:\n]/); if ($fileuser eq $user) { $fileencpwd = $encpwd; } print OUT "$fileuser:$fileencpwd\n"; } close(IN); if (!close(OUT)) { print "Status: 500\r\n"; print "Content-Type: text/html\r\n"; print "\r\n"; print "Server Error\n"; print "

Server Error

\n"; print "Could not close new password file: $!\n"; exit(0); } if (!rename ("$htpasswdfile.$$", "$htpasswdfile")) { print "Status: 500\r\n"; print "Content-Type: text/html\r\n"; print "\r\n"; print "Server Error\n"; print "

Server Error

\n"; print "Could switch password files: $!\n"; exit(0); } print "Content-Type: text/html\r\n"; print "Refresh: 5; url=https://autsch.hjp.at/mod/\r\n"; print "\r\n"; print "Password changed\n"; print "\n"; print "

Password changed

\n"; print "

The new encrypted password is $encpwd\n"; print "

You will be asked to enter your new password in a few seconds"; print " or when you try to continue.\n";