dnsmasq: stay close as possible to master branch
[tomato.git] / release / src-rt-6.x.4708 / router / httpd / nocat.c
blob7c961c9fb68bc6102cfee435165f0eb334f72542
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 NVRAMCMD "nvram"
19 void wi_uploadsplash(char *url, int len, char *boundary)
21 char *buf;
22 char *p;
23 const char *error;
24 int ok;
25 int n;
26 char tmp[255];
28 // check_id();
31 tmp[0] = 0;
32 buf = NULL;
33 error = "Error reading file";
34 ok = 0;
36 if (!skip_header(&len)) {
37 goto ERROR;
40 if ((len < 64) || (len > (NVRAM_SPACE * 2))) {
41 error = "Invalid file";
42 goto ERROR;
45 if ((buf = malloc(len)) == NULL) {
46 error = "Not enough memory";
47 goto ERROR;
50 n = web_read(buf, len);
51 len -= n;
52 n = n - strlen(boundary)-6;
53 syslog(LOG_INFO, "boundary %s, len %d", boundary, strlen(boundary));
54 if ((p = nvram_get("NC_DocumentRoot")) == NULL) p = "/tmp/splashd";
55 sprintf(tmp, "%s/splash.html", p);
56 if (f_write(tmp, buf, n, 0, 0600) != n) {
57 error = "Error writing temporary file";
58 goto ERROR;
61 nvram_set_file("NC_SplashFile", tmp, 8192);
62 nvram_commit();
63 rboot = 1;
65 error = NULL;
67 ERROR:
68 free(buf);
69 if (error != NULL) resmsg_set(error);
70 web_eat(len);
73 void wo_uploadsplash(char *url)
75 if (rboot) {
76 redirect("/new-splashd.asp");
77 exit(0);
79 else {
80 parse_asp("error.asp");