I am hosting multiple websites, and each website has webmail access by going to [webmail.domainname.com...]
basically i want to setup a perl script that will allow me to let users login to their webmail through my site.
If users goto webmail.theirdomain.com they are presented with a login page that has the following type of login form:
<form action="login.php" method="post" name="login">
<input type="text" size="25" name="username"><br>
<input type="password" size="25" name="password">
<input type="hidden" name="server_id" value="0">
<input type="hidden" name="template" value="style1">
<input type="hidden" name="language" value="en">
<input type="submit" name="submit" value="Login">
</form>
Basically, i want to make a script that will ask the user for their email address and password, and using that information it logs them onto the relavant domain's webmail. So basically, if the user enters linda@mydomain.com, the perl script should set the login form action to [webmail.mydomain.com...] and the username should be set to linda and the password should be same.
Can anyone help me make such a script?
Any help would be much appreciated.
Cheers
Linda
The webmail client you are using - your requirements say that is must be logged into using just "linda" and the password.
Do you know if it works if you try and login using the full email address, even though you _don't_ need to? Most email clients are reasonably clever like that. It's the same way that most ISP's will accept either "username" or "username@domain.com" as your username.
First see if that works. If it does, then I think your easiest solution is on your common login script (login.pl?) you inspect the email address to figure out which domain name they're from.
If the email address is linda@foo.com, you would extract foo.com. I don't do Perl, but i'm sure extracting the part after the '@' from a string is easy.
So you've extracted "foo.com". Concat this together with "http://webmail." and "/login.php", giving you "http://webmail.foo.com/login.php", and send the browser a 302 (page moved) to this new location.
The browser should then re-post the form to the users appropriate webmail login script.. :)
Cheers!
PS: If you discover that your webmail system doesn't like the full email address as the username, do you have access to login.php so that you can hack it so that it does?
I've not tested this and i'm making the assumption that 302 (page moved) is a valid reponse to a POST operation and can be handled by browsers ok....
Might be worth checking up with the specs. It's the sort of thing I would imagine Internet Explorer being okay about even if it's not in the specs :)
using these variables i will create a page with hidden fields and then i will use an onload="document.login.submit();" in order to log the user in their webmail
Any suggestions would be much appreciated.
Cheers
Linda
Did you try the 302 solution? It does work, but a GG search reveals some quirks so I wouldn't risk it.
Anyway, if you're going to use JavaScript, why not just do the whole thing client side in JavaScript?
One reason for coming back to your server would of course be to veryify that the domain extracted from the email address is one of yours....
<script type='text/javascript'>
function doSubmit()
{
var s = document.login.username.value;
var p = s.indexOf('@');
var d = s.substring(p + 1, s.length);
var u = s.substring(0, p);
document.login.username.value = u;
document.login.action = 'http://webmail.'+d+'/login.php';
document.login.submit();
}
</script>
<form name="login" method="post" action="">
Email Address: <input type="text" name="username"><br>
Password: <input type="password" name="password"><br>
<input type="hidden" name="server_id" value="0">
<input type="hidden" name="template" value="style1">
<input type="hidden" name="language" value="en">
<input type='button' value='Login' onclick='javascript:doSubmit();'>
</form>
var p = s.indexOf('@');
if (p == -1)
{
alert('Please enter a valid email address.');
}
else
{
var d = s.substring(p + 1, s.length);
var u = s.substring(0, p);
document.login.username.value = u;
document.login.action = 'http://webmail.'+d+'/login.php';
document.login.submit();
}
Other than that, you can of course go a step further and check "d" for ".com" or ".net" etc, or ultimately go all the way and check "d" against all the domains for which you offer webhosting...