Exemple #1
0
 /**
  * Export configuration
  * @param DatabaseSqlite3 &$db Database object
  * @return boolean
  */
 public function exportConfiguration(&$db)
 {
     Log::debug('Export configuration: opendkim');
     // Smarty template
     $smarty = TemplateFactory::create();
     if ($smarty === false) {
         return false;
     }
     // Check for default key
     if (!is_file('/etc/opendkim/keys/default.private') || !is_file('/etc/opendkim/keys/default.txt')) {
         // Generate key
         exec('/usr/sbin/opendkim-default-keygen');
         // Re-check
         if (!is_file('/etc/opendkim/keys/default.private') || !is_file('/etc/opendkim/keys/default.txt')) {
             Log::error('Error while creating OpenDKIM keys via /usr/sbin/opendkim-default-keygen, ensure the /etc/hosts file contains the IP and FQDM of the server');
             return false;
         }
     }
     // OpenDKIM config file
     $rc = $this->saveConfigFile(Config::read('opendkim|opendkimConfFile'), 'opendkimconffile', 'opendkim.tpl', $smarty);
     if ($rc === false) {
         return false;
     } else {
         return true;
     }
 }
 /**
  * Export configuration
  * @param DatabaseSqlite3 &$db Database object
  * @return boolean
  */
 public function exportConfiguration(&$db)
 {
     Log::debug('Export configuration: spamassassin');
     // Smarty template
     $smarty = TemplateFactory::create();
     if ($smarty === false) {
         return false;
     }
     // SpamAssassin daemon (spamd)
     // Init file
     $rc = $this->saveConfigFile(Config::read('spamassassin|initPreFile'), 'spamdinitpre', 'spamassassin.tpl', $smarty);
     if ($rc === false) {
         return false;
     }
     // Milter sysconfig file
     $rc = $this->saveConfigFile(Config::read('spamassassin|milterFile'), 'spamassmilter', 'spamassassin.tpl', $smarty);
     if ($rc === false) {
         return false;
     }
     // Local file
     $rc = $this->saveConfigFile(Config::read('spamassassin|localCfFile'), 'spamdlocalcf', 'spamassassin.tpl', $smarty);
     if ($rc === false) {
         return false;
     } else {
         return true;
     }
 }
Exemple #3
0
 /**
  * Export configuration (php.ini)
  * @param DatabaseSqlite3 &$db Database object
  * @return boolean
  */
 public function exportConfiguration(&$db)
 {
     Log::debug('Export configuration: php');
     // Smarty template
     $smarty = TemplateFactory::create();
     if ($smarty === false) {
         return false;
     }
     // Try to detect the timezone of the server
     $timezone = '';
     $timedatectl = array();
     exec('/usr/bin/timedatectl', $timedatectl);
     foreach ($timedatectl as $t) {
         // Look for time zone string
         if (strpos($t, 'Time zone') !== false) {
             $rc = preg_match('/Time zone: (.*) \\(/U', $t, $matches);
             if ($rc === 1 && isset($matches[1])) {
                 // Match found, store and break from loop
                 $timezone = trim($matches[1]);
                 break;
             }
         }
     }
     // Assign variables
     $smarty->assignByRef('TIMEZONE', $timezone);
     // Load custom changes from template
     $params = explode("\n", $smarty->fetch('php.tpl'));
     // Load the php.ini file into memory
     $ini = file_get_contents(Config::read('php|iniFile'));
     if ($ini === false) {
         Log::error('Error while loading file: ' . Config::read('php|iniFile'));
         return false;
     }
     // Loop each parameter
     foreach ($params as $p) {
         // Trim input
         $p = trim($p);
         // Skip empty and/or invalid lines
         if ($p == '' || strpos($p, '=') === false) {
             continue;
         }
         $p = explode('=', $p);
         $rc = $this->_setIniParameter($ini, $p[0], $p[1]);
         if ($rc === false) {
             return false;
         }
     }
     // Save the modified php.ini
     Log::debug('Writing to file: ' . Config::read('php|iniFile'));
     $rc = file_put_contents(Config::read('php|iniFile'), $ini, LOCK_EX);
     if ($rc === false) {
         Log::error('Error while writing to file: ' . Config::read('php|iniFile'));
         return false;
     }
     return true;
 }
Exemple #4
0
 /**
  * Export configuration (server.cnf)
  * @param DatabaseSqlite3 &$db Database object
  * @return boolean
  */
 public function exportConfiguration(&$db)
 {
     Log::debug('Export configuration: mariadb');
     // Smarty template
     $smarty = TemplateFactory::create();
     if ($smarty === false) {
         return false;
     }
     // Generate main configuration (server.cnf)
     $rc = $this->saveConfigFile(Config::read('mariadb|serverFile'), '', 'mariadb.tpl', $smarty);
     if ($rc === false) {
         return false;
     } else {
         return true;
     }
 }
Exemple #5
0
 /**
  * @param Template $template
  * @param $params
  * @throws \Exception
  */
 public function bootTemplate($template, $params)
 {
     if (!$template->isBootExists()) {
         throw new \Exception('No boot for template');
     }
     $bootData = $this->logicProcessor->processBootLogic($template, $params);
     if ($bootData->getExtend() != null) {
         /** @var Template $parent */
         $parent = $this->templateFactory->getTemplate($bootData->getExtend());
         $template->setParent($parent);
         $parent->setChild($template);
         if ($parent->isBootExists()) {
             $this->bootTemplate($parent, $params);
         }
     }
 }
 public function runTests($output)
 {
     $this->getTestFixturesByParent();
     $this->run();
     if (PHP_SAPI === 'cli') {
         $output = TemplateType::Cli;
     }
     $OutputTemplate = TemplateFactory::createOutputTemplate($output, $this->Language);
     echo $OutputTemplate->get($this->Errors, $this->Results, $this->Text, $this->Duration, $this->MethodCalls);
     if (count($this->Errors) > 0) {
         exit(1);
     } else {
         exit(0);
     }
 }
Exemple #7
0
 /**
  * Export configuration (httpd.conf, modules and virtual hosts)
  * @param DatabaseSqlite3 &$db Database object
  * @return boolean
  */
 public function exportConfiguration(&$db)
 {
     Log::debug('Export configuration: apache');
     // Smarty template
     if ($this->smarty === null) {
         $this->smarty = TemplateFactory::create();
         if ($this->smarty === false) {
             return false;
         }
     }
     // Disable autoindex
     $file = Config::read('apache|directoryConfD') . '/autoindex.conf';
     if (is_file($file)) {
         rename($file, $file . '.disabled');
     }
     // Disable welcome
     $file = Config::read('apache|directoryConfD') . '/welcome.conf';
     if (is_file($file)) {
         rename($file, $file . '.disabled');
     }
     // Assign variables
     $this->smarty->assign('SERVERNAME', php_uname('n'));
     $this->smarty->assign('SERVERIP', gethostbyname(php_uname('n')));
     $this->smarty->assign('CERTS', Config::read('pkitls|directoryCerts'));
     $this->smarty->assign('KEYS', Config::read('pkitls|directoryPrivate'));
     if (is_file(Config::read('pkitls|directoryCerts') . '/localhost.chain')) {
         $this->smarty->assign('CHAIN', true);
     } else {
         $this->smarty->assign('CHAIN', false);
     }
     if (is_file(Config::read('pkitls|directoryCerts') . '/localhost.cabundle')) {
         $this->smarty->assign('CABUNDLE', true);
     } else {
         $this->smarty->assign('CABUNDLE', false);
     }
     // Generate main configuration (httpd.conf)
     $rc = $this->saveConfigFile(Config::read('apache|directoryConf') . '/httpd.conf', 'httpdConf', 'apache.tpl', $this->smarty);
     if ($rc === false) {
         return false;
     }
     // Generate ssl configuration (ssl.conf)
     $rc = $this->saveConfigFile(Config::read('apache|directoryConfD') . '/ssl.conf', 'sslConf', 'apache.tpl', $this->smarty);
     if ($rc === false) {
         return false;
     }
     // Generate evasive configuration (mod_evasive.conf)
     $rc = $this->saveConfigFile(Config::read('apache|directoryConfD') . '/mod_evasive.conf', 'evasiveConf', 'apache.tpl', $this->smarty);
     if ($rc === false) {
         return false;
     }
     // Generate base modules (00-base.conf)
     $rc = $this->saveConfigFile(Config::read('apache|directoryConfModulesD') . '/00-base.conf', 'baseConf', 'apache.tpl', $this->smarty);
     if ($rc === false) {
         return false;
     }
     // Get all virtual hosts and generate individual configurations
     $rc = $this->exportVirtualHosts($db);
     if ($rc === false) {
         return false;
     }
     // Generate mpm-itk configuration (00-mpm-itk.conf)
     $rc = $this->saveConfigFile(Config::read('apache|directoryConfModulesD') . '/00-mpm-itk.conf', 'mpmitkconf', 'apache.tpl', $this->smarty);
     if ($rc === false) {
         return false;
     } else {
         return true;
     }
 }
 protected function createTemplate($class = null)
 {
     $template = $this->templateFactory->createTemplate($this);
     $template->groupList = $this->context->groups->getList();
     return $template;
 }
Exemple #9
0
 /**
  * Export configuration (/etc/postfix/ files)
  * @param DatabaseSqlite3 &$db Database object
  * @return boolean
  */
 public function exportConfiguration(&$db)
 {
     Log::debug('Export configuration: postfix');
     // Smarty template
     if ($this->smarty === null) {
         $this->smarty = TemplateFactory::create();
         if ($this->smarty === false) {
             return false;
         }
     }
     // Export virtual hosts
     $rc = $this->exportVirtualHosts($db);
     if ($rc === false) {
         return false;
     }
     // Set permissions
     chmod(Config::read('postfix|virtualDomainsFile'), 0640);
     // Assign variables
     $this->smarty->assignByRef('VHOSTS', $this->vhosts);
     $this->smarty->assign('CLAMAV', Config::read('clamav'));
     $this->smarty->assign('SPAMASSASSIN', Config::read('spamassassin'));
     $this->smarty->assign('OPENDKIM', Config::read('opendkim'));
     /*
      * The following part checks for the existence of:
      *
      * Perl implementation of policyd-spf which can be downloaded from:
      * https://launchpad.net/postfix-policyd-spf-perl/
      * (requires manual copy of the file under /usr/local/lib/policyd-spf-perl/)
      *
      * Python implementation of policyd-spf which can be installed
      * via the rpm package 'pypolicyd-spf'
      * (yum install pypolicyd-spf)
      *
      * Warning: the Perl implementation seems abandoned
      */
     if (is_file('/usr/local/lib/policyd-spf-perl/postfix-policyd-spf-perl')) {
         // Detected policyd-spf (perl)
         Log::debug('Detected: policyd-spf (perl)');
         // Assign variables
         $this->smarty->assign('SPFPERL', true);
         $this->smarty->assign('SPFPYTH', false);
     } elseif (is_file('/usr/libexec/postfix/policyd-spf')) {
         // Detected policyd-spf (python)
         Log::debug('Detected: policyd-spf (python)');
         // Assign variables
         $this->smarty->assign('SPFPERL', false);
         $this->smarty->assign('SPFPYTH', true);
     } else {
         // Assign variables
         $this->smarty->assign('SPFPERL', false);
         $this->smarty->assign('SPFPYTH', false);
     }
     // Generate smtp_header_checks
     $rc = $this->saveConfigFile(Config::read('postfix|postfixDirectory') . '/smtp_header_checks', 'smtpheaderchecks', 'postfix.tpl', $this->smarty);
     if ($rc === false) {
         return false;
     }
     // Generate main.cf
     $rc = $this->saveConfigFile(Config::read('postfix|postfixDirectory') . '/main.cf', 'maincf', 'postfix.tpl', $this->smarty);
     if ($rc === false) {
         return false;
     }
     // Generate master.cf
     $rc = $this->saveConfigFile(Config::read('postfix|postfixDirectory') . '/master.cf', 'mastercf', 'postfix.tpl', $this->smarty);
     if ($rc === false) {
         return false;
     } else {
         return true;
     }
 }
Exemple #10
0
 /**
  * Export configuration (/etc/nsd/nsd.conf)
  * @param DatabaseSqlite3 &$db Database object
  * @return boolean
  */
 public function exportConfiguration(&$db)
 {
     Log::debug('Export configuration: nsd');
     // Smarty template
     if ($this->smarty === null) {
         $this->smarty = TemplateFactory::create();
         if ($this->smarty === false) {
             return false;
         }
     }
     // Detect CPU count
     $cpucount = file_get_contents('/proc/cpuinfo');
     if ($cpucount === false) {
         Log::error('Error while detecting CPU count via /proc/cpuinfo');
         return false;
     }
     $cpucount = preg_match_all('/^processor/m', $cpucount);
     if ($cpucount === false || !is_numeric($cpucount) || $cpucount < 1) {
         $cpucount = 1;
     }
     // Assign variables
     $this->smarty->assignByRef('CPUCOUNT', $cpucount);
     // NSD daemon (nsd) configuration
     $rc = $this->saveConfigFile(Config::read('nsd|nsdConfFile'), 'nsdconf', 'nsd.tpl', $this->smarty);
     if ($rc === false) {
         return false;
     }
     // Generate conf+zone combo files for virtual hosts
     $rc = $this->exportVirtualHosts($db);
     if ($rc === false) {
         return false;
     } else {
         return true;
     }
 }
Exemple #11
0
Log::debug('Create css directory: ' . $cssDir);
$rc = mkdir($cssDir);
if ($rc === false) {
    Log::error('Error creating www/css directory: ' . $cssDir);
    exit(9);
}
// Create www/scripts directory
$scriptsDir = Config::read('pwd') . '/www/scripts';
Log::debug('Create scripts directory: ' . $scriptsDir);
$rc = mkdir($scriptsDir);
if ($rc === false) {
    Log::error('Error creating www/scripts directory: ' . $scriptsDir);
    exit(9);
}
// Load smarty
$smarty = TemplateFactory::create();
if ($smarty === false) {
    exit(9);
}
// Production (p,production)
if (Config::read('production') === 'true') {
    $smarty->assign('PRODUCTION', 'true');
} else {
    $smarty->assign('PRODUCTION', 'false');
}
Log::debug('Searching for css: ' . Config::read('pwd') . '/css');
if (Config::read('production') === 'true') {
    // Universal CSS file
    $uniFile = Config::read('pwd') . '/www/css/style.min.css';
    // Touch empty file
    $rc = file_put_contents($uniFile, '');
Exemple #12
0
 public function __construct()
 {
     $config = Config::getInstance('config')->all();
     $this->template = TemplateFactory::make($config['view'], $config['app_name']);
 }
Exemple #13
0
 /**
  * Export configuration (dovecot.conf and related conf.d/*.conf files)
  * @param DatabaseSqlite3 &$db Database object
  * @return boolean
  */
 public function exportConfiguration(&$db)
 {
     Log::debug('Export configuration: dovecot');
     // Smarty template
     if ($this->smarty === null) {
         $this->smarty = TemplateFactory::create();
         if ($this->smarty === false) {
             return false;
         }
     }
     // Required directories for virtual hosts
     if (!is_dir('/etc/dovecot/vhost')) {
         // Create vhost directory for storing passwd/shadow files
         $rc = mkdir('/etc/dovecot/vhost', 0700);
         if ($rc === false) {
             return false;
         }
     }
     // Generate dovecot.conf
     $rc = $this->saveConfigFile(Config::read('dovecot|confFile'), 'dovecotConf', 'dovecot.tpl', $this->smarty);
     if ($rc === false) {
         return false;
     }
     // Generate 10-auth.conf
     $rc = $this->saveConfigFile(Config::read('dovecot|directoryConfD') . '/10-auth.conf', '10authconf', 'dovecot.tpl', $this->smarty);
     if ($rc === false) {
         return false;
     }
     // Generate 10-mail.conf
     $rc = $this->saveConfigFile(Config::read('dovecot|directoryConfD') . '/10-mail.conf', '10mailconf', 'dovecot.tpl', $this->smarty);
     if ($rc === false) {
         return false;
     }
     // Generate 10-master.conf
     $rc = $this->saveConfigFile(Config::read('dovecot|directoryConfD') . '/10-master.conf', '10masterconf', 'dovecot.tpl', $this->smarty);
     if ($rc === false) {
         return false;
     }
     // Generate 10-ssl.conf and export virtual hosts
     $rc = $this->exportVirtualHosts($db);
     if ($rc === false) {
         return false;
     }
     // Generate 15-lda.conf
     $rc = $this->saveConfigFile(Config::read('dovecot|directoryConfD') . '/15-lda.conf', '15ldaconf', 'dovecot.tpl', $this->smarty);
     if ($rc === false) {
         return false;
     }
     // Generate 15-mailboxes.conf
     $rc = $this->saveConfigFile(Config::read('dovecot|directoryConfD') . '/15-mailboxes.conf', '15mailboxesconf', 'dovecot.tpl', $this->smarty);
     if ($rc === false) {
         return false;
     }
     // Generate 20-imap.conf
     $rc = $this->saveConfigFile(Config::read('dovecot|directoryConfD') . '/20-imap.conf', '20imapconf', 'dovecot.tpl', $this->smarty);
     if ($rc === false) {
         return false;
     }
     // Generate 20-pop3.conf
     $rc = $this->saveConfigFile(Config::read('dovecot|directoryConfD') . '/20-pop3.conf', '20pop3conf', 'dovecot.tpl', $this->smarty);
     if ($rc === false) {
         return false;
     }
     // Generate 90-acl.conf
     $rc = $this->saveConfigFile(Config::read('dovecot|directoryConfD') . '/90-acl.conf', '90aclconf', 'dovecot.tpl', $this->smarty);
     if ($rc === false) {
         return false;
     }
     // Generate 90-quota.conf
     $rc = $this->saveConfigFile(Config::read('dovecot|directoryConfD') . '/90-quota.conf', '90quotaconf', 'dovecot.tpl', $this->smarty);
     if ($rc === false) {
         return false;
     }
     // Generate auth-passwdfile.conf.ext
     $rc = $this->saveConfigFile(Config::read('dovecot|directoryConfD') . '/auth-passwdfile.conf.ext', 'authpasswdconfext', 'dovecot.tpl', $this->smarty);
     if ($rc === false) {
         return false;
     } else {
         return true;
     }
 }
Exemple #14
0
 /**
  * Enable Roundcube and restart the httpd service
  * @return void
  */
 function enable()
 {
     // Return if Roundcube, MariaDB or Dovecot are not enabled
     if (Config::read('roundcube') !== 'enabled' || Config::read('mariadb') !== 'enabled' || Config::read('dovecot') !== 'enabled') {
         Log::warning('Roundcube requires the following features to be enabled: mariadb, dovecot');
         Log::warning('Feature is not enabled: roundcube');
         return;
     }
     Log::debug('Enabling feature: roundcube');
     // Make sure there is a Roundcube configuration for Apache
     $cfgFile = Config::read('apache|directoryConfD') . '/roundcubemail.conf';
     if (!is_file($cfgFile)) {
         // Smarty template
         $smarty = TemplateFactory::create();
         if ($smarty === false) {
             return;
         }
         // Generate roundcubemail.conf
         $rc = $this->saveConfigFile(Config::read('apache|directoryConfD') . '/roundcubemail.conf', 'roundcubemailconf', 'roundcube.tpl', $smarty);
         if ($rc === false) {
             return false;
         }
     }
     // Reload Apache, if enabled
     if (Config::read('apache') === 'enabled') {
         $feature = new Apache();
         $feature->reload();
     }
 }
Exemple #15
0
 /**
  * Export configuration (/etc/clamd.d/clamd.conf, /etc/freshclam.conf, /etc/mail/clamav-milter.conf)
  * @param DatabaseSqlite3 &$db Database object
  * @return boolean
  */
 public function exportConfiguration(&$db)
 {
     Log::debug('Export configuration: clamav');
     // Smarty template
     $smarty = TemplateFactory::create();
     if ($smarty === false) {
         return false;
     }
     // ClamAV daemon (clamd, provided by clamav-server)
     // Find the default clamd.conf
     $clamdconfFile = exec('/usr/bin/find /usr/share/doc/ -iname clamd.conf');
     if ($clamdconfFile === '') {
         Log::error('Error while searching for: clamd.conf');
         return false;
     }
     // Load custom changes from template
     $smartyTpl = base64_encode('{block name=clamdconf}{/block}');
     $params = explode("\n", $smarty->fetch('extends:string:base64:' . $smartyTpl . '|clamav.tpl'));
     // Load the clamd.conf file into memory
     $conf = file_get_contents($clamdconfFile);
     if ($conf === false) {
         Log::error('Error while loading file: ' . $clamdconfFile);
         return false;
     }
     // Loop each parameter
     foreach ($params as $p) {
         // Trim input
         $p = trim($p);
         // Skip empty and/or invalid lines
         if ($p == '') {
             continue;
         }
         $p = explode(' ', $p, 2);
         $rc = $this->_setConfParameter($conf, $p[0], $p[1]);
         if ($rc === false) {
             return false;
         }
     }
     // Remove line to enable execution of clamd
     $conf = str_replace("\nExample\n", '', $conf);
     // Save file
     Log::debug('Writing to file: ' . Config::read('clamav|clamdConfFile'));
     $rc = file_put_contents(Config::read('clamav|clamdConfFile'), $conf, LOCK_EX);
     if ($rc === false) {
         Log::error('Error while writing to file: ' . Config::read('clamav|clamdConfFile'));
         return false;
     }
     // ClamAV daemon sysconfig file
     $rc = $this->saveConfigFile(Config::read('clamav|clamdSysconfigFile'), 'clamdsysconfig', 'clamav.tpl', $smarty);
     if ($rc === false) {
         return false;
     }
     // Assign variables
     $smarty->assign('CLAMDCONFFILE', Config::read('clamav|clamdConfFile'));
     // ClamAV daemon systemd service
     $rc = $this->saveConfigFile(Config::read('clamav|clamdSystemdFile'), 'clamdsystemd', 'clamav.tpl', $smarty);
     if ($rc === false) {
         return false;
     }
     // ClamAV tmpfiles configuration
     $rc = $this->saveConfigFile(Config::read('clamav|clamdTmpfilesFile'), 'clamdtmpfiles', 'clamav.tpl', $smarty);
     if ($rc === false) {
         return false;
     }
     // ClamAV updater (freshclam)
     $freshclam = file_get_contents('/etc/sysconfig/freshclam');
     if ($freshclam === false) {
         Log::error('Error while loading file: /etc/sysconfig/freshclam');
         return false;
     }
     // Remove line to enable freshclam network access
     $freshclam = str_replace('FRESHCLAM_DELAY=disabled-warn', '', $freshclam);
     // Save file
     Log::debug('Writing to file: /etc/sysconfig/freshclam');
     $rc = file_put_contents('/etc/sysconfig/freshclam', $freshclam);
     if ($rc === false) {
         Log::error('Error while writing to file: /etc/sysconfig/freshclam');
         return false;
     }
     // ClamAV updater (freshclam.conf)
     $freshclam = file_get_contents('/etc/freshclam.conf');
     if ($freshclam === false) {
         Log::error('Error while loading file: /etc/freshclam.conf');
         return false;
     }
     // Remove line to enable execution of freshclam
     $freshclam = str_replace("\nExample\n", '', $freshclam);
     // Save file
     Log::debug('Writing to file: /etc/freshclam.conf');
     $rc = file_put_contents('/etc/freshclam.conf', $freshclam);
     if ($rc === false) {
         Log::error('Error while writing to file: /etc/freshclam.conf');
         return false;
     }
     // ClamAV milter
     $rc = $this->saveConfigFile(Config::read('clamav|clamavMilterFile'), 'clamavmilter', 'clamav.tpl', $smarty);
     if ($rc === false) {
         return false;
     }
     // ClamAV milter tmpfiles configuration
     $rc = $this->saveConfigFile(Config::read('clamav|clamavMilterTmp'), 'clamavmiltertmp', 'clamav.tpl', $smarty);
     if ($rc === false) {
         return false;
     }
     // Group 'postfix' ownership of clamav-milter socket
     chmod('/var/run/clamav-milter', 0711);
     // @TODO As of 2015, there is a bug in clamav-milter which prevents it from setting the correct group ownership to 'postfix'. If we tried to use the the configuration parameter MilterSocketGroup, then the service would die and fail to start because it has already dropped root priviledges. In other distributions we could use the /etc/default/clamav-milter file to set the variable SOCKET_RWGROUP, but this does not seem to work in CentOS 7. As a result, we run a world-writable socket (for now).
     $rc = $this->saveConfigFile('/etc/default/clamav-milter', 'defaultclamavmilter', 'clamav.tpl', $smarty);
     if ($rc === false) {
         return false;
     } else {
         return true;
     }
 }