-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy patheS_WebCheck.php
executable file
·242 lines (205 loc) · 7.52 KB
/
eS_WebCheck.php
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
<?php
/**
* Description:
* Die Klasse eS_WebCheck liesst eine externe Website ein und sucht darauf nach
* dem angegebenen Suchtext. So wird festgestellt, ob eine Seite erreichbar ist
* und das CMS funktioniert.
*
* @author Patrick Froch (e@sy Solutions IT) <[email protected]>
* @copyright Copyright 2011 by e@sy Solutions IT
* @version 1.0.0
* @since 27.05.2011
* @category eS_Tools
* @package eS_Webiste-Check
*/
/**
* Description:
* Die Klasse eS_WebCheck liesst eine externe Website ein und sucht darauf nach
* dem angegebenen Suchtext. So wird festgestellt, ob eine Seite erreichbar ist
* und das CMS funktioniert.
*
* @author Patrick Froch (e@sy Solutions IT) <[email protected]>
* @copyright Copyright 2011 by e@sy Solutions IT
* @version 1.0.0
* @since 27.05.2011
* @category eS_Tools
* @package eS_Webiste-Check
*/
class eS_WebCheck extends Backend{
/**
* Description:
* Erstellt das Objekt.
*
* @author Patrick Froch (e@sy Solutions IT) <[email protected]>
* @since 27.05.2011
* @return <objekt> Gibt das erstellte Objekt zurueck
*/
public function __construct() {
$this->import('Database');
$this->import('Input');
$this->import('String');
parent::__construct();
}
/**
* Description:
* Fuehrt die Suche fuer alle Webseiten durch. Wird kein Sourcecode zurueck gegeben, ist der Server wahrscheinlich
* offline. Gibt es einen Sourcecode, aber nicht den Erwarteten, so funktioniert scheinbar das CMS oder die DB
* nicht.
*
* @author Patrick Froch (e@sy Solutions IT) <[email protected]>
* @since 05.06.2011
* @param <integer> $id Id des zu pruefenden Datensatzes
*/
public function run($id){
// Von checkall werden die Id's uebergeben, beim Einzelaufruf wird die Id aus $this->id genommen.
if(is_object($id)){
$id = $this->Input->get('id');
$goBack = true;
} else {
$goBack = false;
}
$data = $this->loadData($id);
if($data){
$site = $this->valString($data['url']);
$search = $this->valString($data['teststring']);
$source = $this->loadSite($site);
$result['date'] = date('d.m.Y');
$result['time'] = date('H:i:s');
$result['source'] = substr($source, 0, 255);
$result['reachable'] = $this->compareSite($source, $search);
$this->saveData($id, $result);
// Nur zurueck gehen, bei Einzelaufruf, sonst wird ueber checkall() zurueck gegangen!
if($goBack){
$this->returnToList($this->Input->get('do')); // Zurueck zur Liste
}
}
}
/**
* Description:
* Laedt alle Id's aus der DB un ruft für alle den Check auf!
*
* @author Patrick Froch (e@sy Solutions IT) <[email protected]>
* @since 10.06.2011
*/
public function checkall(){
$result = $this->Database->execute('SELECT id FROM tl_es_webcheck');
while($result->next()){
$id = $result->id;
$this->run($id);
}
$this->returnToList($this->Input->get('do')); // Zurueck zur Liste
}
/**
* Description:
* Speichert das Ergebniss in der DB.
*
* @author Patrick Froch (e@sy Solutions IT) <[email protected]>
* @since 05.06.2011
* @param <integer> $id Die Id des zu speichernden Datensatzes
* @param <array> $result Das Array mit den Daten, die eingetragen werden sollen
*/
private function saveData($id, $result){
$query = 'UPDATE tl_es_webcheck SET ';
foreach($result as $k => $v){
$query .= "$k = '$v', ";
}
$query = substr($query, 0, strlen($query)-2);
$query .= ' WHERE id = ?';
$res = $this->Database->prepare($query)
->execute($id);
}
/**
* Description:
* Laedt die Daten aus der DB.
*
* @author Patrick Froch (e@sy Solutions IT) <[email protected]>
* @since 05.06.2011
* @param <integer> Die des zu ladenen Datensatzes
* @return <mixed> Array mit den Daten des WebCheck-Auftrages, oder FALSE im Fehlerfall.
*/
private function loadData($id){
$query = 'SELECT * FROM tl_es_webcheck WHERE id = ?';
$result = $this->Database->prepare($query)
->execute($id);
if($result){
return $result->fetchAssoc();
} else {
return false;
}
}
/**
* Description:
* Laedt die Websiten
*
* @author Patrick Froch (e@sy Solutions IT) <[email protected]>
* @since 27.05.2011
* @param <string> $url Die Adresse der Seite, die abgefragt werden soll.
* @return <string> Der Qeulltext der Seite.
*/
private function loadSite($url){
if(substr_count($url, 'http://') == 0){
$url = 'http://' . $url;
}
if($source = @file_get_contents($url)){
return $this->valString($source);
} else {
return false;
}
}
/**
* Description:
* Sucht das Suchwort in der Seite
*
* @author Patrick Froch (e@sy Solutions IT) <[email protected]>
* @since 27.05.2011
* @param <string> $source Der Quelltext der Seite.
* @param <string> $search Das Suchwort.
* @return <boolean> TRUE, wenn das Suchwort gefunden wurde, sonst FALSE
*/
private function compareSite($source, $search){
if($source != '' AND $search != ''){
if(substr_count($source, $search) != 0){
return true;
} else {
return false;
}
} else {
return false;
}
}
/**
* Description:
* Die Mehtode valString bearbeitet der uebergebenen String und entfernt alle
* HTML- u. PHP-Tags. Ausserdem werden alle Leerzeichen und Zeilenumbrueche
* entfernt.
*
* @author Patrick Froch (e@sy Solutions IT) <[email protected]>
* @since 27.05.2011
* @param <string> $str Der zu bearbeitende String
* @return <string> Der bearbeitete String.
*/
private function valString($str){
$str = strtolower(strip_tags($str));
$str = str_replace(' ', '', $str);
$str = str_replace("\n", '', $str);
$str = $this->String->decodeEntities($str);
return $str;
}
/**
* Description:
* Nach dem Versenden der Zugangsdaten wird wirder auf die Uebersicht umgeleitet.
*
* @author Patrick Froch (e@sy Solutions IT) <[email protected]>
* @since 19.05.2011
* @param <string> $act Die aufgerufenen Aktion
*/
private function returnToList($act){
if(version_compare(VERSION . '.' . BUILD, '2.9.0', '<')) {
$path = $this->Environment->base . 'typolight/main.php?do=' . $act;
} else {
$path = $this->Environment->base . 'contao/main.php?do=' . $act;
}
$this->redirect($path, 301);
}
}
?>