File: convert.php

package info (click to toggle)
loganalyzer 4.1.5%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 9,360 kB
  • ctags: 12,591
  • sloc: php: 56,221; sh: 66; makefile: 15
file content (282 lines) | stat: -rw-r--r-- 9,205 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
<?php
/*
	*********************************************************************
	* LogAnalyzer - http://loganalyzer.adiscon.com
	* -----------------------------------------------------------------
	* Configuration Converter File											
	*																	
	* -> Helps to convert from config file to userdb if desired 
	*																	
	* All directives are explained within this file
	*
	* Copyright (C) 2008-2010 Adiscon GmbH.
	*
	* This file is part of LogAnalyzer.
	*
	* LogAnalyzer 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 3 of the License, or
	* (at your option) any later version.
	*
	* LogAnalyzer 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.
	*
	* You should have received a copy of the GNU General Public License
	* along with LogAnalyzer. If not, see <http://www.gnu.org/licenses/>.
	*
	* A copy of the GPL can be found in the file "COPYING" in this
	* distribution				
	* 
	* Adiscon LogAnalyzer is also available under a commercial license.
	* For details, contact info@adiscon.com or visit
	* http://loganalyzer.adiscon.com/commercial
	*********************************************************************
*/


// *** Default includes	and procedures *** //
define('IN_PHPLOGCON', true);
define('IN_PHPLOGCON_CONVERT', true);		// Extra for CONVERT Script!
define('STEPSCRIPTNAME', "convert.php");	// Helper variable for the STEP helper functions
$gl_root_path = './';

// Now include necessary include files!
include($gl_root_path . 'include/functions_common.php');
include($gl_root_path . 'include/functions_frontendhelpers.php');
include($gl_root_path . 'include/functions_installhelpers.php');

// This site can not require LOGIN
define('IS_NOLOGINPAGE', true);
$content['IS_NOLOGINPAGE'] = true;
InitPhpLogCon();
InitSourceConfigs();
InitFrontEndDefaults();	// Only in WebFrontEnd

// --- PreCheck if conversion is allowed!
if ( 
		
		GetConfigSetting("UserDBEnabled", false) &&
		GetConfigSetting("UserDBConvertAllowed", false) 
	) 
{
	// Setup static values
	define('MAX_STEPS', 6);
	$content['web_theme'] = "default";
	$content['user_theme'] = "default";
}
else
	DieWithErrorMsg( $content['LN_CONVERT_ERRORINSTALLED'] );
// --- 

// --- CONTENT Vars
$content['TITLE'] = "LogAnalyzer :: " . $content['LN_CONVERT_TITLE'];
// --- 

// --- Read Vars
if ( isset($_GET['step']) )
{
	$content['CONVERT_STEP'] = intval(DB_RemoveBadChars($_GET['step']));
	if ( $content['CONVERT_STEP'] > MAX_STEPS ) 
		$content['CONVERT_STEP'] = 1;
}
else
	$content['CONVERT_STEP'] = 1;

// Set Next Step 
$content['CONVERT_NEXT_STEP'] = $content['CONVERT_STEP'];

if ( MAX_STEPS > $content['CONVERT_STEP'] )
{
	$content['NEXT_ENABLED'] = "true";
	$content['FINISH_ENABLED'] = "false";
	$content['CONVERT_NEXT_STEP']++;
}
else
{
	$content['NEXT_ENABLED'] = "false";
	$content['FINISH_ENABLED'] = "true";
}
// --- 

// --- BEGIN Custom Code

// Set Bar Images
$content['BarImagePlus'] = $gl_root_path . "images/bars/bar-middle/green_middle_17.png";
$content['BarImageLeft'] = $gl_root_path . "images/bars/bar-middle/green_left_17.png";
$content['BarImageRight'] = $gl_root_path . "images/bars/bar-middle/green_right_17.png";
$content['WidthPlus'] = intval( $content['CONVERT_STEP'] * (100 / MAX_STEPS) ) - 8;
$content['WidthPlusText'] = "Installer Step " . $content['CONVERT_STEP'];

// --- Set Title
$content['TITLE'] = GetAndReplaceLangStr( $content['TITLE'], $content['CONVERT_STEP'] );
$content['LN_CONVERT_TITLETOP'] = GetAndReplaceLangStr( $content['LN_CONVERT_TITLETOP'], $content['CONVERT_STEP'] );
// --- 

// --- Start Setup Processing
if ( $content['CONVERT_STEP'] == 2 )
{	
	// Check the database connect
	$link_id = mysql_connect( GetConfigSetting("UserDBServer"), GetConfigSetting("UserDBUser"), GetConfigSetting("UserDBPass") );
	if (!$link_id) 
		RevertOneStep( $content['CONVERT_STEP']-1, GetAndReplaceLangStr( $content['LN_INSTALL_ERRORCONNECTFAILED'], GetConfigSetting("UserDBServer") . "<br>" . DB_ReturnSimpleErrorMsg() ) );
	
	// Try to select the DB!
	$db_selected = mysql_select_db(GetConfigSetting("UserDBName"), $link_id);
	if(!$db_selected) 
		RevertOneStep( $content['CONVERT_STEP']-1,GetAndReplaceLangStr( $content['LN_INSTALL_ERRORACCESSDENIED'], GetConfigSetting("UserDBName") . "<br>" . DB_ReturnSimpleErrorMsg() ) );
}
else if ( $content['CONVERT_STEP'] == 3 )
{	
	// Predefine sql helper vars
	$content['sql_sucess'] = 0;
	$content['sql_failed'] = 0;

	// Init $totaldbdefs
	$totaldbdefs = "";

	// Read the table GLOBAL definitions 
	ImportDataFile( $content['BASEPATH'] . "include/db_template.txt" );

	// Process definitions ^^
	if ( strlen($totaldbdefs) <= 0 )
	{
		$content['failedstatements'][ $content['sql_failed'] ]['myerrmsg'] = GetAndReplaceLangStr( $content['LN_INSTALL_ERRORINVALIDDBFILE'], $content['BASEPATH'] . "include/db_template.txt");
		$content['failedstatements'][ $content['sql_failed'] ]['mystatement'] = "";
		$content['sql_failed']++;
	}

	// Replace stats_ with the custom one ;)
	$totaldbdefs = str_replace( "`logcon_", "`" . GetConfigSetting("UserDBPref"), $totaldbdefs );
	
	// Now split by sql command
	$mycommands = split( ";\n", $totaldbdefs );
	
//		// check for different linefeed
//		if ( count($mycommands) <= 1 )
//			$mycommands = split( ";\n", $totaldbdefs );

	//Still only one? Abort
	if ( count($mycommands) <= 1 )
	{
		$content['failedstatements'][ $content['sql_failed'] ]['myerrmsg'] = GetAndReplaceLangStr( $content['LN_INSTALL_ERRORINSQLCOMMANDS'], $content['BASEPATH'] . "include/db_template.txt"); 
		$content['failedstatements'][ $content['sql_failed'] ]['mystatement'] = "";
		$content['sql_failed']++;
	}

	// Append INSERT Statement for Config Table to set the Database Version ^^!
	$mycommands[count($mycommands)] = "INSERT INTO `" . GetConfigSetting("UserDBPref") . "config` (`propname`, `propvalue`, `is_global`) VALUES ('database_installedversion', '" . $content['database_internalversion'] . "', 1)";

	// --- Now execute all commands
	ini_set('error_reporting', E_WARNING); // Enable Warnings!

	// Establish DB Connection
	DB_Connect();

	for($i = 0; $i < count($mycommands); $i++)
	{
		if ( strlen(trim($mycommands[$i])) > 1 )
		{
			$result = DB_Query( $mycommands[$i], false );
			if ($result == FALSE)
			{
				$content['failedstatements'][ $content['sql_failed'] ]['myerrmsg'] = DB_ReturnSimpleErrorMsg();
				$content['failedstatements'][ $content['sql_failed'] ]['mystatement'] = $mycommands[$i];

				// --- Set CSS Class
				if ( $content['sql_failed'] % 2 == 0 )
					$content['failedstatements'][ $content['sql_failed'] ]['cssclass'] = "line1";
				else
					$content['failedstatements'][ $content['sql_failed'] ]['cssclass'] = "line2";
				// --- 

				$content['sql_failed']++;
			}
			else
				$content['sql_sucess']++;

			// Free result
			DB_FreeQuery($result);
		}
	}
}
else if ( $content['CONVERT_STEP'] == 4 )
{
	if ( isset($_SESSION['MAIN_Username']) )
		$content['MAIN_Username'] = $_SESSION['MAIN_Username'];
	else
		$content['MAIN_Username'] = "";

	$content['MAIN_Password1'] = "";
	$content['MAIN_Password2'] = "";

	// Check for Error Msg
	if ( isset($_GET['errormsg']) )
	{
		$content['iserror'] = "true";
		$content['errormsg'] = DB_StripSlahes( urldecode($_GET['errormsg']) );
	}
}
else if ( $content['CONVERT_STEP'] == 5 )
{
	// Verify Username and Password Input
	if ( isset($_POST['username']) )
		$_SESSION['MAIN_Username'] = DB_RemoveBadChars($_POST['username']);
	else
		RevertOneStep( $content['CONVERT_STEP']-1, $content['LN_INSTALL_MISSINGUSERNAME'] );

	if ( isset($_POST['password1']) )
		$_SESSION['MAIN_Password1'] = DB_RemoveBadChars($_POST['password1']);
	else
		$_SESSION['MAIN_Password1'] = "";

	if ( isset($_POST['password2']) )
		$_SESSION['MAIN_Password2'] = DB_RemoveBadChars($_POST['password2']);
	else
		$_SESSION['MAIN_Password2'] = "";

	if (	
			strlen($_SESSION['MAIN_Password1']) < 4 ||
			$_SESSION['MAIN_Password1'] != $_SESSION['MAIN_Password2'] 
		)
		RevertOneStep( $content['CONVERT_STEP']-1, $content['LN_INSTALL_PASSWORDNOTMATCH'] );

	// --- Now execute all commands
	ini_set('error_reporting', E_WARNING); // Enable Warnings!

	// Establish DB Connection
	DB_Connect();

	// Everything is fine, lets go create the User!
	CreateUserName( $_SESSION['MAIN_Username'], $_SESSION['MAIN_Password1'], 1 );
	
	// Show User success!
	$content['MAIN_Username'] = $_SESSION['MAIN_Username'];
	$content['createduser'] = true;
}
else if ( $content['CONVERT_STEP'] == 6 )
{
	// To be on the save side, establish DB Connection
	DB_Connect();

	// Perform conversion of settings into the database now!
	ConvertCustomSearches();
	ConvertCustomViews();
	ConvertCustomSources();
	ConvertCustomCharts();
	
	// Import General Settings in the last step!
	ConvertGeneralSettings();
}
// --- 

// --- Parsen and Output
InitTemplateParser();
$page -> parser($content, "convert.html");
$page -> output(); 
// ---

// --- Helper functions
// ---
?>