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

Workflow question #66

Open
drnasin opened this issue Aug 18, 2020 · 4 comments
Open

Workflow question #66

drnasin opened this issue Aug 18, 2020 · 4 comments
Labels

Comments

@drnasin
Copy link

drnasin commented Aug 18, 2020

Hi guys. I am a full blooded PHP dev but I suck at mikrotik stuff. I have a task to do the following

"Add 2 rules. Make sure they are inserted (or moved afterwards) before a rule that has a comment "Block access to internet")
I have no idea how to do that using UTIL class.

I can add rules. My problem is how to insert them or move them afterwards before the stated rule..

            $additionalRule = [];
            if($fw_rules_comment === 'Allow Teamviewer') {
                $additionalRule = $insertRule;
                $additionalRule['protocol'] = 'udp';
            }

            $insertRuleID = $util->add($insertRule);

            if(count($additionalRule)) {
                $additionalRuleID = $util->add($additionalRule);
            }

//make sure both rules are added or moved afterwards BEFORE the rule that has comment "Block access to internet"

Thank you!

@drnasin
Copy link
Author

drnasin commented Aug 18, 2020

Also how do you remove the rule?

$util->remove(\PEAR2\Net\RouterOS\Query::where('comment', 'Allow Teamviewer'));

throws an error: Error when removing items

@boenrobot
Copy link
Member

boenrobot commented Aug 19, 2020

RouterOS has a "place-before" property in menus with a move command. When you add, this inserts the new item before the target item.

To move an item afterwards, Util has a move() method that works in a similar fashion. See this part in the wiki page about it.

The remove of multiple items with a query should work in dev-master, but in 1.0.0b6, you can workaround it by wrapping the query in a find(), i.e.

$util->remove($util->find(\PEAR2\Net\RouterOS\Query::where('comment', 'Allow Teamviewer')));

@drnasin
Copy link
Author

drnasin commented Aug 19, 2020

thank you @boenrobot

I did try that initially as well but I keep getting the same error message

$util->remove($util->find(\PEAR2\Net\RouterOS\Query::where('comment', 'Allow Teamviewer')));

@drnasin
Copy link
Author

drnasin commented Aug 19, 2020

@boenrobot

Found another solution which works like a charm

           foreach ($util->getAll() as $rule) {
                if(intval($rule->getProperty('dst-port')) === 5938) {
                    $util->remove($rule->getProperty('.id'));
                }
            }

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