Skip to content

Commit

Permalink
Item14664: Add new checkers for WEB and TOPIC names
Browse files Browse the repository at this point in the history
Also let Bootstrap find an existing SitePreferences and adjust config
accordingly.

Fix bug in SCRIPTHASH where on occasion the script directory path was
not expanded.
  • Loading branch information
gac410 committed Apr 23, 2018
1 parent 4ec3caa commit 76a27fb
Show file tree
Hide file tree
Showing 10 changed files with 492 additions and 80 deletions.
5 changes: 3 additions & 2 deletions core/data/Main/WebHome.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
%META:TOPICINFO{author="ProjectContributor" date="1519617704" format="1.1" version="1"}%
%META:TOPICINFO{author="ProjectContributor" comment="" date="1524451936" format="1.1" version="1"}%
---+!! %MAKETEXT{"Welcome to the [_1] web" args="<nop>%WEB%"}%
Congratulations, you have finished installing Foswiki.

This site is running Foswiki release *%WIKIRELEASE%*, Plugin API version *%PLUGINVERSION{}%*

To learn more about Foswiki, visit the [[%SYSTEMWEB%.%HOMETOPIC%][%SYSTEMWEB% web]]. Please ensure that the read/write
permissions for each web on your site match your access control policies (see [[%SYSTEMWEB%.%WIKIPREFSTOPIC%]]
and [[%LOCALSITEPREFS%]]). Replace this text with a description of your new
%IF{"istopic '%LOCALSITEPREFS%'" then="and [[%LOCALSITEPREFS%]]" else="See [[System.InstallationGuidePart2]] for information on customizing your site preferences."}%). Replace this text with a description of your new
%IF{"defined WIKITOOLNAME" then="<nop>%WIKITOOLNAME%" else="Foswiki"}% site.

---++ <nop>%WEB% Web Utilities
Expand All @@ -20,4 +20,5 @@ and [[%LOCALSITEPREFS%]]). Replace this text with a description of your new
* [[WebRss]], [[WebAtom]] - RSS and ATOM news feeds of topic changes %IF{"istopic '%STATISTICSTOPIC%'" then="
* [[%STATISTICSTOPIC%]] - listing popular topics and top contributors"}%
* [[WebPreferences]] - preferences of this web

%META:PREFERENCE{name="ALLOWTOPICCHANGE" title="ALLOWTOPICCHANGE" type="Set" value="AdminGroup"}%
160 changes: 86 additions & 74 deletions core/lib/Foswiki.spec
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,92 @@ $Foswiki::cfg{WorkingDir} = '$Foswiki::cfg{RootDir}/working';
# created. It is normally set automatically in the code.
# $Foswiki::cfg{TempfileDir} = '';

#---++ Web and topic names
# Change default Web and Topic names used by Foswiki *Caution:*
# These should only be changed if you know what you are doing!
# Changing any of these settings requires you to manually rename
# the directories or files in the storage system external to Foswiki.
# If the webs are populated with topics and/or referenced from other topics
# and webs, topics will need to be manually edited to correct links.

#---+++ Web names
# **WEB 20 LABEL="Sandbox WebName" CHECK="exists"**
# Name of the web used as a scratchpad or temporary workarea for users to
# experiment with Foswiki topics.
$Foswiki::cfg{SandboxWebName} = 'Sandbox';

# **STRING 20 LABEL="System WebName" EXPERT CHECK="exists"**
# Name of the web where documentation and default preferences are held. If you
# change this setting, you must make sure the web exists and contains
# appropriate content, and upgrade scripts may no longer work (don't
# change it unless you are certain that you know what you are doing!)
$Foswiki::cfg{SystemWebName} = 'System';

# **WEB 20 LABEL="Trash WebName" CHECK="exists" **
# Name of the web used as a trashcan (where deleted topics are moved)
# If you change this setting, you must make sure the web exists.
$Foswiki::cfg{TrashWebName} = 'Trash';

# **WEB 20 LABEL="Users WebName" CHECK="exists"**
# Name of the web where user and group topics are stored. If you
# change this setting, you must make sure the web exists and contains
# appropriate content including all user and group templates. Note that
# this web also houses the SitePreferences topic.
# (don't change it unless you are *certain* that you know what
# you are doing!)
$Foswiki::cfg{UsersWebName} = 'Main';

# **WEB 20 LABEL="Configuration WebName" CHECK="exists" **
# Name of the web where the web based site configuration is stored.
# This web is normally hidden from guests. It can only be modified
# by members of the AdminGroup.
#$Foswiki::cfg{ConfigWebName} = 'System/Config';

#---+++ Topic names

# **TOPIC 20 LABEL="Home TopicName"**
# Name of main topic in a web.
# *If you change this setting you will have to
# use Foswiki to manually rename the topic in all existing webs*
# (don't change it unless you are *certain* that you know what
# you are doing!)
$Foswiki::cfg{HomeTopicName} = 'WebHome';

# **TOPIC 20 LABEL="DefaultPreferences TopicName" EXPERT CHECK="exists:{SystemWebName}" **
# Name of site-level preferences topic in the {SystemWebName} web.
# *If you change this setting you will have to
# use Foswiki and *manually* rename the existing topic.*
# (don't change it unless you are *certain* that you know what
# you are doing!)
$Foswiki::cfg{SitePrefsTopicName} = 'DefaultPreferences';

# **WEBTOPIC 70 LABEL="SitePreferences TopicName" CHECK="exists" **
# Web.TopicName of the site-level local preferences topic. If this topic
# exists, any settings in it will *override* settings in
# {SitePrefsTopicName}.
#
# You are *strongly* recommended to keep all your local changes in
# a {LocalSitePreferences} topic rather than changing DefaultPreferences,
# as it will make upgrading a lot easier.
$Foswiki::cfg{LocalSitePreferences} =
'$Foswiki::cfg{ConfigWebName}.SitePreferences';

# **TOPIC 20 LABEL="WebPreferences TopicName" EXPERT**
# Name of preferences topic in a web.
# *If you change this setting you will have to
# use Foswiki to manually rename the topic in all existing webs*
# (don't change it unless you are *certain* that you know what
# you are doing!)
$Foswiki::cfg{WebPrefsTopicName} = 'WebPreferences';

# **TOPIC 20 LABEL="Notification TopicName" EXPERT**
# Name of topic in each web that has notification registrations.
# *If you change this setting you will have to
# use Foswiki to manually rename the topic in all existing webs*
$Foswiki::cfg{NotifyTopicName} = 'WebNotify';



#############################################################################
#---+ Security and Authentication
# Control most aspects of how Foswiki handles security related activities.
Expand Down Expand Up @@ -2340,80 +2426,6 @@ $Foswiki::cfg{LeaseLengthLessForceful} = 3600;
# parameter is non-zero, you will be unable to save the configuration.
$Foswiki::cfg{MaxLSCBackups} = 10;

#---++ Web and topic names
# **STRING 20 LABEL="Sandbox WebName" EXPERT**
# Name of the web used as a scratchpad or temporary workarea for users to
# experiment with Foswiki topics.
$Foswiki::cfg{SandboxWebName} = 'Sandbox';

# **STRING 20 LABEL="System WebName" EXPERT**
# Name of the web where documentation and default preferences are held. If you
# change this setting, you must make sure the web exists and contains
# appropriate content, and upgrade scripts may no longer work (don't
# change it unless you are certain that you know what you are doing!)
$Foswiki::cfg{SystemWebName} = 'System';

# **STRING 20 LABEL="Trash WebName" EXPERT**
# Name of the web used as a trashcan (where deleted topics are moved)
# If you change this setting, you must make sure the web exists.
$Foswiki::cfg{TrashWebName} = 'Trash';

# **STRING 20 LABEL="Users WebName" EXPERT**
# Name of the web where user and group topics are stored. If you
# change this setting, you must make sure the web exists and contains
# appropriate content including all user and group templates. Note that
# this web also houses the SitePreferences topic.
# (don't change it unless you are *certain* that you know what
# you are doing!)
$Foswiki::cfg{UsersWebName} = 'Main';

# **STRING 20 LABEL="Configuration WebName" EXPERT**
# Name of the web where the web based site configuration is stored.
# This web is normally hidden from guests. It can only be modified
# by members of the AdminGroup.
$Foswiki::cfg{ConfigWebName} = 'System/Config';

# **STRING 20 LABEL="DefaultPreferences TopicName" EXPERT**
# Name of site-level preferences topic in the {SystemWebName} web.
# *If you change this setting you will have to
# use Foswiki and *manually* rename the existing topic.*
# (don't change it unless you are *certain* that you know what
# you are doing!)
$Foswiki::cfg{SitePrefsTopicName} = 'DefaultPreferences';

# **STRING 70 LABEL="SitePreferences TopicName" EXPERT**
# Web.TopicName of the site-level local preferences topic. If this topic
# exists, any settings in it will *override* settings in
# {SitePrefsTopicName}.
#
# You are *strongly* recommended to keep all your local changes in
# a {LocalSitePreferences} topic rather than changing DefaultPreferences,
# as it will make upgrading a lot easier.
$Foswiki::cfg{LocalSitePreferences} =
'$Foswiki::cfg{ConfigWebName}.SitePreferences';

# **STRING 20 LABEL="WebPreferences TopicName" EXPERT**
# Name of preferences topic in a web.
# *If you change this setting you will have to
# use Foswiki to manually rename the topic in all existing webs*
# (don't change it unless you are *certain* that you know what
# you are doing!)
$Foswiki::cfg{WebPrefsTopicName} = 'WebPreferences';

# **STRING 20 LABEL="Home TopicName" EXPERT**
# Name of main topic in a web.
# *If you change this setting you will have to
# use Foswiki to manually rename the topic in all existing webs*
# (don't change it unless you are *certain* that you know what
# you are doing!)
$Foswiki::cfg{HomeTopicName} = 'WebHome';

# **STRING 20 LABEL="Notification TopicName" EXPERT**
# Name of topic in each web that has notification registrations.
# *If you change this setting you will have to
# use Foswiki to manually rename the topic in all existing webs*
$Foswiki::cfg{NotifyTopicName} = 'WebNotify';

#---++ Compatibility
# This section contains options that you can use to enforce compatibility
# with older releases of Foswiki.
Expand Down
22 changes: 20 additions & 2 deletions core/lib/Foswiki/Configure/Bootstrap.pm
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ sub setBootstrap {

# Bootstrap works out the correct values of these keys
my @BOOTSTRAP =
qw( {DefaultUrlHost} {ForceDefaultUrlHost} {DetailedOS} {OS} {PubUrlPath}
qw( {ConfigWebName} {DefaultUrlHost} {ForceDefaultUrlHost} {DetailedOS} {OS} {PubUrlPath}
{ScriptUrlPath} {ScriptUrlPaths}{view}
{ScriptSuffix} {Store}{Implementation} {NFCNormalizeFilenames}
{Store}{SearchAlgorithm} {Site}{Locale} );
Expand Down Expand Up @@ -256,6 +256,23 @@ sub bootstrapConfig {
# Bootstrap the store related settings.
_bootstrapStoreSettings();

# Detect an existing SitePreferences.txt. If it exists, set ConfigWebName to the containing web,
# otherwise set it to the default. Note that we can't use the {LocalSitePreferencess} key, as it includes
# a reference to another key which will be undefined at this time.
#
# SMELL: This is setting some hard coded defaults which should be applied after the
# next readConfig is executed.
if ( -e "$Foswiki::cfg{DataDir}/Main/SitePreferences.txt" ) {
print STDERR
"AUTOCONFIG: Detected an existing SitePreferences.txt in Main web \n";
$Foswiki::cfg{ConfigWebName} = "Main";
}
else {
$Foswiki::cfg{ConfigWebName} = "System/Config";
}
print STDERR
"AUTOCONFIG: ConfigWebName set to $Foswiki::cfg{ConfigWebName} \n";

if ($fatal) {
die <<EPITAPH;
Unable to bootstrap configuration. LocalSite.cfg could not be loaded,
Expand Down Expand Up @@ -432,6 +449,7 @@ sub _bootstrapStoreSettings {
print STDERR "AUTOCONFIG: WARNING: Unable to detect Normalization.\n";
$Foswiki::cfg{NFCNormalizeFilenames} = 1; #enable too - safer as none
}

}

=begin TML
Expand Down Expand Up @@ -669,7 +687,7 @@ BOOTS
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2008-2015 Foswiki Contributors. Foswiki Contributors
Copyright (C) 2008-2018 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
Expand Down
152 changes: 152 additions & 0 deletions core/lib/Foswiki/Configure/Checkers/ConfigWebName.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
# See bottom of file for license and copyright information
package Foswiki::Configure::Checkers::ConfigWebName;

use strict;
use warnings;

use Assert;
use Foswiki::Configure::Checkers::WEBTOPIC ();
our @ISA = ('Foswiki::Configure::Checkers::WEBTOPIC');

use Foswiki::Configure::FileUtil ();

sub check_current_value {
my ( $this, $reporter ) = @_;

$this->SUPER::check_current_value($reporter);
}

=begin TML
---++ ObjectMethod onSave()
This routine is called during the Save wizard, when !ConfigWebName is
saved, regardless of whether or not it has actually changed. This
is enabled by including the ONSAVE key in the Spec.
This routine will create a missing ConfigWebName, and migrate the obsolete
{RCS}{WorkAreaDir}. to the new ConfigWebName.
If compression is enabled, it also compresses the language file.
=cut

sub XXXonSave {
my ( $this, $reporter, $key, $d, $old_dir ) = @_;

$d =~ s/\$Foswiki::cfg(\{\w+\})+/eval( "\$Foswiki::cfg$1")/ge;
$old_dir =~ s/\$Foswiki::cfg(\{\w+\})+/eval( "\$Foswiki::cfg$1")/ge;

return if ( $d eq $old_dir );

# SMELL: In a suexec environment, umask is forced to 077, blocking
# group and world access. This is probably not bad for the working
# directories. But noting smell if mismatched permissions are questioned.
# ... Enabled the umask override.

my $saveumask = umask(
( oct(777) - $Foswiki::cfg{Store}{dirPermission} + 0 ) & oct(777) );

unless ( -d $d ) {
mkdir( $d, oct(755) )
|| return $reporter->ERROR(
"$d does not exist, and I can't create it: $!");
$reporter->NOTE("Created $d");
}

unless ( -d "$d/tmp" ) {
if ( -e "$d/tmp" ) {
$reporter->ERROR("$d/tmp already exists, but is not a directory");
}
elsif ( !mkdir( "$d/tmp", oct(1777) ) ) {
$reporter->ERROR("Could not create $d/tmp");
}
else {
$reporter->NOTE("Created $d/tmp");
}
}

unless ( -d "$d/logs" ) {
if ( -e "$d/logs" ) {
$reporter->ERROR("$d/logs already exists, but is not a directory");
}
elsif ( !mkdir( "$d/logs", oct(755) ) ) {
$reporter->ERROR("Could not create $d/logs");
}
else {
$reporter->NOTE("Created $d/logs");
}
}

unless ( -d "$d/work_areas" ) {
if ( -e "$d/work_areas" ) {
$reporter->ERROR(
"$d/work_areas already exists, but is not a directory");
}
elsif ( !mkdir( "$d/work_areas", oct(755) ) ) {
$reporter->ERROR("Could not create $d/work_areas");
}
else {
$reporter->NOTE("Created $d/work_areas");
}
}

# Automatic upgrade of work_areas
my $existing = $old_dir || $Foswiki::cfg{Store}{WorkAreaDir} || '';
$existing =~ s/\$Foswiki::cfg(\{\w+\})+/eval( "$Foswiki::cfg$1")/ge;
if ( $existing && -d $existing ) {

# Try and move the contents of the old workarea
my @report =
Foswiki::Configure::FileUtil::copytree( $existing, "$d/work_areas" );
if (@report) {
$reporter->ERROR(@report);
}
else {
$reporter->WARN( "
You have an existing {Store}{WorkAreaDir} ($Foswiki::cfg{Store}{WorkAreaDir}),
so I have copied the contents of that directory into the new
$d/work_areas. You should delete the old
$Foswiki::cfg{Store}{WorkAreaDir} when you are happy with
the upgrade." );
delete( $Foswiki::cfg{Store}{WorkAreaDir} );
}
}

unless ( -d "$d/registration_approvals" ) {
if ( -e "$d/registration_approvals" ) {
$reporter->ERROR(
"$d/registration_approvals already exists, but is not a directory"
);
}
elsif ( !mkdir( "$d/registration_approvals", oct(755) ) ) {
$reporter->ERROR("Could not create $d/registration_approvals");
}
}

umask($saveumask);

my $report = Foswiki::Configure::FileUtil::checkTreePerms( $d, 'rw',
filter => qr/configure\/backup\/|README/ );
$reporter->ERROR( @{ $report->{messages} } );
}

1;
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2014-2018 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
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.
Loading

0 comments on commit 76a27fb

Please sign in to comment.