Skip to content

Commit

Permalink
feat:添加远程日志
Browse files Browse the repository at this point in the history
  • Loading branch information
zzzzzhy committed Oct 27, 2023
1 parent fc7fca9 commit ac5334c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
4 changes: 2 additions & 2 deletions hi.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ func hiExecCommand(br *broker, cmdr *hi.CmdrModel, callurl string) string {
cmdConfig := hi.Base64Encode(cmdr.Cmd)

// cmd := fmt.Sprintf("curl -sSL -4 %s/hi/other/cmdr/%s | bash", br.cfg.HiApiUrl, cmdr.Token)
cmd := fmt.Sprintf("echo %s | base64 -d > /tmp/%s && cat /tmp/%s>>/var/log/exec.log; bash -x /tmp/%s 2>>/var/log/exec.log;if [ \"$?\" != \"0\" ]; then tail -n5 /var/log/exec.log; error ;else rm /tmp/%s;fi", cmdConfig, token, token, token, token)
cmd := fmt.Sprintf("echo %s | base64 -d > /tmp/%s && bash /tmp/%s && rm -f /tmp/%s", cmdConfig, token, token, token)
params := []string{"-c", cmd}

data := make([]string, 5)
Expand Down Expand Up @@ -464,7 +464,7 @@ func hiExecRequest(br *broker, c *gin.Context, cmdr *hi.CmdrModel) {
cmdConfig := hi.Base64Encode(cmdr.Cmd)

// cmd := fmt.Sprintf("curl -sSL -4 %s/hi/other/cmdr/%s | bash", br.cfg.HiApiUrl, cmdr.Token)
cmd := fmt.Sprintf("echo %s | base64 -d > /tmp/%s && cat /tmp/%s>>/var/log/exec.log; bash -x /tmp/%s 2>>/var/log/exec.log;if [ \"$?\" != \"0\" ]; then tail -n5 /var/log/exec.log ; error ;else rm /tmp/%s;fi", cmdConfig, token, token, token, token)
cmd := fmt.Sprintf("echo %s | base64 -d > /tmp/%s && bash /tmp/%s && rm -f /tmp/%s", cmdConfig, token, token, token)
params := []string{"-c", cmd}

data := make([]string, 5)
Expand Down
30 changes: 13 additions & 17 deletions hi/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -2039,12 +2039,6 @@ set_bypass_host() {
local host="$1"
local thName="hi-th-api"
local domainFile="/etc/dnsmasq.d/domain_hicloud.conf"
#---next upgrade remove----
local byId=99
rm -f /etc/hotplug.d/iface/${byId}-hi-bypass-route
rm -f /etc/hotplug.d/iface/${byId}-hi-bypass-dnsmasq
rm -f /etc/hotplug.d/firewall/${byId}-hi-bypass-iptables
#---next upgrade remove----
local old2="$(cat ${domainFile} | grep "ipset=/${host}/")"
local old1="$(cat /etc/dnsmasq.conf | grep "${host}")"
local gatewayIP=$(ip route show 1/0 | head -n1 | sed -e 's/^default//' | awk '{print $2}' | awk -F. '$1<=255&&$2<=255&&$3<=255&&$4<=255{print $1"."$2"."$3"."$4}')
Expand All @@ -2061,6 +2055,8 @@ set_bypass_host() {
fi
sed -i "/#${thName}#/d" /etc/dnsmasq.conf
sed -i "/${thName}/d" ${domainFile}
ip route add 8.8.8.8 via ${gatewayIP}
ip route add 154.207.81.170 via ${gatewayIP}
timeout -t 2 pwd 1>/dev/null 2>&1
if [ "$?" = "0" ]; then
timeout -t 2 nslookup ${host} ${gatewayIP}
Expand All @@ -2069,11 +2065,11 @@ set_bypass_host() {
fi
runflag=$(echo $?)
if [ "$runflag" != 0 ]; then
ip route add 8.8.8.8 via ${gatewayIP}
echo "server=/${host}/8.8.8.8 #${thName}#" >> /etc/dnsmasq.conf
else
echo "server=/${host}/${gatewayIP} #${thName}#" >> /etc/dnsmasq.conf
fi
charA="$(cat ${domainFile} | grep -n "ipset=/${host}/")"
if [ -z "$charA" ]; then
echo "ipset=/${host}/hi-th-rtty #${thName}#" >> ${domainFile}
Expand Down Expand Up @@ -2118,9 +2114,9 @@ EOB
mkdir -p /etc/hotplug.d/dhcp/
cat >/etc/hotplug.d/dhcp/99-hi-dhcp<<EOF
[ "\$ACTION" = "add" ] && {
if [ "\$ACTION" = "add" ]; then
flock -xn /tmp/hi-clients.lock -c /usr/sbin/hi-clients
}
fi
EOF
chmod +x /etc/hotplug.d/dhcp/99-hi-dhcp
Expand Down Expand Up @@ -2732,16 +2728,19 @@ fi
const RouterLogUpload = string(`
if [ -z "$(uci get system.@system[0].log_file)" ] || [ "$1" == "edit" ]; then
uci set system.@system[0].log_file='/var/log/syslogbk.log'
uci set system.@system[0].log_buffer_size='128'
uci set system.@system[0].log_buffer_size='256'
uci set system.@system[0].log_size='5120'
uci set system.@system[0].log_ip='154.207.81.170'
uci set system.@system[0].log_ip='514'
uci set system.@system[0].log_hostname=$(uci get rtty.general.id)
uci commit system
/etc/init.d/log restart
exit 0
fi
cat >/tmp/net_ping_detected<<EOF
node_host={{.nodeHost}}
import_ip=\$(uci get wireguard.@peers[0].end_point|awk -F':' '{print \$1}')
echo "#------------ping start--------------">/var/log/ping.log
echo "#------------ping start--------------$(date)">/var/log/ping.log
oping -c5 \$import_ip \$node_host 8.8.8.8 >>/var/log/ping.log
if [ -n "\$(cat /var/log/ping.log|grep 'timeout')" ]; then
echo "#------------ping end--------------">>/var/log/ping.log
Expand All @@ -2757,12 +2756,9 @@ fi
host="{{.logUrl}}/$(uci get rtty.general.id)$(_sign)"
logread >/var/log/syslog.log
dmesg >/var/log/dmesg.log
curl -F file=@/var/log/dmesg.log "$host""&log_type=dmesg"
res=$(curl -F file=@/var/log/syslog.log "$host""&log_type=sys")
if [ "$res" == "success" ]; then
rm /var/log/syslog.log
/etc/init.d/log restart
fi
curl -sF file=@/var/log/dmesg.log "$host""&log_type=dmesg"
curl -sF file=@/var/log/syslog.log "$host""&log_type=sys"
if [ -e "/var/log/exec.log" ]; then
curl -F file=@/var/log/exec.log "$host""&log_type=exec"
[ $? == 0 ] && rm /var/log/exec.log
Expand Down

0 comments on commit ac5334c

Please sign in to comment.