4G/LTE - add watchdog and more
[tomato.git] / release / src / router / httpd / webmsg.c
blob5044856740ce8e2d8840c30ff9e5f7501de5af87
1 /*
3 Tomato Firmware
4 Copyright (C) 2006-2009 Jonathan Zarate
6 */
8 #include "tomato.h"
10 #include <sys/stat.h>
14 static const char webMsgFile[] = "/tmp/.webmsg";
17 void setWebMsg(const char *s)
19 FILE *f;
20 if (s) {
21 if ((f = fopen(webMsgFile, "w")) != NULL) {
22 fputs(s, f);
23 fclose(f);
26 else {
27 unlink(webMsgFile);
31 void getWebMsg(char *s, int max)
33 FILE *f;
34 int n;
36 if ((f = fopen(webMsgFile, "r")) != NULL) {
37 n = fread(s, 1, max - 1, f);
38 s[n] = 0;
39 fclose(f);
40 unlink(webMsgFile);
42 else s[0] = 0;
45 int webMsgExist(void)
47 struct stat st;
48 return ((stat(webMsgFile, &st) == 0) && (st.st_size > 0));
51 void asp_webmsg(int argc, char **argv)
53 char s[512];
54 const char *msg = s;
56 getWebMsg(s, sizeof(s));
57 if (s[0] == 0) {
58 if (argc == 0) return;
59 msg = argv[0];
61 if ((argc >= 2) && (argv[1][0] == '1')) web_putj(msg);
62 else web_puth(msg);