RESTFul API ?

Suggest improvements and new features for Gargoyle.

Moderator: Moderators

Post Reply
foxyboy
Posts: 71
Joined: Tue Dec 22, 2015 10:23 am
Location: Ireland

RESTFul API ?

Post by foxyboy »

Hi,

Have gargoyle 191 up and running a good few months now, was particulary after the QoS and Restricitions functionality as i have a house full of teenangers.

One issue i do come across is i may have wifi restricted for the kids devices during the day but suddenly they get a day off school for example ! Chaos ensues :roll:
I dont really expect my wife to login and disable the Restriction so
i was thinking i could do the following
* create an android app that has 2 buttons - Wifi Schedules Enable/Disable
* this executes some java code on the router which has a RESTful API
called schedulewifi, this in turn either enables all schedules or disables them (could enforce naming scheme to get these)
trouble is hiow do i get access to this level of functionality ?

Now if i got this working it could simply be expanded for simlar types of tasks.

So my question is would this RESTful API not be a good feature to implement for the router itself or maybe as an addon ??????
Linksys WRT1200AC v1 Gargoyle 1.12
TP-Link Archer A7 v5 Gargoyle 1.13 PL

Lantis
Moderator
Posts: 6753
Joined: Mon Jan 05, 2015 5:33 am
Location: Australia

Re: RESTFul API ?

Post by Lantis »

If anything it should be a plugin.

There are several ways to skin a cat. I think an app is overkill. But a new web page in the router is easily doable without needing to expose any extra APIs.
Access everything through UCI.

If this was something you wanted to pursue I can point you in the right direction.
http://lantisproject.com/downloads/gargoyle_ispyisail.php for the latest releases
Please be respectful when posting. I do this in my free time on a volunteer basis.

foxyboy
Posts: 71
Joined: Tue Dec 22, 2015 10:23 am
Location: Ireland

Re: RESTFul API ?

Post by foxyboy »

Yes please !
Linksys WRT1200AC v1 Gargoyle 1.12
TP-Link Archer A7 v5 Gargoyle 1.13 PL

Lantis
Moderator
Posts: 6753
Joined: Mon Jan 05, 2015 5:33 am
Location: Australia

Re: RESTFul API ?

Post by Lantis »

https://wiki.openwrt.org/doc/uci

So this is UCI. It exposes all of the configuration files for Gargoyle to the command line. The important command we need are
uci get config.section.option
uci set config.section.option=value
uci commit config
uci show config

In this case, restrictions are stored in the firewall config, so we want
uci show firewall
this will give us a formatted view of the firewall config.

Now from memory, restrictions are of the form firewall.restriction_rule and firewall.whitelist_rule.
So now we can do uci show firewall.restriction_rule to get a list of only those sections.

Each section should have an option "enabled" set to either 1 or 0. This is the value we will modify using uci set.
After we modify configs we must uci commit them. Then we restart the service that uses them, in this case the firewall using /usr/lib/gargoyle/restart_firewall.sh.

So hopefully with this information you can come up with an idea for how to disable/enable the rules you are interested in?
We can go from there once we have a strategy.

Feel free to post the output of uci show firewall if you need a hand. Just give it a quick read and make sure there's no passwords or anything else you don't want in there. I don't think there is in that config.
http://lantisproject.com/downloads/gargoyle_ispyisail.php for the latest releases
Please be respectful when posting. I do this in my free time on a volunteer basis.

foxyboy
Posts: 71
Joined: Tue Dec 22, 2015 10:23 am
Location: Ireland

Re: RESTFul API ?

Post by foxyboy »

Great stuff, I was unaware of UCI functionality

So for example I would need to allow the Mrs to disable the following rule, trick will be to allow here to do this easily via url

root@Gargoyle:~# uci show firewall|grep firewall.rule_5
firewall.rule_5=restriction_rule
firewall.rule_5.is_ingress='0'
firewall.rule_5.description='MonTueThu-Avo-SchoolTerm'
firewall.rule_5.active_weekdays='mon,tue,thu'
firewall.rule_5.active_hours='16:30-18:00'
firewall.rule_5.enabled='1'
Linksys WRT1200AC v1 Gargoyle 1.12
TP-Link Archer A7 v5 Gargoyle 1.13 PL

Lantis
Moderator
Posts: 6753
Joined: Mon Jan 05, 2015 5:33 am
Location: Australia

Re: RESTFul API ?

Post by Lantis »

So the quickest way will be to create a script that sets the enabled flag to 0, commits the change, and then reboots the firewall.

About, 3-4 lines of code :)

How to make it accessible to your wife.... hmm.

You could create a new page in the interface with 2 buttons. Enable and disable.
Are you familiar with javascript at all?
http://lantisproject.com/downloads/gargoyle_ispyisail.php for the latest releases
Please be respectful when posting. I do this in my free time on a volunteer basis.

ispyisail
Moderator
Posts: 5185
Joined: Mon Apr 06, 2009 3:15 am
Location: New Zealand

Re: RESTFul API ?

Post by ispyisail »

You could create a new page in the interface with 2 buttons. Enable and disable.
Are you familiar with javascript at all?
plink + Autohotkey?

foxyboy
Posts: 71
Joined: Tue Dec 22, 2015 10:23 am
Location: Ireland

Re: RESTFul API ?

Post by foxyboy »

Yes i can mange javascript, is there any sample or tutorial around ?
Ive search the forum and these no where i can find that someone has done something similar, im sure thats not the case

I will also want to login automatically, can this be done by providng params in url, passing these to login function and then displaying my custom page with 2 buttons ? On button press then execute the script and toggle the enabled flag
Linksys WRT1200AC v1 Gargoyle 1.12
TP-Link Archer A7 v5 Gargoyle 1.13 PL

Lantis
Moderator
Posts: 6753
Joined: Mon Jan 05, 2015 5:33 am
Location: Australia

Re: RESTFul API ?

Post by Lantis »

Auto login... not sure.
We could just make the page accessible without logging in. How much do you trust your children :P
The menu wouldn't work without being logged in so the only way they could find it would be to discover the page name e.g. http://192.168.1.1/holidaywifi.sh
This is no problem for your wife if you just add it as a bookmark on the phone/computer etc.


The simplest page to base it off might be the "identification" page under System settings.
Swap the two boxes for a single drop down?
Or implement the two button idea.

The basic idea of the gargoyle pages is that they buffer all of the required commands into a "commands" variable and then post these to the router, which is then executed by a script on the router.

https://github.com/ericpaulbishop/gargo ... ication.sh

https://github.com/ericpaulbishop/gargo ... ication.js

Unfortunately i don't have time to build this for you but i can continue to provide support and pointers.
I think user nworbnhoj might have made a page that doesn't require login? I think you just need to remove the cookie/hash checker from the beginning of the page.
http://lantisproject.com/downloads/gargoyle_ispyisail.php for the latest releases
Please be respectful when posting. I do this in my free time on a volunteer basis.

foxyboy
Posts: 71
Joined: Tue Dec 22, 2015 10:23 am
Location: Ireland

Re: RESTFul API ?

Post by foxyboy »

Thanks Lantis, appreciate it.
I think I have enough to give this a go.
Linksys WRT1200AC v1 Gargoyle 1.12
TP-Link Archer A7 v5 Gargoyle 1.13 PL

Post Reply