1 | <?php
|
---|
2 |
|
---|
3 | include_once(dirname(__FILE__).'/../../Base/Model.php');
|
---|
4 |
|
---|
5 | class MangosDebug extends Model
|
---|
6 | {
|
---|
7 | var $ItemPerPage = 35;
|
---|
8 | var $MaxMangosThreadCount = 12;
|
---|
9 |
|
---|
10 | function __construct($System)
|
---|
11 | {
|
---|
12 | parent::__construct($System);
|
---|
13 | }
|
---|
14 |
|
---|
15 | function ProcessLog($RealmId)
|
---|
16 | {
|
---|
17 | $Output = '';
|
---|
18 | // Read server Id from first parameter
|
---|
19 | $Realm = new Realm($this->System, $RealmId);
|
---|
20 |
|
---|
21 | $LogDir = '../realm/'.$RealmId.'/log/';
|
---|
22 | $MangosConfFile = '../realm/'.$RealmId.'/etc/mangosd.conf';
|
---|
23 | $StdOutLogFile = $LogDir.'mangos-worldd.log';
|
---|
24 | $ErrOutLogFile = $LogDir.'mangos-worldd.err';
|
---|
25 | $MangosLogFile = $LogDir.'Server.log';
|
---|
26 | $MangosDbErrorsLogFile = $LogDir.'DBErrors.log';
|
---|
27 |
|
---|
28 | if(!file_exists($StdOutLogFile)) exit;
|
---|
29 |
|
---|
30 | $Content = file_get_contents($StdOutLogFile);
|
---|
31 | $Lines = explode("\n", $Content);
|
---|
32 | $Content = ''; // Free unused memory
|
---|
33 |
|
---|
34 | // Separate information from log file
|
---|
35 | $Line = 0;
|
---|
36 | while(($Line < count($Lines)) and (substr($Lines[$Line], 0, 6) != 'MaNGOS')) $Line++;
|
---|
37 | $MangosVersion = $Lines[$Line];
|
---|
38 |
|
---|
39 | // Try to find start of backtrace
|
---|
40 | while(($Line < count($Lines)) and (substr($Lines[$Line], 0, 16) != 'Program received')) $Line++;
|
---|
41 | $Backtrace = array_slice($Lines, $Line, count($Lines) - $Line); // Assume rest of file to be backtrace
|
---|
42 | $Backtrace = addslashes(implode("\n", $Backtrace));
|
---|
43 | $Lines = '';
|
---|
44 |
|
---|
45 | //$Log = array_slice($Lines, 0, $Line);
|
---|
46 | //$Log = addslashes(implode("\n", $Log));
|
---|
47 |
|
---|
48 | // Get used database version from database
|
---|
49 | $DbResult = $this->Database->query('SELECT * FROM `realm'.$RealmId.'_mangos`.`db_version`');
|
---|
50 | $DbRow = $DbResult->fetch_array();
|
---|
51 | $DbVersion = $DbRow['version'];
|
---|
52 |
|
---|
53 | // Get last uptime info
|
---|
54 | $DbResult = $this->Database->query('SELECT * FROM `server'.$Realm->Data['Server'].'_realmd`.`uptime` ORDER BY `starttime` DESC LIMIT 1');
|
---|
55 | //$Output = $this->Database->error;
|
---|
56 | $DbRow = $DbResult->fetch_array();
|
---|
57 | $MaxPlayerCount = $DbRow['maxplayers'];
|
---|
58 | $Uptime = $DbRow['uptime'];
|
---|
59 |
|
---|
60 | // Insert data to database
|
---|
61 | $this->Database->query('INSERT INTO `Debug` (`Realm`, `Time`, `MangosVersion`, `DbVersion`, `Uptime`, `MaxPlayerCount`) VALUES ('.$RealmId.', NOW(), "'.$MangosVersion.'", "'.$DbVersion.'", '.$Uptime.', '.$MaxPlayerCount.')');
|
---|
62 | $InsertId = $this->Database->insert_id;
|
---|
63 |
|
---|
64 | // Insert data in separate query to partly avoid too long query packet error
|
---|
65 | $this->Database->query('UPDATE `Debug` SET Backtrace="'.$Backtrace.'" WHERE Id='.$InsertId);
|
---|
66 | $Backtrace = '';
|
---|
67 |
|
---|
68 | if(file_exists($MangosLogFile))
|
---|
69 | {
|
---|
70 | $Log = addslashes(file_get_contents($MangosLogFile));
|
---|
71 | $this->Database->query('UPDATE `Debug` SET Log="'.$Log.'" WHERE Id='.$InsertId);
|
---|
72 | unlink($MangosLogFile);
|
---|
73 | }
|
---|
74 |
|
---|
75 | if(file_exists($MangosDbErrorsLogFile))
|
---|
76 | {
|
---|
77 | $Log = addslashes(file_get_contents($MangosDbErrorsLogFile));
|
---|
78 | $this->Database->query('UPDATE `Debug` SET DbErrors="'.$Log.'" WHERE Id='.$InsertId);
|
---|
79 | unlink($MangosDbErrorsLogFile);
|
---|
80 | }
|
---|
81 |
|
---|
82 | if(file_exists($MangosConfFile))
|
---|
83 | {
|
---|
84 | $Configuration = array();
|
---|
85 | $Log = addslashes(file_get_contents($MangosConfFile));
|
---|
86 | $LogLines = explode("\n", $Log);
|
---|
87 | foreach($LogLines as $LogLine)
|
---|
88 | {
|
---|
89 | if(substr($LogLine, 0, 1) != '#') $Configuration[] = $LogLine;
|
---|
90 | }
|
---|
91 | $this->Database->query('UPDATE `Debug` SET Configuration="'.implode("\n", $Configuration).'" WHERE Id='.$InsertId);
|
---|
92 | }
|
---|
93 |
|
---|
94 | if(file_exists($ErrOutLogFile))
|
---|
95 | {
|
---|
96 | $Log = addslashes(file_get_contents($ErrOutLogFile));
|
---|
97 | $this->Database->query('UPDATE `Debug` SET ErrorLog="'.$Log.'" WHERE Id='.$InsertId);
|
---|
98 | unlink($ErrOutLogFile);
|
---|
99 | }
|
---|
100 | unlink($StdOutLogFile);
|
---|
101 | return($Output);
|
---|
102 | }
|
---|
103 | }
|
---|