diff --git a/ShareX/UploadTask.cs b/ShareX/UploadTask.cs index 6954b65e8..b31241404 100644 --- a/ShareX/UploadTask.cs +++ b/ShareX/UploadTask.cs @@ -931,7 +931,7 @@ public UploadResult UploadFile(Stream stream, string fileName) fileUploader = new AmazonS3(Program.UploadersConfig.AmazonS3Settings); break; case FileDestination.OwnCloud: - fileUploader = new OwnCloud("http://demo.owncloud.org", "test", "test"); + fileUploader = new OwnCloud(Program.UploadersConfig.OwnCloudHost, Program.UploadersConfig.OwnCloudUsername, Program.UploadersConfig.OwnCloudPassword, Program.UploadersConfig.OwnCloudPath); break; case FileDestination.Pushbullet: fileUploader = new Pushbullet(Program.UploadersConfig.PushbulletSettings); diff --git a/UploadersLib/Favicons/OwnCloud.png b/UploadersLib/Favicons/OwnCloud.png new file mode 100644 index 000000000..8067350ef Binary files /dev/null and b/UploadersLib/Favicons/OwnCloud.png differ diff --git a/UploadersLib/FileUploaders/OwnCloud.cs b/UploadersLib/FileUploaders/OwnCloud.cs index fd1a0ebfc..db3c295a1 100644 --- a/UploadersLib/FileUploaders/OwnCloud.cs +++ b/UploadersLib/FileUploaders/OwnCloud.cs @@ -24,12 +24,14 @@ #endregion License Information (GPL v3) using HelpersLib; +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Collections.Specialized; using System.IO; using System.Linq; using System.Text; +using System.Web; namespace UploadersLib.FileUploaders { @@ -40,34 +42,12 @@ public sealed class OwnCloud : FileUploader public string Password { get; set; } public string Path { get; set; } - public OwnCloud(string host, string username, string password) + public OwnCloud(string host, string username, string password, string path = "/") { Host = host; Username = username; Password = password; - } - - public string ShareFile(string path) - { - Dictionary args = new Dictionary(); - args.Add("format", "json"); - args.Add("path", path); // path to the file/folder which should be shared - args.Add("shareType", "3"); // ‘0’ = user; ‘1’ = group; ‘3’ = public link - // args.Add("shareWith", ""); // user / group id with which the file should be shared - // args.Add("publicUpload", "false"); // allow public upload to a public shared folder (true/false) - // args.Add("password", ""); // password to protect public link Share with - // args.Add("permissions", "1"); // 1 = read; 2 = update; 4 = create; 8 = delete; 16 = share; 31 = all (default: 31, for public shares: 1) - - string url = URLHelpers.CombineURL(Host, "ocs/v1.php/apps/files_sharing/api/v1/shares"); - NameValueCollection headers = CreateAuthenticationHeader(Username, Password); - string response = SendRequest(HttpMethod.GET, url, args, headers); - - if (!string.IsNullOrEmpty(response)) - { - return ""; // Parse response - } - - return null; + Path = path; } public override UploadResult Upload(Stream stream, string fileName) @@ -87,16 +67,77 @@ public override UploadResult Upload(Stream stream, string fileName) Path = "/"; } - string url = URLHelpers.CombineURL(Host, "remote.php/webdav", Path); + string path = URLHelpers.CombineURL(Path, fileName); + string url = URLHelpers.CombineURL(Host, "remote.php/webdav", path); NameValueCollection headers = CreateAuthenticationHeader(Username, Password); UploadResult result = UploadData(stream, url, fileName, headers: headers, method: HttpMethod.PUT); - if (result.IsSuccess) + if (!IsError) { - result.URL = ShareFile(Path); + result.URL = ShareFile(path); } return result; } + + // http://doc.owncloud.org/server/7.0/developer_manual/core/ocs-share-api.html#create-a-new-share + public string ShareFile(string path) + { + Dictionary args = new Dictionary(); + args.Add("path", path); // path to the file/folder which should be shared + args.Add("shareType", "3"); // ‘0’ = user; ‘1’ = group; ‘3’ = public link + // args.Add("shareWith", ""); // user / group id with which the file should be shared + // args.Add("publicUpload", "false"); // allow public upload to a public shared folder (true/false) + // args.Add("password", ""); // password to protect public link Share with + args.Add("permissions", "1"); // 1 = read; 2 = update; 4 = create; 8 = delete; 16 = share; 31 = all (default: 31, for public shares: 1) + + string url = URLHelpers.CombineURL(Host, "ocs/v1.php/apps/files_sharing/api/v1/shares?format=json"); + NameValueCollection headers = CreateAuthenticationHeader(Username, Password); + string response = SendRequest(HttpMethod.POST, url, args, headers); + + if (!string.IsNullOrEmpty(response)) + { + OwnCloudShareResponse result = JsonConvert.DeserializeObject(response); + + if (result != null && result.ocs != null && result.ocs.meta != null) + { + if (result.ocs.data != null && result.ocs.meta.statuscode == 100) + { + return result.ocs.data.url; + } + else + { + Errors.Add(string.Format("Status: {0}\r\nStatus code: {1}\r\nMessage: {2}", result.ocs.meta.status, result.ocs.meta.statuscode, result.ocs.meta.message)); + } + } + } + + return null; + } + + public class OwnCloudShareResponse + { + public OwnCloudShareResponseOcs ocs { get; set; } + } + + public class OwnCloudShareResponseOcs + { + public OwnCloudShareResponseMeta meta { get; set; } + public OwnCloudShareResponseData data { get; set; } + } + + public class OwnCloudShareResponseMeta + { + public string status { get; set; } + public int statuscode { get; set; } + public string message { get; set; } + } + + public class OwnCloudShareResponseData + { + public int id { get; set; } + public string url { get; set; } + public string token { get; set; } + } } } \ No newline at end of file diff --git a/UploadersLib/Forms/UploadersConfigForm.Designer.cs b/UploadersLib/Forms/UploadersConfigForm.Designer.cs index a510f0649..c1f340de9 100644 --- a/UploadersLib/Forms/UploadersConfigForm.Designer.cs +++ b/UploadersLib/Forms/UploadersConfigForm.Designer.cs @@ -37,6 +37,7 @@ private void InitializeComponent() this.tpOtherUploaders = new System.Windows.Forms.TabPage(); this.tcOtherUploaders = new System.Windows.Forms.TabControl(); this.tpCustomUploaders = new System.Windows.Forms.TabPage(); + this.btnCustomUploaderExamples = new System.Windows.Forms.Button(); this.btnCustomUploaderHelp = new System.Windows.Forms.Button(); this.lblCustomUploaderImageUploader = new System.Windows.Forms.Label(); this.btnCustomUploaderFileUploaderTest = new System.Windows.Forms.Button(); @@ -183,6 +184,15 @@ private void InitializeComponent() this.btnGoogleDriveRefreshFolders = new System.Windows.Forms.Button(); this.cbGoogleDriveIsPublic = new System.Windows.Forms.CheckBox(); this.oauth2GoogleDrive = new UploadersLib.OAuthControl(); + this.tpOwnCloud = new System.Windows.Forms.TabPage(); + this.txtOwnCloudPath = new System.Windows.Forms.TextBox(); + this.txtOwnCloudPassword = new System.Windows.Forms.TextBox(); + this.txtOwnCloudUsername = new System.Windows.Forms.TextBox(); + this.txtOwnCloudHost = new System.Windows.Forms.TextBox(); + this.lblOwnCloudPath = new System.Windows.Forms.Label(); + this.lblOwnCloudPassword = new System.Windows.Forms.Label(); + this.lblOwnCloudUsername = new System.Windows.Forms.Label(); + this.lblOwnCloudHost = new System.Windows.Forms.Label(); this.tpPushbullet = new System.Windows.Forms.TabPage(); this.lblPushbulletDevices = new System.Windows.Forms.Label(); this.cboPushbulletDevices = new System.Windows.Forms.ComboBox(); @@ -361,7 +371,6 @@ private void InitializeComponent() this.ttlvMain = new HelpersLib.TabToListView(); this.lblWidthHint = new System.Windows.Forms.Label(); this.actRapidShareAccountType = new UploadersLib.AccountTypeControl(); - this.btnCustomUploaderExamples = new System.Windows.Forms.Button(); this.tpOtherUploaders.SuspendLayout(); this.tcOtherUploaders.SuspendLayout(); this.tpCustomUploaders.SuspendLayout(); @@ -384,6 +393,7 @@ private void InitializeComponent() this.tpMega.SuspendLayout(); this.tpAmazonS3.SuspendLayout(); this.tpGoogleDrive.SuspendLayout(); + this.tpOwnCloud.SuspendLayout(); this.tpPushbullet.SuspendLayout(); this.tpBox.SuspendLayout(); this.tpRapidShare.SuspendLayout(); @@ -526,6 +536,16 @@ private void InitializeComponent() this.tpCustomUploaders.Text = "Custom uploaders"; this.tpCustomUploaders.UseVisualStyleBackColor = true; // + // btnCustomUploaderExamples + // + this.btnCustomUploaderExamples.Location = new System.Drawing.Point(560, 376); + this.btnCustomUploaderExamples.Name = "btnCustomUploaderExamples"; + this.btnCustomUploaderExamples.Size = new System.Drawing.Size(80, 24); + this.btnCustomUploaderExamples.TabIndex = 32; + this.btnCustomUploaderExamples.Text = "Examples..."; + this.btnCustomUploaderExamples.UseVisualStyleBackColor = true; + this.btnCustomUploaderExamples.Click += new System.EventHandler(this.btnCustomUploaderExamples_Click); + // // btnCustomUploaderHelp // this.btnCustomUploaderHelp.Location = new System.Drawing.Point(488, 376); @@ -1285,6 +1305,7 @@ private void InitializeComponent() this.tcFileUploaders.Controls.Add(this.tpMega); this.tcFileUploaders.Controls.Add(this.tpAmazonS3); this.tcFileUploaders.Controls.Add(this.tpGoogleDrive); + this.tcFileUploaders.Controls.Add(this.tpOwnCloud); this.tcFileUploaders.Controls.Add(this.tpPushbullet); this.tcFileUploaders.Controls.Add(this.tpBox); this.tcFileUploaders.Controls.Add(this.tpRapidShare); @@ -2023,6 +2044,93 @@ private void InitializeComponent() this.oauth2GoogleDrive.ClearButtonClicked += new UploadersLib.OAuthControl.ClearButtonclickedEventHandler(this.oauth2GoogleDrive_ClearButtonClicked); this.oauth2GoogleDrive.RefreshButtonClicked += new UploadersLib.OAuthControl.RefreshButtonClickedEventHandler(this.oauth2GoogleDrive_RefreshButtonClicked); // + // tpOwnCloud + // + this.tpOwnCloud.Controls.Add(this.txtOwnCloudPath); + this.tpOwnCloud.Controls.Add(this.txtOwnCloudPassword); + this.tpOwnCloud.Controls.Add(this.txtOwnCloudUsername); + this.tpOwnCloud.Controls.Add(this.txtOwnCloudHost); + this.tpOwnCloud.Controls.Add(this.lblOwnCloudPath); + this.tpOwnCloud.Controls.Add(this.lblOwnCloudPassword); + this.tpOwnCloud.Controls.Add(this.lblOwnCloudUsername); + this.tpOwnCloud.Controls.Add(this.lblOwnCloudHost); + this.tpOwnCloud.Location = new System.Drawing.Point(4, 22); + this.tpOwnCloud.Name = "tpOwnCloud"; + this.tpOwnCloud.Padding = new System.Windows.Forms.Padding(3); + this.tpOwnCloud.Size = new System.Drawing.Size(972, 493); + this.tpOwnCloud.TabIndex = 15; + this.tpOwnCloud.Text = "ownCloud"; + this.tpOwnCloud.UseVisualStyleBackColor = true; + // + // txtOwnCloudPath + // + this.txtOwnCloudPath.Location = new System.Drawing.Point(80, 84); + this.txtOwnCloudPath.Name = "txtOwnCloudPath"; + this.txtOwnCloudPath.Size = new System.Drawing.Size(248, 20); + this.txtOwnCloudPath.TabIndex = 7; + this.txtOwnCloudPath.TextChanged += new System.EventHandler(this.txtOwnCloudPath_TextChanged); + // + // txtOwnCloudPassword + // + this.txtOwnCloudPassword.Location = new System.Drawing.Point(80, 60); + this.txtOwnCloudPassword.Name = "txtOwnCloudPassword"; + this.txtOwnCloudPassword.Size = new System.Drawing.Size(248, 20); + this.txtOwnCloudPassword.TabIndex = 6; + this.txtOwnCloudPassword.UseSystemPasswordChar = true; + this.txtOwnCloudPassword.TextChanged += new System.EventHandler(this.txtOwnCloudPassword_TextChanged); + // + // txtOwnCloudUsername + // + this.txtOwnCloudUsername.Location = new System.Drawing.Point(80, 36); + this.txtOwnCloudUsername.Name = "txtOwnCloudUsername"; + this.txtOwnCloudUsername.Size = new System.Drawing.Size(248, 20); + this.txtOwnCloudUsername.TabIndex = 5; + this.txtOwnCloudUsername.TextChanged += new System.EventHandler(this.txtOwnCloudUsername_TextChanged); + // + // txtOwnCloudHost + // + this.txtOwnCloudHost.Location = new System.Drawing.Point(80, 12); + this.txtOwnCloudHost.Name = "txtOwnCloudHost"; + this.txtOwnCloudHost.Size = new System.Drawing.Size(248, 20); + this.txtOwnCloudHost.TabIndex = 4; + this.txtOwnCloudHost.TextChanged += new System.EventHandler(this.txtOwnCloudHost_TextChanged); + // + // lblOwnCloudPath + // + this.lblOwnCloudPath.AutoSize = true; + this.lblOwnCloudPath.Location = new System.Drawing.Point(16, 88); + this.lblOwnCloudPath.Name = "lblOwnCloudPath"; + this.lblOwnCloudPath.Size = new System.Drawing.Size(32, 13); + this.lblOwnCloudPath.TabIndex = 3; + this.lblOwnCloudPath.Text = "Path:"; + // + // lblOwnCloudPassword + // + this.lblOwnCloudPassword.AutoSize = true; + this.lblOwnCloudPassword.Location = new System.Drawing.Point(16, 64); + this.lblOwnCloudPassword.Name = "lblOwnCloudPassword"; + this.lblOwnCloudPassword.Size = new System.Drawing.Size(56, 13); + this.lblOwnCloudPassword.TabIndex = 2; + this.lblOwnCloudPassword.Text = "Password:"; + // + // lblOwnCloudUsername + // + this.lblOwnCloudUsername.AutoSize = true; + this.lblOwnCloudUsername.Location = new System.Drawing.Point(16, 40); + this.lblOwnCloudUsername.Name = "lblOwnCloudUsername"; + this.lblOwnCloudUsername.Size = new System.Drawing.Size(58, 13); + this.lblOwnCloudUsername.TabIndex = 1; + this.lblOwnCloudUsername.Text = "Username:"; + // + // lblOwnCloudHost + // + this.lblOwnCloudHost.AutoSize = true; + this.lblOwnCloudHost.Location = new System.Drawing.Point(16, 16); + this.lblOwnCloudHost.Name = "lblOwnCloudHost"; + this.lblOwnCloudHost.Size = new System.Drawing.Size(32, 13); + this.lblOwnCloudHost.TabIndex = 0; + this.lblOwnCloudHost.Text = "Host:"; + // // tpPushbullet // this.tpPushbullet.Controls.Add(this.lblPushbulletDevices); @@ -3859,16 +3967,6 @@ private void InitializeComponent() this.actRapidShareAccountType.Size = new System.Drawing.Size(214, 29); this.actRapidShareAccountType.TabIndex = 16; // - // btnCustomUploaderExamples - // - this.btnCustomUploaderExamples.Location = new System.Drawing.Point(560, 376); - this.btnCustomUploaderExamples.Name = "btnCustomUploaderExamples"; - this.btnCustomUploaderExamples.Size = new System.Drawing.Size(80, 24); - this.btnCustomUploaderExamples.TabIndex = 32; - this.btnCustomUploaderExamples.Text = "Examples..."; - this.btnCustomUploaderExamples.UseVisualStyleBackColor = true; - this.btnCustomUploaderExamples.Click += new System.EventHandler(this.btnCustomUploaderExamples_Click); - // // UploadersConfigForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -3920,6 +4018,8 @@ private void InitializeComponent() this.tpAmazonS3.PerformLayout(); this.tpGoogleDrive.ResumeLayout(false); this.tpGoogleDrive.PerformLayout(); + this.tpOwnCloud.ResumeLayout(false); + this.tpOwnCloud.PerformLayout(); this.tpPushbullet.ResumeLayout(false); this.tpPushbullet.PerformLayout(); this.tpBox.ResumeLayout(false); @@ -4315,5 +4415,14 @@ private void InitializeComponent() private System.Windows.Forms.CheckBox cbGoogleDriveUseFolder; private System.Windows.Forms.Label lblWidthHint; private System.Windows.Forms.Button btnCustomUploaderExamples; + private System.Windows.Forms.TabPage tpOwnCloud; + private System.Windows.Forms.TextBox txtOwnCloudPath; + private System.Windows.Forms.TextBox txtOwnCloudPassword; + private System.Windows.Forms.TextBox txtOwnCloudUsername; + private System.Windows.Forms.TextBox txtOwnCloudHost; + private System.Windows.Forms.Label lblOwnCloudPath; + private System.Windows.Forms.Label lblOwnCloudPassword; + private System.Windows.Forms.Label lblOwnCloudUsername; + private System.Windows.Forms.Label lblOwnCloudHost; } } \ No newline at end of file diff --git a/UploadersLib/Forms/UploadersConfigForm.cs b/UploadersLib/Forms/UploadersConfigForm.cs index 2bf94b795..ba6944c0d 100644 --- a/UploadersLib/Forms/UploadersConfigForm.cs +++ b/UploadersLib/Forms/UploadersConfigForm.cs @@ -98,6 +98,7 @@ private void FormSettings() uploadersImageList.Images.Add("Bitly", Resources.Bitly); uploadersImageList.Images.Add("Yourls", Resources.Yourls); uploadersImageList.Images.Add("Twitter", Resources.Twitter); + uploadersImageList.Images.Add("ownCloud", Resources.OwnCloud); tpImageShack.ImageKey = "ImageShack"; tpTinyPic.ImageKey = "TinyPic"; @@ -130,6 +131,7 @@ private void FormSettings() tpGist.ImageKey = "Gist"; tpUpaste.ImageKey = "Upaste"; tpAmazonS3.ImageKey = "AmazonS3"; + tpOwnCloud.ImageKey = "ownCloud"; ttlvMain.ImageList = uploadersImageList; ttlvMain.MainTabControl = tcUploaders; @@ -474,6 +476,13 @@ public void LoadSettings(UploadersConfig uploadersConfig) cbAmazonS3UseRRS.Checked = Config.AmazonS3Settings.UseReducedRedundancyStorage; UpdateAmazonS3Status(); + // ownCloud + + txtOwnCloudHost.Text = Config.OwnCloudHost; + txtOwnCloudUsername.Text = Config.OwnCloudUsername; + txtOwnCloudPassword.Text = Config.OwnCloudPassword; + txtOwnCloudPath.Text = Config.OwnCloudPath; + #endregion File uploaders #region URL Shorteners @@ -1631,6 +1640,30 @@ private void cbAmazonS3UseRRS_CheckedChanged(object sender, EventArgs e) #endregion Amazon S3 + #region ownCloud + + private void txtOwnCloudHost_TextChanged(object sender, EventArgs e) + { + Config.OwnCloudHost = txtOwnCloudHost.Text; + } + + private void txtOwnCloudUsername_TextChanged(object sender, EventArgs e) + { + Config.OwnCloudUsername = txtOwnCloudUsername.Text; + } + + private void txtOwnCloudPassword_TextChanged(object sender, EventArgs e) + { + Config.OwnCloudPassword = txtOwnCloudPassword.Text; + } + + private void txtOwnCloudPath_TextChanged(object sender, EventArgs e) + { + Config.OwnCloudPath = txtOwnCloudPath.Text; + } + + #endregion ownCloud + #region Pushbullet private void txtPushbulletUserKey_TextChanged(object sender, EventArgs e) diff --git a/UploadersLib/Properties/Resources.Designer.cs b/UploadersLib/Properties/Resources.Designer.cs index 1b3619421..4ce3bae0a 100644 --- a/UploadersLib/Properties/Resources.Designer.cs +++ b/UploadersLib/Properties/Resources.Designer.cs @@ -310,6 +310,16 @@ internal class Resources { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap OwnCloud { + get { + object obj = ResourceManager.GetObject("OwnCloud", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// diff --git a/UploadersLib/Properties/Resources.resx b/UploadersLib/Properties/Resources.resx index bd4f5652b..270187e5e 100644 --- a/UploadersLib/Properties/Resources.resx +++ b/UploadersLib/Properties/Resources.resx @@ -304,4 +304,7 @@ ..\favicons\hostr.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\favicons\owncloud.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + \ No newline at end of file diff --git a/UploadersLib/UploadersConfig.cs b/UploadersLib/UploadersConfig.cs index 4bf5bda91..3b6ce93aa 100644 --- a/UploadersLib/UploadersConfig.cs +++ b/UploadersLib/UploadersConfig.cs @@ -204,6 +204,13 @@ public class UploadersConfig : SettingsBase UseReducedRedundancyStorage = true }; + // ownCloud + + public string OwnCloudHost = ""; + public string OwnCloudUsername = ""; + public string OwnCloudPassword = ""; + public string OwnCloudPath = "/"; + #endregion File uploaders #region URL shorteners diff --git a/UploadersLib/UploadersLib.csproj b/UploadersLib/UploadersLib.csproj index 775721731..993550ab8 100644 --- a/UploadersLib/UploadersLib.csproj +++ b/UploadersLib/UploadersLib.csproj @@ -424,6 +424,7 @@ +