Browse Source

Enhancements for DEBUG_MODE, allowing the site to run within Docker.

ngxez 8 years ago
parent
commit
451326c0c9

+ 2
- 0
.gitignore View File

1
+classes/config.php
2
+.DS_Store

+ 4
- 1
classes/misc.class.php View File

17
     $Headers .= 'X-Mailer: Project Gazelle'."\r\n";
17
     $Headers .= 'X-Mailer: Project Gazelle'."\r\n";
18
     $Headers .= 'Message-Id: <'.Users::make_secret().'@'.SITE_DOMAIN.">\r\n";
18
     $Headers .= 'Message-Id: <'.Users::make_secret().'@'.SITE_DOMAIN.">\r\n";
19
     $Headers .= 'X-Priority: 3'."\r\n";
19
     $Headers .= 'X-Priority: 3'."\r\n";
20
-    mail($To, $Subject, $Body, $Headers, "-f $From@".SITE_DOMAIN);
20
+    // do not attempt to send email when DEBUG_MODE is enabled
21
+    if (!DEBUG_MODE) {
22
+      mail($To, $Subject, $Body, $Headers, "-f $From@".SITE_DOMAIN);
23
+    }
21
   }
24
   }
22
 
25
 
23
 
26
 

+ 22
- 7
classes/mysql.class.php View File

222
     }
222
     }
223
     $QueryStartTime = microtime(true);
223
     $QueryStartTime = microtime(true);
224
     $this->connect();
224
     $this->connect();
225
-    // In the event of a MySQL deadlock, we sleep allowing MySQL time to unlock, then attempt again for a maximum of 5 tries
226
-    for ($i = 1; $i < 6; $i++) {
225
+
226
+    if (DEBUG_MODE) {
227
       $this->QueryID = mysqli_query($this->LinkID, $Query);
227
       $this->QueryID = mysqli_query($this->LinkID, $Query);
228
-      if (!in_array(mysqli_errno($this->LinkID), array(1213, 1205))) {
229
-        break;
228
+
229
+      // in DEBUG_MODE, return the full trace on a SQL error (super useful for debugging).
230
+      // do not attempt to retry to query
231
+      if (!$this->QueryID) {
232
+        echo '<pre>' . mysqli_error($this->LinkID) . '<br><br>';
233
+        debug_print_backtrace();
234
+        echo '</pre>';
235
+        die();
230
       }
236
       }
231
-      $Debug->analysis('Non-Fatal Deadlock:', $Query, 3600 * 24);
232
-      trigger_error("Database deadlock, attempt $i");
237
+    } else {
238
+      // In the event of a MySQL deadlock, we sleep allowing MySQL time to unlock, then attempt again for a maximum of 5 tries
239
+      for ($i = 1; $i < 6; $i++) {
240
+        $this->QueryID = mysqli_query($this->LinkID, $Query);
241
+        if (!in_array(mysqli_errno($this->LinkID), array(1213, 1205))) {
242
+          break;
243
+        }
244
+        $Debug->analysis('Non-Fatal Deadlock:', $Query, 3600 * 24);
245
+        trigger_error("Database deadlock, attempt $i");
233
 
246
 
234
-      sleep($i * rand(2, 5)); // Wait longer as attempts increase
247
+        sleep($i * rand(2, 5)); // Wait longer as attempts increase
248
+      }
235
     }
249
     }
250
+
236
     $QueryEndTime = microtime(true);
251
     $QueryEndTime = microtime(true);
237
     $this->Queries[] = array($Query, ($QueryEndTime - $QueryStartTime) * 1000, null);
252
     $this->Queries[] = array($Query, ($QueryEndTime - $QueryStartTime) * 1000, null);
238
     $this->Time += ($QueryEndTime - $QueryStartTime) * 1000;
253
     $this->Time += ($QueryEndTime - $QueryStartTime) * 1000;

+ 10
- 1
classes/tracker.class.php View File

23
     }
23
     }
24
 
24
 
25
     $MaxAttempts = 3;
25
     $MaxAttempts = 3;
26
+    // don't wait around if we're debugging
27
+    if (DEBUG_MODE) {
28
+      $MaxAttempts = 1;
29
+    }
30
+
26
     $Err = false;
31
     $Err = false;
27
     if (self::send_request($Get, $MaxAttempts, $Err) === false) {
32
     if (self::send_request($Get, $MaxAttempts, $Err) === false) {
28
       send_irc("PRIVMSG #tracker :$MaxAttempts $Err $Get");
33
       send_irc("PRIVMSG #tracker :$MaxAttempts $Err $Get");
130
       if ($Sleep) {
135
       if ($Sleep) {
131
         sleep($Sleep);
136
         sleep($Sleep);
132
       }
137
       }
133
-      $Sleep = 6;
138
+
139
+      // spend some time retrying if we're not in DEBUG_MODE
140
+      if (!DEBUG_MODE) {
141
+        $Sleep = 6;
142
+      }
134
 
143
 
135
       // Send request
144
       // Send request
136
       $File = fsockopen(TRACKER_HOST, TRACKER_PORT, $ErrorNum, $ErrorString);
145
       $File = fsockopen(TRACKER_HOST, TRACKER_PORT, $ErrorNum, $ErrorString);

+ 5
- 0
classes/util.php View File

133
  * @param string $Raw An IRC protocol snippet to send.
133
  * @param string $Raw An IRC protocol snippet to send.
134
  */
134
  */
135
 function send_irc($Raw) {
135
 function send_irc($Raw) {
136
+  // don't bother talking to IRC in DEBUG_MODE
137
+  if (DEBUG_MODE) {
138
+    return;
139
+  }
140
+
136
   $IRCSocket = fsockopen(SOCKET_LISTEN_ADDRESS, SOCKET_LISTEN_PORT);
141
   $IRCSocket = fsockopen(SOCKET_LISTEN_ADDRESS, SOCKET_LISTEN_PORT);
137
   $Raw = str_replace(array("\n", "\r"), '', $Raw);
142
   $Raw = str_replace(array("\n", "\r"), '', $Raw);
138
   fwrite($IRCSocket, $Raw);
143
   fwrite($IRCSocket, $Raw);

+ 10
- 3
sections/login/index.php View File

274
                   $DB->query("SELECT ASN FROM geoip_asn WHERE StartIP<=INET6_ATON('$_SERVER[REMOTE_ADDR]') AND EndIP>=INET6_ATON('$_SERVER[REMOTE_ADDR]')");
274
                   $DB->query("SELECT ASN FROM geoip_asn WHERE StartIP<=INET6_ATON('$_SERVER[REMOTE_ADDR]') AND EndIP>=INET6_ATON('$_SERVER[REMOTE_ADDR]')");
275
                   list($CurrentASN) = $DB->next_record();
275
                   list($CurrentASN) = $DB->next_record();
276
 
276
 
277
-                  if (!in_array($CurrentASN, $PastASNs)) {
277
+                  // if we are in DEBUG_MODE, no need to enforce location restriction
278
+                  if (!in_array($CurrentASN, $PastASNs) && !DEBUG_MODE) {
278
                     // Never logged in from this location before
279
                     // Never logged in from this location before
279
                     if ($Cache->get_value('new_location_'.$UserID.'_'.$CurrentASN) !== true) {
280
                     if ($Cache->get_value('new_location_'.$UserID.'_'.$CurrentASN) !== true) {
280
                       $DB->query("
281
                       $DB->query("
294
 
295
 
295
               $SessionID = Users::make_secret(64);
296
               $SessionID = Users::make_secret(64);
296
               $KeepLogged = ($_POST['keeplogged'] ?? false) ? 1 : 0;
297
               $KeepLogged = ($_POST['keeplogged'] ?? false) ? 1 : 0;
297
-              setcookie('session', $SessionID, (time()+60*60*24*365)*$KeepLogged, '/', '', true, true);
298
-              setcookie('userid', $UserID, (time()+60*60*24*365)*$KeepLogged, '/', '', true, true);
298
+              if (DEBUG_MODE) {
299
+                // allow HTTP (non secure) cookies if running in DEBUG_MODE
300
+                setcookie('session', $SessionID, (time()+60*60*24*365)*$KeepLogged, '/', '', false, true);
301
+                setcookie('userid', $UserID, (time()+60*60*24*365)*$KeepLogged, '/', '', false, true);
302
+              } else {
303
+                setcookie('session', $SessionID, (time()+60*60*24*365)*$KeepLogged, '/', '', true, true);
304
+                setcookie('userid', $UserID, (time()+60*60*24*365)*$KeepLogged, '/', '', true, true);
305
+              }
299
 
306
 
300
               // Because we <3 our staff
307
               // Because we <3 our staff
301
               $Permissions = Permissions::get_permissions($PermissionID);
308
               $Permissions = Permissions::get_permissions($PermissionID);

+ 4
- 1
sections/tools/index.php View File

10
   $_REQUEST['action'] = $argv[1];
10
   $_REQUEST['action'] = $argv[1];
11
 } else {
11
 } else {
12
   if (empty($_REQUEST['action']) || ($_REQUEST['action'] != 'public_sandbox' && $_REQUEST['action'] != 'ocelot')) {
12
   if (empty($_REQUEST['action']) || ($_REQUEST['action'] != 'public_sandbox' && $_REQUEST['action'] != 'ocelot')) {
13
-    enforce_login();
13
+    // do not enforce in debug mode so we can set the encryption key w/o an account
14
+    if (!DEBUG_MODE) {
15
+      enforce_login();
16
+    }
14
   }
17
   }
15
 }
18
 }
16
 
19
 

+ 9
- 3
sections/tools/misc/database_key.php View File

1
 <?
1
 <?
2
-if (!check_perms('site_debug')) {
3
-    error(403);
2
+// do not enforce in debug mode so we can set the encryption key w/o an account
3
+if (!DEBUG_MODE) {
4
+  if (!check_perms('site_debug')) {
5
+      error(403);
6
+  }
4
 }
7
 }
5
 
8
 
6
 if (isset($_POST['dbkey'])) {
9
 if (isset($_POST['dbkey'])) {
7
-  authorize();
10
+  // do not enforce in debug mode so we can set the encryption key w/o an account
11
+  if (!DEBUG_MODE) {
12
+    authorize();
13
+  }
8
   apc_store('DBKEY', hash('sha512', $_POST['dbkey']));
14
   apc_store('DBKEY', hash('sha512', $_POST['dbkey']));
9
 }
15
 }
10
 
16
 

Loading…
Cancel
Save