Commit 2907b5ea authored by Cédric's avatar Cédric

Add php file update

parent bc9f02cb
<?php
/**
* mail_domain_barracuda_plugin
* mail_domain_barracuda_plugin plugin
*
* @author Gody - ORM 2016
* @author: LEVEILLE Cédric (web@oricom.org) - Oricom Internet Inc.
*/
class mail_domain_barracuda_plugin {
var $plugin_name = 'mail_domain_barracuda_plugin';
var $class_name = 'mail_domain_barracuda_plugin';
/*
This function is called when the plugin is loaded
*/
function onLoad() {
global $app;
......@@ -24,22 +22,27 @@ class mail_domain_barracuda_plugin {
$app->plugin->registerEvent('mail:mail_domain:on_after_insert', 'mail_domain_barracuda_plugin', 'mail_domain_barracuda_edit');
$app->plugin->registerEvent('mail:mail_domain:on_after_update', 'mail_domain_barracuda_plugin', 'mail_domain_barracuda_edit');
$app->plugin->registerEvent('mail:mail_domain:on_after_delete', 'mail_domain_barracuda_plugin', 'mail_domain_barracuda_del');
$app->plugin->registerEvent('mail:mail_domain:on_after_delete', 'mail_domain_barracuda_plugin', 'mail_domain_barracuda_del');
$app->plugin->registerEvent('mailpub:mail_domain:on_after_insert', 'mail_domain_barracuda_plugin', 'mail_domain_barracuda_edit');
$app->plugin->registerEvent('mailpub:mail_domain:on_after_update', 'mail_domain_barracuda_plugin', 'mail_domain_barracuda_edit');
$app->plugin->registerEvent('mailpub:mail_domain:on_after_delete', 'mail_domain_barracuda_plugin', 'mail_domain_barracuda_del');
}
/*
function to create and edit domain into barracuda by api
Function to create domain name into barracuda by api
*/
private function cuda($xml_params, $cuda_methode){
global $conf;
$xml_methode = new xmlrpcmsg ($cuda_methode);
$xml_methode->addParam($xml_params);
$xml_methode ->addParam($xml_params);
$barra_con = new xmlrpc_client("/cgi-mod/api.cgi?password={$conf['bsf_password']}", $conf['bsf_hostname']);
$barra_con->setDebug(0);
$result = $barra_con->send($xml_methode);
$result = $barra_con ->send($xml_methode);
if (!$result->faultcode())
{
......@@ -54,53 +57,68 @@ class mail_domain_barracuda_plugin {
return $resultat;
}
/*
Function to edit domain name into barracuda by api
*/
function mail_domain_barracuda_edit($event_name, $page_form){
global $app, $conf;
// Récupération des variables
$domain = $page_form->dataRecord["domain"] ;
$chk_active = $page_form->dataRecord["active"] ;
$server_name = $app->db->queryOneRecord("SELECT server_name FROM server WHERE server_id = ".$page_form->dataRecord["server_id"]);
$server_name = $server_name['server_name'];
// Ajout si checkbox non coché sinon suppression
if ( $chk_active == 'y' ) {
// Génération des xmls
$xml_params_add = new xmlrpcval (array (
"domain" => new xmlrpcval($domain, "string")
// If domain is in the excluded list, do nothing
if(!in_array($domain, $conf['bsf_excluded']))
{
$chk_active = $page_form->dataRecord["active"] ;
$server_name = $app->db->queryOneRecord("SELECT server_name FROM server WHERE server_id = ".$page_form->dataRecord["server_id"]);
$server_name = $server_name['server_name'];
// Verify if domain is enable in ISPConfig
if ( $chk_active == 'y' ) {
// Generate XML
$xml_params_add = new xmlrpcval (array (
"domain" => new xmlrpcval($domain, "string")
), "struct");
$xml_params_set = new xmlrpcval (array (
"mta_relay_advanced_use_mx" => new xmlrpcval(0, "boolean"),
"mta_relay_advanced_host" => new xmlrpcval($server_name, "string"),
"path" => new xmlrpcval($domain, "string"),
"type" => new xmlrpcval("domain", "string"),
), "struct");
$xml_params_set = new xmlrpcval (array (
"mta_relay_advanced_use_mx" => new xmlrpcval(1, "boolean"),
"mta_relay_advanced_host" => new xmlrpcval($server_name, "string"),
"path" => new xmlrpcval($domain, "string"),
"type" => new xmlrpcval("domain", "string"),
), "struct");
// TODO ajout gestion erreur en cas de plantage coté barracuda
$add=$this->cuda($xml_params_add, 'domain.add');
$set=$this->cuda($xml_params_set, 'config.set');
}
else {
$this->mail_domain_barracuda_del($event_name, $page_form) ;
$add=$this->cuda($xml_params_add, 'domain.add'); // Add domain name to the barracuda
$set=$this->cuda($xml_params_set, 'config.set'); // Update domain name destination inside barracuda
// TODO : Log in case of error (WIP)
}
else {
$this->mail_domain_barracuda_del($event_name, $page_form) ;
}
}
}
/*
Function to remove domain name from the barracuda by api
*/
function mail_domain_barracuda_del($event_name, $page_form){
global $app, $conf;
// Récupération des variables
$domain = $page_form->dataRecord["domain"] ;
// Génération xmls
$xml_params_del = new xmlrpcval (array (
"domain" => new xmlrpcval($domain, "string")
), "struct");
// Suppresion domaine du barracuda
// TODO ajout gestion erreur en cas de plantage coté barracuda
$del=$this->cuda($xml_params_del, 'domain.delete');
// If domain is in the excluded list, do nothing
if(!in_array($domain, $conf['bsf_excluded']))
{
// Generate XML
$xml_params_del = new xmlrpcval (array (
"domain" => new xmlrpcval($domain, "string")
), "struct");
// Remove domain name from the barracuda
$del=$this->cuda($xml_params_del, 'domain.delete');
// TODO : Log in case of error (WIP)
}
}
} // end class
......@@ -108,8 +126,6 @@ class mail_domain_barracuda_plugin {
//################# XMLRPC fonction and Class #######################
// by Edd Dumbill (C) 1999-2002
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment