diff --git a/OctoConnect/ConnectionPanel.Designer.cs b/OctoConnect/ConnectionPanel.Designer.cs index 903c501..ac13776 100644 --- a/OctoConnect/ConnectionPanel.Designer.cs +++ b/OctoConnect/ConnectionPanel.Designer.cs @@ -37,6 +37,7 @@ private void InitializeComponent() this.labelPort = new System.Windows.Forms.Label(); this.bindingConnection = new System.Windows.Forms.BindingSource(this.components); this.numericUpDownPort = new System.Windows.Forms.NumericUpDown(); + this.checkBoxSsl = new System.Windows.Forms.CheckBox(); ((System.ComponentModel.ISupportInitialize)(this.bindingConnection)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownPort)).BeginInit(); this.SuspendLayout(); @@ -111,10 +112,22 @@ private void InitializeComponent() 0}); this.numericUpDownPort.ValueChanged += new System.EventHandler(this.numericUpDownPort_ValueChanged); // + // checkBoxSsl + // + this.checkBoxSsl.AutoSize = true; + this.checkBoxSsl.Location = new System.Drawing.Point(174, 66); + this.checkBoxSsl.Name = "checkBoxSsl"; + this.checkBoxSsl.Size = new System.Drawing.Size(133, 17); + this.checkBoxSsl.TabIndex = 7; + this.checkBoxSsl.Text = "Connect using HTTPS"; + this.checkBoxSsl.UseVisualStyleBackColor = true; + this.checkBoxSsl.CheckedChanged += new System.EventHandler(this.checkBoxSsl_CheckedChanged); + // // ConnectionPanel // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.checkBoxSsl); this.Controls.Add(this.numericUpDownPort); this.Controls.Add(this.labelPort); this.Controls.Add(this.textBoxHostname); @@ -139,5 +152,6 @@ private void InitializeComponent() private System.Windows.Forms.Label labelPort; private System.Windows.Forms.BindingSource bindingConnection; private System.Windows.Forms.NumericUpDown numericUpDownPort; + private System.Windows.Forms.CheckBox checkBoxSsl; } } diff --git a/OctoConnect/ConnectionPanel.cs b/OctoConnect/ConnectionPanel.cs index 4a12fce..b87f15c 100644 --- a/OctoConnect/ConnectionPanel.cs +++ b/OctoConnect/ConnectionPanel.cs @@ -46,6 +46,12 @@ private void numericUpDownPort_ValueChanged(object sender, EventArgs e) con.Port = (int)numericUpDownPort.Value; } + private void checkBoxSsl_CheckedChanged(object sender, EventArgs e) + { + if (updating) return; + con.UseSsl = checkBoxSsl.Checked; + } + bool updating; private void bindingConnection_CurrentItemChanged(object sender, EventArgs e) { @@ -53,6 +59,7 @@ private void bindingConnection_CurrentItemChanged(object sender, EventArgs e) textBoxApiKey.Text = con.Apikey; textBoxHostname.Text = con.Hostname; numericUpDownPort.Value = con.Port; + checkBoxSsl.Checked = con.UseSsl; updating = false; } } diff --git a/OctoConnect/Connector.cs b/OctoConnect/Connector.cs index 748d69d..5dd99c4 100644 --- a/OctoConnect/Connector.cs +++ b/OctoConnect/Connector.cs @@ -101,14 +101,14 @@ dynamic getOctoPrintJSON(string apiname) { var wc = new WebClient(); wc.Headers["X-Api-Key"] = apikey; wc.Headers[HttpRequestHeader.ContentType] = "application/json"; - string response = wc.DownloadString(string.Format(@"http://{0}:{1}/api/{2}?apikey={3}", hostname, port, apiname, apikey)); + string response = wc.DownloadString(string.Format(@"{0}://{1}:{2}/api/{3}?apikey={4}", usessl ? "https" : "http", hostname, port, apiname, apikey)); return JObject.Parse(response == "" ? "{}" : response); // Parse method doesn't accept an empty string, so instead we give it an empty JSON } dynamic postOctoPrintJSON(string apiname, string json = "") { var wc = new WebClient(); wc.Headers["X-Api-Key"] = apikey; wc.Headers[HttpRequestHeader.ContentType] = "application/json"; - string response = wc.UploadString(string.Format(@"http://{0}:{1}/api/{2}", hostname, port, apiname), json); + string response = wc.UploadString(string.Format(@"{0}://{1}:{2}/api/{3}", usessl ? "https" : "http", hostname, port, apiname), json); return JObject.Parse(response == "" ? "{}" : response); } float uploadPercentDone = 0; @@ -119,7 +119,7 @@ Task postOctoPrintGCode(string filepath) wc.UploadProgressChanged += (o, e) => uploadPercentDone = ((float)e.BytesSent / e.TotalBytesToSend) * 100; // ProgressPercentage is int, not double wc.UploadFileCompleted += (o, e) => uploadDone = true; wc.Headers["X-Api-Key"] = apikey; - return wc.UploadFileTaskAsync(new Uri(string.Format(@"http://{0}:{1}/api/files/local", hostname, port)), filepath); + return wc.UploadFileTaskAsync(new Uri(string.Format(@"{0}://{1}:{2}/api/files/local", usessl ? "https" : "http", hostname, port)), filepath); } bool connectToPrinter() { @@ -187,7 +187,7 @@ public override bool Connect(bool failSilent = false) string username = loginResponse["name"]; string session = loginResponse["session"]; - string websocketUri = string.Format(@"ws://{0}:{1}/sockjs/websocket", hostname, port); + string websocketUri = string.Format(@"{0}://{1}:{2}/sockjs/websocket", usessl ? "wss" : "ws", hostname, port); if (pushSocket != null) if (pushSocket.Url.ToString() != websocketUri) // Test if address in panel changed { @@ -545,12 +545,14 @@ public override void LoadFromRegistry() Apikey = key.GetString("opapikey", apikey); Hostname = key.GetString("ophostname", hostname); Port = key.GetInt("opport", port); + UseSsl = key.GetBool("opusessl", usessl); } public override void SaveToRegistry() { key.SetString("opapikey", apikey == null ? "" : apikey); key.SetString("ophostname", hostname); key.SetInt("opport", port); + key.SetBool("opusessl", usessl); } @@ -589,5 +591,11 @@ protected virtual void OnPropertyChanged(PropertyChangedEventArgs e) get { return hostname; } set { hostname = value; OnPropertyChanged(new PropertyChangedEventArgs("Hostname")); } } + + bool usessl = false; public bool UseSsl + { + get { return usessl; } + set { usessl = value; OnPropertyChanged(new PropertyChangedEventArgs("UseSsl")); } + } } } diff --git a/OctoConnect/OctoConnect.csproj b/OctoConnect/OctoConnect.csproj index 42eba36..0102ac5 100644 --- a/OctoConnect/OctoConnect.csproj +++ b/OctoConnect/OctoConnect.csproj @@ -32,10 +32,10 @@ - ..\..\..\..\..\..\Programs\Repetier-Host\Newtonsoft.Json.dll + ..\..\..\..\..\..\Program Files\Repetier-Host\Newtonsoft.Json.dll - ..\..\..\..\..\..\Programs\Repetier-Host\RepetierHostExtender.dll + ..\..\..\..\..\..\Program Files\Repetier-Host\RepetierHostExtender.dll @@ -48,7 +48,7 @@ - ..\..\..\..\..\..\Programs\Repetier-Host\plugins\RepetierServerConnector\websocket-sharp.dll + ..\..\..\..\..\..\Program Files\Repetier-Host\plugins\RepetierServerConnector\websocket-sharp.dll