Skip to content

Commit

Permalink
Merge pull request #9 from andrewbonney/master
Browse files Browse the repository at this point in the history
Add basic support for SOCKS proxies
  • Loading branch information
kutzi committed Jan 5, 2014
2 parents ad5a93a + c91be4d commit 1861e97
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/main/java/hudson/plugins/ircbot/IrcPublisher.java
Expand Up @@ -180,6 +180,10 @@ public static final class DescriptorImpl extends BuildStepDescriptor<Publisher>

String nickServPassword = null;

private String socksHost = null;

private Integer socksPort = 1080;

/**
* Marks if passwords are already scrambled.
* Needed to migrate old, unscrambled passwords.
Expand Down Expand Up @@ -274,6 +278,13 @@ public boolean configure(StaplerRequest req, JSONObject formData) throws FormExc
throw new FormException("port field must be an Integer",
"irc_publisher.port");
}
this.socksHost = req.getParameter("irc_publisher.socksHost");
try {
this.socksPort = Integer.valueOf(req.getParameter("irc_publisher.socksPort"));
} catch (NumberFormatException e) {
throw new FormException("SOCKS proxy port field must be an Integer",
"irc_publisher.socksPort");
}
this.ssl = "on".equals(req.getParameter("irc_publisher.ssl"));
this.sslTrustAllCertificates = "on".equals(req.getParameter("irc_publisher.ssl_trust_all_certificates"));
this.commandPrefix = req.getParameter("irc_publisher.commandPrefix");
Expand Down Expand Up @@ -465,6 +476,14 @@ public int getPort() {
return port;
}

public String getSocksHost() {
return socksHost;
}

public int getSocksPort() {
return socksPort;
}

public boolean isSsl() {
return this.ssl;
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/hudson/plugins/ircbot/v2/IRCConnection.java
Expand Up @@ -25,6 +25,7 @@
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.net.Proxy;

import javax.net.SocketFactory;
import javax.net.ssl.SSLSocketFactory;
Expand All @@ -34,6 +35,7 @@
import org.pircbotx.UtilSSLSocketFactory;
import org.pircbotx.exception.IrcException;
import org.pircbotx.exception.NickAlreadyInUseException;
import org.pircbotx.ProxySocketFactory;

/**
* IRC specific implementation of an {@link IMConnection}.
Expand Down Expand Up @@ -116,6 +118,8 @@ public boolean connect() {
} else {
sf = SSLSocketFactory.getDefault();
}
} else if (!this.descriptor.getSocksHost().equals("") && this.descriptor.getSocksPort() > 0) {
sf = new ProxySocketFactory(Proxy.Type.SOCKS, this.descriptor.getSocksHost(), this.descriptor.getSocksPort());
} else {
sf = SocketFactory.getDefault();
}
Expand Down
Expand Up @@ -67,6 +67,12 @@
help="/plugin/ircbot/help-globalTrustAllCertificates.html">
<f:checkbox name="irc_publisher.ssl_trust_all_certificates" checked="${descriptor.trustAllCertificates}"/>
</f:entry>
<f:entry title="SOCKS proxy host" description="Proxy server hostname or IP (if applicable). Only supported without SSL.">
<f:textbox name="irc_publisher.socksHost" value="${descriptor.getSocksHost()}"/>
</f:entry>
<f:entry title="SOCKS proxy port" description="Proxy server port">
<f:textbox name="irc_publisher.socksPort" value="${descriptor.getSocksPort()}"/>
</f:entry>
<f:entry title="Disallow Private Chat" description="Disallow bot commands from private chat.">
<f:checkbox name="irc_publisher.disallowPrivateChat" checked="${descriptor.disallowPrivateChat}"/>
</f:entry>
Expand Down

0 comments on commit 1861e97

Please sign in to comment.