Hua Hin cloud server 2017 on Synology DS716+.
/usr/syno/etc/preference/username/google_authenticator
<?php
try {
$url = 'https://dynamicdns.park-your-domain.com/update?host='.$_GET['host'].'&domain='.$_GET['domain'].'&password='.$_GET['password'].'&ip='.$_GET['ip'];
// with allow_url_fopen enabled
$output = file_get_contents($url);
// with curl
//$req = curl_init();
//curl_setopt($req, CURLOPT_URL, $url);
//curl_setopt($req, CURLOPT_RETURNTRANSFER, true);
//curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: text/xml'));
//$output = curl_exec($req);
//curl_close($req);
$xml = new SimpleXMLElement(trim(str_replace("encoding=\"utf-16\"","",$output)));
if ($xml->ErrCount > 0) {
$error = $xml->errors[0]->Err1;
if (strcmp($error, "Domain name not found") === 0) {
echo "nohost";
} elseif (strcmp($error, "Passwords do not match") === 0) {
echo "badauth";
} elseif (strcmp($error, "Passwords is empty") === 0) {
echo "badauth";
} elseif (strcmp($error, "No Records updated. A record not Found;") === 0) {
echo "nohost";
} else {
echo "911 [".$error."]";
}
} else {
echo "good";
}
} catch (Exception $e) {
echo "911 [".$e->getMessage()."]";
}
<RequireAny>
Require expr "%{QUERY_STRING} =~ /your Namecheap DDNS password/" # allow the DDNS updater to run from the changed ip address
Require forward-dns host.domain.tld # allow access from the DDNS domain name after updating the ip address
</RequireAny>
https://vps.condrau.com/html/ddns-namecheap.php?host=__USERNAME__&domain=__HOSTNAME__&password=__PASSWORD__&ip=__MYIP__
If you are running a Synology NAS to handle cloud and mail, but another webserver to handle https sites, you will end up with some certificate issues. I solve those by updating the certificate on the web server and then copy the renewed certificate over to the NAS.
which rsync
user ALL=(root) NOPASSWD:/path/to/rsync
sudo rsync -aPLe 'ssh -l user -i /volume1/homes/user/.ssh/id_rsa' --rsync-path='sudo rsync' pandora:/etc/letsencrypt/live/cloud.domain.tld/fullchain.pem /usr/syno/etc/certificate/_archive/<dir>/cert.pem
cat /usr/syno/etc/certificate/_archive/DEFAULT
sudo -u bco sh /volume1/homes/bco/batch/copycert
#!/bin/sh
#
# Copy certificates from web server to NAS
# you must add user to be able to run cksum with sudo without password on the remote machine
# (c) 2019-08-06, 2019-11-27, 2020-02-21, Bernard Condrau
#
# CERTDIR must be hardcoded and is different in every server instance
# see https://github.com/Neilpang/acme.sh/wiki/Synology-NAS-Guide
# if you used the normal method the certificate will be installed in the "system/default" directory
# if you used the alternative method it is copied to an unknown path, you can find it in file "_archive/DEFAULT"
# CERTDIR="system/default"
CERTDIR="_archive/4LSLbi"
CERTROOTDIR="/usr/syno/etc/certificate"
PACKAGECERTROOTDIR="/usr/local/etc/certificate"
FULLCERTDIR="$CERTROOTDIR/$CERTDIR"
# compare cksums first to decide whether certificates need to be copied
REM_CERT=$(ssh -i /volume1/homes/bco/.ssh/id_rsa bco@pandora sudo cksum /etc/letsencrypt/live/cloud.condrau.com/cert.pem | cut -d' ' -f 1)
REM_FULL=$(ssh -i /volume1/homes/bco/.ssh/id_rsa bco@pandora sudo cksum /etc/letsencrypt/live/cloud.condrau.com/fullchain.pem | cut -d' ' -f 1)
REM_PRIV=$(ssh -i /volume1/homes/bco/.ssh/id_rsa bco@pandora sudo cksum /etc/letsencrypt/live/cloud.condrau.com/privkey.pem | cut -d' ' -f 1)
LOC_CERT=$(cksum /usr/syno/etc/certificate/$CERTDIR/cert.pem | cut -d' ' -f 1)
LOC_FULL=$(cksum /usr/syno/etc/certificate/$CERTDIR/fullchain.pem | cut -d' ' -f 1)
LOC_PRIV=$(cksum /usr/syno/etc/certificate/$CERTDIR/privkey.pem | cut -d' ' -f 1)
if [[ $LOC_CERT -ne $REM_CERT ]] || [[ $LOC_FULL -ne $REM_FULL ]] || [[ $LOC_PRIV -ne $REM_PRIV ]]; then
# copy certificates from web server
sudo rsync -aPLe 'ssh -l bco -i /volume1/homes/bco/.ssh/id_rsa' --rsync-path='sudo rsync' pandora:/etc/letsencrypt/live/cloud.condrau.com/cert.pem $FULLCERTDIR/cert.pem
sudo rsync -aPLe 'ssh -l bco -i /volume1/homes/bco/.ssh/id_rsa' --rsync-path='sudo rsync' pandora:/etc/letsencrypt/live/cloud.condrau.com/fullchain.pem $FULLCERTDIR/fullchain.pem
sudo rsync -aPLe 'ssh -l bco -i /volume1/homes/bco/.ssh/id_rsa' --rsync-path='sudo rsync' pandora:/etc/letsencrypt/live/cloud.condrau.com/privkey.pem $FULLCERTDIR/privkey.pem
# find all subdirectories containing cert.pem files
PEMFILES=$(find $CERTROOTDIR -name cert.pem)
if [ ! -z "$PEMFILES" ]; then
for DIR in $PEMFILES; do
# replace the certificates, but never the ones in the _archive folders as those are all the unique certificates on the system.
if [[ $DIR != *"/_archive/"* ]]; then
rsync -avh "$FULLCERTDIR/" "$(dirname $DIR)/"
fi
done
fi
# reload
/usr/syno/sbin/synoservicectl --reload nginx
# update and restart all installed packages
PEMFILES=$(find $PACKAGECERTROOTDIR -name cert.pem)
if [ ! -z "$PEMFILES" ]; then
for DIR in $PEMFILES; do
#active directory has it's own certificate so we do not update that package
if [[ $DIR != *"/ActiveDirectoryServer/"* ]]; then
rsync -avh "$FULLCERTDIR/" "$(dirname $DIR)/"
/usr/syno/bin/synopkg restart $(echo $DIR | awk -F/ '{print $6}')
fi
done
fi
echo "certificates updated"
else
echo "nothing to update"
fi
exit 0
user ALL=(ALL) NOPASSWD: /usr/bin/cksum
sudo vim /etc/synoinfo.conf custom_login_title="hostname"
sudo vim /etc/sysconfig/network HOSTNAME=hostname
http://diskstation.name:5000/carddav/<user>/ # local network https://domain.name.tld:5001/carddav/<user>/ # internet
http://diskstation.name:5000/caldav/<user>/ # local network - Make sure you select the correct calendar as default for new appointments on your Android device https://domain.name.tld:5001/caldav/<user>/ # internet
Since DSM 6 the Synology NAS features a linux kernel, so Raid management can also be done on the command line. Since the Diskstation 212+ and 213+ do not support HGST Deskstar 10TB drives, I started to look into this to find a way how to make it work. Here is what I found:
# cat /proc/mdstat
Personalities : [linear] [raid0] [raid1] [raid10] [raid6] [raid5] [raid4]
md2 : active raid1 sda3[2]
5855800416 blocks super 1.2 [2/1] [U_]
md1 : active raid1 sda2[0] sdb2[1]
2097088 blocks [2/2] [UU]
md0 : active raid1 sda1[0] sdb1[1]
2490176 blocks [2/2] [UU]
unused devices: <none>
# mdadm --add /dev/md2 /dev/sdb3 # mdadm --detail --scan > /etc/mdadm.conf
cd /var/services/homes/user sudo chmod 700 . sudo chmod 700 .ssh sudo chmod 600 authorized_keys
rsync -av -e ssh sample.file user@machine:/var/services/homes/user/
Follow this guide: Configuration on Synology DSM6 Hosts
Follow this guide: Encrypted partitions/folders with auto-mount