-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostalart.php
More file actions
96 lines (83 loc) · 2.85 KB
/
postalart.php
File metadata and controls
96 lines (83 loc) · 2.85 KB
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
<?php
/**
* [API] Post data.
*
* Use HTTP POST method for posting data from slider to the monitor.
*
* Requires $_POST['serial_id']
* $_POST['name']
* $_POST['data']
*
* Option $_POST['datetime'] server time is used in case not specified.
*
* @author Dr. Takeyuki UEDA
* @copyright Copyright© Atelier UEDA 2016 - All rights reserved.
*
*/
require("sc.php");
require_once("vendor/autoload.php");
#require_once("Log.php");
$logfilename = "postalart.out.log";
$logfile = &Log::factory('file', $logfilename, 'TEST');
$logfile->log('['.__LINE__.']'.'*** STARTED ***');
// 必用に応じて log ファイルのコンパクションを行う
$p=pathinfo($_SERVER['SCRIPT_FILENAME']);
$logfile->log('['.__LINE__.']'.'$_SERVER[SCRIPT_FILENAME] = '.$_SERVER['SCRIPT_FILENAME']);
$command = "".$p['dirname']."/compaction.sh ".$logfilename;
$logfile->log('['.__LINE__.']'.'$command = '.$command);
`$command`;
if($_SERVER["REQUEST_METHOD"] == "POST"){
# confirm post parameters.
if (isset($_POST['serial_id'])){
$logfile->log('['.__LINE__.']'.'$_POST[serial_id] = '.$_POST['serial_id']);
} else {exit;}
if (isset($_POST['name'])){
$logfile->log('['.__LINE__.']'.'$_POST[name] = '.$_POST['name']);
} else {exit;}
if (isset($_POST['status'])){
$logfile->log('['.__LINE__.']'.'$_POST[status] = '.$_POST['status']);
} else {exit;}
$alarm_ini_file = __DIR__. "/uploads/".$_POST['serial_id']."/alart.ini";
# confirm alarm.ini file existance and read/write ability.
if (!is_readable($alarm_ini_file)) {exit;}
# read alarm.ini
$ini = parse_ini_file($alarm_ini_file);
if (isset($ini[$_POST['name']])){
$datetime = date("Y年m月d日H時i分s秒"); # current time.
if ($_POST['status'] == "on"){
if ($ini[$_POST['name']] == ""){
# emargency call if first alart
$query = ['serial_id'=>$_POST['serial_id'],'name'=>'water'];
$contents = file_get_contents(ALART_CALL_URL.'?'.http_build_query($query));
#$contents = file_get_contents(ALART_CALL_URL);
# set alart state.
$ini[$_POST['name']] = $datetime;
$logfile->log('['.__LINE__.']'.'Set '. $_POST['name']. ' ON at $datetime = '.$datetime);
}
} else {
$ini[$_POST['name']] = "";
$logfile->log('['.__LINE__.']'.'Set '. $_POST['name']. ' OFF at $datetime = '.$datetime);
}
}
# update alarm.ini
$fp = fopen($alarm_ini_file, 'w');
foreach ($ini as $k => $i) fputs($fp, "$k=$i\n");
fclose($fp);
exit();
}
?>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>Alarm</title>
</head>
<body>
<form action="" method="POST" >
serial_id<input type="text" name="serial_id" id="serial_id"/>
name<input type="text" name="name" id="name">
status<input type="text" name="status" id="status">
<input type="submit" value="登録">
</form>
</body>
</html>