Changes to update Tomato RAF.
[tomato.git] / release / src / router / httpd / nocat.c
blob2ba3cf28e76d1d69fcf9817fbeb8b168ddf49bf9
1 /*
3 Tomato Firmware
4 Copyright (C) 2006-2008 Jonathan Zarate
6 */
8 #include "tomato.h"
10 #include <fcntl.h>
11 #include <errno.h>
12 #include <sys/stat.h>
13 #include <sys/wait.h>
14 #include <typedefs.h>
15 #include <sys/reboot.h>
17 // #define DEBUG
19 #ifdef DEBUG
20 #define NVRAMCMD "/tmp/nvram"
21 #else
22 #define NVRAMCMD "nvram"
23 #endif
25 void wi_uploadsplash(char *url, int len, char *boundary)
27 char *buf;
28 char *p;
29 const char *error;
30 int ok;
31 int n;
32 char tmp[255];
34 // check_id();
37 tmp[0] = 0;
38 buf = NULL;
39 error = "Error reading file";
40 ok = 0;
42 if (!skip_header(&len)) {
43 goto ERROR;
46 if ((len < 64) || (len > (NVRAM_SPACE * 2))) {
47 error = "Invalid file";
48 goto ERROR;
51 if ((buf = malloc(len)) == NULL) {
52 error = "Not enough memory";
53 goto ERROR;
56 n = web_read(buf, len);
57 len -= n;
58 n = n - strlen(boundary)-6;
59 syslog(LOG_INFO, "boundary %s, len %d", boundary, strlen(boundary));
60 if ((p = nvram_get("NC_DocumentRoot")) == NULL) p = "/tmp/splashd";
61 sprintf(tmp, "%s/splash.html", p);
62 if (f_write(tmp, buf, n, 0, 0600) != n) {
63 error = "Error writing temporary file";
64 goto ERROR;
67 nvram_set_file("NC_SplashFile", tmp, 8192);
68 nvram_commit();
69 rboot = 1;
71 #ifndef DEBUG
72 #endif
73 error = NULL;
75 ERROR:
76 free(buf);
77 if (error != NULL) resmsg_set(error);
78 web_eat(len);
81 void wo_uploadsplash(char *url)
83 if (rboot) {
84 redirect("/new-splashd.asp");
85 exit(0);
87 else {
88 parse_asp("error.asp");