From 5529a38063649943d881a64be1f641fb8d731f8d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zden=C4=9Bk=20=C5=A0ustr?= Date: Wed, 1 Aug 2012 13:02:29 +0000 Subject: [PATCH] Initial support for included HTML styles - untested --- org.glite.lb.common/interface/context-int.h | 2 ++ org.glite.lb.common/src/context.c | 2 ++ org.glite.lb.server/src/bkserverd.c | 25 ++++++++++++++++++++++++- org.glite.lb.server/src/lb_html.c | 12 ++++++++---- 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/org.glite.lb.common/interface/context-int.h b/org.glite.lb.common/interface/context-int.h index 265fe51..13ab3fd 100644 --- a/org.glite.lb.common/interface/context-int.h +++ b/org.glite.lb.common/interface/context-int.h @@ -186,6 +186,8 @@ glite_lb_padded_struct(_edg_wll_Context,150, int count_server_stats; char *authz_policy_file; + + char *html_header_file; ) /* to be used internally: set, update and and clear the error information in diff --git a/org.glite.lb.common/src/context.c b/org.glite.lb.common/src/context.c index 49ffd5b..47aaa51 100644 --- a/org.glite.lb.common/src/context.c +++ b/org.glite.lb.common/src/context.c @@ -212,6 +212,8 @@ void edg_wll_FreeContext(edg_wll_Context ctx) if (ctx->authz_policy_file) free(ctx->authz_policy_file); + if (ctx->html_header_file) free(ctx->html_header_file); + edg_wll_FreeParams(ctx); free(ctx); diff --git a/org.glite.lb.server/src/bkserverd.c b/org.glite.lb.server/src/bkserverd.c index b833491..956b847 100644 --- a/org.glite.lb.server/src/bkserverd.c +++ b/org.glite.lb.server/src/bkserverd.c @@ -185,6 +185,8 @@ struct _edg_wll_authz_policy authz_policy = { NULL, 0}; static int exclusive_zombies = 1; static char **msg_brokers = NULL; static char **msg_prefixes = NULL; +char * html_header = NULL; +static int html_header_forced = 0; static struct option opts[] = { @@ -211,6 +213,7 @@ static struct option opts[] = { {"super-user", 1, NULL, 'R'}, // {"super-users-file", 1, NULL,'F'}, {"msg-conf", 1, NULL,'F'}, + {"html-header", 1, NULL,'H'}, {"no-index", 1, NULL, 'x'}, {"strict-locking",0, NULL, 'O'}, {"limits", 1, NULL, 'L'}, @@ -239,7 +242,7 @@ static struct option opts[] = { {NULL,0,NULL,0} }; -static const char *get_opt_string = "Ac:k:C:V:p:a:drm:ns:i:S:D:J:jR:F:xOL:N:X:Y:T:t:e:f:zb:gPBo:q:W:Z:GI:l:E" +static const char *get_opt_string = "Ac:k:C:V:p:a:drm:ns:i:S:D:J:jR:F:xOL:N:X:Y:T:t:e:f:zb:gPBo:q:W:Z:GI:l:EH:" #ifdef GLITE_LB_SERVER_WITH_WS "w:" #endif @@ -302,6 +305,7 @@ static void usage(char *me) "\t-l,--policy\tauthorization policy file\n" "\t-E,--exclusive-zombies-off\twith 'exclusive' flag, allow reusing IDs of purged jobs\n" "\t-F,--msg-conf\t path to configuration file with messaging settings\n" + "\t-H,--html-header\t path to HTML header file for customized/branded HTML output\n" ,me); } @@ -481,6 +485,7 @@ int main(int argc, char *argv[]) case 'i': strcpy(pidfile,optarg); pidfile_forced = 1; break; case 'R': add_root(ctx, optarg, ADMIN_ACCESS); break; case 'F': msg_conf = strdup(optarg); break; + case 'H': html_header = strdup(optarg); html_header_forced = 1; break; case 'x': noIndex = atoi(optarg); if (noIndex < 0 || noIndex > 2) { usage(name); return 1; } break; @@ -580,6 +585,24 @@ int main(int argc, char *argv[]) return 1; } + if (!html_header) { + char *html_header_prefix = getenv("GLITE_LB_LOCATION_ETC"); + if (!html_header_prefix) html_header_prefix=strdup("/etc/glite-lb"); + asprintf(&html_header, "%s/html_header.html", html_header_prefix); + free(html_header_prefix); + } + if (html_header) { + char *et, *ed; + FILE *fp = fopen("file","r"); + if( fp ) { + fclose(fp); + glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_DEBUG, "Using HTML header file %s", html_header); + } else { + glite_common_log(LOG_CATEGORY_CONTROL, html_header_forced ? LOG_PRIORITY_ERROR : LOG_PRIORITY_INFO, "Cannot open HTML header file %s", html_header); + } + ctx->html_header_file=html_header; + } + if (msg_conf) { int retv_msg; glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_DEBUG, "Parsing MSG conf file: %s", msg_conf); diff --git a/org.glite.lb.server/src/lb_html.c b/org.glite.lb.server/src/lb_html.c index aca66ed..fa3858f 100644 --- a/org.glite.lb.server/src/lb_html.c +++ b/org.glite.lb.server/src/lb_html.c @@ -61,10 +61,10 @@ int jobstat_cmp (const void *a, const void *b) { /* construct Message-Body of Response-Line for edg_wll_UserJobs */ int edg_wll_UserInfoToHTML(edg_wll_Context ctx UNUSED_VAR, edg_wlc_JobId *jobsOut, edg_wll_JobStat *statsOut, char **message, int text) { - char *pomA = NULL, *pomB, *pomC; + char *pomA = NULL, *pomB, *pomC, *header = NULL; int i, total = 0, bufsize, written = 0, linlen, wassub = 0, lineoverhead; JobIdSorter *order; - + FILE *header_file; while (jobsOut && jobsOut[total]) total++; @@ -84,9 +84,13 @@ int edg_wll_UserInfoToHTML(edg_wll_Context ctx UNUSED_VAR, edg_wlc_JobId *jobsOu } else { qsort(order, total, sizeof(JobIdSorter), jobstat_cmp); + + if (header_file = fopen(ctx->html_header_file, "r")) getdelim( &header, 0, '\0', header_file); - linlen = asprintf(&pomA, "\n\nUser Jobs\n\n" - "

User Jobs

\nTotal of %d