2 * $Id: enigma_dyn_boot.cpp,v 1.21 2005/12/28 10:42:06 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/ioctl.h>
35 #include <sys/mount.h>
36 #include <arpa/inet.h>
37 #include <linux/if_ether.h>
41 #include <lib/system/info.h>
42 #include <lib/system/http_dyn.h>
43 #include <enigma_dyn_utils.h>
44 #include <enigma_dyn_boot.h>
45 #include <bootmenue/bmconfig.h>
46 #define INSTIMAGESUPPORT
47 #include <bootmenue/bmimage.h>
48 #include <bootmenue/bmboot.h>
50 extern eString
firmwareLevel(eString versionString
);
54 eString
getSkins(eString skinPath
, eString skinName
, eString mountPoint
)
59 bmgr
.getSkins(skinPath
, mountPoint
);
60 for (unsigned int i
= 0; i
< bmgr
.skinList
.size(); i
++)
62 eString skin
= bmgr
.skinList
[i
];
63 unsigned int pos
= skin
.find_last_of('/');
64 eString name
= skin
.right(skin
.length() - pos
- 1);
65 eString skinPath2
= skin
.left(pos
);
67 skins
= skins
+ "<option value=\"" + skin
+ "\"" + eString((skinName
== name
&& skinPath
== skinPath2
) ? " selected" : "") + ">" + name
+ "</option>";
71 skins
= "<option value=\"" + skinPath
+ "\">none</option>";
80 bool fwInstalled
= false;
87 ifstream
initFile ("/tmp/jffs2/etc/init");
90 while (getline(initFile
, line
, '\n'))
92 if (line
.find("fwpro") != eString::npos
)
94 int pos
= line
.find_first_not_of(" ");
95 fw
= line
[pos
] != '#' && line
[pos
] != ':';
98 if (line
.find("bm.sh") != eString::npos
)
100 int pos
= line
.find_first_not_of(" ");
101 bm
= line
[pos
] != '#' && line
[pos
] != ':';
109 bmgr
.activateMenu("BM");
113 eString menus
= "<option value=\"none\">none</option>";
114 menus
+= "<option value=\"BM\"" + eString((bm
) ? " selected" : "") + ">BootManager</option>";
116 menus
+= "<option value=\"FW\"" + eString((fw
) ? " selected" : "") + ">FlashWizard</option>";
117 result
= readFile(TEMPLATE_DIR
+ "bootMenus.tmp");
118 result
.strReplace("#OPTIONS#", menus
);
120 result
.strReplace("#BMSETTINGSBUTTON#", button(100, "Settings", TOPNAVICOLOR
, "javascript:editBootManagerSettings('')", "#000000"));
122 result
.strReplace("#BMSETTINGSBUTTON#", " ");
129 eString
getInstalledImages()
140 imgs
.load(cfg
.mpoint
, true);
142 for (unsigned int i
= 0; i
< imgs
.imageList
.size(); i
++)
144 eString name
= imgs
.imageList
[i
].name
;
145 eString location
= imgs
.imageList
[i
].location
;
146 eString image
= readFile(TEMPLATE_DIR
+ "image.tmp");
147 image
.strReplace("#NAME#", name
);
148 eString version
= firmwareLevel(getAttribute(location
+ "/.version", "version"));
149 image
.strReplace("#VERSION#", version
);
152 image
.strReplace("#LOCATION#", location
);
153 image
.strReplace("#SETTINGSBUTTON#", button(80, "Settings", GREEN
, "javascript:editImageSettings('" + location
+ "')", "#FFFFFF"));
154 image
.strReplace("#DELETEBUTTON#", button(80, "Delete", RED
, "javascript:deleteImage('" + location
+ "')", "#FFFFFF"));
158 image
.strReplace("#LOCATION#", " ");
159 image
.strReplace("#SETTINGSBUTTON#", " ");
160 image
.strReplace("#DELETEBUTTON#", " ");
166 images
= "<tr><td colspan=\"5\">No images found on selected boot device.</td></tr>";
171 eString
getConfigBoot(void)
173 eString result
= readFile(TEMPLATE_DIR
+ "bootMgr.tmp");
174 result
.strReplace("#MENU#", getMenus());
175 result
.strReplace("#IMAGES#", getInstalledImages());
176 result
.strReplace("#ADDIMAGEBUTTON#", button(100, "Add", GREEN
, "javascript:showAddImageWindow('')", "#FFFFFF"));
181 eString
installImage(eString request
, eString dirpath
, eString opts
, eHTTPConnection
*content
)
192 std::map
<eString
, eString
> opt
= getRequestOptions(opts
, '&');
193 eString sourceImage
= opt
["image"];
194 if (sourceImage
!= "none")
196 eString mountDir
= opt
["target"];
198 mountDir
= cfg
.mpoint
;
199 eString imageName
= opt
["name"];
202 unsigned int pos
= sourceImage
.find_last_of("/");
203 imageName
= sourceImage
.right(sourceImage
.length() - pos
- 1);
204 imageName
= imageName
.left(imageName
.length() - 4);
206 content
->local_header
["Content-Type"]="text/html; charset=utf-8";
208 int rc
= imgs
.add(sourceImage
, imageName
, mountDir
);
210 result
= "<html><head><title>Image installation in process</title></head><body>Enigma will shut down during the installation process and restart once installation is complete.<br><br>Please wait...</body></html>";
212 result
= "<html><head><title>Error during image installation</title></head><body>The image could not be installed due to error: " + eString().sprintf("%d", rc
) + "</body></html>";
215 result
= closeWindow(content
, "", 10);
220 eString
deleteImage(eString request
, eString dirpath
, eString opts
, eHTTPConnection
*content
)
223 std::map
<eString
, eString
> opt
= getRequestOptions(opts
, '&');
224 eString image
= opt
["image"];
226 content
->local_header
["Content-Type"]="text/html; charset=utf-8";
230 return closeWindow(content
, "", 10);
233 eString
editImageSettings(eString request
, eString dirpath
, eString opts
, eHTTPConnection
*content
)
236 std::map
<eString
, eString
> opt
= getRequestOptions(opts
, '&');
237 eString image
= opt
["image"];
239 eString result
= readFile(TEMPLATE_DIR
+ "editImageSettingsWindow.tmp");
241 content
->local_header
["Content-Type"]="text/html; charset=utf-8";
243 bool reload_modules
= (access(eString(image
+ "/lib/modules/2.6.9/.reload_modules").c_str(), R_OK
) == 0);
244 bool fast_boot
= (access(eString(image
+ "/var/etc/.dont_mount_hdd").c_str(), R_OK
) == 0);
245 bool dont_start_dccamd
= (access(eString(image
+ "/var/etc/.dont_start_dccamd").c_str(), R_OK
) == 0);
247 result
.strReplace("#IMAGE#", image
);
248 result
.strReplace("#NAME#", imgs
.getImageName(image
));
249 result
.strReplace("#RELOADMODULES#", (reload_modules
) ? "checked" : "");
250 result
.strReplace("#FASTBOOT#", (fast_boot
) ? "checked" : "");
251 result
.strReplace("#DONTSTARTDCCAMD#", (dont_start_dccamd
) ? "checked" : "");
257 eString
setImageSettings(eString request
, eString dirpath
, eString opts
, eHTTPConnection
*content
)
261 std::map
<eString
, eString
> opt
= getRequestOptions(opts
, '&');
263 content
->local_header
["Content-Type"]="text/html; charset=utf-8";
265 eString image
= opt
["image"];
266 eString name
= opt
["name"];
267 eString reload_modules
= opt
["reload_modules"];
268 eString fast_boot
= opt
["fast_boot"];
269 eString dont_start_dccamd
= opt
["dont_start_dccamd"];
271 imgs
.setImageName(image
, name
);
272 if (reload_modules
== "on")
273 system(eString("touch " + image
+ "/lib/modules/2.6.9/.reload_modules").c_str());
275 system(eString("rm " + image
+ "/lib/modules/2.6.9/.reload_modules").c_str());
277 if (fast_boot
== "on")
278 system(eString("touch " + image
+ "/var/etc/.dont_mount_hdd").c_str());
280 system(eString("rm " + image
+ "/var/etc/.dont_mount_hdd").c_str());
282 if (dont_start_dccamd
== "on")
283 system(eString("touch " + image
+ "/var/etc/.dont_start_dccamd").c_str());
285 system(eString("rm " + image
+ "/var/etc/.dont_start_dccamd").c_str());
290 eString
editBootManagerSettings(eString request
, eString dirpath
, eString opts
, eHTTPConnection
*content
)
292 std::map
<eString
, eString
> opt
= getRequestOptions(opts
, '&');
294 content
->local_header
["Content-Type"]="text/html; charset=utf-8";
303 eString result
= readFile(TEMPLATE_DIR
+ "bootMgrSettings.tmp");
304 result
.strReplace("#SKINOPTIONS#", getSkins(SKINDIR
, cfg
.skinName
, cfg
.mpoint
));
305 result
.strReplace("#MPOINT#", cfg
.mpoint
);
306 result
.strReplace("#SELECTEDENTRY#", cfg
.selectedEntry
);
307 result
.strReplace("#RANDOMSKIN#", cfg
.randomSkin
);
308 result
.strReplace("#TIMEOUTVALUE#", cfg
.timeoutValue
);
309 result
.strReplace("#VIDEOFORMAT#", cfg
.videoFormat
);
310 result
.strReplace("#SKINPATH1#", cfg
.skinPath
);
311 result
.strReplace("#SKINPATH2#", cfg
.mpoint
+ "/boot/skins");
312 result
.strReplace("#SKINNAME#", cfg
.skinName
);
314 result
.strReplace("#BUTTONSUBMIT#", button(100, "Change", TOPNAVICOLOR
, "javascript:submitSettings()", "#000000"));
319 eString
setBootManagerSettings(eString request
, eString dirpath
, eString opts
, eHTTPConnection
*content
)
321 std::map
<eString
, eString
> opt
= getRequestOptions(opts
, '&');
325 content
->local_header
["Content-Type"]="text/html; charset=utf-8";
327 cfg
.mpoint
= opt
["mpoint"];
328 cfg
.selectedEntry
= opt
["selectedEntry"];
329 cfg
.randomSkin
= opt
["randomSkin"];
330 cfg
.timeoutValue
= opt
["timeoutValue"];
331 cfg
.videoFormat
= opt
["videoFormat"];
332 cfg
.skinPath
= opt
["skinPath1"];
333 cfg
.skinName
= opt
["skinName"];
334 unsigned int pos
= cfg
.skinName
.find_last_of("/");
335 if (pos
!= eString::npos
&& pos
> 0)
336 cfg
.skinName
= cfg
.skinName
.right(cfg
.skinName
.length() - pos
- 1);
345 eString
selectBootMenu(eString request
, eString dirpath
, eString opts
, eHTTPConnection
*content
)
348 std::map
<eString
, eString
> opt
= getRequestOptions(opts
, '&');
349 eString menu
= opt
["menu"];
351 content
->local_header
["Content-Type"]="text/html; charset=utf-8";
353 bmgr
.activateMenu(menu
);
355 return closeWindow(content
, "", 10);
358 eString
showAddImageWindow(eString request
, eString dirpath
, eString opts
, eHTTPConnection
*content
)
367 std::map
<eString
, eString
> opt
= getRequestOptions(opts
, '&');
369 content
->local_header
["Content-Type"]="text/html; charset=utf-8";
371 eString result
= readFile(TEMPLATE_DIR
+ "addImageWindow.tmp");
374 if (DIR *p
= opendir(cfg
.mpoint
.c_str()))
376 while (struct dirent
*e
= readdir(p
))
378 eString name
= cfg
.mpoint
+ "/" + e
->d_name
;
381 if (tmp
.find(".IMG") != eString::npos
)
382 images
+= "<option value=\"" + name
+ "\">" + e
->d_name
+ "</option>\n";
387 images
= "<option value=\"none\">none</option>";
389 result
.strReplace("#MPOINT#", cfg
.mpoint
);
390 result
.strReplace("#IMAGES#", images
);
395 void ezapBootManagerInitializeDyn(eHTTPDynPathResolver
*dyn_resolver
, bool lockWeb
)
397 dyn_resolver
->addDyn("GET", "/cgi-bin/installimage", installImage
, lockWeb
);
398 dyn_resolver
->addDyn("GET", "/cgi-bin/deleteimage", deleteImage
, lockWeb
);
399 dyn_resolver
->addDyn("GET", "/cgi-bin/editimagesettings", editImageSettings
, lockWeb
);
400 dyn_resolver
->addDyn("GET", "/cgi-bin/setimagesettings", setImageSettings
, lockWeb
);
401 dyn_resolver
->addDyn("GET", "/cgi-bin/selectbootmenu", selectBootMenu
, lockWeb
);
402 dyn_resolver
->addDyn("GET", "/cgi-bin/showaddimagewindow", showAddImageWindow
, lockWeb
);
403 dyn_resolver
->addDyn("GET", "/cgi-bin/editbootmanagersettings", editBootManagerSettings
, lockWeb
);
404 dyn_resolver
->addDyn("GET", "/cgi-bin/setbootmanagersettings", setBootManagerSettings
, lockWeb
);