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,64 @@
pwr
mysql tabellen
device
id name ports
ports
id dev_id nr descr state
webpage index.pl
table
tr
td
dev1
/td
/tr
tr /tr
tr
td
dev2
td
/tr
/table
dev1 dev2
table
tr
td
nr
/td
td
desc
/td
td
state
/td
/tr
tr
...
/tr
/table
getstatus get.pl
?dev=name&get=all
?dev=name&get=all
?dev=name&get=1 .... 6
${'dev_name'}->{id => 'id',
ports => '6',
@port
}
$port[0]=state
...

View File

@@ -0,0 +1,39 @@
#!/usr/bin/perl
#Kommt auf LSH zum Einsatz
use DBI;
use strict;
# Variable für SQL Befehle
my $sql;
# DB Parameter
my ($db_user, $db_name, $db_pass, $db_host) = ('1_mfi', '1_mfi', 'K01v1kk0!', 'panel.agserver.de');
# DB connect
my $dbh = DBI->connect("DBI:mysql:database=$db_name;host=$db_host", $db_user, $db_pass) or die "Cannot connect to DB\n";
# Cron Einträge in DB?
$sql = "select * from cron";
my $rows = $dbh->do("$sql");
if ($rows == 0) {
print "nothing to do\n";
exit 0;
}
open FILEHANDLE, ">/scripts/mFi2/cron_db";
$sql = "select id, min, hour, dom, mon, dow, port_id, state, active from cron";
my $rows = $dbh->selectall_arrayref("$sql");
foreach (@$rows) {
my $row=$_;
my $state="on" if ($row->[7] == 1);
$state="off" if ($row->[7] == 0);
my $rem='' if ($row->[8] == 1);
$rem='#' if ($row->[8] == 0);
printf FILEHANDLE "# id %5d\n", $row->[0];
printf FILEHANDLE "%1s %5s %5s %5s %5s %5s root /scripts/mFi2/write_queue.pl %3s %5s > /dev/null 2>&1\n", $rem, $row->[1], $row->[2], $row->[3], $row->[4], $row->[5], $row->[6], $state;
printf "%1s %5s %5s %5s %5s %5s root /scripts/mFi2/write_queue.pl %3s %5s > /dev/null 2>&1\n", $rem, $row->[1], $row->[2], $row->[3], $row->[4], $row->[5], $row->[6], $state;
}

11
Perl control mFi/alt/cron Normal file
View File

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

View File

@@ -0,0 +1,56 @@
# id 1
5 5 * * 1-5 root /scripts/mFi2/write_queue.pl 3 on > /dev/null 2>&1
# id 2
30 5 * * 1-5 root /scripts/mFi2/write_queue.pl 3 off > /dev/null 2>&1
# id 3
30 15 * * 1-5 root /scripts/mFi2/write_queue.pl 3 on > /dev/null 2>&1
# id 4
10 16 * * 1-5 root /scripts/mFi2/write_queue.pl 3 off > /dev/null 2>&1
# id 5
5 5 * * 1-5 root /scripts/mFi2/write_queue.pl 4 on > /dev/null 2>&1
# id 6
30 5 * * 1-5 root /scripts/mFi2/write_queue.pl 4 off > /dev/null 2>&1
# id 7
30 15 * * 1-5 root /scripts/mFi2/write_queue.pl 4 on > /dev/null 2>&1
# id 8
10 16 * * 1-5 root /scripts/mFi2/write_queue.pl 4 off > /dev/null 2>&1
# id 9
# 0 0 * * * root /scripts/mFi2/write_queue.pl 6 off > /dev/null 2>&1
# id 10
# 1 0 * * * root /scripts/mFi2/write_queue.pl 6 on > /dev/null 2>&1
# id 11
# * * * * * root /scripts/mFi2/write_queue.pl 1 on > /dev/null 2>&1
# id 12
# * * * * * root /scripts/mFi2/write_queue.pl 6 on > /dev/null 2>&1
# id 13
# 5 7 * * 1-5 root /scripts/mFi2/write_queue.pl 3 on > /dev/null 2>&1
# id 14
# 30 7 * * 1-5 root /scripts/mFi2/write_queue.pl 3 off > /dev/null 2>&1
# id 15
# 30 17 * * 1-5 root /scripts/mFi2/write_queue.pl 3 on > /dev/null 2>&1
# id 16
# 10 18 * * 1-5 root /scripts/mFi2/write_queue.pl 3 off > /dev/null 2>&1
# id 17
# 5 7 * * 1-5 root /scripts/mFi2/write_queue.pl 4 on > /dev/null 2>&1
# id 18
# 30 7 * * 1-5 root /scripts/mFi2/write_queue.pl 4 off > /dev/null 2>&1
# id 19
# 30 17 * * 1-5 root /scripts/mFi2/write_queue.pl 4 on > /dev/null 2>&1
# id 20
# 10 18 * * 1-5 root /scripts/mFi2/write_queue.pl 4 off > /dev/null 2>&1
# id 21
# 15 11 * * 1-5 root /scripts/mFi2/write_queue.pl 3 on > /dev/null 2>&1
# id 22
# 30 11 * * 1-5 root /scripts/mFi2/write_queue.pl 3 off > /dev/null 2>&1
# id 23
# 30 21 * * 1-5 root /scripts/mFi2/write_queue.pl 3 on > /dev/null 2>&1
# id 24
# 10 22 * * 1-5 root /scripts/mFi2/write_queue.pl 3 off > /dev/null 2>&1
# id 25
# 15 11 * * 1-5 root /scripts/mFi2/write_queue.pl 4 on > /dev/null 2>&1
# id 26
# 30 11 * * 1-5 root /scripts/mFi2/write_queue.pl 4 off > /dev/null 2>&1
# id 27
# 30 21 * * 1-5 root /scripts/mFi2/write_queue.pl 4 on > /dev/null 2>&1
# id 28
# 10 22 * * 1-5 root /scripts/mFi2/write_queue.pl 4 off > /dev/null 2>&1

View File

@@ -0,0 +1,37 @@
#!/usr/bin/perl
use DBI;
use strict;
my ($db_user, $db_name, $db_pass, $db_host) = ('1_mfi', '1_mfi', 'K01v1kk0!', 'panel.agserver.de');
my $dbh = DBI->connect("DBI:mysql:database=$db_name;host=$db_host", $db_user, $db_pass) or die "Cannot connect to DB\n";
#my $rows = $dbh->do("select * from device") or die "$dbh->errstr";
my $sql;
#my $sql="select id, name, ports from device";
#my @row_ary = $dbh->selectrow_array("$sql");
#my $ary_ref1 = $dbh->selectrow_arrayref("$sql");
#my $hash_ref1 = $dbh->selectrow_hashref("$sql");
#my $ary_ref2 = $dbh->selectall_arrayref("$sql");
#my $hash_ref2 = $dbh->selectall_hashref("$sql", 'id');
$sql = "select * from device";
my $res_ref_device = $dbh->selectall_arrayref("$sql");
my $res_ref_port;
print "<table>
<tr><td colspan=2>Device</td><td>Ports</td></tr>\n";
foreach (@$res_ref_device) {
print "<tr><td colspan=2>$_->[1] (ID: $_->[0])</td><td>$_->[2]</td></tr>\n";
$sql = "select id, nr, descr, state from port where dev_id = '$_->[0]'";
$res_ref_port = $dbh->selectall_arrayref("$sql");
print "<tr><td>Port</td><td>Description</td><td>State</td></tr>\n";
foreach (@$res_ref_port) {
print "<tr><td>$_->[1] (ID $_->[0])</td><td>$_->[2]</td><td>$_->[3]</td></tr>\n";
}
}
print "</table>";
exit 0;

View File

@@ -0,0 +1,81 @@
#!/usr/bin/perl
use strict;
use Net::MySQL;
my $mysql = Net::MySQL->new(
hostname => 'panel.agserver.de', # Default use UNIX socket
database => '1_mfi',
user => '1_mfi',
password => 'K01v1kk0!'
);
# INSERT example
#$mysql->query(q{
# INSERT INTO tablename (first, next) VALUES ('Hello', 'World')
#});
#printf "Affected row: %d\n", $mysql->get_affected_rows_length;
# SELECT example
$mysql->query(q{SELECT count(*) FROM device});
my $record_set = $mysql->create_record_iterator;
my $DEVcount=0;
while (my $record = $record_set->each) {
# printf "First column: %s Next column: %s\n",
# $record->[0], $record->[1];
$DEVcount = $record->[0];
}
#print "<table>\n";
#for (my $dev=1; $dev<=$DEVcount; $dev++) {
# print " <tr>
# <td>
#";
#}
my $DEVname;
my $DEVports;
$mysql->query(q{SELECT name,ports FROM device});
my $record_set = $mysql->create_record_iterator;
while (my $record = $record_set->each) {
$DEVname=$record->[0]; $DEVports=$record->[1];
print " <table>
<tr>
<td colspan=3>
$DEVname $DEVports
</td>
</tr>\n";
for (my $ports=0; $ports < $DEVports; $ports++) {
print " <tr>
<td>
Portname
</td>
<td>
PortDescr
</td>
<td>
PortState
</td>
</tr>\n";
}
print "
</table>\n";
}
print " </td>
</tr>
<tr>
</tr>
";
print "</table>\n";
$mysql->close;

View File

@@ -0,0 +1,78 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de-DE" lang="de-DE">
<head>
<title>mfi.andregeissler.de</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="refresh" content="30">
<style>
DIV.table
{
display:table;
width:100%;
}
FORM.tr, DIV.tr
{
display:table-row;
}
SPAN.td
{
display:table-cell;
width:33%;
border-bottom-width:1px;
border-bottom-style:solid;
}
</style>
</head>
<body>
<div class=table>
<form class=tr method=post action=index.php>
<span class=td>Test</span>
</form>
<form class=tr method=post action=index.php>
<input type=hidden name=id value=1>
<span class=td>1</span><span class=td><input type=text name=descr value='Port 1'></span><span class=td><input type=text name=state value=1></span><span class=td><input type=submit value=speichern /></span>
</form>
<form class=tr method=post action=index.php>
<input type=hidden name=id value=2>
<span class=td>2</span><span class=td><input type=text name=descr value='Port 2'></span><span class=td><input type=text name=state value=0></span><span class=td><input type=submit value=speichern /></span>
</form>
<form class=tr method=post action=index.php>
<input type=hidden name=id value=3>
<span class=td>3</span><span class=td><input type=text name=descr value='Port 3'></span><span class=td><input type=text name=state value=1></span><span class=td><input type=submit value=speichern /></span>
</form>
<form class=tr method=post action=index.php>
<input type=hidden name=id value=4>
<span class=td>4</span><span class=td><input type=text name=descr value='Port 4'></span><span class=td><input type=text name=state value=0></span><span class=td><input type=submit value=speichern /></span>
</form>
<form class=tr method=post action=index.php>
<input type=hidden name=id value=5>
<span class=td>5</span><span class=td><input type=text name=descr value='Port 5'></span><span class=td><input type=text name=state value=1></span><span class=td><input type=submit value=speichern /></span>
</form>
<form class=tr method=post action=index.php>
<input type=hidden name=id value=6>
<span class=td>6</span><span class=td><input type=text name=descr value='Port 6'></span><span class=td><input type=text name=state value=0></span><span class=td><input type=submit value=speichern /></span>
</form>
</div>
<br>
<div class=table>
<form class=tr method=post action=index.php>
<span class=td>DEV2</span>
</form>
<form class=tr method=post action=index.php>
<input type=hidden name=id value=7>
<span class=td>1</span><span class=td><input type=text name=descr value='Port 1'></span><span class=td><input type=text name=state value=1></span><span class=td><input type=submit value=speichern /></span>
</form>
<form class=tr method=post action=index.php>
<input type=hidden name=id value=8>
<span class=td>2</span><span class=td><input type=text name=descr value='Port 2'></span><span class=td><input type=text name=state value=0></span><span class=td><input type=submit value=speichern /></span>
</form>
<form class=tr method=post action=index.php>
<input type=hidden name=id value=9>
<span class=td>3</span><span class=td><input type=text name=descr value='Port 3'></span><span class=td><input type=text name=state value=1></span><span class=td><input type=submit value=speichern /></span>
</form>
</div>
<br>
</body>
</html>

View File

@@ -0,0 +1,151 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de-DE" lang="de-DE">
<head>
<title>mfi.andregeissler.de</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="refresh" content="10; URL=https://mfi.andregeissler.de/">
<style>
INPUT {
font-size:20px;
}
SPAN.tdh {
font-size:25px;
}
DIV.table
{
display:table;
width:650px;
}
FORM.tr, DIV.tr
{
display:table-row;
}
SPAN.td1
{
display:table-cell;
width:10%;
vertical-align:middle;
font-size:20px;
}
SPAN.td2
{
display:table-cell;
width:50%;
vertical-align:middle;
font-size:20px;
}
SPAN.td3
{
display:table-cell;
width:15%;
vertical-align:middle;
font-size:20px;
}
SPAN.td4
{
display:table-cell;
width:15%;
vertical-align:middle;
font-size:20px;
}
.onoffswitch {
position: relative; width: 100px;
-webkit-user-select:none; -moz-user-select:none; -ms-user-select: none;
}
.onoffswitch-checkbox {
display: none;
}
.onoffswitch-label {
display: block; overflow: hidden; cursor: pointer;
border: 2px solid #999999; border-radius: 20px;
}
.onoffswitch-inner {
display: block; width: 200%; margin-left: -100%;
-moz-transition: margin 0.3s ease-in 0s; -webkit-transition: margin 0.3s ease-in 0s;
-o-transition: margin 0.3s ease-in 0s; transition: margin 0.3s ease-in 0s;
}
.onoffswitch-inner:before, .onoffswitch-inner:after {
display: block; float: left; width: 50%; height: 35px; padding: 0; line-height: 35px;
font-size: 15px; color: white; font-family: Trebuchet, Arial, sans-serif; font-weight: bold;
-moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;
}
.onoffswitch-inner:before {
content: "AN";
padding-left: 10px;
background-color: #00FF00; color: #000000;
}
.onoffswitch-inner:after {
content: "AUS";
padding-right: 10px;
background-color: #FF0000; color: #000000;
text-align: right;
}
.onoffswitch-switch {
display: block; width: 20px; margin: 7.5px;
background: #FFFFFF;
border: 2px solid #999999; border-radius: 20px;
position: absolute; top: 0; bottom: 0; right: 61px;
-moz-transition: all 0.3s ease-in 0s; -webkit-transition: all 0.3s ease-in 0s;
-o-transition: all 0.3s ease-in 0s; transition: all 0.3s ease-in 0s;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-inner {
margin-left: 0;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-switch {
right: 0px;
}
</style>
</head>
<body>
<?php
if( $_POST["id"] != "" ) {
$st=0;
if ($_POST['statesw'] == "on") { $st=1; }
$pdo = new PDO('mysql:host=panel.agserver.de;dbname=1_mfi', '1_mfi', 'K01v1kk0!');
$sql = "insert into queue (port_id, state, source) values (".$_POST['id'].",'".$st."', 'www')";
$pdo->query($sql);
$sql = "update port set descr='".$_POST['descr']."' where id=".$_POST['id'];
$pdo->query($sql);
}
?>
<?php
$pdo = new PDO('mysql:host=panel.agserver.de;dbname=1_mfi', '1_mfi', 'K01v1kk0!');
$sql = "SELECT * FROM device";
foreach ($pdo->query($sql) as $row) {
#echo " <table border=1 width=100%>\n";
echo " <div class=table>\n";
#echo " <tr><td colspan=2>".$row['name']."</td><td>".$row['ports']."</td></tr>\n";
echo " <form class=tr method=post action=index.php>\n";
echo " <span class=tdh>".$row['name']."</span>\n";
echo " </form>\n";
#echo " </div>\n";
$sql = "select * from port where dev_id = ".$row['id']." order by nr asc";
foreach ($pdo->query($sql) as $port) {
#echo " <tr><td>".$port['nr']."</td><td>".$port['descr']."</td><td>".$port['state']."</td></tr>\n";
echo " <form class=tr method=post action=index.php>\n";
echo " <input type=hidden name=id value=".$port['id'].">\n";
?>
<span class=td1><?php echo $port['nr'] ?></span>
<span class=td2><input type=text name=descr value='<?php echo $port['descr'] ?>'></span>
<span class=td3><input type=hidden name=state value='<?php echo $port['state'] ?>'>
<div class='onoffswitch'>
<input type='checkbox' name='statesw' class='onoffswitch-checkbox' id='myonoffswitch<?php echo $port['id'] ?>' <?php if ($port['state'] == 1) { echo "checked"; } ?>>
<label class='onoffswitch-label' for='myonoffswitch<?php echo $port['id'] ?>'>
<span class='onoffswitch-inner'></span>
<span class='onoffswitch-switch'></span>
</label>
</div>
</span>
<span class=td4><input type=submit value=speichern></span>
<?php
echo " </form>\n";
}
#echo " </table>\n <br>\n";
echo " </div>\n <br>\n";
}
?>
</body>
</html>

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,89 @@
#!/usr/bin/perl
#Kommt auf LSH zum Einsatz
use DBI;
use strict;
# Variable für SQL Befehle
my $sql;
# Gerätelogin
my ($DEVICEUSER, $DEVICEIP, $DEVICEPASS) = ('admin', '192.168.100.7', 'admin');
# DB Parameter
my ($db_user, $db_name, $db_pass, $db_host) = ('1_mfi', '1_mfi', 'K01v1kk0!', 'panel.agserver.de');
# DB connect
my $dbh = DBI->connect("DBI:mysql:database=$db_name;host=$db_host", $db_user, $db_pass) or die "Cannot connect to DB\n";
# Läuft ein Prozess bereits?
if (-e "/scripts/mFi2/read_queue") {
print "already running\n";
exit 0;
}
open HANDLE, ">/scripts/mFi2/read_queue" || die "cannot touch 'read_queue'\n";
close HANDLE;
# Zeilen in Queue vorhanden? Wenn nicht beenden
$sql = "select * from queue";
my $rows = $dbh->do("$sql");
if ($rows == 0) {
print "nothing to do\n";
unlink "/scripts/mFi2/read_queue";
exit 0;
}
for (my $row=1; $row<=$rows; $row++) {
# Queue auslesen
$sql = "select id, port_id, state, source from queue order by id asc";
my @row_queue_ary = $dbh->selectrow_array("$sql");
if ($row_queue_ary[2] == 0 or $row_queue_ary[2] == 1) {
# Ändert sich der Portstatus?
# neu: $row_queue_ary[2]
$sql = "select state from port where id = $row_queue_ary[1]";
my @row_old = $dbh->selectrow_array("$sql");
# alt: $row_old[0]
if ($row_queue_ary[2] != $row_old[0]) {
# Portstatus in DB setzen
$sql = "update port set state = $row_queue_ary[2] where id = $row_queue_ary[1]";
$dbh->do("$sql") or die "$dbh->errstr";
# Portnummer des Gerätes ermitteln
$sql = "select nr, descr, dev_id from port where id = $row_queue_ary[1]";
my @row_port_ary = $dbh->selectrow_array("$sql");
# Geräteinfo holen
$sql = "select id, name, ip, user, pass from device where id = $row_port_ary[2]";
my @row_dev_ary = $dbh->selectrow_array("$sql");
# Logeintrag
# $row_queue_ary[3] source
my $msg = "Setze Port `$row_port_ary[0]` [ID|$row_queue_ary[1], Descr|$row_port_ary[1]] von Device `$row_dev_ary[1]` [ID|$row_dev_ary[0]] auf Status `$row_queue_ary[2]`";
$sql = "insert into log (msg, source) values ('$msg', '$row_queue_ary[3]')";
$dbh->do("$sql");
# Gerät steuern
# Port $row_port_ary[0] (portnummer; evtl -1? da portzählung im gerät bei 0 beginnt) auf on|off setzen ($row_queue_ary[2] entw 0 oder 1)
# print "Setze Port $row_port_ary[0] mit ID $row_queue_ary[1] '$row_port_ary[1]' auf Status $row_queue_ary[2]\n";
print "send commands to device\n";
my $dev = $row_port_ary[0]; # - 1;
my $com = "echo $row_queue_ary[2] > /dev/output$dev";
my $cmd = "expect /scripts/mFi2/port.exp $row_dev_ary[3] $row_dev_ary[2] $row_dev_ary[4] '$com' &";
`$cmd`;
}
print "no change on port with $row_queue_ary[1]\n";
}
# Eintrag aus Queue löschen
$sql = "delete from queue where id = $row_queue_ary[0]";
$dbh->do("$sql") or die "$dbh->errstr";
}
print "job done\n";
unlink "/scripts/mFi2/read_queue";
exit 0;

View File

@@ -0,0 +1,43 @@
#!/bin/bash
if [ "$1" == "" ]
then
echo "
./schicht.sh <früh|mittel|spät>
"
exit 0
fi
if [ "$1" == "früh" ]
then
A=1
B=0
C=0
elif [ "$1" == "mittel" ]
then
A=0
B=1
C=0
elif [ "$1" == "spät" ]
then
A=0
B=0
C=1
else
echo "
Fehlerhafter Aufruf
"
exit 1;
fi
echo "
update cron set active=$A where marker1='früh';
update cron set active=$B where marker1='mittel';
update cron set active=$C where marker1='spät';
" | mysql -u1_mfi -pK01v1kk0! -D 1_mfi -h panel.agserver.de
echo "
select * from cron;
" | mysql -u1_mfi -pK01v1kk0! -D 1_mfi -h panel.agserver.de

View File

@@ -0,0 +1,42 @@
#!/usr/bin/perl
## INSERT INTO `queue` (`id`, `port_id`, `state`) VALUES (NULL, '1', '1');
use DBI;
use strict;
# Variable für SQL Befehle
my $sql;
# DB Parameter
my ($db_user, $db_name, $db_pass, $db_host) = ('1_mfi', '1_mfi', 'K01v1kk0!', 'panel.agserver.de');
# DB connect
my $dbh = DBI->connect("DBI:mysql:database=$db_name;host=$db_host", $db_user, $db_pass) or die "Cannot connect to DB\n";
# Eintrag in Queue schreiben
#my $rows;
#for (my $i=1; $i<=9; $i++) {
# $sql = "insert into queue (port_id, state) values ($i, 1)";
# $rows = $dbh->do("$sql");
#}
#for (my $i=1; $i<=4; $i++) {
# $sql = "insert into queue (port_id, state) values ($i*2, 0)";
# $rows = $dbh->do("$sql");
#}
print "$ARGV[0]\n";
print "$ARGV[1]\n";
my $state=0;
if ($ARGV[1] eq "on") {
$state=1;
} elsif ($ARGV[1] eq "off") {
$state=0;
} else {
print "ungültiger Status\n";
exit 1;
}
$sql = "insert into queue (port_id, state, source) values ($ARGV[0], $state, 'cron')";
$dbh->do("$sql");

View File

@@ -0,0 +1,39 @@
#!/usr/bin/perl
#Kommt auf LSH zum Einsatz
use DBI;
use strict;
# Variable für SQL Befehle
my $sql;
# DB Parameter
my ($db_user, $db_name, $db_pass, $db_host) = ('1_mfi', '1_mfi', 'K01v1kk0!', 'panel.agserver.de');
# DB connect
my $dbh = DBI->connect("DBI:mysql:database=$db_name;host=$db_host", $db_user, $db_pass) or die "Cannot connect to DB\n";
# Cron Einträge in DB?
$sql = "select * from cron";
my $rows = $dbh->do("$sql");
if ($rows == 0) {
print "nothing to do\n";
exit 0;
}
open FILEHANDLE, ">/scripts/mFi2/cron_db";
$sql = "select id, min, hour, dom, mon, dow, port_id, state, active from cron";
my $rows = $dbh->selectall_arrayref("$sql");
foreach (@$rows) {
my $row=$_;
my $state="on" if ($row->[7] == 1);
$state="off" if ($row->[7] == 0);
my $rem='' if ($row->[8] == 1);
$rem='#' if ($row->[8] == 0);
printf FILEHANDLE "# id %5d\n", $row->[0];
printf FILEHANDLE "%1s %5s %5s %5s %5s %5s root /scripts/mFi2/write_queue.pl %3s %5s > /dev/null 2>&1\n", $rem, $row->[1], $row->[2], $row->[3], $row->[4], $row->[5], $row->[6], $state;
printf "%1s %5s %5s %5s %5s %5s root /scripts/mFi2/write_queue.pl %3s %5s > /dev/null 2>&1\n", $rem, $row->[1], $row->[2], $row->[3], $row->[4], $row->[5], $row->[6], $state;
}

56
Perl control mFi/cron_db Normal file
View File

@@ -0,0 +1,56 @@
# id 1
# 5 5 * * 1-5 root /scripts/mFi2/write_queue.pl 3 on > /dev/null 2>&1
# id 2
# 30 5 * * 1-5 root /scripts/mFi2/write_queue.pl 3 off > /dev/null 2>&1
# id 3
# 40 15 * * 1-5 root /scripts/mFi2/write_queue.pl 3 on > /dev/null 2>&1
# id 4
# 15 16 * * 1-5 root /scripts/mFi2/write_queue.pl 3 off > /dev/null 2>&1
# id 5
# 5 5 * * 1-5 root /scripts/mFi2/write_queue.pl 4 on > /dev/null 2>&1
# id 6
# 30 5 * * 1-5 root /scripts/mFi2/write_queue.pl 4 off > /dev/null 2>&1
# id 7
# 40 15 * * 1-5 root /scripts/mFi2/write_queue.pl 4 on > /dev/null 2>&1
# id 8
# 15 16 * * 1-5 root /scripts/mFi2/write_queue.pl 4 off > /dev/null 2>&1
# id 9
0 0 * * * root /scripts/mFi2/write_queue.pl 6 off > /dev/null 2>&1
# id 11
* * * * * root /scripts/mFi2/write_queue.pl 6 on > /dev/null 2>&1
# id 12
* * * * * root /scripts/mFi2/write_queue.pl 1 on > /dev/null 2>&1
# id 13
20 7 * * 1-5 root /scripts/mFi2/write_queue.pl 3 on > /dev/null 2>&1
# id 14
40 7 * * 1-5 root /scripts/mFi2/write_queue.pl 3 off > /dev/null 2>&1
# id 15
40 17 * * 1-5 root /scripts/mFi2/write_queue.pl 3 on > /dev/null 2>&1
# id 16
15 18 * * 1-5 root /scripts/mFi2/write_queue.pl 3 off > /dev/null 2>&1
# id 17
20 7 * * 1-5 root /scripts/mFi2/write_queue.pl 4 on > /dev/null 2>&1
# id 18
40 7 * * 1-5 root /scripts/mFi2/write_queue.pl 4 off > /dev/null 2>&1
# id 19
40 17 * * 1-5 root /scripts/mFi2/write_queue.pl 4 on > /dev/null 2>&1
# id 20
15 18 * * 1-5 root /scripts/mFi2/write_queue.pl 4 off > /dev/null 2>&1
# id 21
# 15 11 * * 1-5 root /scripts/mFi2/write_queue.pl 3 on > /dev/null 2>&1
# id 22
# 30 11 * * 1-5 root /scripts/mFi2/write_queue.pl 3 off > /dev/null 2>&1
# id 23
# 30 21 * * 1-5 root /scripts/mFi2/write_queue.pl 3 on > /dev/null 2>&1
# id 24
# 10 22 * * 1-5 root /scripts/mFi2/write_queue.pl 3 off > /dev/null 2>&1
# id 25
# 15 11 * * 1-5 root /scripts/mFi2/write_queue.pl 4 on > /dev/null 2>&1
# id 26
# 30 11 * * 1-5 root /scripts/mFi2/write_queue.pl 4 off > /dev/null 2>&1
# id 27
# 30 21 * * 1-5 root /scripts/mFi2/write_queue.pl 4 on > /dev/null 2>&1
# id 28
# 10 22 * * 1-5 root /scripts/mFi2/write_queue.pl 4 off > /dev/null 2>&1
# id 30
0 2 23 2 * root /scripts/mFi2/write_queue.pl 4 off > /dev/null 2>&1

231
Perl control mFi/index.php Normal file
View File

@@ -0,0 +1,231 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de-DE" lang="de-DE">
<head>
<title>mfi.andregeissler.de</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="refresh" content="10; URL=https://mfi.andregeissler.de/">
<style>
INPUT {
font-size:20px;
}
SPAN.tdh {
font-size:20px;
}
DIV.table
{
display:table;
width:1000px;
}
FORM.tr, DIV.tr
{
display:table-row;
}
SPAN.td1
{
display:table-cell;
width:10%;
vertical-align:middle;
font-size:20px;
}
SPAN.td2
{
display:table-cell;
width:25%;
vertical-align:middle;
font-size:20px;
}
SPAN.td3
{
display:table-cell;
width:11%;
vertical-align:middle;
font-size:20px;
}
SPAN.td4
{
display:table-cell;
width:4%;
vertical-align:middle;
font-size:20px;
}
SPAN.td5
{
display:table-cell;
width:10%;
vertical-align:middle;
font-size:20px;
}
SPAN.td6
{
display:table-cell;
width:15%;
vertical-align:middle;
padding-left:10px;
font-size:20px;
}
SPAN.td7
{
display:table-cell;
width:25%;
vertical-align:middle;
font-size:20px;
}
.onoffswitch {
position: relative; width: 100px;
-webkit-user-select:none; -moz-user-select:none; -ms-user-select: none;
}
.onoffswitch-checkbox {
display: none;
}
.onoffswitch-label {
display: block; overflow: hidden; cursor: pointer;
border: 2px solid #999999; border-radius: 20px;
}
.onoffswitch-inner {
display: block; width: 200%; margin-left: -100%;
-moz-transition: margin 0.3s ease-in 0s; -webkit-transition: margin 0.3s ease-in 0s;
-o-transition: margin 0.3s ease-in 0s; transition: margin 0.3s ease-in 0s;
}
.onoffswitch-inner:before, .onoffswitch-inner:after {
display: block; float: left; width: 50%; height: 35px; padding: 0; line-height: 35px;
font-size: 15px; color: white; font-family: Trebuchet, Arial, sans-serif; font-weight: bold;
-moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;
}
.onoffswitch-inner:before {
content: "AN";
padding-left: 10px;
background-color: #00FF00; color: #000000;
}
.onoffswitch-inner:after {
content: "AUS";
padding-right: 10px;
background-color: #FF0000; color: #000000;
text-align: right;
}
.onoffswitch-switch {
display: block; width: 20px; margin: 7.5px;
background: #FFFFFF;
border: 2px solid #999999; border-radius: 20px;
position: absolute; top: 0; bottom: 0; right: 61px;
-moz-transition: all 0.3s ease-in 0s; -webkit-transition: all 0.3s ease-in 0s;
-o-transition: all 0.3s ease-in 0s; transition: all 0.3s ease-in 0s;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-inner {
margin-left: 0;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-switch {
right: 0px;
}
</style>
</head>
<body>
<?php
if( $_POST["id"] != "" ) {
$st=0;
if ($_POST['statesw'] == "on") { $st=1; }
$forced=0;
if ($_POST['forced'] == "on") { $forced=1; }
$pdo = new PDO('mysql:host=panel.agserver.de;dbname=1_mfi', '1_mfi', 'K01v1kk0!');
$sql = "update port set descr='".$_POST['descr']."' where id=".$_POST['id'];
$pdo->query($sql);
if ($_POST['submit'] == "speichern") {
if ($_POST['timer'] == "") {
$sql = "insert into queue (port_id, state, source, forced) values (".$_POST['id'].",'".$st."', 'www', ".$forced.")";
$pdo->query($sql);
} else {
$sql = "insert into timer (min, port_id, state) values (".$_POST['timer'].",".$_POST['id'].",".$st.")";
$pdo->query($sql);
}
} else {
$sql = "insert into timer (min, port_id, state) values (0,".$_POST['id'].",1)";
$pdo->query($sql);
$sql = "insert into timer (min, port_id, state) values (".$_POST['submit'].",".$_POST['id'].",0)";
$pdo->query($sql);
}
}
?>
<?php
$pdo = new PDO('mysql:host=panel.agserver.de;dbname=1_mfi', '1_mfi', 'K01v1kk0!');
$sql = "SELECT * FROM device";
foreach ($pdo->query($sql) as $row) {
echo " <div class=table>\n";
echo " <form class=tr method=post action=index.php>\n";
echo " <span class=tdh>".$row['name']."</span>\n";
echo " </form>\n";
$sql = "select * from port where dev_id = ".$row['id']." order by nr asc";
foreach ($pdo->query($sql) as $port) {
echo " <form class=tr method=post action=index.php>\n";
echo " <input type=hidden name=id value=".$port['id'].">\n";
?>
<span class=td1><?php echo $port['nr'] ?></span>
<span class=td2><input type=text name=descr size=13 value='<?php echo $port['descr'] ?>'></span>
<span class=td3><input type=hidden name=state value='<?php echo $port['state'] ?>'>
<div class='onoffswitch'>
<input type='checkbox' name='statesw' class='onoffswitch-checkbox' id='myonoffswitch<?php echo $port['id'] ?>' <?php if ($port['state'] == 1) { echo "checked"; } ?>>
<label class='onoffswitch-label' for='myonoffswitch<?php echo $port['id'] ?>'>
<span class='onoffswitch-inner'></span>
<span class='onoffswitch-switch'></span>
</label>
</div>
</span>
<span class=td4><input type=checkbox name=forced></span>
<span class=td5><input type=text name=timer size=1></span>
<span class=td6><input type=submit name=submit value=speichern></span>
<span class=td7><input type=submit name=submit value=5><input type=submit name=submit value=15><input type=submit name=submit value=45></span>
<?php
echo " </form>\n";
}
echo " </div>\n";
}
?>
<font size=+2>
<hr>
<b>Laufende Timer</b>
<table border=0>
<?php
$e = 1;
$sql = "select * from ActiveTimer";
foreach ($pdo->query($sql) as $port) {
if ($e == 1) {
echo " <tr><td>Ger&auml;t</td><td>Port</td><td>Beschreibung</td><td>Restzeit</td><td>Status</td></tr>\n";
$e = 0;
}
echo " <tr><td>$port[dev_name]</td><td>$port[nr]</td><td>$port[descr]</td><td>$port[min]</td><td>$port[state]</td></tr>\n";
}
?>
</table>
<hr>
<b>Aktive Cronjobs</b>
<table border=0>
<?php
$e = 1;
$sql = "select * from ActiveCronJobs";
foreach ($pdo->query($sql) as $jobs) {
if ($e == 1) {
echo " <tr><td>Ger&auml;t</td><td>Port</td><td>Beschreibung</td><td>Status</td><td>Forced</td><td>Stunde</td><td>Minute</td><td>Marker</td></tr>\n";
$e = 0;
}
if ( $jobs['state'] == '1' ) {
$bgcolor='lightgreen';
} else {
$bgcolor='red';
}
if ( $jobs['forced'] == '1' ) {
$fbgcolor='lightgreen';
} else {
$fbgcolor='red';
}
echo " <tr><td>$jobs[Device]</td><td>$jobs[Port]</td><td>$jobs[PortDescr]</td><td bgcolor=$bgcolor>$jobs[state]</td><td bgcolor=$fbgcolor>$jobs[forced]</td><td>$jobs[hour]</td><td>$jobs[min]</td><td>$jobs[marker1], $jobs[marker2], $jobs[marker3]</td></tr>\n";
}
?>
</table>
</font>
</body>
</html>

View File

@@ -0,0 +1,19 @@
#!/bin/bash
if [ "$2" == "" ]
then
echo "
./marker.sh <0|1> <marker=txt>
"
exit 0
fi
echo "
update cron set active=$1 where $2;
" | mysql -u1_mfi -pK01v1kk0! -D 1_mfi -h panel.agserver.de
echo "
select * from cron where $2;
" | mysql -u1_mfi -pK01v1kk0! -D 1_mfi -h panel.agserver.de

16
Perl control mFi/port.exp Normal file
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,89 @@
#!/usr/bin/perl
#Kommt auf LSH zum Einsatz
use DBI;
use strict;
# Variable für SQL Befehle
my $sql;
# Gerätelogin
my ($DEVICEUSER, $DEVICEIP, $DEVICEPASS) = ('admin', '192.168.100.7', 'admin');
# DB Parameter
my ($db_user, $db_name, $db_pass, $db_host) = ('1_mfi', '1_mfi', 'K01v1kk0!', 'panel.agserver.de');
# DB connect
my $dbh = DBI->connect("DBI:mysql:database=$db_name;host=$db_host", $db_user, $db_pass) or die "Cannot connect to DB\n";
# Läuft ein Prozess bereits?
if (-e "/scripts/mFi2/read_queue") {
print "already running\n";
exit 0;
}
open HANDLE, ">/scripts/mFi2/read_queue" || die "cannot touch 'read_queue'\n";
close HANDLE;
# Zeilen in Queue vorhanden? Wenn nicht beenden
$sql = "select * from queue";
my $rows = $dbh->do("$sql");
if ($rows == 0) {
print "nothing to do\n";
unlink "/scripts/mFi2/read_queue";
exit 0;
}
for (my $row=1; $row<=$rows; $row++) {
# Queue auslesen
$sql = "select id, port_id, state, source from queue order by id asc";
my @row_queue_ary = $dbh->selectrow_array("$sql");
if ($row_queue_ary[2] == 0 or $row_queue_ary[2] == 1) {
# Ändert sich der Portstatus?
# neu: $row_queue_ary[2]
$sql = "select state from port where id = $row_queue_ary[1]";
my @row_old = $dbh->selectrow_array("$sql");
# alt: $row_old[0]
if ($row_queue_ary[2] != $row_old[0]) {
# Portstatus in DB setzen
$sql = "update port set state = $row_queue_ary[2] where id = $row_queue_ary[1]";
$dbh->do("$sql") or die "$dbh->errstr";
# Portnummer des Gerätes ermitteln
$sql = "select nr, descr, dev_id from port where id = $row_queue_ary[1]";
my @row_port_ary = $dbh->selectrow_array("$sql");
# Geräteinfo holen
$sql = "select id, name, ip, user, pass from device where id = $row_port_ary[2]";
my @row_dev_ary = $dbh->selectrow_array("$sql");
# Logeintrag
# $row_queue_ary[3] source
my $msg = "Setze Port auf neuen Status";
$sql = "insert into log (msg, port, port_id, device, device_id, status, source, descr) values ('$msg', '$row_port_ary[0]', '$row_queue_ary[1]', '$row_dev_ary[1]', '$row_dev_ary[0]', '$row_queue_ary[2]', '$row_queue_ary[3]', '$row_port_ary[1]')";
$dbh->do("$sql");
# Gerät steuern
# Port $row_port_ary[0] (portnummer; evtl -1? da portzählung im gerät bei 0 beginnt) auf on|off setzen ($row_queue_ary[2] entw 0 oder 1)
# print "Setze Port $row_port_ary[0] mit ID $row_queue_ary[1] '$row_port_ary[1]' auf Status $row_queue_ary[2]\n";
print "send commands to device\n";
my $dev = $row_port_ary[0]; # - 1;
my $com = "echo $row_queue_ary[2] > /dev/output$dev";
my $cmd = "expect /scripts/mFi2/port.exp $row_dev_ary[3] $row_dev_ary[2] $row_dev_ary[4] '$com' &";
`$cmd`;
}
print "no change on port with $row_queue_ary[1]\n";
}
# Eintrag aus Queue löschen
$sql = "delete from queue where id = $row_queue_ary[0]";
$dbh->do("$sql") or die "$dbh->errstr";
}
print "job done\n";
unlink "/scripts/mFi2/read_queue";
exit 0;

View File

@@ -0,0 +1,48 @@
#!/bin/bash
if [ "$1" == "" ]
then
echo "
./schicht.sh <früh|mittel|spät|home>
"
exit 0
fi
if [ "$1" == "früh" ]
then
A=1
B=0
C=0
elif [ "$1" == "mittel" ]
then
A=0
B=1
C=0
elif [ "$1" == "spät" ]
then
A=0
B=0
C=1
elif [ "$1" == "home" ]
then
A=0
B=0
C=0
else
echo "
Fehlerhafter Aufruf
"
exit 1;
fi
echo "
update cron set active=$A where marker1='früh';
update cron set active=$B where marker1='mittel';
update cron set active=$C where marker1='spät';
" | mysql -u1_mfi -pK01v1kk0! -D 1_mfi -h panel.agserver.de
echo "
select * from cron;
" | mysql -u1_mfi -pK01v1kk0! -D 1_mfi -h panel.agserver.de

53
Perl control mFi/timer.pl Normal file
View File

@@ -0,0 +1,53 @@
#!/usr/bin/perl
## INSERT INTO `queue` (`id`, `port_id`, `state`) VALUES (NULL, '1', '1');
use DBI;
use strict;
# Variable für SQL Befehle
my $sql;
# DB Parameter
my ($db_user, $db_name, $db_pass, $db_host) = ('1_mfi', '1_mfi', 'K01v1kk0!', 'panel.agserver.de');
# DB connect
my $dbh = DBI->connect("DBI:mysql:database=$db_name;host=$db_host", $db_user, $db_pass) or die "Cannot connect to DB\n";
# Cron Einträge in DB?
$sql = "select * from timer";
my $rows = $dbh->do("$sql");
if ($rows == 0) {
print "nothing to do\n";
exit 0;
}
# Lese timer Tabelle
$sql = "select id, min, port_id, state from timer";
# 0 1 2 3
my $rows = $dbh->selectall_arrayref("$sql");
foreach (@$rows) {
# für jeden Eintrag
my $row=$_;
my $id=$row->[0];
my $min=$row->[1];
my $port_id=$row->[2];
my $state=$row->[3];
print "ID:$id Restminuten:$min Port-ID:$port_id Status:$state\n";
# ist 'min' = 0 eintrag löschen und einen Eintrag in queue schreiben
if ($min == 0) {
print "Lösche Timer und erstelle cron Eintrag\n";
$sql = "delete from timer where id='$id'";
$dbh->do("$sql");
$sql = "insert into queue (port_id, state, forced, source) values ($port_id, $state, 1, 'timer')";
$dbh->do("$sql");
} else {
print "Eine (weitere) Minute ist vergangen\n";
# min um eins reduzieren
$min--;
# min zurückschreiben
$sql = "update timer set min = '$min' where id='$id'";
$dbh->do("$sql");
}
}

View File

@@ -0,0 +1,40 @@
#!/usr/bin/perl
## INSERT INTO `queue` (`id`, `port_id`, `state`) VALUES (NULL, '1', '1');
use DBI;
use strict;
# Variable für SQL Befehle
my $sql;
# DB Parameter
my ($db_user, $db_name, $db_pass, $db_host) = ('1_mfi', '1_mfi', 'K01v1kk0!', 'panel.agserver.de');
# DB connect
my $dbh = DBI->connect("DBI:mysql:database=$db_name;host=$db_host", $db_user, $db_pass) or die "Cannot connect to DB\n";
# Eintrag in Queue schreiben
#my $rows;
#for (my $i=1; $i<=9; $i++) {
# $sql = "insert into queue (port_id, state) values ($i, 1)";
# $rows = $dbh->do("$sql");
#}
#for (my $i=1; $i<=4; $i++) {
# $sql = "insert into queue (port_id, state) values ($i*2, 0)";
# $rows = $dbh->do("$sql");
#}
my $state=0;
if ($ARGV[1] eq "on") {
$state=1;
} elsif ($ARGV[1] eq "off") {
$state=0;
} else {
print "ungültiger Status\n";
exit 1;
}
$sql = "insert into queue (port_id, state, source, forced) values ($ARGV[0], $state, 'cron', $ARGV[2])";
$dbh->do("$sql");