-
Notifications
You must be signed in to change notification settings - Fork 0
/
sys_startup.php
executable file
·106 lines (86 loc) · 2.72 KB
/
sys_startup.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#! /usr/bin/php
<?
/*
Used for PI startup
run at boot to cover all the startup needs of the custom PI
*/
global $start_log;
global $ini_array;
global $ini_file;
global $unitname;
$GLOBALS['startlog'] = "/var/log/start.log";
$GLOBALS['ini_file'] =__DIR__ ."/sys_startup.ini";
/*if(!check_root())
{
echo "\nMust be run as root or from cron!!\n\n";
log_it("Must be run as root or from cron!!");
die;
}
*/
log_it("[Startup Ran]");
echo "FILE " .$GLOBALS['ini_file'] ."\n";
readini($GLOBALS['ini_file']);
//print_r($GLOBALS['ini_array']);
/* When this PI is using relays we need to init them using GPIO*/
initrelay();
/* Start temp monitor */
system("/home/pi/bin/templog/temp1.php -D 2>&1 &");
/* Start network monitor */
system("/root/network-monitorrpi.sh >/dev/null 2>&1 &");
$GLOBALS['unitname'] = preg_replace("/\r|\n/", "", shell_exec("/bin/hostname"));
//'*******************************************************************************
function check_root()
{
if (posix_getuid() == 0){
//echo "This is root !";
return True;
} else {
//echo "This is non-root";
return False;
}
}
//'*******************************************************************************
//'*******************************************************************************
function log_it($log_str)
{
file_put_contents($GLOBALS['startlog'], date("Y-m-d H:i:s") ." - " .$log_str ."\n", FILE_APPEND | LOCK_EX);
}
//'*******************************************************************************
//'*******************************************************************************
function initrelay()
{
if(isset($GLOBALS['ini_array']['userelay']['val']))
{
if($GLOBALS['ini_array']['userelay']['val'] == 1)
{
if(is_array($GLOBALS['ini_array']['relay']))
{
echo "Use Relay\n";
$relay_array = array_values($GLOBALS['ini_array']['relay']);
for($i = 0; $i < sizeof($relay_array); $i++)
{
$relays = explode(",", $relay_array[$i]);
//file_put_contents('/sys/class/gpio/export', 'gpio'.$relays[1]);
//$f = fopen('/sys/class/gpio/export', "w");
//fwrite($f, 'gpio'.$relays[1]);
//fclose($f);
echo "RELAY " .$relays[0] ." Value " .$relays[1] ."\n";
system("/usr/local/bin/gpio -g mode " .$relays[1] ." out");
system("/usr/local/bin/gpio -g write " .$relays[1] ." 1");
}
sleep(1);
print_r($relay_array);
}
}
}else{
echo "error\n";
}
}
//'*******************************************************************************
//'*******************************************************************************
function readini($file)
{
$GLOBALS['ini_array'] = parse_ini_file($file,true);
}
//'*******************************************************************************
?>