Changeset 97eb5a5 for apps


Ignore:
Timestamp:
Mar 28, 2019 2:04:21 AM (20 months ago)
Author:
zab2 <zab2@…>
Branches:
master
Children:
d2bdbcd
Parents:
473ced4
Message:

add the UI bits of the access rules

Location:
apps/i2ptunnel
Files:
4 edited

Legend:

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

    r473ced4 r97eb5a5  
    935935    public String getI2CPHost() { return _config.getProperty(PROP_I2CP_HOST); }
    936936    public String getI2CPPort() { return _config.getProperty(PROP_I2CP_PORT); }
     937    public String getFilter() { return _config.getProperty(PROP_FILTER); }
    937938
    938939    /**
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/ui/GeneralHelper.java

    r473ced4 r97eb5a5  
    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";
    5152
    5253    private static final String OPT = TunnelController.PFX_OPTION;
     
    616617        if (getBooleanProperty(tunnel, PROP_ENABLE_BLACKLIST))
    617618            return 2;
     619        TunnelController tun = getController(tunnel);
     620        if (tun.getFilter() != null)
     621            return 3;
    618622        return 0;
    619623    }
    620624   
    621625    public String getAccessList(int tunnel) {
    622         return getProperty(tunnel, "i2cp.accessList", "").replace(",", "\n");
     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);
    623634    }
    624635   
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/ui/TunnelConfig.java

    r473ced4 r97eb5a5  
    99import java.util.StringTokenizer;
    1010import java.util.concurrent.ConcurrentHashMap;
     11
     12import java.io.File;
     13import java.io.FileOutputStream;
     14import java.io.IOException;
    1115
    1216import net.i2p.I2PAppContext;
     
    7680    private String _newProxyPW;
    7781    private Destination _dest;
     82    private boolean _filter;
     83    private String _filterDefinition;
    7884
    7985    public TunnelConfig() {
     
    305311    protected static final String PROP_ENABLE_ACCESS_LIST = "i2cp.enableAccessList";
    306312    protected static final String PROP_ENABLE_BLACKLIST = "i2cp.enableBlackList";
     313    protected static final String PROP_FILTER = "filterDefinition";
    307314
    308315    /**
     
    323330            _booleanOptions.remove(PROP_ENABLE_ACCESS_LIST);
    324331            _booleanOptions.add(PROP_ENABLE_BLACKLIST);
     332            break;
     333        case 3:
     334            _filter = true;
    325335            break;
    326336        default:
     
    372382
    373383    public void setAccessList(String val) {
    374         if (val != null)
    375             _otherOptions.put("i2cp.accessList", val.trim().replace("\r\n", ",").replace("\n", ",").replace(" ", ","));
     384        if (val == null)
     385            return;
     386        _filterDefinition = val;
    376387    }
    377388
     
    618629            for (String p : _booleanServerOpts)
    619630                config.setProperty(OPT + p, Boolean.toString(_booleanOptions.contains(p)));
     631            if (_filter) {
     632                String dslFile = _context.getConfigDir() + File.separator + _name+".accessrules";
     633                config.setProperty(TunnelController.PROP_FILTER, dslFile);
     634                FileOutputStream fos = null;
     635                try {
     636                    fos = new FileOutputStream(dslFile);
     637                    fos.write(_filterDefinition.getBytes());
     638                } catch (IOException bad) {
     639                    throw new RuntimeException("failed to save access rules", bad);
     640                } finally {
     641                    if (fos != null) try { fos.close(); } catch (IOException ignored) {}
     642                }
     643            } else {               
     644               _otherOptions.put("i2cp.accessList", _filterDefinition.trim().replace("\r\n", ",").replace("\n", ",").replace(" ", ","));
     645            }
    620646            for (String p : _otherServerOpts) {
    621647                if (_otherOptions.containsKey(p))
  • apps/i2ptunnel/jsp/editServer.jsi

    r473ced4 r97eb5a5  
    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             </td>
    537         </tr>
    538 
    539         <tr>
    540             <td colspan="2">
    541                 <b><%=intl._t("Access List")%></b> (<%=intl._t("Specify clients, 1 per line")%>)
     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            </td>
     539        </tr>
     540
     541        <tr>
     542            <td colspan="2">
     543                <b><%=intl._t("Access List Description")%></b> (<%=intl._t("Specify clients, 1 per line or describe access list")%>)
    542544            </td>
    543545        </tr>
Note: See TracChangeset for help on using the changeset viewer.