blob: 5044856740ce8e2d8840c30ff9e5f7501de5af87 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
/*
Tomato Firmware
Copyright (C) 2006-2009 Jonathan Zarate
*/
#include "tomato.h"
#include <sys/stat.h>
static const char webMsgFile[] = "/tmp/.webmsg";
void setWebMsg(const char *s)
{
FILE *f;
if (s) {
if ((f = fopen(webMsgFile, "w")) != NULL) {
fputs(s, f);
fclose(f);
}
}
else {
unlink(webMsgFile);
}
}
void getWebMsg(char *s, int max)
{
FILE *f;
int n;
if ((f = fopen(webMsgFile, "r")) != NULL) {
n = fread(s, 1, max - 1, f);
s[n] = 0;
fclose(f);
unlink(webMsgFile);
}
else s[0] = 0;
}
int webMsgExist(void)
{
struct stat st;
return ((stat(webMsgFile, &st) == 0) && (st.st_size > 0));
}
void asp_webmsg(int argc, char **argv)
{
char s[512];
const char *msg = s;
getWebMsg(s, sizeof(s));
if (s[0] == 0) {
if (argc == 0) return;
msg = argv[0];
}
if ((argc >= 2) && (argv[1][0] == '1')) web_putj(msg);
else web_puth(msg);
}
|