function myHandler($signal)
{
    if ($signal === SIGTERM) {
        System_Daemon::warning('I received the termination signal. ' . $sig);
        // Execute some final code
        // and be sure to:
        System_Daemon::stop();
    }
}
 function oneLoop($pause = True)
 {
     if (file_exists($this->command_file())) {
         $text = file_get_contents($this->command_file());
         $command_lines = split("\n", $text);
         $command = $command_lines[0];
         if ($command == "stop") {
             return False;
         }
     }
     $delay = $pause ? 1 : 0;
     System_Daemon::iterate($delay);
     return True;
 }
Example #3
0
 public function init()
 {
     if (!$this->appName) {
         throw new CException('Invalid application name for daemon.');
     }
     if ($this->logFile == '') {
         $this->logFile = implode(DIRECTORY_SEPARATOR, array(Yii::getPathOfAlias('application'), 'runtime', self::LOG_FILE_NAME));
     }
     if (!file_exists($this->logFile)) {
         if (!touch($this->logFile)) {
             throw new CException('Invalid log file ' . $this->logFile);
         }
     }
     Yii::registerAutoloader(array('System_Daemon', 'autoload'));
     System_Daemon::setOptions(array('appName' => $this->appName, 'appDir' => Yii::getPathOfAlias('application'), 'sysMaxExecutionTime' => $this->sysMaxExecutionTime, 'sysMaxInputTime' => $this->sysMaxInputTime, 'sysMemoryLimit' => $this->sysMemoryLimit, 'appRunAsGID' => $this->runAsGID, 'appRunAsUID' => $this->runAsUID, 'logLocation' => $this->logFile));
 }
Example #4
0
 public static function SaveRCConfig()
 {
     System_Daemon::debug('Starting "DaemonConfigTools::SaveRCConfig" subprocess.');
     $xml = simplexml_load_file(DaemonConfig::$cfg->{'CONF_DIR'} . '/EasySCP_Config_RC.xml');
     // Backup current Roundcube conf if exists
     if (file_exists(DaemonConfig::$cfg->{'GUI_ROOT_DIR'} . '/tools/webmail/config/config.inc.php')) {
         exec(DaemonConfig::$cmd->{'CMD_CP'} . ' -pf ' . DaemonConfig::$cfg->{'GUI_ROOT_DIR'} . '/tools/webmail/config/config.inc.php ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/roundcube/backup/config.inc.php' . '_' . date("Y_m_d_H_i_s"), $result, $error);
     }
     $tpl_param = array('CUBE_USER' => $xml->{'CUBE_USER'}, 'CUBE_PASS' => DB::decrypt_data($xml->{'CUBE_PASS'}), 'HOSTNAME' => $xml->{'DATABASE_HOST'});
     $tpl = DaemonCommon::getTemplate($tpl_param);
     $config = $tpl->fetch('roundcube/parts/config.inc.tpl');
     $confFile = DaemonConfig::$cfg->{'CONF_DIR'} . '/roundcube/working/config.inc.php';
     $tpl = NULL;
     unset($tpl);
     if (!DaemonCommon::systemWriteContentToFile($confFile, $config, DaemonConfig::$cfg->{'ROOT_USER'}, DaemonConfig::$cfg->{'ROOT_GROUP'}, 0640)) {
         System_Daemon::debug('Error: Failed to write ' . $confFile);
         return;
     }
     System_Daemon::debug('Storing the roundcube config files in the working directory');
     exec(DaemonConfig::$cmd->{'CMD_CP'} . ' -pf ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/roundcube/working/config.inc.php ' . DaemonConfig::$cfg->{'GUI_ROOT_DIR'} . '/tools/webmail/config', $result, $error);
     DaemonCommon::systemSetFilePermissions(DaemonConfig::$cfg->{'GUI_ROOT_DIR'} . '/tools/webmail/config/config.inc.php', DaemonConfig::$cfg->{'APACHE_SUEXEC_USER_PREF'} . DaemonConfig::$cfg->{'APACHE_SUEXEC_MIN_UID'}, DaemonConfig::$cfg->{'APACHE_SUEXEC_USER_PREF'} . DaemonConfig::$cfg->{'APACHE_SUEXEC_MIN_GID'}, 0644);
     System_Daemon::debug('Finished "DaemonConfigTools::SaveRCConfig" subprocess.');
 }
Example #5
0
 public function execute()
 {
     ob_start();
     if ($this->runmodes['help'] == true) {
         echo 'Usage: ' . $argv[0] . ' [runmodes]' . "\n";
         echo 'Available runmodes:' . "\n";
         foreach ($this->runmodes as $runmode) {
             echo ' --' . $runmode . "\n";
         }
         die;
     }
     System_Daemon::setOptions($this->options);
     if (!$this->runmodes['no-daemon']) {
         System_Daemon::start();
     }
     if (!$this->runmodes['write-initd']) {
         System_Daemon::info('not writing an init.d script this time');
     } else {
         if (($initd_location = System_Daemon::writeAutoRun()) === false) {
             System_Daemon::notice('unable to write init.d script');
         } else {
             System_Daemon::info('sucessfully written startup script: %s', $initd_location);
         }
     }
     $this->application->dataLink->disconnect();
     $this->application->dataLink->connect();
     while (!System_Daemon::isDying() && $this->status == self::RUN) {
         $this->process();
         System_Daemon::iterate($this->ownOptions['sleep']);
         $output = ob_get_contents();
         if ($output != '') {
             System_Daemon::info($output);
         }
         ob_clean();
     }
 }
Example #6
0
 /**
  * @return mixed
  */
 public static function SaveMTAConfig()
 {
     System_Daemon::debug('Starting "DaemonConfigMail::SaveMTAConfig" subprocess.');
     /**
      * Postfix main.cf
      */
     // Backup current main.cf if exists
     if (file_exists(DaemonConfig::$distro->{'POSTFIX_CONF_FILE'})) {
         exec(DaemonConfig::$cmd->{'CMD_CP'} . ' -pf ' . DaemonConfig::$distro->{'POSTFIX_CONF_FILE'} . ' ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/postfix/backup/main.cf' . '_' . date("Y_m_d_H_i_s"), $result, $error);
     }
     // Loading the template from /etc/easyscp/postfix/, Building the file
     $tpl_param = array('MTA_HOSTNAME' => idn_to_ascii(DaemonConfig::$cfg->{'SERVER_HOSTNAME'}), 'MTA_LOCAL_DOMAIN' => idn_to_ascii(DaemonConfig::$cfg->{'SERVER_HOSTNAME'}) . '.local', 'MTA_VERSION' => DaemonConfig::$cfg->{'Version'}, 'MTA_TRANSPORT' => DaemonConfig::$distro->{'MTA_TRANSPORT'}, 'MTA_LOCAL_MAIL_DIR' => DaemonConfig::$distro->{'MTA_LOCAL_MAIL_DIR'}, 'MTA_LOCAL_ALIAS_HASH' => DaemonConfig::$distro->{'MTA_LOCAL_ALIAS_HASH'}, 'MTA_VIRTUAL_MAIL_DIR' => DaemonConfig::$distro->{'MTA_VIRTUAL_MAIL_DIR'}, 'MTA_VIRTUAL_DMN' => DaemonConfig::$distro->{'MTA_VIRTUAL_DMN'}, 'MTA_VIRTUAL_MAILBOX' => DaemonConfig::$distro->{'MTA_VIRTUAL_MAILBOX'}, 'MTA_VIRTUAL_ALIAS' => DaemonConfig::$distro->{'MTA_VIRTUAL_ALIAS'}, 'MTA_MAILBOX_MIN_UID' => DaemonConfig::$cfg->{'MTA_MAILBOX_MIN_UID'}, 'MTA_MAILBOX_UID' => DaemonConfig::$cfg->{'MTA_MAILBOX_UID'}, 'MTA_MAILBOX_GID' => DaemonConfig::$cfg->{'MTA_MAILBOX_GID'}, 'PORT_POSTGREY' => DaemonConfig::$cfg->{'PORT_POSTGREY'}, 'MTA_SSL' => DaemonConfig::$cfg->{'MTA_SSL_STATUS'} == '1' ? true : false);
     $tpl = DaemonCommon::getTemplate($tpl_param);
     $config = $tpl->fetch('postfix/parts/' . DaemonConfig::$cfg->{'DistName'} . '_' . DaemonConfig::$cfg->{'DistVersion'} . '/main.cf');
     $confFile = DaemonConfig::$cfg->{'CONF_DIR'} . '/postfix/working/main.cf';
     $tpl = NULL;
     unset($tpl);
     // Storing the new file in working directory
     if (!DaemonCommon::systemWriteContentToFile($confFile, $config, DaemonConfig::$cfg->{'ROOT_USER'}, DaemonConfig::$cfg->{'ROOT_GROUP'}, 0644)) {
         return 'Error: Failed to write ' . $confFile;
     }
     // Installing the new file in production directory
     exec(DaemonConfig::$cmd->{'CMD_CP'} . ' -pf ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/postfix/working/main.cf ' . DaemonConfig::$distro->{'POSTFIX_CONF_FILE'}, $result, $error);
     /**
      * Postfix master.cf
      */
     // Backup current master.cf if exists
     if (file_exists(DaemonConfig::$distro->{'POSTFIX_MASTER_CONF_FILE'})) {
         exec(DaemonConfig::$cmd->{'CMD_CP'} . ' -pf ' . DaemonConfig::$distro->{'POSTFIX_MASTER_CONF_FILE'} . ' ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/postfix/backup/master.cf' . '_' . date("Y_m_d_H_i_s"), $result, $error);
     }
     // Storing the new file in working directory
     exec(DaemonConfig::$cmd->{'CMD_CP'} . ' -pf ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/postfix/parts/' . DaemonConfig::$cfg->{'DistName'} . '_' . DaemonConfig::$cfg->{'DistVersion'} . '/master.cf ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/postfix/working/master.cf', $result, $error);
     DaemonCommon::systemSetFilePermissions(DaemonConfig::$cfg->{'CONF_DIR'} . '/postfix/working/master.cf', DaemonConfig::$cfg->{'ROOT_USER'}, DaemonConfig::$cfg->{'ROOT_GROUP'}, 0644);
     // Installing the new file in production directory
     exec(DaemonConfig::$cmd->{'CMD_CP'} . ' -pf ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/postfix/working/master.cf ' . DaemonConfig::$distro->{'POSTFIX_MASTER_CONF_FILE'}, $result, $error);
     // Loading the template from /etc/easyscp/postfix/, Building the file
     $MTA_DB_HOST = idn_to_ascii(DaemonConfig::$cfg->{'DATABASE_HOST'});
     $MTA_DB_USER = '******';
     $MTA_DB_PASS = DaemonCommon::generatePassword(9);
     $MTA_CONFIG_FILES = array('domains', 'email2email', 'forwardings', 'mailboxes', 'transports');
     $tpl_param = array('MTA_DB_USER' => $MTA_DB_USER, 'MTA_DB_PASS' => $MTA_DB_PASS);
     foreach ($MTA_CONFIG_FILES as $FILE) {
         $tpl = DaemonCommon::getTemplate($tpl_param);
         $config = $tpl->fetch('postfix/parts/mysql-virtual_' . $FILE . '.cf');
         $confFile = DaemonConfig::$cfg->{'CONF_DIR'} . '/postfix/working/mysql-virtual_' . $FILE . '.cf';
         $tpl = NULL;
         unset($tpl);
         // Storing the new file in working directory
         if (!DaemonCommon::systemWriteContentToFile($confFile, $config, DaemonConfig::$cfg->{'ROOT_USER'}, DaemonConfig::$cfg->{'ROOT_GROUP'}, 0644)) {
             return 'Error: Failed to write ' . $confFile;
         }
         // Installing the new file in production directory
         exec(DaemonConfig::$cmd->{'CMD_CP'} . ' -pf ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/postfix/working/mysql-virtual_' . $FILE . '.cf ' . DaemonConfig::$distro->{'MTA_VIRTUAL_CONF_DIR'} . '/mysql-virtual_' . $FILE . '.cf', $result, $error);
     }
     # Adding the mail_admin user
     $sql_param = array(':MTA_DB_HOST' => $MTA_DB_HOST, ':MTA_DB_USER' => $MTA_DB_USER, ':MTA_DB_PASS' => $MTA_DB_PASS);
     $sql_query = "\n\t\t\tGRANT SELECT, INSERT, UPDATE, DELETE ON mail.* TO :MTA_DB_USER@:MTA_DB_HOST IDENTIFIED BY :MTA_DB_PASS;\n\t\t\tFLUSH PRIVILEGES;\n\t\t";
     DB::prepare($sql_query);
     DB::execute($sql_param)->closeCursor();
     /**
      * Dovecot Konfiguration
      */
     $configPath = 'dovecot/parts/' . DaemonConfig::$cfg->{'DistName'} . '_' . DaemonConfig::$cfg->{'DistVersion'};
     switch (DaemonConfig::$cfg->{'DistName'} . '_' . DaemonConfig::$cfg->{'DistVersion'}) {
         default:
             /**
              * 10-auth.conf
              */
             exec(DaemonConfig::$cmd->{'CMD_CP'} . ' -pf ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/' . $configPath . '/10-auth.conf ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/dovecot/working/10-auth.conf', $result, $error);
             DaemonCommon::systemSetFilePermissions(DaemonConfig::$cfg->{'CONF_DIR'} . '/dovecot/working/10-auth.conf', DaemonConfig::$cfg->{'ROOT_USER'}, DaemonConfig::$cfg->{'ROOT_GROUP'}, 0644);
             exec(DaemonConfig::$cmd->{'CMD_CP'} . ' -pf ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/dovecot/working/10-auth.conf ' . DaemonConfig::$distro->{'DOVECOT_CONF_DIR'} . '/conf.d/10-auth.conf', $result, $error);
             /**
              * 10-logging.conf
              */
             exec(DaemonConfig::$cmd->{'CMD_CP'} . ' -f ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/' . $configPath . '/10-logging.conf ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/dovecot/working/10-logging.conf', $result, $error);
             DaemonCommon::systemSetFilePermissions(DaemonConfig::$cfg->{'CONF_DIR'} . '/dovecot/working/10-logging.conf', DaemonConfig::$cfg->{'ROOT_USER'}, DaemonConfig::$cfg->{'ROOT_GROUP'}, 0644);
             exec(DaemonConfig::$cmd->{'CMD_CP'} . ' -pf ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/dovecot/working/10-logging.conf ' . DaemonConfig::$distro->{'DOVECOT_CONF_DIR'} . '/conf.d/10-logging.conf', $result, $error);
             /**
              * 10-mail.conf
              */
             $tpl_param = array('MTA_VIRTUAL_MAIL_DIR' => DaemonConfig::$distro->{'MTA_VIRTUAL_MAIL_DIR'}, 'MTA_MAILBOX_UID' => DaemonConfig::$cfg->{'MTA_MAILBOX_UID'});
             $tpl = DaemonCommon::getTemplate($tpl_param);
             $config = $tpl->fetch($configPath . '/10-mail.conf');
             $confFile = DaemonConfig::$cfg->{'CONF_DIR'} . '/dovecot/working/10-mail.conf';
             $tpl = NULL;
             unset($tpl);
             if (!DaemonCommon::systemWriteContentToFile($confFile, $config, DaemonConfig::$cfg->{'ROOT_USER'}, DaemonConfig::$cfg->{'ROOT_GROUP'}, 0644)) {
                 return 'Error: Failed to write ' . $confFile;
             }
             exec(DaemonConfig::$cmd->{'CMD_CP'} . ' -pf ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/dovecot/working/10-mail.conf ' . DaemonConfig::$distro->{'DOVECOT_CONF_DIR'} . '/conf.d/10-mail.conf', $result, $error);
             /**
              * 10-master.conf
              */
             exec(DaemonConfig::$cmd->{'CMD_CP'} . ' -pf ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/' . $configPath . '/10-master.conf ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/dovecot/working/10-master.conf', $result, $error);
             DaemonCommon::systemSetFilePermissions(DaemonConfig::$cfg->{'CONF_DIR'} . '/dovecot/working/10-master.conf', DaemonConfig::$cfg->{'ROOT_USER'}, DaemonConfig::$cfg->{'ROOT_GROUP'}, 0644);
             exec(DaemonConfig::$cmd->{'CMD_CP'} . ' -pf ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/dovecot/working/10-master.conf ' . DaemonConfig::$distro->{'DOVECOT_CONF_DIR'} . '/conf.d/10-master.conf', $result, $error);
             /**
              * 10-ssl.conf
              */
             if (file_exists(DaemonConfig::$cfg->{'CONF_DIR'} . '/' . $configPath . '/10-ssl.conf')) {
                 exec(DaemonConfig::$cmd->{'CMD_CP'} . ' -pf ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/' . $configPath . '/10-ssl.conf ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/dovecot/working/10-ssl.conf', $result, $error);
                 DaemonCommon::systemSetFilePermissions(DaemonConfig::$cfg->{'CONF_DIR'} . '/dovecot/working/10-ssl.conf', DaemonConfig::$cfg->{'ROOT_USER'}, DaemonConfig::$cfg->{'ROOT_GROUP'}, 0644);
                 exec(DaemonConfig::$cmd->{'CMD_CP'} . ' -pf ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/dovecot/working/10-ssl.conf ' . DaemonConfig::$distro->{'DOVECOT_CONF_DIR'} . '/conf.d/10-ssl.conf', $result, $error);
             }
             /**
              * 15-lda.conf
              */
             $tpl_param = array('DEFAULT_ADMIN_ADDRESS' => DaemonConfig::$cfg->{'DEFAULT_ADMIN_ADDRESS'});
             $tpl = DaemonCommon::getTemplate($tpl_param);
             $config = $tpl->fetch($configPath . '/15-lda.conf');
             $confFile = DaemonConfig::$cfg->{'CONF_DIR'} . '/dovecot/working/15-lda.conf';
             $tpl = NULL;
             unset($tpl);
             if (!DaemonCommon::systemWriteContentToFile($confFile, $config, DaemonConfig::$cfg->{'ROOT_USER'}, DaemonConfig::$cfg->{'ROOT_GROUP'}, 0644)) {
                 return 'Error: Failed to write ' . $confFile;
             }
             exec(DaemonConfig::$cmd->{'CMD_CP'} . ' -pf ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/dovecot/working/15-lda.conf ' . DaemonConfig::$distro->{'DOVECOT_CONF_DIR'} . '/conf.d/15-lda.conf', $result, $error);
             /**
              * 20-lmtp.conf
              */
             if (file_exists(DaemonConfig::$cfg->{'CONF_DIR'} . '/' . $configPath . '/20-lmtp.conf')) {
                 exec(DaemonConfig::$cmd->{'CMD_CP'} . ' -pf ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/' . $configPath . '/20-lmtp.conf ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/dovecot/working/20-lmtp.conf', $result, $error);
                 DaemonCommon::systemSetFilePermissions(DaemonConfig::$cfg->{'CONF_DIR'} . '/dovecot/working/20-lmtp.conf', DaemonConfig::$cfg->{'ROOT_USER'}, DaemonConfig::$cfg->{'ROOT_GROUP'}, 0644);
                 exec(DaemonConfig::$cmd->{'CMD_CP'} . ' -pf ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/dovecot/working/20-lmtp.conf ' . DaemonConfig::$distro->{'DOVECOT_CONF_DIR'} . '/conf.d/20-lmtp.conf', $result, $error);
             }
             /**
              * 20-managesieve.conf
              */
             if (file_exists(DaemonConfig::$cfg->{'CONF_DIR'} . '/' . $configPath . '/20-managesieve.conf')) {
                 exec(DaemonConfig::$cmd->{'CMD_CP'} . ' -pf ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/' . $configPath . '/20-managesieve.conf ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/dovecot/working/20-managesieve.conf', $result, $error);
                 DaemonCommon::systemSetFilePermissions(DaemonConfig::$cfg->{'CONF_DIR'} . '/dovecot/working/20-managesieve.conf', DaemonConfig::$cfg->{'ROOT_USER'}, DaemonConfig::$cfg->{'ROOT_GROUP'}, 0644);
                 exec(DaemonConfig::$cmd->{'CMD_CP'} . ' -pf ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/dovecot/working/20-managesieve.conf ' . DaemonConfig::$distro->{'DOVECOT_CONF_DIR'} . '/conf.d/20-managesieve.conf', $result, $error);
             }
             /**
              * 90-sieve.conf
              */
             if (file_exists(DaemonConfig::$cfg->{'CONF_DIR'} . '/' . $configPath . '/90-sieve.conf')) {
                 $tpl_param = array('MTA_VIRTUAL_MAIL_DIR' => DaemonConfig::$distro->{'MTA_VIRTUAL_MAIL_DIR'});
                 $tpl = DaemonCommon::getTemplate($tpl_param);
                 $config = $tpl->fetch($configPath . '/90-sieve.conf');
                 $confFile = DaemonConfig::$cfg->{'CONF_DIR'} . '/dovecot/working/90-sieve.conf';
                 $tpl = NULL;
                 unset($tpl);
                 if (!DaemonCommon::systemWriteContentToFile($confFile, $config, DaemonConfig::$cfg->{'ROOT_USER'}, DaemonConfig::$cfg->{'ROOT_GROUP'}, 0644)) {
                     return 'Error: Failed to write ' . $confFile;
                 }
                 exec(DaemonConfig::$cmd->{'CMD_CP'} . ' -pf ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/dovecot/working/90-sieve.conf ' . DaemonConfig::$distro->{'DOVECOT_CONF_DIR'} . '/conf.d/90-sieve.conf', $result, $error);
             }
             /**
              * auth-sql.conf.ext
              */
             $tpl_param = array('MTA_MAILBOX_UID' => DaemonConfig::$cfg->{'MTA_MAILBOX_UID'}, 'MTA_MAILBOX_GID' => DaemonConfig::$cfg->{'MTA_MAILBOX_GID'}, 'MTA_VIRTUAL_MAIL_DIR' => DaemonConfig::$distro->{'MTA_VIRTUAL_MAIL_DIR'});
             $tpl = DaemonCommon::getTemplate($tpl_param);
             $config = $tpl->fetch($configPath . '/auth-sql.conf.ext');
             $confFile = DaemonConfig::$cfg->{'CONF_DIR'} . '/dovecot/working/auth-sql.conf.ext';
             $tpl = NULL;
             unset($tpl);
             if (!DaemonCommon::systemWriteContentToFile($confFile, $config, DaemonConfig::$cfg->{'ROOT_USER'}, DaemonConfig::$cfg->{'ROOT_GROUP'}, 0644)) {
                 return 'Error: Failed to write ' . $confFile;
             }
             exec(DaemonConfig::$cmd->{'CMD_CP'} . ' -pf ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/dovecot/working/auth-sql.conf.ext ' . DaemonConfig::$distro->{'DOVECOT_CONF_DIR'} . '/conf.d/auth-sql.conf.ext', $result, $error);
             /**
              * dovecot-sql.conf.ext
              */
             $tpl_param = array('MTA_DB_HOST' => $MTA_DB_HOST, 'MTA_DB_USER' => $MTA_DB_USER, 'MTA_DB_PASS' => $MTA_DB_PASS);
             $tpl = DaemonCommon::getTemplate($tpl_param);
             $config = $tpl->fetch($configPath . '/dovecot-sql.conf.ext');
             $confFile = DaemonConfig::$cfg->{'CONF_DIR'} . '/dovecot/working/dovecot-sql.conf.ext';
             $tpl = NULL;
             unset($tpl);
             // Storing the new file in working directory
             if (!DaemonCommon::systemWriteContentToFile($confFile, $config, DaemonConfig::$cfg->{'ROOT_USER'}, DaemonConfig::$cfg->{'ROOT_GROUP'}, 0644)) {
                 return 'Error: Failed to write ' . $confFile;
             }
             // Installing the new file in production directory
             exec(DaemonConfig::$cmd->{'CMD_CP'} . ' -pf ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/dovecot/working/dovecot-sql.conf.ext ' . DaemonConfig::$distro->{'DOVECOT_CONF_DIR'} . '/dovecot-sql.conf.ext', $result, $error);
     }
     unset($configPath);
     // Sonstige Anpassungen
     switch (DaemonConfig::$cfg->{'DistName'}) {
         case 'CentOS':
             // Wird auf CentOS benötigt da ansonsten bei unzustellbaren Mails der Fehler
             // "status=bounced (can't create user output file. Command output: procmail: Couldn't create "/var/spool/mail/nobody" )" im log erscheint.
             // "procmail" hat hier wohl nicht die richtigen Rechte.
             if (file_exists('/usr/bin/procmail')) {
                 exec("chmod g+s /usr/bin/procmail", $result, $error);
             }
             break;
         default:
     }
     System_Daemon::debug('Finished "DaemonConfigMail::SaveMTAConfig" subprocess.');
     return true;
 }
Example #7
0
function Setup_Finishing()
{
    //exec(DaemonConfig::$cmd->{'SRV_HTTPD'} . ' restart');
    $ControlConnect = DaemonCommon::ControlConnect('ApacheRestart');
    if ($ControlConnect !== true) {
        return $ControlConnect . ' System is unable to reload Apache config.<br />';
    }
    System_Daemon::info('Restart Daemon.');
    $ControlConnect = DaemonCommon::ControlConnect('DaemonRestart');
    if ($ControlConnect !== true) {
        return $ControlConnect . ' System is unable to restart EasySCP Daemon.<br />';
    }
    unlink(DaemonConfig::$cfg->{'ROOT_DIR'} . '/daemon/DaemonCoreSetup.php');
    exec(DaemonConfig::$cmd->{'CMD_RM'} . ' -rf ' . DaemonConfig::$cfg->{'ROOT_DIR'} . '/../setup >> /dev/null 2>&1');
    // SocketHandler::Close();
    // System_Daemon::restart();
}
Example #8
0
 /**
  *
  * @param string $fileName
  * @param mixed $content
  * @param mixed $user
  * @param mixed $group
  * @param mixed $perm
  * @param bool $append
  * @return boolean
  */
 public static function systemWriteContentToFile($fileName, $content, $user, $group, $perm, $append = false)
 {
     $flags = $append == true ? FILE_APPEND : 0;
     if (file_put_contents($fileName, $content, $flags)) {
         return DaemonCommon::systemSetFilePermissions($fileName, $user, $group, $perm);
     } else {
         System_Daemon::warning("Failed to write content to {$fileName}");
         return false;
     }
 }
Example #9
0
 /**
  * Sets up Option Object instance
  *
  * @return boolean
  */
 protected static function _optionObjSetup()
 {
     // Create Option Object if nescessary
     if (!self::$_optObj) {
         self::$_optObj = new System_Daemon_Options(self::$_optionDefinitions);
     }
     // Still false? This was an error!
     if (!self::$_optObj) {
         return self::emerg('Unable to setup Options object. ');
     }
     return true;
 }
$appname = "ykval-queue";
System_Daemon::setOption("appName", $appname);
System_Daemon::setOption("appDescription", "Yubico val-server sync daemon");
System_Daemon::setOption("authorName", "*****@*****.**");
System_Daemon::setOption("authorEmail", "*****@*****.**");
if ($argc == 2 && strcmp($argv[1], "install") == 0) {
    $autostart_path = System_Daemon::writeAutoRun();
    if ($autostart_path != 1) {
        echo "Successfully created start script at " . $autostart_path . "\n";
        echo "To start daemon use: /etc/init.d/" . $appname . " start\n";
    } else {
        echo "Start script already created\n";
        echo "To start daemon use: /etc/init.d/" . $appname . " start\n";
    }
    exit;
}
require_once 'ykval-synclib.php';
require_once 'ykval-config.php';
require_once 'ykval-log.php';
System_Daemon::start();
// Spawn Deamon!
/* Application start */
$sl = new SyncLib('ykval-queue:synclib');
# Loop forever and resync
$res == 0;
while ($res == 0) {
    $sl->reSync($baseParams['__YKVAL_SYNC_OLD_LIMIT__'], $baseParams['__YKVAL_SYNC_RESYNC_TIMEOUT__']);
    $res = sleep($baseParams['__YKVAL_SYNC_INTERVAL__']);
}
System_Daemon::stop();
Example #11
0
 /**
  * Sets up Option Object instance
  *
  * @return boolean
  */
 protected static function _optionObjSetup()
 {
     // Create Option Object if nescessary
     if (self::$_optObj === false) {
         self::$_optObj = new System_Daemon_Options(self::$_optionDefinitions);
     }
     // Still false? This was an error!
     if (self::$_optObj === false) {
         self::log(self::LOG_EMERG, "Unable to setup Options object. " . "You must provide valid option definitions");
         return false;
     }
     return true;
 }
 /**
  * Add a new follower to the table
  **/
 protected function addFollower($data)
 {
     /**
      * Set up database connection
      */
     ORM::configure('mysql:host=localhost;dbname=' . DATABASE_TABLE);
     ORM::configure('username', DATABASE_USERNAME);
     ORM::configure('password', DATABASE_PASSWORD);
     if ($data['screen_name'] == TWITTER_USERNAME) {
         return;
     }
     // TODO change to production twitter handle
     $follow_code = md5($data['screen_name']);
     $follower = ORM::for_table('followers')->where('twitter_id', $data['id'])->find_one();
     if ($follower == false) {
         $follower = ORM::for_table('followers')->create();
         $follower->twitter_id = $data['id'];
         $follower->username = $data['screen_name'];
         $follower->follow_code = $follow_code;
     }
     $follower->created = date('Y-m-d H:i:s', time());
     $follower->save();
     /**
      * Send Direct Message
      **/
     $google = new GoogleURL(GOOGLE_API_KEY);
     $url = $google->shorten(WEB_APP_BASE_URL . "?follow_code={$follow_code}");
     $message = "Thanks for following, please visit " . $url . " within the hour to verify your age or you'll be blocked.";
     $connection = new TwitterOAuth(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET, OAUTH_TOKEN, OAUTH_SECRET);
     $message_resp = $connection->post('direct_messages/new', array('user_id' => $data['id'], 'text' => $message));
     System_Daemon::log(System_Daemon::LOG_INFO, "New request to follow, direct message http code resp was " . $connection->http_code);
     // get rid of db connection
     unset($follower);
     // get rid of db connection
 }
Example #13
0
 /**
  * Delete server alias (vuXXXX.myserver.tld) from DNS
  * @param $dmn_id
  * @return bool
  */
 public static function DeleteServerAlias($dmn_id)
 {
     $row = self::getUidAndIP($dmn_id);
     System_Daemon::debug("Domain ID: " . $dmn_id);
     $domainData = array('subdomain_name' => DaemonConfig::$cfg->APACHE_SUEXEC_USER_PREF . $row['domain_uid'], 'domain_name' => DaemonConfig::$cfg->BASE_SERVER_VHOST);
     System_Daemon::debug('Trying to delete name:' . $domainData['subdomain_name'] . '.' . $domainData['domain_name']);
     return self::DeleteDNSEntry($domainData);
 }
Example #14
0
 /**
  * @return mixed
  */
 public static function SaveProFTPdConfig()
 {
     System_Daemon::debug('Starting "DaemonConfigFTP::SaveProFTPdConfig" subprocess.');
     $xml = simplexml_load_file(DaemonConfig::$cfg->{'CONF_DIR'} . '/EasySCP_Config_FTP.xml');
     // Create config dir if it doesn't exists
     if (!file_exists(DaemonConfig::$distro->{'FTPD_CONF_DIR'})) {
         DaemonCommon::systemCreateDirectory(DaemonConfig::$distro->{'FTPD_CONF_DIR'}, DaemonConfig::$cfg->{'ROOT_USER'}, DaemonConfig::$cfg->{'ROOT_GROUP'}, 0755);
     }
     // Backup current proftpd.conf if exists
     if (file_exists(DaemonConfig::$distro->{'FTPD_CONF_FILE'})) {
         exec(DaemonConfig::$cmd->{'CMD_CP'} . ' -pf ' . DaemonConfig::$distro->{'FTPD_CONF_FILE'} . ' ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/proftpd/backup/proftpd.conf' . '_' . date("Y_m_d_H_i_s"), $result, $error);
     }
     // Loading the template from /etc/easyscp/proftpd/parts/, Building the new file
     // Store the new file in working directory
     $tpl_param = array('HOST_NAME' => idn_to_ascii(DaemonConfig::$cfg->{'SERVER_HOSTNAME'}));
     $tpl_param['UseIPv6'] = isset(DaemonConfig::$cfg->{'BASE_SERVER_IPv6'}) && DaemonConfig::$cfg->{'BASE_SERVER_IPv6'} != '' ? 'on' : 'off';
     $tpl = DaemonCommon::getTemplate($tpl_param);
     $config = $tpl->fetch('proftpd/parts/proftpd_' . DaemonConfig::$cfg->{'DistVersion'} . '.conf');
     $confFile = DaemonConfig::$cfg->{'CONF_DIR'} . '/proftpd/working/proftpd.conf';
     $tpl = NULL;
     unset($tpl);
     if (!DaemonCommon::systemWriteContentToFile($confFile, $config, DaemonConfig::$cfg->{'ROOT_USER'}, DaemonConfig::$cfg->{'ROOT_GROUP'}, 0600)) {
         return 'Error: Failed to write ' . $confFile;
     }
     // Installing the new file
     exec(DaemonConfig::$cmd->{'CMD_CP'} . ' -pf ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/proftpd/working/proftpd.conf ' . DaemonConfig::$distro->{'FTPD_CONF_FILE'}, $result, $error);
     $tpl_param = array('DATABASE_NAME' => $xml->{'DB_DATABASE'}, 'DATABASE_HOST' => $xml->{'DB_HOST'}, 'DATABASE_USER' => $xml->{'FTP_USER'}, 'DATABASE_PASS' => DB::decrypt_data($xml->{'FTP_PASSWORD'}), 'FTPD_MIN_UID' => DaemonConfig::$cfg->{'APACHE_SUEXEC_MIN_UID'}, 'FTPD_MIN_GID' => DaemonConfig::$cfg->{'APACHE_SUEXEC_MIN_GID'});
     $tpl = DaemonCommon::getTemplate($tpl_param);
     $config = $tpl->fetch('proftpd/parts/sql.conf');
     $confFile = DaemonConfig::$cfg->{'CONF_DIR'} . '/proftpd/working/sql.conf';
     $tpl = NULL;
     unset($tpl);
     if (!DaemonCommon::systemWriteContentToFile($confFile, $config, DaemonConfig::$cfg->{'ROOT_USER'}, DaemonConfig::$cfg->{'ROOT_GROUP'}, 0600)) {
         return 'Error: Failed to write ' . $confFile;
     }
     // Installing the new file
     exec(DaemonConfig::$cmd->{'CMD_CP'} . ' -pf ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/proftpd/working/sql.conf ' . DaemonConfig::$distro->FTPD_SQL_CONF_FILE, $result, $error);
     if (file_exists(DaemonConfig::$cfg->{'CONF_DIR'} . '/proftpd/parts/modules_' . DaemonConfig::$cfg->{'DistVersion'} . '.conf')) {
         exec(DaemonConfig::$cmd->{'CMD_CP'} . ' -pf ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/proftpd/parts/modules_' . DaemonConfig::$cfg->{'DistVersion'} . '.conf ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/proftpd/working/modules.conf', $result, $error);
         DaemonCommon::systemSetFilePermissions(DaemonConfig::$cfg->{'CONF_DIR'} . '/proftpd/working/modules.conf', DaemonConfig::$cfg->{'ROOT_USER'}, DaemonConfig::$cfg->{'ROOT_GROUP'}, 0644);
         exec(DaemonConfig::$cmd->{'CMD_CP'} . ' -pf ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/proftpd/working/modules.conf ' . DaemonConfig::$distro->FTPD_MODULES_CONF_FILE, $result, $error);
     }
     $tpl_param = array('APACHE_WWW_DIR' => DaemonConfig::$distro->{'APACHE_WWW_DIR'});
     $tpl = DaemonCommon::getTemplate($tpl_param);
     $config = $tpl->fetch('proftpd/parts/master.conf');
     $confFile = DaemonConfig::$cfg->{'CONF_DIR'} . '/proftpd/working/' . DaemonConfig::$cfg->{'SERVER_HOSTNAME'} . '.conf';
     $tpl = NULL;
     unset($tpl);
     if (!DaemonCommon::systemWriteContentToFile($confFile, $config, DaemonConfig::$cfg->{'ROOT_USER'}, DaemonConfig::$cfg->{'ROOT_GROUP'}, 0600)) {
         return 'Error: Failed to write ' . $confFile;
     }
     // Installing the new file
     exec(DaemonConfig::$cmd->{'CMD_CP'} . ' -pf ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/proftpd/working/' . DaemonConfig::$cfg->{'SERVER_HOSTNAME'} . '.conf ' . DaemonConfig::$distro->{'FTPD_CONF_DIR'} . '/' . DaemonConfig::$cfg->{'SERVER_HOSTNAME'} . '.conf', $result, $error);
     System_Daemon::debug('Finished "DaemonConfigFTP::SaveProFTPdConfig" subprocess.');
     return true;
 }
Example #15
0
 /**
  * start pcntl based daemon
  *
  * @return void
  */
 private function _daemonStart()
 {
     $options = array('appName' => 'osclog', 'appDir' => dirname(__FILE__), 'appDescription' => 'logs osc messages', 'sysMaxExecutionTime' => '0', 'sysMaxInputTime' => '0', 'sysMemoryLimit' => '1024M');
     System_Daemon::setOptions($options);
     System_Daemon::start();
 }
Example #16
0
 /**
  * Delete a given fileName
  *
  * returns true on success or error message otherwise
  *
  * @param $fileName
  * @return bool|string
  */
 protected static function deleteFile($fileName)
 {
     if (file_exists($fileName)) {
         if (!unlink($fileName)) {
             $msg = 'Cannot delete ' . $fileName;
             System_Daemon::debug($msg);
             return $msg . '<br />';
         }
     }
     return true;
 }
Example #17
0
        echo ' --' . $runmod . "\n";
    }
    die;
}
// Make it possible to test in source directory
// This is for PEAR developers only
ini_set('include_path', ini_get('include_path') . ':..');
// Include Class
error_reporting(E_STRICT);
require_once 'System/Daemon.php';
$nom = basename($_SERVER['PHP_SELF']);
// Setup
$options = array('appName' => $nom, 'appDir' => dirname(__FILE__), 'appDescription' => 'Parses KNX logfiles and stores them in MySQL for INIT', 'authorName' => 'Stan', 'authorEmail' => '', 'sysMaxExecutionTime' => '0', 'sysMaxInputTime' => '0', 'sysMemoryLimit' => '128M', 'appRunAsGID' => 0, 'appRunAsUID' => 0);
System_Daemon::setOptions($options);
// This program can also be run in the forground with runmode --no-daemon
if (!$runmode['no-daemon']) {
    // Spawn Daemon
    System_Daemon::start();
}
// With the runmode --write-initd, this program can automatically write a
// system startup file called: 'init.d'
// This will make sure your daemon will be started on reboot
if (!$runmode['write-initd']) {
    System_Daemon::info('not writing an init.d script this time');
} else {
    if (($initd_location = System_Daemon::writeAutoRun()) === false) {
        System_Daemon::notice('unable to write init.d script');
    } else {
        System_Daemon::info('sucessfully written startup script: %s', $initd_location);
    }
}
Example #18
0
 /**
  * Checks all data eg. Domain, Mail.
  *
  * @return boolean
  */
 private static function checkAllData()
 {
     System_Daemon::debug('Starting "checkAllData" subprocess.');
     $retVal = self::checkAllDataDomain();
     if ($retVal !== true) {
         $msg = 'Checking of domains failed';
         System_Daemon::debug($msg);
         return $msg . '<br />' . $retVal;
     }
     $retVal = self::checkAllDataAlias();
     if ($retVal !== true) {
         $msg = 'Checking of alias failed';
         System_Daemon::debug($msg);
         return $msg . '<br />' . $retVal;
     }
     $retVal = self::checkAllDataMail();
     if ($retVal !== true) {
         $msg = 'Checking of mail accounts failed';
         System_Daemon::debug($msg);
         return $msg . '<br />' . $retVal;
     }
     $retVal = self::checkAllDataHTAccess();
     if ($retVal !== true) {
         $msg = 'Checking of htaccess related data failed';
         System_Daemon::debug($msg);
         return $msg . '<br />' . $retVal;
     }
     // Fake aufruf um den Apache neu zu starten
     $retVal = DaemonDomain::Start('reload', true);
     if ($retVal !== true) {
         return $retVal;
     }
     System_Daemon::debug('Finished "checkAllData" subprocess.');
     return $retVal;
 }
Example #19
0
System_Daemon::debug('Starting "CronDomainBackup".');
$sql_query = "\n\tSELECT\n\t\tdomain_id, domain_name, domain_gid, domain_uid, status, allowbackup\n\tFROM\n\t\tdomain\n\tWHERE\n\t\tstatus = 'ok'\n\tORDER BY\n\t\tdomain_id;\n";
foreach (DB::query($sql_query) as $row) {
    // System_Daemon::info(var_dump($row));
    switch ($row['allowbackup']) {
        case 'dmn':
            System_Daemon::debug('Starting "Domain backup" subprocess.');
            DaemonBackup::DomainData($row);
            System_Daemon::debug('Finished "Domain backup" subprocess.');
            break;
        case 'sql':
            System_Daemon::debug('Starting "SQL backup" subprocess.');
            DaemonBackup::DomainDB($row);
            System_Daemon::debug('Finished "SQL backup" subprocess.');
            break;
        case 'full':
            System_Daemon::debug('Starting "Full backup" subprocess.');
            DaemonBackup::DomainDB($row);
            DaemonBackup::DomainData($row);
            System_Daemon::debug('Finished "Full backup" subprocess.');
            break;
        case 'no':
            System_Daemon::debug("Nichts sichern.");
            break;
        default:
            System_Daemon::debug("Don't know what to do with " . $row['allowbackup']);
    }
    DaemonBackup::CleanUp(DaemonConfig::$distro->{'APACHE_WWW_DIR'} . '/' . $row['domain_name'] . '/backups/', 2);
}
System_Daemon::debug('Finished "CronDomainBackup".');
Example #20
0
 /**
  * Handles DaemonSystem requests
  *
  * @param string $Input
  * @return mixed
  */
 public static function Start($Input)
 {
     System_Daemon::debug('Starting "DaemonSystem::Start" subprocess.');
     $data = explode(" ", $Input);
     switch ($data[0]) {
         case 'cron':
             System_Daemon::debug('Starting "cron" subprocess.');
             $retVal = self::handleCronjobsForAllUsers();
             if ($retVal !== true) {
                 System_Daemon::warning('Failed to handle Cronjobs');
                 System_Daemon::debug('Finished "cron" subprocess.');
                 return false;
             }
             System_Daemon::debug('Finished "cron" subprocess.');
             break;
         case 'direxists':
             System_Daemon::debug('Starting "direxists" subprocess.');
             if (is_dir($data[1])) {
                 System_Daemon::debug('Directory ' . $data[1] . ' exists');
                 System_Daemon::debug('Finished "direxists" subprocess.');
                 return true;
             } else {
                 System_Daemon::debug('Directory ' . $data[1] . ' does not exist');
                 System_Daemon::debug('Finished "direxists" subprocess.');
                 return false;
             }
             break;
         case 'fileexists':
             System_Daemon::debug('Starting "fileexists" subprocess.');
             if (is_file($data[1])) {
                 System_Daemon::debug('File ' . $data[1] . ' exists');
                 System_Daemon::debug('Finished "fileexists" subprocess.');
                 return true;
             } else {
                 System_Daemon::debug('File ' . $data[1] . ' does not exist');
                 System_Daemon::debug('Finished "fileexists" subprocess.');
                 return false;
             }
             break;
         case 'isexecutable':
             System_Daemon::debug('Starting "isexecutable" subprocess.');
             $internalCMD = explode(',', DaemonConfig::$cmd->SHELL_INTERNAL_CMDS);
             System_Daemon::debug(DaemonConfig::$cmd->SHELL_INTERNAL_CMDS);
             if (in_array($data[1], $internalCMD)) {
                 System_Daemon::debug('Command ' . $data[1] . ' is an internal command');
                 System_Daemon::debug('Finished "isexecutable" subprocess.');
                 return true;
             }
             if (self::Start('fileexists ' . $data[1])) {
                 if (is_executable($data[1])) {
                     System_Daemon::debug('File ' . $data[1] . ' is executable');
                     System_Daemon::debug('Finished "isexecutable" subprocess.');
                     return true;
                 } else {
                     System_Daemon::debug('File ' . $data[1] . ' is not executable');
                     System_Daemon::debug('Finished "isexecutable" subprocess.');
                     return false;
                 }
             } else {
                 System_Daemon::debug('Finished "isexecutable" subprocess.');
                 return false;
             }
             break;
         case 'rebuildConfig':
             System_Daemon::debug('Starting "rebuildConfig" subprocess.');
             $rebuildConfig = DaemonConfigCommon::rebuildConfig($data[1]);
             if ($rebuildConfig !== true) {
                 return $rebuildConfig;
             }
             System_Daemon::debug('Finished "rebuildConfig" subprocess.');
             break;
         case 'setPermissions':
             System_Daemon::debug('Starting "setPermissions" subprocess.');
             DaemonCommon::systemSetSystemPermissions();
             DaemonCommon::systemSetGUIPermissions();
             System_Daemon::debug('Finished "setPermissions" subprocess.');
             break;
         case 'updateIana':
             System_Daemon::debug('Starting "updateIana" subprocess.');
             self::updateIanaXML();
             DaemonCommon::systemSetFolderPermissions(EasyConfig_PATH . 'Iana_TLD.xml', 'root', 'root', '644');
             System_Daemon::debug('Finished "updateIana" subprocess.');
             break;
         case 'updateSystem':
             System_Daemon::debug('Starting "updateSystem" subprocess.');
             if (self::verifySystemUpdate()) {
                 self::handleSystemUpdate();
             }
             System_Daemon::debug('Finished "updateSystem" subprocess.');
             break;
         case 'userexists':
             System_Daemon::debug('Starting "userexists" subprocess.');
             exec(DaemonConfig::$cmd->CMD_ID . ' -u ' . $data['1'] . ' 2>&1', $result, $error);
             if ($error != 0) {
                 System_Daemon::debug('User ' . $data['1'] . ' does not exist');
                 unset($result);
                 return false;
             }
             System_Daemon::debug('Finished "userexists" subprocess.');
             break;
         default:
             System_Daemon::warning("Don't know what to do with " . $data[0]);
             return false;
     }
     System_Daemon::debug('Finished "DaemonSystem::Start" subprocess.');
     return true;
 }
Example #21
0
 private static function DaemonMailEnable($row)
 {
     System_Daemon::debug('Starting "DaemonMailDisable" subprocess.');
     $mail_ok = true;
     if ($mail_ok) {
         $sql_param = array(':mail_id' => $row['mail_id']);
         $sql_query = "\n\t\t\t\tUPDATE\n\t\t\t\t\tmail_users\n\t\t\t\tSET\n\t\t\t\t\tstatus = 'ok'\n\t\t\t\tWHERE\n\t\t\t\t\tmail_id = :mail_id\n\t\t\t";
         DB::prepare($sql_query);
         DB::execute($sql_param)->closeCursor();
     }
     System_Daemon::debug('Finished "DaemonMailDisable" subprocess.');
 }
Example #22
0
        $heure = date("H:i:s", $time);
        $req_eq_inser = "INSERT INTO knx_tracking (knx_equipement_id,jour,heure,value) VALUES ('" . $sniffed[$grpaddr]['id'] . "','" . $jour . "','" . $heure . "','" . $sniffed[$grpaddr]['value'] . "')";
        //System_Daemon::notice("Requete SQL -> ".$req_eq_inser);
        // Et on update la BDD
        $db->query($req_eq_inser);
        //System_Daemon::notice("OK");
    }
    //System_Daemon::info("GroupAddr : ".$grpaddr." | hexa : ".$hexa." - value :".$sniffed[$grpaddr]['value'] );
}
//on ecrit les données dans le fichier json trace
System_Daemon::info("Initialisation du fichier knxtrace.json");
makeJsonTrace($sniffed);
/*
Mise a jour du ficheir knxtrace.json a chaque modification d'un equipement suivi
*/
System_Daemon::info("Mise a jour du fichier knxtrace.json a chaque modification d'un equipement suivi et sauvegarde en base s'il doit etre historisé");
//$lastpos = 0;
while (true) {
    // On tail le fichier de log
    $knxlisten = tail(PATH_LOG, $lastpos);
    // On r�agit d�s qu'on a un Write
    // Pour chaque ligne, on r�cup�re le Groupe d'Addresse et de la valeur qu'on converti
    $groupaddr = get_string_between($knxlisten, 'group addr: ', ' -');
    $hexa = get_string_between($knxlisten, 'Hexa: ', ' -');
    //on met a jour le valeur dans le tableau et on regenere le fichier json
    //recursive_array_search
    if (array_key_exists($groupaddr, $sniffed)) {
        $decimal = hexdec($hexa);
        $value = dptSelectDecode($sniffed[$groupaddr]['dpt'], $decimal);
        //ecriture en base si changement d'etat et bas simplement l'equipement qui redis la meme chose sur le bus
        //System_Daemon::notice("Old Value -> ".$groupaddr.":: ".$oldSniffedValue[$groupaddr]);
Example #23
0
 /**
  * verifySystemUpdate
  *
  * @return mixed
  */
 protected static function verifySystemUpdate()
 {
     System_Daemon::debug('Starting "verifySystemUpdate" subprocess.');
     System_Daemon::debug('Finished "verifySystemUpdate" subprocess.');
     return true;
 }
Example #24
0
 protected static function handleSubDomainAlias($subDomainAliasData)
 {
     System_Daemon::debug('Starting "DaemonDomain::handleSubDomainAlias = ' . $subDomainAliasData['subdomain_name'] . '.' . $subDomainAliasData['alias_name'] . '" subprocess.');
     switch ($subDomainAliasData['alias_status']) {
         case 'add':
             $retVal = self::apacheWriteDomainConfig($subDomainAliasData);
             if ($retVal !== true) {
                 $msg = 'Writing subdomain-alias configuration failed';
                 System_Daemon::debug($msg);
                 return $msg . '<br />' . $retVal;
             }
             $retVal = DaemonDNS::AddDNSEntry($subDomainAliasData);
             if ($retVal !== true) {
                 $msg = 'Creating of subdomain-alias dns entry failed';
                 System_Daemon::debug($msg);
                 return $msg . '<br />' . $retVal;
             }
             break;
         case 'change':
             $retVal = self::apacheWriteDomainConfig($subDomainAliasData);
             if ($retVal !== true) {
                 $msg = 'Writing subdomain-alias configuration failed';
                 System_Daemon::debug($msg);
                 return $msg . '<br />' . $retVal;
             }
             break;
         case 'delete':
             $retVal = self::deleteAliasSubDomain($subDomainAliasData);
             if ($retVal !== true) {
                 $msg = 'Deleting of subdomain-alias failed';
                 System_Daemon::debug($msg);
                 return $msg . '<br />' . $retVal;
             }
             $retVal = DaemonDNS::DeleteDNSEntry($subDomainAliasData);
             if ($retVal !== true) {
                 $msg = 'Deleting of subdomain-alias dns entry failed';
                 System_Daemon::debug($msg);
                 return $msg . '<br />' . $retVal;
             }
             break;
         case 'ok':
             // Configuration has to be rewritten every time to ensure that
             // all domains and subdomains are completely configured
             $retVal = self::apacheWriteDomainConfig($subDomainAliasData);
             if ($retVal !== true) {
                 $msg = 'Writing subdomain-alias configuration failed';
                 System_Daemon::debug($msg);
                 return $msg . '<br />' . $retVal;
             }
             break;
         default:
             $msg = "Don't know what to do with " . $subDomainAliasData['status'] . " (handlesubdomainalias)";
             System_Daemon::warning($msg);
             return $msg . '<br />';
             break;
     }
     if ($retVal === true) {
         $retVal = self::dbSetAliasSubDomainStatus('ok', $subDomainAliasData['subdomain_alias_id']);
         if ($retVal !== true) {
             $msg = 'Setting Aliassubdomain status failed';
             System_Daemon::debug($msg);
             return $msg . '<br />' . $retVal;
         }
     }
     return true;
 }
<?php

require_once "../System/Daemon.php";
System_Daemon::setOption("appName", "leakplugger");
System_Daemon::start();
$last = 0;
while (!System_Daemon::isDying()) {
    $mem = memory_get_peak_usage();
    $use = $mem - $last;
    if ($use >= 0) {
        $use = '+' . $use;
    }
    System_Daemon::info("test");
    echo "debug: memory_get_peak_usage: " . $use . "\n";
    $last = $mem;
    System_Daemon::iterate(1);
}
Example #26
0
 public function runTaskAsDaemon($task_name, $options = array())
 {
     $this->_ensurePosixAndPcntlAreAvailable();
     require_once 'System/Daemon.php';
     $app_name = AkInflector::underscore($task_name);
     $pid_file = AK_BASE_DIR . DS . 'run' . DS . $app_name . DS . $app_name . '.pid';
     $log_file = AK_LOG_DIR . DS . 'daemons' . DS . $app_name . '.log';
     if (!file_exists($pid_file)) {
         if (empty($options['attributes']['kill'])) {
             AkFileSystem::file_put_contents($pid_file, '');
             AkFileSystem::file_delete($pid_file);
         } else {
             $this->error("Could not kill process for {$task_name}", true);
         }
     } else {
         $pid = (int) file_get_contents($pid_file);
         if ($pid > 0) {
             if (!empty($options['attributes']['kill'])) {
                 $this->message("Killing process {$pid}");
                 `kill {$pid}`;
                 AkFileSystem::file_delete($pid_file);
                 die;
             } elseif (!empty($options['attributes']['restart'])) {
                 $this->message("Restarting {$task_name}.");
                 $this->message(`kill {$pid}`);
             } else {
                 $this->error("Daemon for {$task_name} still running ({$pid_file}).\nTask aborted.", true);
             }
         }
     }
     if (!empty($options['attributes']['kill']) && empty($pid)) {
         $this->error("No daemon running for task {$task_name}", true);
     }
     unset($options['attributes']['restart']);
     if (!file_exists($log_file)) {
         AkFileSystem::file_put_contents($log_file, '');
     }
     System_Daemon::setOption('appName', $app_name);
     System_Daemon::setOption('appDir', AK_BASE_DIR);
     System_Daemon::setOption('logLocation', $log_file);
     System_Daemon::setOption('appRunAsUID', posix_geteuid());
     System_Daemon::setOption('appRunAsGID', posix_getgid());
     System_Daemon::setOption('appPidLocation', $pid_file);
     $this->message("Staring daemon. ({$log_file})");
     System_Daemon::start();
     $dsn = Ak::getStaticVar('dsn');
     defined('AK_SKIP_DB_CONNECTION') && AK_SKIP_DB_CONNECTION ? null : Ak::db($dsn);
     $this->runTask($task_name, $options);
     System_Daemon::stop();
     AkFileSystem::file_delete($pid_file);
     die;
 }
Example #27
0
 /**
  * @return mixed
  */
 public static function SavePDNSConfig()
 {
     System_Daemon::debug('Starting "DaemonConfigDNS::SavePDNSConfig" subprocess.');
     if (!file_exists(DaemonConfig::$distro->{'PDNS_DB_DIR'} . '/')) {
         DaemonCommon::systemCreateDirectory(DaemonConfig::$distro->{'PDNS_DB_DIR'} . '/', DaemonConfig::$cfg->{'ROOT_USER'}, DaemonConfig::$cfg->{'ROOT_GROUP'}, 0640);
     }
     $xml = simplexml_load_file(DaemonConfig::$cfg->{'CONF_DIR'} . '/EasySCP_Config_DNS.xml');
     $tpl_param = array('PDNS_USER' => $xml->{'PDNS_USER'}, 'PDNS_PASS' => DB::decrypt_data($xml->{'PDNS_PASS'}), 'HOSTNAME' => $xml->{'HOSTNAME'});
     switch (DaemonConfig::$cfg->{'DistName'} . '_' . DaemonConfig::$cfg->{'DistVersion'}) {
         case 'CentOS_6':
             $tpl = DaemonCommon::getTemplate($tpl_param);
             $config = $tpl->fetch('pdns/parts/pdns.conf');
             $confFile = DaemonConfig::$cfg->{'CONF_DIR'} . '/pdns/working/pdns.conf';
             $tpl = NULL;
             unset($tpl);
             if (!DaemonCommon::systemWriteContentToFile($confFile, $config, DaemonConfig::$cfg->{'ROOT_USER'}, DaemonConfig::$cfg->{'ROOT_GROUP'}, 0640)) {
                 return 'Error: Failed to write ' . $confFile;
             }
             break;
         case 'Debian_8':
             exec(DaemonConfig::$cmd->{'CMD_CP'} . ' -pf ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/pdns/parts/pdns_8.conf ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/pdns/working/pdns.conf', $result, $error);
             $tpl = DaemonCommon::getTemplate($tpl_param);
             $config = $tpl->fetch('pdns/parts/pdns.local.gmysql.conf');
             $confFile = DaemonConfig::$cfg->{'CONF_DIR'} . '/pdns/working/pdns.local.gmysql.conf';
             $tpl = NULL;
             unset($tpl);
             if (!DaemonCommon::systemWriteContentToFile($confFile, $config, DaemonConfig::$cfg->{'ROOT_USER'}, DaemonConfig::$cfg->{'ROOT_GROUP'}, 0640)) {
                 return 'Error: Failed to write ' . $confFile;
             }
             // Installing the new file
             exec(DaemonConfig::$cmd->{'CMD_CP'} . ' -pf ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/pdns/working/pdns.local.gmysql.conf ' . DaemonConfig::$distro->{'PDNS_DB_DIR'} . '/pdns.local.gmysql.conf', $result, $error);
             if (file_exists(DaemonConfig::$distro->{'PDNS_DB_DIR'} . '/../bindbackend.conf')) {
                 unlink(DaemonConfig::$distro->{'PDNS_DB_DIR'} . '/../bindbackend.conf');
             }
             if (file_exists(DaemonConfig::$distro->{'PDNS_DB_DIR'} . '/pdns.simplebind.conf')) {
                 unlink(DaemonConfig::$distro->{'PDNS_DB_DIR'} . '/pdns.simplebind.conf');
             }
             break;
         case 'Ubuntu_14.04':
             exec(DaemonConfig::$cmd->{'CMD_CP'} . ' -pf ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/pdns/parts/pdns_14.04.conf ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/pdns/working/pdns.conf', $result, $error);
             $tpl = DaemonCommon::getTemplate($tpl_param);
             $config = $tpl->fetch('pdns/parts/pdns.local.gmysql.conf');
             $confFile = DaemonConfig::$cfg->{'CONF_DIR'} . '/pdns/working/pdns.local.gmysql.conf';
             $tpl = NULL;
             unset($tpl);
             if (!DaemonCommon::systemWriteContentToFile($confFile, $config, DaemonConfig::$cfg->{'ROOT_USER'}, DaemonConfig::$cfg->{'ROOT_GROUP'}, 0640)) {
                 return 'Error: Failed to write ' . $confFile;
             }
             // Installing the new file
             exec(DaemonConfig::$cmd->{'CMD_CP'} . ' -pf ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/pdns/working/pdns.local.gmysql.conf ' . DaemonConfig::$distro->{'PDNS_DB_DIR'} . '/pdns.local.gmysql.conf', $result, $error);
             if (file_exists(DaemonConfig::$distro->{'PDNS_DB_DIR'} . '/../bindbackend.conf')) {
                 unlink(DaemonConfig::$distro->{'PDNS_DB_DIR'} . '/../bindbackend.conf');
             }
             if (file_exists(DaemonConfig::$distro->{'PDNS_DB_DIR'} . '/pdns.simplebind.conf')) {
                 unlink(DaemonConfig::$distro->{'PDNS_DB_DIR'} . '/pdns.simplebind.conf');
             }
             break;
         default:
             exec(DaemonConfig::$cmd->{'CMD_CP'} . ' -f ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/pdns/parts/pdns.conf ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/pdns/working/pdns.conf', $result, $error);
             $tpl = DaemonCommon::getTemplate($tpl_param);
             $config = $tpl->fetch('pdns/parts/pdns.local.gmysql');
             $confFile = DaemonConfig::$cfg->{'CONF_DIR'} . '/pdns/working/pdns.local.gmysql';
             $tpl = NULL;
             unset($tpl);
             if (!DaemonCommon::systemWriteContentToFile($confFile, $config, DaemonConfig::$cfg->{'ROOT_USER'}, DaemonConfig::$cfg->{'ROOT_GROUP'}, 0640)) {
                 return 'Error: Failed to write ' . $confFile;
             }
             // Installing the new file
             exec(DaemonConfig::$cmd->{'CMD_CP'} . ' -pf ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/pdns/working/pdns.local.gmysql ' . DaemonConfig::$distro->{'PDNS_DB_DIR'} . '/pdns.local.gmysql', $result, $error);
             if (file_exists(DaemonConfig::$distro->{'PDNS_DB_DIR'} . '/../bindbackend.conf')) {
                 unlink(DaemonConfig::$distro->{'PDNS_DB_DIR'} . '/../bindbackend.conf');
             }
             if (file_exists(DaemonConfig::$distro->{'PDNS_DB_DIR'} . '/pdns.simplebind')) {
                 unlink(DaemonConfig::$distro->{'PDNS_DB_DIR'} . '/pdns.simplebind');
             }
     }
     // Backup current pdns.conf if exists
     if (file_exists(DaemonConfig::$distro->{'PDNS_CONF_FILE'})) {
         exec(DaemonConfig::$cmd->{'CMD_CP'} . ' -pf ' . DaemonConfig::$distro->{'PDNS_CONF_FILE'} . ' ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/pdns/backup/pdns.conf' . '_' . date("Y_m_d_H_i_s"), $result, $error);
     }
     DaemonCommon::systemSetFilePermissions(DaemonConfig::$cfg->{'CONF_DIR'} . '/pdns/working/pdns.conf', DaemonConfig::$cfg->{'ROOT_USER'}, DaemonConfig::$cfg->{'ROOT_GROUP'}, 0640);
     exec(DaemonConfig::$cmd->{'CMD_CP'} . ' -pf ' . DaemonConfig::$cfg->{'CONF_DIR'} . '/pdns/working/pdns.conf ' . DaemonConfig::$distro->{'PDNS_CONF_FILE'}, $result, $error);
     System_Daemon::debug('Finished "DaemonConfigDNS::SavePDNSConfig" subprocess.');
     return true;
 }
Example #28
0
#!/usr/bin/php -q
<?php 
include '_includes/knx-function-daemon.php';
include '_includes/knx-config.php';
include '_includes/knx-function.php';
include '_includes/eib-functions.php';
System_Daemon::info("######    KNX Tracking -> Insert in db knxtrace.json each minute   #####");
/*
$sniffed[ $data['group_addr'] ]   = array(
                                            "id"        => data['id'],
   	                                        "name"      => $data['name'],
   	                                        "dpt"       => $data['dpt'],
   	                                        "value"     => "",
   	                                        "unite"     => getDptUnite($data['dpt'])
   	                                        );
*/
while (true) {
    sleep(60);
    $json = file_get_contents(PATH_JSON);
    $trace = json_decode($json, true);
    $jour = date('Y-m-d');
    $heure = date('H:i:s');
    foreach ($trace as $groupaddr => $info) {
        $req_eq_inser = "INSERT INTO knx_tracking (knx_equipement_id,jour,heure,value) VALUES ('" . $info['id'] . "','" . $jour . "','" . $heure . "','" . $info['value'] . "')";
        //System_Daemon::notice("Requete SQL -> ".$req_eq_inser);
        // Et on update la BDD
        mysql_query($req_eq_inser);
    }
}
Example #29
0
 /**
  * @param string $config
  * @return mixed
  */
 public static function rebuildConfigPass($config = 'system')
 {
     System_Daemon::debug('Starting "DaemonConfigCommon::rebuildConfigPass" subprocess.');
     switch ($config) {
         case 'DNS':
             System_Daemon::debug('Starting "DNS" subprocess.');
             $SavePDNSConfig = DaemonConfigDNS::SavePDNSConfig();
             if ($SavePDNSConfig !== true) {
                 return $SavePDNSConfig;
             }
             System_Daemon::debug('Finished "DNS" subprocess.');
             break;
         case 'FTP':
             System_Daemon::debug('Starting "FTP" subprocess.');
             $SaveProFTPdConfig = DaemonConfigFTP::SaveProFTPdConfig();
             if ($SaveProFTPdConfig !== true) {
                 return $SaveProFTPdConfig;
             }
             System_Daemon::debug('Finished "FTP" subprocess.');
             break;
         case 'MTA':
             System_Daemon::debug('Starting "MTA" subprocess.');
             $SaveMTAConfig = DaemonConfigMail::SaveMTAConfig();
             if ($SaveMTAConfig !== true) {
                 return $SaveMTAConfig;
             }
             System_Daemon::debug('Finished "MTA" subprocess.');
             break;
         case 'PMA':
             System_Daemon::debug('Starting "PMA" subprocess.');
             DaemonConfigTools::SavePMAConfig();
             System_Daemon::debug('Finished "PMA" subprocess.');
             break;
         case 'RC':
             System_Daemon::debug('Starting "RC" subprocess.');
             DaemonConfigTools::SaveRCConfig();
             System_Daemon::debug('Finished "RC" subprocess.');
             break;
         case 'system':
             System_Daemon::debug('Starting "system" subprocess.');
             $SavePDNSConfig = DaemonConfigDNS::SavePDNSConfig();
             if ($SavePDNSConfig !== true) {
                 return $SavePDNSConfig;
             }
             $SaveProFTPdConfig = DaemonConfigFTP::SaveProFTPdConfig();
             if ($SaveProFTPdConfig !== true) {
                 return $SaveProFTPdConfig;
             }
             $SaveMTAConfig = DaemonConfigMail::SaveMTAConfig();
             if ($SaveMTAConfig !== true) {
                 return $SaveMTAConfig;
             }
             System_Daemon::debug('Finished "system" subprocess.');
             break;
         default:
             System_Daemon::warning("Don't know what to do with " . $config);
             return false;
     }
     System_Daemon::debug('Finished "DaemonConfigCommon::rebuildConfigPass" subprocess.');
     return true;
 }