2016-07-19 12:39:03 +02:00
< ? php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2012 Artica Soluciones Tecnologicas
// Please see http://pandorafms.org for full contribution list
// 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 for version 2.
// 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. See the
// GNU General Public License for more details.
// Only accesible by ajax
if ( is_ajax ()) {
global $config ;
check_login ();
2017-02-14 09:36:11 +01:00
$updare_rr = get_parameter ( 'updare_rr' , 0 );
2016-07-19 12:39:03 +02:00
2017-02-14 09:36:11 +01:00
if ( $updare_rr ) {
2016-07-19 12:39:03 +02:00
$number = get_parameter ( 'number' );
2017-03-16 16:00:57 +01:00
$package = get_parameter ( 'package' );
2017-03-16 18:23:07 +01:00
$ent = get_parameter ( 'ent' );
2017-03-16 19:14:19 +01:00
$offline = get_parameter ( 'offline' );
2017-03-16 18:23:07 +01:00
if ( ! $ent ) {
$dir = $config [ 'attachment_store' ] . " /last_package/downloads/extras/mr " ;
}
else {
2017-03-16 19:14:19 +01:00
if ( $offline ) {
$dir = $package . " extras/mr " ;
}
else {
$dir = sys_get_temp_dir () . " /pandora_oum/ " . $package . " /extras/mr " ;
}
2017-03-16 18:23:07 +01:00
}
2017-03-16 14:31:33 +01:00
$file = " $dir / $number .sql " ;
2016-07-19 13:48:56 +02:00
$dangerous_query = false ;
$mr_file = fopen ( $file , " r " );
while ( ! feof ( $mr_file )) {
$line = fgets ( $mr_file );
if (( preg_match ( " /^drop/ " , $line )) ||
2016-07-19 15:39:31 +02:00
( preg_match ( " /^truncate table/ " , $line ))) {
2016-07-19 13:48:56 +02:00
$dangerous_query = true ;
}
}
if ( $dangerous_query ) {
$error_file = fopen ( $config [ " homedir " ] . " /extras/mr/error.txt " , " w " );
2017-03-14 10:36:10 +01:00
$message = " <div> " ;
$message .= " <div style='width:25%; float:left'><img style='padding-left:20px; padding-top:20px;' src='images/icono_error_mr.png'></div> " ;
$message .= " <div style='width:75%; float:left;'><h3><strong style='font-family:Verdana; font-size:13pt;'>ERROR</strong></h3> " ;
2017-03-15 10:24:29 +01:00
$message .= " <p style='font-family:Verdana; font-size:12pt;'> " . __ ( 'The sql file contains a dangerous query' ) . " </p></div> " ;
2017-03-14 10:36:10 +01:00
$message .= " </div> " ;
2016-07-19 13:48:56 +02:00
fwrite ( $error_file , $message );
fclose ( $error_file );
}
else {
if ( file_exists ( $dir ) && is_dir ( $dir )) {
if ( is_readable ( $dir )) {
2017-03-15 09:36:31 +01:00
if (( $number > $config [ 'MR' ] + 1 ) || ( $number == $config [ 'MR' ])) {
2017-03-14 15:20:12 +01:00
$message = " bad_mr_filename " ;
}
2017-03-15 09:36:31 +01:00
else if ( $config [ " MR " ] > $number ) {
2016-07-19 13:48:56 +02:00
if ( ! file_exists ( $dir . " /updated " ) || ! is_dir ( $dir . " /updated " )) {
mkdir ( $dir . " /updated " );
}
2017-03-16 14:56:10 +01:00
$file_dest = $config [ " homedir " ] . " /extras/mr/updated/ $number .sql " ;
2016-07-19 13:48:56 +02:00
if ( copy ( $file , $file_dest )) {
unlink ( $file );
2016-07-19 12:39:03 +02:00
}
2017-03-16 16:28:27 +01:00
$message = " bad_mr_filename " ;
2016-07-19 13:48:56 +02:00
}
else {
$result = db_run_sql_file ( $file );
if ( $result ) {
2017-02-14 09:36:11 +01:00
$update_config = update_config_token ( " MR " , $number );
2016-07-19 13:48:56 +02:00
if ( $update_config ) {
2017-02-14 09:36:11 +01:00
$config [ " MR " ] = $number ;
2016-07-19 12:39:03 +02:00
}
2017-02-14 09:36:11 +01:00
if ( $config [ " MR " ] == $number ) {
2016-07-19 13:48:56 +02:00
if ( ! file_exists ( $dir . " /updated " ) || ! is_dir ( $dir . " /updated " )) {
mkdir ( $dir . " /updated " );
}
2017-03-16 14:56:10 +01:00
$file_dest = $config [ " homedir " ] . " /extras/mr/updated/ $number .sql " ;
2017-03-16 16:28:27 +01:00
if ( copy ( $file , $file_dest )) {
2016-07-19 13:48:56 +02:00
unlink ( $file );
}
2016-07-19 12:39:03 +02:00
}
}
2016-07-19 13:48:56 +02:00
else {
$error_file = fopen ( $config [ " homedir " ] . " /extras/mr/error.txt " , " w " );
2017-03-14 10:36:10 +01:00
$message = " <div> " ;
$message .= " <div style='width:25%; float:left'><img style='padding-left:20px; padding-top:20px;' src='images/icono_error_mr.png'></div> " ;
$message .= " <div style='width:75%; float:left;'><h3><strong style='font-family:Verdana; font-size:13pt;'>ERROR</strong></h3> " ;
2017-03-15 10:24:29 +01:00
$message .= " <p style='font-family:Verdana; font-size:12pt;'> " . __ ( 'An error occurred while updating the database schema to the minor release ' ) . $number . " </p></div> " ;
2017-03-14 10:36:10 +01:00
$message .= " </div> " ;
2016-07-19 13:48:56 +02:00
fwrite ( $error_file , $message );
fclose ( $error_file );
}
2016-07-19 12:39:03 +02:00
}
}
2016-07-19 13:48:56 +02:00
else {
$error_file = fopen ( $config [ " homedir " ] . " /extras/mr/error.txt " , " w " );
2017-03-14 10:36:10 +01:00
$message = " <div> " ;
$message .= " <div style='width:25%; float:left'><img style='padding-left:20px; padding-top:20px;' src='images/icono_error_mr.png'></div> " ;
$message .= " <div style='width:75%; float:left;'><h3><strong style='font-family:Verdana; font-size:13pt;'>ERROR</strong></h3> " ;
2017-03-15 10:24:29 +01:00
$message .= " <p style='font-family:Verdana; font-size:12pt;'> " . __ ( 'The directory ' ) . $dir . __ ( ' should have read permissions in order to update the database schema' ) . " </p></div> " ;
2017-03-14 10:36:10 +01:00
$message .= " </div> " ;
2016-07-19 13:48:56 +02:00
fwrite ( $error_file , $message );
fclose ( $error_file );
}
2016-07-19 12:39:03 +02:00
}
else {
$error_file = fopen ( $config [ " homedir " ] . " /extras/mr/error.txt " , " w " );
2017-03-14 10:36:10 +01:00
$message = " <div> " ;
$message .= " <div style='width:25%; float:left'><img style='padding-left:20px; padding-top:20px;' src='images/icono_error_mr.png'></div> " ;
$message .= " <div style='width:75%; float:left;'><h3><strong style='font-family:Verdana; font-size:13pt;'>ERROR</strong></h3> " ;
2017-03-15 10:24:29 +01:00
$message .= " <p style='font-family:Verdana; font-size:12pt;'> " . __ ( 'The directory ' ) . $dir . __ ( ' does not exist' ) . " </p></div> " ;
2017-03-14 10:36:10 +01:00
$message .= " </div> " ;
2016-07-19 12:39:03 +02:00
fwrite ( $error_file , $message );
fclose ( $error_file );
}
}
echo $message ;
return ;
}
}
?>