From dadfb45a9a29e239ff722e6d8e91c75f76c314b8 Mon Sep 17 00:00:00 2001 From: Florian Schaal <florian@schaal-24.de> Date: Fri, 05 Jun 2015 10:47:36 -0400 Subject: [PATCH] Merge branch 'master' of http://git.ispconfig.org/ispconfig/ispconfig3 --- server/conf/nginx_vhost.conf.master | 7 + interface/web/tools/dns_import_tupa.php | 7 + interface/web/admin/language_add.php | 9 + interface/web/sites/lib/lang/ar_shell_user.lng | 2 server/scripts/run-getmail.sh | 2 interface/web/themes/default/templates/form.tpl.htm | 4 interface/web/admin/remote_action_osupdate.php | 9 + interface/web/vm/openvz_action.php | 9 + server/conf/vhost.conf.master | 6 + interface/web/admin/language_edit.php | 9 + install/sql/ispconfig3.sql | 3 install/sql/incremental/upd_dev_collection.sql | 3 interface/web/admin/language_complete.php | 8 + server/plugins-available/apache2_plugin.inc.php | 31 +++-- interface/web/dns/dns_wizard.php | 10 + interface/web/client/client_message.php | 10 + interface/web/admin/server_config_edit.php | 10 + interface/lib/lang/de.lng | 1 server/lib/classes/cron.d/150-webalizer.inc.php | 8 + server/plugins-available/nginx_plugin.inc.php | 25 ++- interface/web/sites/lib/lang/en_shell_user.lng | 2 server/lib/classes/cron.d/150-awstats.inc.php | 5 interface/web/sites/form/web_vhost_domain.tform.php | 9 + interface/web/sites/lib/lang/de_shell_user.lng | 2 interface/web/sites/templates/web_vhost_domain_redirect.htm | 6 + interface/web/tools/resync.php | 11 + server/cron.sh | 2 interface/web/admin/language_import.php | 9 + server/server.sh | 2 server/plugins-available/shelluser_base_plugin.inc.php | 8 + interface/lib/classes/auth.inc.php | 50 ++++++++ install/tpl/authmysqlrc.master | 2 interface/lib/classes/tform_base.inc.php | 14 - interface/web/tools/import_ispconfig.php | 9 + interface/web/admin/remote_action_ispcupdate.php | 9 + 35 files changed, 261 insertions(+), 52 deletions(-) diff --git a/install/sql/incremental/upd_dev_collection.sql b/install/sql/incremental/upd_dev_collection.sql index b9c0562..919f8d4 100644 --- a/install/sql/incremental/upd_dev_collection.sql +++ b/install/sql/incremental/upd_dev_collection.sql @@ -144,7 +144,7 @@ ALTER TABLE `dns_rr` CHANGE `ttl` `ttl` INT(11) UNSIGNED NOT NULL DEFAULT '3600'; ALTER TABLE `dns_soa` CHANGE `minimum` `minimum` INT(11) UNSIGNED NOT NULL DEFAULT '3600', CHANGE `ttl` `ttl` INT(11) UNSIGNED NOT NULL DEFAULT '3600'; ALTER TABLE `client` CHANGE `web_php_options` `web_php_options` VARCHAR(255) NOT NULL DEFAULT 'no,fast-cgi,cgi,mod,suphp,php-fpm,hhvm'; -ALTER TABLE `web_domain` ADD COLUMN `enable_pagespeed` ENUM('y','n') NULL DEFAULT 'n' AFTER `directive_snippets_id`; +ALTER TABLE `web_domain` ADD COLUMN `enable_pagespeed` ENUM('y','n') NOT NULL DEFAULT 'n' AFTER `directive_snippets_id`; ALTER TABLE openvz_template ADD COLUMN `features` varchar(255) DEFAULT NULL AFTER `capability`; ALTER TABLE openvz_vm ADD COLUMN `features` TEXT DEFAULT NULL AFTER `capability`; @@ -165,3 +165,4 @@ PRIMARY KEY (`server_ip_map_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; +ALTER TABLE `web_domain` ADD COLUMN `rewrite_to_https` ENUM('y','n') NOT NULL DEFAULT 'n' AFTER `seo_redirect`; diff --git a/install/sql/ispconfig3.sql b/install/sql/ispconfig3.sql index a55ff21..df45246 100644 --- a/install/sql/ispconfig3.sql +++ b/install/sql/ispconfig3.sql @@ -1884,6 +1884,7 @@ `redirect_type` varchar(255) default NULL, `redirect_path` varchar(255) default NULL, `seo_redirect` varchar(255) default NULL, + `rewrite_to_https` ENUM('y','n') NOT NULL DEFAULT 'n', `ssl` enum('n','y') NOT NULL default 'n', `ssl_state` varchar(255) NULL, `ssl_locality` varchar(255) NULL, @@ -1924,7 +1925,7 @@ `added_date` date NOT NULL DEFAULT '0000-00-00', `added_by` varchar(255) DEFAULT NULL, `directive_snippets_id` int(11) unsigned NOT NULL default '0', - `enable_pagespeed` ENUM('y','n') NULL DEFAULT 'n', + `enable_pagespeed` ENUM('y','n') NOT NULL DEFAULT 'n', `http_port` int(11) unsigned NOT NULL DEFAULT '80', `https_port` int(11) unsigned NOT NULL DEFAULT '443', PRIMARY KEY (`domain_id`), diff --git a/install/tpl/authmysqlrc.master b/install/tpl/authmysqlrc.master index 214c40f..c35aca8 100644 --- a/install/tpl/authmysqlrc.master +++ b/install/tpl/authmysqlrc.master @@ -16,4 +16,4 @@ #MYSQL_QUOTA_FIELD concat(quota,'S') #MYSQL_WHERE_CLAUSE access='y' #MYSQL_AUXOPTIONS_FIELD concat('disableimap=',disableimap,',disablepop3=',disablepop3) -MYSQL_AUXOPTIONS_FIELD concat('disableimap=',(replace(disableimap,'y',1)),',','disablepop3=',(replace(disablepop3,'y',1))) +MYSQL_AUXOPTIONS_FIELD concat('disableimap=', if(disableimap = 'y', 1, 0), ',', 'disablepop3=', if(disablepop3 = 'y', 1, 0)) \ No newline at end of file diff --git a/interface/lib/classes/auth.inc.php b/interface/lib/classes/auth.inc.php index e281c03..4c97757 100644 --- a/interface/lib/classes/auth.inc.php +++ b/interface/lib/classes/auth.inc.php @@ -222,6 +222,56 @@ $salt.="$"; return crypt($cleartext_password, $salt); } + + public function csrf_token_get($form_name) { + /* CSRF PROTECTION */ + // generate csrf protection id and key + $_csrf_id = uniqid($form_name . '_'); // form id + $_csrf_key = sha1(uniqid(microtime(true), true)); // the key + if(!isset($_SESSION['_csrf'])) $_SESSION['_csrf'] = array(); + if(!isset($_SESSION['_csrf_timeout'])) $_SESSION['_csrf_timeout'] = array(); + $_SESSION['_csrf'][$_csrf_id] = $_csrf_key; + $_SESSION['_csrf_timeout'][$_csrf_id] = time() + 3600; // timeout hash in 1 hour + + return array('csrf_id' => $_csrf_id,'csrf_key' => $_csrf_key); + } + + public function csrf_token_check() { + global $app; + + if(isset($_POST) && is_array($_POST)) { + $_csrf_valid = false; + if(isset($_POST['_csrf_id']) && isset($_POST['_csrf_key'])) { + $_csrf_id = trim($_POST['_csrf_id']); + $_csrf_key = trim($_POST['_csrf_key']); + if(isset($_SESSION['_csrf']) && isset($_SESSION['_csrf'][$_csrf_id]) && isset($_SESSION['_csrf_timeout']) && isset($_SESSION['_csrf_timeout'][$_csrf_id])) { + if($_SESSION['_csrf'][$_csrf_id] === $_csrf_key && $_SESSION['_csrf_timeout'] >= time()) $_csrf_valid = true; + } + } + if($_csrf_valid !== true) { + $app->log('CSRF attempt blocked. Referer: ' . (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'unknown'), LOGLEVEL_WARN); + $app->error($app->lng('err_csrf_attempt_blocked')); + } + $_SESSION['_csrf'][$_csrf_id] = null; + $_SESSION['_csrf_timeout'][$_csrf_id] = null; + unset($_SESSION['_csrf'][$_csrf_id]); + unset($_SESSION['_csrf_timeout'][$_csrf_id]); + + if(isset($_SESSION['_csrf_timeout']) && is_array($_SESSION['_csrf_timeout'])) { + $to_unset = array(); + foreach($_SESSION['_csrf_timeout'] as $_csrf_id => $timeout) { + if($timeout < time()) $to_unset[] = $_csrf_id; + } + foreach($to_unset as $_csrf_id) { + $_SESSION['_csrf'][$_csrf_id] = null; + $_SESSION['_csrf_timeout'][$_csrf_id] = null; + unset($_SESSION['_csrf'][$_csrf_id]); + unset($_SESSION['_csrf_timeout'][$_csrf_id]); + } + unset($to_unset); + } + } + } } diff --git a/interface/lib/classes/tform_base.inc.php b/interface/lib/classes/tform_base.inc.php index 104217d..784e96a 100644 --- a/interface/lib/classes/tform_base.inc.php +++ b/interface/lib/classes/tform_base.inc.php @@ -416,12 +416,10 @@ /* CSRF PROTECTION */ // generate csrf protection id and key - $_csrf_id = uniqid($this->formDef['name'] . '_'); - $_csrf_value = sha1(uniqid(microtime(true), true)); - if(!isset($_SESSION['_csrf'])) $_SESSION['_csrf'] = array(); - if(!isset($_SESSION['_csrf_timeout'])) $_SESSION['_csrf_timeout'] = array(); - $_SESSION['_csrf'][$_csrf_id] = $_csrf_value; - $_SESSION['_csrf_timeout'][$_csrf_id] = time() + 3600; // timeout hash in 1 hour + $csrf_token = $app->auth->csrf_token_get($this->formDef['name']); + $_csrf_id = $csrf_token['csrf_id']; + $_csrf_value = $csrf_token['csrf_key']; + $this->formDef['tabs'][$tab]['fields']['_csrf_id'] = array( 'datatype' => 'VARCHAR', 'formtype' => 'TEXT', @@ -714,10 +712,6 @@ unset($_POST); unset($record); } - $_SESSION['_csrf'][$_csrf_id] = null; - $_SESSION['_csrf_timeout'][$_csrf_id] = null; - unset($_SESSION['_csrf'][$_csrf_id]); - unset($_SESSION['_csrf_timeout'][$_csrf_id]); if(isset($_SESSION['_csrf_timeout']) && is_array($_SESSION['_csrf_timeout'])) { $to_unset = array(); diff --git a/interface/lib/lang/de.lng b/interface/lib/lang/de.lng index 1fc1152..fb35c30 100644 --- a/interface/lib/lang/de.lng +++ b/interface/lib/lang/de.lng @@ -43,6 +43,7 @@ $wb['latest_news_txt'] = 'Neuigkeiten'; $wb['err_csrf_attempt_blocked'] = 'CSRF-Versuch blockiert.'; $wb['top_menu_vm'] = 'vServer'; +$wb['err_csrf_attempt_blocked'] = 'CSRF-Versuch blockiert.'; $wb['daynamesmin_su'] = 'So'; $wb['daynamesmin_mo'] = 'Mo'; $wb['daynamesmin_tu'] = 'Di'; diff --git a/interface/web/admin/language_add.php b/interface/web/admin/language_add.php index 8c488c3..f58a2db 100644 --- a/interface/web/admin/language_add.php +++ b/interface/web/admin/language_add.php @@ -65,6 +65,10 @@ $app->tpl->setVar('error', $error); if(isset($_POST['lng_new']) && strlen($_POST['lng_new']) == 2 && $error == '') { + + //* CSRF Check + $app->auth->csrf_token_check(); + $lng_new = $_POST['lng_new']; if(!preg_match("/^[a-z]{2}$/i", $lng_new)) die('unallowed characters in language name.'); @@ -94,6 +98,11 @@ $app->tpl->setVar('msg', $msg); +//* SET csrf token +$csrf_token = $app->auth->csrf_token_get('language_add'); +$app->tpl->setVar('_csrf_id',$csrf_token['csrf_id']); +$app->tpl->setVar('_csrf_key',$csrf_token['csrf_key']); + //* load language file $lng_file = 'lib/lang/'.$_SESSION['s']['language'].'_language_add.lng'; include $lng_file; diff --git a/interface/web/admin/language_complete.php b/interface/web/admin/language_complete.php index d8f4bbd..d28e89a 100644 --- a/interface/web/admin/language_complete.php +++ b/interface/web/admin/language_complete.php @@ -67,6 +67,9 @@ // Export the language file if(isset($_POST['lng_select']) && $error == '') { + //* CSRF Check + $app->auth->csrf_token_check(); + // complete the global langauge file merge_langfile(ISPC_LIB_PATH."/lang/".$selected_language.".lng", ISPC_LIB_PATH."/lang/en.lng"); @@ -157,6 +160,11 @@ $app->tpl->setVar('msg', $msg); +//* SET csrf token +$csrf_token = $app->auth->csrf_token_get('language_merge'); +$app->tpl->setVar('_csrf_id',$csrf_token['csrf_id']); +$app->tpl->setVar('_csrf_key',$csrf_token['csrf_key']); + //* load language file $lng_file = 'lib/lang/'.$_SESSION['s']['language'].'_language_complete.lng'; include $lng_file; diff --git a/interface/web/admin/language_edit.php b/interface/web/admin/language_edit.php index 7d83b9b..c94a5eb 100644 --- a/interface/web/admin/language_edit.php +++ b/interface/web/admin/language_edit.php @@ -55,6 +55,10 @@ //* Save data if(isset($_POST['records']) && is_array($_POST['records'])) { + + //* CSRF Check + $app->auth->csrf_token_check(); + $file_content = "<?php\n"; foreach($_POST['records'] as $key => $val) { $val = stripslashes($val); @@ -93,6 +97,11 @@ unset($wb); } +//* SET csrf token +$csrf_token = $app->auth->csrf_token_get('language_edit'); +$app->tpl->setVar('_csrf_id',$csrf_token['csrf_id']); +$app->tpl->setVar('_csrf_key',$csrf_token['csrf_key']); + //* load language file $lng_file = 'lib/lang/'.$_SESSION['s']['language'].'_language_edit.lng'; diff --git a/interface/web/admin/language_import.php b/interface/web/admin/language_import.php index d53575b..00d105c 100644 --- a/interface/web/admin/language_import.php +++ b/interface/web/admin/language_import.php @@ -129,6 +129,10 @@ // Export the language file if(isset($_FILES['file']['name']) && is_uploaded_file($_FILES['file']['tmp_name'])) { + + //* CSRF Check + $app->auth->csrf_token_check(); + $lines = file($_FILES['file']['tmp_name']); // initial check $parts = explode('|', $lines[0]); @@ -183,6 +187,11 @@ $app->tpl->setVar('msg', $msg); $app->tpl->setVar('error', $error); +//* SET csrf token +$csrf_token = $app->auth->csrf_token_get('language_import'); +$app->tpl->setVar('_csrf_id',$csrf_token['csrf_id']); +$app->tpl->setVar('_csrf_key',$csrf_token['csrf_key']); + //* load language file $lng_file = 'lib/lang/'.$_SESSION['s']['language'].'_language_import.lng'; include $lng_file; diff --git a/interface/web/admin/remote_action_ispcupdate.php b/interface/web/admin/remote_action_ispcupdate.php index 2634006..f22661e 100644 --- a/interface/web/admin/remote_action_ispcupdate.php +++ b/interface/web/admin/remote_action_ispcupdate.php @@ -66,6 +66,10 @@ //* Note: Disabled post action if (1 == 0 && isset($_POST['server_select'])) { + + //* CSRF Check + $app->auth->csrf_token_check(); + $server = $_POST['server_select']; $servers = array(); if ($server == '*') { @@ -88,6 +92,11 @@ $app->tpl->setVar('msg', $msg); +//* SET csrf token +$csrf_token = $app->auth->csrf_token_get('ispupdate'); +$app->tpl->setVar('_csrf_id',$csrf_token['csrf_id']); +$app->tpl->setVar('_csrf_key',$csrf_token['csrf_key']); + $app->tpl->setVar($wb); $app->tpl_defaults(); diff --git a/interface/web/admin/remote_action_osupdate.php b/interface/web/admin/remote_action_osupdate.php index 8f48e29..5e73cdf 100644 --- a/interface/web/admin/remote_action_osupdate.php +++ b/interface/web/admin/remote_action_osupdate.php @@ -62,6 +62,10 @@ * If the user wants to do the action, write this to our db */ if (isset($_POST['server_select'])) { + + //* CSRF Check + $app->auth->csrf_token_check(); + $server = $_POST['server_select']; $servers = array(); if ($server == '*') { @@ -84,6 +88,11 @@ $app->tpl->setVar('msg', $msg); +//* SET csrf token +$csrf_token = $app->auth->csrf_token_get('osupdate'); +$app->tpl->setVar('_csrf_id',$csrf_token['csrf_id']); +$app->tpl->setVar('_csrf_key',$csrf_token['csrf_key']); + $app->tpl->setVar($wb); $app->tpl_defaults(); diff --git a/interface/web/admin/server_config_edit.php b/interface/web/admin/server_config_edit.php index d64b6dd..4c03e7e 100644 --- a/interface/web/admin/server_config_edit.php +++ b/interface/web/admin/server_config_edit.php @@ -93,10 +93,14 @@ } } - $server_config_array[$section] = $app->tform->encode($this->dataRecord, $section); - $server_config_str = $app->ini_parser->get_ini_string($server_config_array); + if($app->tform->errorMessage == '') { + $server_config_array[$section] = $app->tform->encode($this->dataRecord, $section); + $server_config_str = $app->ini_parser->get_ini_string($server_config_array); - $app->db->datalogUpdate('server', array("config" => $server_config_str), 'server_id', $server_id); + $app->db->datalogUpdate('server', array("config" => $server_config_str), 'server_id', $server_id); + } else { + $app->error('Security breach!'); + } } } diff --git a/interface/web/client/client_message.php b/interface/web/client/client_message.php index 0e3bd2e..eb8bcdb 100644 --- a/interface/web/client/client_message.php +++ b/interface/web/client/client_message.php @@ -51,7 +51,10 @@ //* Save data if(isset($_POST) && count($_POST) > 1) { - + + //* CSRF Check + $app->auth->csrf_token_check(); + //* Check values if(!preg_match("/^\w+[\w\.\-\+]*\w{0,}@\w+[\w.-]*\w+\.[a-zA-Z0-9\-]{2,30}$/i", $_POST['sender'])) $error .= $wb['sender_invalid_error'].'<br />'; if(empty($_POST['subject'])) $error .= $wb['subject_invalid_error'].'<br />'; @@ -161,6 +164,11 @@ } $app->tpl->setVar('message_variables', trim($message_variables)); +//* SET csrf token +$csrf_token = $app->auth->csrf_token_get('client_message'); +$app->tpl->setVar('_csrf_id',$csrf_token['csrf_id']); +$app->tpl->setVar('_csrf_key',$csrf_token['csrf_key']); + $app->tpl->setVar('okmsg', $msg); $app->tpl->setVar('error', $error); diff --git a/interface/web/dns/dns_wizard.php b/interface/web/dns/dns_wizard.php index 198245b..1800259 100644 --- a/interface/web/dns/dns_wizard.php +++ b/interface/web/dns/dns_wizard.php @@ -197,7 +197,10 @@ } if($_POST['create'] == 1) { - + + //* CSRF Check + $app->auth->csrf_token_check(); + $error = ''; if ($post_server_id) @@ -430,6 +433,11 @@ $app->tpl->setVar("title", 'DNS Wizard'); +//* SET csrf token +$csrf_token = $app->auth->csrf_token_get('dns_wizard'); +$app->tpl->setVar('_csrf_id',$csrf_token['csrf_id']); +$app->tpl->setVar('_csrf_key',$csrf_token['csrf_key']); + $lng_file = 'lib/lang/'.$_SESSION['s']['language'].'_dns_wizard.lng'; include $lng_file; $app->tpl->setVar($wb); diff --git a/interface/web/sites/form/web_vhost_domain.tform.php b/interface/web/sites/form/web_vhost_domain.tform.php index b457be7..d232f12 100644 --- a/interface/web/sites/form/web_vhost_domain.tform.php +++ b/interface/web/sites/form/web_vhost_domain.tform.php @@ -400,6 +400,15 @@ 'width' => '30', 'maxlength' => '255' ), + 'rewrite_to_https' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'CHECKBOX', + 'default' => 'n', + 'value' => array ( + 0 => 'n', + 1 => 'y' + ) + ), //################################# // ENDE Datatable fields //################################# diff --git a/interface/web/sites/lib/lang/ar_shell_user.lng b/interface/web/sites/lib/lang/ar_shell_user.lng index 0b274d3..eac85fd 100644 --- a/interface/web/sites/lib/lang/ar_shell_user.lng +++ b/interface/web/sites/lib/lang/ar_shell_user.lng @@ -1,6 +1,6 @@ <?php $wb['shell_txt'] = 'Shell'; -$wb['dir_txt'] = 'Dir'; +$wb['dir_txt'] = 'Base Dir'; $wb['server_id_txt'] = 'Server'; $wb['parent_domain_id_txt'] = 'Site'; $wb['username_txt'] = 'Username'; diff --git a/interface/web/sites/lib/lang/de_shell_user.lng b/interface/web/sites/lib/lang/de_shell_user.lng index 4ae442c..9130b45 100644 --- a/interface/web/sites/lib/lang/de_shell_user.lng +++ b/interface/web/sites/lib/lang/de_shell_user.lng @@ -1,6 +1,6 @@ <?php $wb['shell_txt'] = 'Shell'; -$wb['dir_txt'] = 'Verzeichnis'; +$wb['dir_txt'] = 'Basis Verzeichnis'; $wb['server_id_txt'] = 'Server'; $wb['parent_domain_id_txt'] = 'Webseite'; $wb['username_txt'] = 'Benutzername'; diff --git a/interface/web/sites/lib/lang/en_shell_user.lng b/interface/web/sites/lib/lang/en_shell_user.lng index 66d3367..1b605b5 100644 --- a/interface/web/sites/lib/lang/en_shell_user.lng +++ b/interface/web/sites/lib/lang/en_shell_user.lng @@ -2,7 +2,7 @@ $wb['puser_txt'] = "Web Username"; $wb['pgroup_txt'] = "Web Group"; $wb['shell_txt'] = "Shell"; -$wb['dir_txt'] = "Dir"; +$wb['dir_txt'] = "Base Dir"; $wb['server_id_txt'] = "Server"; $wb['parent_domain_id_txt'] = "Site"; $wb['username_txt'] = "Username"; diff --git a/interface/web/sites/templates/web_vhost_domain_redirect.htm b/interface/web/sites/templates/web_vhost_domain_redirect.htm index 1bdcf00..06cc8a1 100644 --- a/interface/web/sites/templates/web_vhost_domain_redirect.htm +++ b/interface/web/sites/templates/web_vhost_domain_redirect.htm @@ -33,6 +33,12 @@ <label for="rewrite_rules" class="col-sm-3 control-label">{tmpl_var name='rewrite_rules_txt'}</label> <div class="col-sm-9"><textarea class="form-control" name="rewrite_rules" id="rewrite_rules" rows='10' cols='50'>{tmpl_var name='rewrite_rules'}</textarea></div> <b>{tmpl_var name="allowed_rewrite_rule_directives_txt"}</b><br><br> break<br> if<br> return<br> rewrite<br> set<br><br> <a href="http://wiki.nginx.org/HttpRewriteModule" target="_blank">http://wiki.nginx.org/HttpRewriteModule</a> </div> + <div class="form-group"> + <label class="col-sm-3 control-label">{tmpl_var name='rewrite_to_https_txt'}</label> + <div class="col-sm-9"> + {tmpl_var name="rewrite_to_https"} + </div> + </div> <input type="hidden" name="id" value="{tmpl_var name='id'}"> diff --git a/interface/web/themes/default/templates/form.tpl.htm b/interface/web/themes/default/templates/form.tpl.htm index 429bfd9..a2d3dfc 100644 --- a/interface/web/themes/default/templates/form.tpl.htm +++ b/interface/web/themes/default/templates/form.tpl.htm @@ -1 +1,3 @@ -<tmpl_dyninclude name="content_tpl"> \ No newline at end of file +<tmpl_dyninclude name="content_tpl"> +<input type="hidden" name="_csrf_id" value="{tmpl_var name='_csrf_id'}" /> +<input type="hidden" name="_csrf_key" value="{tmpl_var name='_csrf_key'}" /> \ No newline at end of file diff --git a/interface/web/tools/dns_import_tupa.php b/interface/web/tools/dns_import_tupa.php index b81a83b..849a097 100644 --- a/interface/web/tools/dns_import_tupa.php +++ b/interface/web/tools/dns_import_tupa.php @@ -45,6 +45,9 @@ // Resyncing dns zones if(isset($_POST['start']) && $_POST['start'] == 1) { + + //* CSRF Check + $app->auth->csrf_token_check(); //* Set variable sin template $app->tpl->setVar('dbhost', $_POST['dbhost']); @@ -181,6 +184,10 @@ $app->tpl->setVar('msg', $msg); $app->tpl->setVar('error', $error); +//* SET csrf token +$csrf_token = $app->auth->csrf_token_get('dns_import'); +$app->tpl->setVar('_csrf_id',$csrf_token['csrf_id']); +$app->tpl->setVar('_csrf_key',$csrf_token['csrf_key']); $app->tpl_defaults(); $app->tpl->pparse(); diff --git a/interface/web/tools/import_ispconfig.php b/interface/web/tools/import_ispconfig.php index 0998d18..efcf022 100644 --- a/interface/web/tools/import_ispconfig.php +++ b/interface/web/tools/import_ispconfig.php @@ -49,6 +49,10 @@ $app->tpl->setVar($wb); if(isset($_POST['connected'])) { + + //* CSRF Check + $app->auth->csrf_token_check(); + $connected = $app->functions->intval($_POST['connected']); if($connected == 0) { @@ -133,6 +137,11 @@ $app->tpl->setVar('msg', $msg); $app->tpl->setVar('error', $error); +//* SET csrf token +$csrf_token = $app->auth->csrf_token_get('ispconfig_import'); +$app->tpl->setVar('_csrf_id',$csrf_token['csrf_id']); +$app->tpl->setVar('_csrf_key',$csrf_token['csrf_key']); + $app->tpl_defaults(); $app->tpl->pparse(); diff --git a/interface/web/tools/resync.php b/interface/web/tools/resync.php index 2ae7784..8425a12 100644 --- a/interface/web/tools/resync.php +++ b/interface/web/tools/resync.php @@ -379,6 +379,10 @@ } } + $csrf_token = $app->auth->csrf_token_get('tools_resync'); + $app->tpl->setVar('_csrf_id', $csrf_token['csrf_id']); + $app->tpl->setVar('_csrf_key', $csrf_token['csrf_key']); + parent::onShowEnd(); } @@ -429,7 +433,12 @@ function onSubmit() { global $app; - + + if(isset($_POST) && count($_POST) > 1) { + //* CSRF Check + $app->auth->csrf_token_check(); + } + //* all services if($this->dataRecord['resync_all'] == 1) { $this->dataRecord['resync_sites'] = 1; diff --git a/interface/web/vm/openvz_action.php b/interface/web/vm/openvz_action.php index 757f55e..4b429eb 100644 --- a/interface/web/vm/openvz_action.php +++ b/interface/web/vm/openvz_action.php @@ -17,6 +17,10 @@ if($vm_id == 0) die('Invalid VM ID'); +if(isset($_POST) && count($_POST) > 1) { + //* CSRF Check + $app->auth->csrf_token_check(); +} $vm = $app->db->queryOneRecord("SELECT server_id, veid FROM openvz_vm WHERE vm_id = ?", $vm_id); $veid = $app->functions->intval($vm['veid']); $server_id = $app->functions->intval($vm['server_id']); @@ -112,6 +116,11 @@ $app->tpl->setVar($options); $app->tpl->setVar('error', $error_msg); +//* SET csrf token +$csrf_token = $app->auth->csrf_token_get('openvz_action'); +$app->tpl->setVar('_csrf_id',$csrf_token['csrf_id']); +$app->tpl->setVar('_csrf_key',$csrf_token['csrf_key']); + $app->tpl_defaults(); $app->tpl->pparse(); diff --git a/server/conf/nginx_vhost.conf.master b/server/conf/nginx_vhost.conf.master index 040af21..4a775ce 100644 --- a/server/conf/nginx_vhost.conf.master +++ b/server/conf/nginx_vhost.conf.master @@ -33,6 +33,13 @@ rewrite ^<tmpl_var name='local_redirect_exclude'>(.*)$ <tmpl_var name='local_redirect_target'>$2 <tmpl_var name='local_redirect_type'>; } </tmpl_loop> +<tmpl_if name='ssl_enabled'> +<tmpl_if name='rewrite_to_https' op='==' value='y'> + if ($scheme != "https") { + rewrite ^ https://$http_host$request_uri? permanent; + } +</tmpl_if> +</tmpl_if> <tmpl_loop name="own_redirects"> <tmpl_if name='use_rewrite'> diff --git a/server/conf/vhost.conf.master b/server/conf/vhost.conf.master index 279cbc5..bdfc761 100644 --- a/server/conf/vhost.conf.master +++ b/server/conf/vhost.conf.master @@ -412,6 +412,12 @@ RewriteRule ^/(.*)$ <tmpl_var name='rewrite_target'><tmpl_if name="rewrite_add_path" op="==" value="y">$1</tmpl_if> <tmpl_var name='rewrite_type'> </tmpl_loop> +<tmpl_if name='ssl_enabled'> +<tmpl_if name='rewrite_to_https' op='==' value='y'> + RewriteCond %{HTTPS} off + RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] +</tmpl_if> +</tmpl_if> </tmpl_if> # add support for apache mpm_itk diff --git a/server/cron.sh b/server/cron.sh index 3670e68..98f0ddf 100644 --- a/server/cron.sh +++ b/server/cron.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/X11R6/bin diff --git a/server/lib/classes/cron.d/150-awstats.inc.php b/server/lib/classes/cron.d/150-awstats.inc.php index ea0c64f..2d281c7 100644 --- a/server/lib/classes/cron.d/150-awstats.inc.php +++ b/server/lib/classes/cron.d/150-awstats.inc.php @@ -117,6 +117,10 @@ } if(!@is_dir($statsdir)) mkdir($statsdir); + $username = escapeshellcmd($rec['system_user']); + $groupname = escapeshellcmd($rec['system_group']); + chown($statsdir, $username); + chgrp($statsdir, $groupname); if(is_link('/var/log/ispconfig/httpd/'.$domain.'/yesterday-access.log')) unlink('/var/log/ispconfig/httpd/'.$domain.'/yesterday-access.log'); symlink($logfile, '/var/log/ispconfig/httpd/'.$domain.'/yesterday-access.log'); @@ -174,6 +178,7 @@ chgrp($rec['document_root']."/".$web_folder."/stats/index.php", $rec['system_group']); } + exec('chown -R '.$username.':'.$groupname.' '.$statsdir); } diff --git a/server/lib/classes/cron.d/150-webalizer.inc.php b/server/lib/classes/cron.d/150-webalizer.inc.php index b850003..0ae05dd 100644 --- a/server/lib/classes/cron.d/150-webalizer.inc.php +++ b/server/lib/classes/cron.d/150-webalizer.inc.php @@ -79,7 +79,7 @@ } - $sql = "SELECT domain_id, domain, document_root, web_folder, type, parent_domain_id FROM web_domain WHERE (type = 'vhost' or type = 'vhostsubdomain' or type = 'vhostalias') and stats_type = 'webalizer' AND server_id = ?"; + $sql = "SELECT domain_id, domain, document_root, web_folder, type, parent_domain_id, system_user, system_group FROM web_domain WHERE (type = 'vhost' or type = 'vhostsubdomain' or type = 'vhostalias') and stats_type = 'webalizer' AND server_id = ?"; $records = $app->db->queryAllRecords($sql, $conf['server_id']); foreach($records as $rec) { @@ -122,7 +122,13 @@ if(!@is_dir($statsdir)) mkdir($statsdir); + $username = escapeshellcmd($rec['system_user']); + $groupname = escapeshellcmd($rec['system_group']); + chown($statsdir, $username); + chgrp($statsdir, $groupname); exec("$webalizer -c $webalizer_conf -n $domain -s $domain -r $domain -q -T -p -o $statsdir $logfile"); + + exec('chown -R '.$username.':'.$groupname.' '.$statsdir); } diff --git a/server/plugins-available/apache2_plugin.inc.php b/server/plugins-available/apache2_plugin.inc.php index b2f2115..4bacf07 100644 --- a/server/plugins-available/apache2_plugin.inc.php +++ b/server/plugins-available/apache2_plugin.inc.php @@ -650,6 +650,7 @@ if(!is_dir($data['new']['document_root'].'/' . $web_folder)) $app->system->mkdirpath($data['new']['document_root'].'/' . $web_folder); if(!is_dir($data['new']['document_root'].'/' . $web_folder . '/error') and $data['new']['errordocs']) $app->system->mkdirpath($data['new']['document_root'].'/' . $web_folder . '/error'); + if(!is_dir($data['new']['document_root'].'/' . $web_folder . '/stats')) $app->system->mkdirpath($data['new']['document_root'].'/' . $web_folder . '/stats'); //if(!is_dir($data['new']['document_root'].'/'.$log_folder)) exec('mkdir -p '.$data['new']['document_root'].'/'.$log_folder); if(!is_dir($data['new']['document_root'].'/ssl')) $app->system->mkdirpath($data['new']['document_root'].'/ssl'); if(!is_dir($data['new']['document_root'].'/cgi-bin')) $app->system->mkdirpath($data['new']['document_root'].'/cgi-bin'); @@ -771,27 +772,31 @@ } if (file_exists($conf['rootpath'] . '/conf-custom/index/standard_index.html_'.substr(escapeshellcmd($conf['language']), 0, 2))) { - exec('cp ' . $conf['rootpath'] . '/conf-custom/index/standard_index.html_'.substr(escapeshellcmd($conf['language']), 0, 2).' '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html'); + if(!file_exists(escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html')) exec('cp ' . $conf['rootpath'] . '/conf-custom/index/standard_index.html_'.substr(escapeshellcmd($conf['language']), 0, 2).' '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html'); if(is_file($conf['rootpath'] . '/conf-custom/index/favicon.ico')) { - exec('cp ' . $conf['rootpath'] . '/conf-custom/index/favicon.ico '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/'); + if(!file_exists(escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/favicon.ico')) exec('cp ' . $conf['rootpath'] . '/conf-custom/index/favicon.ico '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/'); } if(is_file($conf['rootpath'] . '/conf-custom/index/robots.txt')) { - exec('cp ' . $conf['rootpath'] . '/conf-custom/index/robots.txt '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/'); + if(!file_exists(escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/robots.txt')) exec('cp ' . $conf['rootpath'] . '/conf-custom/index/robots.txt '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/'); } if(is_file($conf['rootpath'] . '/conf-custom/index/.htaccess')) { - exec('cp ' . $conf['rootpath'] . '/conf-custom/index/.htaccess '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/'); + if(!file_exists(escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/.htaccess')) exec('cp ' . $conf['rootpath'] . '/conf-custom/index/.htaccess '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/'); } - } - else { + } else { if (file_exists($conf['rootpath'] . '/conf-custom/index/standard_index.html')) { - exec('cp ' . $conf['rootpath'] . '/conf-custom/index/standard_index.html '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html'); - } - else { - exec('cp ' . $conf['rootpath'] . '/conf/index/standard_index.html_'.substr(escapeshellcmd($conf['language']), 0, 2).' '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html'); - if(is_file($conf['rootpath'] . '/conf/index/favicon.ico')) exec('cp ' . $conf['rootpath'] . '/conf/index/favicon.ico '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/'); - if(is_file($conf['rootpath'] . '/conf/index/robots.txt')) exec('cp ' . $conf['rootpath'] . '/conf/index/robots.txt '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/'); - if(is_file($conf['rootpath'] . '/conf/index/.htaccess')) exec('cp ' . $conf['rootpath'] . '/conf/index/.htaccess '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/'); + if(!file_exists(escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html')) exec('cp ' . $conf['rootpath'] . '/conf-custom/index/standard_index.html '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html'); + } else { + if(!file_exists(escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html')) exec('cp ' . $conf['rootpath'] . '/conf/index/standard_index.html_'.substr(escapeshellcmd($conf['language']), 0, 2).' '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html'); + if(is_file($conf['rootpath'] . '/conf/index/favicon.ico')){ + if(!file_exists(escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/favicon.ico')) exec('cp ' . $conf['rootpath'] . '/conf/index/favicon.ico '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/'); + } + if(is_file($conf['rootpath'] . '/conf/index/robots.txt')){ + if(!file_exists(escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/robots.txt')) exec('cp ' . $conf['rootpath'] . '/conf/index/robots.txt '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/'); + } + if(is_file($conf['rootpath'] . '/conf/index/.htaccess')){ + if(!file_exists(escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/.htaccess')) exec('cp ' . $conf['rootpath'] . '/conf/index/.htaccess '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/'); + } } } exec('chmod -R a+r '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/'); diff --git a/server/plugins-available/nginx_plugin.inc.php b/server/plugins-available/nginx_plugin.inc.php index 24c46ba..9ce9de8 100644 --- a/server/plugins-available/nginx_plugin.inc.php +++ b/server/plugins-available/nginx_plugin.inc.php @@ -531,6 +531,7 @@ if(!is_dir($data['new']['document_root'].'/' . $web_folder)) $app->system->mkdirpath($data['new']['document_root'].'/' . $web_folder); if(!is_dir($data['new']['document_root'].'/' . $web_folder . '/error') and $data['new']['errordocs']) $app->system->mkdirpath($data['new']['document_root'].'/' . $web_folder . '/error'); + if(!is_dir($data['new']['document_root'].'/' . $web_folder . '/stats')) $app->system->mkdirpath($data['new']['document_root'].'/' . $web_folder . '/stats'); //if(!is_dir($data['new']['document_root'].'/'.$log_folder)) exec('mkdir -p '.$data['new']['document_root'].'/'.$log_folder); if(!is_dir($data['new']['document_root'].'/ssl')) $app->system->mkdirpath($data['new']['document_root'].'/ssl'); if(!is_dir($data['new']['document_root'].'/cgi-bin')) $app->system->mkdirpath($data['new']['document_root'].'/cgi-bin'); @@ -652,26 +653,28 @@ } if (file_exists($conf['rootpath'] . '/conf-custom/index/standard_index.html_'.substr(escapeshellcmd($conf['language']), 0, 2))) { - exec('cp ' . $conf['rootpath'] . '/conf-custom/index/standard_index.html_'.substr(escapeshellcmd($conf['language']), 0, 2).' '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html'); + if(!file_exists(escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html')) exec('cp ' . $conf['rootpath'] . '/conf-custom/index/standard_index.html_'.substr(escapeshellcmd($conf['language']), 0, 2).' '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html'); if(is_file($conf['rootpath'] . '/conf-custom/index/favicon.ico')) { - exec('cp ' . $conf['rootpath'] . '/conf-custom/index/favicon.ico '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/'); + if(!file_exists(escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/favicon.ico')) exec('cp ' . $conf['rootpath'] . '/conf-custom/index/favicon.ico '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/'); } if(is_file($conf['rootpath'] . '/conf-custom/index/robots.txt')) { - exec('cp ' . $conf['rootpath'] . '/conf-custom/index/robots.txt '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/'); + if(!file_exists(escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/robots.txt')) exec('cp ' . $conf['rootpath'] . '/conf-custom/index/robots.txt '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/'); } //if(is_file($conf['rootpath'] . '/conf-custom/index/.htaccess')) { // exec('cp ' . $conf['rootpath'] . '/conf-custom/index/.htaccess '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/'); //} - } - else { + } else { if (file_exists($conf['rootpath'] . '/conf-custom/index/standard_index.html')) { - exec('cp ' . $conf['rootpath'] . '/conf-custom/index/standard_index.html '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html'); - } - else { - exec('cp ' . $conf['rootpath'] . '/conf/index/standard_index.html_'.substr(escapeshellcmd($conf['language']), 0, 2).' '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html'); - if(is_file($conf['rootpath'] . '/conf/index/favicon.ico')) exec('cp ' . $conf['rootpath'] . '/conf/index/favicon.ico '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/'); - if(is_file($conf['rootpath'] . '/conf/index/robots.txt')) exec('cp ' . $conf['rootpath'] . '/conf/index/robots.txt '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/'); + if(!file_exists(escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html')) exec('cp ' . $conf['rootpath'] . '/conf-custom/index/standard_index.html '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html'); + } else { + if(!file_exists(escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html')) exec('cp ' . $conf['rootpath'] . '/conf/index/standard_index.html_'.substr(escapeshellcmd($conf['language']), 0, 2).' '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html'); + if(is_file($conf['rootpath'] . '/conf/index/favicon.ico')){ + if(!file_exists(escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/favicon.ico')) exec('cp ' . $conf['rootpath'] . '/conf/index/favicon.ico '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/'); + } + if(is_file($conf['rootpath'] . '/conf/index/robots.txt')){ + if(!file_exists(escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/robots.txt')) exec('cp ' . $conf['rootpath'] . '/conf/index/robots.txt '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/'); + } //if(is_file($conf['rootpath'] . '/conf/index/.htaccess')) exec('cp ' . $conf['rootpath'] . '/conf/index/.htaccess '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/'); } } diff --git a/server/plugins-available/shelluser_base_plugin.inc.php b/server/plugins-available/shelluser_base_plugin.inc.php index a0ae9a5..d66428b 100755 --- a/server/plugins-available/shelluser_base_plugin.inc.php +++ b/server/plugins-available/shelluser_base_plugin.inc.php @@ -237,7 +237,7 @@ $app->system->chgrp(escapeshellcmd($data['new']['dir'].'/home'),escapeshellcmd($data['new']['pgroup'])); } $app->file->mkdirs(escapeshellcmd($homedir), '0750'); - $app->system->chown(escapeshellcmd($homedir),escapeshellcmd($data['new']['username'])); + $app->system->chown(escapeshellcmd($homedir),escapeshellcmd($data['new']['puser'])); $app->system->chgrp(escapeshellcmd($homedir),escapeshellcmd($data['new']['pgroup'])); $app->system->web_folder_protection($web['document_root'], true); } else { @@ -407,6 +407,12 @@ } $sshrsa = trim($sshrsa); $usrdir = escapeshellcmd($this->data['new']['dir']); + //* Home directory of the new shell user + if($this->data['new']['chroot'] == 'jailkit') { + $usrdir = escapeshellcmd($this->data['new']['dir']); + } else { + $usrdir = escapeshellcmd($this->data['new']['dir'].'/home/'.$this->data['new']['username']); + } $sshdir = $usrdir.'/.ssh'; $sshkeys= $usrdir.'/.ssh/authorized_keys'; diff --git a/server/scripts/run-getmail.sh b/server/scripts/run-getmail.sh index 81f897a..3eac5ec 100644 --- a/server/scripts/run-getmail.sh +++ b/server/scripts/run-getmail.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/X11R6/bin set -e cd /etc/getmail diff --git a/server/server.sh b/server/server.sh index 2d05d4f..9c92a86 100755 --- a/server/server.sh +++ b/server/server.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/X11R6/bin -- Gitblit v1.9.1