4 Copyright (C) 2006-2009 Jonathan Zarate
15 #include <sys/reboot.h>
20 #define NVRAMCMD "/tmp/nvram"
22 #define NVRAMCMD "nvram"
25 void wo_defaults(char *url
)
30 if ((v
= webcgi_get("mode")) != NULL
) {
32 if ((mode
== 1) || (mode
== 2)) {
35 parse_asp("reboot-default.asp");
38 // disconnect ppp - need this for PPTP/L2TP/PPPOE to finish gracefully
39 killall("xl2tpd", SIGTERM
);
40 killall("pppd", SIGTERM
);
46 // eval(NVRAMCMD, "defaults", "--yes");
47 nvram_set("restore_defaults", "1");
51 eval("mtd-erase", "-d", "nvram");
54 set_action(ACT_REBOOT
);
61 redirect("/admin-config.asp");
64 void wo_backup(char *url
)
68 static char *args
[] = {
69 NVRAMCMD
, "backup", NULL
, NULL
72 strcpy(tmp
, "/tmp/backupXXXXXX");
76 sprintf(msg
, ">%s.msg", tmp
);
78 if (_eval(args
, msg
, 0, NULL
) == 0) {
79 send_header(200, NULL
, mime_binary
, 0);
84 resmsg_fread(msg
+ 1);
85 send_header(200, NULL
, mime_html
, 0);
86 parse_asp("error.asp");
92 void wi_restore(char *url
, int len
, char *boundary
)
104 error
= "Error reading file";
107 if (!skip_header(&len
)) {
111 if ((len
< 64) || (len
> (NVRAM_SPACE
* 2))) {
112 error
= "Invalid file";
116 if ((buf
= malloc(len
)) == NULL
) {
117 error
= "Not enough memory";
121 n
= web_read(buf
, len
);
124 strcpy(tmp
, "/tmp/restoreXXXXXX");
126 if (f_write(tmp
, buf
, n
, 0, 0600) != n
) {
127 error
= "Error writing temporary file";
135 static char *args
[] = {
136 NVRAMCMD
, "restore", NULL
, NULL
141 sprintf(msg
, ">%s.msg", tmp
);
143 if (_eval(args
, msg
, 0, NULL
) != 0) {
144 resmsg_fread(msg
+ 1);
153 if (error
!= NULL
) resmsg_set(error
);
156 if (tmp
[0]) unlink(tmp
);
161 void wo_restore(char *url
)
164 parse_asp("reboot.asp");
167 // disconnect ppp - need this for PPTP/L2TP/PPPOE to finish gracefully
168 killall("xl2tpd", SIGTERM
);
169 killall("pppd", SIGTERM
);
173 cprintf("---reboot=%d\n", rboot
);
175 set_action(ACT_REBOOT
);
183 parse_asp("error.asp");