| 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 | }
|
|---|
| 56 | runComp2(header, title, pageheader);
|
|---|
| 57 | unsigned ick;
|
|---|
| 58 | ick = strtoul(ck.c_str(), NULL, 0);
|
|---|
| 59 | if (!okay) {
|
|---|
| 60 | </%cpp>
|
|---|
| 61 | <h1>Management functions</h1>
|
|---|
| 62 | <p>Please choose one of the following management functions.</p><ul>
|
|---|
| 63 | <li><a href="mgmt?op=commit">Commit changes to flash (FWCF)</a></li>
|
|---|
| 64 | <li><a href="version">FWWIF Version Information</a></li>
|
|---|
| 65 | </ul>
|
|---|
| 66 | % } else if (really == "yes" && ick && ick == checkpoint) {
|
|---|
| 67 | <h1><$pagetitle_run$>…</h1>
|
|---|
| 68 | <p>Please wait…</p>
|
|---|
| 69 | <%cpp>
|
|---|
| 70 | int i = 0;
|
|---|
| 71 | const char *s;
|
|---|
| 72 | char *text;
|
|---|
| 73 |
|
|---|
| 74 | if (op == "commit") {
|
|---|
| 75 | s = "fwcf commit";
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | reply.setDirectMode(); // flush output
|
|---|
| 79 |
|
|---|
| 80 | checkpoint = arc4random(); /* prevent re-use */
|
|---|
| 81 | text = c_exec(s, &i);
|
|---|
| 82 | if (i) {
|
|---|
| 83 | reply.out() << "<h1>";
|
|---|
| 84 | reply.sout() << text_wrong;
|
|---|
| 85 | reply.out() << "!</h1>\n<p>" << text_wrong << "</p>\n";
|
|---|
| 86 | } else {
|
|---|
| 87 | reply.out() << "<h1>";
|
|---|
| 88 | reply.sout() << text_ok;
|
|---|
| 89 | reply.out() << ".</h1>\n<p>" << text_ok << "</p>\n";
|
|---|
| 90 | }
|
|---|
| 91 | </%cpp>
|
|---|
| 92 | <p class="blkbeg">The “<$utilname$>” utility returned the following output:</p>
|
|---|
| 93 | <pre class="blkmid">
|
|---|
| 94 | % reply.sout() << text ? (*text ? text : "(no output)") : "(null)";
|
|---|
| 95 | </pre><p class="blkend">The exit code was <$ WEXITSTATUS(i) $>.</p>
|
|---|
| 96 | <p>Go <a href="javascript:back();">back</a> or to the <a href="/">index</a>.</p>
|
|---|
| 97 | <%cpp>
|
|---|
| 98 | } else {
|
|---|
| 99 | do {
|
|---|
| 100 | checkpoint = arc4random(); /* authorisation */
|
|---|
| 101 | } while (!checkpoint);
|
|---|
| 102 |
|
|---|
| 103 | if (op == "commit") {
|
|---|
| 104 | int i;
|
|---|
| 105 | char *changes;
|
|---|
| 106 |
|
|---|
| 107 | changes = c_exec("/sbin/fwcf status", &i);
|
|---|
| 108 | if (changes) {
|
|---|
| 109 | </%cpp>
|
|---|
| 110 | <p class="blkbeg">The following files have been modified:</p>
|
|---|
| 111 | <pre class="blkmid"><$ *changes ? changes : "No files modified." $></pre>
|
|---|
| 112 | <p class="blkend">Do you really want to commit all these changes
|
|---|
| 113 | % free(changes);
|
|---|
| 114 | % } else {
|
|---|
| 115 | <h1>Commit to flash</h1>
|
|---|
| 116 | <p>Do you really want to commit all changes to <tt>/etc</tt>
|
|---|
| 117 | % }
|
|---|
| 118 | into flash to retain them over system reboots?</p>
|
|---|
| 119 | <table width="100%">
|
|---|
| 120 | <tr>
|
|---|
| 121 | <td> </td>
|
|---|
| 122 | <td style="background-color:#00FF00;width:60px;height:32px;font-size:big;text-align:center;"><a
|
|---|
| 123 | href="commit?op=commit&really=yes&ck=<$checkpoint$>">Yes</a></td>
|
|---|
| 124 | <td style="background-color:#FF0000;width:60px;height:32px;font-size:big;text-align:center;"><a
|
|---|
| 125 | href="/">No</a></td>
|
|---|
| 126 | <td> </td>
|
|---|
| 127 | </tr>
|
|---|
| 128 | </table>
|
|---|
| 129 | % }
|
|---|
| 130 | % }
|
|---|
| 131 | <& footer>
|
|---|