Skip to content
Permalink
Browse files

Closes #146: Prefill parameter field with user's IP

  • Loading branch information
vincentbernat committed Feb 12, 2021
1 parent 4d95a68 commit 4f007003d5717a3d94fc989bdb9160d381d65a76
Showing with 25 additions and 20 deletions.
  1. +1 −9 execute.php
  2. +17 −0 includes/utils.php
  3. +7 −11 index.php
@@ -25,15 +25,7 @@
require_once('includes/utils.php');

// From where the user *really* comes from.
if ($config['misc']['enable_http_x_forwarded_for'] === true && isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
// The user can pass several proxy's, which each one will add its own IP address,
// so we like to take only the first IP address
$ips = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
$ip = trim($ips[0]);
$requester = is_valid_ip_address($ip) ? $ip : $_SERVER['REMOTE_ADDR']; // as a fallback we use the REMOTE_ADDR
} else {
$requester = $_SERVER['REMOTE_ADDR'];
}
$requester = get_requester_ip();

// Obvious spam
if (!isset($_POST['dontlook']) || !empty($_POST['dontlook'])) {
@@ -363,4 +363,21 @@ function quote($string) {
return sprintf('"%s"', $string);
}

/**
* Return IP address of the requester.
*/
function get_requester_ip() {
global $config;
if ($config['misc']['enable_http_x_forwarded_for'] === true && isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
// The user can pass several proxy's, which each one will add its own IP address,
// so we like to take only the first IP address
$ips = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
$ip = trim($ips[0]);
$requester = is_valid_ip_address($ip) ? $ip : $_SERVER['REMOTE_ADDR']; // as a fallback we use the REMOTE_ADDR
} else {
$requester = $_SERVER['REMOTE_ADDR'];
}
return $requester;
}

// End of utils.php
@@ -104,10 +104,15 @@ private function render_commands() {
}

private function render_parameter() {
if ($this->frontpage['show_visitor_ip']) {
$requester = htmlentities(get_requester_ip());
} else {
$requester = "";
}
print('<div class="form-group">');
print('<label for="input-param">Parameter</label>');
print('<div class="input-group">');
print('<input class="form-control" name="parameter" id="input-param" autofocus />');
print('<input class="form-control" name="parameter" id="input-param" autofocus value="'.$requester.'" />');
print('<div class="input-group-append">');
print('<button type="button" class="btn btn-info" data-toggle="modal" data-target="#help">');
print('<i class="fas fa-question-circle"></i> Help');
@@ -203,16 +208,7 @@ private function render_footer() {
print('<p class="text-center">');

if ($this->frontpage['show_visitor_ip']) {
if ($this->misc['enable_http_x_forwarded_for'] === true && isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
// The user can pass several proxy's, which each one will add its own IP address,
// so we like to take only the first IP address
$ips = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
$ip = trim($ips[0]);
$requester = is_valid_ip_address($ip) ? $ip : $_SERVER['REMOTE_ADDR']; // as a fallback we use the REMOTE_ADDR
printf('Your IP address: %s<br>', htmlentities($requester));
} else {
printf('Your IP address: %s<br>', htmlentities($_SERVER['REMOTE_ADDR']));
}
printf('Your IP address: %s<br>', htmlentities(get_requester_ip()));
}

if ($this->frontpage['disclaimer']) {

0 comments on commit 4f00700

Please sign in to comment.