Well, it’s 3 AM, but I finally have a solution.
If you have an easier solution, I’m all ears!
(Gladys runs on a raspberry pi)
ON THE RASPBERRY PI:
#################
- We update the raspberry:
sudo apt-get update
sudo apt-get upgrade
- We install apache and modify the port so that it does not use the same one as gladys:
sudo apt-get install apache2 -y
sudo nano /etc/apache2/ports.conf
- modify the line « Listen 80 » to « Listen 90 » (I put 90 as the port but you can put the port you prefer)
- We install PHP:
sudo apt-get install php -y
- We enable the apache service at OS startup and start the apache service:
sudo systemctl enable apache2.service
sudo systemctl start apache2.service
- We install the services to shut down and start the remote PC:
sudo apt-get install samba-common -y
sudo apt-get install samba-common-bin
sudo apt-get install etherwake -y
- We create the PHP script file to start the remote PC via Wake-On-Lan:
sudo nano /var/www/html/boot.php
- We add the following code to it:
<?php
exec("etherwake -D MACADRESSEDUPC");
?>
(replace MACADRESSEDUPC with the MAC address of the remote PC)
- Then we add permissions to it:
sudo chmod 700 /var/www/html/boot.php
sudo chown www-data:www-data /var/www/html/boot.php
ON THE REMOTE WINDOWS PC:
###########################
Launch regedit and go to this location:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System
Add a new DWORD32 key named « LocalAccountTokenFilterPolicy » and set the value to « 1 » if it does not exist.
Launch Services.msc, set the « Remote Registry » service to « Automatic » and start it.
In the Windows firewall, allow « Windows Management Infrastructure (WMI) » (personally, I did not have to do this)
IN GLADYS4:
#############
Create a new Scene.
As a trigger, choose the one you prefer. (for my part, I chose « return home », so that my pc turns on when I get home.)
As an action, choose « Make an HTTP request », method = « POST » and URL = « http://IPDURASPBERRY:90/boot.php ». Leave the rest empty and save the scene.
(replace IPDURASPBERRY with the IP address of the raspberry pi)
You can test the operation by pressing the « Start » button on the scene you just created.
To cancel a shutdown under Windows, open a CMD and type « shutdown -a »
.
.
.
.
.
.
To shut down the remote PC, we repeat steps 6 to 8 as follows:
6) We create the PHP script file to shut down the remote PC:
sudo nano /var/www/html/shutdown.php
- We add the following code to it:
<?php
exec("net rpc shutdown -f -I IPDUPCDISTANT -U UTILISATEUR%MOTDEPASSE");
?>
(replace IPDUPCDISTANT with the IP address of the remote PC, UTILISATEUR with your username of the remote PC and MOTDEPASSE with the password of the user of the remote PC)
- Then we add permissions to it:
sudo chmod 700 /var/www/html/shutdown.php
sudo chown www-data:www-data /var/www/html/shutdown.php
Of course, you still have to make a scene in Gladys like for the boot but by choosing « leaving home » as a trigger for example and as an action, choose « Make an HTTP request », method = « POST » and URL = « http://IPDURASPBERRY:90/shutdown.php ». Leave the rest empty and save the scene.