This commit is contained in:
2024-10-14 00:08:40 +02:00
parent dbfba56f66
commit 1462d52e13
4572 changed files with 2658864 additions and 0 deletions

View File

@@ -0,0 +1,95 @@
#!/usr/bin/perl
use feature "switch";
$USER="andre";
$PASS="mesh-assort2";
$HOST="power.andregeissler.de";
$DEVICE="Test";
$DEVICEIP="192.168.100.7";
$DEVICEUSER="admin";
$DEVICEPASS="admin";
$cmd="curl -s http://$USER:$PASS\@$HOST/$DEVICE/timer > /scripts/mFi/timer";
`$cmd`;
$cmd="dos2unix /scripts/mFi/timer";
`$cmd`;
open CTRL, "</scripts/mFi/timer";
@TIMER=<CTRL>;
close CTRL;
my $startfound=0;
my $endefound=0;
foreach (@TIMER) {
$startfound=1 if (/###START/);
$endefound=1 if (/###ENDE/);
}
exit if ($startfound == 0 || $endefound == 0);
@ports=();
@comms=();
$str="";
my $time=`date +"%H:%M"`;
chomp $time;
print "\ntime ($time)\n";
$cmd="curl -s http://$USER:$PASS\@$HOST/$DEVICE/api.php?action=getstatus";
print "get state via ($cmd)\n";
$result=`$cmd`;
chomp $result;
print "result ($result)\n";
next if ( $result eq "" );
@ports=split /;/, $result;
foreach $port (@ports) {
($dev, $state) = $port =~ /^([0-9]+):'(.*)'$/;
$ch="";
print "Check $dev\n";
$f=0;
foreach (@TIMER) {
chomp;
print ".";
if ($_ =~ /^$dev,off,$time$/) {
$f=1;
print "$dev off at $time\n";
$comm ="echo 0 > /dev/output$dev";
} elsif ($_ =~ /^$dev,on,$time$/) {
$f=1;
print "$dev on at $time\n";
$comm ="echo 1 > /dev/output$dev";
$ch="on";
} elsif ($_ =~ /^$dev,off,always$/) {
$f=1;
print "$dev always off\n";
$comm ="echo 0 > /dev/output$dev";
} elsif ($_ =~ /^$dev,on,always$/) {
$f=1;
print "$dev always on\n";
$comm ="echo 1 > /dev/output$dev";
$ch="on";
}
}
if ($f == 0) {
if ($state eq "checked") {
print "$dev on\n";
$comm="echo 1 > /dev/output$dev";
$ch="on";
} else {
print "$dev off\n";
$comm="echo 0 > /dev/output$dev";
}
}
$str .= "&oos$dev=$ch";
push(@comms, $comm);
}
$com=join(";", @comms);
$cmd="curl -s 'http://$USER:$PASS\@$HOST/$DEVICE/api.php?action=setstatus$str'";
print "set state via ($cmd)\n";
`$cmd`;
$cmd="expect /scripts/mFi/port.exp $DEVICEUSER $DEVICEIP $DEVICEPASS '$com'";
print "send commands to device\n";
`$cmd`;

View File

@@ -0,0 +1,18 @@
#!/bin/bash
export USER="andre"
export PASS="mesh-assort2"
export HOST="power.andregeissler.de"
export DEVICE="Test"
rm /scripts/mFi/cron
curl -s http://$USER:$PASS@$HOST/$DEVICE/timer > /scripts/mFi/cron_input
dos2unix /scripts/mFi/cron_input > /dev/null 2>&1
cat /scripts/mFi/cron_input | egrep "^ct" | awk '{print $2 " " $3 " " $4 " " $5 " " $6 " root /scripts/mFi/switch_port.sh " $7 " " $8 " >/dev/null 2>&1"}' >> /scripts/mFi/cron
rm /scripts/mFi/cron_input
#export CRON=`cat /scripts/mFi/cron`
#sed -s -i "/####mFi####.*####mFi####/####mFi\n$CRON\n####mFi####/m" /var/spool/cron/crontabs/root

View File

@@ -0,0 +1,10 @@
05 05 * * 1-5 root /scripts/mFi/switch_port.sh 3 on >/dev/null 2>&1
30 05 * * 1-5 root /scripts/mFi/switch_port.sh 3 off >/dev/null 2>&1
30 15 * * 1-5 root /scripts/mFi/switch_port.sh 3 on >/dev/null 2>&1
10 16 * * 1-5 root /scripts/mFi/switch_port.sh 3 off >/dev/null 2>&1
06 05 * * 1-5 root /scripts/mFi/switch_port.sh 4 on >/dev/null 2>&1
31 05 * * 1-5 root /scripts/mFi/switch_port.sh 4 off >/dev/null 2>&1
31 15 * * 1-5 root /scripts/mFi/switch_port.sh 4 on >/dev/null 2>&1
31 16 * * 1-5 root /scripts/mFi/switch_port.sh 4 off >/dev/null 2>&1
00 00 * * * root /scripts/mFi/switch_port.sh 6 off >/dev/null 2>&1
01 00 * * * root /scripts/mFi/switch_port.sh 6 on >/dev/null 2>&1

View File

@@ -0,0 +1,10 @@
05 05 * * 1-5 root /scripts/mFi/switch_port.sh 3 on >/dev/null 2>&1
30 05 * * 1-5 root /scripts/mFi/switch_port.sh 3 off >/dev/null 2>&1
30 15 * * 1-5 root /scripts/mFi/switch_port.sh 3 on >/dev/null 2>&1
10 16 * * 1-5 root /scripts/mFi/switch_port.sh 3 off >/dev/null 2>&1
06 05 * * 1-5 root /scripts/mFi/switch_port.sh 4 on >/dev/null 2>&1
31 05 * * 1-5 root /scripts/mFi/switch_port.sh 4 off >/dev/null 2>&1
31 15 * * 1-5 root /scripts/mFi/switch_port.sh 4 on >/dev/null 2>&1
31 16 * * 1-5 root /scripts/mFi/switch_port.sh 4 off >/dev/null 2>&1
00 00 * * * root /scripts/mFi/switch_port.sh 6 off >/dev/null 2>&1
01 00 * * * root /scripts/mFi/switch_port.sh 6 on >/dev/null 2>&1

View File

@@ -0,0 +1,8 @@
# ubiqiti mfi power steuerung
#3 * * * * /scripts/mFi/create_cron.sh > /dev/null 2>&1
#* * * * * /usr/bin/perl /scripts/mFi/control.pl > /dev/null 2>&1
#* * * * * sleep 15; /usr/bin/perl /scripts/mFi/control.pl > /dev/null 2>&1
#* * * * * sleep 30; /usr/bin/perl /scripts/mFi/control.pl > /dev/null 2>&1
#* * * * * sleep 45; /usr/bin/perl /scripts/mFi/control.pl > /dev/null 2>&1

View File

@@ -0,0 +1,16 @@
#!/usr/bin/expect -f
set timeout 10
set user [lindex $argv 0]
set host [lindex $argv 1]
set pass [lindex $argv 2]
set cmd [lindex $argv 3]
spawn ssh $user@$host -oKexAlgorithms=+diffie-hellman-group1-sha1 -caes256-cbc
expect "*?assword:*"
send -- "$pass\r"
sleep 5
send -- "$cmd\r"
sleep 2
send -- "exit\r"
expect eof

View File

@@ -0,0 +1,133 @@
#!/bin/bash
sleep 5
export USER="andre"
export PASS="mesh-assort2"
export HOST="power.andregeissler.de"
export DEVICE="Test"
export DEVICEIP="192.168.100.7"
export DEVICEUSER="admin"
export DEVICEPASS="admin"
export STATUS=`curl -s 'http://andre:mesh-assort2@power.andregeissler.de/Test/api.php?action=getstatus'`
s1=`echo $STATUS | awk -F';' '{print $1}' | grep -o checked`
s2=`echo $STATUS | awk -F';' '{print $2}' | grep -o checked`
s3=`echo $STATUS | awk -F';' '{print $3}' | grep -o checked`
s4=`echo $STATUS | awk -F';' '{print $4}' | grep -o checked`
s5=`echo $STATUS | awk -F';' '{print $5}' | grep -o checked`
s6=`echo $STATUS | awk -F';' '{print $6}' | grep -o checked`
if [ "$s1" == "checked" ]
then
s1=on
fi
if [ "$s2" == "checked" ]
then
s2=on
fi
if [ "$s3" == "checked" ]
then
s3=on
fi
if [ "$s4" == "checked" ]
then
s4=on
fi
if [ "$s5" == "checked" ]
then
s5=on
fi
if [ "$s6" == "checked" ]
then
s6=on
fi
if [ "$1" == "1" ]
then
if [ "$2" == "off" ]
then
val=""
comm="echo 0 > /dev/output1"
else
val="on"
comm="echo 1 > /dev/output1"
fi
s1=$val
fi
if [ "$1" == "2" ]
then
if [ "$2" == "off" ]
then
val=""
comm="echo 0 > /dev/output2"
else
val="on"
comm="echo 1 > /dev/output2"
fi
s2=$val
fi
if [ "$1" == "3" ]
then
if [ "$2" == "off" ]
then
val=""
comm="echo 0 > /dev/output3"
else
val="on"
comm="echo 1 > /dev/output3"
fi
s3=$val
fi
if [ "$1" == "4" ]
then
if [ "$2" == "off" ]
then
val=""
comm="echo 0 > /dev/output4"
else
val="on"
comm="echo 1 > /dev/output4"
fi
s4=$val
fi
if [ "$1" == "5" ]
then
if [ "$2" == "off" ]
then
val=""
comm="echo 0 > /dev/output5"
else
val="on"
comm="echo 1 > /dev/output5"
fi
s5=$val
fi
if [ "$1" == "6" ]
then
if [ "$2" == "off" ]
then
val=""
comm="echo 0 > /dev/output6"
else
val="on"
comm="echo 1 > /dev/output6"
fi
s6=$val
fi
str="&oos1=$s1&oos2=$s2&oos3=$s3&oos4=$s4&oos5=$s5&oos6=$s6"
export cmd="/usr/bin/curl -s 'http://andre:mesh-assort2@power.andregeissler.de/Test/api.php?action=setstatus$str'"
/bin/bash -c "$cmd"
expect /scripts/mFi/port.exp $DEVICEUSER $DEVICEIP $DEVICEPASS '$comm'

View File

@@ -0,0 +1,46 @@
###START
# Ausgang,on|off,hh:mm|always
# ct min hour dom month dow port on|off
# ct 25 07 * * 1-5 3 on
# auto on/off Frühschicht
ct 05 05 * * 1-5 3 on
ct 30 05 * * 1-5 3 off
ct 30 15 * * 1-5 3 on
ct 10 16 * * 1-5 3 off
ct 06 05 * * 1-5 4 on
ct 31 05 * * 1-5 4 off
ct 31 15 * * 1-5 4 on
ct 31 16 * * 1-5 4 off
# auto on/off Mittelschicht
#ct 25 07 * * 1-5 3 on
#ct 40 07 * * 1-5 3 off
#ct 40 17 * * 1-5 3 on
#ct 10 18 * * 1-5 3 off
#ct 26 07 * * 1-5 4 on
#ct 41 07 * * 1-5 4 off
#ct 41 17 * * 1-5 4 on
#ct 31 18 * * 1-5 4 off
# auto on/off Spätschicht
#ct 00 11 * * 1-5 3 on
#ct 30 11 * * 1-5 3 off
#ct 40 21 * * 1-5 3 on
#ct 10 22 * * 1-5 3 off
#ct 01 11 * * 1-5 4 on
#ct 31 11 * * 1-5 4 off
#ct 41 21 * * 1-5 4 on
#ct 31 22 * * 1-5 4 off
########################
1,on,always
5,on,always
ct 00 00 * * * 6 off
ct 01 00 * * * 6 on
###ENDE