本文整理汇总了PHP中tpl::grab方法的典型用法代码示例。如果您正苦于以下问题:PHP tpl::grab方法的具体用法?PHP tpl::grab怎么用?PHP tpl::grab使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tpl
的用法示例。
在下文中一共展示了tpl::grab方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: show
function show()
{
global $app, $conf;
//* Loading Template
$app->uses('tpl');
$tpl = new tpl();
$tpl->newTemplate("dashlets/templates/modules.htm");
$wb = array();
$lng_file = 'lib/lang/' . $_SESSION['s']['language'] . '_dashlet_modules.lng';
if (is_file($lng_file)) {
include $lng_file;
}
$tpl->setVar($wb);
/*
* Show all modules, the user is allowed to use
*/
$modules = explode(',', $_SESSION['s']['user']['modules']);
$mod = array();
if (is_array($modules)) {
foreach ($modules as $mt) {
if (is_file('../' . $mt . '/lib/module.conf.php')) {
if (!preg_match("/^[a-z]{2,20}\$/i", $mt)) {
die('module name contains unallowed chars.');
}
include_once '../' . $mt . '/lib/module.conf.php';
/* We don't want to show the dashboard */
if ($mt != 'dashboard') {
$module_title = $app->lng($module['title']);
if (function_exists('mb_strlen')) {
if (mb_strlen($module_title, "UTF-8") > 8) {
$module_title = mb_substr($module_title, 0, 7, "UTF-8") . '..';
}
} else {
if (strlen($module_title) > 8) {
$module_title = substr($module_title, 0, 7) . '..';
}
}
$mod[] = array('modules_title' => $module_title, 'modules_startpage' => $module['startpage'], 'modules_name' => $module['name']);
}
}
}
$tpl->setloop('modules', $mod);
}
return $tpl->grab();
}
示例2: update
function update($event_name, $data)
{
global $app, $conf;
$domains = $this->_getSquidDomains($app);
$rules = $this->_getSquidRewriteRules($app);
$app->load('tpl');
$tpl = new tpl();
$tpl->newTemplate("squidRewriteRules.py.master");
if (!empty($rules)) {
$tpl->setLoop('squid_rewrite_rules', $rules);
}
file_put_contents('/etc/squid/squidRewriteRules.py', $tpl->grab());
unset($tpl);
$app->log('Writing squid rewrite configuration to /etc/squid/squidRewriteRules.py', LOGLEVEL_DEBUG);
$tpl = new tpl();
$tpl->newTemplate("domains.txt.master");
$tpl->setLoop('squid_domains', $domains);
file_put_contents('/etc/squid/domains.txt', $tpl->grab());
unset($tpl);
$app->log('Writing squid domains configuration to /etc/squid/domains.txt', LOGLEVEL_DEBUG);
// request a httpd reload when all records have been processed
$app->services->restartServiceDelayed('squid', 'restart');
}
示例3: configure_apache
public function configure_apache()
{
global $conf;
if ($conf['apache']['installed'] == false) {
return;
}
//* Create the logging directory for the vhost logfiles
if (!is_dir($conf['ispconfig_log_dir'] . '/httpd')) {
mkdir($conf['ispconfig_log_dir'] . '/httpd', 0755, true);
}
if (is_file($conf['suphp']['config_file'])) {
$content = rf($conf['suphp']['config_file']);
if (!preg_match('|^x-httpd-suphp=php:/usr/bin/php-cgi$|m', $content)) {
$content = preg_replace('/;Handler for php-scripts/', ";Handler for php-scripts\nx-httpd-suphp=php:/usr/bin/php-cgi", $content);
$content = preg_replace('/;?umask=\\d+/', 'umask=0022', $content);
}
$this->write_config_file($conf['suphp']['config_file'], $content);
}
//* Enable ISPConfig default vhost settings
$default_vhost_path = $conf['apache']['vhost_conf_dir'] . '/' . $conf['apache']['vhost_default'];
if (is_file($default_vhost_path)) {
$content = rf($default_vhost_path);
$content = preg_replace('/^#?\\s*NameVirtualHost.*$/m', 'NameVirtualHost *:80', $content);
$content = preg_replace('/<VirtualHost[^>]+>/', '<VirtualHost *:80>', $content);
$this->write_config_file($default_vhost_path, $content);
}
//* Generate default ssl certificates
if (!is_dir($conf['apache']['ssl_dir'])) {
mkdir($conf['apache']['ssl_dir']);
}
if ($conf['services']['mail'] == true) {
copy($conf['postfix']['config_dir'] . "/smtpd.key", $conf['apache']['ssl_dir'] . "/server.key");
copy($conf['postfix']['config_dir'] . "/smtpd.cert", $conf['apache']['ssl_dir'] . "/server.crt");
} else {
if (!is_file($conf['apache']['ssl_dir'] . '/server.crt')) {
exec("openssl req -new -outform PEM -out {$conf['apache']['ssl_dir']}/server.crt -newkey rsa:2048 -nodes -keyout {$conf['apache']['ssl_dir']}/server.key -keyform PEM -days 365 -x509");
}
}
//* Copy the ISPConfig configuration include
/*
$content = $this->get_template_file('apache_ispconfig.conf', true);
$records = $this->db->queryAllRecords("SELECT * FROM server_ip WHERE server_id = ".$conf["server_id"]." AND virtualhost = 'y'");
if(is_array($records) && count($records) > 0)
{
foreach($records as $rec) {
$content .= "NameVirtualHost ".$rec["ip_address"].":80\n";
$content .= "NameVirtualHost ".$rec["ip_address"].":443\n";
}
}
$this->write_config_file($conf['apache']['vhost_conf_dir'].'/000-ispconfig.conf', $content);
*/
$tpl = new tpl('apache_ispconfig.conf.master');
$tpl->setVar('apache_version', getapacheversion());
$records = $this->db->queryAllRecords('SELECT * FROM ' . $conf['mysql']['master_database'] . '.server_ip WHERE server_id = ' . $conf['server_id'] . " AND virtualhost = 'y'");
$ip_addresses = array();
if (is_array($records) && count($records) > 0) {
foreach ($records as $rec) {
if ($rec['ip_type'] == 'IPv6') {
$ip_address = '[' . $rec['ip_address'] . ']';
} else {
$ip_address = $rec['ip_address'];
}
$ports = explode(',', $rec['virtualhost_port']);
if (is_array($ports)) {
foreach ($ports as $port) {
$port = intval($port);
if ($port > 0 && $port < 65536 && $ip_address != '') {
$ip_addresses[] = array('ip_address' => $ip_address, 'port' => $port);
}
}
}
}
}
if (count($ip_addresses) > 0) {
$tpl->setLoop('ip_adresses', $ip_addresses);
}
wf($conf['apache']['vhost_conf_dir'] . '/000-ispconfig.conf', $tpl->grab());
unset($tpl);
//* Gentoo by default does not include .vhost files. Add include line to config file.
$content = rf($conf['apache']['config_file']);
if (strpos($content, 'Include /etc/apache2/vhosts.d/*.vhost') === false) {
$content = preg_replace('|(Include /etc/apache2/vhosts.d/\\*.conf)|', "\$1\nInclude /etc/apache2/vhosts.d/*.vhost", $content);
}
$this->write_config_file($conf['apache']['config_file'], $content);
//* make sure that webalizer finds its config file when it is directly in /etc
if (is_file('/etc/webalizer.conf') && !is_dir('/etc/webalizer')) {
mkdir('/etc/webalizer', 0755);
symlink('/etc/webalizer.conf', '/etc/webalizer/webalizer.conf');
}
if (is_file('/etc/webalizer/webalizer.conf')) {
replaceLine('/etc/webalizer/webalizer.conf', '#IncrementalName', 'IncrementalName webalizer.current', 0, 0);
replaceLine('/etc/webalizer/webalizer.conf', '#Incremental', 'Incremental yes', 0, 0);
replaceLine('/etc/webalizer/webalizer.conf', '#HistoryName', 'HistoryName webalizer.hist', 0, 0);
}
//* add a sshusers group
if (!is_group('sshusers')) {
$command = 'groupadd sshusers';
caselog($command . ' &> /dev/null 2> /dev/null', __FILE__, __LINE__, "EXECUTED: {$command}", "Failed to execute the command {$command}");
//.........这里部分代码省略.........
示例4: show
//.........这里部分代码省略.........
$tpl->newTemplate("dashlets/templates/quota.htm");
$wb = array();
$lng_file = 'lib/lang/' . $_SESSION['s']['language'] . '_dashlet_quota.lng';
if (is_file($lng_file)) {
include $lng_file;
}
$tpl->setVar($wb);
$tmp_rec = $app->db->queryAllRecords("SELECT data from monitor_data WHERE type = 'harddisk_quota' ORDER BY created DESC");
$monitor_data = array();
if (is_array($tmp_rec)) {
foreach ($tmp_rec as $tmp_mon) {
$monitor_data = array_merge_recursive($monitor_data, unserialize($app->db->unquote($tmp_mon['data'])));
}
}
//print_r($monitor_data);
if ($_SESSION["s"]["user"]["typ"] != 'admin') {
$sql_where = " AND sys_groupid = " . $app->functions->intval($_SESSION['s']['user']['default_group']);
}
$has_quota = false;
// select websites belonging to client
$sites = $app->db->queryAllRecords("SELECT * FROM web_domain WHERE active = 'y' AND type = 'vhost'" . $sql_where);
//print_r($sites);
if (is_array($sites) && !empty($sites)) {
for ($i = 0; $i < sizeof($sites); $i++) {
$username = $sites[$i]['system_user'];
$sites[$i]['used'] = $monitor_data['user'][$username]['used'];
$sites[$i]['soft'] = $monitor_data['user'][$username]['soft'];
$sites[$i]['hard'] = $monitor_data['user'][$username]['hard'];
$sites[$i]['files'] = $monitor_data['user'][$username]['files'];
if (!is_numeric($sites[$i]['used'])) {
if ($sites[$i]['used'][0] > $sites[$i]['used'][1]) {
$sites[$i]['used'] = $sites[$i]['used'][0];
} else {
$sites[$i]['used'] = $sites[$i]['used'][1];
}
}
if (!is_numeric($sites[$i]['soft'])) {
$sites[$i]['soft'] = $sites[$i]['soft'][1];
}
if (!is_numeric($sites[$i]['hard'])) {
$sites[$i]['hard'] = $sites[$i]['hard'][1];
}
if (!is_numeric($sites[$i]['files'])) {
$sites[$i]['files'] = $sites[$i]['files'][1];
}
// colours
$sites[$i]['display_colour'] = '#000000';
if ($sites[$i]['soft'] > 0) {
$used_ratio = $sites[$i]['used'] / $sites[$i]['soft'];
} else {
$used_ratio = 0;
}
if ($used_ratio >= 0.8) {
$sites[$i]['display_colour'] = '#fd934f';
}
if ($used_ratio >= 1) {
$sites[$i]['display_colour'] = '#cc0000';
}
if ($sites[$i]['used'] > 1024) {
$sites[$i]['used'] = round($sites[$i]['used'] / 1024, 2) . ' MB';
} else {
if ($sites[$i]['used'] != '') {
$sites[$i]['used'] .= ' KB';
}
}
if ($sites[$i]['soft'] > 1024) {
$sites[$i]['soft'] = round($sites[$i]['soft'] / 1024, 2) . ' MB';
} else {
$sites[$i]['soft'] .= ' KB';
}
if ($sites[$i]['hard'] > 1024) {
$sites[$i]['hard'] = round($sites[$i]['hard'] / 1024, 2) . ' MB';
} else {
$sites[$i]['hard'] .= ' KB';
}
if ($sites[$i]['soft'] == " KB") {
$sites[$i]['soft'] = $app->lng('unlimited');
}
if ($sites[$i]['hard'] == " KB") {
$sites[$i]['hard'] = $app->lng('unlimited');
}
/*
if(!strstr($sites[$i]['used'],'M') && !strstr($sites[$i]['used'],'K')) $sites[$i]['used'].= ' B';
if(!strstr($sites[$i]['soft'],'M') && !strstr($sites[$i]['soft'],'K')) $sites[$i]['soft'].= ' B';
if(!strstr($sites[$i]['hard'],'M') && !strstr($sites[$i]['hard'],'K')) $sites[$i]['hard'].= ' B';
*/
if ($sites[$i]['soft'] == '0 B' || $sites[$i]['soft'] == '0 KB' || $sites[$i]['soft'] == '0') {
$sites[$i]['soft'] = $app->lng('unlimited');
}
if ($sites[$i]['hard'] == '0 B' || $sites[$i]['hard'] == '0 KB' || $sites[$i]['hard'] == '0') {
$sites[$i]['hard'] = $app->lng('unlimited');
}
}
$has_quota = true;
$tpl->setloop('quota', $sites);
}
//print_r($sites);
$tpl->setVar('has_quota', $has_quota);
return $tpl->grab();
}
示例5: show
function show()
{
global $app, $conf;
$limits = array();
/* Limits to be shown*/
$limits[] = array('field' => 'limit_maildomain', 'db_table' => 'mail_domain', 'db_where' => '');
$limits[] = array('field' => 'limit_mailmailinglist', 'db_table' => 'mail_mailinglist', 'db_where' => '');
$limits[] = array('field' => 'limit_mailbox', 'db_table' => 'mail_user', 'db_where' => '');
$limits[] = array('field' => 'limit_mailalias', 'db_table' => 'mail_forwarding', 'db_where' => "type = 'alias'");
$limits[] = array('field' => 'limit_mailaliasdomain', 'db_table' => 'mail_forwarding', 'db_where' => "type = 'aliasdomain'");
$limits[] = array('field' => 'limit_mailforward', 'db_table' => 'mail_forwarding', 'db_where' => "type = 'forward'");
$limits[] = array('field' => 'limit_mailcatchall', 'db_table' => 'mail_forwarding', 'db_where' => "type = 'catchall'");
$limits[] = array('field' => 'limit_mailrouting', 'db_table' => 'mail_transport', 'db_where' => "");
$limits[] = array('field' => 'limit_mailfilter', 'db_table' => 'mail_user_filter', 'db_where' => "");
$limits[] = array('field' => 'limit_fetchmail', 'db_table' => 'mail_get', 'db_where' => "");
$limits[] = array('field' => 'limit_spamfilter_wblist', 'db_table' => 'spamfilter_wblist', 'db_where' => "");
$limits[] = array('field' => 'limit_spamfilter_user', 'db_table' => 'spamfilter_users', 'db_where' => "");
$limits[] = array('field' => 'limit_spamfilter_policy', 'db_table' => 'spamfilter_policy', 'db_where' => "");
$limits[] = array('field' => 'limit_web_domain', 'db_table' => 'web_domain', 'db_where' => "type = 'vhost'");
$limits[] = array('field' => 'limit_web_subdomain', 'db_table' => 'web_domain', 'db_where' => "(type = 'subdomain' OR type = 'vhostsubdomain')");
$limits[] = array('field' => 'limit_web_aliasdomain', 'db_table' => 'web_domain', 'db_where' => "type = 'alias'");
$limits[] = array('field' => 'limit_ftp_user', 'db_table' => 'ftp_user', 'db_where' => "");
$limits[] = array('field' => 'limit_shell_user', 'db_table' => 'shell_user', 'db_where' => "");
$limits[] = array('field' => 'limit_dns_zone', 'db_table' => 'dns_soa', 'db_where' => "");
$limits[] = array('field' => 'limit_dns_slave_zone', 'db_table' => 'dns_slave', 'db_where' => "");
$limits[] = array('field' => 'limit_dns_record', 'db_table' => 'dns_rr', 'db_where' => "");
$limits[] = array('field' => 'limit_database', 'db_table' => 'web_database', 'db_where' => "");
$limits[] = array('field' => 'limit_cron', 'db_table' => 'cron', 'db_where' => "");
$limits[] = array('field' => 'limit_client', 'db_table' => 'client', 'db_where' => "");
//* Loading Template
$app->uses('tpl,tform');
$tpl = new tpl();
$tpl->newTemplate("dashlets/templates/limits.htm");
$wb = array();
$lng_file = 'lib/lang/' . $_SESSION['s']['language'] . '_dashlet_limits.lng';
if (is_file($lng_file)) {
include $lng_file;
}
$tpl->setVar($wb);
if ($app->auth->is_admin()) {
$user_is_admin = true;
} else {
$user_is_admin = false;
}
$tpl->setVar('is_admin', $user_is_admin);
if ($user_is_admin == false) {
$client_group_id = $_SESSION["s"]["user"]["default_group"];
$client = $app->db->queryOneRecord("SELECT * FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = {$client_group_id}");
}
$rows = array();
foreach ($limits as $limit) {
$field = $limit['field'];
if ($user_is_admin) {
$value = $wb['unlimited_txt'];
} else {
$value = $client[$field];
}
if ($value != 0 || $value == $wb['unlimited_txt']) {
$value_formatted = $value == '-1' ? $wb['unlimited_txt'] : $value;
$rows[] = array('field' => $field, 'field_txt' => $wb[$field . '_txt'], 'value' => $value_formatted, 'usage' => $this->_get_limit_usage($limit));
}
}
$tpl->setLoop('rows', $rows);
return $tpl->grab();
}
示例6: install_ispconfig
//.........这里部分代码省略.........
caselog($command . ' &> /dev/null', __FILE__, __LINE__, "EXECUTED: {$command}", "Failed to execute the command {$command}");
if (is_group('ispapps')) {
$command = 'adduser ' . $conf['nginx']['user'] . ' ispapps';
caselog($command . ' &> /dev/null', __FILE__, __LINE__, "EXECUTED: {$command}", "Failed to execute the command {$command}");
}
}
//* Make the shell scripts executable
$command = "chmod +x {$install_dir}/server/scripts/*.sh";
caselog($command . ' &> /dev/null', __FILE__, __LINE__, "EXECUTED: {$command}", "Failed to execute the command {$command}");
if ($conf['apache']['installed'] == true && $this->install_ispconfig_interface == true) {
//* Copy the ISPConfig vhost for the controlpanel
$vhost_conf_dir = $conf['apache']['vhost_conf_dir'];
$vhost_conf_enabled_dir = $conf['apache']['vhost_conf_enabled_dir'];
// Dont just copy over the virtualhost template but add some custom settings
$tpl = new tpl('apache_ispconfig.vhost.master');
$tpl->setVar('vhost_port', $conf['apache']['vhost_port']);
// comment out the listen directive if port is 80 or 8443
if ($conf['apache']['vhost_port'] == 80 or $conf['apache']['vhost_port'] == 8443) {
$tpl->setVar('vhost_port_listen', '#');
} else {
$tpl->setVar('vhost_port_listen', '');
}
if (is_file($install_dir . '/interface/ssl/ispserver.crt') && is_file($install_dir . '/interface/ssl/ispserver.key')) {
$tpl->setVar('ssl_comment', '');
} else {
$tpl->setVar('ssl_comment', '#');
}
if (is_file($install_dir . '/interface/ssl/ispserver.crt') && is_file($install_dir . '/interface/ssl/ispserver.key') && is_file($install_dir . '/interface/ssl/ispserver.bundle')) {
$tpl->setVar('ssl_bundle_comment', '');
} else {
$tpl->setVar('ssl_bundle_comment', '#');
}
$tpl->setVar('apache_version', getapacheversion());
wf($vhost_conf_dir . '/ispconfig.vhost', $tpl->grab());
//* and create the symlink
if ($this->is_update == false) {
if (@is_link($vhost_conf_enabled_dir . '/ispconfig.vhost')) {
unlink($vhost_conf_enabled_dir . '/ispconfig.vhost');
}
if (!@is_link($vhost_conf_enabled_dir . '/000-ispconfig.vhost')) {
symlink($vhost_conf_dir . '/ispconfig.vhost', $vhost_conf_enabled_dir . '/000-ispconfig.vhost');
}
}
//if(!is_file('/home/www/php-fcgi-scripts/ispconfig/.php-fcgi-starter')) {
$content = rfsel($conf['ispconfig_install_dir'] . '/server/conf-custom/install/apache_ispconfig_fcgi_starter.master', 'tpl/apache_ispconfig_fcgi_starter.master');
$content = str_replace('{fastcgi_bin}', $conf['fastcgi']['fastcgi_bin'], $content);
$content = str_replace('{fastcgi_phpini_path}', $conf['fastcgi']['fastcgi_phpini_path'], $content);
@mkdir('/home/www/php-fcgi-scripts/ispconfig', 0755, true);
wf('/home/www/php-fcgi-scripts/ispconfig/.php-fcgi-starter', $content);
exec('chmod +x /home/www/php-fcgi-scripts/ispconfig/.php-fcgi-starter');
@symlink($install_dir . '/interface/web', '/home/www/ispconfig');
exec('chown -R ispconfig:ispconfig /home/www/php-fcgi-scripts/ispconfig');
//}
}
if ($conf['nginx']['installed'] == true && $this->install_ispconfig_interface == true) {
//* Copy the ISPConfig vhost for the controlpanel
$vhost_conf_dir = $conf['nginx']['vhost_conf_dir'];
$vhost_conf_enabled_dir = $conf['nginx']['vhost_conf_enabled_dir'];
// Dont just copy over the virtualhost template but add some custom settings
$content = rfsel($conf['ispconfig_install_dir'] . '/server/conf-custom/install/nginx_ispconfig.vhost.master', 'tpl/nginx_ispconfig.vhost.master');
$content = str_replace('{vhost_port}', $conf['nginx']['vhost_port'], $content);
if (is_file($install_dir . '/interface/ssl/ispserver.crt') && is_file($install_dir . '/interface/ssl/ispserver.key')) {
$content = str_replace('{ssl_on}', 'on', $content);
$content = str_replace('{ssl_comment}', '', $content);
$content = str_replace('{fastcgi_ssl}', 'on', $content);
} else {
示例7: php_fpm_pool_update
//.........这里部分代码省略.........
$tpl->setVar('pm', $data['new']['pm']);
$tpl->setVar('pm_max_children', $data['new']['pm_max_children']);
$tpl->setVar('pm_start_servers', $data['new']['pm_start_servers']);
$tpl->setVar('pm_min_spare_servers', $data['new']['pm_min_spare_servers']);
$tpl->setVar('pm_max_spare_servers', $data['new']['pm_max_spare_servers']);
$tpl->setVar('pm_process_idle_timeout', $data['new']['pm_process_idle_timeout']);
$tpl->setVar('pm_max_requests', $data['new']['pm_max_requests']);
$tpl->setVar('document_root', $data['new']['document_root']);
$tpl->setVar('security_level', $web_config['security_level']);
$tpl->setVar('domain', $data['new']['domain']);
$php_open_basedir = $data['new']['php_open_basedir'] == '' ? escapeshellcmd($data['new']['document_root']) : escapeshellcmd($data['new']['php_open_basedir']);
$tpl->setVar('php_open_basedir', $php_open_basedir);
if ($php_open_basedir != '') {
$tpl->setVar('enable_php_open_basedir', '');
} else {
$tpl->setVar('enable_php_open_basedir', ';');
}
// Custom php.ini settings
$final_php_ini_settings = array();
$custom_php_ini_settings = trim($data['new']['custom_php_ini']);
if ($custom_php_ini_settings != '') {
// Make sure we only have Unix linebreaks
$custom_php_ini_settings = str_replace("\r\n", "\n", $custom_php_ini_settings);
$custom_php_ini_settings = str_replace("\r", "\n", $custom_php_ini_settings);
$ini_settings = explode("\n", $custom_php_ini_settings);
if (is_array($ini_settings) && !empty($ini_settings)) {
foreach ($ini_settings as $ini_setting) {
$ini_setting = trim($ini_setting);
if (substr($ini_setting, 0, 1) == ';') {
continue;
}
if (substr($ini_setting, 0, 1) == '#') {
continue;
}
if (substr($ini_setting, 0, 2) == '//') {
continue;
}
list($key, $value) = explode('=', $ini_setting, 2);
$value = trim($value);
if ($value != '') {
$key = trim($key);
switch (strtolower($value)) {
case '0':
// PHP-FPM might complain about invalid boolean value if you use 0
$value = 'off';
case '1':
case 'on':
case 'off':
case 'true':
case 'false':
case 'yes':
case 'no':
$final_php_ini_settings[] = array('ini_setting' => 'php_admin_flag[' . $key . '] = ' . $value);
break;
default:
$final_php_ini_settings[] = array('ini_setting' => 'php_admin_value[' . $key . '] = ' . $value);
}
}
}
}
}
$tpl->setLoop('custom_php_ini_settings', $final_php_ini_settings);
$app->system->file_put_contents($pool_dir . $pool_name . '.conf', $tpl->grab());
$app->log('Writing the PHP-FPM config file: ' . $pool_dir . $pool_name . '.conf', LOGLEVEL_DEBUG);
unset($tpl);
// delete pool in all other PHP versions
$default_pool_dir = escapeshellcmd($web_config['php_fpm_pool_dir']);
if (substr($default_pool_dir, -1) != '/') {
$default_pool_dir .= '/';
}
if ($default_pool_dir != $pool_dir) {
if (@is_file($default_pool_dir . $pool_name . '.conf')) {
$app->system->unlink($default_pool_dir . $pool_name . '.conf');
$app->log('Removed PHP-FPM config file: ' . $default_pool_dir . $pool_name . '.conf', LOGLEVEL_DEBUG);
$app->services->restartService('php-fpm', 'reload:' . $conf['init_scripts'] . '/' . $web_config['php_fpm_init_script']);
}
}
$php_versions = $app->db->queryAllRecords("SELECT * FROM server_php WHERE php_fpm_init_script != '' AND php_fpm_ini_dir != '' AND php_fpm_pool_dir != '' AND server_id = " . $conf["server_id"]);
if (is_array($php_versions) && !empty($php_versions)) {
foreach ($php_versions as $php_version) {
if (substr($php_version['php_fpm_pool_dir'], -1) != '/') {
$php_version['php_fpm_pool_dir'] .= '/';
}
if ($php_version['php_fpm_pool_dir'] != $pool_dir) {
if (@is_file($php_version['php_fpm_pool_dir'] . $pool_name . '.conf')) {
$app->system->unlink($php_version['php_fpm_pool_dir'] . $pool_name . '.conf');
$app->log('Removed PHP-FPM config file: ' . $php_version['php_fpm_pool_dir'] . $pool_name . '.conf', LOGLEVEL_DEBUG);
$app->services->restartService('php-fpm', 'reload:' . $php_version['php_fpm_init_script']);
}
}
}
}
// Reload current PHP-FPM after all others
sleep(1);
if (!$default_php_fpm) {
$app->services->restartService('php-fpm', 'reload:' . $custom_php_fpm_init_script);
} else {
$app->services->restartService('php-fpm', 'reload:' . $conf['init_scripts'] . '/' . $web_config['php_fpm_init_script']);
}
}
示例8: update
function update($event_name, $data)
{
global $app, $conf;
/*
* If $action is not 'insert', let's set it to update
*/
if ($this->action != 'insert') {
$this->action = 'update';
}
/*
* load the server configuration options
*/
$app->uses('getconf');
$web_config = $app->getconf->get_server_config($conf['server_id'], 'web');
/*
* We load the global template engine
*/
$app->load('tpl');
/*
* Create a new template and choose which master template to take
* the file is located within /usr/local/ispconfig/server/conf/
*/
$tpl = new tpl();
$tpl->newTemplate('apache2_userdir_plugin.conf.master');
/*
* Write some values from the array to single variables
*/
$vhost_data = $data['new'];
/*
* To have a better overview we split our update function into several parts,
* for sites, aliases and subdomains
* -> vhost
*/
if ($data['new']['type'] == 'vhost') {
/*
* We have collected all data in the $vhost_data array
* so we can pass it to the template engine
*/
$tpl->setVar($vhost_data);
/*
* if this is an 'insert', we have to create the vhost file
*/
if ($this->action == 'insert') {
$this->vhost('insert', $data, $tpl->grab());
}
/*
* if this is an 'update', we have to update the vhost file
*/
if ($this->action == 'update') {
$vhost_backup = $this->vhost('update', $data, $tpl->grab());
}
}
/*
* reload the apache2 webserver to apply changes
*/
$app->services->restartServiceDelayed('httpd', 'reload');
/*
* everything went hopefully well, so we can now
* delete the vhosts backup
*/
if (isset($vhost_backup)) {
unlink($vhost_backup['file_new'] . '~');
}
unset($vhost_backup);
/*
* Unset 'action' to clean it for next processed vhost
*/
$this->action = '';
}
示例9: escapeshellcmd
function _setup_jailkit_chroot()
{
global $app;
//check if the chroot environment is created yet if not create it with a list of program sections from the config
if (!is_dir($this->parent_domain['document_root'] . '/etc/jailkit')) {
$command = '/usr/local/ispconfig/server/scripts/create_jailkit_chroot.sh';
$command .= ' ' . escapeshellcmd($this->parent_domain['document_root']);
$command .= ' \'' . $this->jailkit_config['jailkit_chroot_app_sections'] . '\'';
exec($command . ' 2>/dev/null');
$this->app->log("Added jailkit chroot with command: " . $command, LOGLEVEL_DEBUG);
//$this->_add_jailkit_programs(); // done later on
$this->app->load('tpl');
$tpl = new tpl();
$tpl->newTemplate("bash.bashrc.master");
$tpl->setVar('jailkit_chroot', true);
$tpl->setVar('domain', $this->parent_domain['domain']);
$tpl->setVar('home_dir', $this->_get_home_dir(""));
$bashrc = escapeshellcmd($this->parent_domain['document_root']) . '/etc/bash.bashrc';
if (@is_file($bashrc) || @is_link($bashrc)) {
unlink($bashrc);
}
$app->system->file_put_contents($bashrc, $tpl->grab());
unset($tpl);
$this->app->log('Added bashrc script: ' . $bashrc, LOGLEVEL_DEBUG);
$tpl = new tpl();
$tpl->newTemplate('motd.master');
$tpl->setVar('domain', $this->parent_domain['domain']);
$motd = escapeshellcmd($this->parent_domain['document_root']) . '/var/run/motd';
if (@is_file($motd) || @is_link($motd)) {
unlink($motd);
}
$app->system->file_put_contents($motd, $tpl->grab());
}
$this->_add_jailkit_programs();
}
示例10: php_fpm_pool_update
private function php_fpm_pool_update($data, $web_config, $pool_dir, $pool_name, $socket_dir)
{
global $app, $conf;
//$reload = false;
if ($data['new']['php'] == 'no') {
if (@is_file($pool_dir . $pool_name . '.conf')) {
unlink($pool_dir . $pool_name . '.conf');
//$reload = true;
}
//if($reload == true) $app->services->restartService('php-fpm','reload');
return;
}
$app->uses("getconf");
$web_config = $app->getconf->get_server_config($conf["server_id"], 'web');
$app->load('tpl');
$tpl = new tpl();
$tpl->newTemplate('php_fpm_pool.conf.master');
if ($data['new']['php_fpm_use_socket'] == 'y') {
$use_tcp = 0;
$use_socket = 1;
if (!is_dir($socket_dir)) {
exec('mkdir -p ' . $socket_dir);
}
} else {
$use_tcp = 1;
$use_socket = 0;
}
$tpl->setVar('use_tcp', $use_tcp);
$tpl->setVar('use_socket', $use_socket);
$fpm_socket = $socket_dir . $pool_name . '.sock';
$tpl->setVar('fpm_socket', $fpm_socket);
$tpl->setVar('fpm_pool', $pool_name);
$tpl->setVar('fpm_port', $web_config['php_fpm_start_port'] + $data['new']['domain_id'] - 1);
$tpl->setVar('fpm_user', $data['new']['system_user']);
$tpl->setVar('fpm_group', $data['new']['system_group']);
$tpl->setVar('pm_max_children', $data['new']['pm_max_children']);
$tpl->setVar('pm_start_servers', $data['new']['pm_start_servers']);
$tpl->setVar('pm_min_spare_servers', $data['new']['pm_min_spare_servers']);
$tpl->setVar('pm_max_spare_servers', $data['new']['pm_max_spare_servers']);
$tpl->setVar('document_root', $data['new']['document_root']);
$tpl->setVar('security_level', $web_config['security_level']);
$php_open_basedir = $data['new']['php_open_basedir'] == '' ? escapeshellcmd($data['new']['document_root']) : escapeshellcmd($data['new']['php_open_basedir']);
$tpl->setVar('php_open_basedir', $php_open_basedir);
if ($php_open_basedir != '') {
$tpl->setVar('enable_php_open_basedir', '');
} else {
$tpl->setVar('enable_php_open_basedir', ';');
}
// Custom php.ini settings
$final_php_ini_settings = array();
$custom_php_ini_settings = trim($data['new']['custom_php_ini']);
if ($custom_php_ini_settings != '') {
// Make sure we only have Unix linebreaks
$custom_php_ini_settings = str_replace("\r\n", "\n", $custom_php_ini_settings);
$custom_php_ini_settings = str_replace("\r", "\n", $custom_php_ini_settings);
$ini_settings = explode("\n", $custom_php_ini_settings);
if (is_array($ini_settings) && !empty($ini_settings)) {
foreach ($ini_settings as $ini_setting) {
list($key, $value) = explode('=', $ini_setting);
if ($value) {
$value = escapeshellcmd(trim($value));
$key = escapeshellcmd(trim($key));
switch (strtolower($value)) {
case 'on':
case 'off':
case '1':
case '0':
// PHP-FPM might complain about invalid boolean value if you use 0
$value = 'off';
case 'true':
case 'false':
case 'yes':
case 'no':
$final_php_ini_settings[] = array('ini_setting' => 'php_admin_flag[' . $key . '] = ' . $value);
break;
default:
$final_php_ini_settings[] = array('ini_setting' => 'php_admin_value[' . $key . '] = ' . $value);
}
}
}
}
}
$tpl->setLoop('custom_php_ini_settings', $final_php_ini_settings);
file_put_contents($pool_dir . $pool_name . '.conf', $tpl->grab());
$app->log('Writing the PHP-FPM config file: ' . $pool_dir . $pool_name . '.conf', LOGLEVEL_DEBUG);
unset($tpl);
//$reload = true;
//if($reload == true) $app->services->restartService('php-fpm','reload');
}
示例11: update
//.........这里部分代码省略.........
$data['new']['redirect_type'] = 'break';
break;
case 'L':
$data['new']['redirect_type'] = 'break';
break;
default:
$data['new']['redirect_type'] = 'permanent';
}
}
switch ($data['new']['subdomain']) {
case 'www':
$rewrite_rules[] = array('rewrite_domain' => '^' . $data['new']['domain'], 'rewrite_type' => $data['new']['redirect_type'] == 'no' ? '' : $data['new']['redirect_type'], 'rewrite_target' => $rewrite_target, 'rewrite_target_ssl' => $rewrite_target_ssl);
$rewrite_rules[] = array('rewrite_domain' => '^www.' . $data['new']['domain'], 'rewrite_type' => $data['new']['redirect_type'] == 'no' ? '' : $data['new']['redirect_type'], 'rewrite_target' => $rewrite_target, 'rewrite_target_ssl' => $rewrite_target_ssl);
break;
case '*':
$rewrite_rules[] = array('rewrite_domain' => '(^|\\.)' . $data['new']['domain'], 'rewrite_type' => $data['new']['redirect_type'] == 'no' ? '' : $data['new']['redirect_type'], 'rewrite_target' => $rewrite_target, 'rewrite_target_ssl' => $rewrite_target_ssl);
break;
default:
$rewrite_rules[] = array('rewrite_domain' => '^' . $data['new']['domain'], 'rewrite_type' => $data['new']['redirect_type'] == 'no' ? '' : $data['new']['redirect_type'], 'rewrite_target' => $rewrite_target, 'rewrite_target_ssl' => $rewrite_target_ssl);
}
}
if ($data['new']['seo_redirect'] != '' && ($data['new']['subdomain'] == 'www' || $data['new']['subdomain'] == '*')) {
$vhost_data['seo_redirect_enabled'] = 1;
if ($data['new']['seo_redirect'] == 'non_www_to_www') {
$vhost_data['seo_redirect_origin_domain'] = $data['new']['domain'];
$vhost_data['seo_redirect_target_domain'] = 'www.' . $data['new']['domain'];
}
if ($data['new']['seo_redirect'] == 'www_to_non_www') {
$vhost_data['seo_redirect_origin_domain'] = 'www.' . $data['new']['domain'];
$vhost_data['seo_redirect_target_domain'] = $data['new']['domain'];
}
} else {
$vhost_data['seo_redirect_enabled'] = 0;
}
$errordocs = !$data['new']['errordocs'];
$nginx_directives = $data['new']['nginx_directives'];
$nginx_directives = str_replace("\r\n", "\n", $nginx_directives);
$nginx_directives = str_replace("\r", "\n", $nginx_directives);
$crt_file = escapeshellcmd($data['new']['document_root'] . '/ssl/' . $data['new']['ssl_domain'] . '.crt');
$key_file = escapeshellcmd($data['new']['document_root'] . '/ssl/' . $data['new']['ssl_domain'] . '.key');
if ($data['new']['ssl_domain'] != '' && $data['new']['ssl'] == 'y' && is_file($crt_file) && is_file($key_file) && filesize($crt_file) > 0 && filesize($key_file) > 0) {
$http_to_https = 1;
} else {
$http_to_https = 0;
}
// non-ssl vhost loop
if (count($rewrite_rules) > 0) {
$vhosts[] = array('ip_address' => $data['new']['ip_address'], 'ipv6_address' => $data['new']['ipv6_address'], 'ssl_enabled' => 0, 'http_to_https' => $http_to_https, 'nginx_directives' => $nginx_directives, 'errordocs' => $errordocs, 'port' => 80, 'apache2_port' => 82);
} else {
$vhosts[] = array('ip_address' => $data['new']['ip_address'], 'ipv6_address' => $data['new']['ipv6_address'], 'ssl_enabled' => 0, 'http_to_https' => $http_to_https, 'nginx_directives' => $nginx_directives, 'errordocs' => $errordocs, 'port' => 80, 'apache2_port' => 82);
}
// ssl vhost loop
if ($http_to_https == 1) {
$vhost_data['web_document_root_ssl'] = $data['new']['document_root'] . '/ssl';
if (count($rewrite_rules) > 0) {
$vhosts[] = array('ip_address' => $data['new']['ip_address'], 'ipv6_address' => $data['new']['ipv6_address'], 'ssl_enabled' => 1, 'http_to_https' => 0, 'rewrite_enabled' => 1, 'nginx_directives' => $nginx_directives, 'errordocs' => $errordocs, 'port' => 443, 'apache2_port' => 82);
} else {
$vhosts[] = array('ip_address' => $data['new']['ip_address'], 'ipv6_address' => $data['new']['ipv6_address'], 'ssl_enabled' => 1, 'http_to_https' => 0, 'rewrite_enabled' => 0, 'nginx_directives' => $nginx_directives, 'errordocs' => $errordocs, 'port' => 443, 'apache2_port' => 82);
}
}
$tpl->setLoop('vhosts', $vhosts);
$tpl->setVar($vhost_data);
if ($this->action == 'insert') {
$this->vhost_helper('insert', $data, $tpl->grab());
}
if ($this->action == 'update') {
$vhost_backup = $this->vhost_helper('update', $data, $tpl->grab());
}
}
/**
* Section for aliasdomains.
*
* This section is used for aliasdomains.
*/
if ($data['new']['type'] == 'alias') {
$parent_domain = $app->dbmaster->queryOneRecord('SELECT * FROM web_domain WHERE domain_id = ' . intval($data['new']['parent_domain_id']) . '');
$parent_domain['parent_domain_id'] = $data['new']['parent_domain_id'];
$data['old'] = $parent_domain;
$data['new'] = $parent_domain;
$this->update($event_name, $data);
}
/**
* Section for classic subdomains.
*
* This section is used for classic subdomains (non vhost subdomains).
*/
if ($data['new']['type'] == 'subdomain') {
$parent_domain = $app->dbmaster->queryOneRecord('SELECT * FROM web_domain WHERE domain_id = ' . intval($data['new']['parent_domain_id']) . '');
$parent_domain['parent_domain_id'] = $data['new']['parent_domain_id'];
$data['old'] = $parent_domain;
$data['new'] = $parent_domain;
$this->update($event_name, $data);
}
exec($final_command);
if (isset($vhost_backup)) {
$app->system->unlink($vhost_backup['file_new'] . '~');
}
unset($vhost_backup);
$this->action = '';
}
示例12: update
function update($event_name, $data)
{
global $app, $conf;
// get the config
$app->uses('getconf');
$server_config = $app->getconf->get_server_config($conf['server_id'], 'server');
//* Configure the debian network card settings.
//* Dont configure
if ($server_config['auto_network_configuration'] == 'y' && $data['mirrored'] == false && $server_config['ip_address'] != '0.0.0.0' && $server_config['gateway'] != '0.0.0.0') {
if (is_file('/etc/debian_version')) {
copy('/etc/network/interfaces', '/etc/network/interfaces~');
$app->load('tpl');
$network_tpl = new tpl();
$network_tpl->newTemplate('debian_network_interfaces.master');
$network_tpl->setVar('ip_address', $server_config['ip_address']);
$network_tpl->setVar('netmask', $server_config['netmask']);
$network_tpl->setVar('gateway', $server_config['gateway']);
$network_tpl->setVar('broadcast', $this->broadcast($server_config['ip_address'], $server_config['netmask']));
$network_tpl->setVar('network', $this->network($server_config['ip_address'], $server_config['netmask']));
$records = $app->db->queryAllRecords("SELECT ip_address FROM server_ip WHERE server_id = " . intval($conf['server_id']) . ' ORDER BY server_ip_id ASC');
$ip_records = array();
$additionl_ip_records = 0;
$n = 0;
if (is_array($records)) {
foreach ($records as $rec) {
/*
* don't insert the main-ip again!
*/
if ($rec['ip_address'] != $server_config['ip_address']) {
$ip_records[$n] = array('id' => $n, 'ip_address' => $rec['ip_address'], 'netmask' => $server_config['netmask'], 'gateway' => $server_config['gateway'], 'broadcast' => $this->broadcast($rec['ip_address'], $server_config['netmask']), 'network' => $this->network($rec['ip_address'], $server_config['netmask']));
$additionl_ip_records = 1;
$n++;
}
}
}
/*
* If we have more than 1 IP we have to add the main-ip at the end
* of the network-ip-list. If we don't do so, there may be problems
* in multi-server-settings (with the acces from other server to the
* main-server) because the LAST IP in the list is the IP mysql uses
* to determine the host, the user is logging in from.
*/
/*
// Disabled this part as it causes problems on multiserver setups
if ($additionl_ip_records != 0)
{
$swap['ip_address'] = $ip_records[$n-1]['ip_address'];
$swap['netmask'] = $ip_records[$n-1]['netmask'];
$swap['gateway'] = $ip_records[$n-1]['gateway'];
$ip_records[$n-1] = array(
'id' => $n-1,
'ip_address' => $server_config['ip_address'],
'netmask' => $server_config['netmask'],
'gateway' => $server_config['gateway'],
'broadcast' => $this->broadcast($server_config['ip_address'],$server_config['netmask']),
'network' => $this->network($server_config['ip_address'],$server_config['netmask'])
);
$network_tpl->setVar('ip_address',$swap['ip_address']);
$network_tpl->setVar('netmask',$swap['netmask']);
$network_tpl->setVar('gateway',$swap['gateway']);
$network_tpl->setVar('broadcast',$this->broadcast($swap['ip_address'],$swap['netmask']));
$network_tpl->setVar('network',$this->network($swap['ip_address'],$swap['netmask']));
}
*/
$network_tpl->setVar('additionl_ip_records', $additionl_ip_records);
$network_tpl->setLoop('interfaces', $ip_records);
file_put_contents('/etc/network/interfaces', $network_tpl->grab());
unset($network_tpl);
$app->log('Changed Network settings', LOGLEVEL_DEBUG);
exec($conf['init_scripts'] . '/' . 'networking force-reload');
} elseif (is_file('/etc/gentoo-release')) {
copy('/etc/conf.d/net', '/etc/conf.d/net~');
$app->load('tpl');
$network_tpl = new tpl();
$network_tpl->newTemplate('gentoo_network_interfaces.master');
$network_tpl->setVar('ip_address', $server_config['ip_address']);
$network_tpl->setVar('netmask', $server_config['netmask']);
$network_tpl->setVar('gateway', $server_config['gateway']);
$network_tpl->setVar('broadcast', $this->broadcast($server_config['ip_address'], $server_config['netmask']));
$records = $app->db->queryAllRecords("SELECT ip_address FROM server_ip WHERE server_id = " . intval($conf['server_id']) . " order by ip_address");
$ip_records = array();
$additionl_ip_records = 0;
$n = 0;
if (is_array($records)) {
foreach ($records as $rec) {
/*
* don't insert the main-ip again!
*/
if ($rec['ip_address'] != $server_config['ip_address']) {
$ip_records[$n] = array('id' => $n, 'ip_address' => $rec['ip_address'], 'netmask' => $server_config['netmask'], 'gateway' => $server_config['gateway'], 'broadcast' => $this->broadcast($rec['ip_address'], $server_config['netmask']));
$additionl_ip_records = 1;
$n++;
}
}
}
/*
* If we have more than 1 IP we have to add the main-ip at the end
* of the network-ip-list. If we don't do so, there may be problems
* in multi-server-settings (with the acces from other server to the
//.........这里部分代码省略.........
示例13: update
function update($event_name, $data)
{
global $app, $conf;
// get the config
$app->uses('getconf');
$server_config = $app->getconf->get_server_config($conf['server_id'], 'server');
//* Configure the debian network card settings.
//* Dont configure
if ($server_config['auto_network_configuration'] == 'y' && $data['mirrored'] == false && $server_config['ip_address'] != '0.0.0.0' && $server_config['gateway'] != '0.0.0.0') {
if (is_file('/etc/debian_version')) {
copy('/etc/network/interfaces', '/etc/network/interfaces~');
$app->load('tpl');
$network_tpl = new tpl();
$network_tpl->newTemplate('debian_network_interfaces.master');
$network_tpl->setVar('ip_address', $server_config['ip_address']);
$network_tpl->setVar('netmask', $server_config['netmask']);
$network_tpl->setVar('gateway', $server_config['gateway']);
$network_tpl->setVar('broadcast', $this->broadcast($server_config['ip_address'], $server_config['netmask']));
$network_tpl->setVar('network', $this->network($server_config['ip_address'], $server_config['netmask']));
$records = $app->db->queryAllRecords("SELECT ip_address FROM server_ip WHERE server_id = " . intval($conf['server_id']) . ' ORDER BY server_ip_id ASC');
$ip_records = array();
$additionl_ip_records = 0;
$n = 0;
if (is_array($records)) {
foreach ($records as $rec) {
/*
* don't insert the main-ip again!
*/
if ($rec['ip_address'] != $server_config['ip_address']) {
$ip_records[$n] = array('id' => $n, 'ip_address' => $rec['ip_address'], 'netmask' => $server_config['netmask'], 'gateway' => $server_config['gateway'], 'broadcast' => $this->broadcast($rec['ip_address'], $server_config['netmask']), 'network' => $this->network($rec['ip_address'], $server_config['netmask']));
$additionl_ip_records = 1;
$n++;
}
}
}
/*
* If we have more than 1 IP we have to add the main-ip at the end
* of the network-ip-list. If we don't do so, there may be problems
* in multi-server-settings (with the acces from other server to the
* main-server) because the LAST IP in the list is the IP mysql uses
* to determine the host, the user is logging in from.
*/
/*
// Disabled this part as it causes problems on multiserver setups
if ($additionl_ip_records != 0)
{
$swap['ip_address'] = $ip_records[$n-1]['ip_address'];
$swap['netmask'] = $ip_records[$n-1]['netmask'];
$swap['gateway'] = $ip_records[$n-1]['gateway'];
$ip_records[$n-1] = array(
'id' => $n-1,
'ip_address' => $server_config['ip_address'],
'netmask' => $server_config['netmask'],
'gateway' => $server_config['gateway'],
'broadcast' => $this->broadcast($server_config['ip_address'],$server_config['netmask']),
'network' => $this->network($server_config['ip_address'],$server_config['netmask'])
);
$network_tpl->setVar('ip_address',$swap['ip_address']);
$network_tpl->setVar('netmask',$swap['netmask']);
$network_tpl->setVar('gateway',$swap['gateway']);
$network_tpl->setVar('broadcast',$this->broadcast($swap['ip_address'],$swap['netmask']));
$network_tpl->setVar('network',$this->network($swap['ip_address'],$swap['netmask']));
}
*/
$network_tpl->setVar('additionl_ip_records', $additionl_ip_records);
$network_tpl->setLoop('interfaces', $ip_records);
file_put_contents('/etc/network/interfaces', $network_tpl->grab());
unset($network_tpl);
$app->log('Changed Network settings', LOGLEVEL_DEBUG);
exec($conf['init_scripts'] . '/' . 'networking force-reload');
} elseif (is_file('/etc/gentoo-release')) {
copy('/etc/conf.d/net', '/etc/conf.d/net~');
$app->load('tpl');
$network_tpl = new tpl();
$network_tpl->newTemplate('gentoo_network_interfaces.master');
$network_tpl->setVar('ip_address', $server_config['ip_address']);
$network_tpl->setVar('netmask', $server_config['netmask']);
$network_tpl->setVar('gateway', $server_config['gateway']);
$network_tpl->setVar('broadcast', $this->broadcast($server_config['ip_address'], $server_config['netmask']));
$records = $app->db->queryAllRecords("SELECT ip_address FROM server_ip WHERE server_id = " . intval($conf['server_id']) . " order by ip_address");
$ip_records = array();
$additionl_ip_records = 0;
$n = 0;
if (is_array($records)) {
foreach ($records as $rec) {
/*
* don't insert the main-ip again!
*/
if ($rec['ip_address'] != $server_config['ip_address']) {
$ip_records[$n] = array('id' => $n, 'ip_address' => $rec['ip_address'], 'netmask' => $server_config['netmask'], 'gateway' => $server_config['gateway'], 'broadcast' => $this->broadcast($rec['ip_address'], $server_config['netmask']));
$additionl_ip_records = 1;
$n++;
}
}
}
/*
* If we have more than 1 IP we have to add the main-ip at the end
* of the network-ip-list. If we don't do so, there may be problems
* in multi-server-settings (with the acces from other server to the
//.........这里部分代码省略.........
示例14: update
function update($event_name, $data)
{
global $app, $conf;
// load the server configuration options
$app->uses("getconf");
$mail_config = $app->getconf->get_server_config($conf["server_id"], 'mail');
if (substr($mail_config["homedir_path"], -1) == '/') {
$mail_config["homedir_path"] = substr($mail_config["homedir_path"], 0, -1);
}
if (isset($data["new"]["email"])) {
$email_parts = explode("@", $data["new"]["email"]);
} else {
$email_parts = explode("@", $data["old"]["email"]);
}
// Write the custom mailfilter script, if mailfilter recipe has changed
if ($data["old"]["custom_mailfilter"] != $data["new"]["custom_mailfilter"] or $data["old"]["move_junk"] != $data["new"]["move_junk"] or $data["old"]["autoresponder_text"] != $data["new"]["autoresponder_text"] or $data["old"]["autoresponder"] != $data["new"]["autoresponder"] or isset($data["new"]["email"]) and $data["old"]["email"] != $data["new"]["email"] or $data["old"]["autoresponder_start_date"] != $data["new"]["autoresponder_start_date"] or $data["old"]["autoresponder_end_date"] != $data["new"]["autoresponder_end_date"] or $data["old"]["cc"] != $data["new"]["cc"]) {
$app->log("Mailfilter config has been changed", LOGLEVEL_DEBUG);
$sieve_file = $data["new"]["maildir"] . '/.sieve';
if (is_file($sieve_file)) {
unlink($sieve_file) or $app->log("Unable to delete file: {$sieve_file}", LOGLEVEL_WARN);
}
$app->load('tpl');
$tpl = new tpl();
$tpl->newTemplate("sieve_filter.master");
// cc Field
$tpl->setVar('cc', $data["new"]["cc"]);
// Custom filters
$tpl->setVar('custom_mailfilter', $data["new"]["custom_mailfilter"]);
// Move junk
$tpl->setVar('move_junk', $data["new"]["move_junk"]);
// Set autoresponder start date
$tpl->setVar('start_date', $data["new"]["autoresponder_start_date"]);
// Set autoresponder end date
$tpl->setVar('end_date', $data["new"]["autoresponder_end_date"]);
// Autoresponder
$tpl->setVar('autoresponder', $data["new"]["autoresponder"]);
$data["new"]["autoresponder_text"] = str_replace("\"", "'", $data["new"]["autoresponder_text"]);
$tpl->setVar('autoresponder_text', $data["new"]["autoresponder_text"]);
//* Set alias addresses for autoresponder
$sql = "SELECT * FROM mail_forwarding WHERE type = 'alias' AND destination = '" . $app->db->quote($data["new"]["email"]) . "'";
$records = $app->db->queryAllRecords($sql);
$addresses = '';
if (is_array($records) && count($records) > 0) {
$addresses .= ':addresses ["' . $data["new"]["email"] . '",';
foreach ($records as $rec) {
$addresses .= '"' . $rec['source'] . '",';
}
$addresses = substr($addresses, 0, -1);
$addresses .= ']';
}
$tpl->setVar('addresses', $addresses);
file_put_contents($sieve_file, $tpl->grab());
unset($tpl);
}
}
示例15: bastille_update
private function bastille_update($event_name, $data)
{
global $app, $conf;
$app->uses('system');
$tcp_ports = $this->clean_ports($data['new']['tcp_port'], ' ');
$udp_ports = $this->clean_ports($data['new']['udp_port'], ' ');
$app->load('tpl');
$tpl = new tpl();
$tpl->newTemplate('bastille-firewall.cfg.master');
$tpl->setVar('TCP_PUBLIC_SERVICES', $tcp_ports);
$tpl->setVar('UDP_PUBLIC_SERVICES', $udp_ports);
file_put_contents('/etc/Bastille/bastille-firewall.cfg', $tpl->grab());
$app->log('Writing firewall configuration /etc/Bastille/bastille-firewall.cfg', LOGLEVEL_DEBUG);
unset($tpl);
if ($data['new']['active'] == 'y') {
//* ensure that ufw firewall is disabled in case both firewalls are installed
if ($app->system->is_installed('ufw')) {
exec('ufw disable');
}
exec($conf['init_scripts'] . '/' . 'bastille-firewall restart 2>/dev/null');
if (@is_file('/etc/debian_version')) {
exec('update-rc.d bastille-firewall defaults');
}
$app->log('Restarting the firewall', LOGLEVEL_DEBUG);
} else {
exec($conf['init_scripts'] . '/' . 'bastille-firewall stop 2>/dev/null');
if (@is_file('/etc/debian_version')) {
exec('update-rc.d -f bastille-firewall remove');
}
$app->log('Stopping the firewall', LOGLEVEL_DEBUG);
}
}