Restrictive plugin

Discussion in 'Developers' Forum' started by gody, Feb 1, 2021.

  1. gody

    gody Member

    Hello guys,

    I'm trying to create a plugin that prevent remove of a specific domain no matter what happen

    Basically the plugin lookks like that :

    PHP:
    class admin_restriction_plugin {

         var 
    $plugin_name 'admin_restriction_plugin';
         var 
    $class_name 'admin_restriction_plugin';
        
         function 
    onLoad() {
             global 
    $app;

             
    $app->plugin->registerEvent('mail:mail_domain:on_before_delete''admin_restriction_plugin''before_mail_domain_delete');
             
    $app->plugin->registerEvent('dns:dns_soa:on_before_delete''admin_restriction_plugin''before_dns_soa_delete');
         }
        
        function 
    before_mail_domain_delete($event_name$page_form){
            global 
    $app$conf;   
            
            if(
    in_array($page_form->dataRecord['domain'], $conf['domain_deletion_restriction'])  )
            {
                
    $app->error('Opération non permise / Operation not allowed'''true1);
            }   
        }
        

        function 
    before_dns_soa_delete($event_name$page_form){
            global 
    $app$conf;   
            
            
    $origin rtrim($page_form->dataRecord['origin'], ".") ; // trailling dot not needed
            
            
    if(in_array($origin$conf['domain_deletion_restriction'])  )
            {
                
    $app->error('Opération non permise / Operation not allowed'''true1);
            }   
            
            
    // Records inside the zone are deleted ... not good
        
    }
        
    }
    Problems:
    1. Records inside a DNS zone are deleted but not the zone itself...
      • We need to preserved the records inside the zone AND the zone
    2. The same happens for a mail domain.
      • We need to preserve mailbox, alias, forward ...
    Is it possible ?
    Any idea how can I do that ?

    Regards,
    Cédric
     

Share This Page