Browse Source

Use feature flags for manipulating tracker settings (rather than DEBUG_MODE).

ngxez 8 years ago
parent
commit
919182e493

+ 5
- 1
classes/config.template View File

@@ -76,7 +76,11 @@ define('BLOCK_OPERA_MINI',  false); //Set to true to block Opera Mini proxy
76 76
 define('DONOR_INVITES',     2);
77 77
 
78 78
 // Features
79
-define('FEATURE_EMAIL_REENABLE', true);
79
+define('FEATURE_EMAIL_REENABLE',     true);
80
+define('FEATURE_SEND_EMAIL',         true);  //Attempt to send email from the site
81
+define('FEATURE_IRC',                true);  //Attempt to send messages to IRC
82
+define('FEATURE_ENFORCE_LOCATIONS',  true);  //Require users to verify login from unknown devices
83
+define('FEATURE_SET_ENC_KEY_PUBLIC', false); //Allow the site encryption key to be set without an account
80 84
 
81 85
 // User class IDs needed for automatic promotions. Found in the 'permissions' table
82 86
 // Name of class  Class ID (NOT level)

+ 2
- 2
classes/misc.class.php View File

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

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

@@ -222,32 +222,17 @@ class DB_MYSQL {
222 222
     }
223 223
     $QueryStartTime = microtime(true);
224 224
     $this->connect();
225
-
226
-    if (DEBUG_MODE) {
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++) {
227 227
       $this->QueryID = mysqli_query($this->LinkID, $Query);
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();
228
+      if (!in_array(mysqli_errno($this->LinkID), array(1213, 1205))) {
229
+        break;
236 230
       }
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");
231
+      $Debug->analysis('Non-Fatal Deadlock:', $Query, 3600 * 24);
232
+      trigger_error("Database deadlock, attempt $i");
246 233
 
247
-        sleep($i * rand(2, 5)); // Wait longer as attempts increase
248
-      }
234
+      sleep($i * rand(2, 5)); // Wait longer as attempts increase
249 235
     }
250
-
251 236
     $QueryEndTime = microtime(true);
252 237
     $this->Queries[] = array($Query, ($QueryEndTime - $QueryStartTime) * 1000, null);
253 238
     $this->Time += ($QueryEndTime - $QueryStartTime) * 1000;

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

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

+ 2
- 2
classes/util.php View File

@@ -133,8 +133,8 @@ function display_str($Str) {
133 133
  * @param string $Raw An IRC protocol snippet to send.
134 134
  */
135 135
 function send_irc($Raw) {
136
-  // don't bother talking to IRC in DEBUG_MODE
137
-  if (DEBUG_MODE) {
136
+  // check if IRC is enabled
137
+  if (!FEATURE_IRC) {
138 138
     return;
139 139
   }
140 140
 

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

@@ -275,7 +275,7 @@ else {
275 275
                   list($CurrentASN) = $DB->next_record();
276 276
 
277 277
                   // if we are in DEBUG_MODE, no need to enforce location restriction
278
-                  if (!in_array($CurrentASN, $PastASNs) && !DEBUG_MODE) {
278
+                  if (!in_array($CurrentASN, $PastASNs) && FEATURE_ENFORCE_LOCATIONS) {
279 279
                     // Never logged in from this location before
280 280
                     if ($Cache->get_value('new_location_'.$UserID.'_'.$CurrentASN) !== true) {
281 281
                       $DB->query("
@@ -295,14 +295,8 @@ else {
295 295
 
296 296
               $SessionID = Users::make_secret(64);
297 297
               $KeepLogged = ($_POST['keeplogged'] ?? false) ? 1 : 0;
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
-              }
298
+              setcookie('session', $SessionID, (time()+60*60*24*365)*$KeepLogged, '/', '', true, true);
299
+              setcookie('userid', $UserID, (time()+60*60*24*365)*$KeepLogged, '/', '', true, true);
306 300
 
307 301
               // Because we <3 our staff
308 302
               $Permissions = Permissions::get_permissions($PermissionID);

+ 2
- 2
sections/tools/index.php View File

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

+ 4
- 4
sections/tools/misc/database_key.php View File

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

Loading…
Cancel
Save