ties / compal_CH7465LG_py

Python interface for the Ziggo Connect Box/Compal CH7465LG
MIT License
116 stars 19 forks source link

set_mac_filter how does it work? #34

Closed Hochiss closed 2 years ago

Hochiss commented 3 years ago

Thanks for your api. I tried as following to set mac filter:

from compal import *
modem = Compal('192.168.178.1', 'mypwd')
modem.login()

ft=Filters(modem)
ft.set_mac_filter(FilterAction(2), "Devicexxx", "xx:xx:xx:xx:xx:xx", TimerMode(1), 1) # FilterAction(2) = 'delete', TimerMode(1) = 'generaltime'
<Response [200]>

It returns <Response [200]>, i.e. OK, but checking modem interface, the mac filter rule was not deleted, or I tried a different device to add, i.e. FilterAction(1), that rule in MAC_filter panel not shown up.

cf. def set_mac_filter(self, action, device_name, mac_addr, timer_mode, enable) the parameters of action, _devicename, _macaddr, _timermode all should have been correctly taken? only the last 'enable' i not sure how to implement.

On the other side, does it need a 'apply' or 'update' function as PortForward?

please advise.

Hochiss commented 3 years ago

Could anyone help? or this github is dead?

ties commented 3 years ago

Hi,

The github is not dead. However I can not test it at the moment so I can not help with your question.

Can you try the same action in the web ui and look at the messages sent by your browser in the network tab? (usually under developer tools)?

If so we can compare the payloads.

Hochiss commented 2 years ago

@ties thanks for the feedback and the debugging method, still cannot go through, EDIT: it seems def set_mac_filter(self, action, device_name, mac_addr, timer_mode, enable) missing parameters/entries? please review:

I have made following change myself and now works: def set_mac_filter(self, action, device_name, mac_ads, timer_mode,time_rule, enable)

and change compal/init.py#L560 & 562 from timerule = "0,0" to time_rule = time_rule

with a e.g. time_rule = "16777215,16777215,16777215,16777215,16777215,16777215,16777215" (all days hours to block) also mac_addr will be add following ',1' (= enable) or ',2' ( = not enable) , e.g.: enable : `mac_ads = mac_addr + ',1'

def MacBlock(ONOFF) 
     ...
    hostname = myHOST 
    mac_addr = 'xx.xx.xx.xx.xx.xx'
    if ONOFF == 'ON':
        mac_ads = mac_addr + ',1'
    elif ONOFF == 'OFF':
        mac_ads = mac_addr + ',2'
    else:
        print('ERROR input of parameter: ONOFF')
        modem.logout()
        sys.exit(1)

    time_rule = '16777215,16777215,16777215,16777215,16777215,16777215,16777215'
    ft=Filters(modem)
    r=ft.set_mac_filter(FilterAction(3), hostname, mac_ads, TimerMode(2),timerule,1)
    ... 

previous post:

Via Network/setter.xml => Request, the data was: data:"EN,myDEVICE_NAME,xx.xx.xx.xx.xx.xx,2,1;MODE=2,TIME=16777215,16711679,16711679,16711679,16711679,16711679,16777215;"

Comparing the data sent via api:( ft.set_mac_filter(FilterAction(2), "Devicexxx", "xx:xx:xx:xx:xx:xx", TimerMode(2), 1)) the response was: DATA0 = EN, myDEVICE_NAME, xx.xx.xx.xx.xx.xx,1;MODE=2,TIME=0,0;

Hereby after MAC_ADDRESS is asking 2,1;, but api send only 1; ?

Also i don't understand the web-ui's time definition: TIME=16777215,16711679,16711679,16711679,16711679,16711679,16777215;" Could you explain are they BASE64 or other coding?

PS: here's the relevant .js from web-ui I got relevant:

function setMACFilter()
{
    $(".TimeRuleError").hide();
    var Setting = "";
    var TIMERULE = "";
    var times = 0;
    $('#macfilter-tbody > #instance').each(function(index){
          var delRule = $(this).find('input[name="delete"]').prop('checked')?1:0;
          var enableChange = ($(this).find('input[name="enable"]').prop('checked') != o_data[index])?1:0;
          var enable = $(this).find('input[name="enable"]').prop('checked')?1:2;
          if(delRule == 1 && $(this).attr("value").match("New"))
                return;
          else if(delRule == 1)
                Setting += "DEL,"
          else if($(this).attr("value").match("New"))
                Setting += "ADD,"
          else if(enableChange == 1)
                Setting += "EN,"
          else return;
          times++;
          Setting += $(this).find("#deviceName").text() + ',' + $(this).find("#MACAddress").text() +',' + enable +',' + times +';';
    });

    if(checkIsChange()===true)
    {
          if(n_time.tMode==1)
          {
                TIMERULE = n_time.generalTime;
                if(n_time.count > 16 || n_time.generalTime == "0,0")
                {
                      $("[name='TimeErrMsg']").attr("id","g_pc31");
                      updateContent();
                      return $(".TimeRuleError").show();
                }
          }
          else if(n_time.tMode==2)
          {
                TIMERULE = n_time.dailyTime;
                if(n_time.count>32 || n_time.count == 0)
                {
                      $("[name='TimeErrMsg']").attr("id","g_pc32");
                      updateContent();
                      return $(".TimeRuleError").show();
                }
          }
          else
                TIMERULE = "0";
          Setting += "MODE="+n_time.tMode+",TIME="+TIMERULE+";";
   ajaxSet({'fun':120,'data':Setting},function(){goto("../gw_page/MACFiltering.html", "content", updatesuccess); }, NoneAction,updateerror);
    }else{
          return goto('../gw_page/MACFiltering.html','content');
    }
}