-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathsources.php
220 lines (204 loc) · 6.47 KB
/
sources.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<?php
/*
* PlayerUI Copyright (C) 2013 Andrea Coiutti & Simone De Gregori
* Tsunamp Team
* http://www.tsunamp.com
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with RaspyFi; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*
* UI-design/JS code by: Andrea Coiutti (aka ACX)
* PHP/JS code by: Simone De Gregori (aka Orion)
*
* file: sources.php
* version: 1.1
*
*/
// common include
include('inc/connection.php');
playerSession('open',$db,'','');
?>
<?php
// handle (reset)
if (isset($_POST['reset']) && $_POST['reset'] == 1) {
// tell worker to write new MPD config
if ($_SESSION['w_lock'] != 1 && $_SESSION['w_queue'] == '') {
session_start();
$_SESSION['w_queue'] = "sourcecfgman";
$_SESSION['w_queueargs'] = 'sourcecfgreset';
$_SESSION['w_active'] = 1;
// set UI notify
$_SESSION['notify']['title'] = 'auto.nas modified';
$_SESSION['notify']['msg'] = 'remount shares in progress...';
session_write_close();
} else {
session_start();
$_SESSION['notify']['title'] = 'Job Failed';
$_SESSION['notify']['msg'] = 'background worker is busy.';
session_write_close();
}
unset($_POST);
}
if (isset($_GET['updatempd']) && $_GET['updatempd'] == '1' ){
if ( !$mpd) {
session_start();
$_SESSION['notify']['title'] = 'Error';
$_SESSION['notify']['msg'] = 'Cannot connect to MPD Daemon';
} else {
sendMpdCommand($mpd,'update');
session_start();
$_SESSION['notify']['title'] = 'MPD Update';
$_SESSION['notify']['msg'] = 'database update started...';
}
}
// handle POST
if(isset($_POST['mount']) && !empty($_POST['mount'])) {
// convert slashes for remotedir path
$_POST['mount']['remotedir'] = str_replace('\\', '/', $_POST['mount']['remotedir']);
if ($_POST['mount']['wsize'] == '') {
$_POST['mount']['wsize'] = 8096;
}
if ($_POST['mount']['rsize'] == '') {
$_POST['mount']['rsize'] = 8048;
}
if ($_POST['mount']['options'] == '') {
if ($_POST['mount']['type'] == 'cifs') {
$_POST['mount']['options'] = "ro,dir_mode=0777,file_mode=0777";
} else {
$_POST['mount']['options'] = "nfsvers=3,ro,noatime";
}
}
// activate worker
if (isset($_POST['delete']) && $_POST['delete'] == 1) {
// delete an existing entry
if ($_SESSION['w_lock'] != 1 && $_SESSION['w_queue'] == '') {
session_start();
$_SESSION['w_queue'] = 'sourcecfg';
$_POST['mount']['action'] = 'delete';
$_SESSION['w_queueargs'] = $_POST;
$_SESSION['w_active'] = 1;
// set UI notify
$_SESSION['notify']['title'] = 'mount point deleted';
$_SESSION['notify']['msg'] = 'Update DB in progress...';
session_write_close();
} else {
session_start();
$_SESSION['notify']['title'] = 'Job Failed';
$_SESSION['notify']['msg'] = 'background worker is busy.';
session_write_close();
}
} else {
if ($_SESSION['w_lock'] != 1 && $_SESSION['w_queue'] == '') {
session_start();
$_SESSION['w_queue'] = 'sourcecfg';
$_SESSION['w_queueargs'] = $_POST;
$_SESSION['w_active'] = 1;
// set UI notify
$_SESSION['notify']['title'] = 'mount point modified';
$_SESSION['notify']['msg'] = 'Update DB in progress...';
session_write_close();
} else {
session_start();
$_SESSION['notify']['title'] = 'Job Failed';
$_SESSION['notify']['msg'] = 'background worker is busy.';
session_write_close();
}
}
}
// handle manual config
// rel 1.0 autoFS
/*
if(isset($_POST['sourceconf']) && !empty($_POST['sourceconf'])) {
// tell worker to write new MPD config
if ($_SESSION['w_lock'] != 1 && $_SESSION['w_queue'] == '') {
session_start();
$_SESSION['w_queue'] = "sourcecfgman";
$_SESSION['w_queueargs'] = $_POST['sourceconf'];
$_SESSION['w_active'] = 1;
// set UI notify
$_SESSION['notify']['title'] = 'auto.nas modified';
$_SESSION['notify']['msg'] = 'remount shares in progress...';
session_write_close();
} else {
session_start();
$_SESSION['notify']['title'] = 'Job Failed';
$_SESSION['notify']['msg'] = 'background worker is busy.';
session_write_close();
}
} */
// wait for worker output if $_SESSION['w_active'] = 1
waitWorker(5,'sources');
$dbh = cfgdb_connect($db);
$source = cfgdb_read('cfg_source',$dbh);
$dbh = null;
// set normal config template
$tpl = "sources.html";
// unlock session files
playerSession('unlock',$db,'','');
foreach ($source as $mp) {
if (wrk_checkStrSysfile('/proc/mounts',$mp['name']) ) {
$icon = "<i class='fa fa-check green sx'></i>";
} else {
$icon = "<i class='fa fa-remove red sx'></i>";
}
$_mounts .= "<p><a href=\"sources.php?p=edit&id=".$mp['id']."\" class='btn btn-large btn-block'> ".$icon." NAS/".$mp['name']." //".$mp['address']."/".$mp['remotedir']." </a></p>";
}
?>
<?php
$sezione = basename(__FILE__, '.php');
include('_header.php');
?>
<!-- content --!>
<?php
if (isset($_GET['p']) && !empty($_GET['p'])) {
if (isset($_GET['id']) && !empty($_GET['id'])) {
$_id = $_GET['id'];
foreach ($source as $mount) {
if ($mount['id'] == $_id) {
$_name = $mount['name'];
$_address = $mount['address'];
$_remotedir = $mount['remotedir'];
$_username = $mount['username'];
$_password = $mount['password'];
$_rsize = $mount['rsize'];
$_wsize = $mount['wsize'];
// mount type select
$_source_select['type'] .= "<option value=\"cifs\" ".(($mount['type'] == 'cifs') ? "selected" : "")." >SMB/CIFS</option>\n";
$_source_select['type'] .= "<option value=\"nfs\" ".(($mount['type'] == 'nfs') ? "selected" : "")." >NFS</option>\n";
$_charset = $mount['charset'];
$_options = $mount['options'];
$_error = $mount['error'];
if (empty($_error)) {
$_hideerror = 'hide';
}
}
}
$_title = 'Edit network mount';
$_action = 'edit';
} else {
$_title = 'Add new network mount';
$_hide = 'hide';
$_hideerror = 'hide';
$_action = 'add';
$_source_select['type'] .= "<option value=\"cifs\">SMB/CIFS</option>\n";
$_source_select['type'] .= "<option value=\"nfs\">NFS</option>\n";
}
$tpl = 'source.html';
}
debug($_POST);
eval("echoTemplate(\"".getTemplate("templates/$tpl")."\");");
?>
<!-- content -->
<?php include('_footer.php'); ?>