forked from RobboRob/allsky
-
Notifications
You must be signed in to change notification settings - Fork 0
/
camera_settings.php
147 lines (134 loc) · 5.35 KB
/
camera_settings.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
include_once( 'includes/status_messages.php' );
function DisplayCameraConfig(){
$camera_options_str = file_get_contents(RASPI_CAMERA_OPTIONS, true);
$camera_options_array = json_decode($camera_options_str, true);
$text_options = array();
foreach($camera_options_array as $option)
{
if ( $option['type'] === 'text' && !in_array($option['name'], ["filename", "fontcolor"])){
$text_options[] = $option['name'];
}
}
$status = new StatusMessages();
if (isset($_POST['save_camera_options'])) {
if (CSRFValidate()) {
if ($camera_settings_file = fopen(RASPI_CAMERA_SETTINGS, 'w')) {
$settings = array();
foreach ($_POST as $key => $value){
// We look into POST data to only select camera settings
if (!in_array($key, ["csrf_token", "save_camera_options", "reset_camera_options"])){
if (camera_options_array[$key] == "checkbox"){
$settings[$key] = $value;
} else {
$settings[$key] = $value;
}
}
}
fwrite($camera_settings_file, json_encode($settings));
fclose($camera_settings_file);
$status->addMessage('Camera configuration saved.');
shell_exec("sudo systemctl restart allsky_RPiHQ.service");
} else {
$status->addMessage('Failed to save camera configuration', 'danger');
}
} else {
error_log('CSRF violation');
}
}
if (isset($_POST['reset_camera_options'])) {
if (CSRFValidate()) {
if ($camera_settings_file = fopen(RASPI_CAMERA_SETTINGS, 'w')) {
$settings = array();
foreach ($camera_options_array as $option){
$key = $option['name'];
$value = $option['default'];
$settings[$key] = $value;
}
fwrite($camera_settings_file, json_encode($settings));
fclose($camera_settings_file);
$status->addMessage('Camera configuration reset to default');
} else {
$status->addMessage('Failed to reset camera configuration', 'danger');
}
} else {
error_log('CSRF violation');
}
}
$camera_settings_str = file_get_contents(RASPI_CAMERA_SETTINGS, true);
$camera_settings_array = json_decode($camera_settings_str, true);
$text_options = array();
foreach($camera_options_array as $option)
{
if ( $option['type'] === 'text' && !in_array($option['name'], ["filename", "fontcolor"])){
$text_options[] = $option['name'];
}
}
?>
<div class="row">
<div class="col-lg-12">
<div class="panel panel-primary">
<div class="panel-heading"><i class="fa fa-camera fa-fw"></i> Configure Camera Settings</div>
<!-- /.panel-heading -->
<div class="panel-body">
<p><?php $status->showMessages(); ?></p>
<form method="POST" class="form-inline" action="?page=camera_conf" name="camera_conf_form">
<?php CSRFToken()?>
<?php
foreach($camera_options_array as $option) {
$label = $option['label'];
$name = $option['name'];
$value = $camera_settings_array[$option['name']] != null ? $camera_settings_array[$option['name']] : $option['default'];
$description = $option['description'];
$type = $option['type'];
echo "<div class='form-group' style='margin: 3px 0'>";
echo "<label style='width: 140px'>$label</label>";
if ($type == "text" || $type == "number"){
echo "<input class='form-control' type='$type' ".
"style='text-align: right; width: 120px; margin-right: 20px' ".
"name='$name' value='$value'>";
} else if ($type == "select"){
echo "<select class='form-control' name='$name' ".
"style='width: 120px; margin-right: 20px'>";
foreach($option['options'] as $opt){
$val = $opt['value'];
$lab = $opt['label'];
if ($value == $val){
echo "<option value='$val' selected>$lab</option>";
} else {
echo "<option value='$val'>$lab</option>";
}
}
echo "</select>";
} else if ($type == "checkbox"){
echo "<div class='switch-field'>";
echo "<input id='switch_no_".$name."' class='form-control' type='radio' ".
"style='width: 40px; box-shadow:none' ".
"name='$name' value='0' ".
($value == 0 ? " checked " : "").
">";
echo "<label for='switch_no_".$name."'>No</label>";
echo "<input id='switch_yes_".$name."' class='form-control' type='radio' ".
"style='width: 40px; box-shadow:none' ".
"name='$name' value='1' ".
($value == 1 ? " checked " : "").
">";
echo "<label for='switch_yes_".$name."'>Yes</label>";
echo "</div>";
}
echo "<span>$description</span>";
echo "</div><div style='clear:both'></div>";
}?>
<div style="margin-top: 20px">
<input type="submit" class="btn btn-outline btn-primary" name="save_camera_options" value="Save changes">
<input type="submit" class="btn btn-warning" name="reset_camera_options" value="Reset to default values">
</div>
</form>
</div><!-- ./ Panel body -->
<!--<div class="panel-footer"><strong>Note,</strong> WEP access points appear as 'Open'. Allsky Camera Portal does not currently support connecting to WEP.</div>-->
</div><!-- /.panel-primary -->
</div><!-- /.col-lg-12 -->
</div><!-- /.row -->
<?php
}
?>