Restructured means to detect a development site and cleaned up data connection proble...
authorChuck Scott <cscott@gaslightmedia.com>
Mon, 16 Sep 2019 15:21:20 +0000 (11:21 -0400)
committerChuck Scott <cscott@gaslightmedia.com>
Mon, 16 Sep 2019 15:21:20 +0000 (11:21 -0400)
classes/serverBandwidthSupport.php
defines.php
index.php
setup/commonHooks.php
views/adminServerStats.html

index f4d0900..e971880 100755 (executable)
@@ -354,6 +354,10 @@ class glmServerStatsBandwidthSupport
     {
         global $bwdb;
 
+        if (!$siteId) {
+            return false;
+        }
+
         $stats = array();
 
         // Check for good database connection
@@ -634,6 +638,10 @@ class glmServerStatsBandwidthSupport
     public function getStatsAndCheckTargetExceeded($settings)
     {
 
+        if (!$settings) {
+            return false;
+        }
+
         $stats = $this->bandwidthGetStats($settings['websitepk']);
 
         // Compare the taget in Megabytes to the acutal traffic in Gigabytes
index 34bb6de..5b25a03 100755 (executable)
@@ -15,8 +15,7 @@ define('GLM_SERVERSTATS_DATABASE_USER',     'bandwidthRO');
 define('GLM_SERVERSTATS_DATABASE_PASSWORD', ',Wv4W*~^bL_vF3F4PbGsS');
 
 // PROVIDER ENABLED ADDRESSES - If base URL matches one of these, site is considered the "Provider" site.
-define('GLM_SERVERSTATS_PROVIDER_1', '192.168.44.82');                  // Development System
-define('GLM_SERVERSTATS_PROVIDER_2', 'www.gaslightmedia.com');          // Home Site where sites are configured and reported
+define('GLM_SERVERSTATS_PROVIDER', 'www.gaslightmedia.com:192.168.44.82:localhost');         // Development System
 
 // Check if debug enabled
 if (GLM_SERVERSTATS_PLUGIN_DEBUG) {
@@ -66,13 +65,16 @@ $urlParts = parse_url(get_bloginfo('url'));
 
 // Set Website hostname - but override if development system
 $hostname = $urlParts['host'];
-if ($hostname == GLM_SERVERSTATS_PROVIDER_1) {
+$provider1Hosts = explode(':', GLM_SERVERSTATS_PROVIDER);
+if (in_array($hostname, $provider1Hosts)) {
     // Must be on development system, so use data for GLM site
+    define('GLM_SERVERSTATS_PLUGIN_IS_PROVIDER', true);
     define('GLM_SERVERSTATS_PLUGIN_HOSTNAME', 'www.gaslightmedia.com');
 } else {
+    define('GLM_SERVERSTATS_PLUGIN_IS_PROVIDER', false);
     define('GLM_SERVERSTATS_PLUGIN_HOSTNAME', $urlParts['host']);
 }
-
+echo GLM_SERVERSTATS_PLUGIN_HOSTNAME;
 $pageUri = explode('?', $_SERVER['REQUEST_URI']);               // Bust this up to access URL path and script name only
 
 // Enable to display smarty template debug.
@@ -108,7 +110,8 @@ define('GLM_SERVERSTATS_PLUGIN_MODEL_PATH', GLM_SERVERSTATS_PLUGIN_PATH.'/models
 define('GLM_SERVERSTATS_PLUGIN_VIEW_PATH', GLM_SERVERSTATS_PLUGIN_PATH.'/views');
 
 // Update Server
-define('GLM_SERVERSTATS_PLUGIN_UPDATE_SERVER', 'http://www.gaslightmedia.com/update_server');
+// define('GLM_SERVERSTATS_PLUGIN_UPDATE_SERVER', 'http://www.gaslightmedia.com/update_server');
+define('GLM_SERVERSTATS_PLUGIN_UPDATE_SERVER', 'https://192.168.44.82/update_server');
 
 // Other
 define('GLM_SERVERSTATS_PLUGIN_THRESHOLD_OPTION', 'glmServerStatsThreshold');
index 30f16ac..eb79f9f 100755 (executable)
--- a/index.php
+++ b/index.php
@@ -43,9 +43,6 @@ require_once GLM_SERVERSTATS_PLUGIN_LIB_PATH.'/smartyTemplateSupport.php';
 // Connect to bandwidth database and get all settings for this site
 $bwdb = false;
 $websiteSettings = bandwidthDataConnect(GLM_SERVERSTATS_PLUGIN_HOSTNAME);
-if (!$websiteSettings) {
-    wp_die('FAILURE: Unable to connect to GLM Bandwidth database. Please check connection settings in defines.php of this plugin.');
-}
 
 // If this is an admin request
 if (is_admin()) {
@@ -409,6 +406,12 @@ if (apply_filters('glm-serverstats-is-provider', false) || true) {
  */
 function bandwidthDataConnect($website = false)
 {
+    // Check that we have a good website name
+    if (empty($website)) {
+        trigger_error('GLM Usage: bandwidthDataConnect() - No Website name provided!', E_USER_NOTICE);
+        return false;
+    }
+
     // Moved msqli_init() to here to be compatible with activation
     global $bwdb;
     $bwdb = mysqli_init();
index ecdba0c..b996e3e 100644 (file)
@@ -37,7 +37,7 @@
  * and be able to connect to the server usage statistics database.
  */
 add_filter('glm-serverstats-is-provider', function() {
-    return ((strpos(GLM_SERVERSTATS_SITE_BASE_URL, GLM_SERVERSTATS_PROVIDER_1) !== false || strpos(GLM_SERVERSTATS_SITE_BASE_URL, GLM_SERVERSTATS_PROVIDER_2) !== false) && current_user_can( 'administrator' ));
+    return (GLM_SERVERSTATS_PLUGIN_IS_PROVIDER && current_user_can( 'administrator' ));
     },
     10,
     2
index d52ff45..76207f1 100755 (executable)
 </style>
 
 {if !$haveStats}
-    <h3 class="glm-error">This application has not been configured. Please ask Gaslight Media this for your Website.</h3>
-    <p><b>Error:</b> {$connectError}</p>
+    <h3 class="glm-error">This Website is not known to this plugin!</h3>
+    <p>
+        <ul>
+            <li>Is this plugin being run on a Website that is not listed in the "bandwidth" database?</li>
+            <li>Is this plugin being run on a development site not listed in the GLM_SERVERSTATS_PROVIDER defined parameter in "defines.php"?</li>
+            <li>Is there a problem with the "bandwidth" database Connection settings in the "defines.php" file?</li>
+            <li>There may be other problems. Please check error log.</li>
+        </ul>
+    </p>
 {else}
 
     {if apply_filters('glm-serverstats-is-provider', false)}