pls groot genoeg

This commit is contained in:
2018-11-18 16:02:11 +01:00
commit 8206ede06a
253 changed files with 159550 additions and 0 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,406 @@
#!/bin/sh
########################
# http server checking #
########################
MAX_COUNT=5
MYDLINK_BASE="/mydlink"
PID_BASE="/tmp/run"
LOG_BASE="/tmp/md-log"
WATCHDOG_PID="$PID_BASE/mydlink-watch-dog.pid"
LOG_FILE="${LOG_BASE}/mydlink.log"
LOG_MAX_SZ=500000
DEV_CMD="mdb"
PORT_CMD="get http_port"
SPORT_CMD="get https_port"
UNIT_CHECK_T=5
HTTP_CHECK_T=300
STREAM_CGI=""
INFO_CGI="/common/info.cgi"
VIDEO_93x_CGI="/h264.cgi"
VIDEO_NIPCA_CGI="/video/ACVS-H264.cgi"
VIDEO_MJPG_CGI="/video/mjpg.cgi"
HTTP_BASE="http://127.0.0.1"
HTTPS_BASE="https://127.0.0.1"
HTTP_CMD="/mydlink/httpd_check"
# 30 days per check
CA_CHECK_PERIOD=30
CA_PID_FILE="ca-update.pid"
DST_SRV="http://ca-mgr.auto.mydlink.com/default"
PUB_KEY="public-key.pem"
CA_CHECK_FLAG="/tmp/.ca.check.flag"
TMP_CA_FILE="/tmp/.tmp.ca.file"
MD_CA_FILE="/tmp/.mydlink.ca-bundle.crt"
SYS_CA_FILE="/etc/ca-bundle.crt"
CA_FILE_NAME="ca-bundle.crt"
############################
# Message logging function #
############################
# $1: message
log() {
#echo "[`date +"%Y-%m-%d %H:%M:%S"`] $1" >> $LOG_FILE
echo "[`date +"%Y-%m-%d %H:%M:%S"`] $1" > /dev/null 2>&1
}
restart_httpd_93x() {
killall -q -9 alphapd
alphapd& > /dev/null 2>&1
}
restart_httpd_94x() {
if [ -f "/etc/rc.d/init.d/lighttpd.sh" ]; then
/etc/rc.d/init.d/lighttpd.sh stop
/etc/rc.d/init.d/lighttpd.sh start
fi
}
restart_httpd() {
# keep the way for restart httpd after wizard setup
if [ $DEV_CMD == "tdb" ]; then
restart_httpd_93x
restart_httpd_94x
else
# new defined way
mdb set reload_http_service 1 > /dev/null 2>&1
mdb apply > /dev/null 2>&1
fi
}
##########################
# Video CGI detection #
##########################
# $1: http port
detect_stream_cgi() {
stream_path=""
for path in "${VIDEO_NIPCA_CGI}" "${VIDEO_93x_CGI}" "${VIDEO_MJPG_CGI}"
do
code=`${HTTP_CMD} ${HTTP_BASE}:${1}${path}`
if [ "0${code}" = "0200" ] || [ "0${code}" = "0499" ]; then
stream_path=${path}
break;
fi
done
if [ "0$stream_path" = "0" ]; then
return 127
fi
log "video CGI '${stream_path}' detected."
echo $stream_path
}
##########################
# Device httpd checking #
##########################
#$1: http port
#$2: https port
#$3: stream_path
health_check_httpd() {
for url in "${HTTP_BASE}:${1}${INFO_CGI}" "${HTTPS_BASE}:${2}${INFO_CGI}" "${HTTP_BASE}:${1}${3}"
do
# cgi checking
count=0
while [ $count -lt ${MAX_COUNT} ]
do
code=`${HTTP_CMD} ${url}`
#log "${url} -> ${code}"
if [ "0${code}" != "0200" ] && [ "0${code}" != "0499" ]; then
count=`expr $count + 1`
sleep 3
else
break
fi
done
# retry and failed
if [ $count -ge ${MAX_COUNT} ]; then
log "Failed to access ${url}, restarting system services.."
restart_httpd
break;
fi
done
}
##########################
# mydlink agent checking #
##########################
# $1: process name
# $2: launch argument
check_alive() {
# check if the program exists or not
if [ ! -f "$MYDLINK_BASE/$1" ]; then
return
fi
# check if process exists by pid
pid="-1"
if [ -f "${PID_BASE}/${1}.pid" ]; then
pid=`cat ${PID_BASE}/${1}.pid`
fi
if [ -d "/proc/${pid}" ]; then
restart_cnt=0
return
fi
restart_cnt=`expr $restart_cnt + 1`
if [ "$restart_cnt" -gt 6 ]; then
log "reboot cause device agent can't startup"
reboot
fi
log "$1 is not running! ($pid)"
# kill all remaining processes and wait a moment
killall -q $1 2>/dev/null
sleep 1
# launch the process
# $MYDLINK_BASE/$1 $2 >> "${LOG_BASE}/${1}.log" 2>&1 &
$MYDLINK_BASE/$1 $2 > /dev/null 2>&1 &
pid="$!"
res="$?"
# keep the pid
echo $pid > "${PID_BASE}/${1}.pid"
log " - launch $1 ($pid, $res)"
}
# $1: folder
validate_log_size() {
count=0
size=0
for it in `ls -l "$1"`
do
count=`expr $count % 9 + 1`
if [ `expr $count % 5` -eq 0 ]; then
size=`expr $size + $it`
fi
done
if [ $size -ge $LOG_MAX_SZ ]; then
for file in `ls $1`
do
echo "[`date +"%Y-%m-%d %H:%M:%S"`] reset log" > "$1/$file"
done
log "Reset logs in folder '$1'"
fi
}
##########################
# Verify CA file #
##########################
ERR_NO_ERROR=0
ERR_NO_CHANGE=1
ERR_MDB_FAIL=2
# Touch last check time
set_checked() {
t=`date +"%s"`
c=`expr $t / 86400`
echo -n $c > $CA_CHECK_FLAG
}
# Check last check time
# $1: base dir
# return 0 if need to check
need_to_check() {
ret=0
# try to copy from system if no such file exists
if [ -f ${SYS_CA_FILE} ] && [ ! -f ${MD_CA_FILE} ]; then
cp ${SYS_CA_FILE} ${MD_CA_FILE}
fi
# check if meta-file exists. if not, the process shall be processing
if [ ! -f ${MD_CA_FILE} ] || [ ! -f $CA_CHECK_FLAG ]; then
return 0
fi
# check last access time
t=`date +"%s"`
curr=`expr $t / 86400`
last=`cat $CA_CHECK_FLAG`
next=`expr $last + $CA_CHECK_PERIOD`
if [ $curr -lt $next ]; then
ret=1
fi
return $ret
}
# CA Refresh Process
# $1 BASE
# RET result
refresh_ca() {
# check the executable
if [ ! -f $1/ca-refresh ]; then
has_ca_refresh=0
log "$1/ca-refresh not found."
return 127
fi
log "refreshing ca-list"
$1/ca-refresh "${DST_SRV}" "${MD_CA_FILE}" "${TMP_CA_FILE}" "$1/${PUB_KEY}"
ret=$?
if [ $ret -eq $ERR_NO_ERROR ]; then
set_checked
# update the new ca
cp -f ${TMP_CA_FILE} ${MD_CA_FILE}
# try to store to system
retry=0
while [ $retry -lt 2 ]
do
retry=`expr $retry + 1`
mdb set cainfo "${TMP_CA_FILE}"
if [ $? -eq 0 ]; then
return $ERR_NO_ERROR
fi
done
return $ERR_MDB_FAIL
elif [ $ret -eq $ERR_NO_CHANGE ]; then
set_checked
return $ERR_NO_ERROR
else
log "CA refresh failed ($ret)."
fi
return $ret
}
#=======================================================
# Get mydlink folder
if [ -f /mydlink/signalc ]; then
MYDLINK_BASE="/mydlink"
elif [ -f /opt/signalc ]; then
MYDLINK_BASE="/opt"
fi
HTTP_CMD="$MYDLINK_BASE/httpd_check"
# Set mydlink into PATH
export PATH="$MYDLINK_BASE:$PATH"
# Get model name
MODEL_NAME="Unknown"
HAS_MDB=`mdb get dev_model | grep "L" -c` 2>/dev/null
if [ "1" -eq "$HAS_MDB" ]; then
MODEL_NAME=`mdb get dev_model`
else
DEV_CMD="tdb"
PORT_CMD="get HTTPServer Port_num"
SPORT_CMD="get HTTPServer HTTPSPort_num"
wlan=`pibinfo Wireless` 2>/dev/null
if [ "$wlan" = "1" ]; then
MODEL_NAME=`tdb get System ModelW_ss`
else
MODEL_NAME=`tdb get System Model_ss`
fi
fi
# Get LAN interface
LAN_INT="br0"
HAS_BR0=`ifconfig | grep "br0" -c`
if [ "$HAS_BR0" -ge "1" ]; then
LAN_INT="br0"
else
LAN_INT="eth0"
fi
# Make neccessary folders
mkdir -p $PID_BASE
mkdir -p $LOG_BASE
# Manage the watchdog PID
wd_pid="-1"
if [ -f ${WATCHDOG_PID} ]; then
wd_pid=`cat ${WATCHDOG_PID}`
fi
if [ -d "/proc/$wd_pid" ] && [ "0$wd_pid" -ne "0$$" ]; then
log "Watchdog is running, exit."
exit 255
else
echo "$$" > "${WATCHDOG_PID}"
fi
# Check agent status
runs=0
restart_cnt=0
has_ca_refresh=1
PRIVACY_MODE=0
GET_PRIV_CMD="get privmode"
while [ 1 ]
do
curpid=`cat ${WATCHDOG_PID}`
if [ "0$$" -ne "0$curpid" ]; then
log "Unexpected pid (self: $$ cur: $curpid), exit!"
exit 255
fi
if [ "0$has_ca_refresh" = "01" ]; then
# check CA list
need_to_check $MYDLINK_BASE
if [ $? -eq 0 ]; then
refresh_ca $MYDLINK_BASE
fi
fi
# check running status of mydlink agents
check_alive dcp "-i $LAN_INT -m $MODEL_NAME"
check_alive signalc
# check if device in privacy mode
if [ "1" -eq "$HAS_MDB" ]; then
PRIVACY_MODE=`$DEV_CMD $GET_PRIV_CMD`
# check format
if [ $? -ne 0 ] || [ "1" -ne "$PRIVACY_MODE" ]; then
PRIVACY_MODE=0
fi
fi
# if device in privacy mode, we are not going to check httpd service
if [ "0" -eq "$PRIVACY_MODE" ]; then
# check web services
runs=`expr $runs + $UNIT_CHECK_T`
if [ $runs -ge $HTTP_CHECK_T ]; then
http_port=`$DEV_CMD $PORT_CMD`
https_port=`$DEV_CMD $SPORT_CMD`
if [ "0$STREAM_CGI" = "0" ]; then
STREAM_CGI=`detect_stream_cgi $http_port`
fi
health_check_httpd "$http_port" "$https_port" "$STREAM_CGI"
runs=0
fi
fi
sleep $UNIT_CHECK_T
done

View File

@@ -0,0 +1,87 @@
#!/bin/sh
die() {
echo $@
exit 1
}
showUsage() {
die "$0 {start|stop|restart}"
}
action=$1
end=$2
[ "$end" = "" ] && [ "$action" != "" ] || showUsage
# Get mydlink folder
DIR="/mydlink"
if [ -f "/opt/signalc" ]; then
DIR="/opt"
fi
export PATH=$DIR:$PATH
# Get LAN interface
LAN_INT="br0"
HAS_BR0=`ifconfig | grep "br0" -c`
if [ "$HAS_BR0" -ne "1" ]; then
LAN_INT="eth0"
fi
# Set run dir
PID_DIR="/tmp/run"
# remove provision to prevent misuse
rm /tmp/provision.conf
start() {
mkdir -p $PID_DIR
$DIR/mydlink-watch-dog.sh 2>&1 &
echo $! > $PID_DIR/mydlink-watch-dog.pid
echo opt.local start ok.
}
stop() {
pid="-1"
if [ -f $PID_DIR/mydlink-watch-dog.pid ]; then
pid=`cat $PID_DIR/mydlink-watch-dog.pid`
fi
if [ -d "/proc/$pid" ]; then
kill -9 $pid
fi
# delete all mydlink agents
killall -q -9 dcp signalc upnpc-ddns tsa
echo "opt.local stop ok."
}
startNoneL() {
$DIR/dcp -i $LAN_INT > /dev/null 2>&1 &
echo "opt.local(NoneL) start ok."
}
case $action in
start)
stop
start
;;
stop)
stop
;;
restart)
stop
start
;;
startNoneL)
stop
startNoneL
;;
*)
showUsage
;;
esac
exit 0

View File

@@ -0,0 +1,85 @@
-----BEGIN CERTIFICATE-----
MIIDjjCCAnagAwIBAgIQAzrx5qcRqaC7KGSxHQn65TANBgkqhkiG9w0BAQsFADBh
MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3
d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBH
MjAeFw0xMzA4MDExMjAwMDBaFw0zODAxMTUxMjAwMDBaMGExCzAJBgNVBAYTAlVT
MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5j
b20xIDAeBgNVBAMTF0RpZ2lDZXJ0IEdsb2JhbCBSb290IEcyMIIBIjANBgkqhkiG
9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuzfNNNx7a8myaJCtSnX/RrohCgiN9RlUyfuI
2/Ou8jqJkTx65qsGGmvPrC3oXgkkRLpimn7Wo6h+4FR1IAWsULecYxpsMNzaHxmx
1x7e/dfgy5SDN67sH0NO3Xss0r0upS/kqbitOtSZpLYl6ZtrAGCSYP9PIUkY92eQ
q2EGnI/yuum06ZIya7XzV+hdG82MHauVBJVJ8zUtluNJbd134/tJS7SsVQepj5Wz
tCO7TG1F8PapspUwtP1MVYwnSlcUfIKdzXOS0xZKBgyMUNGPHgm+F6HmIcr9g+UQ
vIOlCsRnKPZzFBQ9RnbDhxSJITRNrw9FDKZJobq7nMWxM4MphQIDAQABo0IwQDAP
BgNVHRMBAf8EBTADAQH/MA4GA1UdDwEB/wQEAwIBhjAdBgNVHQ4EFgQUTiJUIBiV
5uNu5g/6+rkS7Q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sBUnuId9Mcj8e6uYi1agnnc+gRQKfRzMpijS3ljwumUNKoUMMo6vWrJYeK
mpYcqWe4PwzV9/lSEy/CG9VwcPCPwBLKBsua4dnKM3p31vjsufFoREJIE9LAwqSu
XmD+tqYF/LTdB1kC1FkYmGP1pWPgkAx9XbIGevOF6uvUA65ehD5f/xXtabz5OTZy
dc93Uk3zyZAsuT3lySNTPx8kmCFcB5kpvcY67Oduhjprl3RjM71oGDHweI12v/ye
jl0qhqdNkNwnGjkCAwEAAaNFMEMwHQYDVR0OBBYEFOWdWTCCR1jMrPoIVDaGezq1
BE3wMBIGA1UdEwEB/wQIMAYBAf8CAQMwDgYDVR0PAQH/BAQDAgEGMA0GCSqGSIb3
DQEBBQUAA4IBAQCFDF2O5G9RaEIFoN27TyclhAO992T9Ldcw46QQF+vaKSm2eT92
9hkTI7gQCvlYpNRhcL0EYWoSihfVCr3FvDB81ukMJY2GQE/szKN+OMY3EU/t3Wgx
jkzSswF07r51XgdIGn9w/xZchMB5hbgF/X++ZRGjD8ACtPhSNzkE1akxehi/oCr0
Epn3o0WC4zxe9Z2etciefC7IpJ5OCBRLbf1wbWsaY71k5h+3zvDyny67G7fyUIhz
ksLi4xaNmjICq44Y3ekQEe5+NauQrz4wlHrQMz2nZQ/1/I6eYs9HRCwBXbsdtTLS
R9I4LtD+gdwyah617jzV/OeBHRnDJELqYzmp
-----END CERTIFICATE-----
Verisign Class 3 Public Primary Certification Authority
-----BEGIN CERTIFICATE-----
MIICPDCCAaUCEHC65B0Q2Sk0tjjKewPMur8wDQYJKoZIhvcNAQECBQAwXzELMAkG
A1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMTcwNQYDVQQLEy5DbGFz
cyAzIFB1YmxpYyBQcmltYXJ5IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MB4XDTk2
MDEyOTAwMDAwMFoXDTI4MDgwMTIzNTk1OVowXzELMAkGA1UEBhMCVVMxFzAVBgNV
BAoTDlZlcmlTaWduLCBJbmMuMTcwNQYDVQQLEy5DbGFzcyAzIFB1YmxpYyBQcmlt
YXJ5IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MIGfMA0GCSqGSIb3DQEBAQUAA4GN
ADCBiQKBgQDJXFme8huKARS0EN8EQNvjV69qRUCPhAwL0TPZ2RHP7gJYHyX3KqhE
BarsAx94f56TuZoAqiN91qyFomNFx3InzPRMxnVx0jnvT0Lwdd8KkMaOIG+YD/is
I19wKTakyYbnsZogy1Olhec9vn2a/iRFM9x2Fe0PonFkTGUugWhFpwIDAQABMA0G
CSqGSIb3DQEBAgUAA4GBALtMEivPLCYATxQT3ab7/AoRhIzzKBxnki98tsX63/Do
lbwdj2wsqFHMc9ikwFPwTtYmwHYBV4GSXiHx0bH/59AhWM1pF+NEHJwZRDmJXNyc
AA9WjQKZ7aKQRUzkuxCkPfAyAw7xzvjoyVGM5mKf5p/AfbdynMk2OmufTqj/ZA1k
-----END CERTIFICATE-----

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1 @@
VERSION=2.2.0-b33n