From 7ee9a220af5864181736da56da4c7eb80be2f7e0 Mon Sep 17 00:00:00 2001 From: robbt Date: Tue, 12 May 2020 12:24:02 -0400 Subject: [PATCH] failed attempt at doing things without initiation of entire MVC framework --- .../airtime-setup/forms/general-settings.php | 3 +- airtime_mvc/public/setup/general-setup.php | 78 ++++++++++++++++++- 2 files changed, 75 insertions(+), 6 deletions(-) diff --git a/airtime_mvc/build/airtime-setup/forms/general-settings.php b/airtime_mvc/build/airtime-setup/forms/general-settings.php index d3729f6a5..e31eada08 100644 --- a/airtime_mvc/build/airtime-setup/forms/general-settings.php +++ b/airtime_mvc/build/airtime-setup/forms/general-settings.php @@ -29,8 +29,7 @@
- +
diff --git a/airtime_mvc/public/setup/general-setup.php b/airtime_mvc/public/setup/general-setup.php index a7d5a959e..f70f00410 100644 --- a/airtime_mvc/public/setup/general-setup.php +++ b/airtime_mvc/public/setup/general-setup.php @@ -1,5 +1,18 @@ value pairs for airtime.conf protected static $_properties; @@ -25,7 +39,7 @@ class GeneralSetup extends Setup { static $errors = array(); function __construct($settings) { - + self::$corsUrl = $settings[self::CORS_URL]; self::$_properties = array( "api_key" => $this->generateRandomString(), "base_url" => $settings[self::GENERAL_HOST], @@ -43,11 +57,67 @@ class GeneralSetup extends Setup { if (count(self::$errors) <= 0) { $this->writeToTemp(); } + $this->setupCorsUrl(); return array( "message" => self::$message, "errors" => self::$errors ); } + /** + * If the user entered a CORS Url then add it to the system preferences + * TODO Make sure we check for existing CORS URLs and display them on initial form + */ + function setupCorsUrl() { + try { + $_SERVER['AIRTIME_CONF'] = AIRTIME_CONF_TEMP_PATH; + Propel::init(CONFIG_PATH . "airtime-conf-production.php"); + $con = Propel::getConnection(); + } catch(Exception $e) { + self::$message = "Failed to insert Cors URL; database isn't configured properly!"; + self::$errors[] = self::MEDIA_FOLDER; + return; + } + $this->runCorsUrlQuery($con); + } + + function runCorsUrlQuery($con) { + try { + //Check if key already exists + $sql = "SELECT valstr FROM cc_pref" + ." WHERE keystr = 'allowed_cors_urls'"; + + $paramMap = array(); + $paramMap[':key'] = 'allowed_cors_urls'; + + $sql .= " FOR UPDATE"; + + $result = Application_Common_Database::prepareAndExecute($sql, + $paramMap, + Application_Common_Database::ROW_COUNT, + PDO::FETCH_ASSOC, + $con); + + if ($result > 1) { + + } + else { + $pref = new CcPref(); + //if (self::$corsUrl != '') { + $pref->setKeyStr('allowed_cors_urls') + ->setValStr(self::$corsUrl) + ->save(); + //$pref::setValue('allowed_cors_urls', self::CORS_URL); + self::$message = "Saved cors_url"; + //} + Propel::close(); + //unset($_SERVER['AIRTIME_CONF']); + } + } catch (Exception $e) { + self::$message = "Failed to insert " . self::$corsUrl . " into cc_pref" . $e; + self::$errors[] = self::CORS_URL; + } + + } } \ No newline at end of file