"Fossies" - the Fresh Open Source Software Archive

Member "openmailadmin-1.0.1/samples/oma_mail.daimon.php" (31 May 2007, 2772 Bytes) of package /linux/privat/old/openmailadmin-1.0.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/bin/env php
    2 <?php
    3 /* *********************** change these according to your environment ******* */
    4 $MTA['virtual'] = '/etc/postfix/db/virtual';
    5 $MTA['regexp']  = '/etc/postfix/db/virtual.regex';
    6 $MTA['domains'] = '/etc/postfix/db/domains';
    7 $POSTPROCESS    = '/usr/sbin/postmap %s';
    8 // Set this to null if you don't use pam_pwdfile for caching.
    9 $PASSWD_CACHE   = '/var/lib/pam_mysql.cache';
   10 
   11 $DB = array(
   12     'DSN'       => 'mysqli://User:Passwd@localhost/DB',
   13     'PREFIX'    => '',
   14 );
   15 
   16 /* *********************** functions **************************************** */
   17 /* *********************** don't edit anything below +++++++++++++++++******* */
   18 function make_hashfile_of_query($file, $query, $delimiter = "\t\t", $postprocess = true) {
   19     global $POSTPROCESS, $db;
   20 
   21     if($fp = fopen($file, 'w')) {
   22         $result = $db->Execute($query);
   23         while(!$result->EOF) {
   24             fputs($fp, $result->fields[0].$delimiter.$result->fields[1]."\n");
   25             $result->MoveNext();
   26         }
   27         fclose($fp);
   28 
   29         if($postprocess) {
   30             exec(sprintf($POSTPROCESS, $file));
   31         }
   32     }
   33 }
   34 
   35 /* *********************** logic ******************************************** */
   36 include('adodb/adodb.inc.php');
   37 $db = ADONewConnection($DB['DSN']);
   38 $db->SetFetchMode(ADODB_FETCH_NUM);
   39 
   40 // virtual
   41 $amount_new = $db->GetOne('SELECT COUNT(*) FROM '.$DB['PREFIX'].'virtual WHERE neu=1');
   42 if(!is_file($MTA['virtual']) || $amount_new > 0 || time()%6<1) {
   43     make_hashfile_of_query($MTA['virtual'], 'SELECT address,dest FROM '.$DB['PREFIX'].'virtual WHERE active=1 ORDER BY address DESC');
   44     $db->Execute('UPDATE '.$DB['PREFIX'].'virtual SET neu=0 WHERE neu=1');
   45 }
   46 
   47 // virtual.regexp
   48 $amount_new = $db->GetOne('SELECT COUNT(*) FROM '.$DB['PREFIX'].'virtual_regexp WHERE neu=1');
   49 if(!is_file($MTA['regexp']) || $amount_new > 0 || time()%6<1) {
   50     make_hashfile_of_query($MTA['regexp'], 'SELECT reg_exp,dest FROM '.$DB['PREFIX'].'virtual_regexp WHERE active=1 ORDER BY LENGTH(reg_exp) DESC', "\t\t", false);
   51     $db->Execute('UPDATE '.$DB['PREFIX'].'virtual_regexp SET neu=0 WHERE neu=1');
   52 }
   53 
   54 // domains
   55 $amount_new = $db->GetOne('SELECT COUNT(*) FROM '.$DB['PREFIX'].'domains WHERE neu=1');
   56 if(!is_file($MTA['domains']) || $amount_new > 0 || time()%96<1) {
   57     make_hashfile_of_query($MTA['domains'], 'SELECT domain,domain FROM '.$DB['PREFIX'].'domains');
   58     $db->Execute('UPDATE '.$DB['PREFIX'].'domains SET neu=0 WHERE neu=1');
   59 }
   60 
   61 // for pam_pwdfile
   62 if(!is_null($PASSWD_CACHE) && (!is_file($PASSWD_CACHE) || time()%24<1)) {
   63     make_hashfile_of_query($PASSWD_CACHE, 'SELECT mbox, password FROM '.$DB['PREFIX'].'user', ':', false);
   64 }
   65 
   66 // optimize DB
   67 if(time()%50 < 2 && ($DB['TYPE'] == 'mysql' || $DB['TYPE'] == 'mysqli')) {
   68     $db->Execute('OPTIMIZE TABLE '.$DB['PREFIX'].'virtual, '.$DB['PREFIX'].'virtual_regexp, '.$DB['PREFIX'].'user, '.$DB['PREFIX'].'domains');
   69 }
   70 ?>