Initial support for included HTML styles - untested
authorZdeněk Šustr <sustr4@cesnet.cz>
Wed, 1 Aug 2012 13:02:29 +0000 (13:02 +0000)
committerZdeněk Šustr <sustr4@cesnet.cz>
Wed, 1 Aug 2012 13:02:29 +0000 (13:02 +0000)
org.glite.lb.common/interface/context-int.h
org.glite.lb.common/src/context.c
org.glite.lb.server/src/bkserverd.c
org.glite.lb.server/src/lb_html.c

index 265fe51..13ab3fd 100644 (file)
@@ -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 
index 49ffd5b..47aaa51 100644 (file)
@@ -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);
index b833491..956b847 100644 (file)
@@ -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);
index aca66ed..fa3858f 100644 (file)
@@ -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, "<HTML>\n<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\">\n<TITLE>User Jobs</TITLE>\n<BODY>\n"
-                       "<h2><B>User Jobs</B></h2>\nTotal of %d<P><UL>\n",total);
+               linlen = asprintf(&pomA, "<HTML>\n<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\">\n<TITLE>User Jobs</TITLE>\n<HEAD>\n%s\n</HEAD>\n<BODY>\n"
+                       "<h2><B>User Jobs</B></h2>\nTotal of %d<P><UL>\n", header ? header : "", total);
+
+               free(header);
 
                asprintf(&pomC, "</UL>User subject: %s<p>\n"
                        "</BODY>\n</HTML>",