[#2082] [WebUI] [Console] Validate interface entry for IP address

This commit is contained in:
Calum Lind 2014-02-18 20:55:28 +00:00
commit cb87509e4f
2 changed files with 20 additions and 4 deletions

View file

@ -35,6 +35,7 @@
from deluge.ui.console.modes.input_popup import TextInput,SelectInput,CheckedInput,IntSpinInput,FloatSpinInput,CheckedPlusInput from deluge.ui.console.modes.input_popup import TextInput,SelectInput,CheckedInput,IntSpinInput,FloatSpinInput,CheckedPlusInput
import deluge.ui.console.modes.alltorrents import deluge.ui.console.modes.alltorrents
from deluge.common import is_ip
try: try:
import curses import curses
@ -106,12 +107,16 @@ class BasePane:
# gross, have to special case in/out ports since they are tuples # gross, have to special case in/out ports since they are tuples
if ipt.name in ("listen_ports_to", "listen_ports_from", "out_ports_from", "out_ports_to", if ipt.name in ("listen_ports_to", "listen_ports_from", "out_ports_from", "out_ports_to",
"i2p_port", "i2p_hostname", "proxy_type", "proxy_username", "proxy_hostnames", "i2p_port", "i2p_hostname", "proxy_type", "proxy_username", "proxy_hostnames",
"proxy_password", "proxy_hostname", "proxy_port", "proxy_peer_connections" "proxy_password", "proxy_hostname", "proxy_port", "proxy_peer_connections",
): "listen_interface"):
if ipt.name == "listen_ports_to": if ipt.name == "listen_ports_to":
conf_dict["listen_ports"] = (self.infrom.get_value(),self.into.get_value()) conf_dict["listen_ports"] = (self.infrom.get_value(),self.into.get_value())
elif ipt.name == "out_ports_to": elif ipt.name == "out_ports_to":
conf_dict["outgoing_ports"] = (self.outfrom.get_value(),self.outto.get_value()) conf_dict["outgoing_ports"] = (self.outfrom.get_value(),self.outto.get_value())
elif ipt.name == "listen_interface":
interface = ipt.get_value().strip()
if is_ip(interface) or not interface:
conf_dict["listen_interface"] = interface
elif ipt.name == "i2p_port": elif ipt.name == "i2p_port":
conf_dict.setdefault("i2p_proxy", {})["port"] = ipt.get_value() conf_dict.setdefault("i2p_proxy", {})["port"] = ipt.get_value()
elif ipt.name == "i2p_hostname": elif ipt.name == "i2p_hostname":
@ -131,6 +136,7 @@ class BasePane:
elif ipt.name == "proxy_peer_connections": elif ipt.name == "proxy_peer_connections":
conf_dict.setdefault("proxy", {})["proxy_peer_connections"] = ipt.get_value() conf_dict.setdefault("proxy", {})["proxy_peer_connections"] = ipt.get_value()
else: else:
conf_dict[ipt.name] = ipt.get_value() conf_dict[ipt.name] = ipt.get_value()
if hasattr(ipt,"get_child"): if hasattr(ipt,"get_child"):

View file

@ -31,6 +31,15 @@
*/ */
Ext.namespace('Deluge.preferences'); Ext.namespace('Deluge.preferences');
// custom Vtype for vtype:'IPAddress'
Ext.apply(Ext.form.field.VTypes, {
IPAddress: function(v) {
return /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(v);
},
IPAddressText: 'Must be a numeric IP address',
IPAddressMask: /[\d\.]/i
});
/** /**
* @class Deluge.preferences.Network * @class Deluge.preferences.Network
* @extends Ext.form.FormPanel * @extends Ext.form.FormPanel
@ -44,7 +53,7 @@ Deluge.preferences.Network = Ext.extend(Ext.form.FormPanel, {
initComponent: function() { initComponent: function() {
Deluge.preferences.Network.superclass.initComponent.call(this); Deluge.preferences.Network.superclass.initComponent.call(this);
var optMan = deluge.preferences.getOptionsManager(); var optMan = deluge.preferences.getOptionsManager();
console.log(Ext.form.VTypes);
fieldset = this.add({ fieldset = this.add({
xtype: 'fieldset', xtype: 'fieldset',
border: false, border: false,
@ -58,7 +67,8 @@ Deluge.preferences.Network = Ext.extend(Ext.form.FormPanel, {
name: 'listen_interface', name: 'listen_interface',
fieldLabel: '', fieldLabel: '',
labelSeparator: '', labelSeparator: '',
width: 200 width: 200,
vtype: 'IPAddress',
})); }));
var fieldset = this.add({ var fieldset = this.add({