Tuesday, December 8, 2015

Linux pc (arch) as slave to synology NAS that's connected to a UPS with USB

My synology NAS is connected to my UPS with USB. I want my linux pc to listen for UPS events and shut down when the power is low.

Step 1 - Set up UPS daemon the on the synology nas

192.168.1.148 is the IP of my PC.



Step 2  - Install network-ups-tools

https://aur4.archlinux.org/packages/network-ups-tools/

In my case it was
$aura -A network-ups-tools


Step 3 - Configure network ups tools client.

First I got the password from the synology ups daemon.
 $ ssh root@nas1
$ DS212J> cat /usr/syno/etc/ups/upsd.users

In my case it was:

[monuser]
password = secret
upsmon master

Second add the credentials to /etc/ups/upsmon.conf

For me it ended up being

MONITOR ups@192.168.1.69:3493 1 monuser secret slave
Step 4 - Enable the nut-monitor

sudo systemctl daemon-reload
sudo systemctl enable nut-monitor
sudo systemctl start nut-monitor

Step 5 - Test

$ sudo systemctl status nut-monitor

Dec 08 20:01:31 buggle upsmon[17335]: UPS ups@192.168.1.69:3493 on battery
Dec 08 20:02:01 buggle upsmon[17335]: UPS ups@192.168.1.69:3493 on line power
Dec 08 20:04:41 buggle upsmon[17335]: UPS ups@192.168.1.69:3493 battery is low

Step 6 - WalNUT

I installed https://github.com/zykh/walNUT to get some status in gnome shell.


1.) mkdir ~/.local/share/gnome-shell/extensions
2.) cd ~/.local/share/gnome-shell/extensions3.) git clone --depth 1 https://github.com/zykh/walNUT.git walnut@networkupstools

4.) glib-compile-schemas walnut@networkupstools/schemas/
5.) alt+f2 r (restart shell)
6.) Use gnome web browser to go to extensions.gnome.org
7.) Enable the extension.
8.) Click the magnifying glass and put in 192.168.1.69:3493 (ip of nas).

Saturday, October 10, 2015

Reverse proxy for sonarr

First, on my home PC which is hosting sonarr - I'll restrict access to PCs on my LAN and the VPS.
iptables -I INPUT -p tcp -s VPS_IP --dport 8989 -j ACCEPT
iptables -I INPUT -p tcp -s 192.168.1.0/24 --dport 8989 -j ACCEPT
iptables -I INPUT -p tcp -s 127.0.0.1 --dport 8989 -j ACCEPT
iptables -I INPUT -p tcp -s 0.0.0.0/0 --dport 8989 -j DROP
Forward 8989 to PC running sonarr in router.



On vps in apache default site:

ProxyPreserveHost Off
ProxyPass /sonarr http://HOME_PC:8989/sonarr
ProxyPassReverse /sonarr http://HOME_PC:8989/sonarr

Also had to set settings->general-> URL Base in sonarr.


Make sure to enable authentication, either via sonarr or apache. I used form login.

<Proxy z>
AuthFormProvider file
    AuthType form
    AuthName "Login Required"
    Session Off
    SessionCookieName session path=/
    require valid-user
  # This is the login page
   ErrorDocument 401 /auth.html
           # This is the file containing users login data
   AuthUserFile /etc/apache2/.htpasswd
</Proxy>



Friday, September 18, 2015

Configuring new VPS.

Login to the server (via ssh).

$ ssh root@*.*.*.*
root@ubuntu:~# w
I want to create another user.
root@ubuntu:~# adduser youri
Make sure I can login as youri. 
 $ ssh youri@*.*.*.*

Escalate to root:
youri@ubuntu:~$ su root
Password: 
I want to disable root ssh login.
#PermitRootLogin no in /etc/ssh/sshd_config and service ssh restart
Logging as root says: Permission denied, please try again
Now I want to transfer my keys.
 $ ssh-copy-id  youri@*.*.*.*
spits out

/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: WARNING: All keys were skipped because they already exist on the remote system.
but after ssh-add ~/.ssh/id_rsa it worked and copied the key.

Ssh in again and passwordless login is working. 

Now I want to disable password logins altogether.
PasswordAuthentication no in /etc/ssh/sshd_config and service ssh restart
Add my user to sudoers:
root@ubuntu:/home/youri# usermod -a -G sudo youri
Set.