-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dispatch.php
67 lines (52 loc) · 1.38 KB
/
Dispatch.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
require('Initialize.php');
//lock the settings file
$file="data/gpio.status";
//open the settings
$ettings=init();
$fs=lockStatusFile($file);
//open the status file
function invert($item, $tate){
if ($item['invertedOutput']=="1"){
return ($tate=="1"?"0":"1");
}
return $tate;
}
foreach ($argv as $arg) {
$e=explode("=",$arg);
if(count($e)==2){
$_GET[$e[0]]=$e[1];
}else{
$_GET[]=$e[0];
}
}
function doScript($target, $fs){
unlockStatusFile($fs);
$script=$target["script"];
exec($script);
}
function dispatch($ettings, $fs){
if (isset($_GET["target"])){
$name=$_GET["target"];
if (array_key_exists($name , $ettings)){
$target=$ettings["$name"];
$type=$target["type"];
if ($type == "gpio"){
require ("GPIO.php");
gpio($ettings, $target);
unlockStatusFile($fs);
}else if ($type =="script"){
doScript($target,$fs);
}else {
echo "I can't handle anything except GPIOs right now ".$target['type']."<br>\n";
}
} else {
echo "invalid setting $name<br>\n";
}
} else {
echo "no parameters specified to dispatch<br>\n";
}
}
include_once('writeTimestamp.php');
dispatch($ettings, $fs);
writeTimeStamp();