Skip to content

Commit

Permalink
Item12180: Adaptive bandwith management v0, sticky changes, revert DS…
Browse files Browse the repository at this point in the history
…N to default until Storable segfaults understood/fixed

git-svn-id: http://svn.foswiki.org/trunk@15967 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
TimotheLitt authored and TimotheLitt committed Nov 9, 2012
1 parent 2cf157a commit a8f15c3
Show file tree
Hide file tree
Showing 10 changed files with 295 additions and 41 deletions.
55 changes: 36 additions & 19 deletions core/bin/configure
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,26 @@ use warnings;
use constant COOKIEEXP => '61m'; # Lifetime of cookie
use constant SAVEEXP => '5m'; # Lifetime of cached save password
use constant RESOURCEEXP => '1m'; # Resource access window
use constant COOKIENAME => 'FOSWIKICFG2SID';
use constant COOKIENAME => 'FOSWIKICFG3SID'; # Change with DSN

use constant RESOURCECACHETIME => ( 30 * 24 * 60 * 60 )
; # MAX-AGE of cached resources
# in seconds. 0 to disable caching
; # MAX-AGE of cached resources
# in seconds. 0 to disable caching
}

{ # Constants that enable debugging code
{ # Constants that enable debugging code

package Foswiki;
use constant SESSIONTRACE => 0; # DEBUG temp
use constant SESSIONTRACE => 0; # DEBUG temp
use constant TRANSACTIONLOG => 0;

# Work-around for https://rt.cpan.org/Public/Bug/Display.html?id=80346
# (Taint failure when Storable is used for cookies with db_file.)

# use constant SESSION_DSN => "driver:file;serializer:default;id:md5";
use constant RT80346 => 1;
use constant SESSION_DSN => "driver:file;serializer:storable;id:md5";
#use constant SESSION_DSN => "driver:file;serializer:storable;id:md5"; # Use Cookie 2
use constant SESSION_DSN =>
"driver:file;serializer:default;id:md5"; # Use Cookie 3
use constant RT80346 => 0; # Set with Storable until fixed...

use constant DISPLAY_UNSAVED => 0;
}
Expand Down Expand Up @@ -196,7 +197,7 @@ package Foswiki;
my ( %cfg, $defaultCfg );

# Declared in Foswiki to support checkers
our $query = new CGI;
our $query = CGI->new;
our $session;

# 'constants' used in Foswiki.spec
Expand All @@ -218,6 +219,7 @@ our $configItemRegex;

our $sanityStatement;
our $unsavedChangesNotice = '';
our $newLogin;

our $time = time();

Expand Down Expand Up @@ -300,6 +302,8 @@ our $DEFAULT_FIELD_WIDTH_NO_CSS = '70';
undef $sid;
}

# Do we need a more permanent place than tmpdir (carts)?

$session =
CGI::Session->load( SESSION_DSN, $sid,
{ Directory => File::Spec->tmpdir } )
Expand Down Expand Up @@ -631,7 +635,7 @@ sub _getEnvironmentInfo {
# ######################################################################

sub unsavedChangesNotice {
my $updated = shift;
my ( $updated, $includeTime, $timeSaved ) = @_;

# Remove any {ConfigureGUI} pseudo-keys from %updated and count the rest.

Expand All @@ -647,17 +651,18 @@ sub unsavedChangesNotice {
my @pendingItems = map { { item => $_ } } sortHashkeyList( keys %$updated )
if (DISPLAY_UNSAVED);

my @args = (
pendingCount => $pending,
listPending => DISPLAY_UNSAVED,
pendingItems => \@pendingItems,
);
push @args, timesaved => scalar localtime($timeSaved) if ($includeTime);

my $pendingHtml =
Foswiki::Configure::UI::getTemplateParser()
->readTemplate('feedbackunsaved');
$pendingHtml = Foswiki::Configure::UI::getTemplateParser()->parse(
$pendingHtml,
{
pendingCount => $pending,
listPending => DISPLAY_UNSAVED,
pendingItems => \@pendingItems,
}
);
$pendingHtml = Foswiki::Configure::UI::getTemplateParser()
->parse( $pendingHtml, { @args, } );
Foswiki::Configure::UI::getTemplateParser()
->cleanupTemplateResidues($pendingHtml);

Expand Down Expand Up @@ -700,6 +705,17 @@ HERE
return $ui;
}

sub _validateDiscardChanges {
my ( $action, $session, $cookie ) = @_;

if ( $query->request_method() ne 'POST' ) {
invalidRequest( "", 405, Allow => 'POST' );
}

::_loadBasicModule('Foswiki::Configure::MainScreen');
return;
}

sub _validateLogout {
my ( $action, $session, $cookie ) = @_;

Expand Down Expand Up @@ -945,6 +961,7 @@ sub refreshLoggedIn {
print STDERR "Strace: Reflog "
. join( ', ', ( caller(1) )[ 0, 3, 1, 2 ] ) . "\n"
if (SESSIONTRACE);
$newLogin = !$session->param('_PASSWD_OK');
$session->param( '_PASSWD_OK', 1 );
$session->expires( '_PASSWD_OK', SESSIONEXP );

Expand Down Expand Up @@ -1015,7 +1032,7 @@ sub closeSession {
$session->clear(
[qw/_PASSWD_OK _SAVE_OK _RES_OK redirect redirectResults/] );

# $session->delete;
# Note that we do not clear 'pending' or delete the session

return;
}
Expand Down
30 changes: 30 additions & 0 deletions core/lib/Foswiki/Configure/Feedback.pm
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ feedback request has been received.
}

sub _actionfeedbackUI {

# my ( $action, $session, $cookie ) = @_;

binmode STDOUT;
_loadSiteConfig();

Expand All @@ -83,6 +86,7 @@ sub new {
# ######################################################################

sub deliver {
my ( $action, $session, $cookie ) = @_;
my $query = $Foswiki::query;

my $valuer =
Expand All @@ -97,6 +101,7 @@ sub deliver {
# Handle an unsaved changes request without any checking or UI

if ( $request eq '{ConfigureGUI}{Unsaved}status' ) {
checkpointChanges( $session, $query, \%updated );
deliverResponse( {}, \%updated );
}

Expand Down Expand Up @@ -187,6 +192,31 @@ sub deliver {
deliverResponse( $fb, \%updated );
}

# ######################################################################
# checkpointChanges
# ######################################################################

sub checkpointChanges {
my ( $session, $query, $updated ) = @_;

unless ( keys %$updated ) {
$session->clear('pending');
return;
}

require Foswiki::Configure::Feedback::Cart;

my $cart = Foswiki::Configure::Feedback::Cart->new( $query, $updated );

$session->param( 'pending', $cart );

return;
}

# ######################################################################
# Deliver feedback response message
# ######################################################################

sub deliverResponse {
my $fb = shift;
my $updated = shift;
Expand Down
100 changes: 100 additions & 0 deletions core/lib/Foswiki/Configure/Feedback/Cart.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# See bottom of file for license and copyright information

package Foswiki::Configure::Feedback::Cart;

=begin TML
"Shopping cart" holding unsaved changes.
Holds changes across sessions (esp. timeouts).
=cut

# ######################################################################
# new - create a new cart from %updated keys and $query values
# ######################################################################

sub new {
my $class = shift;
my ( $query, $updated ) = @_;

my $cart = { time => time };

foreach my $keys ( keys %$updated ) {
next if ( $keys =~ /^\{ConfigureGUI\}/ );

$cart->{param}{$keys} = [ $query->param($keys) ];
my $typeof = "TYPEOF:$keys";
$cart->{param}{$typeof} = [ $query->param($typeof) ];
}

bless $cart, $class;
}

# ######################################################################
# param - item accessor
# ######################################################################

sub param {
my $cart = shift;
my ($name) = @_;

return keys %{ $cart->{param} } unless (@_);

my $value = $cart->{param}{$name};
return unless ( defined $name && $value );

my @value = @$value;
return wantarray ? @result : $result[0];
}

# ######################################################################
# loadQuery - update $query with pending changes from $cart
# ######################################################################

sub loadQuery {
my $cart = shift;
my ($query) = @_;

foreach my $param ( keys %{ $cart->{param} } ) {
$query->param( $param, @{ $cart->{param}{$param} } );
}

return $cart->timeSaved;
}

# ######################################################################
# timeSaved - return time cart was saved
# ######################################################################

sub timeSaved {
my $cart = shift;

return $cart->{time};
}

1;
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2008-2010 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
Additional copyrights apply to some or all of the code in this
file as follows:
Copyright (C) 2000-2007 TWiki Contributors. All Rights Reserved.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. For
more details read LICENSE in the root of this distribution.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
As per the GPL, removal of this notice is prohibited.
73 changes: 67 additions & 6 deletions core/lib/Foswiki/Configure/MainScreen.pm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ loaded for resource or feedback requests.
=cut

our $sanityStatement;
our $newLogin;

# ######################################################################
# Main screen for configure
Expand Down Expand Up @@ -765,6 +766,9 @@ sub _screenSaveChanges {

undef $ui;

$session->clear('pending');
$session->flush;

# Build list of hashes with each changed key and its value(s) for template

my $changesList = [];
Expand Down Expand Up @@ -809,12 +813,6 @@ sub configureScreen {
}
$messages .= shift;

# Unless we already have status of unsaved changes, generate "none" status
# Also suppress if badLSC - the happy green checkmark would confuse.

$unsavedChangesNotice = unsavedChangesNotice( {} )
unless ( $unsavedChangesNotice || $badLSC );

my $contents = '';
my $isFirstTime = $badLSC;

Expand All @@ -826,6 +824,26 @@ sub configureScreen {
my $valuer =
new Foswiki::Configure::Valuer( $Foswiki::defaultCfg, \%Foswiki::cfg );

# If there's already a notice, don't use the cart
# E.g. MakeMoreChanges...

if ( !$unsavedChangesNotice && ( my $cart = $session->param('pending') ) ) {
require Foswiki::Configure::Feedback::Cart;

$cart->loadQuery($query);

my %updated;
$valuer->loadCGIParams( $query, \%updated );
$unsavedChangesNotice =
unsavedChangesNotice( \%updated, $newLogin, $cart->timeSaved );
}
else {
# Unless we already have status of unsaved changes, generate "none" status
# Also suppress if badLSC - the happy green checkmark would confuse.
$unsavedChangesNotice = unsavedChangesNotice( {} )
unless ( $unsavedChangesNotice || $badLSC );
}

# This is the root of the model
my $root = new Foswiki::Configure::Root();

Expand Down Expand Up @@ -959,6 +977,49 @@ sub _actionLogout {
rawRedirect($frontpageUrl);
}

# ######################################################################
# Discard changes
# ######################################################################

sub _authenticateDiscardChanges {
establishSession( $_[1], $_[2] );
my ( $action, $session, $cookie ) = @_;

_loadSiteConfig();

if ( loggedIn($session) || $badLSC || $query->auth_type ) {
$messageType = $MESSAGE_TYPE->{OK};
refreshLoggedIn($session);
refreshSaveAuthorized($session)
if ( $query->param('cfgAccess') || $badLSC );
return;
}

( my $authorised, $messageType ) =
Foswiki::Configure::UI::authorised($query);

if ($authorised) {
refreshLoggedIn($session);
refreshSaveAuthorized($session);
return;
}

htmlResponse( _screenAuthorize( $action, $messageType, 0 ) );

# does not return
}

sub _actionDiscardChanges {
my ( $action, $session, $cookie ) = @_;

$session->clear('pending');
$session->flush;

htmlResponse( configureScreen('') );

# does not return
}

# ######################################################################
# Require valid LocalSite.cfg
# ######################################################################
Expand Down
Binary file added core/lib/Foswiki/Configure/resources/cart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit a8f15c3

Please sign in to comment.