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,6 +29,12 @@
*/
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"');
@ -36,7 +42,11 @@ if (!isset($_SERVER['PHP_AUTH_USER'])) {
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');

View File

@ -785,13 +785,28 @@ ORDER BY
/* ----------------------------------------------------------------- */
/** Out (echo) the complete hosted domain list :
*/
function echo_domain_list() {
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()) {
echo $db->f("domaine")."\n";
$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
}