Mxlist peut donner la liste en format json avec un check d'integrité

This commit is contained in:
Alan Garcia 2013-04-23 12:58:59 +00:00
parent db5395c769
commit 5a3559a1fa
2 changed files with 41 additions and 16 deletions

View File

@ -29,19 +29,29 @@
*/ */
require_once("../class/config_nochk.php"); require_once("../class/config_nochk.php");
$fields = array (
"json" => array ("get", "boolean", "0"),
);
getFields($fields);
// Check for the http authentication // Check for the http authentication
if (!isset($_SERVER['PHP_AUTH_USER'])) { if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="MX List Authentication"'); header('WWW-Authenticate: Basic realm="MX List Authentication"');
header('HTTP/1.0 401 Unauthorized'); header('HTTP/1.0 401 Unauthorized');
exit; exit;
} else { } else {
if ($mail->check_slave_account($_SERVER['PHP_AUTH_USER'],$_SERVER['PHP_AUTH_PW'])) { if ($mail->check_slave_account($_SERVER['PHP_AUTH_USER'],$_SERVER['PHP_AUTH_PW'])) {
$mail->echo_domain_list(); if (!$json) {
} else { $mail->echo_domain_list();
header('WWW-Authenticate: Basic realm="MX List Authentication"'); } else {
header('HTTP/1.0 401 Unauthorized'); print_r($mail->echo_domain_list("json"));
exit; }
} } else {
header('WWW-Authenticate: Basic realm="MX List Authentication"');
header('HTTP/1.0 401 Unauthorized');
exit;
} }
}
?> ?>

View File

@ -785,13 +785,28 @@ ORDER BY
/* ----------------------------------------------------------------- */ /* ----------------------------------------------------------------- */
/** Out (echo) the complete hosted domain list : /** Out (echo) the complete hosted domain list :
*/ */
function echo_domain_list() { function echo_domain_list($format=null) {
global $db,$err; global $db,$err;
$db->query("SELECT domaine FROM domaines WHERE gesmx=1 ORDER BY domaine"); $db->query("SELECT domaine FROM domaines WHERE gesmx=1 ORDER BY domaine");
while ($db->next_record()) { $lst=array();
echo $db->f("domaine")."\n"; $tt="";
} while ($db->next_record()) {
return true; $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
} }