#!/usr/bin/perl

print "Content-type: text/HTML\n\n";

require "pw_variables.pm";

$referring_url = $ENV{'HTTP_REFERER'};

if ( !( $referring_url =~ "passwordprotection.html") )
{
	print "You have called this page from an incorrect location - this program will now exit ...<BR>";
	exit;
}

print<<MAINBODY;

<HTML>
<HEAD>
<TITLE>
IE Internet Password Protected Area Management
</TITLE>
<link rel="stylesheet" type="text/css" href="http://www.ieinternet.com/home2.css">
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1"></head>
</HEAD>
<BODY>
<TABLE WIDTH="750" BORDER="0" CELLPADDING="0" CELLSPACING="0">
<TR VALIGN=TOP>
<TD COLSPAN=3>
	<A HREF="http://ieinternet.com/index.htm"><IMG SRC="http://ieinternet.com/images/logo_top.gif" WIDTH="291" HEIGHT="58" BORDER="0"
	ALT="Irelands leader for affordable web hosting, website hosting, email hosting, ecommerce hosting, 
	windows hosting, secure hosting, full anti-virus email screening, full anti-spam email screening, ieinternet.com 
	shared hosting, ieinternet.com sme hosting, irelands leading cost effective web hosting provider.ieinternet.com"></A>
</TD>

<TD>
	<IMG SRC="http://ieinternet.com/images/dot.gif" WIDTH="289" HEIGHT="51" BORDER="0">
</TD>
<TD colspan=2>
	<A HREF="http://ieinternet.com/mycontrolpanel.htm"><img src="http://www.ieinternet.com/images/control_panel.gif"
        WIDTH="170" HEIGHT="51" ALT="Access your control panel here" BORDER="0"></A>

<TD>
	<A HREF="http://ieinternet.com/webmail"><img src="http://ieinternet.com/images/my_webmail.gif" 
	WIDTH="131" HEIGHT="51" ALT="Access your webmail here" BORDER="0"></A>
</TD>
</table>
<P CLASS=TEXT>
<BR><BR>
This page allows you to add and remove users from your password protected area, as well
as being able to change the passwords for <BR>existing users<BR><BR>

<form action=/cgi-bin/pw_updateusers.pl method=post class=text>
<input type=hidden name=section value=add_user>
<B>Add User</B><BR>
<table width=40% class=text>
<tr>
<td width=24%>User Name:</td><td><input class=text name=username><br></td>
</tr>
<tr>
<td>Password:</td><td><input class=text name=password><BR></td>
</tr>
</table>
<input type=image src=http://www.ieinternet.com/images/button_submit.gif>
</form>

<hr WIDTH=50% align=left>

<form action=/cgi-bin/pw_updateusers.pl method=post class=text>
<input type=hidden name=section value=delete_user>
<BR><B>Remove User</B><BR>
<table width=40% class=text>
<tr>
<td width=24%>User Name:</td><td>
MAINBODY

# List the users
open (HTPASSWD, $htpasswdfile) || die "couldn't open the file $htpasswdfile: $!";
while (<HTPASSWD>)
{
	($user, $password) = split (/:/, $_);
	push @htusers, $user;
}
close (HTPASSWD);

$arraysize = @htusers;
print "<select name=username class=text>";
for ( $i = 0 ; $i < $arraysize ; $i++ )
{
	print "<option value=$htusers[$i]>$htusers[$i]";
}
print "</select>";

print<<MIDDLE;

</tr>
</table>
<input type=image src=http://www.ieinternet.com/images/button_submit.gif>
</form>

<hr WIDTH=50% align=left>

<form action=/cgi-bin/pw_updateusers.pl method=post class=text>
<input type=hidden name=section value=change_password>
<BR><B>Change a user's password</B><BR>
<table width=40% class=text>
<tr>
<td width=24%>User Name:</td><td>

MIDDLE

print "<select name=username class=text>";
for ( $i = 0 ; $i < $arraysize ; $i++ )
{
        print "<option value=$htusers[$i]>$htusers[$i]";
}
print "</select>";

print<<FOOT;
</td>
</tr>
<tr>
<td width=24%>New Password:</td><td><input class=text name=password><BR></td>
</tr>
</table>
<input type=image src=http://www.ieinternet.com/images/button_submit.gif>
</form>

<hr WIDTH=50% align=left>

<br><br>
<TABLE WIDTH="750" BORDER="0" CELLPADDING="0" CELLSPACING="0">
<TR VALIGN=TOP><TD><IMG SRC="http://www.ieinternet.com/images/dot.gif"
HEIGHT="3" BORDER="0"></TD>
</TR><TR VALIGN=TOP><TD BGCOLOR="#CC0000"><IMG SRC="http://www.ieinternet.com/images/dot.gif" HEIGHT="7" BORDER="0"></TD>
</TR><TR VALIGN=TOP><TD class="copyright"><IMG SRC="http://www.ieinternet.com/images/home_logos.gif" HEIGHT="46" WIDTH="750" BORDER="0">
<center> Copyright 1998 -  2004 IE Internet.com Ltd. All Rights Reserved. </center></TD></TR></TABLE>

</BODY>
</HTML>

FOOT

