From cb336cfc00dcaecfd0eced8dba3a92f8336c9671 Mon Sep 17 00:00:00 2001 From: jundis Date: Fri, 27 Jan 2017 11:43:05 -0600 Subject: [PATCH] Update script for #92 --- updates/update-2.2-to-2.3.php | 178 ++++++++++++++++++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100644 updates/update-2.2-to-2.3.php diff --git a/updates/update-2.2-to-2.3.php b/updates/update-2.2-to-2.3.php new file mode 100644 index 0000000..3f9b207 --- /dev/null +++ b/updates/update-2.2-to-2.3.php @@ -0,0 +1,178 @@ +. +*/ + +ini_set('display_errors', 1); //Display errors in case something occurs +?> + + + + + + + + + + + CWSlack Updater + + +
+
+

CWSlack-SlashCommands Updater

+ Settings Configuration

"; + echo "
Any field left blank will not change the setting, however yes/no questions must be updated any time you save this.
"; + echo "
+

General

+
Set below variable to True if you know your ConnectWise is slow. This will slow down the Slack integration a bit but prevent the 3000ms slack error.
+
Yes No
+

TimeAlerts Module

+
+

Time Module

+
+
+

"; + echo "
"; + //Template for future use + //
Yes No
+ //
+ die(); + } + if ($_GET["page"] == "Save Settings") { + $filedata = file('config.php'); + $newdata = array(); + $line1 = false; //For later use + + foreach ($filedata as $data) { + if (stristr($data, '$timeoutfix =')) { + if ($_POST["timeoutfix"] == "yes") { + $newdata[] = '$timeoutfix = true; //Enable to fix any 3000ms response from Slack.' . PHP_EOL; + $line1=true; + } else { + $newdata[] = '$timeoutfix = false; //Enable to fix any 3000ms response from Slack.' . PHP_EOL; + } + } else if (stristr($data, '$timebusinessstart =')) { + if (!empty($_POST["timebusinessstart"])) { + $newdata[] = '$timebusinessstart = ' . $_POST["timebusinessstart"] . '; //Set to when your business opens in your timezone' . PHP_EOL; + } else { + $newdata[] = $data; + } + } else if (stristr($data, '$timebusinessclose =')) { + if (!empty($_POST["timebusinessclose"])) { + $newdata[] = '$timebusinessclose = ' . $_POST["timebusinessclose"] . '; //Set to when your business closes in your timezone' . PHP_EOL; + } else { + $newdata[] = $data; + } + } else if (stristr($data, '//cwslack-incoming.php') && !$line1) { + array_pop($newdata); + if (!empty($_POST["timebusinessstart"])) { + $newdata[] = '$timebusinessstart = ' . $_POST["timebusinessstart"] . '; //Set to when your business opens in your timezone' . PHP_EOL; + } else { + $newdata[] = $data; + } + if (!empty($_POST["timebusinessstart"])) { + $newdata[] = '$timebusinessstart = ' . $_POST["timebusinessstart"] . '; //Set to when your business opens in your timezone' . PHP_EOL; + } else { + $newdata[] = $data; + } + $newdata[] = PHP_EOL . $data; + } else if (stristr($data, '// Database Configuration') && !$line1) { + array_pop($newdata); + if ($_POST["timeoutfix"] == "yes") { + $newdata[] = '$timeoutfix = true; //Enable to fix any 3000ms response from Slack.' . PHP_EOL; + } else { + $newdata[] = '$timeoutfix = false; //Enable to fix any 3000ms response from Slack.' . PHP_EOL; + } + $newdata[] = PHP_EOL . $data; + } else { + $newdata[] = $data; + } + } + + + file_put_contents('config.php', implode('', $newdata)); + echo "
"; + echo "Successfully configured the config.php file! Please test out your commands in Slack and submit any issues you have to GitHub!"; + echo "
Please remove update-2.2-to-2.3.php to avoid people accessing it externally. You can re-add it anytime to configure database or settings again, or just manually edit config.php.
"; + echo ""; + die(); + } + } + + $php_version=phpversion(); + preg_match("#^\d.\d#", phpversion(), $match); + if($match[0]<5) + { + $php_error="Error: PHP version is ".phpversion().", Version 5 or newer is required."; + } + if($match[0]>6) + { + $php_warning="Warning: PHP version is ".phpversion().", Script tested only on Version 5."; + } + + // declare function + function find_SQL_Version() { + $output = shell_exec('mysql -V'); + preg_match('@[0-9]+\.[0-9]+\.[0-9]+@', $output, $version); + return @$version[0]?$version[0]:-1; + } + + $mysql_version=find_SQL_Version(); + if($mysql_version<5) + { + $mysql_error="Error: MySQL version is $mysql_version. Version 5 or newer is required."; + } + + if(!function_exists('curl_exec')) + { + $curl_error="Error: PHP CURL function is not enabled!"; + } + ?> + + +

Checking versions...

+ + Success: PHP Version $php_version - OK!

"; + else if (empty($php_error)) echo "$php_warning

"; + else echo "$php_error

"; + + if(empty($mysql_error)) echo "Success: MySQL Version $mysql_version - OK!

"; + else echo "$mysql_error

"; + + if(empty($curl_error)) echo "Success: cURL Enabled - OK!

"; + else echo "$curl_error

"; + + if(empty($curl_error) && empty($mysql_error) && empty($php_error)) + { + echo "
+ +
"; + } + else + { + echo ""; + } + ?> + + + + \ No newline at end of file