Automatic cf ip detection

This commit is contained in:
Matteo Gheza 2020-06-17 12:05:10 +02:00
parent e063051c7e
commit 0167266fa9
3 changed files with 10 additions and 9 deletions

View File

@ -13,8 +13,4 @@ define( 'DB_PASSWORD', '@@password@@' );
define( 'DB_HOST', '@@host@@' );
/* Database hostname */
define( 'DB_PREFIX', '@@prefix@@' );
/* Is the server under Cloudflare® */
/* Cloudflare is a registered trademark of Cloudflare, Inc. */
define( 'SERVER_UNDER_CF', false );
define( 'DB_PREFIX', '@@prefix@@' );

View File

@ -12,8 +12,11 @@ session_start();
date_default_timezone_set('Europe/Rome');
class tools{
public function __construct(){
public $check_cf_ip;
public function __construct($check_cf_ip){
define("TOOLS", "OK");
$this->check_cf_ip = $check_cf_ip;
}
public function validate_form_data($data, $noempty=true, $value=null){
@ -82,7 +85,7 @@ class tools{
}else{
$ip = $_SERVER['REMOTE_ADDR'];
}
if(SERVER_UNDER_CF){
if($this->check_cf_ip){
if(!empty($_SERVER['HTTP_CF_CONNECTING_IP'])){
$ip = $_SERVER['HTTP_CF_CONNECTING_IP'];
}
@ -426,8 +429,8 @@ class user{
function init_class(){
global $user, $tools, $database;
if(!isset($user) && !isset($tools) && !isset($database)){
$tools = new tools();
$database = new database();
$tools = new tools($database->getOption("check_cf_ip"));
$user = new user($database, $tools);
}
//if($user->requireRole(Role::DEVELOPER)){

View File

@ -389,6 +389,7 @@ function initOptions($name, $visible, $password, $report_email, $owner){
$auth = new \Delight\Auth\Auth($connection, $_SERVER['REMOTE_ADDR'], $prefix."_");
$userId = $auth->register($report_email, $password, $name);
$auth->admin()->addRoleForUserById($userId, Role::SUPER_ADMIN);
$option_check_cf_ip = empty($_SERVER['HTTP_CF_CONNECTING_IP']) ? "INSERT INTO `".$prefix."_options` (`id`, `name`, `value`, `enabled`, `created_time`, `last_edit`, `user_id`) VALUES ('10', 'check_cf_ip', 1, '1', current_timestamp(), current_timestamp(), '1');" : "INSERT INTO `".$prefix."_options` (`id`, `name`, `value`, `enabled`, `created_time`, `last_edit`, `user_id`) VALUES ('10', 'check_cf_ip', 0, '1', current_timestamp(), current_timestamp(), '1');";
$prep = $connection->prepare("
INSERT INTO `".$prefix."_profiles` (`id`, `hidden`) VALUES (NULL, :hidden);
INSERT INTO `".$prefix."_options` (`id`, `name`, `value`, `enabled`, `created_time`, `last_edit`, `user_id`) VALUES ('1', 'report_email', :report_email, '1', current_timestamp(), current_timestamp(), '1');
@ -399,7 +400,8 @@ INSERT INTO `".$prefix."_options` (`id`, `name`, `value`, `enabled`, `created_ti
INSERT INTO `".$prefix."_options` (`id`, `name`, `value`, `enabled`, `created_time`, `last_edit`, `user_id`) VALUES ('6', 'intrusion_save', 1, '1', current_timestamp(), current_timestamp(), '1');
INSERT INTO `".$prefix."_options` (`id`, `name`, `value`, `enabled`, `created_time`, `last_edit`, `user_id`) VALUES ('7', 'intrusion_save_info', 1, '1', current_timestamp(), current_timestamp(), '1');
INSERT INTO `".$prefix."_options` (`id`, `name`, `value`, `enabled`, `created_time`, `last_edit`, `user_id`) VALUES ('8', 'enable_technical_support', 0, '1', current_timestamp(), current_timestamp(), '1');
INSERT INTO `".$prefix."_options` (`id`, `name`, `value`, `enabled`, `created_time`, `last_edit`, `user_id`) VALUES ('9', 'technical_support_key', '', '1', current_timestamp(), current_timestamp(), '1');");
INSERT INTO `".$prefix."_options` (`id`, `name`, `value`, `enabled`, `created_time`, `last_edit`, `user_id`) VALUES ('9', 'technical_support_key', '', '1', current_timestamp(), current_timestamp(), '1');
$option_check_cf_ip");
$prep->bindValue(':hidden', ($visible ? 0 : 1), PDO::PARAM_INT);
$prep->bindValue(':report_email', $report_email, PDO::PARAM_STR);
$prep->bindValue(':owner', $owner, PDO::PARAM_STR);