<?php
if (isset($_SERVER['HTTP_ORIGIN'])) {
  header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
  header('Access-Control-Allow-Credentials: true');
  header('Access-Control-Max-Age: 86400');    // cache for 1 day
}

// Access-Control headers are received during OPTIONS requests
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {

  if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
      header("Access-Control-Allow-Methods: GET, POST, OPTIONS");         

  if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
      header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");

  exit(0);
}

// BOTH ZZ AND XX are the SAME
  if(!(isset($apppath))){$apppath = "/home/relayup/";}
  $settingfile = $apppath . "dev/Shield";
  
  $seperator ="//\n";
  $SheildSettings = "";

  $ShieldSetting_00 = "";  $ShieldSetting_01 = "";
  $ShieldSetting_02 = "";  $ShieldSetting_03 = "";
  $ShieldSetting_04 = "";  $ShieldSetting_05 = "";
  $ShieldSetting_06 = "";  $ShieldSetting_07 = "";
  $ShieldSetting_08 = "";  $ShieldSetting_09 = "";
  $ShieldSetting_10 = "";  $ShieldSetting_11 = "";
  $ShieldSetting_12 = "";  $ShieldSetting_13 = "";
  $ShieldSetting_14 = "";  $ShieldSetting_15 = "";
  $ShieldSetting_16 = "";
  $ShieldSetting_94 = "";  $ShieldSetting_95 = "";

  $readname = $apppath . 'dev/00_websaved.cfg';
  if (file_exists($readname)) { } else {$readname = $apppath . 'dev/00_saved.cfg';}
  $savedcontent = file_get_contents($readname);
  if($savedcontent != ""){
    $savedlist = preg_split("/\r\n|\n|\r/", $savedcontent);
    foreach ($savedlist as $saveditem){
      $TheIndex = substr($saveditem, 0, 2); // 00_SET=
      $TheValue = substr($saveditem, 7);    // 00_SET=

      $pos = strpos($saveditem, "=");
      if ($pos !== false) {
        $TheValue = substr($saveditem, $pos+1);
      }      
      if($TheIndex == "00"){$ShieldSetting_00 = $TheValue;}
      if($TheIndex == "01"){$ShieldSetting_01 = $TheValue;}
      if($TheIndex == "02"){$ShieldSetting_02 = $TheValue;}
      if($TheIndex == "03"){$ShieldSetting_03 = $TheValue;}
      if($TheIndex == "04"){$ShieldSetting_04 = $TheValue;}
      if($TheIndex == "05"){$ShieldSetting_05 = $TheValue;}
      if($TheIndex == "06"){$ShieldSetting_06 = $TheValue;}
      if($TheIndex == "07"){$ShieldSetting_07 = $TheValue;}
      if($TheIndex == "08"){$ShieldSetting_08 = $TheValue;}
      if($TheIndex == "09"){$ShieldSetting_09 = $TheValue;}
      if($TheIndex == "10"){$ShieldSetting_10 = $TheValue;}
      if($TheIndex == "11"){$ShieldSetting_11 = $TheValue;}
      if($TheIndex == "12"){$ShieldSetting_12 = $TheValue;}
      if($TheIndex == "13"){$ShieldSetting_13 = $TheValue;}
      if($TheIndex == "14"){$ShieldSetting_14 = $TheValue;}
      if($TheIndex == "15"){$ShieldSetting_15 = $TheValue;}
      if($TheIndex == "16"){$ShieldSetting_16 = $TheValue;}
      if($TheIndex == "94"){$ShieldSetting_94 = $TheValue;}
      if($TheIndex == "95"){$ShieldSetting_95 = $TheValue;}
    }

    $SheildSettings = $seperator;

    $SheildSettings .= "ShieldSetting_00=$ShieldSetting_00$seperator";
  //  $SheildSettings .= "ShieldSetting_01=$ShieldSetting_01$seperator";
  //  $SheildSettings .= "ShieldSetting_02=$ShieldSetting_02$seperator";

    $SheildSettings .= "ShieldSetting_04=$ShieldSetting_04$seperator";
    $SheildSettings .= "ShieldSetting_03=$ShieldSetting_03$seperator";//Keep this after number 4. I forget why.

    $SheildSettings .= "ShieldSetting_05=$ShieldSetting_05$seperator";
    $SheildSettings .= "ShieldSetting_06=$ShieldSetting_06$seperator";
    $SheildSettings .= "ShieldSetting_07=$ShieldSetting_07$seperator";
    $SheildSettings .= "ShieldSetting_08=$ShieldSetting_08$seperator";
    $SheildSettings .= "ShieldSetting_09=$ShieldSetting_09$seperator";
    $SheildSettings .= "ShieldSetting_10=$ShieldSetting_10$seperator";
    $SheildSettings .= "ShieldSetting_11=$ShieldSetting_11$seperator";
    $SheildSettings .= "ShieldSetting_12=$ShieldSetting_12$seperator";
    $SheildSettings .= "ShieldSetting_13=$ShieldSetting_13$seperator";
    $SheildSettings .= "ShieldSetting_14=$ShieldSetting_14$seperator";
    $SheildSettings .= "ShieldSetting_15=$ShieldSetting_15$seperator";
    $SheildSettings .= "ShieldSetting_16=$ShieldSetting_16$seperator";
//    $SheildSettings .= "ShieldSetting_94=$ShieldSetting_94$seperator";
//    $SheildSettings .= "ShieldSetting_95=$ShieldSetting_95$seperator";
  }
?>