2 * $Id: enigma_dyn_conf.cpp,v 1.23 2008/01/30 19:01:42 dbluelle 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
30 #include <sys/types.h>
33 #include <sys/socket.h>
34 #include <sys/ioctl.h>
36 #include <arpa/inet.h>
37 #include <linux/if_ether.h>
43 #include <enigma_main.h>
44 #include <enigma_standby.h>
46 #include <lib/driver/eavswitch.h>
47 #include <lib/dvb/dvb.h>
48 #include <lib/dvb/edvb.h>
49 #include <lib/dvb/epgcache.h>
50 #include <lib/dvb/servicestructure.h>
51 #include <lib/dvb/decoder.h>
52 #include <lib/dvb/dvbservice.h>
53 #include <lib/dvb/service.h>
54 #include <lib/dvb/record.h>
55 #include <lib/dvb/serviceplaylist.h>
57 #include <lib/system/info.h>
58 #include <lib/system/http_dyn.h>
59 #include <lib/system/econfig.h>
60 #include <enigma_dyn.h>
61 #include <enigma_dyn_utils.h>
62 #include <enigma_dyn_conf.h>
63 #include <configfile.h>
67 eString
getConfigSwapFile(void)
70 eString th1
, th2
, th3
, th4
, th5
;
71 eString td1
, td2
, td3
, td4
, td5
;
74 eString procswaps
= readFile("/proc/swaps");
77 result
= readFile(TEMPLATE_DIR
+ "configSwapFile.tmp");
78 std::stringstream tmp
;
80 tmp
>> th1
>> th2
>> th3
>> th4
>> th5
>> td1
>> td2
>> td3
>> td4
>> td5
;
82 result
.strReplace("#TH1#", th1
);
83 result
.strReplace("#TH2#", th2
);
84 result
.strReplace("#TH3#", th3
);
85 result
.strReplace("#TH4#", th4
);
86 result
.strReplace("#TH5#", th5
);
87 result
.strReplace("#TD1#", td1
);
88 result
.strReplace("#TD2#", td2
);
89 result
.strReplace("#TD3#", td3
);
90 result
.strReplace("#TD4#", td4
);
91 result
.strReplace("#TD5#", td5
);
94 result
= "No swap file active.";
96 result
+= readFile(TEMPLATE_DIR
+ "configSwapFileMenu.tmp");
97 eConfig::getInstance()->getKey("/extras/swapfile", swapfile
);
98 char *swapfilename
= 0;
99 eConfig::getInstance()->getKey("/extras/swapfilename", swapfilename
);
100 result
.strReplace("#SWAP#", (swapfile
== 1) ? "checked" : "");
107 result
.strReplace("#SWAPFILE#", rpl
);
108 result
.strReplace("#SWAPFILEBUTTON#", button(100, "Configure", NOCOLOR
, "javascript:configSwapFile()", "#000000"));
113 void deactivateSwapFile(eString swapFile
)
116 cmd
= "swapoff " + swapFile
;
120 void activateSwapFile(eString swapFile
)
122 eString procswaps
= readFile("/proc/swaps");
123 eString th1
, th2
, th3
, th4
, th5
;
124 eString td1
, td2
, td3
, td4
, td5
;
125 std::stringstream tmp
;
127 tmp
>> th1
>> th2
>> th3
>> th4
>> th5
>> td1
>> td2
>> td3
>> td4
>> td5
;
128 if ((td1
!= "") && (td1
!= swapFile
))
129 deactivateSwapFile(td1
);
130 if ((td1
== "") || (td1
!= swapFile
))
132 eString cmd
= "mkswap " + swapFile
;
134 cmd
= "swapon " + swapFile
;
137 system("echo 0 > /proc/sys/vm/swappiness");
140 void setSwapFile(int nextswapfile
, eString nextswapfilename
)
142 eConfig::getInstance()->setKey("/extras/swapfile", nextswapfile
);
143 if (nextswapfile
== 1)
145 eConfig::getInstance()->setKey("/extras/swapfilename", nextswapfilename
.c_str());
146 activateSwapFile(nextswapfilename
);
149 deactivateSwapFile(nextswapfilename
);
152 eString
setConfigSwapFile(eString request
, eString dirpath
, eString opts
, eHTTPConnection
*content
)
154 std::map
<eString
, eString
> opt
= getRequestOptions(opts
, '&');
155 eString swap
= opt
["swap"];
156 eString swapFile
= opt
["swapfile"];
160 if (access(swapFile
.c_str(), W_OK
) != 0)
161 system(eString("dd if=/dev/zero of=" + swapFile
+ " bs=1024 count=32768").c_str());
164 setSwapFile((swap
== "on") ? 1 : 0, swapFile
);
166 return closeWindow(content
, "", 500);
169 void initHDDparms(void)
175 eConfig::getInstance()->getKey("/extras/hdparm-s", ti
);
176 eConfig::getInstance()->getKey("/extras/hdparm-m", ac
);
179 cmd
.sprintf("hdparm -S %d /dev/ide/host0/bus0/target0/lun0/disc", ti
);
184 cmd
.sprintf("hdparm -M %d /dev/ide/host0/bus0/target0/lun0/disc", ac
);
190 eString
getConfigSettings(void)
192 eString result
= readFile(TEMPLATE_DIR
+ "configSettings.tmp");
193 int fastshutdown
= 0;
194 eConfig::getInstance()->getKey("/extras/fastshutdown", fastshutdown
);
196 eConfig::getInstance()->getKey("/extras/showSatPos", showSatPos
);
197 result
.strReplace("#SHOWSATPOS#", (showSatPos
== 1) ? "checked" : "");
199 eConfig::getInstance()->getKey("/enigma/timeroffset", timeroffset
);
200 result
.strReplace("#TIMEROFFSET#", eString().sprintf("%d", timeroffset
));
202 eConfig::getInstance()->getKey("/elitedvb/network/maxmtu", maxmtu
);
203 result
.strReplace("#MAXMTU#", eString().sprintf("%d", maxmtu
));
205 eConfig::getInstance()->getKey("/elitedvb/network/samba", samba
);
206 result
.strReplace("#SAMBA#", (samba
== 1) ? "checked" : "");
208 eConfig::getInstance()->getKey("/ezap/webif/lockWebIf", webLock
);
209 result
.strReplace("#WEBIFLOCK#", (webLock
== 1) ? "checked" : "");
211 eConfig::getInstance()->getKey("/extras/hdparm-s", hddti
);
212 result
.strReplace("#HDDSTANDBY#", eString().sprintf("%d", hddti
/ 12));
214 eConfig::getInstance()->getKey("/extras/hdparm-m", hddac
);
215 result
.strReplace("#HDDACOUSTICS#", eString().sprintf("%d", hddac
));
216 char *audiochannelspriority
=0;
217 eConfig::getInstance()->getKey("/extras/audiochannelspriority", audiochannelspriority
);
219 if ( audiochannelspriority
)
221 rpl
= audiochannelspriority
;
222 free(audiochannelspriority
);
224 result
.strReplace("#AUDIOCHANNELSPRIORITY#", rpl
);
225 char *trustedhosts
=NULL
;
226 eConfig::getInstance()->getKey("/ezap/webif/trustedhosts", trustedhosts
);
233 result
.strReplace("#TRUSTEDHOSTS#", rpl
);
234 char *epgcachepath
=NULL
;
235 eConfig::getInstance()->getKey("/extras/epgcachepath", epgcachepath
);
242 result
.strReplace("#EPGCACHEPATH#", rpl
);
246 eString
setConfigSettings(eString request
, eString dirpath
, eString opts
, eHTTPConnection
*content
)
248 std::map
<eString
, eString
> opt
= getRequestOptions(opts
, '&');
249 eString maxmtu
= opt
["maxmtu"];
250 eString samba
= opt
["samba"];
251 eString hddti
= opt
["hddstandby"];
252 eString hddac
= opt
["hddacoustics"];
253 eString timeroffset
= opt
["timeroffset"];
254 eString showsatpos
= opt
["showsatpos"];
255 eString webiflock
= opt
["webiflock"];
256 eString audiochannelspriority
= opt
["audiochannelspriority"];
257 eString trustedhosts
= opt
["trustedhosts"];
258 eString epgcachepath
= opt
["epgcachepath"];
259 eConfig::getInstance()->setKey("/ezap/webif/trustedhosts", trustedhosts
.c_str());
260 eConfig::getInstance()->setKey("/extras/epgcachepath", epgcachepath
.c_str());
263 eConfig::getInstance()->getKey("/extras/hdparm-s", oldti
);
265 eConfig::getInstance()->getKey("/extras/hdparm-m", oldac
);
267 eConfig::getInstance()->setKey("/elitedvb/network/samba", (samba
== "on" ? 1 : 0));
270 eConfig::getInstance()->getKey("/ezap/webif/lockWebIf", webLock1
);
271 eConfig::getInstance()->setKey("/ezap/webif/lockWebIf", (webiflock
== "on" ? 1 : 0));
273 eConfig::getInstance()->getKey("/ezap/webif/lockWebIf", webLock2
);
274 if (webLock1
!= webLock2
)
275 eZap::getInstance()->reconfigureHTTPServer();
276 eConfig::getInstance()->setKey("/extras/showSatPos", (showsatpos
== "on" ? 1 : 0));
277 eConfig::getInstance()->setKey("/enigma/timeroffset", atoi(timeroffset
.c_str()));
278 eConfig::getInstance()->setKey("/elitedvb/network/maxmtu", atoi(maxmtu
.c_str()));
279 system(eString("/sbin/ifconfig eth0 mtu " + maxmtu
).c_str());
280 if ((atoi(hddti
.c_str()) * 12) != oldti
)
281 eConfig::getInstance()->setKey("/extras/hdparm-s", atoi(hddti
.c_str()) * 12);
282 if (atoi(hddac
.c_str()) != oldac
)
283 eConfig::getInstance()->setKey("/extras/hdparm-m", atoi(hddac
.c_str()));
285 eConfig::getInstance()->setKey("/extras/audiochannelspriority", audiochannelspriority
.c_str());
287 return closeWindow(content
, "", 500);
290 void ezapConfInitializeDyn(eHTTPDynPathResolver
*dyn_resolver
, bool lockWeb
)
292 dyn_resolver
->addDyn("GET", "/cgi-bin/setConfigSwapFile", setConfigSwapFile
, lockWeb
);
293 dyn_resolver
->addDyn("GET", "/cgi-bin/setConfigSettings", setConfigSettings
, lockWeb
);