Example #1
0
 /**
  * Create cron file for one user 
  * 
  * @param int $userID
  * @param string $userName
  * @return mixed
  */
 protected static function handleCronjobForUser($userID, $userName)
 {
     System_Daemon::debug('Starting "handleCronjobForUser" subprocess.');
     // Due to bug https://bugs.launchpad.net/ubuntu/+source/cron/+bug/706565 all . in username must be removed or
     // replaced. Otherwise the cronjobs never run.
     $confUser = str_replace('.', '_', $userName);
     $confFile = DaemonConfig::$distro->{'CRON_DIR'} . '/EasySCP_' . $confUser;
     $sql_param = array(':user_id' => $userID, ':active' => 'yes');
     $sql_query = "\n\t\t\tSELECT\n\t\t\t\t*\n\t\t\tFROM\n\t\t\t\tcronjobs\n\t\t\tWHERE\n\t\t\t\tactive = :active\n\t\t\tAND\n\t\t\t\tuser_id = :user_id\n\t\t";
     DB::prepare($sql_query);
     $cronData = DB::execute($sql_param);
     if ($cronData->rowCount() == 0) {
         @unlink($confFile);
     } else {
         $tpl_param = array('ADMIN' => $userName);
         $tpl = DaemonCommon::getTemplate($tpl_param);
         while ($cronJob = $cronData->fetch()) {
             $tpl->append(array('DESCRIPTION' => "# " . $cronJob['description'], 'SCHEDULE' => $cronJob['schedule'], 'USER' => $cronJob['user'], 'COMMAND' => $cronJob['command']));
         }
         // write Cron config
         $config = $tpl->fetch("tpl/cron.tpl");
         System_Daemon::debug($confFile);
         $retVal = DaemonCommon::systemWriteContentToFile($confFile, $config, DaemonConfig::$cfg->{'ROOT_USER'}, DaemonConfig::$cfg->{'ROOT_GROUP'}, 0644, false);
         if ($retVal !== true) {
             $msg = 'Failed to write' . $confFile;
             System_Daemon::warning($msg);
             return $msg . '<br />' . $retVal;
         } else {
             System_Daemon::debug($confFile . ' successfully written!');
         }
     }
     System_Daemon::debug('Finished "handleCronjobForUser" subprocess.');
     return true;
 }
Example #2
0
 public static function SaveOldConfig()
 {
     $tpl_param = array('BuildDate' => self::$cfg->{'BuildDate'}, 'DistName' => self::$cfg->{'DistName'}, 'Version' => self::$cfg->{'Version'}, 'DEFAULT_ADMIN_ADDRESS' => self::$cfg->{'DEFAULT_ADMIN_ADDRESS'}, 'SERVER_HOSTNAME' => self::$cfg->{'SERVER_HOSTNAME'}, 'BASE_SERVER_IP' => self::$cfg->{'BASE_SERVER_IP'}, 'BASE_SERVER_VHOST' => self::$cfg->{'BASE_SERVER_VHOST'}, 'BASE_SERVER_VHOST_PREFIX' => self::$cfg->{'BASE_SERVER_VHOST_PREFIX'}, 'DATABASE_HOST' => self::$cfg->{'DATABASE_HOST'}, 'DATABASE_NAME' => self::$cfg->{'DATABASE_NAME'}, 'DATABASE_PASSWORD' => self::$cfg->{'DATABASE_PASSWORD'}, 'DATABASE_USER' => self::$cfg->{'DATABASE_USER'}, 'PHP_TIMEZONE' => self::$cfg->{'PHP_TIMEZONE'}, 'SECONDARY_DNS' => self::$cfg->{'Secondary_DNS'}, 'LOCAL_DNS_RESOLVER' => self::$cfg->{'LOCAL_DNS_RESOLVER'}, 'AWSTATS_ACTIVE' => self::$cfg->{'AWSTATS_ACTIVE'}, 'AWSTATS_MODE' => self::$cfg->{'AWSTATS_MODE'}, 'APACHE_SUEXEC_MIN_GID' => self::$cfg->{'APACHE_SUEXEC_MIN_GID'}, 'APACHE_SUEXEC_MIN_UID' => self::$cfg->{'APACHE_SUEXEC_MIN_UID'}, 'MTA_MAILBOX_MIN_UID' => self::$cfg->{'MTA_MAILBOX_MIN_UID'}, 'MTA_MAILBOX_UID' => self::$cfg->{'MTA_MAILBOX_UID'}, 'MTA_MAILBOX_GID' => self::$cfg->{'MTA_MAILBOX_GID'}, 'MYSQL_PREFIX' => self::$cfg->{'MYSQL_PREFIX'}, 'MYSQL_PREFIX_TYPE' => self::$cfg->{'MYSQL_PREFIX_TYPE'}, 'DEBUG' => self::$cfg->{'DEBUG'});
     $tpl = DaemonCommon::getTemplate($tpl_param);
     $config = $tpl->fetch('tpl/easyscp.conf');
     $confFile = DaemonConfig::$cfg->{'CONF_DIR'} . '/easyscp.conf';
     if (!DaemonCommon::systemWriteContentToFile($confFile, $config, DaemonConfig::$cfg->{'ROOT_USER'}, DaemonConfig::$cfg->{'ROOT_GROUP'}, 0644)) {
         return 'Error: Failed to write ' . $confFile;
     }
     $tpl = NULL;
     unset($tpl);
     return 'Ok';
 }
Example #3
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 #4
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 #5
0
function GUI_VHOST()
{
    $tpl_param = array('APACHE_LOG_DIR' => DaemonConfig::$distro->APACHE_LOG_DIR, 'BASE_PORT' => 80, 'BASE_SERVER_IP' => DaemonConfig::$cfg->BASE_SERVER_IP, 'BASE_SERVER_VHOST' => idn_to_ascii(DaemonConfig::$cfg->{'BASE_SERVER_VHOST'}), 'DEFAULT_ADMIN_ADDRESS' => DaemonConfig::$cfg->DEFAULT_ADMIN_ADDRESS, 'GUI_ROOT_DIR' => DaemonConfig::$cfg->GUI_ROOT_DIR, 'PHP_STARTER_DIR' => DaemonConfig::$distro->{'PHP_STARTER_DIR'}, 'SUEXEC_GID' => DaemonConfig::$cfg->{'APACHE_SUEXEC_USER_PREF'} . DaemonConfig::$cfg->{'APACHE_SUEXEC_MIN_GID'}, 'SUEXEC_UID' => DaemonConfig::$cfg->{'APACHE_SUEXEC_USER_PREF'} . DaemonConfig::$cfg->{'APACHE_SUEXEC_MIN_UID'});
    if (isset(DaemonConfig::$cfg->BASE_SERVER_IPv6) && DaemonConfig::$cfg->BASE_SERVER_IPv6 != '') {
        $tpl_param['BASE_SERVER_IPv6'] = DaemonConfig::$cfg->BASE_SERVER_IPv6;
    }
    $tpl = DaemonCommon::getTemplate($tpl_param);
    $config = $tpl->fetch('apache/parts/' . DaemonConfig::$cfg->{'DistName'} . '_' . DaemonConfig::$cfg->{'DistVersion'} . '/00_master.conf.tpl');
    $confFile = DaemonConfig::$cfg->{'CONF_DIR'} . '/apache/working/00_master.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'} . '/apache/working/00_master.conf ' . DaemonConfig::$distro->{'APACHE_SITES_DIR'} . '/00_master.conf', $result, $error);
    return 'Ok';
}
Example #6
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 #7
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 #8
0
 /**
  * Verify if SSL-key and certificate corresponds. Write key and certificate
  * @param array $domainData
  * @return mixed
  */
 protected static function writeSSLKeys($domainData)
 {
     System_Daemon::debug(print_r($domainData, true));
     if (isset($domainData['subdomain_name'])) {
         $fqdn = $domainData['subdomain_name'] . '.' . $domainData['domain_name'];
     } else {
         $fqdn = $domainData['domain_name'];
     }
     $certFile = DaemonConfig::$distro->SSL_CERT_DIR . '/easyscp_' . $fqdn . '-cert.pem';
     $cacertFile = DaemonConfig::$distro->SSL_CERT_DIR . '/easyscp_' . $fqdn . '-cacert.pem';
     $keyFile = DaemonConfig::$distro->SSL_KEY_DIR . '/easyscp_' . $fqdn . '-key.pem';
     $cert = $domainData['ssl_cert'];
     $key = $domainData['ssl_key'];
     if (openssl_x509_check_private_key($cert, $key)) {
         if (!DaemonCommon::systemWriteContentToFile($certFile, $domainData['ssl_cert'], DaemonConfig::$cfg->ROOT_USER, DaemonConfig::$cfg->ROOT_GROUP, 0644)) {
             $msg = 'Failed to write certificate ' . $certFile;
             System_Daemon::debug($msg);
             return $msg . '<br />';
         }
         if (!DaemonCommon::systemWriteContentToFile($keyFile, $domainData['ssl_key'], DaemonConfig::$cfg->ROOT_USER, DaemonConfig::$cfg->ROOT_GROUP, 0640)) {
             $msg = 'Failed to write key ' . $keyFile;
             System_Daemon::debug($msg);
             return $msg . '<br />';
         }
         if (isset($domainData['ssl_cacert']) && $domainData['ssl_cacert'] != '') {
             if (!DaemonCommon::systemWriteContentToFile($cacertFile, $domainData['ssl_cacert'], DaemonConfig::$cfg->ROOT_USER, DaemonConfig::$cfg->ROOT_GROUP, 0644)) {
                 $msg = 'Failed to write certificate of certification authorities (CA) ' . $cacertFile;
                 System_Daemon::debug($msg);
                 return $msg . '<br />';
             }
         }
     } else {
         $msg = 'Certificate and key don\'t match';
         System_Daemon::debug($msg);
         return $msg . '<br />';
     }
     return true;
 }