mirror of
https://github.com/greenshot/greenshot
synced 2025-08-21 05:53:27 -07:00
Added Proxy support
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@899 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
82207ac607
commit
2cc6277ce2
4 changed files with 201 additions and 102 deletions
|
@ -28,6 +28,7 @@ using System.Windows.Forms;
|
|||
using Greenshot.Core;
|
||||
using Greenshot.Helpers;
|
||||
using GreenshotConfluencePlugin;
|
||||
using GreenshotCore.Helpers;
|
||||
|
||||
/// <summary>
|
||||
/// For details see the Confluence API site
|
||||
|
@ -47,57 +48,58 @@ namespace Confluence {
|
|||
#endregion
|
||||
|
||||
public class ConfluenceConnector {
|
||||
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ConfluenceConnector));
|
||||
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ConfluenceConnector));
|
||||
private const string AUTH_FAILED_EXCEPTION_NAME = "com.atlassian.confluence.rpc.AuthenticationFailedException";
|
||||
|
||||
private string credentials = null;
|
||||
private DateTime loggedInTime = DateTime.Now;
|
||||
private bool loggedIn = false;
|
||||
private ConfluenceSoapServiceService confluence;
|
||||
private int timeout;
|
||||
private string url;
|
||||
private Dictionary<string, string> userMap = new Dictionary<string, string>();
|
||||
private string credentials = null;
|
||||
private DateTime loggedInTime = DateTime.Now;
|
||||
private bool loggedIn = false;
|
||||
private ConfluenceSoapServiceService confluence;
|
||||
private int timeout;
|
||||
private string url;
|
||||
private Dictionary<string, string> userMap = new Dictionary<string, string>();
|
||||
|
||||
public ConfluenceConnector(string url, int timeout) {
|
||||
this.url = url;
|
||||
this.timeout = timeout;
|
||||
confluence = new ConfluenceSoapServiceService();
|
||||
confluence.Url = url;
|
||||
}
|
||||
public ConfluenceConnector(string url, int timeout) {
|
||||
this.url = url;
|
||||
this.timeout = timeout;
|
||||
confluence = new ConfluenceSoapServiceService();
|
||||
confluence.Url = url;
|
||||
confluence.Proxy = NetworkHelper.CreateProxy(new Uri(url));
|
||||
}
|
||||
|
||||
~ConfluenceConnector() {
|
||||
logout();
|
||||
}
|
||||
/// <summary>
|
||||
/// Internal login which catches the exceptions
|
||||
/// </summary>
|
||||
/// <returns>true if login was done sucessfully</returns>
|
||||
private bool doLogin(string user, string password) {
|
||||
try {
|
||||
this.credentials = confluence.login(user, password);
|
||||
this.loggedInTime = DateTime.Now;
|
||||
~ConfluenceConnector() {
|
||||
logout();
|
||||
}
|
||||
/// <summary>
|
||||
/// Internal login which catches the exceptions
|
||||
/// </summary>
|
||||
/// <returns>true if login was done sucessfully</returns>
|
||||
private bool doLogin(string user, string password) {
|
||||
try {
|
||||
this.credentials = confluence.login(user, password);
|
||||
this.loggedInTime = DateTime.Now;
|
||||
this.loggedIn = true;
|
||||
} catch (Exception e) {
|
||||
// check if auth failed
|
||||
if (e.Message.Contains(AUTH_FAILED_EXCEPTION_NAME)) {
|
||||
} catch (Exception e) {
|
||||
// check if auth failed
|
||||
if (e.Message.Contains(AUTH_FAILED_EXCEPTION_NAME)) {
|
||||
return false;
|
||||
}
|
||||
// Not an authentication issue
|
||||
this.loggedIn = false;
|
||||
this.credentials = null;
|
||||
e.Data.Add("user", user);
|
||||
e.Data.Add("url", url);
|
||||
throw e;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// Not an authentication issue
|
||||
this.loggedIn = false;
|
||||
this.credentials = null;
|
||||
e.Data.Add("user", user);
|
||||
e.Data.Add("url", url);
|
||||
throw e;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void login() {
|
||||
logout();
|
||||
try {
|
||||
// Get the system name, so the user knows where to login to
|
||||
string systemName = url.Replace(ConfluenceConfiguration.DEFAULT_POSTFIX,"");
|
||||
CredentialsDialog dialog = new CredentialsDialog(systemName);
|
||||
public void login() {
|
||||
logout();
|
||||
try {
|
||||
// Get the system name, so the user knows where to login to
|
||||
string systemName = url.Replace(ConfluenceConfiguration.DEFAULT_POSTFIX,"");
|
||||
CredentialsDialog dialog = new CredentialsDialog(systemName);
|
||||
dialog.Name = null;
|
||||
while (dialog.Show(dialog.Name) == DialogResult.OK) {
|
||||
if (doLogin(dialog.Name, dialog.Password)) {
|
||||
|
@ -122,45 +124,45 @@ namespace Confluence {
|
|||
// exception handling ...
|
||||
LOG.Error("Problem using the credentials dialog", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void logout() {
|
||||
if (credentials != null) {
|
||||
confluence.logout(credentials);
|
||||
credentials = null;
|
||||
loggedIn = false;
|
||||
}
|
||||
}
|
||||
public void logout() {
|
||||
if (credentials != null) {
|
||||
confluence.logout(credentials);
|
||||
credentials = null;
|
||||
loggedIn = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void checkCredentials() {
|
||||
if (loggedIn) {
|
||||
private void checkCredentials() {
|
||||
if (loggedIn) {
|
||||
if (loggedInTime.AddMinutes(timeout-1).CompareTo(DateTime.Now) < 0) {
|
||||
logout();
|
||||
login();
|
||||
}
|
||||
} else {
|
||||
login();
|
||||
}
|
||||
}
|
||||
logout();
|
||||
login();
|
||||
}
|
||||
} else {
|
||||
login();
|
||||
}
|
||||
}
|
||||
|
||||
public bool isLoggedIn() {
|
||||
return loggedIn;
|
||||
}
|
||||
|
||||
public void addAttachment(long pageId, string mime, string comment, string filename, byte[] buffer) {
|
||||
checkCredentials();
|
||||
public bool isLoggedIn() {
|
||||
return loggedIn;
|
||||
}
|
||||
|
||||
public void addAttachment(long pageId, string mime, string comment, string filename, byte[] buffer) {
|
||||
checkCredentials();
|
||||
RemoteAttachment attachment = new RemoteAttachment();
|
||||
// Comment is ignored, see: http://jira.atlassian.com/browse/CONF-9395
|
||||
attachment.comment = comment;
|
||||
attachment.fileName = filename;
|
||||
attachment.contentType = mime;
|
||||
confluence.addAttachment(credentials, pageId, attachment, buffer);
|
||||
}
|
||||
|
||||
public Page getPage(string spaceKey, string pageTitle) {
|
||||
checkCredentials();
|
||||
RemotePage page = confluence.getPage(credentials, spaceKey, pageTitle);
|
||||
return new Page(page);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Page getPage(string spaceKey, string pageTitle) {
|
||||
checkCredentials();
|
||||
RemotePage page = confluence.getPage(credentials, spaceKey, pageTitle);
|
||||
return new Page(page);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,6 +98,7 @@
|
|||
<Compile Include="Helpers\ImageHelper.cs" />
|
||||
<Compile Include="Helpers\ImageOutput.cs" />
|
||||
<Compile Include="Helpers\MailHelper.cs" />
|
||||
<Compile Include="Helpers\NetworkHelper.cs" />
|
||||
<Compile Include="Helpers\Objects.cs" />
|
||||
<Compile Include="Helpers\PluginHelper.cs" />
|
||||
<Compile Include="Helpers\PrintHelper.cs" />
|
||||
|
|
90
GreenshotCore/Helpers/NetworkHelper.cs
Normal file
90
GreenshotCore/Helpers/NetworkHelper.cs
Normal file
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2010 Thomas Braun, Jens Klingen, Robin Krom
|
||||
*
|
||||
* For more information see: http://getgreenshot.org/
|
||||
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 1 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Net;
|
||||
|
||||
using Greenshot.Core;
|
||||
|
||||
namespace GreenshotCore.Helpers {
|
||||
/// <summary>
|
||||
/// Description of NetworkHelper.
|
||||
/// </summary>
|
||||
public class NetworkHelper {
|
||||
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(NetworkHelper));
|
||||
private static CoreConfiguration config = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
|
||||
/// <summary>
|
||||
/// Download the FavIcon as a Bitmap
|
||||
/// </summary>
|
||||
/// <param name="baseUri"></param>
|
||||
/// <returns>Bitmap with the FavIcon</returns>
|
||||
public static Bitmap DownloadFavIcon(Uri baseUri) {
|
||||
Uri url = new Uri(baseUri, new Uri("favicon.ico"));
|
||||
try {
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
||||
request.Proxy = NetworkHelper.CreateProxy(url);
|
||||
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
||||
if (request.HaveResponse) {
|
||||
Image image = Image.FromStream(response.GetResponseStream());
|
||||
return (image.Height > 16 && image.Width > 16) ? new Bitmap(image, 16, 16) : new Bitmap(image);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
LOG.Error("Problem downloading the FavIcon from: " + baseUri.ToString(), e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a IWebProxy Object which can be used to access the Internet
|
||||
/// This method will check the configuration if the proxy is allowed to be used.
|
||||
/// Usages can be found in the DownloadFavIcon or Jira and Confluence plugins
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <returns>IWebProxy filled with all the proxy details or null if none is set/wanted</returns>
|
||||
public static IWebProxy CreateProxy(Uri uri) {
|
||||
IWebProxy proxyToUse = null;
|
||||
if (config.UseProxy) {
|
||||
proxyToUse = WebRequest.DefaultWebProxy;
|
||||
if (proxyToUse != null) {
|
||||
proxyToUse.Credentials = CredentialCache.DefaultCredentials;
|
||||
if (LOG.IsDebugEnabled) {
|
||||
// check the proxy for the Uri
|
||||
if (!proxyToUse.IsBypassed(uri)) {
|
||||
Uri proxyUri = proxyToUse.GetProxy(uri);
|
||||
if (proxyUri != null) {
|
||||
LOG.Debug("Using proxy: " + proxyUri.ToString() + " for " + uri.ToString());
|
||||
} else {
|
||||
LOG.Debug("No proxy found!");
|
||||
}
|
||||
} else {
|
||||
LOG.Debug("Proxy bypass for: " + uri.ToString());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
LOG.Debug("No proxy found!");
|
||||
}
|
||||
}
|
||||
return proxyToUse;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -22,72 +22,77 @@ using System;
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using Greenshot.Core;
|
||||
using Greenshot.Helpers;
|
||||
using GreenshotCore.Helpers;
|
||||
using GreenshotJiraPlugin;
|
||||
|
||||
namespace Jira {
|
||||
#region transport classes
|
||||
public class JiraFilter {
|
||||
public JiraFilter(string name, string id) {
|
||||
this.name = name;
|
||||
this.id = id;
|
||||
this.Name = name;
|
||||
this.Id = id;
|
||||
}
|
||||
public string name {
|
||||
public string Name {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public string id;
|
||||
}
|
||||
public string Id {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
|
||||
public class JiraIssue {
|
||||
public JiraIssue(string key, DateTime? created, string reporter, string assignee, string project, string summary, string description, string environment, string [] attachmentNames) {
|
||||
this.key = key;
|
||||
this.created = created;
|
||||
this.reporter = reporter;
|
||||
this.assignee = assignee;
|
||||
this.project = project;
|
||||
this.summary = summary;
|
||||
this.description = description;
|
||||
this.environment = environment;
|
||||
this.attachmentNames = attachmentNames;
|
||||
this.Key = key;
|
||||
this.Created = created;
|
||||
this.Reporter = reporter;
|
||||
this.Assignee = assignee;
|
||||
this.Project = project;
|
||||
this.Summary = summary;
|
||||
this.Description = description;
|
||||
this.Environment = environment;
|
||||
this.AttachmentNames = attachmentNames;
|
||||
}
|
||||
public string key {
|
||||
public string Key {
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
public DateTime? created {
|
||||
public DateTime? Created {
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
public string reporter {
|
||||
public string Reporter {
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
public string assignee {
|
||||
public string Assignee {
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
public string project {
|
||||
public string Project {
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
public string summary {
|
||||
public string Summary {
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
public string description {
|
||||
public string Description {
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
public string environment {
|
||||
public string Environment {
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
public string[] attachmentNames {
|
||||
public string[] AttachmentNames {
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
@ -95,11 +100,11 @@ namespace Jira {
|
|||
#endregion
|
||||
|
||||
public class JiraConnector {
|
||||
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(JiraConnector));
|
||||
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(JiraConnector));
|
||||
private const string AUTH_FAILED_EXCEPTION_NAME = "com.atlassian.jira.rpc.exception.RemoteAuthenticationException";
|
||||
private string credentials = null;
|
||||
private string credentials;
|
||||
private DateTime loggedInTime = DateTime.Now;
|
||||
private bool loggedIn = false;
|
||||
private bool loggedIn;
|
||||
private JiraSoapServiceService jira;
|
||||
private int timeout;
|
||||
private string url;
|
||||
|
@ -110,6 +115,7 @@ namespace Jira {
|
|||
this.timeout = timeout;
|
||||
jira = new JiraSoapServiceService();
|
||||
jira.Url = url;
|
||||
jira.Proxy = NetworkHelper.CreateProxy(new Uri(url));
|
||||
}
|
||||
|
||||
~JiraConnector() {
|
||||
|
@ -135,7 +141,7 @@ namespace Jira {
|
|||
this.credentials = null;
|
||||
e.Data.Add("user", user);
|
||||
e.Data.Add("url", url);
|
||||
throw e;
|
||||
throw;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue