Mods, including escaping sql data.

git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@1706 e3e1d417-86f3-4887-817a-d78f3d33393f
pull/27/merge
stan 2005-12-21 00:10:31 +00:00
parent 8b30f67bcd
commit 533f3c2867
1 changed files with 43 additions and 12 deletions

View File

@ -25,12 +25,12 @@
#
use strict;
use ZoneMinder::ConfigAdmin;
use ZoneMinder::ConfigAdmin qw( :data );
$| = 1;
my $config_header = "src/zm_config_defines.h";
my $config_sql = "db/zm_config.sql";
my $config_sql = "db/zm_create.sql.in";
generateConfigFiles();
@ -115,11 +115,21 @@ sub generateConfigHeader
sub generateConfigSQL
{
print( "Generating '$config_sql'\n" );
open( CFG_SQL_FILE, ">$config_sql" ) or die( "Can't open '$config_sql' for writing" );
print( CFG_SQL_FILE "-- The file is autogenerated by zmconfgen.pl\n" );
print( CFG_SQL_FILE "-- Do not edit this file as any changes will be overwritten\n\n" );
print( CFG_SQL_FILE "delete from Config;\n\n" );
print( "Updating '$config_sql'\n" );
my $config_sql_temp = $config_sql.".temp";
open( CFG_SQL_FILE, "<$config_sql" ) or die( "Can't open '$config_sql' for reading" );
open( CFG_TEMP_SQL_FILE, ">$config_sql_temp" ) or die( "Can't open '$config_sql_temp' for writing" );
while ( my $line = <CFG_SQL_FILE> )
{
last if ( $line =~ /^-- This section is autogenerated/ );
print( CFG_TEMP_SQL_FILE $line );
}
close( CFG_SQL_FILE );
print( CFG_TEMP_SQL_FILE "-- This section is autogenerated by zmconfgen.pl\n" );
print( CFG_TEMP_SQL_FILE "-- Do not edit this file as any changes will be overwritten\n" );
print( CFG_TEMP_SQL_FILE "--\n\n" );
print( CFG_TEMP_SQL_FILE "delete from Config;\n\n" );
foreach my $option ( @options )
{
next if ( $option->{category} eq 'core' );
@ -145,11 +155,32 @@ sub generateConfigSQL
{
$option->{db_requires} = "";
}
printf( CFG_SQL_FILE
"replace into Config set Id = %d, Name = '%s', Value = '%s', Type = '%s', DefaultValue = '%s', Hint = '%s', Pattern = '%s', Format = '%s', Prompt = '%s', Help = '%s', Category = '%s', Readonly = '%s', Requires = '%s';\n",
$option->{id}, $option->{name}, $option->{db_value}, $option->{db_type}, $option->{default}, $option->{db_hint}, $option->{db_pattern}, $option->{db_format}, $option->{description}, $option->{help}, $option->{category}, $option->{readonly}?1:0, $option->{db_requires}
printf( CFG_TEMP_SQL_FILE
"insert into Config set Id = %d, Name = '%s', Value = '%s', Type = '%s', DefaultValue = '%s', Hint = '%s', Pattern = '%s', Format = '%s', Prompt = '%s', Help = '%s', Category = '%s', Readonly = '%s', Requires = '%s';\n",
$option->{id},
$option->{name},
addSlashes($option->{db_value}),
$option->{db_type},
addSlashes($option->{default}),
addSlashes($option->{db_hint}),
addSlashes($option->{db_pattern}),
addSlashes($option->{db_format}),
addSlashes($option->{description}),
addSlashes($option->{help}),
$option->{category},
$option->{readonly}?1:0,
$option->{db_requires}
);
}
print( CFG_SQL_FILE "\n" );
close( CFG_SQL_FILE );
print( CFG_TEMP_SQL_FILE "\n" );
close( CFG_TEMP_SQL_FILE );
rename( $config_sql_temp, $config_sql ) or die( "Can't rename '$config_sql_temp' to '$config_sql': $!" );
}
sub addSlashes
{
my $string = shift;
$string =~ s|(['"])|\\$1|g;
return( $string );
}