Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-mw committed Feb 23, 2023
1 parent ee18fff commit 8d039de
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 20 deletions.
46 changes: 28 additions & 18 deletions src/MicroweberPackages/User/helpers/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
function user_ip()
{
$ipaddress = '127.0.0.1';
$ipaddressDefault = '127.0.0.1';

if (isset($_SERVER['HTTP_CF_CONNECTING_IP'])) {
$ipaddress = $_SERVER['HTTP_CF_CONNECTING_IP'];
} else if (isset($_SERVER['HTTP_CLIENT_IP'])) {
} else if (isset($_SERVER['HTTP_CLIENT_IP'])) {
$ipaddress = $_SERVER['HTTP_CLIENT_IP'];
} else if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
Expand All @@ -25,6 +26,15 @@ function user_ip()
$ipaddress = $_SERVER['REMOTE_ADDR'];
}

$ipv4_validation_regex = "/^(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/";
$ipv6_validation_regex = "/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/";

if (!preg_match($ipv4_validation_regex, $ipaddress) and !preg_match($ipv6_validation_regex, $ipaddress)) {
//invalid ip is sent, so we return default ip
return $ipaddressDefault;
}


return $ipaddress;
}

Expand Down Expand Up @@ -241,7 +251,7 @@ function only_admin_access()

function is_admin()
{
if(app()->bound('user_manager')){
if (app()->bound('user_manager')) {
return app()->user_manager->is_admin();
}
}
Expand All @@ -264,12 +274,12 @@ function is_live_edit()
return true;
}

$editModeParam2 = app()->url_manager->param('editmode',true);
$editModeParam2 = app()->url_manager->param('editmode', true);
if ($editModeParam2 == 'y') {
return true;
}

if(defined('IN_EDIT') and IN_EDIT){
if (defined('IN_EDIT') and IN_EDIT) {
return true;
}

Expand Down Expand Up @@ -334,16 +344,16 @@ function get_users($params = false)
*
* get_user get the user info from the DB
*
* @category users
* @param bool $id
*
* @author Microweber
*
* @return array
* @link http://microweber.com
*
* @param bool $id
* @category users
*
* @author Microweber
*
* @return array
*/
function get_user($id = false)
{
Expand All @@ -363,7 +373,7 @@ function user_can_access($permission)
}

return false;
// return $user->can($permission);
// return $user->can($permission);
}

function module_permissions($module)
Expand All @@ -374,7 +384,7 @@ function module_permissions($module)

function user_can_destroy_module($module)
{
// $permissions = \MicroweberPackages\Role\Repositories\Permission::generateModulePermissionsSlugs($module);
// $permissions = \MicroweberPackages\Role\Repositories\Permission::generateModulePermissionsSlugs($module);

$user = \Illuminate\Support\Facades\Auth::user();
if (!$user) {
Expand All @@ -385,9 +395,9 @@ function user_can_destroy_module($module)
return true;
}

/* if ($user->can($permissions['destroy'])) {
return true;
}*/
/* if ($user->can($permissions['destroy'])) {
return true;
}*/

return false;
}
Expand All @@ -406,17 +416,17 @@ function user_can_view_module($module)
return true;
}

/* if ($user->can($permissions['index'])) {
return true;
}*/
/* if ($user->can($permissions['index'])) {
return true;
}*/

return false;

}



function detect_user_id_from_params($params){
function detect_user_id_from_params($params)
{

if (!empty($params)) {
if (isset($params['username']) || isset($params['email'])) {
Expand Down
8 changes: 6 additions & 2 deletions userfiles/modules/site_stats/src/Tracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ function process_buffer($track_data = false)
$browser_id = false;
$language = false;

if (isset($item['language']) and $item['language']) {
$item = array_map('strip_tags', $item);
$item = array_map('e', $item);
if (isset($item['language']) and $item['language']) {
$language = $item['language'];
}
if (isset($item['browser_agent']) and $item['browser_agent']) {
Expand Down Expand Up @@ -256,9 +258,11 @@ private function _collect_user_data()
$ref = $_POST['referrer'];
}
}

$ref = e($ref);

if ($last_page) {
$last_page = e($last_page);

$last_page = rtrim($last_page, '?');
$last_page = rtrim($last_page, '#');
}
Expand Down

0 comments on commit 8d039de

Please sign in to comment.