new config file format

This commit is contained in:
JT Smith 2006-02-03 02:04:49 +00:00
parent 01e1bf5a1b
commit 9ff0794746
5 changed files with 265 additions and 150 deletions

View file

@ -15,7 +15,9 @@
options for developers. options for developers.
- The group mail screen now allows sending of HTML messages. - The group mail screen now allows sending of HTML messages.
- Added prequery statements to the SQLReport and configurable allowed statements - Added prequery statements to the SQLReport and configurable allowed statements
to the databas link properties. (Martin Kamerbeek / Procolix) to the database link properties. (Martin Kamerbeek / Procolix)
- Converted config file format from PlainConfig to JSON. The new format is
more powerful and will use slightly less memory.
6.8.6 6.8.6
- Added logic to deal with case sensitivity and whitespace problems in LDAP - Added logic to deal with case sensitivity and whitespace problems in LDAP

View file

@ -36,6 +36,11 @@ save you many hours of grief.
POE::Component::IKC::Server POE::Component::IKC::Server
POE::Component::Client::UserAgent POE::Component::Client::UserAgent
* The upgrade script is going to convert your WebGUI config files
from the current PlainConfig format to the new JSON format.
Don't be alarmed by this, it's a normal part of the upgrade
procedure.
6.8.4 6.8.4
-------------------------------------------------------------------- --------------------------------------------------------------------

View file

@ -1,8 +1,12 @@
# config-file-type: JSON 1
{
# Add a comma separated list of the names this site can use. # Add a comma separated list of the names this site can use.
# The first site in the list will be used as the default # The first site in the list will be used as the default
# sitename for generating offline URLs and other functions. # sitename for generating offline URLs and other functions.
sitename = www.example.com, example.com "sitename" : [ "www.example.com", "example.com"],
# The location where the WebGUI server will be handling # The location where the WebGUI server will be handling
# requests. This is normally just '/' or the root of the # requests. This is normally just '/' or the root of the
@ -12,175 +16,190 @@ sitename = www.example.com, example.com
# contain the WebGUI handler instead in the Apache # contain the WebGUI handler instead in the Apache
# VirtualHost configuration. # VirtualHost configuration.
gateway = / "gateway" : "/",
# The relative or fully qualified URL to the extras folder # The relative or fully qualified URL to the extras folder
# that comes with WebGUI. # that comes with WebGUI.
extrasURL = /extras "extrasURL" : "/extras",
# The filesystem path to get to the extras folder that ships # The filesystem path to get to the extras folder that ships
# with WebGUI. # with WebGUI.
extrasPath = /data/WebGUI/www/extras "extrasPath" : "/data/WebGUI/www/extras",
# The relative for fully qualified URL to the uploads folder # The relative for fully qualified URL to the uploads folder
# for this site where all attachments will be stored. # for this site where all attachments will be stored.
uploadsURL = /uploads "uploadsURL" : "/uploads",
# The filesystem path to get to the uploads folder where all # The filesystem path to get to the uploads folder where all
# attachments for this site will be stored. This needs to be # attachments for this site will be stored. This needs to be
# writable by your web server. # writable by your web server.
uploadsPath = /data/WebGUI/www/uploads "uploadsPath" : "/data/WebGUI/www/uploads",
# An array of URLs that WebGUI should leave alone for normal # An array of URLs that WebGUI should leave alone for normal
# processing by Apache. Anything that begins with these URLs # processing by Apache. Anything that begins with these URLs
# will be entirely ignored by WebGUI # will be entirely ignored by WebGUI
# passthruUrls => /icons, /documentation/pdf, /my-custom-application, /server-status, /perl-status # "passthruUrls" : ["/icons", "/documentation/pdf", "/my-custom-application", "/server-status", "/perl-status"],
# Tell WebGUI where to store cached files. Defaults to the # Tell WebGUI where to store cached files. Defaults to the
# /tmp or c:\temp folder depending upon your operating system. # /tmp or c:\temp folder depending upon your operating system.
#fileCacheRoot=/path/to/cache # "fileCacheRoot" : "/path/to/cache",
# Tell WebGUI how big to let the file cache grow in bytes. # Tell WebGUI how big to let the file cache grow in bytes.
fileCacheSizeLimit=100000000 "fileCacheSizeLimit" : 100000000,
# Support for the memcached distributed caching system. # Support for the memcached distributed caching system.
# See http://www.danga.com/memcached/ for details on memcached. # See http://www.danga.com/memcached/ for details on memcached.
# Uncomment this and point it to your memcached server(s). Use a # Uncomment this and point it to your memcached server(s). Use a
# comma separated list for multiple servers. # comma separated list for multiple servers.
# memcached_servers = 10.0.0.6:11211 # "memcached_servers" : "10.0.0.6:11211",
# Set this to 1 to disable WebGUI's caching subsystems. This is # Set this to 1 to disable WebGUI's caching subsystems. This is
# mainly useful for developers. # mainly useful for developers.
disableCache = 0 "disableCache" : 0,
# The database connection string. It usually takes the form of # The database connection string. It usually takes the form of
# DBI:<driver>:<db>;host=<hostname> # DBI:<driver>:<db>;host:<hostname>
dsn = DBI:mysql:www_example_com "dsn" : "DBI:mysql:www_example_com;host=localhost",
# The username to authenticate to the above database. # The username to authenticate to the above database.
dbuser = webgui "dbuser" : "webgui",
# The password to authenticate to the above database. # The password to authenticate to the above database.
dbpass = password "dbpass" : "password",
# You can configure up to three read-only database slaves to # You can configure up to three read-only database slaves to
# increase WebGUI's read performance. # increase WebGUI's read performance.
#dbslave1 = dsn => DBI:mysql:www_example_com;host=dbslave1.example.com, \ # "dbslave1" : {
# user => webgui, \ # "dsn" : "DBI:mysql:www_example_com;host=dbslave1.example.com",
# pass => password # "user" : "webgui",
# "pass" : "password"
# },
#dbslave2 = dsn => DBI:mysql:www_example_com;host=dbslave2.example.com, \ # "dbslave2" : {
# user => webgui, \ # "dsn" : "DBI:mysql:www_example_com;host=dbslave2.example.com",
# pass => password # "user" : "webgui",
# "pass" : "password"
# },
#dbslave3 = dsn => DBI:mysql:www_example_com;host=dbslave3.example.com, \ # "dbslave3" : {
# user => webgui, \ # "dsn" : "DBI:mysql:www_example_com;host=dbslave3.example.com",
# pass => password # "user" : "webgui",
# "pass" : "password"
# },
# Set this value if you wish to override all outbound emails to a specific # Set this value if you wish to override all outbound emails to a specific
# user for testing purposes. # user for testing purposes.
#emailOverride = joe@example.com
# "emailOverride" : "joe@example.com",
# List the authentication plug-ins you wish to be available on # List the authentication plug-ins you wish to be available on
# this site. # this site.
authMethods = LDAP, WebGUI "authMethods" : [ "LDAP", "WebGUI" ],
# List the merchant gateways you have installed and wish to be # List the merchant gateways you have installed and wish to be
# available on this site. # available on this site.
paymentPlugins = ITransact "paymentPlugins" : ["ITransact"],
# List the shipping plugins you have installed and wish to be # List the shipping plugins you have installed and wish to be
# available for configuration on the site. # available for configuration on the site.
shippingPlugins = ByPrice, ByWeight, PerTransaction "shippingPlugins" : ["ByPrice", "ByWeight", "PerTransaction"],
# Specify the list of template parsers available in the system. # Specify the list of template parsers available in the system.
templateParsers = WebGUI::Asset::Template::HTMLTemplate "templateParsers" : ["WebGUI::Asset::Template::HTMLTemplate"],
# Specify the default template parser. # Specify the default template parser.
defaultTemplateParser = WebGUI::Asset::Template::HTMLTemplate "defaultTemplateParser" : ["WebGUI::Asset::Template::HTMLTemplate"],
# Specify external helper apps that will enable WebGUI's search # Specify external helper apps that will enable WebGUI's search
# engine to index content in various uploaded file formats. The # engine to index content in various uploaded file formats. The
# helpers must take the path to the file as an argument and # helpers must take the path to the file as an argument and
# return either text or html content. # return either text or html content.
searchIndexerPlugins = txt => "/bin/cat", \ "searchIndexerPlugins" : {
readme => "/bin/cat", \ "txt" : "/bin/cat",
html => "/bin/cat", \ "readme" : "/bin/cat",
htm => "/bin/cat" "html" : "/bin/cat",
"htm" : "/bin/cat"
},
# Specify a the list of assets you want to appear in your # Specify a the list of assets you want to appear in your
# Add Content menus. # Add Content menus.
assets = WebGUI::Asset::Snippet, \ "assets" : [
WebGUI::Asset::Redirect, \ "WebGUI::Asset::Snippet",
WebGUI::Asset::FilePile, \ "WebGUI::Asset::Redirect",
WebGUI::Asset::Wobject::Article, \ "WebGUI::Asset::FilePile",
WebGUI::Asset::Wobject::Collaboration, \ "WebGUI::Asset::Wobject::Article",
WebGUI::Asset::Wobject::DataForm, \ "WebGUI::Asset::Wobject::Collaboration",
WebGUI::Asset::Wobject::EventsCalendar, \ "WebGUI::Asset::Wobject::DataForm",
WebGUI::Asset::Wobject::EventManagementSystem, \ "WebGUI::Asset::Wobject::EventsCalendar",
WebGUI::Asset::Wobject::HttpProxy, \ "WebGUI::Asset::Wobject::EventManagementSystem",
WebGUI::Asset::Wobject::MessageBoard, \ "WebGUI::Asset::Wobject::HttpProxy",
WebGUI::Asset::Wobject::Navigation, \ "WebGUI::Asset::Wobject::MessageBoard",
WebGUI::Asset::Wobject::Matrix, \ "WebGUI::Asset::Wobject::Navigation",
WebGUI::Asset::Wobject::Poll, \ "WebGUI::Asset::Wobject::Matrix",
WebGUI::Asset::Wobject::Product, \ "WebGUI::Asset::Wobject::Poll",
WebGUI::Asset::Wobject::SQLReport, \ "WebGUI::Asset::Wobject::Product",
WebGUI::Asset::Wobject::Search, \ "WebGUI::Asset::Wobject::SQLReport",
WebGUI::Asset::Wobject::Survey, \ "WebGUI::Asset::Wobject::Search",
WebGUI::Asset::Wobject::WeatherData, \ "WebGUI::Asset::Wobject::Survey",
WebGUI::Asset::Wobject::MultiSearch, \ "WebGUI::Asset::Wobject::WeatherData",
WebGUI::Asset::Wobject::StockData, \ "WebGUI::Asset::Wobject::MultiSearch",
WebGUI::Asset::Wobject::SyndicatedContent, \ "WebGUI::Asset::Wobject::StockData",
WebGUI::Asset::Wobject::InOutBoard, \ "WebGUI::Asset::Wobject::SyndicatedContent",
WebGUI::Asset::File::ZipArchive, \ "WebGUI::Asset::Wobject::InOutBoard",
WebGUI::Asset::Wobject::WSClient "WebGUI::Asset::File::ZipArchive",
"WebGUI::Asset::Wobject::WSClient"
],
# Specify the list assets that are used for utility purposes only # Specify the list assets that are used for utility purposes only
# and are not typically used as a normal part of content # and are not typically used as a normal part of content
# management. # management.
utilityAssets = WebGUI::Asset::Template, WebGUI::Asset::RichEdit, WebGUI::Asset::File::Image, WebGUI::Asset::File "utilityAssets" : ["WebGUI::Asset::Template", "WebGUI::Asset::RichEdit", "WebGUI::Asset::File::Image", "WebGUI::Asset::File"],
# Specify the list of assets you want to appear in your add # Specify the list of assets you want to appear in your add
# content menus that should act as containers for other content. # content menus that should act as containers for other content.
# These items are typically not content themselves, but rather # These items are typically not content themselves, but rather
# layout mechanisms. # layout mechanisms.
assetContainers = WebGUI::Asset::Wobject::Layout, WebGUI::Asset::Wobject::Folder, WebGUI::Asset::Wobject::Dashboard "assetContainers" : ["WebGUI::Asset::Wobject::Layout", "WebGUI::Asset::Wobject::Folder", "WebGUI::Asset::Wobject::Dashboard"],
# Optionally specify a group id for assets to tell WebGUI what # Optionally specify a group id for assets to tell WebGUI what
# group a user needs to be part of in order to add that type of # group a user needs to be part of in order to add that type of
# asset. # asset.
#assetAddPrivilege = WebGUI::Asset::Wobject::SQLReport => 3, \ # "assetAddPrivilege" : {
# WebGUI:::Asset::Template => 4 # "WebGUI::Asset::Wobject::SQLReport" : 3,
# "WebGUI:::Asset::Template" : 4
# },
# Optionally override the default UI Level of any asset. This # Optionally override the default UI Level of any asset. This
# determines whether the current user has the appropriate UI Level # determines whether the current user has the appropriate UI Level
# to add assets of that type. # to add assets of that type.
#assetUiLevel = WebGUI::Asset::Wobject::WSClient => 7, # "assetUiLevel" : {
# WebGUI::Asset::RichEdit => 4 # "WebGUI::Asset::Wobject::WSClient" : 7,
# "WebGUI::Asset::RichEdit" : 4
# },
# You can override the UI Levels of any field in the edit form of # You can override the UI Levels of any field in the edit form of
# any asset using the following variables. Basically just take the # any asset using the following variables. Basically just take the
@ -188,127 +207,120 @@ assetContainers = WebGUI::Asset::Wobject::Layout, WebGUI::Asset::Wobject::Folder
# _uiLevel to the end of it, then you can start specifying field # _uiLevel to the end of it, then you can start specifying field
# names and associated UI Level. # names and associated UI Level.
#WebGUI_Asset_Wobject_Article_uiLevel = menuTitle => 9, url => 8 # "WebGUI_Asset_Wobject_Article_uiLevel" : { "menuTitle" : 9, "url" : 8 },
#WebGUI_Asset_RichEdit_uiLevel = askAboutRichEdit => 7, preformatted => 3 # "WebGUI_Asset_RichEdit_uiLevel" : { "askAboutRichEdit" : 7, "preformatted" : 3 },
# If exportPath is defined, an "Export" toolbar icon will appear # If exportPath is defined, an "Export" toolbar icon will appear
# which allows you to export assets to static HTML. This folder # which allows you to export assets to static HTML. This folder
# needs to be writable by your web server. # needs to be writable by your web server.
#exportPath = /path/to/export # "exportPath" : "/path/to/export",
# If soapHttpHeaderOverride is set to 1 it will enable Web # If soapHttpHeaderOverride is set to 1 it will enable Web
# Service Client assets to override the default MIME types of # Service Client assets to override the default MIME types of
# SOAP/WDSL content # SOAP/WDSL content
soapHttpHeaderOverride=0 "soapHttpHeaderOverride" : 0,
# Specify the number of days after an event has passed that it # Specify the number of days after an event has passed that it
# should be purged from the Events Calendar. Comment it out if # should be purged from the Events Calendar. Comment it out if
# you never want events to be purged automatically. # you never want events to be purged automatically.
DeleteExpiredEvents_offset = 30 "DeleteExpiredEvents_offset" : 30,
# Select the type of caching you'd like WebGUI to use for
# templates. Choose from file, ipc, memory, memory-ipc,
# memory-file
templateCacheType=file
# Specify the list of macros you wish to be processed on each page. # Specify the list of macros you wish to be processed on each page.
macros=# => Hash_userId, \ "macros" : {
/ => Slash_gatewayUrl, \ "#" : "Hash_userId",
@ => At_username, \ "/" : "Slash_gatewayUrl",
AOIHits => AOIHits, \ "@" : "At_username",
AOIRank => AOIRank, \ "AOIHits" : "AOIHits",
AdminBar => AdminBar, \ "AOIRank" : "AOIRank",
AdminText => AdminText, \ "AdminBar" : "AdminBar",
AdminToggle => AdminToggle, \ "AdminText" : "AdminText",
AssetProxy => AssetProxy, \ "AdminToggle" : "AdminToggle",
CanEditText => CanEditText, \ "AssetProxy" : "AssetProxy",
D => D_date, \ "CanEditText" : "CanEditText",
EditableToggle => EditableToggle, \ "D" : "D_date",
Extras => Extras, \ "EditableToggle" : "EditableToggle",
FetchMimeType => FetchMimeType, \ "Extras" : "Extras",
FileUrl => FileUrl, \ "FetchMimeType" : "FetchMimeType",
GroupAdd => GroupAdd, \ "FileUrl" : "FileUrl",
GroupDelete => GroupDelete, \ "GroupAdd" : "GroupAdd",
GroupText => GroupText, \ "GroupDelete" : "GroupDelete",
H => H_homeLink, \ "GroupText" : "GroupText",
International => International, \ "H" : "H_homeLink",
JavaScript => JavaScript, \ "International" : "International",
L => L_loginBox, \ "JavaScript" : "JavaScript",
LastModified => LastModified, \ "L" : "L_loginBox",
LoginToggle => LoginToggle, \ "LastModified" : "LastModified",
Page => Page, \ "LoginToggle" : "LoginToggle",
PageTitle => PageTitle, \ "Page" : "Page",
PageUrl => PageUrl, \ "PageTitle" : "PageTitle",
RandomAssetProxy => RandomAssetProxy, \ "PageUrl" : "PageUrl",
RandomThread => RandomThread, \ "RandomAssetProxy" : "RandomAssetProxy",
RawHeadTags => RawHeadTags, \ "RandomThread" : "RandomThread",
RootTitle => RootTitle, \ "RawHeadTags" : "RawHeadTags",
Spacer => Spacer, \ "RootTitle" : "RootTitle",
StyleSheet => StyleSheet, \ "Spacer" : "Spacer",
SubscriptionItem => SubscriptionItem, \ "StyleSheet" : "StyleSheet",
SubscriptionItemPurchaseUrl => SubscriptionItemPurchaseUrl, \ "SubscriptionItem" : "SubscriptionItem",
Thumbnail => Thumbnail, \ "SubscriptionItemPurchaseUrl" : "SubscriptionItemPurchaseUrl",
User => User, \ "Thumbnail" : "Thumbnail",
a => a_account, \ "User" : "User",
c => c_companyName, \ "a" : "a_account",
e => e_companyEmail, \ "c" : "c_companyName",
r => r_printable, \ "e" : "e_companyEmail",
u => u_companyUrl "r" : "r_printable",
"u" : "u_companyUrl"
# A comma separated list of scheduler plugins that you do NOT want },
# to run. Normally there's no reason to use this option.
#excludeHourly =
# How often, in seconds, should WebGUI calculate the statistics # How often, in seconds, should WebGUI calculate the statistics
# of passively profiling users to content preferences. Note that # of passively profiling users to content preferences. Note that
# this won't have any effect unless passive profiling is enabled # this won't have any effect unless passive profiling is enabled
# in the UI. # in the UI.
passiveProfileInterval = 86400 "passiveProfileInterval" : 86400,
# If specified, the user login log will delete login history # If specified, the user login log will delete login history
# information older than the specified value. It is specified in # information older than the specified value. It is specified in
# days. # days.
#CleanLoginHistory_ageToDelete = 90 # "CleanLoginHistory_ageToDelete" : 90,
# If minimum karma and decay factor are both specified, then a # If minimum karma and decay factor are both specified, then a
# user's karma will be decremented by the decay factor every hour # user's karma will be decremented by the decay factor every hour
# until the user has less than the minimum karma. # until the user has less than the minimum karma.
#DecayKarma_minimumKarma = 100 # "DecayKarma_minimumKarma" : 100,
#DecayKarma_decayFactor = 1 # "DecayKarma_decayFactor" : 1,
# Specify the number of days content should remain in the # Specify the number of days content should remain in the
# clipboard before being moved to the trash. # clipboard before being moved to the trash.
DeleteExpiredClipboard_offset = 30 "DeleteExpiredClipboard_offset" : 30,
# Specify the number of days content should remain in the trash # Specify the number of days content should remain in the trash
# before it gets purged from the system completely. # before it gets purged from the system completely.
DeleteExpiredTrash_offset = 30 "DeleteExpiredTrash_offset" : 30,
# Specify the number of days old revisions of assets should remain # Specify the number of days old revisions of assets should remain
# available for rollbacks. # available for rollbacks.
DeleteExpiredRevisions_offset = 365 "DeleteExpiredRevisions_offset" : 365,
# How many days after a piece of content expires should it be # How many days after a piece of content expires should it be
# moved to the trash. # moved to the trash.
TrashExpiredContent_offset = 30 "TrashExpiredContent_offset" : 30,
# What hour of the day (for example, 22 = 10 PM = 22:00:00) # What hour of the day (for example, 22 : 10 PM = 22:00:00)
# should WebGUI try to synchronize user profile information from # should WebGUI try to synchronize user profile information from
# the LDAP server. Note that this will only happen for users # the LDAP server. Note that this will only happen for users
# that have LDAP as their authentication. # that have LDAP as their authentication.
SyncProfilesToLDAP_hour = 2 "SyncProfilesToLDAP_hour" : 2
}

View file

@ -15,7 +15,7 @@ package WebGUI::Config;
=cut =cut
use strict; use strict;
use Parse::PlainConfig; use JSON;
use WebGUI::Utility; use WebGUI::Utility;
our %config; our %config;
@ -44,6 +44,40 @@ These subroutines are available from this package:
=cut =cut
#-------------------------------------------------------------------
=head2 delete ( param )
Deletes a key from the config file.
=head3 param
The name of the parameter to delete.
=cut
sub delete {
my $self = shift;
my $param = shift;
delete $self->{_config}{$param};
open(FILE,">".$self->getWebguiRoot.'/etc/'.$self->getFilename);
print FILE "# config-file-type: JSON 1\n".objToJson($self->{_config}, {pretty => 1, indent => 2});
close(FILE);
}
#-------------------------------------------------------------------
=head2 DESTROY ( )
Deconstructor.
=cut
sub DESTROY {
my $self = shift;
undef $self;
}
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 get ( param ) =head2 get ( param )
@ -59,17 +93,7 @@ The name of the parameter to return.
sub get { sub get {
my $self = shift; my $self = shift;
my $param = shift; my $param = shift;
my $value = $self->{_config}->get($param); return $self->{_config}{$param};
if (isIn($param, qw(sitename templateParsers assets utilityAssets assetContainers authMethods shippingPlugins paymentPlugins))) {
if (ref $value ne "ARRAY") {
$value = [$value];
}
} elsif (isIn($param, qw(assetAddPrivilege macros))) {
if (ref $value ne "HASH") {
$value = {};
}
}
return $value;
} }
@ -148,7 +172,13 @@ sub new {
if (exists $config{$filename}) { if (exists $config{$filename}) {
return $config{$filename}; return $config{$filename};
} else { } else {
my $conf = Parse::PlainConfig->new('DELIM' => '=', 'FILE' => $webguiPath.'/etc/'.$filename, 'PURGE' => 1); my $json = "";
open(FILE,"<".$webguiPath.'/etc/'.$filename);
while (my $line = <FILE>) {
$json .= $line unless ($line =~ /^\s*#/);
}
close(FILE);
my $conf = jsonToObj($json);
my $self = {_webguiRoot=>$webguiPath, _configFile=>$filename, _config=>$conf}; my $self = {_webguiRoot=>$webguiPath, _configFile=>$filename, _config=>$conf};
bless $self, $class; bless $self, $class;
$config{$filename} = $self; $config{$filename} = $self;
@ -186,9 +216,31 @@ sub readAllConfigs {
return \%configs; return \%configs;
} }
sub DESTROY {
my ($self) = @_; #-------------------------------------------------------------------
undef $self;
=head2 set ( param, value )
Creates a new or updates an existing parameter in the config file.
=head3 param
A parameter name.
=head3 value
The value to set the paraemter to. Can be a scalar, hash reference, or array reference.
=cut
sub set {
my $self = shift;
my $param = shift;
my $value = shift;
$self->{_config}{$param} = $value;
open(FILE,">".$self->getWebguiRoot.'/etc/'.$self->getFilename);
print FILE "# config-file-type: JSON 1\n".objToJson($self->{_config}, {pretty => 1, indent => 2});
close(FILE);
} }
1; 1;

View file

@ -15,12 +15,15 @@ BEGIN {
unshift (@INC, $webguiRoot."/lib"); unshift (@INC, $webguiRoot."/lib");
} }
use strict;
use DBI; use DBI;
use File::Path; use File::Path;
use Getopt::Long; use Getopt::Long;
use strict; use JSON;
use Parse::PlainConfig;
use WebGUI::Config; use WebGUI::Config;
use WebGUI::Session; use WebGUI::Session;
use WebGUI::Utility;
my $help; my $help;
my $history; my $history;
@ -141,6 +144,23 @@ our (%upgrade, %config);
## Find site configs. ## Find site configs.
print "\nTesting site config versions...\n" unless ($quiet);
opendir(DIR,"../etc");
my @files = readdir(DIR);
closedir(DIR);
foreach my $file (@files) {
next unless ($file =~ m/\.conf$/);
next if ($file eq "spectre.conf" || $file eq "log.conf");
my $configFile = "../etc/".$file;
open(FILE,"<".$configFile);
my $line = <FILE>;
close(FILE);
unless ($line =~ m/JSON 1/) {
print "\tConverting ".$file." from PlainConfig to JSON\n" unless ($quiet);
convertPlainconfigToJson($configFile);
}
}
print "\nGetting site configs...\n" unless ($quiet); print "\nGetting site configs...\n" unless ($quiet);
my $configs = WebGUI::Config->readAllConfigs($webguiRoot); my $configs = WebGUI::Config->readAllConfigs($webguiRoot);
foreach my $filename (keys %{$configs}) { foreach my $filename (keys %{$configs}) {
@ -380,3 +400,27 @@ sub _parseDSN {
} }
return $hash; return $hash;
} }
#-----------------------------------------
sub convertPlainconfigToJson {
my $configFile = shift;
my $pp = Parse::PlainConfig->new('DELIM' => '=', 'FILE' => $configFile, 'PURGE' => 1);
my %config = ();
foreach my $param ($pp->directives) {
my $value = $pp->get($param);
if (isIn($param, qw(sitename templateParsers assets utilityAssets assetContainers authMethods shippingPlugins paymentPlugins))) {
if (ref $value ne "ARRAY") {
$value = [$value];
}
} elsif (isIn($param, qw(assetAddPrivilege macros))) {
if (ref $value ne "HASH") {
$value = {};
}
}
$config{$param} = $value;
}
open(FILE,">".$configFile);
print FILE "# config-file-type: JSON 1\n".objToJson(\%config, {pretty => 1, indent => 2});
close(FILE);
}