More rewrites, and output-mode fixed (we should documentate this)
[mailer.git] / inc / extensions / ext-debug.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 10/12/2008 *
4  * ================                             Last change: 10/12/2008 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : ext-debug.php                                    *
8  * -------------------------------------------------------------------- *
9  * Short description : Extension for sending/receiving debug requests   *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Erweiterung zum Versenden/Empfangen von Debug-Q. *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * Needs to be in all Files and every File needs "svn propset           *
18  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
19  * -------------------------------------------------------------------- *
20  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
21  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
23  * This program is free software; you can redistribute it and/or modify *
24  * it under the terms of the GNU General Public License as published by *
25  * the Free Software Foundation; either version 2 of the License, or    *
26  * (at your option) any later version.                                  *
27  *                                                                      *
28  * This program is distributed in the hope that it will be useful,      *
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
31  * GNU General Public License for more details.                         *
32  *                                                                      *
33  * You should have received a copy of the GNU General Public License    *
34  * along with this program; if not, write to the Free Software          *
35  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
41         die();
42 }
43
44 // Version number
45 setThisExtensionVersion('0.0');
46
47 // Version history array (add more with , '0.1.0' and so on)
48 setExtensionVersionHistory(array('0.0'));
49
50 // Keep this extension always active!
51 setExtensionAlwaysActive('Y');
52
53 switch (getExtensionMode()) {
54         case 'register': // Do stuff when installation is running (modules.php?module=admin is called)
55                 // Table for debug log entries
56                 addExtensionSql("DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_debug_log`");
57                 addExtensionSql("CREATE TABLE `{?_MYSQL_PREFIX?}_debug_log` (
58 `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
59 `sender_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
60 `timestamp` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00',
61 `file` VARCHAR(255) NOT NULL DEFAULT '',
62 `line` MEDIUMINT NOT NOT NULL DEFAULT 0,
63 `message` LONGTEXT,
64 `comment` TINYTEXT,
65 `status` ENUM('NEW','PENDING','ACCEPTED','FIXED','INVALID','DUBLICATE','SPAM') NOT NULL DEFAULT 'NEW',
66 `inserted` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
67 INDEX (`sender_id`),
68 PRIMARY KEY (`id`)
69 ) TYPE={?_TABLE_TYPE?} COMMENT='Debug log data'");
70
71                 // Table against debug log abuse
72                 addExtensionSql("DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_debug_log_abuse`");
73                 addExtensionSql("CREATE TABLE `{?_MYSQL_PREFIX?}_debug_log_abuse` (
74 `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
75 `client_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
76 `timestamp` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00',
77 `raw_data` LONGTEXT,
78 `inserted` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
79 INDEX (`client_id`),
80 PRIMARY KEY (`id`)
81 ) TYPE={?_TABLE_TYPE?} COMMENT='Debug log abuse'");
82
83                 // Table on relay/server for client exchanges
84                 addExtensionSql("DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_debug_client`");
85                 addExtensionSql("CREATE TABLE `{?_MYSQL_PREFIX?}_debug_client` (
86 `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
87 `key` VARCHAR(255) NOT NULL DEFAULT 'SELF',
88 `url` VARCHAR(255) NOT NULL DEFAULT '',
89 `webmaster` VARCHAR(255) NOT NULL DEFAULT '',
90 `title` VARCHAR(255) NOT NULL DEFAULT '',
91 `status` ENUM('ACTIVE','NEW','PENDING','LOCKED','DELETED','SPAM') NOT NULL DEFAULT 'PENDING',
92 `type` ENUM ('CLIENT','RELAY','SERVER') NOT NULL DEFAULT 'CLIENT',
93 `inserted` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
94 `lock_spam_reason` TINYTEXT,
95 UNIQUE (`key`),
96 UNIQUE (`url`),
97 PRIMARY KEY (`id`)
98 ) TYPE={?_TABLE_TYPE?} COMMENT='Debug clients'");
99
100                 // Add this exchange as first client
101                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_debug_client` (`url`,`title`,`webmaster`,`status`) VALUES ('{?URL?}','{?MAIN_TITLE?}','{?WEBMASTER?}','ACTIVE')");
102
103                 // Table for debug log <-> client connection
104                 addExtensionSql("DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_debug_client_log`");
105                 addExtensionSql("CREATE TABLE `{?_MYSQL_PREFIX?}_debug_client_log` (
106 `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
107 `client_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 1,
108 `log_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
109 INDEX `client_log` (`client_id`,`log_id`),
110 UNIQUE (`log_id`),
111 PRIMARY KEY (`id`)
112 ) TYPE={?_TABLE_TYPE?} COMMENT='Debug client <-> log connection'");
113
114                 // Guest menus
115                 addGuestMenuSql('debug',NULL,'Debug-System','Y','Y',2);
116                 addGuestMenuSql('debug','debug_info','Informationen','Y','Y',1);
117                 addGuestMenuSql('debug','debug_reg','Anmeldung','Y','Y',2);
118                 addGuestMenuSql('debug','debug_unreg','Abmeldung','Y','Y',3);
119                 addGuestMenuSql('debug','debug_pilory','Spam-Pranger','Y','Y',4);
120
121                 // Admin menu
122                 addAdminMenuSql('debug',NULL,'Debug-System','Verwalten Sie hier komfortabel das debug.log, welches sich im Verzeichnis <strong>{?CACHE_PATH?}/</strong> befindet.',10);
123                 addAdminMenuSql('debug','import_debug','debug.log importieren','Importieren Sie hier manuell die debug.log, damit neue Eintr&auml;ge mit bestehenden abgeglichen werden k&ouml;nnen und dann evtl. hinzugef&uuml;gt werden. Die <em>debug.log</em> wird nach dem Import automatisch vom Server entfernt. Dieser Vorgang wird f&uuml;r Sie nachts automatisch erledigt!',1);
124                 addAdminMenuSql('debug','list_debug','Eintr&auml;ge anzeigen','Listet alle bereits importierten Eintr&auml;ge auf. Von hier aus versenden Sie noch nicht gemeldete Fehler an das Relay-Netzwerk, damt diese vom MXChange-Team gepr&uuml;ft werden k&ouml;nnen.',2);
125                 addAdminMenuSql('debug','reg_debug','Am Server anmelden','Sie m&uuml;ssen zuerst Ihren Debug-Client (Ihr {?mt_word?} ist dies) oder Relay am Server von MXChange.org anmelden. Dies geschieht f&uuml;r Sie nicht automatisch, da Sie Ihre Daten zuvor &uuml;berpr&uuml;fen m&uuml;ssen, wie z.B. URL, eMail-Adresse und {?mt_word?}-Titel.',3);
126                 addAdminMenuSql('debug','unreg_debug','Vom Server abmelden','Melden Sie bitte Ihren {?mt_word?} wieder vom MXChange-Server ab, damit das Team von MXChange.org weiss, welche Keys nicht mehr genutzt werden.',4);
127                 addAdminMenuSql('debug','config_debug','Einstellungen','&Auml;ndern Sie hier alle Einstellungen, wie auch den Debug-Modus - ob Client, Hub oder selber Server sein. Lesen Sie dazu die Anleitung unter DOCs/de/debug/README.txt durch! Oder kommen Sie in&#39;s Forum. Das Team von MXChange.org hilft Ihnen gerne weiter.',5);
128
129                 // Config entries
130                 addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `debug_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0");
131                 addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `debug_key` VARCHAR(255) NOT NULL DEFAULT ''");
132                 addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `debug_mode` ENUM('CLIENT','RELAY','SERVER') NOT NULL DEFAULT 'CLIENT'");
133                 addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `debug_new_log` ENUM('ACCEPT','FIRST','REG') NOT NULL DEFAULT 'FIRST'");
134                 addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `debug_new_client` ENUM('ACTIVE','NEW','REG') NOT NULL DEFAULT 'NEW'");
135                 addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `debug_reject_log` BIGINT(20) UNSIGNED NOT NULL DEFAULT ".(getConfig('ONE_DAY') * 30)."");
136                 addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `debug_master_url` VARCHAR(255) NOT NULL DEFAULT '{?SERVER_URL?}'");
137                 break;
138
139         case 'remove': // Do stuff when removing extension
140                 // SQL commands to run
141                 addExtensionSql("DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_debug_client_log`");
142                 addExtensionSql("DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_debug_client`");
143                 addExtensionSql("DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_debug_log`");
144                 addExtensionSql("DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_debug_log_abuse`");
145                 addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE `action`='debug'");
146                 addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE `action`='debug'");
147                 break;
148
149         case 'activate': // Do stuff when admin activates this extension
150                 // SQL commands to run
151                 addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_guest_menu` SET `visible`='Y',`locked`='N' WHERE `action`='debug' LIMIT 5");
152                 break;
153
154         case 'deactivate': // Do stuff when admin deactivates this extension
155                 // SQL commands to run
156                 addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_guest_menu` SET `locked`='Y' WHERE `action`='debug' LIMIT 5");
157                 break;
158
159         case 'update': // Update an extension
160                 switch (getCurrentExtensionVersion())
161                 {
162                         case '0.0.1': // SQL queries for v0.0.1
163                                 addExtensionSql('');
164
165                                 // Update notes (these will be set as task text!)
166                                 setExtensionUpdateNotes('');
167                                 break;
168                 }
169                 break;
170
171         case 'modify': // When the extension got modified
172                 break;
173
174         case 'test': // For testing purposes. For details see file inc/modules/admin/what-extensions.php, arround line 305.
175                 break;
176
177         case 'init': // Do stuff when extension is initialized
178                 break;
179
180         default: // Unknown extension mode
181                 DEBUG_LOG(__FILE__, __LINE__, sprintf("Unknown extension mode %s detected.", getExtensionMode()));
182                 break;
183 }
184
185 // [EOF]
186 ?>