cd044dd81daba64a6c9718b516d19b2443694b63
[mailer.git] / inc / extensions / ext-debug.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                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  * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
22  * For more information visit: http://www.mxchange.org                  *
23  *                                                                      *
24  * This program is free software; you can redistribute it and/or modify *
25  * it under the terms of the GNU General Public License as published by *
26  * the Free Software Foundation; either version 2 of the License, or    *
27  * (at your option) any later version.                                  *
28  *                                                                      *
29  * This program is distributed in the hope that it will be useful,      *
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
32  * GNU General Public License for more details.                         *
33  *                                                                      *
34  * You should have received a copy of the GNU General Public License    *
35  * along with this program; if not, write to the Free Software          *
36  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
37  * MA  02110-1301  USA                                                  *
38  ************************************************************************/
39
40 // Some security stuff...
41 if (!defined('__SECURITY')) {
42         die();
43 } // END - if
44
45 // Version number
46 setThisExtensionVersion('0.0');
47
48 // Version history array (add more with , '0.1.0' and so on)
49 setExtensionVersionHistory(array('0.0'));
50
51 // Keep this extension always active!
52 setExtensionAlwaysActive('Y');
53
54 // This extension is in development (non-productive)
55 enableExtensionProductive(false);
56
57 switch (getExtensionMode()) {
58         case 'register': // Do stuff when installation is running (modules.php?module=admin is called)
59                 // Table for debug log entries
60                 addExtensionSql('DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_debug_log`');
61                 addExtensionSql("CREATE TABLE `{?_MYSQL_PREFIX?}_debug_log` (
62 `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
63 `sender_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
64 `timestamp` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00',
65 `file` VARCHAR(255) NOT NULL DEFAULT '',
66 `line` MEDIUMINT NOT NOT NULL DEFAULT 0,
67 `message` LONGTEXT,
68 `comment` TINYTEXT,
69 `status` ENUM('NEW','PENDING','ACCEPTED','FIXED','INVALID','DUBLICATE','SPAM') NOT NULL DEFAULT 'NEW',
70 `inserted` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
71 INDEX (`sender_id`),
72 PRIMARY KEY (`id`)
73 ) TYPE={?_TABLE_TYPE?} COMMENT='Debug log data'");
74
75                 // Table against debug log abuse
76                 addExtensionSql('DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_debug_log_abuse`');
77                 addExtensionSql("CREATE TABLE `{?_MYSQL_PREFIX?}_debug_log_abuse` (
78 `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
79 `client_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
80 `timestamp` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00',
81 `raw_data` LONGTEXT,
82 `inserted` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
83 INDEX (`client_id`),
84 PRIMARY KEY (`id`)
85 ) TYPE={?_TABLE_TYPE?} COMMENT='Debug log abuse'");
86
87                 // Table on relay/server for client exchanges
88                 addExtensionSql('DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_debug_client`');
89                 addExtensionSql("CREATE TABLE `{?_MYSQL_PREFIX?}_debug_client` (
90 `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
91 `key` VARCHAR(255) NOT NULL DEFAULT 'SELF',
92 `url` VARCHAR(255) NOT NULL DEFAULT '',
93 `webmaster` VARCHAR(255) NOT NULL DEFAULT '',
94 `title` VARCHAR(255) NOT NULL DEFAULT '',
95 `status` ENUM('ACTIVE','NEW','PENDING','LOCKED','DELETED','SPAM') NOT NULL DEFAULT 'PENDING',
96 `type` ENUM ('CLIENT','RELAY','SERVER') NOT NULL DEFAULT 'CLIENT',
97 `inserted` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
98 `lock_spam_reason` TINYTEXT,
99 UNIQUE (`key`),
100 UNIQUE (`url`),
101 PRIMARY KEY (`id`)
102 ) TYPE={?_TABLE_TYPE?} COMMENT='Debug clients'");
103
104                 // Add this exchange as first client
105                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_debug_client` (`url`,`title`,`webmaster`,`status`) VALUES ('{?URL?}','{?MAIN_TITLE?}','{?WEBMASTER?}','ACTIVE')");
106
107                 // Table for debug log <-> client connection
108                 addExtensionSql('DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_debug_client_log`');
109                 addExtensionSql("CREATE TABLE `{?_MYSQL_PREFIX?}_debug_client_log` (
110 `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
111 `client_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 1,
112 `log_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
113 INDEX `client_log` (`client_id`,`log_id`),
114 UNIQUE (`log_id`),
115 PRIMARY KEY (`id`)
116 ) TYPE={?_TABLE_TYPE?} COMMENT='Debug client <-> log connection'");
117
118                 // Guest menus
119                 addGuestMenuSql('debug',NULL,'Debug-System','Y','Y',2);
120                 addGuestMenuSql('debug','debug_info','Informationen','Y','Y',1);
121                 addGuestMenuSql('debug','debug_reg','Anmeldung','Y','Y',2);
122                 addGuestMenuSql('debug','debug_unreg','Abmeldung','Y','Y',3);
123                 addGuestMenuSql('debug','debug_pilory','Spam-Pranger','Y','Y',4);
124
125                 // Admin menu
126                 addAdminMenuSql('debug',NULL,'Debug-System','Verwalten Sie hier komfortabel das debug.log, welches sich im Verzeichnis <strong>{?CACHE_PATH?}/</strong> befindet.',10);
127                 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);
128                 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 Entwicklerteam gepr&uuml;ft werden k&ouml;nnen.',2);
129                 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);
130                 addAdminMenuSql('debug','unreg_debug','Vom Server abmelden','Melden Sie bitte Ihren {?mt_word?} wieder vom Projekt-Server ab, damit mein Entwicklerteam weiss, welche Keys nicht mehr genutzt werden.',4);
131                 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);
132
133                 // Config entries
134                 addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `debug_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0");
135                 addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `debug_key` VARCHAR(255) NOT NULL DEFAULT ''");
136                 addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `debug_mode` ENUM('CLIENT','RELAY','SERVER') NOT NULL DEFAULT 'CLIENT'");
137                 addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `debug_new_log` ENUM('ACCEPT','FIRST','REG') NOT NULL DEFAULT 'FIRST'");
138                 addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `debug_new_client` ENUM('ACTIVE','NEW','REG') NOT NULL DEFAULT 'NEW'");
139                 addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `debug_reject_log` BIGINT(20) UNSIGNED NOT NULL DEFAULT " . (getConfig('ONE_DAY') * 30));
140                 addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `debug_master_url` VARCHAR(255) NOT NULL DEFAULT '{?SERVER_URL?}'");
141                 break;
142
143         case 'remove': // Do stuff when removing extension
144                 // SQL commands to run
145                 addExtensionSql('DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_debug_client_log`');
146                 addExtensionSql('DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_debug_client`');
147                 addExtensionSql('DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_debug_log`');
148                 addExtensionSql('DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_debug_log_abuse`');
149                 addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE `action`='debug'");
150                 addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE `action`='debug'");
151                 break;
152
153         case 'activate': // Do stuff when admin activates this extension
154                 // SQL commands to run
155                 addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_guest_menu` SET `visible`='Y',`locked`='N' WHERE `action`='debug' LIMIT 5");
156                 break;
157
158         case 'deactivate': // Do stuff when admin deactivates this extension
159                 // SQL commands to run
160                 addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_guest_menu` SET `locked`='Y' WHERE `action`='debug' LIMIT 5");
161                 break;
162
163         case 'update': // Update an extension
164                 switch (getCurrentExtensionVersion()) {
165                         case '0.0.1': // SQL queries for v0.0.1
166                                 addExtensionSql('');
167
168                                 // Update notes (these will be set as task text!)
169                                 setExtensionUpdateNotes('');
170                                 break;
171                 } // END - switch
172                 break;
173
174         case 'modify': // When the extension got modified
175                 break;
176
177         case 'test': // For testing purposes. For details see file inc/modules/admin/what-extensions.php, arround line 305.
178                 break;
179
180         case 'init': // Do stuff when extension is initialized
181                 break;
182
183         default: // Unknown extension mode
184                 logDebugMessage(__FILE__, __LINE__, sprintf("Unknown extension mode %s in extension %s detected.", getExtensionMode(), getCurrentExtensionName()));
185                 break;
186 } // END - switch
187
188 // [EOF]
189 ?>