Commit d0f8fd35 authored by Benjamin Sonntag's avatar Benjamin Sonntag
Browse files

commit 2/3: new email class, adding PAGER on functions.php, search engine in...

commit 2/3: new email class, adding PAGER on functions.php, search engine in email list, email ARE broken now, please wait for third commit
parent 5a6a7008
bureau/admin/images/check_no.png

1.43 KB | W: | H:

bureau/admin/images/check_no.png

575 Bytes | W: | H:

bureau/admin/images/check_no.png
bureau/admin/images/check_no.png
bureau/admin/images/check_no.png
bureau/admin/images/check_no.png
  • 2-up
  • Swipe
  • Onion skin
bureau/admin/images/check_ok.png

3.96 KB | W: | H:

bureau/admin/images/check_ok.png

535 Bytes | W: | H:

bureau/admin/images/check_ok.png
bureau/admin/images/check_ok.png
bureau/admin/images/check_ok.png
bureau/admin/images/check_ok.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -186,6 +186,7 @@ function check_mail_form_validity(id_elem) {
* Function :is_valid_mail
* @param : interger arg, an RFC 2822 mail adress
* @return : true if arg really is formed like described in RFC 2822, else false
* FIXME: does this function is used anywhere ? if yes, remove it, see http://www.bortzmeyer.org/arreter-d-interdire-des-adresses-legales.html
*/
function is_valid_mail(arg) {
//FIXME mail documentation doesn't expect a maximum length of the mail address : http://tools.ietf.org/html/rfc2822#section-3.4.1
......
<?php
/*
$Id: mail_edit.php, author:squidly
----------------------------------------------------------------------
AlternC - Web Hosting System
Copyright (C) 2002 by the AlternC Development Team.
http://alternc.org/
----------------------------------------------------------------------
Based on:
Valentin Lacambre's web hosting softwares: http://altern.org/
Copyright (C) 2000-2012 by the AlternC Development Team.
https://alternc.org/
----------------------------------------------------------------------
LICENSE
......
<?php
/*
$Id: mail_list.php, author: squidly
----------------------------------------------------------------------
AlternC - Web Hosting System
Copyright (C) 2002 by the AlternC Development Team.
http://alternc.org/
----------------------------------------------------------------------
Based on:
Valentin Lacambre's web hosting softwares: http://altern.org/
Copyright (C) 2000-2012 by the AlternC Development Team.
https://alternc.org/
----------------------------------------------------------------------
LICENSE
......@@ -23,7 +19,7 @@
To read the license please visit http://www.gnu.org/copyleft/gpl.html
----------------------------------------------------------------------
Purpose of file: listing of mail accounts
Purpose of file: listing of mail accounts for one domain.
----------------------------------------------------------------------
*/
......@@ -31,22 +27,27 @@ require_once("../class/config.php");
include_once("head.php");
$fields = array (
"domain" => array ("request", "string", ""),
"domain_id" => array ("request", "integer", ""),
);
"domain_id" => array ("request", "integer", ""),
"search" => array ("request", "string", ""),
"offset" => array ("request", "integer", 0),
"count" => array ("request", "integer", 50),
);
$champs=getFields($fields);
if( !$domain && !$domain_id )
{
include("main.php");
exit();
}
$counts=array("10" => "10", "20" => "20", "30" => "30", "50" => "50", "100" => "100", "200" => "200", "500" => "500", "1000" => "1000");
$domain_id=$champs["domain_id"];
if(!$domain_id ) {
include("main.php");
exit();
}
if(!$mails_list = $mail->enum_domain_mails($domain_id)){
$error=$err->errstr();
if ($domain=$dom->get_domain_byid($domain_id)) {
if(!($mails_list = $mail->enum_domain_mails($domain_id,$search,$offset,$count))) {
$error=$err->errstr();
}
} else {
$error=$err->errstr();
}
?>
......@@ -55,15 +56,14 @@ if (isset($error)) {
echo "<p class=\"error\">$error</p>";
}
//Mail creation.
if ($quota->cancreate("mail")) { ?>
// Mail creation form
if ($quota->cancreate("mail")) {
?>
<h3><?php __("Create a new mail account");?></h3>
<form method="post" action="mail_doadd.php" id="main" name="mail_create" onsubmit="return is_valid_mail(document.getElementById('mail_arg').value+"@"+document.getElementById('domain') )">
<input type="text" class="int" name="mail_arg" value="" size="20" id="mail_arg" maxlength="32" /><span id="emaildom" class="int" > <?php echo "@".$domain; ?></span>
<form method="post" action="mail_doadd.php" id="main" name="mail_create">
<input type="text" class="int intleft" style="text-align: right" name="mail_arg" value="" size="32" id="mail_arg" maxlength="255" /><span id="emaildom" class="int intright"><?php echo "@".$domain; ?></span>
<input type="hidden" name="domain_id" value="<?php echo $domain_id;?>" />
<input type="hidden" name="domain" id="domain" value="<?php echo $domain;?>" />
<input type="hidden" name="arg" id="arg" value="<?php echo $domain;?>" />
<input type="submit" name="submit" class="inb" value="<?php __("Create"); ?>" />
<input type="submit" name="submit" class="inb" value="<?php __("Create this email address"); ?>" />
</form>
<?php
}
......@@ -72,32 +72,73 @@ if (empty($mails_list)){ // If there is no mail for this domain
__("No mail for this domain");
} else {
?>
<br />
<hr />
<h3><?php printf(_("Email addresses of the domain %s"),$domain); ?> : </h3>
<table class="searchtable"><tr><td>
<form method="get" name="" action="mail_list.php">
<input type="hidden" name="domain_id" value="<?php echo $domain_id; ?>" />
<input type="hidden" name="offset" value="0" />
<span class="int intleft"><img src="/images/search.png" style="vertical-align: middle"/> </span><input type="text" name="search" value="<?php ehe($search); ?>" size="20" maxlength="64" class="int intright" />
</form>
</td><td>
<?php pager($offset,$count,$mail->total,"mail_list.php?domain_id=".$domain_id."&count=".$count."&search=".urlencode($search)."&offset=%%offset%%"); ?>
</td><td style="text-align:right">
<form method="get" name="" action="mail_list.php">
<input type="hidden" name="domain_id" value="<?php echo $domain_id; ?>" />
<input type="hidden" name="offset" value="0" />
<?php __("Items per page:"); ?> <select name="count" class="inl" onchange="submit()"><?php eoption($counts,$count); ?></select>
</form>
</td></tr></table>
</fieldset>
<form method="post" action="mail_del.php">
<table class="tlist">
<tr><th><?php __("Active");?></th><th align=center><?php __("Address"); ?></th><th><?php __("State"); ?></th></tr>
<tr><th></th><th></th><th><?php __("Enabled");?></th><th style="text-align:right"><?php __("Address"); ?></th><th><?php __("Pop/Imap"); ?></th><th><?php __("Other recipients"); ?></th><th><?php __("Last login time"); ?></th></tr>
<?php
$col=1;
$col=1; $i=0;
//listing of every mail of the current domain.
while (list($key,$val)=each($mails_list)){
$col=3-$col;
?>
<tr class="lst_clic<?php echo $col; ?>" onclick="javascript:window.location.href='mail_properties.php?mail_id=<?php echo $val["id"]; ?>'">
<tr class="lst<?php echo $col; ?>">
<?php if (!$val["type"]) { ?>
<td align="center">
<input class="inc" type="checkbox" id="del_<?php echo $i; ?>" name="d[]\" value="<?php ehe($val["address"]); ?>" />
</td>
<td>
<div class="ina"><a href="mail_properties.php?mail_id=<?php echo $val["id"] ?>"><img src="images/edit.png" alt="<?php __("Edit"); ?>" /><?php __("Edit"); ?></a></div></td>
<td><?php if ($val["enabled"] ) { ?>
<img src="images/check_ok.png" alt="<?php __("Enabled"); ?>" />
<?php } else { ?>
<img src="images/check_no.png" alt="<?php __("Disabled"); ?>" />
<?php } // if enabled ?>
</td>
<td align=right><?php echo $val["address"]."@".$domain ?></td>
<td><div class="ina"><a href="mail_properties.php?mail_id=<?php echo $val["id"] ?>"><img src="images/edit.png" alt="<?php __("Edit"); ?>" /><?php __("Edit"); ?></a></div></td>
<?php } else { ?>
<td colspan="3"></td>
<?php } ?>
<td style="text-align:right"><?php echo $val["address"]."@".$domain ?></td>
<?php if ($val["type"]) { ?>
<td colspan="2"><?php echo $val["typedata"]; ?></td>
<?php } else { ?>
<td><?php if ($val["islocal"]) echo format_size($val["used"])."/".format_size($val["quota"]); else __("No"); ?></td>
<td><?php echo $val["recipients"]; /* TODO : if >60chars, use "..." + js close/open */ ?></td>
<?php } ?>
<td><?php if ($val["islocal"]) {
if (date("Y-m-d")==substr($val["lastlogin"],0,10)) echo substr($val["lastlogin"],11,5); else if (substr($val["lastlogin"],0,10)=="0000-00-00") __("Never"); else echo format_date(_('%3$d-%2$d-%1$d'),$val["lastlogin"]);
} ?></td>
</tr>
<?php
$i++;
}
} // end if no mail for this domain
?>
</table>
<p><input type="submit" class="inb" name="submit" value="<?php __("Delete the checked email addresses"); ?>" /></p>
</form>
<?php include_once("foot.php"); ?>
......@@ -154,6 +154,14 @@ hr {
padding: 2px;
color: black;
}
.intleft {
border-right: 0px;
padding-right: 0px;
}
.intright {
border-left: 0px;
padding-left: 0px;
}
.lst1 {
background-color: #F1F8FD;
......@@ -329,6 +337,16 @@ img {
margin-right: auto;
}
table.searchtable {
width: 700px;
border: 1px dotted #99f;
margin: 20px 0 20px 0px;
}
table.searchtable td {
padding: 5px;
}
/* Others */
.center {
text-align: center;
......
<?php
/*
$Id: functions.php,v 1.9 2005/12/18 09:50:59 benjamin Exp $
----------------------------------------------------------------------
AlternC - Web Hosting System
Copyright (C) 2002 by the AlternC Development Team.
http://alternc.org/
----------------------------------------------------------------------
Based on:
Valentin Lacambre's web hosting softwares: http://altern.org/
Copyright (C) 2000-2012 by the AlternC Development Team.
https://alternc.org/
----------------------------------------------------------------------
LICENSE
......@@ -23,7 +19,6 @@
To read the license please visit http://www.gnu.org/copyleft/gpl.html
----------------------------------------------------------------------
Original Author of file: Benjamin Sonntag, Franck Missoum
Purpose of file: Miscellaneous functions globally used
----------------------------------------------------------------------
*/
......@@ -35,7 +30,7 @@ mt_srand((float) $sec + ((float) $usec * 100000));
/* Format a field value for input or textarea : */
function fl($str) { return str_replace("<","&lt;",str_replace("\"","&quot;",$str)); }
// Use of m_log
/* Used by class/m_log.php for usort */
function compare_logname($a, $b) {
return strcmp($a['name'],$b['name']);
}
......@@ -141,39 +136,20 @@ function checkipv6($ip) {
return filter_var($ip,FILTER_VALIDATE_IP, FILTER_FLAG_IPV6);
}
/* Check a login mail */
/* Check a login mail, cf http://www.bortzmeyer.org/arreter-d-interdire-des-adresses-legales.html */
/* FIXME: check who is using that function and delete it when unused */
function checkloginmail($mail) {
if (!preg_match("/^[a-zA-Z0-9_\.:\+\-]*[a-zA-Z0-9_]$/",$mail)) {
return false;
} else {
return true;
}
return true;
}
/* " */
/* Check an email address, use checkloginmail and checkfqdn */
/* Check an email address, use filter_var with emails, which works great ;) */
/* FIXME: check who is using that function and delete it when unused */
function checkmail($mail) {
// Retourne 0 si tout va bien, sinon retourne un code erreur...
// 1 s'il n'y a rien devant l'@
// 2 3 ou 4 si le domaine est incorrect.
// 5 s'il y a caractres interdits dans la partie gauche du @
// 6 si le mail contient aucun ou plus d'un @
$t=explode("@",$mail);
if (count($t)!=2) {
return 6;
}
$c=checkfqdn($t[1]);
if ($c)
return $c;
// Verification de la partie gauche :
if (!checkloginmail($t[0])) {
if ($t[0]=="") {
return 1;
} else {
return 5;
}
if (filter_var($mail,FILTER_VALIDATE_EMAIL)) {
return 0;
} else {
return 1;
}
return 0;
}
/* Check that a domain name is fqdn compliant */
......@@ -514,4 +490,94 @@ function list_properties_order($a, $b) {
} // end private function list_properties_order
/** Show a pager as
Previous page 0 1 2 ... 16 17 18 19 20 ... 35 36 37 Next page
Arguments are as follow :
$offset = the current offset from 0
$count = The number of elements shown per page
$total = The total number of elements
$url = The url to show for each page. %%offset%% will be replace by the proper offset
$before & $after are HTML code to show before and after the pager **only if the pager is to be shown**
*/
function pager($offset,$count,$total,$url,$before="",$after="") {
$offset=intval($offset);
$count=intval($count);
$total=intval($total);
if ($offset<=0) $offset="0";
if ($count<=1) $count="1";
if ($total<=0) $total="0";
if ($total<$offset) $offset=max(0,$total-$count);
if ($total<=$count) { // When there is less element than 1 complete page, just don't do anything :-D
return true;
}
echo $before;
// Shall-we show previous page link ?
if ($offset) {
$o=max($offset-$count,0);
echo "<a href=\"".str_replace("%%offset%%",$o,$url)."\" alt=\"(Ctl/Alt-p)\" title=\"(Alt-p)\" accesskey=\"p\">"._("Previous Page")."</a> ";
} else {
echo _("Previous Page")." ";
}
if ($total>(2*$count)) { // On n'affiche le pager central (0 1 2 ...) s'il y a au moins 2 pages.
echo " - ";
if (($total<($count*10)) && ($total>$count)) { // moins de 10 pages :
for($i=0;$i<$total/$count;$i++) {
$o=$i*$count;
if ($offset==$o) {
echo $i." ";
} else {
echo "<a href=\"".str_replace("%%offset%%",$o,$url)."\">$i</a> ";
}
}
} else { // Plus de 10 pages, on affiche 0 1 2 , 2 avant et 2 aprs la page courante, et les 3 dernieres
for($i=0;$i<=2;$i++) {
$o=$i*$count;
if ($offset==$o) {
echo $i." ";
} else {
echo "<a href=\"".str_replace("%%offset%%",$o,$url)."\">$i</a> ";
}
}
if ($offset>=$count && $offset<($total-2*$count)) { // On est entre les milieux ...
// On affiche 2 avant jusque 2 aprs l'offset courant mais sans dborder sur les indices affichs autour
$start=max(3,intval($offset/$count)-2);
$end=min(intval($offset/$count)+3,intval($total/$count)-3);
if ($start!=3) echo " ... ";
for($i=$start;$i<$end;$i++) {
$o=$i*$count;
if ($offset==$o) {
echo $i." ";
} else {
echo "<a href=\"".str_replace("%%offset%%",$o,$url)."\">$i</a> ";
}
}
if ($end!=intval($total/$count)-3) echo " ... ";
} else {
echo " ... ";
}
for($i=intval($total/$count)-3;$i<$total/$count;$i++) {
$o=$i*$count;
if ($offset==$o) {
echo $i." ";
} else {
echo "<a href=\"".str_replace("%%offset%%",$o,$url)."\">$i</a> ";
}
}
echo " - ";
} // More than 10 pages?
}
// Shall-we show the next page link ?
if ($offset+$count<$total) {
$o=$offset+$count;
echo "<a href=\"".str_replace("%%offset%%",$o,$url)."\" alt=\"(Ctl/Alt-s)\" title=\"(Alt-s)\" accesskey=\"s\">"._("Next Page")."</a> ";
} else {
echo _("Next Page")." ";
}
echo $after;
}
?>
<?php
/*
$Id: m_dom.php,v 1.27 2006/02/17 18:34:30 olivier Exp $
----------------------------------------------------------------------
LICENSE
......@@ -16,7 +15,6 @@
To read the license please visit http://www.gnu.org/copyleft/gpl.html
----------------------------------------------------------------------
Original Author of file: Benjamin Sonntag
Purpose of file: PHP Class that manage domain names installed on the server
----------------------------------------------------------------------
*/
......@@ -94,6 +92,7 @@ class m_dom {
function alternc_quota_names() {
return "dom";
}
/* ----------------------------------------------------------------- */
/**
* Retourne un tableau contenant les types de domaines
......@@ -185,6 +184,7 @@ class m_dom {
function domains_type_update($name, $description, $target, $entry, $compatibility, $enable, $only_dns, $need_dns,$advanced) {
global $err,$cuid,$db;
$id=intval($id);
// The name MUST contain only letter and digits, it's an identifier after all ...
if (!preg_match("#^[a-z0-9]+$#",$name)) {
$err->raise("dom", 26);
......@@ -1157,6 +1157,32 @@ class m_dom {
}
/* ----------------------------------------------------------------- */
/**
* Returns the name of a domain for the current user, from it's domain_id
* @param $dom_id integer the domain_id to search for
* @return string the domain name, or false with an error raised.
*/
function get_domain_byid($dom_id) {
global $db,$err,$cuid;
$dom_id=intval($dom_id);
$db->query("SELECT domaine FROM domaines WHERE id=$dom_id AND compte=$cuid;");
if ($db->next_record()) {
$domain=$db->f("domaine");
if (!$domain) {
$err->raise("dom",_("This domain is not installed in your account"));
return false;
} else {
return $domain;
}
} else {
$err->raise("dom",_("This domain is not installed in your account"));
return false;
}
}
/* ----------------------------------------------------------------- */
/**
* Return the list of allowed slave accounts
......
......@@ -91,8 +91,10 @@ class m_err {
*/
function errstr() {
if (is_string($this->error)) {
$str = _("err_".$this->clsid."_generic: ")._($this->error)."\n";
// new way of handling errors: message directly in the class
$str = $this->error."\n";
} else {
// old way: message in the locales files (ugly)
$str = _("err_".$this->clsid."_".$this->error)."\n";
}
$args = $this->param;
......
<?php
/*
$Id: m_mail.php,v 2.00 2012/03/12 06:26:16 anarcat Exp $
----------------------------------------------------------------------
LICENSE
......@@ -16,7 +15,6 @@
To read the license please visit http://www.gnu.org/copyleft/gpl.html
----------------------------------------------------------------------
Original Author of file: Benjamin Sonntag, Franck Missoum
Purpose of file: Manage Email accounts and aliases.
----------------------------------------------------------------------
*/
......@@ -25,224 +23,249 @@
* This class handle emails (pop and/or aliases and even wrapper for internal
* classes) of hosted users.
*
* Copyleft {@link http://alternc.net/ AlternC Team}
*
* @copyright AlternC-Team 2002-11-01 http://alternc.net/
*
* @copyright AlternC-Team 2012-09-01 http://alternc.com/
* This class is directly using the following alternc MySQL tables:
* address = any used email address will be defined here, mailbox = pop/imap mailboxes, recipient = redirection from an email to another
* and indirectly the domain class, to know domain names from their id in the DB.
* This class is also defining a few hooks, search ->invoke in the code.
*/
class m_mail {
/** domain list
/* ----------------------------------------------------------------- */
/** domain list for this account
* @access private
*/
var $domains;
/* ----------------------------------------------------------------- */
/**
* Constructor
/** Number of results for a pager display
* @access public
*/
function m_mail() {
}
var $total;
/* ----------------------------------------------------------------- */
/**
* Quota list (hook for quota class)
/** Quota list (hook for quota class)
*/
function alternc_quota_names() {
return "mail";
}
/* ----------------------------------------------------------------- */
/** get_quota (hook for quota class), returns the number of used
* service for a quota-bound service
* @param $name string the named quota we want
* @return the number of used service for the specified quota,
* or false if I'm not the one for the named quota
*/
function alternc_get_quota($name) {
global $db,$err,$cuid;
if ($name=="mail") {
$err->log("mail","getquota");
//$db->query("SELECT COUNT(*) AS cnt FROM address WHERE domain_id in(select id from domaines where compte=$cuid);");
$db->query("SELECT COUNT(a.id) AS cnt FROM address a, domaines d WHERE a.domain_id =d.id and d.compte=$cuid group by a.id;");
$db->query("SELECT COUNT(*) AS cnt FROM address WHERE domain_id in (select id from domaines where compte=$cuid);");
$db->next_record();
return $db->f("cnt");
}
return false;
}
/**
* Password kind used in this class (hook for admin class)
/* ----------------------------------------------------------------- */
/** Password policy kind used in this class (hook for admin class)
* @return array an array of policykey => "policy name (for humans)"
*/
function alternc_password_policy() {
return array("pop"=>"POP/IMAP account passwords");
return array("pop"=>_("Email account password"));
}
/* ----------------------------------------------------------------- */
/** Returns the list of mail-hosted domains for a user
/** Returns the list of mail-hosting domains for a user
* @return array indexed array of hosted domains
*/
function enum_domains() {
global $db,$err,$cuid;
$err->log("mail","enum_domains");
$db->query("select d.id, d.domaine, count(a.id) as nb_mail FROM domaines d left join address a on a.domain_id=d.id where d.compte = $cuid group by d.id order by d.domaine asc;");
$this->enum_domains=array();
while($db->next_record()){
$this->enum_domains[]=$db->Record;
}
//print_r("<pre>");print_r($this->enum_domains);die();
return $this->enum_domains;
}
/* ----------------------------------------------------------------- */
/* function used to list every mail address hosted on a domain.
* @param : the technical domain id.
* @result : an array of each mail hosted under the domain.
* @param $dom_id integer the domain id.
* @param $search string search that string in recipients or address.
* @param $offset integer skip THAT much emails in the result.
* @param $count integer return no more than THAT much emails.
* @result an array of each mail hosted under the domain.
*/
function enum_domain_mails($dom_id = null){
global $db,$err,$cuid;
function enum_domain_mails($dom_id = null, $search="", $offset=0, $count=30){
global $db,$err,$cuid,$hooks;
$err->log("mail","enum_domains_mail");
$db->query("select * from address where domain_id=$dom_id order by address asc;");
if (!$db->num_rows()) {
$search=trim($search);
$where="a.domain_id=$dom_id";
if ($search)