From 5a3559a1fa7200a9d3bba68cd4f7c0c9eefe52a4 Mon Sep 17 00:00:00 2001 From: Alan Garcia Date: Tue, 23 Apr 2013 12:58:59 +0000 Subject: [PATCH] =?UTF-8?q?Mxlist=20peut=20donner=20la=20liste=20en=20form?= =?UTF-8?q?at=20json=20avec=20un=20check=20d'integrit=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bureau/admin/mxlist.php | 28 +++++++++++++++++++--------- bureau/class/m_mail.php | 29 ++++++++++++++++++++++------- 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/bureau/admin/mxlist.php b/bureau/admin/mxlist.php index cc8372d3..e9ea0f31 100644 --- a/bureau/admin/mxlist.php +++ b/bureau/admin/mxlist.php @@ -29,19 +29,29 @@ */ require_once("../class/config_nochk.php"); +$fields = array ( + "json" => array ("get", "boolean", "0"), +); +getFields($fields); + + // Check for the http authentication if (!isset($_SERVER['PHP_AUTH_USER'])) { header('WWW-Authenticate: Basic realm="MX List Authentication"'); header('HTTP/1.0 401 Unauthorized'); exit; - } else { - if ($mail->check_slave_account($_SERVER['PHP_AUTH_USER'],$_SERVER['PHP_AUTH_PW'])) { - $mail->echo_domain_list(); - } else { - header('WWW-Authenticate: Basic realm="MX List Authentication"'); - header('HTTP/1.0 401 Unauthorized'); - exit; - } +} else { + if ($mail->check_slave_account($_SERVER['PHP_AUTH_USER'],$_SERVER['PHP_AUTH_PW'])) { + if (!$json) { + $mail->echo_domain_list(); + } else { + print_r($mail->echo_domain_list("json")); + } + } else { + header('WWW-Authenticate: Basic realm="MX List Authentication"'); + header('HTTP/1.0 401 Unauthorized'); + exit; } +} -?> \ No newline at end of file +?> diff --git a/bureau/class/m_mail.php b/bureau/class/m_mail.php index d30ed640..26df0241 100644 --- a/bureau/class/m_mail.php +++ b/bureau/class/m_mail.php @@ -785,13 +785,28 @@ ORDER BY /* ----------------------------------------------------------------- */ /** Out (echo) the complete hosted domain list : */ - function echo_domain_list() { - global $db,$err; - $db->query("SELECT domaine FROM domaines WHERE gesmx=1 ORDER BY domaine"); - while ($db->next_record()) { - echo $db->f("domaine")."\n"; - } - return true; + function echo_domain_list($format=null) { + global $db,$err; + $db->query("SELECT domaine FROM domaines WHERE gesmx=1 ORDER BY domaine"); + $lst=array(); + $tt=""; + while ($db->next_record()) { + $lst[]=$db->f("domaine"); + $tt.=$db->f("domaine"); + } + + # Generate an integrity check + $obj=array('integrity'=>md5($tt),'items'=>$lst); + + switch($format) { + case "json": + return json_encode($obj); + break; + default: + foreach ($lst as $l) { echo $l."\n"; } + return true; + break; + } // switch }