dataloghistory_view.php 6.54 KB
Newer Older
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
<?php
/*
Copyright (c) 2007-2008, Till Brehm, projektfarm Gmbh and Oliver Vogel www.muv.com
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice,
      this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
    * Neither the name of ISPConfig nor the names of its contributors
      may be used to endorse or promote products derived from this software without
      specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

require_once '../../lib/config.inc.php';
require_once '../../lib/app.inc.php';

//* Check permissions for module
$app->auth->check_module_permissions('monitor');

$app->load('finediff');

// Loading the template
$app->uses('tpl');
$app->tpl->newTemplate("form.tpl.htm");
$app->tpl->setInclude('content_tpl', 'templates/dataloghistory_view.htm');

$app->load_language_file('web/monitor/lib/lang/'.$_SESSION['s']['language'].'_dataloghistory_view.lng');
require('lib/lang/'.$_SESSION['s']['language'].'_dataloghistory_view.lng');
$app->tpl->setvar($wb);

$id = intval($_GET['id']);

$record = $app->db->queryOneRecord('SELECT * FROM sys_datalog WHERE datalog_id = ?', $id);
$out['id'] = $id;

$out['timestamp'] = date($app->lng('conf_format_datetime'), $record['tstamp']);
$out['table'] = $record['dbtable'];

$out['action_char'] = $record['action'];
$out['action_name'] = $app->lng($record['action']);

$out['session_id'] = $record['session_id'];

60
61
62
63
64
65
66
if ($out['session_id'] != '') {
	$temp = $app->db->queryOneRecord("SELECT username, ip FROM sys_login WHERE session_id = ?", $out['session_id']);
	$out['datalog_username'] = $temp['username'];
	$out['datalog_userip'] = $temp['ip'];
	unset($temp);
}

67
68
69
70
if(!$data = unserialize(stripslashes($record['data']))) {
	$data = unserialize($record['data']);
}

71
$out = describe($record['dbtable'], $data, $out, $record['action']);
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
switch ($record['action']) {
	case 'i':
		$inserts = array();
		foreach ($data['new'] as $key=>$value) {
			$inserts[] = array(
				'key' => $key,
				'value' => nl2br($value),
			);
		}
		$app->tpl->setLoop('inserts', $inserts);
		break;
	case 'u':
		$updates = array();
		foreach ($data['new'] as $key=>$value) {
			if ($value != $data['old'][$key]) {
				$old = $data['old'][$key];
				$new = $value;
				$changes = show_diff_if_needed($old, $new);
				$updates[] = array(
					'key' => $key,
					'is_diff' => $changes['is_diff'],
					'old' => nl2br($changes['old']),
					'new' => nl2br($changes['new']),
					'diff' => nl2br($changes['diff']),
				);
			}
		}
		if (count($updates) > 0) {
			$app->tpl->setLoop('updates', $updates);
		} else {
			$out['no_changes'] = true;
		}
		break;
	case 'd':
		$deletes = array();
		foreach ($data['old'] as $key=>$value) {
			$deletes[] = array(
				'key' => $key,
				'value' => nl2br($value),
			);
		}
		$app->tpl->setLoop('deletes', $deletes);
		break;
}

$app->tpl->setVar($out);
119
$app->tpl->setVar('can_undo', ($out['action_char'] === 'u' || $out['action_char'] === 'd'));
120
121
122
123
124
125
126
127

$app->tpl_defaults();
$app->tpl->pparse();

function show_diff_if_needed($old, $new) {
	global $app;

	$diff_min_lines = 6;
128
$where = @($action == 'd')?$data['old']['parent_domain_id']:$data['new']['parent_domain_id'];
129
130
131
132
133
134
135
136
137
	if (substr_count($old, "\n") >= $diff_min_lines || substr_count($new, "\n") >= $diff_min_lines) {
		$opcodes = FineDiff::getDiffOpcodes($old, $new);
		$html = FineDiff::renderUTF8DiffToHTMLFromOpcodes($old, $opcodes);
		return array('is_diff'=>true, 'old'=>'', 'new'=>'', 'diff'=>$html);
	} else {
		return array('is_diff'=>false, 'old'=>$old, 'new'=>$new, 'diff'=>'');
	}
}

138
function describe($dbtable, $data, $out, $action) {
Florian Schaal's avatar
Florian Schaal committed
139
140
141
142
143
144
	global $app;
	$out['describe'] = $app->lng('describe_'.$dbtable);
	switch ($dbtable) {
		case 'client':
			$check = 'username';
		break;
145
		case 'cron':
146
147
			$where = @($action == 'd')?$data['old']['parent_domain_id']:$data['new']['parent_domain_id'];
			$temp = $app->db->queryOneRecord("SELECT domain FROM web_domain WHERE domain_id = ?", $where);
148
149
			$out['describe_data'] = $temp['domain'];
		break;
Florian Schaal's avatar
Florian Schaal committed
150
151
152
153
154
155
156
157
158
		case 'directive_snippets':
			$check = 'name';
		break;
		case 'domain':
			$check = 'domain';
		break;
		case 'ftp_user':
			$check = 'username';
		break;
159
160
161
162
163
164
165
166
		case 'mail_archive':
			$check = 'storage';
		break;
		case 'mail_archive_store':
			$where = @($action == 'd')?$data['old']['domain_id']:$data['new']['domain_id'];
			$temp = $app->db->queryOneRecord("SELECT domain FROM mail_domain WHERE domain_id = ?", $where);
			$out['describe_data'] = $temp['domain'];
		break;
Florian Schaal's avatar
Florian Schaal committed
167
168
169
170
171
172
173
174
175
176
177
178
		case 'mail_domain':
			$check = 'domain';
		break;
		case 'mail_forwarding':
			$check = 'source';
		break;
		case 'mail_user':
			$check = 'email';
		break;
		case 'mail_user_filter':
			$check = 'rulename';
		break;
179
180
181
182
183
184
		case 'managed_monitor_checks':
			$check = 'description';
		break;
		case 'managed_php':
			$check = 'version';
		break;
Florian Schaal's avatar
Florian Schaal committed
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
		case 'remote_user':
			$check = 'remote_username';
		break;
		case 'server_php':
			$check = 'name';
		break;
		case 'shell_user':
			$check = 'username';
		break;
		case 'spamfilter_policy':
			$check = 'policy_name';
		break;
		case 'spamfilter_users':
			$check = 'email';
		break;
		case 'web_domain':
			$check = 'domain';
		break;
		case 'web_database_user':
			$check = 'database_user';
		break;
		case 'web_database':
			$check = 'database_name';
		break;
		case 'web_folder_user':
			$check = 'username';
		break;
	}

214
	if(!isset($out['describe_data'])) {
215
216
		$out['describe_data'] = @(isset($data['old'][$check]) && $data['old'][$check] != $data['new'][$check])?$data['old'][$check].'/'.$data['new'][$check]:$data['new'][$check];
	}
Florian Schaal's avatar
Florian Schaal committed
217
218
219
220

	return $out;
}

221
?>