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

Feature: OpenWRT service widget #2782

Merged
merged 4 commits into from Jan 29, 2024
Merged

Conversation

DanGRT
Copy link
Contributor

@DanGRT DanGRT commented Jan 29, 2024

Proposed change

Adds a widget for OpenWRT integration
Screenshot 2024-01-29 at 17 54 49

Allows for either system info or information on a particular interface (i.e eth0 for WAN) by adding that interface name as interfaceName in services.yaml

Closes #1509

Type of change

Adds a new widget for OpenWRT

  • New service widget
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Documentation only
  • Other (please explain)

Checklist:

  • If applicable, I have added corresponding documentation changes.
  • If applicable, I have reviewed the feature and / or service widget guidelines.
  • I have checked that all code style checks pass using pre-commit hooks and linting checks.
  • If applicable, I have tested my code for new features & regressions on both mobile & desktop devices, using the latest version of major browsers.

@DanGRT
Copy link
Contributor Author

DanGRT commented Jan 29, 2024

I'm not 100% on the statistics shown here, though the OpenWRT rpc schema is a little tricky to work with so thought of this as decent enough start. Please let me know if you have any suggestions or any requirements I have missed. Thanks

@shamoon
Copy link
Collaborator

shamoon commented Jan 29, 2024

Please provide some sample data, thanks

@shamoon shamoon changed the title Feat: OpenWRT widget implementation Feature: OpenWRT service widget Jan 29, 2024
@DanGRT
Copy link
Contributor Author

DanGRT commented Jan 29, 2024

Not sure if this is what you want exactly, let me know if not.

Example services.yaml:

- OpenWRT:
    - System:
        href: http://192.168.1.71
        widget:
          type: openwrt
          url: http://192.168.1.71
          username: homepage-widget
          password: 1234
    - WAN:
        href: http://192.168.1.71
        widget:
          type: openwrt
          url: http://192.168.1.71
          username: homepage-widget
          password: 1234
          interfaceName: eth0
    - LAN:
        href: http://192.168.1.71
        widget:
          type: openwrt
          url: http://192.168.1.71
          username: homepage-widget
          password: 1234
          interfaceName: eth1

Example response data for ["system", "info", {}]

   0,
   {
      "localtime":1706553900,
      "uptime":939985,
      "load":[
         3264,
         5664,
         4736
      ],
      "memory":{
         "total":8181571584,
         "free":292585472,
         "shared":27353088,
         "buffered":209911808,
         "available":531288064,
         "cached":4923392
      },
      "root":{
         "total":4046560,
         "free":4023408,
         "used":23152,
         "avail":3797312
      },
      "tmp":{
         "total":3994908,
         "free":3993860,
         "used":1048,
         "avail":3993860
      },
      "swap":{
         "total":8178888704,
         "free":6991638528
      }
   }
]`

Example response data for `["network.device", "status", {}]`

`[
   0,
   {
      "eth0":{
         "external":false,
         "present":true,
         "type":"Network device",
         "up":true,
         "carrier":true,
         "auth_status":false,
         "link-advertising":[
            
         ],
         "link-partner-advertising":[
            
         ],
         "link-supported":[
            
         ],
         "speed":"10000F",
         "autoneg":false,
         "flow-control":{
            "autoneg":true,
            "supported":[
               
            ],
            "link-advertising":[
               
            ],
            "link-partner-advertising":[
               
            ],
            "negotiated":[
               
            ]
         },
         "hw-tc-offload":false,
         "devtype":"ethernet",
         "mtu":1500,
         "mtu6":1500,
         "macaddr":"br:24:11:1t:4f:99",
         "txqueuelen":1000,
         "ipv6":true,
         "ip6segmentrouting":false,
         "promisc":false,
         "rpfilter":0,
         "acceptlocal":false,
         "igmpversion":0,
         "mldversion":0,
         "neigh4reachabletime":30000,
         "neigh6reachabletime":30000,
         "neigh4gcstaletime":60,
         "neigh6gcstaletime":60,
         "neigh4locktime":100,
         "dadtransmits":1,
         "multicast":true,
         "sendredirects":true,
         "drop_v4_unicast_in_l2_multicast":false,
         "drop_v6_unicast_in_l2_multicast":false,
         "drop_gratuitous_arp":false,
         "drop_unsolicited_na":false,
         "arp_accept":false,
         "gro":false,
         "statistics":{
            "collisions":0,
            "rx_frame_errors":0,
            "tx_compressed":0,
            "multicast":0,
            "rx_length_errors":0,
            "tx_dropped":0,
            "rx_bytes":26907591560,
            "rx_missed_errors":0,
            "tx_errors":0,
            "rx_compressed":0,
            "rx_over_errors":0,
            "tx_fifo_errors":0,
            "rx_crc_errors":0,
            "rx_packets":21897182,
            "tx_heartbeat_errors":0,
            "rx_dropped":0,
            "tx_aborted_errors":0,
            "tx_packets":12526904,
            "rx_errors":0,
            "tx_bytes":5315404801,
            "tx_window_errors":0,
            "rx_fifo_errors":0,
            "tx_carrier_errors":0
         }
      },
      "eth1":{
         "external":false,
         "present":true,
         "type":"Network device",
         "up":false,
         "carrier":true,
         "auth_status":false,
         "link-advertising":[
            
         ],
         "link-partner-advertising":[
            
         ],
         "link-supported":[
            
         ],
         "speed":"10000F",
         "autoneg":false,
         "flow-control":{
            "autoneg":true,
            "supported":[
               
            ],
            "link-advertising":[
               
            ],
            "link-partner-advertising":[
               
            ],
            "negotiated":[
               
            ]
         },
         "hw-tc-offload":false,
         "devtype":"ethernet",
         "mtu":1500,
         "mtu6":1500,
         "macaddr":"bd:24:11:eb:67:25",
         "txqueuelen":1000,
         "ipv6":true,
         "ip6segmentrouting":false,
         "promisc":false,
         "rpfilter":0,
         "acceptlocal":false,
         "igmpversion":0,
         "mldversion":0,
         "neigh4reachabletime":30000,
         "neigh6reachabletime":30000,
         "neigh4gcstaletime":60,
         "neigh6gcstaletime":60,
         "neigh4locktime":100,
         "dadtransmits":1,
         "multicast":true,
         "sendredirects":true,
         "drop_v4_unicast_in_l2_multicast":false,
         "drop_v6_unicast_in_l2_multicast":false,
         "drop_gratuitous_arp":false,
         "drop_unsolicited_na":false,
         "arp_accept":false,
         "gro":false,
         "statistics":{
            "collisions":0,
            "rx_frame_errors":0,
            "tx_compressed":0,
            "multicast":0,
            "rx_length_errors":0,
            "tx_dropped":0,
            "rx_bytes":4701031034,
            "rx_missed_errors":0,
            "tx_errors":0,
            "rx_compressed":0,
            "rx_over_errors":0,
            "tx_fifo_errors":0,
            "rx_crc_errors":0,
            "rx_packets":11637883,
            "tx_heartbeat_errors":0,
            "rx_dropped":0,
            "tx_aborted_errors":0,
            "tx_packets":21399834,
            "rx_errors":0,
            "tx_bytes":25783880880,
            "tx_window_errors":0,
            "rx_fifo_errors":0,
            "tx_carrier_errors":0
         }
      }
   }
]`

Example from `["00000000000000000000000000000000", "session", "login"]`:

  `[0,{"ubus_rpc_session":"1234","timeout":300,"expires":300,"acls": {}}]`



@shamoon
Copy link
Collaborator

shamoon commented Jan 29, 2024

Yea thanks, I dont have an openwrt device to test.

Is the 00000000000000000000000000000000 thing real??

@DanGRT
Copy link
Contributor Author

DanGRT commented Jan 29, 2024

Yeah, basically when first logging in you need to provide a ubus_rpc_session as the first element in params array (just as when you're logged in)

The session id 00000000000000000000000000000000 (32 zeros) is a special null-session which only has the rights from the unauthenticated access group, only enabling the session.login ubus call. A session has a timeout that can be specified when you login, otherwise it defaults to 5 minutes.
https://openwrt.org/docs/techref/ubus#session_management

Copy link
Collaborator

@shamoon shamoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, some small notes.

I cant really test the proxy, of course, will take your word for it on that. Hopefully openwrt is pretty consistent across installs...

Screenshot 2024-01-29 at 11 26 57 AM Screenshot 2024-01-29 at 11 26 53 AM

docs/widgets/services/openwrt.md Outdated Show resolved Hide resolved
src/widgets/openwrt/proxy.js Outdated Show resolved Hide resolved
src/widgets/openwrt/proxy.js Outdated Show resolved Hide resolved
src/widgets/openwrt/proxy.js Outdated Show resolved Hide resolved
src/widgets/openwrt/proxy.js Outdated Show resolved Hide resolved
public/locales/en/common.json Outdated Show resolved Hide resolved
public/locales/en/common.json Outdated Show resolved Hide resolved
src/widgets/openwrt/methods/system.jsx Outdated Show resolved Hide resolved
docs/widgets/services/openwrt.md Outdated Show resolved Hide resolved
public/locales/en/common.json Outdated Show resolved Hide resolved
@shamoon
Copy link
Collaborator

shamoon commented Jan 29, 2024

Ah, sorry my bad I did not mean to actually push that changes (I had them just to test the lint).

@DanGRT
Copy link
Contributor Author

DanGRT commented Jan 29, 2024

Ah, sorry my bad I did not mean to actually push that changes (I had them just to test the lint).

All good~ I've pushed up with your suggestions. Only one I differed on was using (5m), just because load is returned as an array of 3 values from openwrt (1, 5 and 15 minutes) so I'd prefer to label it as such. Let me know if theres anything else.

Thanks!

@shamoon shamoon enabled auto-merge (squash) January 29, 2024 20:29
Copy link
Collaborator

@shamoon shamoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great thanks

@shamoon shamoon merged commit 86740c6 into gethomepage:main Jan 29, 2024
2 checks passed
@DanGRT
Copy link
Contributor Author

DanGRT commented Jan 29, 2024

Thanks shamoon

discretizer pushed a commit to discretizer/homepage that referenced this pull request Feb 5, 2024
* Feat: OpenWRT widget implementation

* Update proxy.js

* fixes from review

---------

Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
discretizer pushed a commit to discretizer/homepage that referenced this pull request Feb 6, 2024
* Feat: OpenWRT widget implementation

* Update proxy.js

* fixes from review

---------

Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
discretizer pushed a commit to discretizer/homepage that referenced this pull request Feb 6, 2024
* Feat: OpenWRT widget implementation

* Update proxy.js

* fixes from review

---------

Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
Plancke pushed a commit to Plancke/homepage that referenced this pull request Feb 23, 2024
* Feat: OpenWRT widget implementation

* Update proxy.js

* fixes from review

---------

Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
Plancke pushed a commit to Plancke/homepage that referenced this pull request Feb 23, 2024
* Feat: OpenWRT widget implementation

* Update proxy.js

* fixes from review

---------

Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
@enzo-festorazzi
Copy link

UPTIME and CPU LOAD AVG works perfect for me.
Openwrt

But when I add interfaceName: eth0 or interfaceName: eth1 it doesn't work.
1
I do not know what I'm doing wrong.

@shamoon
Copy link
Collaborator

shamoon commented Feb 23, 2024

Better to start a new discussion than comment on a closed PR. Also please post the container logs and api output (there) for that

Copy link
Contributor

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new discussion for related concerns. See our contributing guidelines for more details.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants