Exemplo n.º 1
0
        /// <summary>
        /// Register a new rule
        /// </summary>
        /// <param name="rule">The rule to be registered, the field ID is ignored by the server</param>
        /// <returns>The actual rule registered in the server, with the new ID</returns>
        public GrcBoxRule registerNewRule(GrcBoxRule.Protocol protocol, GrcBoxRule.RuleType t, GrcBoxInterface iface, long expireDate, int dstPort, string dstAddr = null,
                                          int srcPort = -1, string mcastPlugin = null, int dstFwdPort = -1, string srcAddr = null)
        {
            string ifName = iface.name;
            string type   = t.ToString();
            string dstFwdAddr;

            if (GrcBoxRule.RuleType.INCOMING.Equals(t))
            {
                dstAddr    = iface.address;
                dstFwdAddr = getMyIpAddr();
                if (dstFwdPort == -1)
                {
                    dstFwdPort = dstPort;
                }
            }
            else
            {
                srcAddr    = getMyIpAddr();
                dstFwdAddr = null;
            }

            GrcBoxRule rule = new GrcBoxRule(0, protocol.ToString(), type, appId, ifName, expireDate, srcPort,
                                             dstPort, srcAddr, dstAddr, mcastPlugin, dstFwdPort, dstFwdAddr);
            string       uri    = baseUri + APPS + "/" + appId + RULES;
            MemoryStream stream = new MemoryStream();
            DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(GrcBoxRule));

            jsonSerializer.WriteObject(stream, rule);
            stream.Position = 0;
            StreamReader   r       = new StreamReader(stream);
            string         content = r.ReadToEnd();
            GrcBoxRuleList list    = makePostRequest <GrcBoxRuleList>(uri, content, appId.ToString(), mPass);

            return(list.list[list.list.Count - 1]);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Remove a rule from the server
        /// </summary>
        /// <param name="rule"></param>
        public void removeRule(GrcBoxRule rule)
        {
            string uri = baseUri + APPS + "/" + appId + RULES + "/" + rule.id;

            makeDeleteRequest(uri, appId.ToString(), mPass);
        }