115 lines
5.5 KiB
Diff
115 lines
5.5 KiB
Diff
Index: libzyutil-1.0/Makefile
|
|
===================================================================
|
|
--- libzyutil-1.0.orig/Makefile 2014-12-31 19:40:45.432372911 +0800
|
|
+++ libzyutil-1.0/Makefile 2014-12-31 19:43:42.692783924 +0800
|
|
@@ -20,7 +20,7 @@
|
|
INC_PATH += $(ALLOWED_INCLUDE_PATHS)
|
|
endif
|
|
|
|
-ZCFLAGS += -DZYXEL=1
|
|
+ZCFLAGS += -DZYXEL=1 -std=gnu99
|
|
LIB_OBJS = common.o flash.o
|
|
|
|
.PHONY : libzyutil
|
|
Index: libzyutil-1.0/common.c
|
|
===================================================================
|
|
--- libzyutil-1.0.orig/common.c 2014-12-31 19:40:45.440372911 +0800
|
|
+++ libzyutil-1.0/common.c 2014-12-31 19:46:35.580038455 +0800
|
|
@@ -531,9 +531,8 @@
|
|
zcfgRet_t zyUtilMailSend(const char *msg) {
|
|
struct json_object *sendObj = NULL;
|
|
struct json_object *value = NULL;
|
|
- const char sysCmd[2084] = {0};
|
|
+ char sysCmd[2084] = {0};
|
|
const char *eventType;
|
|
-
|
|
time_t time_stamp = time(NULL);
|
|
struct tm *tPtr = localtime(&time_stamp);
|
|
|
|
@@ -548,65 +547,30 @@
|
|
//printf("Got message: %s\n", msg);
|
|
sendObj = json_tokener_parse(msg);
|
|
|
|
- printf("Sending Email...\n");
|
|
- value = json_object_object_get(sendObj, "Event");
|
|
- eventType = json_object_get_string(value);
|
|
-
|
|
- printf("%s\n", asctime(tPtr));
|
|
- if(strcmp(eventType, "MAILSEND_EVENT_3G_UP") == 0) {
|
|
- // Fill in the mail content and replace words here.
|
|
- fprintf(mailbody, "3G event\n\n");
|
|
- fprintf(mailbody, "%s\n", json_object_get_string(json_object_object_get(sendObj, "body")));
|
|
- fprintf(mailbody, "\nSend at\t%s", asctime(tPtr));
|
|
- fclose(mailbody);
|
|
-
|
|
- sprintf(sysCmd, "mailsend -f %s -smtp %s -domain %s -t %s -cs \"utf-8\" -starttls -auth -user %s -pass %s -sub \"%s\" "
|
|
- "-mime-type \"text/plain\" -msg-body \"/var/tmp/mailbody\"",
|
|
- json_object_get_string(json_object_object_get(sendObj, "mailfrom")),
|
|
- json_object_get_string(json_object_object_get(sendObj, "SMTP")),
|
|
- json_object_get_string(json_object_object_get(sendObj, "SMTP")),
|
|
- json_object_get_string(json_object_object_get(sendObj, "mailto")),
|
|
- json_object_get_string(json_object_object_get(sendObj, "user")),
|
|
- json_object_get_string(json_object_object_get(sendObj, "pass")),
|
|
- json_object_get_string(json_object_object_get(sendObj, "subject")));
|
|
- } else if(strcmp(eventType, "MAILSEND_EVENT_WIFI_UP") == 0) {
|
|
- // Fill in the mail content and replace words here.
|
|
- fprintf(mailbody, "Wifi event\n\n");
|
|
- fprintf(mailbody, "%s\n", json_object_get_string(json_object_object_get(sendObj, "body")));
|
|
- fprintf(mailbody, "\nSend at\t%s", asctime(tPtr));
|
|
- fclose(mailbody);
|
|
- //system("sed -i \"s/<\\[wifi\\]>/%s/g\" /var/tmp/mailbody", );
|
|
- //system("sed -i \"s/<\\[mac\\]>/%s/g\" /var/tmp/mailbody", );
|
|
-
|
|
- sprintf(sysCmd, "mailsend -f %s -smtp %s -domain %s -t %s -cs \"utf-8\" -starttls -auth -user %s -pass %s -sub \"%s\" "
|
|
- "-mime-type \"text/plain\" -msg-body \"/var/tmp/mailbody\"",
|
|
- json_object_get_string(json_object_object_get(sendObj, "mailfrom")),
|
|
- json_object_get_string(json_object_object_get(sendObj, "SMTP")),
|
|
- json_object_get_string(json_object_object_get(sendObj, "SMTP")),
|
|
- json_object_get_string(json_object_object_get(sendObj, "mailto")),
|
|
- json_object_get_string(json_object_object_get(sendObj, "user")),
|
|
- json_object_get_string(json_object_object_get(sendObj, "pass")),
|
|
- json_object_get_string(json_object_object_get(sendObj, "subject")));
|
|
- } else if(strcmp(eventType, "MAILSEND_EVENT_LOG_ALERT") == 0) {
|
|
- // Fill in the mail content and replace words here.
|
|
- fprintf(mailbody, "This mail was send by Log alert event\n\n");
|
|
- fprintf(mailbody, "%s\n", json_object_get_string(json_object_object_get(sendObj, "body")));
|
|
- fprintf(mailbody, "\nSend at\t%s", asctime(tPtr));
|
|
- fclose(mailbody);
|
|
-
|
|
- sprintf(sysCmd, "mailsend -f %s -smtp %s -domain %s -t %s -cs \"utf-8\" -starttls -auth -user %s -pass %s -sub \"%s\" "
|
|
- "-mime-type \"text/plain\" -msg-body \"/var/tmp/mailbody\"",
|
|
- json_object_get_string(json_object_object_get(sendObj, "mailfrom")),
|
|
- json_object_get_string(json_object_object_get(sendObj, "SMTP")),
|
|
- json_object_get_string(json_object_object_get(sendObj, "SMTP")),
|
|
- json_object_get_string(json_object_object_get(sendObj, "mailto")),
|
|
- json_object_get_string(json_object_object_get(sendObj, "user")),
|
|
- json_object_get_string(json_object_object_get(sendObj, "pass")),
|
|
- json_object_get_string(json_object_object_get(sendObj, "subject")));
|
|
+ fprintf(mailbody, "%s\n", json_object_get_string(json_object_object_get(sendObj, "body")));
|
|
+ fprintf(mailbody, "\nSend at\t%s", asctime(tPtr));
|
|
+ fclose(mailbody);
|
|
+
|
|
+ json_object_object_foreach(sendObj, keys, val) {
|
|
+ if(!strcmp(keys,"body")) continue;
|
|
+ sprintf(sysCmd, "sed -i \"s/\\${%s}/%s/g\" /var/tmp/mailbody", keys, json_object_get_string(val));
|
|
+ system(sysCmd);
|
|
+ memset(sysCmd, 0, sizeof(sysCmd));
|
|
}
|
|
|
|
+ sprintf(sysCmd, "mailsend -f %s -smtp %s -domain %s -t %s -cs \"utf-8\" -starttls -auth -user %s -pass %s -sub \"%s\" "
|
|
+ "-mime-type \"text/plain\" -msg-body \"/var/tmp/mailbody\"",
|
|
+ json_object_get_string(json_object_object_get(sendObj, "mailfrom")),
|
|
+ json_object_get_string(json_object_object_get(sendObj, "SMTP")),
|
|
+ json_object_get_string(json_object_object_get(sendObj, "SMTP")),
|
|
+ json_object_get_string(json_object_object_get(sendObj, "mailto")),
|
|
+ json_object_get_string(json_object_object_get(sendObj, "user")),
|
|
+ json_object_get_string(json_object_object_get(sendObj, "pass")),
|
|
+ json_object_get_string(json_object_object_get(sendObj, "subject")));
|
|
+
|
|
json_object_put(sendObj);
|
|
json_object_put(value);
|
|
+ printf("Sending Email...\n");
|
|
//printf("%s\n", sysCmd);
|
|
system(sysCmd);
|
|
system("rm -f /var/tmp/mailbody");
|