2 * $Id: enigma_dyn_mount.cpp,v 1.30 2005/10/12 20:46:27 digi_casi Exp $
4 * (C) 2005 by digi_casi <digi_casi@tuxbox.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #ifdef ENABLE_EXPERT_WEBIF
29 #include <sys/types.h>
32 #include <sys/socket.h>
33 #include <sys/ioctl.h>
35 #include <arpa/inet.h>
36 #include <linux/if_ether.h>
40 #include <lib/system/http_dyn.h>
41 #include <lib/system/econfig.h>
42 #include <enigma_dyn.h>
43 #include <enigma_dyn_utils.h>
44 #include <enigma_dyn_mount.h>
45 #include <enigma_main.h>
46 #include <enigma_mount.h>
50 eString
getConfigMountMgr(void)
52 eString result
= readFile(TEMPLATE_DIR
+ "mountPoints.tmp");
53 result
.strReplace("#ADDMOUNTPOINTBUTTON#", button(100, "Add", GREEN
, "javascript:addMountPoint()", "#FFFFFF"));
54 eString skelleton
= readFile(TEMPLATE_DIR
+ "mountPoint.tmp");
55 result
.strReplace("#BODY#", eMountMgr::getInstance()->listMountPoints(skelleton
));
59 static eString
addChangeMountPoint(eString request
, eString dirpath
, eString opts
, eHTTPConnection
*content
)
63 std::map
<eString
,eString
> opt
= getRequestOptions(opts
, '&');
64 eString action
= opt
["action"];
65 eString id
= opt
["id"];
67 mp
.localDir
= opt
["localdir"];
68 mp
.fstype
= atoi(opt
["fstype"].c_str());
69 mp
.password
= opt
["password"];
70 mp
.userName
= opt
["username"];
71 mp
.mountDir
= opt
["mountdir"];
72 mp
.automount
= (opt
["automount"] == "on") ? 1 : 0;
73 eString options
= opt
["options"];
74 mp
.ip
[0] = atoi(opt
["ip0"].c_str());
75 mp
.ip
[1] = atoi(opt
["ip1"].c_str());
76 mp
.ip
[2] = atoi(opt
["ip2"].c_str());
77 mp
.ip
[3] = atoi(opt
["ip3"].c_str());
79 eString async
= opt
["async"];
80 eString sync
= opt
["sync"];
81 eString atime
= opt
["atime"];
82 eString autom
= opt
["autom"];
83 eString execm
= opt
["execm"];
84 eString noexec
= opt
["noexec"];
85 eString ro
= opt
["ro"];
86 eString rw
= opt
["rw"];
87 eString users
= opt
["users"];
88 eString nolock
= opt
["nolock"];
89 eString intr
= opt
["intr"];
90 eString soft
= opt
["soft"];
91 eString udp
= opt
["udp"];
92 mp
.description
= opt
["description"];
95 mp
.options
+= "async,";
97 mp
.options
+= "sync,";
99 mp
.options
+= "atime,";
101 mp
.options
+= "autom,";
103 mp
.options
+= "execm,";
105 mp
.options
+= "noexec,";
111 mp
.options
+= "users,";
113 mp
.options
+= "nolock,";
115 mp
.options
+= "intr,";
117 mp
.options
+= "soft,";
119 mp
.options
+= "udp,";
120 if (mp
.options
.length() > 0)
121 mp
.options
= mp
.options
.substr(0, mp
.options
.length() - 1); //remove last comma
122 mp
.options
+= (options
) ? ("," + options
) : "";
125 if (action
== "change")
127 eMountMgr::getInstance()->changeMountPoint(atoi(id
.c_str()), mp
);
128 result
= "<html><body onUnload=\"parent.window.opener.location.reload(true)\"><script>window.close();</script></body></html>";
132 eMountMgr::getInstance()->addMountPoint(mp
);
133 result
= "<html><body onUnload=\"parent.window.opener.location.reload(true)\"><script>window.close();</script></body></html>";
136 content
->local_header
["Content-Type"]="text/html; charset=utf-8";
140 static eString
removeMountPoint(eString request
, eString dirpath
, eString opts
, eHTTPConnection
*content
)
142 std::map
<eString
,eString
> opt
= getRequestOptions(opts
, '&');
143 eString id
= opt
["id"];
145 content
->local_header
["Content-Type"]="text/html; charset=utf-8";
146 eMountMgr::getInstance()->removeMountPoint(atoi(id
.c_str()));
148 return "<html><body onUnload=\"parent.window.opener.location.reload(true)\">Mount point deleted successfully.</body></html>";
151 static eString
mountPointWindow(eString request
, eString dirpath
, eString opts
, eHTTPConnection
*content
)
153 eString async
, sync
, atime
, autom
, execm
, noexec
, ro
, rw
, users
, nolock
, intr
, soft
, udp
;
157 std::map
<eString
,eString
> opt
= getRequestOptions(opts
, '&');
158 eString action
= opt
["action"];
159 eString id
= opt
["id"];
161 eString result
= readFile(TEMPLATE_DIR
+ "mountPointWindow.tmp");
162 if (action
== "change")
164 result
.strReplace("#TITLE#", "Change Mount Point");
165 mp
= eMountMgr::getInstance()->getMountPointData(atoi(id
.c_str()));
170 result
.strReplace("#TITLE#", "Add Mount Point");
171 mp
.options
= "nolock,intr,soft,udp,rsize=4096,wsize=4096";
181 result
.strReplace("#ACTION#", "/control/addChangeMountPoint");
182 result
.strReplace("#CMD#", cmd
);
184 unsigned int pos
= 0;
185 eString options
, option
;
186 while (mp
.options
.length() > 0)
188 if ((pos
= mp
.options
.find(",")) != eString::npos
)
190 option
= mp
.options
.substr(0, pos
);
191 mp
.options
= mp
.options
.substr(pos
+ 1);
199 if (option
== "async")
202 if (option
== "sync")
205 if (option
== "atime")
208 if (option
== "autom")
211 if (option
== "execm")
214 if (option
== "noexec")
223 if (option
== "users")
226 if (option
== "nolock")
229 if (option
== "intr")
232 if (option
== "soft")
238 options
+= (options
) ? ("," + option
) : option
;
241 result
.strReplace("#ID#", eString().sprintf("%d", mp
.id
));
242 result
.strReplace("#LDIR#", mp
.localDir
);
243 result
.strReplace("#FSTYPE#", eString().sprintf("%d", mp
.fstype
));
244 result
.strReplace("#PW#", mp
.password
);
245 result
.strReplace("#USER#", mp
.userName
);
246 result
.strReplace("#MDIR#", mp
.mountDir
);
247 result
.strReplace("#AUTO#", (mp
.automount
== 1) ? "checked" : "");
248 result
.strReplace("#OPTIONS#", options
);
249 result
.strReplace("#IP0#", eString().sprintf("%d", mp
.ip
[0]));
250 result
.strReplace("#IP1#", eString().sprintf("%d", mp
.ip
[1]));
251 result
.strReplace("#IP2#", eString().sprintf("%d", mp
.ip
[2]));
252 result
.strReplace("#IP3#", eString().sprintf("%d", mp
.ip
[3]));
253 result
.strReplace("#ASYNC#", async
);
254 result
.strReplace("#SYNC#", sync
);
255 result
.strReplace("#ATIME#", atime
);
256 result
.strReplace("#AUTOM#", autom
);
257 result
.strReplace("#EXECM#", execm
);
258 result
.strReplace("#NOEXEC#", noexec
);
259 result
.strReplace("#RO#", ro
);
260 result
.strReplace("#RW#", rw
);
261 result
.strReplace("#USERS#", users
);
262 result
.strReplace("#NOLOCK#", nolock
);
263 result
.strReplace("#INTR#", intr
);
264 result
.strReplace("#SOFT#", soft
);
265 result
.strReplace("#UDP#", udp
);
266 result
.strReplace("#DESCRIPTION#", mp
.description
);
268 content
->local_header
["Content-Type"]="text/html; charset=utf-8";
273 static eString
mountMountPoint(eString request
, eString dirpath
, eString opts
, eHTTPConnection
*content
)
277 std::map
<eString
,eString
> opt
= getRequestOptions(opts
, '&');
278 eString id
= opt
["id"];
280 content
->local_header
["Content-Type"]="text/html; charset=utf-8";
281 int rc
= eMountMgr::getInstance()->mountMountPoint(atoi(id
.c_str()));
286 result
= "Mountpoint is already mounted.";
289 result
= "Local directory is already used as mount point.";
292 result
= "CIFS is not supported.";
295 result
= "NFS is not supported.";
298 result
= "Mount failed (timeout).";
301 result
= "Unable to create mount directory.";
304 result
= "Mount point mounted successfully.";
307 eDebug("[ENIGMA_DYN_MOUNT] mount: rc = %d (%s)", rc
, result
.c_str());
309 return closeWindow(content
, "", 500);
312 static eString
unmountMountPoint(eString request
, eString dirpath
, eString opts
, eHTTPConnection
*content
)
316 std::map
<eString
,eString
> opt
= getRequestOptions(opts
, '&');
317 eString id
= opt
["id"];
319 content
->local_header
["Content-Type"]="text/html; charset=utf-8";
320 int rc
= eMountMgr::getInstance()->unmountMountPoint(atoi(id
.c_str()));
323 result
= "Mount point unmounted successfully.";
325 result
= "Mount point unmount failed.";
327 eDebug("[ENIGMA_DYN_MOUNT] unmount: rc = %d (%s)", rc
, result
.c_str());
329 return closeWindow(content
, "", 500);
332 extern bool rec_movies();
334 static eString
selectMovieSource(eString request
, eString dirpath
, eString opts
, eHTTPConnection
*content
)
338 std::map
<eString
,eString
> opt
= getRequestOptions(opts
, '&');
339 eString id
= opt
["id"];
341 content
->local_header
["Content-Type"]="text/html; charset=utf-8";
343 eZapMain::getInstance()->saveRecordings();
344 eMountMgr::getInstance()->selectMovieSource(atoi(id
.c_str()));
345 if (access("/hdd/movie/recordings.epl", R_OK
) == 0)
347 eDebug("[ENIGMA_DYN_MOUNT] recordings.epl available");
348 eZapMain::getInstance()->loadRecordings();
352 eDebug("[ENIGMA_DYN_MOUNT] recordings.epl not available, recovering...");
356 eDebug("[ENIGMA_DYN_MOUNT] selectMovieSource.");
358 return closeWindow(content
, "", 500);
361 void ezapMountInitializeDyn(eHTTPDynPathResolver
*dyn_resolver
, bool lockWeb
)
363 dyn_resolver
->addDyn("GET", "/control/addChangeMountPoint", addChangeMountPoint
, lockWeb
);
364 dyn_resolver
->addDyn("GET", "/control/removeMountPoint", removeMountPoint
, lockWeb
);
365 dyn_resolver
->addDyn("GET", "/control/mountPointWindow", mountPointWindow
, lockWeb
);
366 dyn_resolver
->addDyn("GET", "/control/mountMountPoint", mountMountPoint
, lockWeb
);
367 dyn_resolver
->addDyn("GET", "/control/unmountMountPoint", unmountMountPoint
, lockWeb
);
368 dyn_resolver
->addDyn("GET", "/control/selectMovieSource", selectMovieSource
, lockWeb
);