//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 = ""; JsonInternetSettingsData settings; context.Response.StatusCode = 200; try { 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 = json.FromJson <JsonInternetSettingsData>(); } catch (Exception ex) { var msg = "Error de-serializing Internet Settings JSON: " + ex.Message; cumulus.LogMessage(msg); cumulus.LogDebugMessage("Internet Data: " + json); context.Response.StatusCode = 500; return(msg); } // process the settings try { cumulus.LogMessage("Updating internet settings"); // website settings try { cumulus.FtpOptions.Enabled = settings.website.enabled; if (cumulus.FtpOptions.Enabled) { cumulus.FtpOptions.Directory = settings.website.directory ?? string.Empty; cumulus.FtpOptions.Port = settings.website.ftpport; cumulus.FtpOptions.Hostname = settings.website.hostname ?? string.Empty; cumulus.FtpOptions.FtpMode = (Cumulus.FtpProtocols)settings.website.sslftp; cumulus.FtpOptions.Password = settings.website.password ?? string.Empty; cumulus.FtpOptions.Username = settings.website.username ?? string.Empty; cumulus.FtpOptions.SshAuthen = settings.website.sshAuth ?? string.Empty; cumulus.FtpOptions.SshPskFile = settings.website.pskFile ?? string.Empty; cumulus.DeleteBeforeUpload = settings.website.general.ftpdelete; cumulus.FTPRename = settings.website.general.ftprename; cumulus.UTF8encode = settings.website.general.utf8encode; if (cumulus.FtpOptions.FtpMode == Cumulus.FtpProtocols.FTP || cumulus.FtpOptions.FtpMode == Cumulus.FtpProtocols.FTPS) { cumulus.FtpOptions.AutoDetect = settings.website.advanced.autodetect; cumulus.FtpOptions.ActiveMode = settings.website.advanced.activeftp; cumulus.FtpOptions.DisableEPSV = settings.website.advanced.disableftpsepsv; } if (cumulus.FtpOptions.FtpMode == Cumulus.FtpProtocols.FTPS) { cumulus.FtpOptions.DisableExplicit = settings.website.advanced.disableftpsexplicit; cumulus.FtpOptions.IgnoreCertErrors = settings.website.advanced.ignorecerts; } } cumulus.FtpOptions.LocalCopyEnabled = settings.website.localcopy; if (cumulus.FtpOptions.LocalCopyEnabled) { cumulus.FtpOptions.LocalCopyFolder = settings.website.localcopyfolder; } } 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.RealtimeIntervalEnabled = settings.websettings.realtime.enabled; if (cumulus.RealtimeIntervalEnabled) { cumulus.FtpOptions.RealtimeEnabled = settings.websettings.realtime.enablerealtimeftp; cumulus.RealtimeInterval = settings.websettings.realtime.realtimeinterval * 1000; if (cumulus.RealtimeTimer.Interval != cumulus.RealtimeInterval) { cumulus.RealtimeTimer.Interval = cumulus.RealtimeInterval; } for (var i = 0; i < cumulus.RealtimeFiles.Length; i++) { cumulus.RealtimeFiles[i].Create = settings.websettings.realtime.files[i].create; cumulus.RealtimeFiles[i].FTP = cumulus.RealtimeFiles[i].Create && settings.websettings.realtime.files[i].ftp; cumulus.RealtimeFiles[i].Copy = cumulus.RealtimeFiles[i].Create && settings.websettings.realtime.files[i].copy; } } cumulus.RealtimeTimer.Enabled = cumulus.RealtimeIntervalEnabled; if (!cumulus.RealtimeTimer.Enabled || !cumulus.FtpOptions.RealtimeEnabled) { cumulus.RealtimeFTPDisconnect(); } cumulus.WebIntervalEnabled = settings.websettings.interval.enabled; if (cumulus.WebIntervalEnabled) { cumulus.FtpOptions.IntervalEnabled = settings.websettings.interval.enableintervalftp; cumulus.UpdateInterval = settings.websettings.interval.ftpinterval; if (cumulus.WebTimer.Interval != cumulus.UpdateInterval * 60 * 1000) { cumulus.WebTimer.Interval = cumulus.UpdateInterval * 60 * 1000; } for (var i = 0; i < cumulus.StdWebFiles.Length; i++) { cumulus.StdWebFiles[i].Create = settings.websettings.interval.stdfiles.files[i].create; cumulus.StdWebFiles[i].FTP = cumulus.StdWebFiles[i].Create && settings.websettings.interval.stdfiles.files[i].ftp; cumulus.StdWebFiles[i].Copy = cumulus.StdWebFiles[i].Create && settings.websettings.interval.stdfiles.files[i].copy; } for (var i = 0; i < cumulus.GraphDataFiles.Length; i++) { cumulus.GraphDataFiles[i].Create = settings.websettings.interval.graphfiles.files[i].create; cumulus.GraphDataFiles[i].FTP = cumulus.GraphDataFiles[i].Create && settings.websettings.interval.graphfiles.files[i].ftp; cumulus.GraphDataFiles[i].Copy = cumulus.GraphDataFiles[i].Create && settings.websettings.interval.graphfiles.files[i].copy; } for (var i = 0; i < cumulus.GraphDataEodFiles.Length; i++) { cumulus.GraphDataEodFiles[i].Create = settings.websettings.interval.graphfileseod.files[i].create; cumulus.GraphDataEodFiles[i].FTP = cumulus.GraphDataEodFiles[i].Create && settings.websettings.interval.graphfileseod.files[i].ftp; cumulus.GraphDataEodFiles[i].Copy = cumulus.GraphDataEodFiles[i].Create && settings.websettings.interval.graphfileseod.files[i].copy; } } } 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 { if (settings.externalprograms != null) { 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; } // MQTT try { cumulus.MQTT.Server = settings.mqtt.server ?? string.Empty; cumulus.MQTT.Port = settings.mqtt.port; cumulus.MQTT.UseTLS = settings.mqtt.useTls; cumulus.MQTT.Username = settings.mqtt.username ?? string.Empty; cumulus.MQTT.Password = settings.mqtt.password ?? string.Empty; cumulus.MQTT.EnableDataUpdate = settings.mqtt.dataUpdate.enabled; if (cumulus.MQTT.EnableDataUpdate) { cumulus.MQTT.UpdateTemplate = settings.mqtt.dataUpdate.template ?? string.Empty; } cumulus.MQTT.EnableInterval = settings.mqtt.interval.enabled; if (cumulus.MQTT.EnableInterval) { cumulus.MQTT.IntervalTime = settings.mqtt.interval.time; cumulus.MQTT.IntervalTemplate = settings.mqtt.interval.template ?? string.Empty; cumulus.MQTTTimer.Interval = cumulus.MQTT.IntervalTime * 1000; cumulus.MQTTTimer.Enabled = cumulus.MQTT.EnableInterval && !string.IsNullOrWhiteSpace(cumulus.MQTT.IntervalTemplate); } } 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.MoonImage.Enabled = settings.moonimage.enabled; if (cumulus.MoonImage.Enabled) { cumulus.MoonImage.Size = settings.moonimage.size; if (cumulus.MoonImage.Size < 10) { cumulus.MoonImage.Size = 10; } cumulus.MoonImage.Ftp = settings.moonimage.includemoonimage; if (cumulus.MoonImage.Ftp) { cumulus.MoonImage.FtpDest = settings.moonimage.ftpdest; } cumulus.MoonImage.Copy = settings.moonimage.copyimage; if (cumulus.MoonImage.Copy) { cumulus.MoonImage.CopyDest = settings.moonimage.copydest; } } } 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; } // email settings try { cumulus.SmtpOptions.Enabled = settings.emailsettings.enabled; if (cumulus.SmtpOptions.Enabled) { cumulus.SmtpOptions.Server = settings.emailsettings.server; cumulus.SmtpOptions.Port = settings.emailsettings.port; cumulus.SmtpOptions.SslOption = settings.emailsettings.ssloption; cumulus.SmtpOptions.RequiresAuthentication = settings.emailsettings.authenticate; cumulus.SmtpOptions.User = settings.emailsettings.user; cumulus.SmtpOptions.Password = settings.emailsettings.password; cumulus.SmtpOptions.IgnoreCertErrors = settings.emailsettings.ignorecerterrors; if (cumulus.emailer == null) { cumulus.emailer = new EmailSender(cumulus); } } } catch (Exception ex) { var msg = "Error processing Email settings: " + ex.Message; cumulus.LogMessage(msg); errorMsg += msg + "\n\n"; context.Response.StatusCode = 500; } // misc settings try { cumulus.WebcamURL = settings.misc.webcamurl ?? string.Empty; cumulus.ForumURL = settings.misc.forumurl ?? string.Empty; } catch (Exception ex) { var msg = "Error processing Misc 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.MQTT.EnableDataUpdate || cumulus.MQTT.EnableInterval) { if (!MqttPublisher.configured) { MqttPublisher.Setup(cumulus); } if (cumulus.MQTT.EnableInterval) { cumulus.MQTTTimer.Elapsed -= cumulus.MQTTTimerTick; cumulus.MQTTTimer.Elapsed += cumulus.MQTTTimerTick; cumulus.MQTTTimer.Start(); } else { cumulus.MQTTTimer.Stop(); } } else { cumulus.MQTTTimer.Stop(); } } catch (Exception ex) { var msg = "Error processing Internet settings: " + ex.Message; cumulus.LogMessage(msg); cumulus.LogDebugMessage("Internet data: " + json); errorMsg += msg; context.Response.StatusCode = 500; } 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); } }