Corrected errors and revamped writing of options file.

git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@328 e3e1d417-86f3-4887-817a-d78f3d33393f
This commit is contained in:
stan 2003-01-15 13:49:51 +00:00
parent c74ab0cff0
commit 75ecd91fb4
1 changed files with 14 additions and 19 deletions

View File

@ -63,7 +63,7 @@ my %types =
file => { hint => 'filename', parse => sub { return( int($_[0] =~ /^([a-zA-Z0-9-_.]+)$/ ), $1 ) } }, file => { hint => 'filename', parse => sub { return( int($_[0] =~ /^([a-zA-Z0-9-_.]+)$/ ), $1 ) } },
hostname => { hint => 'host.your.domain', parse => sub { return( int($_[0] =~ /^([a-zA-Z0-9_.-]+)$/ ), $1 ) } }, hostname => { hint => 'host.your.domain', parse => sub { return( int($_[0] =~ /^([a-zA-Z0-9_.-]+)$/ ), $1 ) } },
url => { hint => 'http://host.your.domain/', parse => sub { return( int($_[0] =~ /^(?:http:\/\/)?(.+)$/ ), 'http://'.$1 ) } }, url => { hint => 'http://host.your.domain/', parse => sub { return( int($_[0] =~ /^(?:http:\/\/)?(.+)$/ ), 'http://'.$1 ) } },
email => { hint => 'your.name@your.domain/', parse => sub { return( int($_[0] =~ /^([a-zA-Z0-9_-.]+)\@([a-zA-Z0-9_-.]+)$/ ), "$1\@$2" ) } }, email => { hint => 'your.name@your.domain/', parse => sub { return( int($_[0] =~ /^([a-zA-Z0-9_.-]+)\@([a-zA-Z0-9_.-]+)$/ ), "$1\@$2" ) } },
string => { hint => 'string', parse => sub { return( int($_[0] =~ /^([a-zA-Z0-9-_]+)$/ ), $1 ) } }, string => { hint => 'string', parse => sub { return( int($_[0] =~ /^([a-zA-Z0-9-_]+)$/ ), $1 ) } },
boolean => { hint => 'yes/no', parse => sub { return( int($_[0] =~ /^([yn])/i ), ($1 && $1 =~ /^y/) ? 'yes' : 'no' ) } }, boolean => { hint => 'yes/no', parse => sub { return( int($_[0] =~ /^([yn])/i ), ($1 && $1 =~ /^y/) ? 'yes' : 'no' ) } },
integer => { hint => 'integer', parse => sub { return( int($_[0] =~ /^(\d+)$/ ), $1 ) } }, integer => { hint => 'integer', parse => sub { return( int($_[0] =~ /^(\d+)$/ ), $1 ) } },
@ -358,7 +358,7 @@ my @options =
name => "ZM_OPT_EMAIL", name => "ZM_OPT_EMAIL",
default => "no", default => "no",
description => "Should ZoneMinder email you details of events that match corresponding filters", description => "Should ZoneMinder email you details of events that match corresponding filters",
help => "In ZoneMinder you can create event filters that specify whether events that match certain criteria should have their details emailed to you at a designated email address. This will allow you to be notified of events as soon as they occur and also to quickly view the events directly. This option specifies whether this functionality should be available. The email created with this option can be any size and is intended to be sent to a regular email reader rather than a mobile device." help => "In ZoneMinder you can create event filters that specify whether events that match certain criteria should have their details emailed to you at a designated email address. This will allow you to be notified of events as soon as they occur and also to quickly view the events directly. This option specifies whether this functionality should be available. The email created with this option can be any size and is intended to be sent to a regular email reader rather than a mobile device.",
type => $types{boolean}, type => $types{boolean},
}, },
{ {
@ -367,13 +367,13 @@ my @options =
description => "The email address to send matching event details to", description => "The email address to send matching event details to",
requires => [ { name => "ZM_OPT_EMAIL", value => "yes" } ], requires => [ { name => "ZM_OPT_EMAIL", value => "yes" } ],
help => "This option is used to define the email address that any events that match the appropriate filters will be sent to.", help => "This option is used to define the email address that any events that match the appropriate filters will be sent to.",
type => $types{string}, type => $types{email},
}, },
{ {
name => "ZM_OPT_MESSAGE", name => "ZM_OPT_MESSAGE",
default => "no", default => "no",
description => "Should ZoneMinder message you with details of events that match corresponding filters", description => "Should ZoneMinder message you with details of events that match corresponding filters",
help => "In ZoneMinder you can create event filters that specify whether events that match certain criteria should have their details sent to you at a designated short message email address. This will allow you to be notified of events as soon as they occur. This option specifies whether this functionality should be available. The email created by this option will be brief and is intended to be sent to an SMS gateway or a minimal mail reader such as a mobile device or phone rather than a regular email reader." help => "In ZoneMinder you can create event filters that specify whether events that match certain criteria should have their details sent to you at a designated short message email address. This will allow you to be notified of events as soon as they occur. This option specifies whether this functionality should be available. The email created by this option will be brief and is intended to be sent to an SMS gateway or a minimal mail reader such as a mobile device or phone rather than a regular email reader.",
type => $types{boolean}, type => $types{boolean},
}, },
{ {
@ -382,14 +382,14 @@ my @options =
description => "The email address to send matching event details to", description => "The email address to send matching event details to",
requires => [ { name => "ZM_OPT_MESSAGE", value => "yes" } ], requires => [ { name => "ZM_OPT_MESSAGE", value => "yes" } ],
help => "This option is used to define the short message email address that any events that match the appropriate filters will be sent to.", help => "This option is used to define the short message email address that any events that match the appropriate filters will be sent to.",
type => $types{string}, type => $types{email},
}, },
{ {
name => "ZM_FROM_EMAIL", name => "ZM_FROM_EMAIL",
default => "", default => "",
description => "The email address you wish your event notification emails to originate from", description => "The email address you wish your event notification emails to originate from",
requires => [ { name => "ZM_OPT_EMAIL", value => "yes" }, { name => "ZM_OPT_MESSAGE", value => "yes" } ], requires => [ { name => "ZM_OPT_EMAIL", value => "yes" }, { name => "ZM_OPT_MESSAGE", value => "yes" } ],
help => "The emails or messages that will be sent to you informing you of events can appear to come from a designated email address to help you with mail filtering etc. An address of something like ZoneMinder@your.domain is recommended." help => "The emails or messages that will be sent to you informing you of events can appear to come from a designated email address to help you with mail filtering etc. An address of something like ZoneMinder\@your.domain is recommended.",
type => $types{email}, type => $types{email},
}, },
{ {
@ -397,7 +397,7 @@ my @options =
default => "", default => "",
description => "The URL of your ZoneMinder installation", description => "The URL of your ZoneMinder installation",
requires => [ { name => "ZM_OPT_EMAIL", value => "yes" }, { name => "ZM_OPT_MESSAGE", value => "yes" } ], requires => [ { name => "ZM_OPT_EMAIL", value => "yes" }, { name => "ZM_OPT_MESSAGE", value => "yes" } ],
help => "The emails or messages that will be sent to you informing you of events can include a link to the events themselves for easy viewing. If you intend to use this feature then set this option to the url of your installation as it would appear from where you read your email, e.g. http://host.your.domain/zm.php." help => "The emails or messages that will be sent to you informing you of events can include a link to the events themselves for easy viewing. If you intend to use this feature then set this option to the url of your installation as it would appear from where you read your email, e.g. http://host.your.domain/zm.php.",
type => $types{url}, type => $types{url},
}, },
{ {
@ -655,6 +655,7 @@ foreach my $option ( @options )
$option->{value} = ''; $option->{value} = '';
} }
} }
if ( -s $config_file ) if ( -s $config_file )
{ {
loadOptions(); loadOptions();
@ -763,9 +764,8 @@ Press enter to continue: " );
} }
} }
} }
saveOptions();
} }
saveOptions();
sub saveOptions sub saveOptions
{ {
@ -786,7 +786,6 @@ sub loadOptions
print( "Loading '$config_file'\n" ); print( "Loading '$config_file'\n" );
open( CONFIG, "<$config_file" ) or die( "Can't open options file: $!" ); open( CONFIG, "<$config_file" ) or die( "Can't open options file: $!" );
local $/ = "\n\n"; local $/ = "\n\n";
my $rewrite_options = undef;
foreach my $section ( <CONFIG> ) foreach my $section ( <CONFIG> )
{ {
my ( $name, $value, $description ) = $section =~ /Name: (.*)\nValue: (.*)\nDescription: (.*)\n/ms; my ( $name, $value, $description ) = $section =~ /Name: (.*)\nValue: (.*)\nDescription: (.*)\n/ms;
@ -795,23 +794,14 @@ sub loadOptions
if ( !$option ) if ( !$option )
{ {
warn( "No option '$name' found, removing" ); warn( "No option '$name' found, removing" );
$rewrite_options = !undef;
next; next;
} }
if ( defined($value) ) if ( defined($value) )
{ {
$option->{value} = $value; $option->{value} = $value;
} }
else
{
$option->{value} = $option->{default};
}
} }
close( CONFIG ); close( CONFIG );
if ( $rewrite_options )
{
saveOptions();
}
} }
sub breaktext sub breaktext
@ -878,6 +868,11 @@ if ( $reprocess )
{ {
$data =~ s/^(use\s+constant\s+$opt_name\s*=>\s*).*$/$1$opt_value;\t# $opt_desc \(from zmconfig\)/mg; $data =~ s/^(use\s+constant\s+$opt_name\s*=>\s*).*$/$1$opt_value;\t# $opt_desc \(from zmconfig\)/mg;
} }
elsif ( $opt_type == $types{email} )
{
$opt_value =~ s/\@/\\\@/;
$data =~ s/^(use\s+constant\s+$opt_name\s*=>\s*).*$/$1"$opt_value";\t# $opt_desc \(from zmconfig\)/mg;
}
else else
{ {
$data =~ s/^(use\s+constant\s+$opt_name\s*=>\s*).*$/$1"$opt_value";\t# $opt_desc \(from zmconfig\)/mg; $data =~ s/^(use\s+constant\s+$opt_name\s*=>\s*).*$/$1"$opt_value";\t# $opt_desc \(from zmconfig\)/mg;