PDA

View Full Version : Webmail Signup PHP, Linux etc



dwnz
12-09-2005, 09:57 PM
Hey,
I need a script that can create an email account for users on a signup page. I have got SquirrelMail going fine, but cant find anything that doesnt use cPannel or the like. All i want is a script that can signup new users for a email account.

Thanks
Daniel

dwnz
13-09-2005, 03:11 PM
Ok, i have found the page where the web config thing i use adds clients, but since its in PHP i dont understand how it works (Im used to using ASP, but that cant do what i want on linux!)
I have this code below, which is what i think i need to use, but im not sure. All i want it to do is enable people to signup online, and get a email address, which this does through the web config thing i use.

I also found this....http://www.clarkconnect.org/developer/api/index.php?target=User.html



<?php

// vim: ts=4
///////////////////////////////////////////////////////////////////////////////
//
// Copyright 2003-2004 Point Clark Networks.
//
///////////////////////////////////////////////////////////////////////////////
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
///////////////////////////////////////////////////////////////////////////////
//
// Gotchas:
// --------
// The "Full Name" form variable is one of the few places where a single quote
// (') is allowed (e.g. Tim O'Reilly). We must do a string replacement right
// before we display the variable, and reverse the process before working
// with the variable.
// ... $fullname = str_replace("'", "&#39", $fullname);
//
///////////////////////////////////////////////////////////////////////////////

require_once("../../classes/webconfig.inc");
require_once("../../classes/locale.class");
require_once("../../classes/user.class");
require_once("../../classes/usermanager.class");
require_once("../../classes/shell.class");
$locale = new Locale();
require_once($locale->GetLanguageTemplate(__FILE__));


///////////////////////////////////////////////////////////////////////////////
//
// Icons
//
///////////////////////////////////////////////////////////////////////////////

define(WEB_ICON_PPTP, ReplacePngTags("/images/icon-users-pptp.png", "P"));
define(WEB_ICON_SAMBA, ReplacePngTags("/images/icon-users-samba.png", "F"));
define(WEB_ICON_SHELL, ReplacePngTags("/images/icon-users-shell.png", "S"));
define(WEB_ICON_EMAIL, ReplacePngTags("/images/icon-users-email.png", "M"));


///////////////////////////////////////////////////////////////////////////////
//
// Header
//
///////////////////////////////////////////////////////////////////////////////

WebAuthenticate();
WebHeader(WEB_LANG_PAGE_TITLE);
WebDialogIntro(WEB_LANG_PAGE_TITLE, "/images/icon-users.png", WEB_LANG_PAGE_INTRO);


///////////////////////////////////////////////////////////////////////////////
//
// Handle Update
//
///////////////////////////////////////////////////////////////////////////////

$errors = array();

$usermanager = new UserManager();

// Common stuff for changing for form variables (on/off) to PHP booleans
//----------------------------------------------------------------------

if ($AddUser || $UpdateUser) {
$username = strtolower($username);
$userinfo[USERMANAGER_USERINFO_FULL_NAME] = str_replace("&#39", "'", $fullname); // see comment above

if (preg_match("/on/i", $shell))
$userinfo[USERMANAGER_USERINFO_IS_SHELL_USER] = true;
else
$userinfo[USERMANAGER_USERINFO_IS_SHELL_USER] = false;

if (preg_match("/on/i", $samba))
$userinfo[USERMANAGER_USERINFO_IS_SAMBA_USER] = true;
else
$userinfo[USERMANAGER_USERINFO_IS_SAMBA_USER] = false;

if (preg_match("/on/i", $pptp))
$userinfo[USERMANAGER_USERINFO_IS_PPTP_USER] = true;
else
$userinfo[USERMANAGER_USERINFO_IS_PPTP_USER] = false;

if (preg_match("/on/i", $email))
$userinfo[USERMANAGER_USERINFO_IS_EMAIL_USER] = true;
else
$userinfo[USERMANAGER_USERINFO_IS_EMAIL_USER] = false;
}

// Do update
//----------

if ($AddUser) {
$checkweak = VerifyPassword($password, $verify);
$checkstrong = VerifyPassword($strongpassword, $strongverify);
if ($checkweak || $checkstrong) {
if ($checkweak)
$errors[] = $checkweak . " (" . LOCALE_LANG_PASSWORD . ")";
if ($checkstrong)
$errors[] = $checkstrong . " (" . USER_LANG_SECURE_PASSWORD . ")";
} else {
$userinfo[USERMANAGER_USERINFO_PASSWORD_WEAK] = $password;
$userinfo[USERMANAGER_USERINFO_PASSWORD_STRONG] = $strongpassword;
$usermanager->AddUser($username, $userinfo, $errmsg);
if ($errmsg)
$errors[] = $errmsg;
}
} else if ($UpdateUser) {
$checkweak = VerifyPassword($password, $verify);
$checkstrong = VerifyPassword($strongpassword, $strongverify);
if ($checkweak || $checkstrong) {
if ($checkweak)
$errors[] = $checkweak . " (" . LOCALE_LANG_PASSWORD . ")";
if ($checkstrong)
$errors[] = $checkstrong . " (" . USER_LANG_SECURE_PASSWORD . ")";
} else {
$userinfo[USERMANAGER_USERINFO_PASSWORD_WEAK] = $password;
$userinfo[USERMANAGER_USERINFO_PASSWORD_STRONG] = $strongpassword;
$usermanager->UpdateUser($username, $userinfo, $errors[]);
}
if ($errors[0])
$EditUser[$username] = "redo";
} else if ($DoDelete) {
$usermanager->DeleteUser(key($DoDelete), $deletehome, $errors[]);
}

$errmsg = WebCheckErrors($errors);
if ($errmsg) {
WebDialogWarning($errmsg);
} else {
$username = "";
$fullname = "";
$shell = "";
$samba = "";
$pptp = "";
$email = "";
$verify = "";
$password = "";
$strongpassword = "";
$strongverify = "";
}


///////////////////////////////////////////////////////////////////////////////
//
// Main
//
///////////////////////////////////////////////////////////////////////////////

if ($EditUser) {
DisplayAddEdit("edit", key($EditUser));
} else if ($legacy_edit && !$Cancel) {
DisplayAddEdit("edit", $legacy_edit);
} else if ($DeleteUser) {
DisplayDelete(key($DeleteUser));
} else {
DisplayUsers();
DisplayAddEdit("add", $username, $shell, $fullname, $samba, $pptp, $email,
$password, $verify, $strongpassword, $strongverify);
}

WebFooter();


///////////////////////////////////////////////////////////////////////////////
// F U N C T I O N S
///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////
//
// DisplayUsers()
//
///////////////////////////////////////////////////////////////////////////////

function DisplayUsers()
{
$user = new User(""); // To grab language tags
$users = new UserManager();
$shell = new Shell();

$userlist = $users->GetAllUserInfo(true, $errmsg);
if ($errmsg) {
WebDialogWarning($errmsg);
return;
}

while (list($user, $info) = each($userlist)) {

// Show error is there is some kind of sanity check failure
//---------------------------------------------------------

if (! $info[USERMANAGER_USERINFO_IS_SANE]) {
$errors[] .= USER_LANG_ERRMSG_USER_SYNCHRONIZATION_ERROR . " (" . $user . ")";
continue;
}

// Don't let users delete root account
//------------------------------------

if ($user == "root")
$deletebutton = "";
else
$deletebutton = WebButtonDelete("DeleteUser[$user]");

// Only show modules installed on the system
//------------------------------------------

$options = "";
if ($info[USERMANAGER_USERINFO_IS_EMAIL_USER])
$options .= WEB_ICON_EMAIL . " ";

if ($info[USERMANAGER_USERINFO_IS_SAMBA_USER])
$options .= WEB_ICON_SAMBA . " ";

if ($info[USERMANAGER_USERINFO_IS_PPTP_USER])
$options .= WEB_ICON_PPTP . " ";

if ($info[USERMANAGER_USERINFO_IS_SHELL_USER])
$options .= WEB_ICON_SHELL . " ";

$usertable[] = "
<tr>
<td>" . $user . "</td>
<td>" . $info[USERMANAGER_USERINFO_FULL_NAME] . "</td>
<td>" . $options . "</td>
<td nowrap>" . WebButtonEdit("EditUser[$user]") . $deletebutton . "</td>
</tr>
";
}

$errmsg = WebCheckErrors($errors);
if ($errmsg)
WebDialogWarning($errmsg);

// Display list of user on the system
//-----------------------------------

if ($usertable) {
sort($usertable);
$usertable_output = implode("\n", $usertable);

global $usermanager;

$services = $usermanager->GetInstalledServices($errmsg);
if ($errmsg)
return;

if (in_array(USERMANAGER_SERVICE_SAMBA, $services))
$legend .= WEB_ICON_SAMBA . " " . USER_LANG_SAMBA . " &nbsp; &nbsp; ";

if (in_array(USERMANAGER_SERVICE_EMAIL, $services))
$legend .= WEB_ICON_EMAIL . " " . USER_LANG_EMAIL . " &nbsp; &nbsp; ";

if (in_array(USERMANAGER_SERVICE_PPTP, $services))
$legend .= WEB_ICON_PPTP . " " . USER_LANG_PPTP . " &nbsp; &nbsp; ";

if (in_array(USERMANAGER_SERVICE_SHELL, $services))
$legend .= WEB_ICON_SHELL . " " . USER_LANG_SHELL . " &nbsp; &nbsp; ";


WebFormOpen("users.php", "post");
WebTableOpen(WEB_LANG_USER_INFO_TITLE, "100%");
WebTableHeader(LOCALE_LANG_USERNAME . "|" . USER_LANG_FULLNAME . "|" . USER_LANG_OPTIONS . "|" . LOCALE_LANG_ACTION);
echo $usertable_output;
echo "<tr><td colspan='4' style='background: #CCCCCC; border-top: 1px solid #999999;' align='center'>$legend</td>";
WebTableClose();
WebFormClose();
}
}


///////////////////////////////////////////////////////////////////////////////
//
// DisplayAddEdit()
//
///////////////////////////////////////////////////////////////////////////////

function DisplayAddEdit($type, $username, $shell = "", $fullname = "", $samba = "", $pptp = "", $email = "",
$password = "", $verify = "", $strongpassword = "", $strongverify = "")
{
// TODO: cleanup the root special case.

global $usermanager;

$user = new User(""); // To grab language tags
$servicelist = $usermanager->GetInstalledServices($errmsg);

if ($type == "add") {
$userfield = "<input type='text' name='username' value='$username'>";
$title = WEB_LANG_ADD_USER_TITLE;
$action = "
<tr>
<td class='header'></td>
<td>" . WebButtonAdd("AddUser") . " " . WebButtonCancel("") . "</td>
</tr>
";

} else {
$userfield = "$username <input type='hidden' name='username' value='$username'>";
$title = WEB_LANG_EDIT_INFO_TITLE;
$action = "
<tr>
<td class='header'></td>
<td>" . WebButtonUpdate("UpdateUser[$username]") . " " . WebButtonCancel("") . "</td>
</tr>
";

$userinfo = $usermanager->GetUserInfo($username, $errmsg);
if ($errmsg) {
WebDialogWarning($errmsg);
return;
}

$fullname = $userinfo[USERMANAGER_USERINFO_FULL_NAME];
$password = $userinfo[USERMANAGER_USERINFO_PASSWORD_WEAK];
$verify = $password;
$strongpassword = $userinfo[USERMANAGER_USERINFO_PASSWORD_STRONG];
$strongverify = $strongpassword;

if ($userinfo[USERMANAGER_USERINFO_IS_SAMBA_USER])
$samba = "on";
if ($userinfo[USERMANAGER_USERINFO_IS_PPTP_USER])
$pptp = "on";
if ($userinfo[USERMANAGER_USERINFO_IS_EMAIL_USER])
$email = "on";
if ($userinfo[USERMANAGER_USERINFO_IS_SHELL_USER])
$shell = "on";

// Upgrade issue -- user must reset password if we don't have
// it in the /etc/users database

if ($username == "root") {
$use_root_config = true;
} else if (!$userinfo[USERMANAGER_USERINFO_PASSWORD_WEAK]) {
$legacy_upgrade_required = true;
$legacy_edit = "<input type='hidden' name='legacy_edit' value='$username'>";
}
}

// Add options if installed
//-------------------------

if (in_array(USERMANAGER_SERVICE_EMAIL, $servicelist)) {
if (preg_match("/on/i", $email))
$emailon = "checked";
$addoptions .= "
<tr>
<td class='header'>" . USER_LANG_EMAIL . "</td>
<td><input type='checkbox' name='email' $emailon></td>
</tr>
";
}

if (in_array(USERMANAGER_SERVICE_SAMBA, $servicelist)) {
if (preg_match("/on/i", $samba))
$sambaon = "checked";
$addoptions .= "
<tr>
<td class='header'>" . USER_LANG_SAMBA . "</td>
<td><input type='checkbox' name='samba' $sambaon></td>
</tr>
";
}

if (in_array(USERMANAGER_SERVICE_PPTP, $servicelist)) {
if (preg_match("/on/i", $pptp))
$pptpon = "checked";
$addoptions .= "
<tr>
<td class='header'>" . USER_LANG_PPTP . "</td>
<td><input type='checkbox' name='pptp' $pptpon></td>
</tr>
";
}

if (in_array(USERMANAGER_SERVICE_SHELL, $servicelist)) {
if (preg_match("/on/i", $shell))
$shellon = "checked";
$addoptions .= "
<tr>
<td class='header'>" . USER_LANG_SHELL . "</td>
<td><input type='checkbox' name='shell' $shellon></td>
</tr>
";
}

if ($legacy_upgrade_required)
WebDialogWarning(WEB_LANG_LEGACY_PASSWORD_RESET);

// Show add user table
//--------------------

$fullname = str_replace("'", "&#39", $fullname);

WebFormOpen("users.php", "post");
if ($use_root_config) {
echo "<input type='hidden' name='password' value='notapplicable'>";
echo "<input type='hidden' name='verify' value='notapplicable'>";
echo "<input type='hidden' name='shell' value='on'>";
echo "<input type='hidden' name='fullname' value='root'>";
}
WebTableOpen($title, "100%");
echo "
<tr>
<td width='100' class='header'>" . LOCALE_LANG_USERNAME . "</td>
<td>$userfield</td>
</tr>
";
if (! $use_root_config) {
echo "
<tr>
<td class='header'>" . USER_LANG_FULLNAME . "</td>
<td><input size='20' type='text' name='fullname' value='$fullname'></td>
</tr>
<tr>
<td class='header'>" . LOCALE_LANG_PASSWORD . "</td>
<td>
<input size='20' type='password' name='password' value='$password'> &nbsp; <b>" . LOCALE_LANG_VERIFY . "</b>
<input size='20' type='password' name='verify' value='$verify'>
</td>
</tr>
";
}
echo "
<tr>
<td class='header'>" . USER_LANG_SECURE_PASSWORD . "</td>
<td>
<input size='20' type='password' name='strongpassword' value='$strongpassword'> &nbsp; <b>" . LOCALE_LANG_VERIFY . "</b>
<input size='20' type='password' name='strongverify' value='$strongverify'>
</td>
</tr>
";

if (! $use_root_config)
echo $addoptions;

echo $action;

WebTableClose();
WebFormClose();
}


///////////////////////////////////////////////////////////////////////////////
//
// DisplayDelete()
//
///////////////////////////////////////////////////////////////////////////////

function DisplayDelete($username)
{
WebFormOpen("users.php", "post");
WebTableOpen(LOCALE_LANG_CONFIRM, "400");
echo "
<tr>
<td align='center'>
<br>
<p>" . WEBCONFIG_ICON_WARNING . " " . WEB_LANG_ARE_YOU_SURE1 . " $username " . WEB_LANG_ARE_YOU_SURE2 . "</p>
<p><input type='checkbox' name='deletehome'>" . WEB_LANG_DELETE_FILES . "<br><br>
". WebButtonDelete("DoDelete[$username]") . " " . WebButtonCancel("Cancel") . "
</td>
</tr>
";
WebTableClose();
WebFormClose();
}


///////////////////////////////////////////////////////////////////////////////
//
// VerifyPassword()
//
///////////////////////////////////////////////////////////////////////////////

function VerifyPassword($password, $verify)
{
if (!$password || !$verify)
return WEB_LANG_PASSWORD_REQUIRED;

if ($password != $verify)
return WEB_LANG_PASSWORD_VERIFY_MISMATCH;
}

?>



Cheers
Daniel