| 1 | <#
|
|---|
| 2 | # The FreeWRT Webinterface
|
|---|
| 3 | #-
|
|---|
| 4 | # Copyright © 2007
|
|---|
| 5 | # Thorsten Glaser <tg@mirbsd.de>
|
|---|
| 6 | #
|
|---|
| 7 | # Provided that these terms and disclaimer and all copyright notices
|
|---|
| 8 | # are retained or reproduced in an accompanying document, permission
|
|---|
| 9 | # is granted to deal in this work without restriction, including un-
|
|---|
| 10 | # limited rights to use, publicly perform, distribute, sell, modify,
|
|---|
| 11 | # merge, give away, or sublicence.
|
|---|
| 12 | #
|
|---|
| 13 | # Advertising materials mentioning features or use of this work must
|
|---|
| 14 | # display the following acknowledgement:
|
|---|
| 15 | # This product includes material provided by Thorsten Glaser.
|
|---|
| 16 | #
|
|---|
| 17 | # This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
|
|---|
| 18 | # the utmost extent permitted by applicable law, neither express nor
|
|---|
| 19 | # implied; without malicious intent or gross negligence. In no event
|
|---|
| 20 | # may a licensor, author or contributor be held liable for indirect,
|
|---|
| 21 | # direct, other damage, loss, or other issues arising in any way out
|
|---|
| 22 | # of dealing in the work, even if advised of the possibility of such
|
|---|
| 23 | # damage or existence of a defect, except proven that it results out
|
|---|
| 24 | # of said person's immediate fault when using the work as intended.
|
|---|
| 25 | #><%pre>
|
|---|
| 26 | #include "common.h"
|
|---|
| 27 | #include <stdlib.h>
|
|---|
| 28 | #include "c_exec.h"
|
|---|
| 29 | __RCSID("$Id$");
|
|---|
| 30 | </%pre>
|
|---|
| 31 | <%args>
|
|---|
| 32 | really;
|
|---|
| 33 | ck;
|
|---|
| 34 | op;
|
|---|
| 35 | </%args>
|
|---|
| 36 | <%application>
|
|---|
| 37 | unsigned checkpoint;
|
|---|
| 38 | </%application>
|
|---|
| 39 | <%cpp>
|
|---|
| 40 | bool okay = false;
|
|---|
| 41 | std::string pageheader = "management";
|
|---|
| 42 | std::string pagetitle_run, pagetitle_wrong, pagetitle_ok, utilname;
|
|---|
| 43 | std::string text_wrong, text_ok; /* HTML ok in these */
|
|---|
| 44 | if (op == "commit") {
|
|---|
| 45 | pageheader = "commit to fwcf (flash)";
|
|---|
| 46 | pagetitle_run = "Committing to flash";
|
|---|
| 47 | pagetitle_wrong = "Commit failed";
|
|---|
| 48 | text_wrong = "Committing to flash failed.";
|
|---|
| 49 | pagetitle_ok = "Committed successfully";
|
|---|
| 50 | text_ok = "The changes to <tt>/etc</tt> were ";
|
|---|
| 51 | text_ok += "successfully committed to flash using the ";
|
|---|
| 52 | text_ok += "FreeWRT Configuration Filesystem.";
|
|---|
| 53 | utilname = "fwcf commit";
|
|---|
| 54 | okay = true;
|
|---|
| 55 | } else if (op == "reload") {
|
|---|
| 56 | pageheader = "reload webinterface";
|
|---|
| 57 | pagetitle_run = "Reloading webinterface";
|
|---|
| 58 | pagetitle_wrong = "Reload failed";
|
|---|
| 59 | text_wrong = "Reloading webinterface failed.";
|
|---|
| 60 | pagetitle_ok = "Reloaded successfully";
|
|---|
| 61 | text_ok = "The webinterface was reloaded.";
|
|---|
| 62 | utilname = "/etc/init.d/fwwif restart";
|
|---|
| 63 | okay = true;
|
|---|
| 64 | } else if (op == "reboot") {
|
|---|
| 65 | pageheader = "reboot";
|
|---|
| 66 | pagetitle_run = "Rebooting";
|
|---|
| 67 | pagetitle_wrong = "Reboot failed";
|
|---|
| 68 | text_wrong = "Reboot failed.";
|
|---|
| 69 | pagetitle_ok = "Rebooted successfully";
|
|---|
| 70 | text_ok = "The embedded system was rebooted.";
|
|---|
| 71 | utilname = "/bin/busybox reboot";
|
|---|
| 72 | okay = true;
|
|---|
| 73 | }
|
|---|
| 74 | runComp2(header, title, pageheader);
|
|---|
| 75 | unsigned ick;
|
|---|
| 76 | ick = strtoul(ck.c_str(), NULL, 0);
|
|---|
| 77 | if (!okay) {
|
|---|
| 78 | </%cpp>
|
|---|
| 79 | <h1>Management functions</h1>
|
|---|
| 80 | <p>Please choose one of the following management functions.</p><ul>
|
|---|
| 81 | <li><a href="mgmt?op=commit">Commit changes to flash</a> (FWCF)</li>
|
|---|
| 82 | <li><a href="mgmt?op=reload">Reload webinterface</a> (FWWIF)</li>
|
|---|
| 83 | <li><a href="mgmt?op=reboot">Reboot embedded system</a> (FreeWRT)</li>
|
|---|
| 84 | <li><a href="version">version information</a> (FWWIF)</li>
|
|---|
| 85 | </ul>
|
|---|
| 86 | % } else if (really == "yes" && ick && ick == checkpoint) {
|
|---|
| 87 | <h1><$pagetitle_run$>…</h1>
|
|---|
| 88 | <p>Please wait…</p>
|
|---|
| 89 | <%cpp>
|
|---|
| 90 | int i = 0;
|
|---|
| 91 | char *text;
|
|---|
| 92 |
|
|---|
| 93 | reply.setDirectMode(); // flush output
|
|---|
| 94 |
|
|---|
| 95 | checkpoint = arc4random(); /* prevent re-use */
|
|---|
| 96 | text = c_exec(utilname.c_str(), &i);
|
|---|
| 97 | if (i) {
|
|---|
| 98 | reply.out() << "<h1>";
|
|---|
| 99 | reply.sout() << text_wrong;
|
|---|
| 100 | reply.out() << "!</h1>\n<p>" << text_wrong << "</p>\n";
|
|---|
| 101 | } else {
|
|---|
| 102 | reply.out() << "<h1>";
|
|---|
| 103 | reply.sout() << text_ok;
|
|---|
| 104 | reply.out() << ".</h1>\n<p>" << text_ok << "</p>\n";
|
|---|
| 105 | }
|
|---|
| 106 | </%cpp>
|
|---|
| 107 | <p class="blkbeg">The “<$utilname$>” utility returned the following output:</p>
|
|---|
| 108 | <pre class="blkmid">
|
|---|
| 109 | % reply.sout() << text ? (*text ? text : "(no output)") : "(null)";
|
|---|
| 110 | </pre><p class="blkend">The exit code was <$ WEXITSTATUS(i) $>.</p>
|
|---|
| 111 | <p>Go <a href="javascript:back();">back</a> or to the <a href="/">index</a>.</p>
|
|---|
| 112 | <%cpp>
|
|---|
| 113 | } else {
|
|---|
| 114 | do {
|
|---|
| 115 | checkpoint = arc4random(); /* authorisation */
|
|---|
| 116 | } while (!checkpoint);
|
|---|
| 117 |
|
|---|
| 118 | if (op == "commit" || op == "reboot") {
|
|---|
| 119 | int i;
|
|---|
| 120 | char *changes;
|
|---|
| 121 |
|
|---|
| 122 | changes = c_exec("/sbin/fwcf status", &i);
|
|---|
| 123 | </%cpp>
|
|---|
| 124 | % if (op == "commit") {
|
|---|
| 125 | <h1>Commit to flash</h1>
|
|---|
| 126 | % } else if (op == "reboot") {
|
|---|
| 127 | <h1>Reboot embedded system</h1>
|
|---|
| 128 | % }
|
|---|
| 129 | % if (changes) {
|
|---|
| 130 | <p class="blkbeg">The following files have been modified:</p>
|
|---|
| 131 | <pre class="blkmid"><$ *changes ? changes : "No files modified." $></pre>
|
|---|
| 132 | % if (op == "commit") {
|
|---|
| 133 | <p class="blkend">Do you really want to commit all these changes
|
|---|
| 134 | into flash to retain them over system reboots?</p>
|
|---|
| 135 | % } else if (op == "reboot") {
|
|---|
| 136 | <p class="blkend">Do you really want to reboot without saving these changes?</p>
|
|---|
| 137 | % }
|
|---|
| 138 | % free(changes);
|
|---|
| 139 | % } else {
|
|---|
| 140 | <p>Do you really want to commit all changes to <tt>/etc</tt>
|
|---|
| 141 | into flash to retain them over system reboots?</p>
|
|---|
| 142 | % }
|
|---|
| 143 | % } else if (op == "reload") {
|
|---|
| 144 | <h1>Reload the webinterface</h1>
|
|---|
| 145 | <p>Do you really want to stop and restart the webinterface?</p>
|
|---|
| 146 | % }
|
|---|
| 147 | <table width="100%">
|
|---|
| 148 | <tr>
|
|---|
| 149 | <td> </td>
|
|---|
| 150 | <td style="background-color:#00FF00;width:60px;height:32px;font-size:big;text-align:center;"><a
|
|---|
| 151 | href="commit?op=<$op$>&really=yes&ck=<$checkpoint$>">Yes</a></td>
|
|---|
| 152 | <td style="background-color:#FF0000;width:60px;height:32px;font-size:big;text-align:center;"><a
|
|---|
| 153 | href="/">No</a></td>
|
|---|
| 154 | <td> </td>
|
|---|
| 155 | </tr>
|
|---|
| 156 | </table>
|
|---|
| 157 | % }
|
|---|
| 158 | <& footer>
|
|---|