• Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login
TRIGGERcmd
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login

Controlling Pi-Hole on the Raspberry Pi remotely through Alexa

Raspberry Pi
2
6
1.1k
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G
    Georgi_Sharkov
    last edited by Apr 16, 2022, 9:33 PM

    Good Evening, and Sorry for the repeating topic.
    I am trying to control Pi-Hole on my Pi with Alexa Echo device. I have installed Triggercmd ( subscribed to it, to use commands more often.)on Windows 10 laptop . Can I enter a command (pihole_on_off.sh)that allows me to run the script on my Pi without installing triggercmd on Pi.
    Sorry again I am quite new in scripting.
    Thanks.
    3375bc8a-325d-4f36-abaf-5c28e5d5dbfa-image.png

    R 1 Reply Last reply Apr 18, 2022, 9:20 PM Reply Quote 0
    • R
      Russ @Georgi_Sharkov
      last edited by Russ Apr 18, 2022, 9:21 PM Apr 18, 2022, 9:20 PM

      @georgi_sharkov, yes, you can use ssh to run commands on your Raspberry Pi from your Windows 10 PC without installing a triggercmd agent on the Raspberry Pi.

      Install the OpenSSH client in Windows 10 by opening an elevated command prompt (right-click cmd and run as administrator) and running this command:

      dism /Online /Add-Capability /CapabilityName:OpenSSH.Client
      

      Then to generate a public/private key pair, run this from a normal cmd prompt, run this and press enter a few times.

      ssh-keygen
      

      You'll end up with a .ssh folder with an id_rsa file and an id_rsa.pub file. The id_rsa is your private key, so keep that private. The id_rsa.pub file contains text you need to copy into the authorized_keys file on your Raspberry Pi so you can ssh into the Pi without a password.

      Log into your Raspberry Pi as the pi user, or which ever user you use:

      ssh pi@garagepi
      

      At this point you'll still need to enter your password.

      Once logged in, edit your pi user's ~/.ssh/authorized_keys file, and append the contents of the id_rsa.pub file to the end of that authorized_keys file. If it's empty that's fine. Just paste the contents in and save it.

      Now logout, and run this command again:

      ssh pi@raspberrypi
      

      If it logs in without a password, you're golden. Now you can run remote commands on the Raspberry Pi like this:

      ssh pi@raspberrypi ls
      

      In that case I ran the ls command on the Pi from my Windows box, but you could run any command including a script that enables or disables Pi Hole. For example your Command and Off Command could be these:

      ssh pi@raspberrypi ~/pi_hole_on.sh
      ssh pi@raspberrypi ~/pi_hole_off.sh
      

      Russell VanderMey

      G 1 Reply Last reply May 21, 2022, 7:15 PM Reply Quote 0
      • G
        Georgi_Sharkov @Russ
        last edited by May 21, 2022, 7:15 PM

        @russ Thank you for the reply and apologies for the late reply from my side. Is it possible to run a curl command in the triggercmd that will be able to deactivate or activate the PiHole?PiHole is installed on the Pi4 and it is accessible through a browser with an internal IP address like 192.168.8.102 from my PC. What will be the command to insert in the triggercmd command line in this case?

        R 1 Reply Last reply May 21, 2022, 9:00 PM Reply Quote 0
        • R
          Russ @Georgi_Sharkov
          last edited by May 21, 2022, 9:00 PM

          @georgi_sharkov, you could use Chrome, press F12, find the request under the network tab, then copy the "Copy all as cURL (cmd)" option.

          a4e9240c-0cb7-41bf-92d6-ac43abf74272-image.png

          That will give you the curl command, but if there's authentication in the request, it will likely expire after some time.

          Russell VanderMey

          G 2 Replies Last reply May 27, 2022, 6:21 PM Reply Quote 0
          • G
            Georgi_Sharkov @Russ
            last edited by May 27, 2022, 6:21 PM

            @russ Thank you for the advice. I tried this command:
            http://192.168.8.102/admin/api.php?disable=300&auth=
            (auth parameter doesn't have any hashed value as I don't have a password setup for Pihole)
            16172f57-f3dd-4d8c-b96e-a125fd1357d8-image.png
            It works just fine if I type it manually in the browser. When I add it to the CMD GUI window command, when I run it with the start command, it shows me the message:
            Empty token! Check if cookies are enabled on your system.
            All cookies are enabled in the browser. What could be the issue?
            Maybe this will help you- when I run the command, it appears in the browser without the last bit 335e47c7-655a-4fc3-84d4-421b473c7e44-image.png
            I don't know, maybe I am doing something wrong as I am quite new in this field.

            1 Reply Last reply Reply Quote 0
            • G
              Georgi_Sharkov @Russ
              last edited by May 29, 2022, 12:44 PM

              @russ I added the password to pi-hole and generated the token from web API. New URL that appeared with that token has been added to the TriggerCMD. However, this still doesn't resolve the problem, I am receiving the same message with empty token. Can anyone help with the issue? Where to dig further? Thanks

              1 Reply Last reply Reply Quote 0
              • First post
                Last post