leiweibau / Pi.Alert

Scan the devices connected to your WIFI / LAN and alert you the connection of unknown devices. It also warns if a "always connected" device disconnects. In addition, it is possible to check web services for availability. For this purpose HTTP status codes and the response time of the service are evaluated.
https://leiweibau.net
GNU General Public License v3.0
331 stars 25 forks source link

Homepage widget #329

Closed d1nc174 closed 1 day ago

d1nc174 commented 4 days ago

Hi, First i want to thank you for your good work. Your fork of Pi.Alert is working very well for my setup on an Proxmox LXC together with Pihole. I have also Homepage installed on my server with a widget for Pi.Alert which was working well until the last update of Pi.Alert. I know that its not working through your API but it's accessing the device list directly with.. "{url}/php/server/devices.php?action=getDevicesTotals" but after the last update it returns only 0 for all devices. Can you please help me with this.. Thnx and have a nice day.

leiweibau commented 3 days ago

Yes, unfortunately that is correct. Because I have created a separate API, I wanted to protect the backend against direct calls. As I don't use the "Homepage" project myself, I wasn't aware of the implications. I would present you with a hot fix here, but would not revert the change in the code for the time being, unless more people get in touch.

Open this file and scroll to this line. https://github.com/leiweibau/Pi.Alert/blob/0f2d275ee7c0489443b89caacb9400b5055b9d0a/front/php/server/devices.php#L15

Change this

if ($_SESSION["login"] != 1) {
    header('Location: ../../index.php');
    exit;
}

to that

// if ($_SESSION["login"] != 1) {
//  header('Location: ../../index.php');
//  exit;
// }
d1nc174 commented 3 days ago

wow, thank you very much for a fast response and a hot fix for my setup.. I'll try it right away.. Have a nice day!

leiweibau commented 3 days ago

I might also adjust the condition so that the backend is both a little more secure, but this particular request is still answered.

d1nc174 commented 3 days ago

I tried it but it's still showing 0 for all devices. I restarted the lxc with PiAlert after changing this few lines. can you advise please.

leiweibau commented 3 days ago

Sorry, my fault. In addition to the change already mentioned, the function used here has been given an additional parameter as part of the satellite extension. This is of course generated and passed on within the web interface, but must be transmitted separately when called directly.

The link to be called now would be: "/php/server/devices.php?action=getDevicesTotals&scansource=local"

I could also install a fallback here. There is actually a fallback, but it is in the frontend.

d1nc174 commented 3 days ago

ok.. I'll try to add this link to the widget and see if it works..

leiweibau commented 3 days ago

This should no longer be necessary after the next update. However, if you adjust it now, it can remain after the update, as it will not cause any issues.

d1nc174 commented 3 days ago

I put the updated link in the widget.js but it still shows me 0es, but in the browser when i try this link it shows the correct numbers.. I also tried to use the netalertx widget and change the link there but it still shows 0es what am I doing wrong?

leiweibau commented 3 days ago

If you can, go back to the original status from 4 hours ago when you reported the issue. In the next 2-3 days I will release an update which should restore the functionality.

d1nc174 commented 3 days ago

ok. thnx I'll do that.

upD8R commented 2 days ago

Would love to see an official widget for homepage, too ;-)

leiweibau commented 2 days ago

I took 2-3 hours of my time today and had a look at the homepage.dev project. If a small change is made to the API with the next update, then everything should work with the code below. Then even with activated password protection.

        widget:
          type: customapi
          url: https://<IP or Hostname>/pialert/api/?get=system-status&api-key=<Your API Key>
          refreshInterval: 10000
          mappings:
            - field: All_Devices
              label: All Devices
              type: number 
            - field: Offline_Devices
              label: Offline
              type: number 
            - field: Online_Devices
              label: Online
              type: number
            - field: New_Devices
              label: New
              type: number 
homepage
leiweibau commented 2 days ago

... or with a little more effort

    - Pi.Alert:
        href: https://<IP or Hostname>/pialert/
        descriptionn: Network Scanner
        icon: https://<IP or Hostname>/pialert/img/favicons/flat_red_white.png
        widget:
          type: customapi
          url: https://<IP or Hostname>/pialert/api/?get=system-status&api-key=<Your API Key>
          refreshInterval: 10000
          display:
          mappings:
            - field: All_Devices
              label: All
              type: number
            - field: Offline_Devices
              label: Offline
              type: number 
            - field: Online_Devices
              label: Online
              type: number 
            - field: New_Devices
              label: New
              type: number
homepage
upD8R commented 2 days ago

Really awesome! Thanks very mich indeed!

leiweibau commented 2 days ago

Update released with https://github.com/leiweibau/Pi.Alert/commit/bf1bf71aaad31459d3a5ee21e53152da960b314b

leiweibau commented 2 days ago

The API used returns these fields. If necessary, you can still make some adjustments here.

"Scanning":"<String>",
"Last_Scan":"<String>",
"All_Devices":<Integer>,
"Offline_Devices":<Integer>,
"Online_Devices":<Integer>,
"Archived_Devices":<Integer>,
"New_Devices":<Integer>,
"All_Devices_ICMP":<Integer>,
"Offline_Devices_ICMP":<Integer>,
"Online_Devices_ICMP":<Integer>,
"All_Services":<Integer>
d1nc174 commented 2 days ago

Awsome indeed! And thank you for finding some time to solve this very niche thing for some of us who use Homepage in their home labs.. Keep the good work and have a nice day.

leiweibau commented 1 day ago

I will make a small extension to the API documentation later today, in which I will address this issue so that I can refer to the documentation in the future.

leiweibau commented 1 day ago

Updated docu https://github.com/leiweibau/Pi.Alert/blob/main/docs/API-USAGE.md#use-api-call-for-homepage