Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do you use delete rule? #1

Open
chancity opened this issue Sep 27, 2016 · 7 comments
Open

How do you use delete rule? #1

chancity opened this issue Sep 27, 2016 · 7 comments
Labels

Comments

@chancity
Copy link

How do you use delete rule?

@marcortw
Copy link
Owner

Does something like this work? Didn't have the time right now to test it myself. Sorry for the lack of documentation.

var fwcontrol = require('pfsense-fwcontrol');

var deleteRule = {
    action: 'delete',
    params: {
        id: <the id you previously received from the addRule>
    }
};

fwcontrol.start({
    baseUrl: 'http://192.168.2.122/',
    username: 'admin',
    password: 'pfsense',
    proxy: 'http://localhost:8888' // proxy is optional
}, [deleteRule], function (err, result) {
    if (err) {
        console.log(err);
    } else {
        console.log(result);
    }
});

@chancity
Copy link
Author

chancity commented Sep 27, 2016

There are no errors when running this but it's not accomplishing the delete.

rule = { action: 'delete', params: { interface: 'lan', id: id } };

@chancity
Copy link
Author

I think this element no longer exists, .listbg.descr

@chancity
Copy link
Author

chancity commented Sep 27, 2016

this fixed it

var getRuleByDescription = function (html, description) {
    var $ = cheerio.load(html);
    var searchString = 'td:contains(' + description + ')';
    var id = null;

    $('#ruletable tr').each(function(){
        $(this).find('td').each(function(){
        var ruleDescription = $(this).text().trim();
        if(ruleDescription == description){
            var parentHtml = $(this).parent().html();
            $ = cheerio.load(parentHtml);
            id = $(':input').attr("value");
        }
    })});

    return id;
};

@chancity chancity reopened this Sep 28, 2016
@marcortw
Copy link
Owner

Thanks for the feedback. I only tested it with the community edition version 2.2.6. It would be nice to have some version detection. If I find the time, i will try to build something like that and would log a warning if it's a higher version number. Feel free to contribute :-)

@marcortw
Copy link
Owner

By the way, which pfsense version are you using? If it's 2.2.x i'll try to fix it and if it's a newer version i can try to write some version detection. If I find the time.

@chancity
Copy link
Author

2.3.2-RELEASE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants