//public string UpdateInternetConfig(HttpListenerContext context) public string UpdateInternetConfig(IHttpContext context) { try { var data = new StreamReader(context.Request.InputStream).ReadToEnd(); // Start at char 5 to skip the "json:" prefix var json = WebUtility.UrlDecode(data.Substring(5)); // de-serialize it to the settings structure //JsonInternetSettingsData settings = new JavaScriptSerializer().Deserialize<JsonInternetSettingsData>(json); var settings = JSON.ToObject <JsonInternetSettingsData>(json); // process the settings cumulus.LogMessage("Updating internet settings"); // website settings cumulus.ftp_directory = settings.website.directory ?? string.Empty; cumulus.ForumURL = settings.website.forumurl ?? string.Empty; cumulus.ftp_port = settings.website.ftpport; cumulus.ftp_host = settings.website.hostname ?? string.Empty; cumulus.ftp_password = settings.website.password ?? string.Empty; cumulus.ftp_user = settings.website.username ?? string.Empty; cumulus.WebcamURL = settings.website.webcamurl ?? string.Empty; // web settings cumulus.ActiveFTPMode = settings.websettings.activeftp; cumulus.Sslftp = settings.websettings.sslftp; cumulus.WebAutoUpdate = settings.websettings.autoupdate; cumulus.RealtimeEnabled = settings.websettings.enablerealtime; cumulus.RealtimeFTPEnabled = settings.websettings.enablerealtimeftp; cumulus.RealtimeTxtFTP = settings.websettings.realtimetxtftp; cumulus.RealtimeGaugesTxtFTP = settings.websettings.realtimegaugestxtftp; cumulus.RealtimeInterval = settings.websettings.realtimeinterval * 1000; cumulus.DeleteBeforeUpload = settings.websettings.ftpdelete; cumulus.UpdateInterval = settings.websettings.ftpinterval; cumulus.FTPRename = settings.websettings.ftprename; cumulus.IncludeStandardFiles = settings.websettings.includestdfiles; cumulus.IncludeGraphDataFiles = settings.websettings.includegraphdatafiles; cumulus.UTF8encode = settings.websettings.utf8encode; if (settings.websettings.ftplogging != cumulus.FTPlogging) { cumulus.FTPlogging = settings.websettings.ftplogging; cumulus.SetFtpLogging(cumulus.FTPlogging); } // external programs cumulus.DailyProgram = settings.externalprograms.dailyprogram ?? string.Empty; cumulus.DailyParams = settings.externalprograms.dailyprogramparams ?? string.Empty; cumulus.ExternalProgram = settings.externalprograms.program ?? string.Empty; cumulus.ExternalParams = settings.externalprograms.programparams ?? string.Empty; cumulus.RealtimeProgram = settings.externalprograms.realtimeprogram ?? string.Empty; cumulus.RealtimeParams = settings.externalprograms.realtimeprogramparams ?? string.Empty; // twitter cumulus.TwitterEnabled = settings.twitter.enabled; cumulus.TwitterInterval = settings.twitter.interval; cumulus.TwitterPW = settings.twitter.password ?? string.Empty; cumulus.TwitterSendLocation = settings.twitter.sendlocation; cumulus.Twitteruser = settings.twitter.user ?? string.Empty; cumulus.SynchronisedTwitterUpdate = (60 % cumulus.TwitterInterval == 0); // wunderground cumulus.WundCatchUp = settings.wunderground.catchup; cumulus.WundEnabled = settings.wunderground.enabled; cumulus.SendIndoorToWund = settings.wunderground.includeindoor; cumulus.SendSRToWund = settings.wunderground.includesolar; cumulus.SendUVToWund = settings.wunderground.includeuv; cumulus.WundInterval = settings.wunderground.interval; cumulus.WundPW = settings.wunderground.password ?? string.Empty; cumulus.WundRapidFireEnabled = settings.wunderground.rapidfire; cumulus.WundSendAverage = settings.wunderground.sendavgwind; cumulus.WundID = settings.wunderground.stationid ?? string.Empty; cumulus.SynchronisedWUUpdate = (!cumulus.WundRapidFireEnabled) && (60 % cumulus.WundInterval == 0); // Awekas cumulus.AwekasEnabled = settings.awekas.enabled; cumulus.AwekasInterval = settings.awekas.interval; cumulus.AwekasLang = settings.awekas.lang; cumulus.AwekasPW = settings.awekas.password ?? string.Empty; cumulus.AwekasUser = settings.awekas.user ?? string.Empty; cumulus.SendSolarToAwekas = settings.awekas.includesolar; cumulus.SendUVToAwekas = settings.awekas.includeuv; cumulus.SendSoilTempToAwekas = settings.awekas.includesoiltemp; cumulus.SynchronisedAwekasUpdate = (60 % cumulus.AwekasInterval == 0); // WeatherCloud cumulus.WCloudWid = settings.weathercloud.wid ?? string.Empty; cumulus.WCloudKey = settings.weathercloud.key ?? string.Empty; cumulus.WCloudEnabled = settings.weathercloud.enabled; cumulus.SendSolarToWCloud = settings.weathercloud.includesolar; cumulus.SendUVToWCloud = settings.weathercloud.includeuv; cumulus.SynchronisedWCloudUpdate = (60 % cumulus.WCloudInterval == 0); // PWS weather cumulus.PWSCatchUp = settings.pwsweather.catchup; cumulus.PWSEnabled = settings.pwsweather.enabled; cumulus.PWSInterval = settings.pwsweather.interval; cumulus.SendSRToPWS = settings.pwsweather.includesolar; cumulus.SendUVToPWS = settings.pwsweather.includeuv; cumulus.PWSPW = settings.pwsweather.password ?? string.Empty; cumulus.PWSID = settings.pwsweather.stationid ?? string.Empty; cumulus.SynchronisedPWSUpdate = (60 % cumulus.PWSInterval == 0); // WOW cumulus.WOWCatchUp = settings.wow.catchup; cumulus.WOWEnabled = settings.wow.enabled; cumulus.SendSRToWOW = settings.wow.includesolar; cumulus.SendUVToWOW = settings.wow.includeuv; cumulus.WOWInterval = settings.wow.interval; cumulus.WOWPW = settings.wow.password ?? string.Empty;; cumulus.WOWID = settings.wow.stationid ?? string.Empty;; cumulus.SynchronisedWOWUpdate = (60 % cumulus.WOWInterval == 0); // Weatherbug cumulus.WeatherbugCatchUp = settings.weatherbug.catchup; cumulus.WeatherbugEnabled = settings.weatherbug.enabled; cumulus.SendSRToWeatherbug = settings.weatherbug.includesolar; cumulus.SendUVToWeatherbug = settings.weatherbug.includeuv; cumulus.WeatherbugInterval = settings.weatherbug.interval; cumulus.WeatherbugNumber = settings.weatherbug.number ?? string.Empty;; cumulus.WeatherbugPW = settings.weatherbug.password ?? string.Empty;; cumulus.WeatherbugID = settings.weatherbug.publisherid ?? string.Empty;; cumulus.SynchronisedWBUpdate = (60 % cumulus.WeatherbugInterval == 0); // CWOP cumulus.APRSenabled = settings.cwop.enabled; cumulus.APRSID = settings.cwop.id ?? string.Empty;; cumulus.APRSinterval = settings.cwop.interval; cumulus.SendSRToAPRS = settings.cwop.includesolar; cumulus.APRSpass = settings.cwop.password ?? string.Empty;; cumulus.APRSport = settings.cwop.port; cumulus.APRSserver = settings.cwop.server ?? string.Empty;; cumulus.SynchronisedAPRSUpdate = (60 % cumulus.APRSinterval == 0); // HTTP proxy cumulus.HTTPProxyPassword = settings.proxies.httpproxy.password ?? string.Empty; cumulus.HTTPProxyPort = settings.proxies.httpproxy.port; cumulus.HTTPProxyName = settings.proxies.httpproxy.proxy ?? string.Empty; cumulus.HTTPProxyUser = settings.proxies.httpproxy.user ?? string.Empty; // Custom HTTP // custom seconds cumulus.CustomHttpSecondsString = settings.customhttp.customseconds.url ?? string.Empty; cumulus.CustomHttpSecondsEnabled = settings.customhttp.customseconds.enabled; cumulus.CustomHttpSecondsInterval = settings.customhttp.customseconds.interval; cumulus.CustomHttpSecondsTimer.Interval = cumulus.CustomHttpSecondsInterval * 1000; cumulus.CustomHttpSecondsTimer.Enabled = cumulus.CustomHttpSecondsEnabled; // custom minutes cumulus.CustomHttpMinutesString = settings.customhttp.customminutes.url ?? string.Empty; cumulus.CustomHttpMinutesEnabled = settings.customhttp.customminutes.enabled; cumulus.CustomHttpMinutesIntervalIndex = settings.customhttp.customminutes.intervalindex; if (cumulus.CustomHttpMinutesIntervalIndex >= 0 && cumulus.CustomHttpMinutesIntervalIndex < cumulus.FactorsOf60.Length) { cumulus.CustomHttpMinutesInterval = cumulus.FactorsOf60[cumulus.CustomHttpMinutesIntervalIndex]; } else { cumulus.CustomHttpMinutesInterval = 10; } // custom rollover cumulus.CustomHttpRolloverString = settings.customhttp.customrollover.url ?? string.Empty; cumulus.CustomHttpRolloverEnabled = settings.customhttp.customrollover.enabled; // Save the settings cumulus.WriteIniFile(); cumulus.SetUpHttpProxy(); //cumulus.SetFtpLogging(cumulus.FTPlogging); context.Response.StatusCode = 200; } catch (Exception ex) { cumulus.LogMessage(ex.Message); context.Response.StatusCode = 500; return(ex.Message); } return("success"); }
public string UpdateConfig(IHttpContext context) { var errorMsg = ""; var json = ""; JsonProgramSettings settings; context.Response.StatusCode = 200; // get the response try { cumulus.LogMessage("Updating Program settings"); var data = new StreamReader(context.Request.InputStream).ReadToEnd(); // Start at char 5 to skip the "json:" prefix json = WebUtility.UrlDecode(data.Substring(5)); // de-serialize it to the settings structure settings = JsonSerializer.DeserializeFromString <JsonProgramSettings>(json); } catch (Exception ex) { var msg = "Error de-serializing Program Settings JSON: " + ex.Message; cumulus.LogMessage(msg); cumulus.LogDebugMessage("Program Data: " + json); context.Response.StatusCode = 500; return(msg); } // process the settings try { cumulus.ProgramOptions.EnableAccessibility = settings.accessible; cumulus.ProgramOptions.StartupPingHost = settings.startup.startuphostping; cumulus.ProgramOptions.StartupPingEscapeTime = settings.startup.startuppingescape; cumulus.ProgramOptions.StartupDelaySecs = settings.startup.startupdelay; cumulus.ProgramOptions.StartupDelayMaxUptime = settings.startup.startupdelaymaxuptime; cumulus.ProgramOptions.DebugLogging = settings.logging.debuglogging; cumulus.ProgramOptions.DataLogging = settings.logging.datalogging; cumulus.SmtpOptions.Logging = settings.logging.emaillogging; cumulus.ErrorLogSpikeRemoval = settings.logging.spikelogging; cumulus.ProgramOptions.WarnMultiple = settings.options.stopsecondinstance; cumulus.ProgramOptions.ListWebTags = settings.options.listwebtags; if (settings.logging.ftplogging != cumulus.FtpOptions.Logging) { cumulus.FtpOptions.Logging = settings.logging.ftplogging; cumulus.SetFtpLogging(cumulus.FtpOptions.Logging); } } catch (Exception ex) { var msg = "Error processing Program Options: " + ex.Message; cumulus.LogMessage(msg); errorMsg += msg + "\n\n"; context.Response.StatusCode = 500; } // Save the settings cumulus.WriteIniFile(); return(context.Response.StatusCode == 200 ? "success" : errorMsg); }
public string UpdateConfig(IHttpContext context) { var errorMsg = ""; var json = ""; JsonProgramSettings settings; context.Response.StatusCode = 200; // get the response try { cumulus.LogMessage("Updating Program settings"); var data = new StreamReader(context.Request.InputStream).ReadToEnd(); // Start at char 5 to skip the "json:" prefix json = WebUtility.UrlDecode(data.Substring(5)); // de-serialize it to the settings structure settings = JsonSerializer.DeserializeFromString <JsonProgramSettings>(json); } catch (Exception ex) { var msg = "Error de-serializing Program Settings JSON: " + ex.Message; cumulus.LogMessage(msg); cumulus.LogDebugMessage("Program Data: " + json); context.Response.StatusCode = 500; return(msg); } // process the settings try { cumulus.ProgramOptions.EnableAccessibility = settings.accessible; cumulus.ProgramOptions.StartupPingHost = settings.startup.startuphostping; cumulus.ProgramOptions.StartupPingEscapeTime = settings.startup.startuppingescape; cumulus.ProgramOptions.StartupDelaySecs = settings.startup.startupdelay; cumulus.ProgramOptions.StartupDelayMaxUptime = settings.startup.startupdelaymaxuptime; cumulus.ProgramOptions.DataStoppedExit = settings.shutdown.datastoppedexit; cumulus.ProgramOptions.DataStoppedMins = settings.shutdown.datastoppedmins; cumulus.ProgramOptions.DebugLogging = settings.logging.debuglogging; cumulus.ProgramOptions.DataLogging = settings.logging.datalogging; cumulus.SmtpOptions.Logging = settings.logging.emaillogging; cumulus.ErrorLogSpikeRemoval = settings.logging.spikelogging; cumulus.ProgramOptions.WarnMultiple = settings.options.stopsecondinstance; cumulus.ProgramOptions.ListWebTags = settings.options.listwebtags; cumulus.ProgramOptions.Culture.RemoveSpaceFromDateSeparator = settings.culture.removespacefromdateseparator; if (cumulus.ProgramOptions.Culture.RemoveSpaceFromDateSeparator && CultureInfo.CurrentCulture.DateTimeFormat.DateSeparator.Contains(" ")) { // get the existing culture var newCulture = CultureInfo.CurrentCulture; // change the date separator newCulture.DateTimeFormat.DateSeparator = CultureInfo.CurrentCulture.DateTimeFormat.DateSeparator.Replace(" ", ""); // set current thread culture Thread.CurrentThread.CurrentCulture = newCulture; // set the default culture for other threads CultureInfo.DefaultThreadCurrentCulture = newCulture; } else { var newCulture = CultureInfo.GetCultureInfo(CultureInfo.CurrentCulture.Name); if (!cumulus.ProgramOptions.Culture.RemoveSpaceFromDateSeparator && newCulture.DateTimeFormat.DateSeparator.Contains(" ") && !CultureInfo.CurrentCulture.DateTimeFormat.DateSeparator.Contains(" ")) { // set current thread culture Thread.CurrentThread.CurrentCulture = newCulture; // set the default culture for other threads CultureInfo.DefaultThreadCurrentCulture = newCulture; } } if (settings.logging.ftplogging != cumulus.FtpOptions.Logging) { cumulus.FtpOptions.Logging = settings.logging.ftplogging; cumulus.SetFtpLogging(cumulus.FtpOptions.Logging); } } catch (Exception ex) { var msg = "Error processing Program Options: " + ex.Message; cumulus.LogMessage(msg); errorMsg += msg + "\n\n"; context.Response.StatusCode = 500; } // Save the settings cumulus.WriteIniFile(); return(context.Response.StatusCode == 200 ? "success" : errorMsg); }
//public string UpdateInternetConfig(HttpListenerContext context) public string UpdateInternetConfig(IHttpContext context) { var ErrorMsg = ""; context.Response.StatusCode = 200; try { var data = new StreamReader(context.Request.InputStream).ReadToEnd(); // Start at char 5 to skip the "json:" prefix var json = WebUtility.UrlDecode(data.Substring(5)); // de-serialize it to the settings structure var settings = JsonConvert.DeserializeObject <JsonInternetSettingsData>(json); // process the settings cumulus.LogMessage("Updating internet settings"); // website settings try { cumulus.ftp_directory = settings.website.directory ?? string.Empty; cumulus.ForumURL = settings.website.forumurl ?? string.Empty; cumulus.ftp_port = settings.website.ftpport; cumulus.ftp_host = settings.website.hostname ?? string.Empty; cumulus.Sslftp = (Cumulus.FtpProtocols)settings.website.sslftp; cumulus.ftp_password = settings.website.password ?? string.Empty; cumulus.ftp_user = settings.website.username ?? string.Empty; cumulus.SshftpAuthentication = settings.website.sshAuth ?? string.Empty; cumulus.SshftpPskFile = settings.website.pskFile ?? string.Empty; cumulus.WebcamURL = settings.website.webcamurl ?? string.Empty; } catch (Exception ex) { var msg = "Error processing website settings: " + ex.Message; cumulus.LogMessage(msg); ErrorMsg += msg + "\n\n"; context.Response.StatusCode = 500; } // web settings try { cumulus.ActiveFTPMode = settings.websettings.activeftp; cumulus.WebAutoUpdate = settings.websettings.autoupdate; cumulus.RealtimeEnabled = settings.websettings.enablerealtime; cumulus.RealtimeFTPEnabled = settings.websettings.enablerealtimeftp; cumulus.RealtimeTxtFTP = settings.websettings.realtimetxtftp; cumulus.RealtimeGaugesTxtFTP = settings.websettings.realtimegaugestxtftp; cumulus.RealtimeInterval = settings.websettings.realtimeinterval * 1000; cumulus.DeleteBeforeUpload = settings.websettings.ftpdelete; cumulus.UpdateInterval = settings.websettings.ftpinterval; cumulus.FTPRename = settings.websettings.ftprename; cumulus.IncludeStandardFiles = settings.websettings.includestdfiles; cumulus.IncludeGraphDataFiles = settings.websettings.includegraphdatafiles; cumulus.IncludeMoonImage = settings.websettings.includemoonimage; cumulus.UTF8encode = settings.websettings.utf8encode; if (settings.websettings.ftplogging != cumulus.FTPlogging) { cumulus.FTPlogging = settings.websettings.ftplogging; cumulus.SetFtpLogging(cumulus.FTPlogging); } } catch (Exception ex) { var msg = "Error processing web settings: " + ex.Message; cumulus.LogMessage(msg); ErrorMsg += msg + "\n\n"; context.Response.StatusCode = 500; } // external programs try { cumulus.DailyProgram = settings.externalprograms.dailyprogram ?? string.Empty; cumulus.DailyParams = settings.externalprograms.dailyprogramparams ?? string.Empty; cumulus.ExternalProgram = settings.externalprograms.program ?? string.Empty; cumulus.ExternalParams = settings.externalprograms.programparams ?? string.Empty; cumulus.RealtimeProgram = settings.externalprograms.realtimeprogram ?? string.Empty; cumulus.RealtimeParams = settings.externalprograms.realtimeprogramparams ?? string.Empty; } catch (Exception ex) { var msg = "Error processing external programs: " + ex.Message; cumulus.LogMessage(msg); ErrorMsg += msg + "\n\n"; context.Response.StatusCode = 500; } // twitter try { cumulus.TwitterEnabled = settings.twitter.enabled; cumulus.TwitterInterval = settings.twitter.interval; cumulus.TwitterPW = settings.twitter.password ?? string.Empty; cumulus.TwitterSendLocation = settings.twitter.sendlocation; cumulus.Twitteruser = settings.twitter.user ?? string.Empty; cumulus.SynchronisedTwitterUpdate = (60 % cumulus.TwitterInterval == 0); cumulus.TwitterTimer.Interval = cumulus.TwitterInterval * 60 * 1000; cumulus.TwitterTimer.Enabled = cumulus.TwitterEnabled && !cumulus.SynchronisedTwitterUpdate && !String.IsNullOrWhiteSpace(cumulus.Twitteruser) && !String.IsNullOrWhiteSpace(cumulus.TwitterPW); } catch (Exception ex) { var msg = "Error processing twitter settings: " + ex.Message; cumulus.LogMessage(msg); ErrorMsg += msg + "\n\n"; context.Response.StatusCode = 500; } // wunderground try { cumulus.WundCatchUp = settings.wunderground.catchup; cumulus.WundEnabled = settings.wunderground.enabled; cumulus.SendIndoorToWund = settings.wunderground.includeindoor; cumulus.SendSRToWund = settings.wunderground.includesolar; cumulus.SendUVToWund = settings.wunderground.includeuv; cumulus.WundInterval = settings.wunderground.interval; cumulus.WundPW = settings.wunderground.password ?? string.Empty; cumulus.WundRapidFireEnabled = settings.wunderground.rapidfire; cumulus.WundSendAverage = settings.wunderground.sendavgwind; cumulus.WundID = settings.wunderground.stationid ?? string.Empty; cumulus.SynchronisedWUUpdate = (!cumulus.WundRapidFireEnabled) && (60 % cumulus.WundInterval == 0); cumulus.WundTimer.Interval = cumulus.WundRapidFireEnabled ? 5000 : cumulus.WundInterval * 60 * 1000; cumulus.WundTimer.Enabled = cumulus.WundEnabled && !cumulus.SynchronisedWUUpdate && !String.IsNullOrWhiteSpace(cumulus.WundID) && !String.IsNullOrWhiteSpace(cumulus.WundPW); } catch (Exception ex) { var msg = "Error processing wunderground settings: " + ex.Message; cumulus.LogMessage(msg); ErrorMsg += msg + "\n\n"; context.Response.StatusCode = 500; } // Windy try { cumulus.WindyCatchUp = settings.windy.catchup; cumulus.WindyEnabled = settings.windy.enabled; //cumulus.WindySendSolar = settings.windy.includesolar; cumulus.WindySendUV = settings.windy.includeuv; cumulus.WindyInterval = settings.windy.interval; cumulus.WindyApiKey = settings.windy.apikey; cumulus.WindyStationIdx = settings.windy.stationidx; cumulus.SynchronisedWindyUpdate = (60 % cumulus.WindyInterval == 0); cumulus.WindyTimer.Interval = cumulus.WindyInterval * 60 * 1000; cumulus.WindyTimer.Enabled = cumulus.WindyEnabled && !cumulus.SynchronisedWindyUpdate && !String.IsNullOrWhiteSpace(cumulus.WindyApiKey); } catch (Exception ex) { var msg = "Error processing Windy settings: " + ex.Message; cumulus.LogMessage(msg); ErrorMsg += msg + "\n\n"; context.Response.StatusCode = 500; } // Awekas try { cumulus.AwekasEnabled = settings.awekas.enabled; cumulus.AwekasInterval = settings.awekas.interval; cumulus.AwekasLang = settings.awekas.lang; cumulus.AwekasPW = settings.awekas.password ?? string.Empty; cumulus.AwekasUser = settings.awekas.user ?? string.Empty; cumulus.SendSolarToAwekas = settings.awekas.includesolar; cumulus.SendUVToAwekas = settings.awekas.includeuv; cumulus.SendSoilTempToAwekas = settings.awekas.includesoiltemp; cumulus.SendSoilMoistureToAwekas = settings.awekas.includesoilmoisture; cumulus.SendLeafWetnessToAwekas = settings.awekas.includeleafwetness; cumulus.SendIndoorToAwekas = settings.awekas.includeindoor; cumulus.SynchronisedAwekasUpdate = (cumulus.AwekasInterval % 60 == 0); cumulus.AwekasTimer.Interval = cumulus.AwekasInterval * 1000; cumulus.AwekasTimer.Enabled = cumulus.AwekasEnabled && !cumulus.SynchronisedAwekasUpdate && !String.IsNullOrWhiteSpace(cumulus.AwekasUser) && !String.IsNullOrWhiteSpace(cumulus.AwekasPW); } catch (Exception ex) { var msg = "Error processing AWEKAS settings: " + ex.Message; cumulus.LogMessage(msg); ErrorMsg += msg + "\n\n"; context.Response.StatusCode = 500; } // WeatherCloud try { cumulus.WCloudWid = settings.weathercloud.wid ?? string.Empty; cumulus.WCloudKey = settings.weathercloud.key ?? string.Empty; cumulus.WCloudEnabled = settings.weathercloud.enabled; cumulus.SendSolarToWCloud = settings.weathercloud.includesolar; cumulus.SendUVToWCloud = settings.weathercloud.includeuv; cumulus.SynchronisedWCloudUpdate = (60 % cumulus.WCloudInterval == 0); //cumulus.WCloudTimer.Interval = cumulus.WCloudInterval * 60 * 1000; ///cumulus.WCloudTimer.Enabled = cumulus.WCloudEnabled && !cumulus.SynchronisedWCloudUpdate && !String.IsNullOrWhiteSpace(cumulus.WCloudWid) && !String.IsNullOrWhiteSpace(cumulus.WCloudKey); } catch (Exception ex) { var msg = "Error processing WeatherCloud settings: " + ex.Message; cumulus.LogMessage(msg); ErrorMsg += msg + "\n\n"; context.Response.StatusCode = 500; } // PWS weather try { cumulus.PWSCatchUp = settings.pwsweather.catchup; cumulus.PWSEnabled = settings.pwsweather.enabled; cumulus.PWSInterval = settings.pwsweather.interval; cumulus.SendSRToPWS = settings.pwsweather.includesolar; cumulus.SendUVToPWS = settings.pwsweather.includeuv; cumulus.PWSPW = settings.pwsweather.password ?? string.Empty; cumulus.PWSID = settings.pwsweather.stationid ?? string.Empty; cumulus.SynchronisedPWSUpdate = (60 % cumulus.PWSInterval == 0); cumulus.PWSTimer.Interval = cumulus.PWSInterval * 60 * 1000; cumulus.PWSTimer.Enabled = cumulus.PWSEnabled && !cumulus.SynchronisedPWSUpdate && !String.IsNullOrWhiteSpace(cumulus.PWSID) && !String.IsNullOrWhiteSpace(cumulus.PWSPW); } catch (Exception ex) { var msg = "Error processing PWS weather settings: " + ex.Message; cumulus.LogMessage(msg); ErrorMsg += msg + "\n\n"; context.Response.StatusCode = 500; } // WOW try { cumulus.WOWCatchUp = settings.wow.catchup; cumulus.WOWEnabled = settings.wow.enabled; cumulus.SendSRToWOW = settings.wow.includesolar; cumulus.SendUVToWOW = settings.wow.includeuv; cumulus.WOWInterval = settings.wow.interval; cumulus.WOWPW = settings.wow.password ?? string.Empty;; cumulus.WOWID = settings.wow.stationid ?? string.Empty;; cumulus.SynchronisedWOWUpdate = (60 % cumulus.WOWInterval == 0); cumulus.WOWTimer.Interval = cumulus.WOWInterval * 60 * 1000; cumulus.WOWTimer.Enabled = cumulus.WOWEnabled && !cumulus.SynchronisedWOWUpdate && !String.IsNullOrWhiteSpace(cumulus.WOWID) && !String.IsNullOrWhiteSpace(cumulus.WOWPW); } catch (Exception ex) { var msg = "Error processing WOW settings: " + ex.Message; cumulus.LogMessage(msg); ErrorMsg += msg + "\n\n"; context.Response.StatusCode = 500; } // CWOP try { cumulus.APRSenabled = settings.cwop.enabled; cumulus.APRSID = settings.cwop.id ?? string.Empty;; cumulus.APRSinterval = settings.cwop.interval; cumulus.SendSRToAPRS = settings.cwop.includesolar; cumulus.APRSpass = settings.cwop.password ?? string.Empty;; cumulus.APRSport = settings.cwop.port; cumulus.APRSserver = settings.cwop.server ?? string.Empty;; cumulus.SynchronisedAPRSUpdate = (60 % cumulus.APRSinterval == 0); cumulus.APRStimer.Interval = cumulus.APRSinterval * 60 * 1000; cumulus.APRStimer.Enabled = cumulus.APRSenabled && !cumulus.SynchronisedAPRSUpdate && !String.IsNullOrWhiteSpace(cumulus.APRSID) && !String.IsNullOrWhiteSpace(cumulus.APRSpass); } catch (Exception ex) { var msg = "Error processing CWOP settings: " + ex.Message; cumulus.LogMessage(msg); ErrorMsg += msg + "\n\n"; context.Response.StatusCode = 500; } // MQTT try { cumulus.MQTTServer = settings.mqtt.server ?? string.Empty; cumulus.MQTTPort = settings.mqtt.port; cumulus.MQTTUseTLS = settings.mqtt.useTls; cumulus.MQTTUsername = settings.mqtt.username ?? string.Empty; cumulus.MQTTPassword = settings.mqtt.password ?? string.Empty; cumulus.MQTTEnableDataUpdate = settings.mqtt.dataUpdate.enabled; cumulus.MQTTUpdateTopic = settings.mqtt.dataUpdate.topic ?? string.Empty; cumulus.MQTTUpdateTemplate = settings.mqtt.dataUpdate.template ?? string.Empty; cumulus.MQTTEnableInterval = settings.mqtt.interval.enabled; cumulus.MQTTIntervalTime = settings.mqtt.interval.time; cumulus.MQTTIntervalTopic = settings.mqtt.interval.topic ?? string.Empty; cumulus.MQTTIntervalTemplate = settings.mqtt.interval.template ?? string.Empty; cumulus.MQTTTimer.Interval = cumulus.MQTTIntervalTime * 1000; cumulus.MQTTTimer.Enabled = cumulus.MQTTEnableInterval && !String.IsNullOrWhiteSpace(cumulus.MQTTIntervalTopic) && !String.IsNullOrWhiteSpace(cumulus.MQTTIntervalTemplate); } catch (Exception ex) { var msg = "Error processing MQTT settings: " + ex.Message; cumulus.LogMessage(msg); ErrorMsg += msg + "\n\n"; context.Response.StatusCode = 500; } // Moon Image try { cumulus.MoonImageEnabled = settings.moonimage.enabled; cumulus.MoonImageSize = settings.moonimage.size; cumulus.MoonImageFtpDest = settings.moonimage.ftpdest; } catch (Exception ex) { var msg = "Error processing Moon image settings: " + ex.Message; cumulus.LogMessage(msg); ErrorMsg += msg + "\n\n"; context.Response.StatusCode = 500; } // HTTP proxy try { cumulus.HTTPProxyPassword = settings.proxies.httpproxy.password ?? string.Empty; cumulus.HTTPProxyPort = settings.proxies.httpproxy.port; cumulus.HTTPProxyName = settings.proxies.httpproxy.proxy ?? string.Empty; cumulus.HTTPProxyUser = settings.proxies.httpproxy.user ?? string.Empty; } catch (Exception ex) { var msg = "Error processing HTTP proxy settings: " + ex.Message; cumulus.LogMessage(msg); ErrorMsg += msg + "\n\n"; context.Response.StatusCode = 500; } // Custom HTTP try { // custom seconds cumulus.CustomHttpSecondsString = settings.customhttp.customseconds.url ?? string.Empty; cumulus.CustomHttpSecondsEnabled = settings.customhttp.customseconds.enabled; cumulus.CustomHttpSecondsInterval = settings.customhttp.customseconds.interval; cumulus.CustomHttpSecondsTimer.Interval = cumulus.CustomHttpSecondsInterval * 1000; cumulus.CustomHttpSecondsTimer.Enabled = cumulus.CustomHttpSecondsEnabled; // custom minutes cumulus.CustomHttpMinutesString = settings.customhttp.customminutes.url ?? string.Empty; cumulus.CustomHttpMinutesEnabled = settings.customhttp.customminutes.enabled; cumulus.CustomHttpMinutesIntervalIndex = settings.customhttp.customminutes.intervalindex; if (cumulus.CustomHttpMinutesIntervalIndex >= 0 && cumulus.CustomHttpMinutesIntervalIndex < cumulus.FactorsOf60.Length) { cumulus.CustomHttpMinutesInterval = cumulus.FactorsOf60[cumulus.CustomHttpMinutesIntervalIndex]; } else { cumulus.CustomHttpMinutesInterval = 10; } // custom rollover cumulus.CustomHttpRolloverString = settings.customhttp.customrollover.url ?? string.Empty; cumulus.CustomHttpRolloverEnabled = settings.customhttp.customrollover.enabled; } catch (Exception ex) { var msg = "Error processing Custom settings: " + ex.Message; cumulus.LogMessage(msg); ErrorMsg += msg + "\n\n"; context.Response.StatusCode = 500; } // Save the settings cumulus.WriteIniFile(); cumulus.SetUpHttpProxy(); //cumulus.SetFtpLogging(cumulus.FTPlogging); // Setup MQTT if (cumulus.MQTTEnableDataUpdate || cumulus.MQTTEnableInterval) { if (!MqttPublisher.configured) { MqttPublisher.Setup(cumulus); } if (cumulus.MQTTEnableInterval) { cumulus.MQTTTimer.Elapsed -= cumulus.MQTTTimerTick; cumulus.MQTTTimer.Elapsed += cumulus.MQTTTimerTick; cumulus.MQTTTimer.Start(); } else { cumulus.MQTTTimer.Stop(); } } else { cumulus.MQTTTimer.Stop(); } } catch (Exception ex) { cumulus.LogMessage(ex.Message); context.Response.StatusCode = 500; return(ex.Message); } if (context.Response.StatusCode == 200) { return("success"); } else { return(ErrorMsg); } }