public function restoreConfig() { // phase 1 retrieve data from browser // extraemos los datos de registro $data = http_request("Data", "s", null); if (!$data) { return array("errorMsg" => "restoreConfig()::download(): No data to import has been received"); } if (!preg_match('/data:([^;]*);base64,(.*)/', $data, $matches)) { return array("errorMsg" => "restoreConfig()::download() cannot handle data received from browser"); } // mimetype for excel file is be stored at $matches[1]: and should be checked // $type=$matches[1]; // 'text/plain', or whatever. Not really used $contents = base64_decode($matches[2]); // decodes received data // phase 2 store it into temporary file $tmpfile = tempnam_sfx(__DIR__ . "/../../../logs", "import", "xlsx"); $file = fopen($tmpfile, "wb"); fwrite($file, $contents); fclose($file); $res = parse_ini_file($tmpfile, false); // don't parse subsections if (!$res) { return array("errorMsg" => "restoreConfig()::download() Received data is not a '.ini' file"); } // phase 3 analyze data. skip internal vars, ignore unknown ones $result = array(); // create result string arrray to send to browser $data = array(); // create array to store valid entries foreach ($res as $key => $value) { $key = strtolower($key); // si no existe se ignora if (!array_key_exists($key, Config::$config_options)) { array_push($result, "{$key}: Unknown. Ignored"); continue; } // si es de sistema se ignora if (Config::$config_options[$key][1] == true) { array_push($result, "{$key}: Forbidden. Ignored"); continue; } // check format $type = ""; switch (Config::$config_options[$key][0]) { case 's': if (is_string($value)) { $type = "string"; } break; case 'c': if (is_color($value)) { $type = "color"; } break; case 'f': // trick to detect if an string contains a float $floatVal = floatval($value); if ($floatVal && intval($floatVal) != $floatVal) { $type = "float"; } break; case 'i': if (is_numeric($value) && strpos($value, '.') == false) { $type = "int"; } break; case 'b': if ($value == "1" || $value == "0") { $type = "bool"; } break; } if ($type == "") { array_push($result, "{$key}: Invalid format. Ignored"); continue; } // arriving here means data is valid // array_push($result,"$key: ($type) $value Accepted"); $data[$key] = $value; } // finally write file: $res = array_merge($this->config, $data); $wres = $this->write_ini_file($res, AC_CONFIG_FILE); if ($wres === FALSE) { return array("errorMsg" => "restoreConfig()::save() error saving .ini file"); } return array('data' => join('<br />', $result)); }
/** * Checks if the param is a decimal number * * @param string decimal to check * @return string error message if decimal is not valid */ function check_is_color($color) { if (!is_color($color)) { return T_('The color value is invalid.'); } }