From: Chuck Scott Date: Mon, 16 Sep 2019 15:21:20 +0000 (-0400) Subject: Restructured means to detect a development site and cleaned up data connection proble... X-Git-Tag: v4.1.0^2~9 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=fc9921b5c19282fad2ec0391ff98e337df8dbb18;p=WP-Plugins%2Fglm-serverstats.git Restructured means to detect a development site and cleaned up data connection problem handling. --- diff --git a/classes/serverBandwidthSupport.php b/classes/serverBandwidthSupport.php index f4d0900..e971880 100755 --- a/classes/serverBandwidthSupport.php +++ b/classes/serverBandwidthSupport.php @@ -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 diff --git a/defines.php b/defines.php index 34bb6de..5b25a03 100755 --- a/defines.php +++ b/defines.php @@ -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'); diff --git a/index.php b/index.php index 30f16ac..eb79f9f 100755 --- 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(); diff --git a/setup/commonHooks.php b/setup/commonHooks.php index ecdba0c..b996e3e 100644 --- a/setup/commonHooks.php +++ b/setup/commonHooks.php @@ -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 diff --git a/views/adminServerStats.html b/views/adminServerStats.html index d52ff45..76207f1 100755 --- a/views/adminServerStats.html +++ b/views/adminServerStats.html @@ -90,8 +90,15 @@ {if !$haveStats} -

This application has not been configured. Please ask Gaslight Media this for your Website.

-

Error: {$connectError}

+

This Website is not known to this plugin!

+

+

+

{else} {if apply_filters('glm-serverstats-is-provider', false)}