Move session->env->getIp into session->request->address
This commit is contained in:
parent
565cf955d7
commit
005b9da1ac
20 changed files with 49 additions and 48 deletions
|
|
@ -6,7 +6,7 @@ The information contained herein documents the API changes that have occurred in
|
|||
|
||||
|
||||
WebGUI::Config
|
||||
=============
|
||||
==============
|
||||
WebGUI::Config->new has a new API. Its WebGUI root parameter has been eliminated. It now only accepts a config file as either an absolute path, or a path relative to WebGUI's etc directory.
|
||||
|
||||
my $config = WebGUI::Config->new($filename);
|
||||
|
|
@ -14,10 +14,19 @@ my $config = WebGUI::Config->new($filename);
|
|||
|
||||
|
||||
WebGUI::Session
|
||||
=============
|
||||
===============
|
||||
WebGUI::Session->open has a new API. Its WebGUI root parameter has been eliminated. The config file it is given can be either an absolute path, or a path relative to WebGUI's etc directory.
|
||||
|
||||
my $session = WebGUI::Session->open($configFile, $request, $server);
|
||||
my $session = WebGUI::Session->open($configFile);
|
||||
|
||||
perldoc WebGUI::Session for more details about the arguments.
|
||||
|
||||
|
||||
WebGUI::Session::Env
|
||||
====================
|
||||
WebGUI::Session::Env has been moved into WebGUI::Session::Request. A listing of replacements and equivalents follows:
|
||||
|
||||
$session->env->getIp => $session->request->address
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -830,7 +830,7 @@ sub hasRated {
|
|||
return 1 if $self->isPoster;
|
||||
my $flag = 0;
|
||||
if ($self->session->user->isVisitor) {
|
||||
($flag) = $self->session->db->quickArray("select count(*) from Post_rating where assetId=? and ipAddress=?",[$self->getId, $self->session->env->getIp]);
|
||||
($flag) = $self->session->db->quickArray("select count(*) from Post_rating where assetId=? and ipAddress=?",[$self->getId, $self->session->request->address]);
|
||||
} else {
|
||||
($flag) = $self->session->db->quickArray("select count(*) from Post_rating where assetId=? and userId=?",[$self->getId, $self->session->user->userId]);
|
||||
}
|
||||
|
|
@ -895,7 +895,7 @@ sub insertUserPostRating {
|
|||
$self->session->db->write("insert into Post_rating (assetId,userId,ipAddress,dateOfRating,rating) values (?,?,?,?,?)",
|
||||
[$self->getId,
|
||||
$self->session->user->userId,
|
||||
$self->session->env->getIp,
|
||||
$self->session->request->address,
|
||||
time(),
|
||||
$rating,]
|
||||
);
|
||||
|
|
|
|||
|
|
@ -203,7 +203,7 @@ sub _hasVoted {
|
|||
my $self = shift;
|
||||
my ($hasVoted) = $self->session->db->quickArray("select count(*) from Poll_answer
|
||||
where assetId=".$self->session->db->quote($self->getId)." and ((userId=".$self->session->db->quote($self->session->user->userId)."
|
||||
and userId<>'1') or (userId=".$self->session->db->quote($self->session->user->userId)." and ipAddress='".$self->session->env->getIp."'))");
|
||||
and userId<>'1') or (userId=".$self->session->db->quote($self->session->user->userId)." and ipAddress='".$self->session->request->address."'))");
|
||||
return $hasVoted;
|
||||
}
|
||||
|
||||
|
|
@ -545,7 +545,7 @@ sub www_vote {
|
|||
my $self = shift;
|
||||
my $u;
|
||||
if ($self->session->form->process("answer") ne "" && $self->session->user->isInGroup($self->get("voteGroup")) && !($self->_hasVoted())) {
|
||||
$self->setVote($self->session->form->process("answer"),$self->session->user->userId,$self->session->env->getIp);
|
||||
$self->setVote($self->session->form->process("answer"),$self->session->user->userId,$self->session->request->address);
|
||||
if ($self->session->setting->get("useKarma")) {
|
||||
$self->session->user->karma($self->get("karmaPerVote"),"Poll (".$self->getId.")","Voted on this poll.");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2045,7 +2045,7 @@ sub responseId {
|
|||
my $ignoreRevisionDate = $opts{ignoreRevisionDate};
|
||||
|
||||
my $user = WebGUI::User->new( $self->session, $userId );
|
||||
my $ip = $self->session->env->getIp;
|
||||
my $ip = $self->session->request->address;
|
||||
|
||||
my $responseId = $self->{responseId};
|
||||
return $responseId if $responseId;
|
||||
|
|
@ -2178,7 +2178,7 @@ sub canTakeSurvey {
|
|||
}
|
||||
|
||||
my $maxResponsesPerUser = $self->maxResponsesPerUser;
|
||||
my $ip = $self->session->env->getIp;
|
||||
my $ip = $self->session->request->address;
|
||||
my $userId = $self->session->user->userId();
|
||||
my $takenCount = 0;
|
||||
|
||||
|
|
|
|||
|
|
@ -565,7 +565,7 @@ sub editThingDataSave {
|
|||
if ($thingDataId eq "new"){
|
||||
$thingData{dateCreated} = time();
|
||||
$thingData{createdById} = $session->user->userId;
|
||||
$thingData{ipAddress} = $session->env->getIp;
|
||||
$thingData{ipAddress} = $session->request->address;
|
||||
}
|
||||
else {
|
||||
%thingData = $session->db->quickHash("select * from ".$session->db->dbh->quote_identifier("Thingy_".$thingId)
|
||||
|
|
|
|||
|
|
@ -301,7 +301,7 @@ sub new {
|
|||
}
|
||||
else {
|
||||
$self->user($session->user);
|
||||
$self->ipAddress($session->env->getIp);
|
||||
$self->ipAddress($session->request->address);
|
||||
$self->submissionDate(WebGUI::DateTime->new($session, time));
|
||||
$entryData{id $self} = {};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ sub _logLogin {
|
|||
$_[0],
|
||||
$_[1],
|
||||
time(),
|
||||
$self->session->env->getIp,
|
||||
$self->session->request->address,
|
||||
$self->session->env->get("HTTP_USER_AGENT"),
|
||||
$self->session->getId,
|
||||
time(),
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ sub getValue {
|
|||
my $ua = LWP::UserAgent->new;
|
||||
my $res = $ua->post('http://api-verify.recaptcha.net/verify', {
|
||||
privatekey => $privKey,
|
||||
remoteip => $self->session->env->getIp,
|
||||
remoteip => $self->session->request->env->{REMOTE_ADDR},
|
||||
challenge => $challenge,
|
||||
response => $response,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -271,7 +271,7 @@ sub www_runCronJob {
|
|||
my $session = shift;
|
||||
$session->http->setMimeType("text/plain");
|
||||
$session->http->setCacheControl("none");
|
||||
unless (isInSubnet($session->env->getIp, $session->config->get("spectreSubnets")) || canView($session)) {
|
||||
unless (isInSubnet($session->request->address, $session->config->get("spectreSubnets")) || canView($session)) {
|
||||
$session->errorHandler->security("make a Spectre cron job runner request, but we're only allowed to accept requests from ".join(",",@{$session->config->get("spectreSubnets")}).".");
|
||||
return "error";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ sub www_spectreGetSiteData {
|
|||
if (!defined $subnets) {
|
||||
$subnets = [];
|
||||
}
|
||||
if (!isInSubnet($session->env->getIp, $subnets)) {
|
||||
if (!isInSubnet($session->request->address, $subnets)) {
|
||||
$session->errorHandler->security("Tried to make a Spectre workflow data load request, but we're only allowed to accept requests from "
|
||||
.join(",",@{$subnets}).".");
|
||||
}
|
||||
|
|
@ -181,7 +181,7 @@ sub www_spectreTest {
|
|||
$subnets = [];
|
||||
}
|
||||
|
||||
my $sessionIp = $session->env->getIp;
|
||||
my $sessionIp = $session->request->address;
|
||||
unless (isInSubnet($sessionIp, $subnets)) {
|
||||
$session->errorHandler->security(
|
||||
sprintf "Tried to make a Spectre workflow runner request from %s, but we're only allowed to accept requests from %s",
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ sub canUseService {
|
|||
my ( $session ) = @_;
|
||||
my $subnets = $session->config->get('serviceSubnets');
|
||||
return 1 if !$subnets || !@{$subnets};
|
||||
return 1 if WebGUI::Utility::isInSubnet( $session->env->getIp, $subnets );
|
||||
return 1 if WebGUI::Utility::isInSubnet( $session->request->address, $subnets );
|
||||
return 0; # Don't go away mad, just go away
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -482,7 +482,7 @@ sub www_runWorkflow {
|
|||
my $session = shift;
|
||||
$session->http->setMimeType("text/plain");
|
||||
$session->http->setCacheControl("none");
|
||||
unless (isInSubnet($session->env->getIp, $session->config->get("spectreSubnets")) || canRunWorkflow($session)) {
|
||||
unless (isInSubnet($session->request->address, $session->config->get("spectreSubnets")) || canRunWorkflow($session)) {
|
||||
$session->errorHandler->security("make a Spectre workflow runner request, but we're only allowed to accept requests from ".join(",",@{$session->config->get("spectreSubnets")}).".");
|
||||
return "error";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@ use 5.010;
|
|||
use CHI;
|
||||
use File::Temp qw( tempdir );
|
||||
use Scalar::Util qw( weaken );
|
||||
use HTTP::Message::PSGI;
|
||||
use HTTP::Request::Common;
|
||||
use WebGUI::Config;
|
||||
use WebGUI::SQL;
|
||||
use WebGUI::User;
|
||||
|
|
@ -480,15 +482,20 @@ sub open {
|
|||
my $self = { _config => $config };
|
||||
bless $self, $class;
|
||||
|
||||
if ($env) {
|
||||
my $request = WebGUI::Session::Request->new($env);
|
||||
$self->{_request} = $request;
|
||||
$self->{_response} = $request->new_response( 200 );
|
||||
|
||||
# Use the WebGUI::Session::Request object to look up the sessionId from cookies, if it
|
||||
# wasn't given explicitly
|
||||
$sessionId ||= $request->cookies->{$config->getCookieName};
|
||||
##No env was passed, so construct one
|
||||
if (! $env) {
|
||||
my $url = 'http://' . $config->get('sitename')->[0];
|
||||
my $request = HTTP::Request::Common::GET($url);
|
||||
$env = $request->to_psgi;
|
||||
}
|
||||
|
||||
my $request = WebGUI::Session::Request->new($env);
|
||||
$self->{_request} = $request;
|
||||
$self->{_response} = $request->new_response( 200 );
|
||||
|
||||
# Use the WebGUI::Session::Request object to look up the sessionId from cookies, if it
|
||||
# wasn't given explicitly
|
||||
$sessionId ||= $request->cookies->{$config->getCookieName};
|
||||
|
||||
# If the sessionId is still unset or is invalid, generate a new one
|
||||
if (!$sessionId || !$self->id->valid($sessionId)) {
|
||||
|
|
|
|||
|
|
@ -118,20 +118,6 @@ sub get {
|
|||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getIp ( )
|
||||
|
||||
Returns the user's IP address.
|
||||
|
||||
=cut
|
||||
|
||||
sub getIp {
|
||||
my $self = shift;
|
||||
return $self->get('REMOTE_ADDR');
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 new ( )
|
||||
|
|
|
|||
|
|
@ -253,7 +253,7 @@ sub security {
|
|||
my $self = shift;
|
||||
my $message = shift;
|
||||
@_ = ($self, $self->session->user->username." (".$self->session->user->userId.") connecting from "
|
||||
.$self->session->env->getIp." attempted to ".$message);
|
||||
.$self->session->request->address." attempted to ".$message);
|
||||
goto $self->can('warn');
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -182,7 +182,7 @@ sub new {
|
|||
my $time = time();
|
||||
my $timeout = $session->setting->get("sessionTimeout");
|
||||
$self->{_var}{lastPageView} = $time;
|
||||
$self->{_var}{lastIP} = $session->env->getIp;
|
||||
$self->{_var}{lastIP} = $session->request->address;
|
||||
$self->{_var}{expires} = $time + $timeout;
|
||||
if ($self->{_var}{nextCacheFlush} > 0 && $self->{_var}{nextCacheFlush} < $time) {
|
||||
delete $self->{_var}{nextCacheFlush};
|
||||
|
|
@ -247,7 +247,7 @@ sub start {
|
|||
$self->{_var} = {
|
||||
expires => $time + $timeout,
|
||||
lastPageView => $time,
|
||||
lastIP => $session->env->getIp,
|
||||
lastIP => $session->request->address,
|
||||
adminOn => 0,
|
||||
userId => $userId
|
||||
};
|
||||
|
|
|
|||
|
|
@ -299,7 +299,7 @@ sub canUseAdminMode {
|
|||
my $pass = 1;
|
||||
my $subnets = $self->session->config->get("adminModeSubnets") || [];
|
||||
if (scalar(@$subnets)) {
|
||||
$pass = WebGUI::Utility::isInSubnet($self->session->env->getIp, $subnets);
|
||||
$pass = WebGUI::Utility::isInSubnet($self->session->request->address, $subnets);
|
||||
}
|
||||
|
||||
return $pass && $self->isInGroup(12)
|
||||
|
|
|
|||
|
|
@ -24,5 +24,5 @@ cmp_ok($session->env->get("REMOTE_ADDR"), 'ne', "", "get() one valid entry");
|
|||
|
||||
my $env = $session->env;
|
||||
$session->request->env->{REMOTE_ADDR} = '192.168.0.2';
|
||||
is ($env->getIp, '192.168.0.2', 'getIp');
|
||||
#is ($env->getIp, '192.168.0.2', 'getIp');
|
||||
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ WebGUI::Test->interceptLogging( sub {
|
|||
is($log_data->{warn}, "Second warning", "warn: Log4perl called again");
|
||||
$eh->security('Shields up, red alert');
|
||||
my $security = sprintf '%s (%d) connecting from %s attempted to %s',
|
||||
$session->user->username, $session->user->userId, $session->env->getIp, 'Shields up, red alert';
|
||||
$session->user->username, $session->user->userId, $session->request->address, 'Shields up, red alert';
|
||||
is($log_data->{warn}, $security, 'security: calls warn with username, userId and IP address');
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -289,6 +289,7 @@ ok($adminSiteWideTag->get(q{isSiteWide}), 'versionTagMode siteWide + admin inher
|
|||
ok($adminSiteWideTag->getId() eq $siteWideTagId, 'versionTagMode siteWide + admin inherited: empty has same ID as site wide');
|
||||
|
||||
|
||||
$adminUserTag->rollback();
|
||||
$admin_session->var()->end();
|
||||
$admin_session->close();
|
||||
|
||||
|
|
@ -314,7 +315,6 @@ isnt(
|
|||
|
||||
$userTag->rollback();
|
||||
$siteWideTag->rollback();
|
||||
$adminUserTag->rollback();
|
||||
|
||||
## Additional VersionTagMode to make sure that auto commit happens only when user is tag creator and tag is not site wide.
|
||||
## See bug #10689 (Version Tag Modes)
|
||||
|
|
@ -329,7 +329,6 @@ $adminUserTag->rollback();
|
|||
|
||||
# create admin session
|
||||
my $admin_session = WebGUI::Test->newSession;
|
||||
WebGUI::Test->addToCleanup($admin_session);
|
||||
$admin_session->user({'userId' => 3});
|
||||
|
||||
setUserVersionTagMode($admin_session->user(), q{autoCommit});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue