Changeset 4790a14 for apps


Ignore:
Timestamp:
Apr 2, 2019 4:04:33 PM (12 months ago)
Author:
zab2 <zab2@…>
Branches:
master
Children:
e380b26
Parents:
194df9d
Message:

change UI to allow same filter definition to be used in multiple tunnels

Location:
apps/i2ptunnel
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/ui/GeneralHelper.java

    r194df9d r4790a14  
    4949    protected static final String PROP_ENABLE_ACCESS_LIST = "i2cp.enableAccessList";
    5050    protected static final String PROP_ENABLE_BLACKLIST = "i2cp.enableBlackList";
    51     protected static final String PROP_FILTER_DEFINITION = "filterDefinition";
    5251
    5352    private static final String OPT = TunnelController.PFX_OPTION;
     
    617616        if (getBooleanProperty(tunnel, PROP_ENABLE_BLACKLIST))
    618617            return 2;
    619         TunnelController tun = getController(tunnel);
    620         if (tun.getFilter() != null)
    621             return 3;
    622618        return 0;
    623619    }
    624620   
    625621    public String getAccessList(int tunnel) {
    626         switch(getAccessMode(tunnel)) {
    627             case 0:
    628             case 1:
    629             case 2:
    630                 return getProperty(tunnel, "i2cp.accessList", "").replace(",", "\n");
    631         }
    632         TunnelController tun = getController(tunnel);
    633         return FileUtil.readTextFile(tun.getFilter(), -1, true);
     622        return getProperty(tunnel, "i2cp.accessList", "").replace(",", "\n");
     623    }
     624
     625    public String getFilterDefinition(int tunnel) {
     626        TunnelController tunnelController = getController(tunnel);
     627        String filter = tunnelController.getFilter();
     628        return filter == null ? "" : filter;
    634629    }
    635630   
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/ui/TunnelConfig.java

    r194df9d r4790a14  
    99import java.util.StringTokenizer;
    1010import java.util.concurrent.ConcurrentHashMap;
    11 
    12 import java.io.File;
    13 import java.io.FileOutputStream;
    14 import java.io.IOException;
    1511
    1612import net.i2p.I2PAppContext;
     
    3127import net.i2p.util.ConcurrentHashSet;
    3228import net.i2p.util.PasswordManager;
    33 import net.i2p.util.SecureFileOutputStream;
    3429
    3530/**
     
    8176    private String _newProxyPW;
    8277    private Destination _dest;
    83     private boolean _filter;
    8478    private String _filterDefinition;
    8579
     
    312306    protected static final String PROP_ENABLE_ACCESS_LIST = "i2cp.enableAccessList";
    313307    protected static final String PROP_ENABLE_BLACKLIST = "i2cp.enableBlackList";
    314     protected static final String PROP_FILTER = "filterDefinition";
    315308
    316309    /**
     
    332325            _booleanOptions.add(PROP_ENABLE_BLACKLIST);
    333326            break;
    334         case 3:
    335             _filter = true;
    336             break;
    337327        default:
    338328            _booleanOptions.remove(PROP_ENABLE_ACCESS_LIST);
    339329            _booleanOptions.remove(PROP_ENABLE_BLACKLIST);
     330        }
     331    }
     332
     333    public void setFilterDefinition(String filterDefinition) {
     334        if (filterDefinition != null) {
     335            filterDefinition = filterDefinition.trim();
     336            if (!filterDefinition.isEmpty())
     337                _filterDefinition = filterDefinition;
    340338        }
    341339    }
     
    383381
    384382    public void setAccessList(String val) {
    385         if (val == null)
    386             return;
    387         _filterDefinition = val;
     383        if (val != null)
     384            _otherOptions.put("i2cp.accessList", val.trim().replace("\r\n", ",").replace("\n", ",").replace(" ", ","));
    388385    }
    389386
     
    626623            if (_targetPort >= 0)
    627624                config.setProperty(TunnelController.PROP_TARGET_PORT, Integer.toString(_targetPort));
     625
     626            if (_filterDefinition != null)
     627                config.setProperty(TunnelController.PROP_FILTER, _filterDefinition);
     628           
    628629            // see TunnelController.setConfig()
    629630            _booleanOptions.add(TunnelController.PROP_LIMITS_SET);
    630631            for (String p : _booleanServerOpts)
    631632                config.setProperty(OPT + p, Boolean.toString(_booleanOptions.contains(p)));
    632             if (_filter) {
    633                 String dslFile = _context.getConfigDir() + File.separator + _name+".accessrules";
    634                 config.setProperty(TunnelController.PROP_FILTER, dslFile);
    635                 FileOutputStream fos = null;
    636                 try {
    637                     fos = new SecureFileOutputStream(dslFile);
    638                     fos.write(_filterDefinition.getBytes());
    639                 } catch (IOException bad) {
    640                     throw new RuntimeException("failed to save access rules", bad);
    641                 } finally {
    642                     if (fos != null) try { fos.close(); } catch (IOException ignored) {}
    643                 }
    644             } else {               
    645                _otherOptions.put("i2cp.accessList", _filterDefinition.trim().replace("\r\n", ",").replace("\n", ",").replace(" ", ","));
    646             }
    647633            for (String p : _otherServerOpts) {
    648634                if (_otherOptions.containsKey(p))
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/web/EditBean.java

    r194df9d r4790a14  
    270270    public String getAccessList(int tunnel) {
    271271        return _helper.getAccessList(tunnel);
     272    }
     273
     274    public String getFilterDefinition(int tunnel) {
     275        return _helper.getFilterDefinition(tunnel);
    272276    }
    273277   
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/web/IndexBean.java

    r194df9d r4790a14  
    889889    }
    890890
     891    public void setFilterDefinition(String val) {
     892        if (val != null)
     893            _config.setFilterDefinition(val);
     894    }
     895
    891896    public void setDelayOpen(String moo) {
    892897        _config.setDelayOpen(true);
  • apps/i2ptunnel/jsp/editServer.jsi

    r194df9d r4790a14  
    534534                <span class="multiOption"><label title="<%=intl._t("Only allow listed clients to connect to this service")%>"><input value="1" type="radio" name="accessMode"<%=(editBean.getAccessMode(curTunnel).equals("1") ? " checked=\"checked\"" : "")%> class="tickbox" />
    535535                    <%=intl._t("Whitelist")%></label></span>
    536                 <span class="multiOption"><label title="<%=intl._t("Advanced access list configuration")%>"><input value="3" type="radio" name="accessMode"<%=(editBean.getAccessMode(curTunnel).equals("3") ? " checked=\"checked\"" : "")%> class="tickbox" />
    537                     <%=intl._t("Advanced")%></label></span>
    538                 <span><a href="http://i2p-projekt.i2p/spec/filter-format">(<%=intl._t("format")%>)</a></span>
    539536            </td>
    540537        </tr>
     
    549546            <td colspan="2">
    550547                <textarea rows="2" style="height: 8em;" cols="60" name="accessList" title="<%=intl._t("Control access to this service")%>" wrap="off" spellcheck="false"><%=editBean.getAccessList(curTunnel)%></textarea>
     548            </td>
     549        </tr>
     550
     551        <tr>
     552            <td colspan="2">
     553                <b><%=intl._t("Filter Definition File")%></b>
     554            </td>
     555        </tr>
     556
     557        <tr>
     558            <td colspan="2">
     559                <%=intl._t("You can define an advanced filter for this tunnel.")%> (<a href="http://i2p-projekt.i2p/spec/filter-format" target="_blank"><%=intl._t("Format Specification")%></a>) 
     560            </td>
     561        </tr>
     562
     563        <tr>
     564            <td colspan="2">
     565                <label for="filterDefinition"><%=intl._t("File containing filter definition")%></label>
     566                <input type="text" id="filterDefinition" name="filterDefinition" value="<%=editBean.getFilterDefinition(curTunnel)%>" size="30"/>
    551567            </td>
    552568        </tr>
Note: See TracChangeset for help on using the changeset viewer.