From caba478eb826ec4e0f912d852fcfca10c27d4098 Mon Sep 17 00:00:00 2001 From: nishi Date: Sat, 11 May 2024 00:46:27 +0000 Subject: [PATCH] set environment variable in exec directive git-svn-id: file:///raid/svn-main/nishi-mandshurica/trunk@72 f982e544-4a7d-3444-ad1a-fde59a2a69f1 --- Mandshurica/template.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Mandshurica/template.c b/Mandshurica/template.c index 142e8f5..e57a333 100644 --- a/Mandshurica/template.c +++ b/Mandshurica/template.c @@ -42,6 +42,8 @@ #include #include +extern char** params; + char* mandshurica_parse_template(const char* data, struct ms_param param) { char* webroot = mandshurica_get_param("HTTPRoot"); if(webroot == NULL) webroot = WEBROOT_PREFIX; @@ -127,6 +129,28 @@ char* mandshurica_parse_template(const char* data, struct ms_param param) { free(tmp); } } + } else if(strcmp(op, "exec") == 0) { + /* Kinda dangerous directive */ + if(arg != NULL) { + int j; + for(j = 0; params[j] != NULL; j += 2) { + char* name = mandshurica_strcat("Config_", params[j]); + setenv(name, params[j + 1], 1); + free(name); + } + FILE* proc = popen(arg, "r"); + char buf[513]; + int len; + while(1) { + len = fread(buf, 1, 512, proc); + if(len == 0) break; + buf[len] = 0; + char* tmp = ret; + ret = mandshurica_strcat(tmp, buf); + free(tmp); + } + pclose(proc); + } } else if(strcmp(op, "version") == 0) { char* tmp = ret; ret = mandshurica_strcat(tmp, MANDSHURICA_VERSION); -- 2.43.0