1 /******************************************************/
2 /* interos Standard Document Header - CGI in C */
3 /******************************************************/
4 /* URIs: https://interos.com/bottom */
5 /* https://www.interos.com/bottom */
7 /* Description: FastCGI for interos bottom toolbar */
8 /* Author: Brent Angeline */
9 /* CGI: FastCGI in ISO/ANSI C */
10 /******************************************************/
12 /* PREPROCESSOR DIRECTIVES */
13 #include "fcgi_stdio.h" /* FCGI_Accept(), fclose(), fgetc(), fopen(), printf() */
14 #include "interos.h" /* DIRECTORY, INT, MAX_PASSWORD_SIZE, PASSWORD_FILE_NAME, SYSTEM_DIRECTORY */
15 #include <stdlib.h> /* free(), getenv(), malloc() */
16 #include <string.h> /* strcat(), strcmp(), strcpy(), strlen() */
17 #include <unistd.h> /* F_OK, access() */
19 /* FUNCTION PROTOTYPE DECLARATIONS */
20 static void RedirectToLoginPanel(void);
21 static void OutputBottom(char *status);
22 static void OutputNewMenuButton(void);
23 static void OutputSettingsMenuButton(void);
24 static void BeginXHTMLOutput(void);
25 static void BeginBottomOutput(void);
26 static void FinishXHTMLOutput(void);
28 /* BEGIN MAIN PROGRAM */
32 while (FCGI_Accept() >= 0) {
34 /* IF COOKIE DATA DOESN'T EXIST OR IS TOO LONG... */
35 if (!getenv("HTTP_COOKIE") || (sizeof(strlen(getenv("HTTP_COOKIE"))) > sizeof(INT))) {
36 /** ERROR | COOKIE DATA DOES NOT EXIST OR IS TOO LONG > REDIRECT TO LOGIN PANEL **/
37 RedirectToLoginPanel();
39 /* OTHERWISE, IF COOKIE DATA DOES EXIST AND IS OF ACCEPTABLE LENGTH... */
42 /* ATTEMPT TO ALLOCATE MEMORY FOR COOKIE VARIABLES */
44 INT cookieLength = strlen(getenv("HTTP_COOKIE"));
45 if ((cookieLength < 1) || !(cookie = malloc(cookieLength + 1))) {
46 /** ERROR | CRUCIAL MEMORY ALLOCATION ERROR FOR COOKIE DATA! > REDIRECT TO LOGIN PANEL **/
47 RedirectToLoginPanel();
50 if (!(variableName = malloc(cookieLength + 1))) {
51 /** ERROR | CANNOT ALLOCATE MEMORY FOR COOKIE VARIABLE NAME > REDIRECT TO LOGIN PANEL **/
52 RedirectToLoginPanel();
55 if (!(variableValue = malloc(cookieLength + 1))) {
56 /** ERROR | CANNOT ALLOCATE MEMORY FOR COOKIE VARIABLE VALUE > REDIRECT TO LOGIN PANEL **/
57 RedirectToLoginPanel();
59 /* IF SUFFICIENT MEMORY FOR COOKIE VARIABLES... */
62 /* PROCESS COOKIE DATA */
63 char *login, *password;
65 login = password = NULL;
67 strcpy(cookie, getenv("HTTP_COOKIE"));
68 while ((c < cookieLength) && (cookie[c] != '\0')) {
70 while ((c < cookieLength) && (cookie[c] != '=') && (cookie[c] != '\0')) {
71 variableName[i] = cookie[c];
75 variableName[i] = '\0';
78 while ((c < cookieLength) && (cookie[c] != ';') && (cookie[c] != '\0')) {
79 variableValue[i] = cookie[c];
83 variableValue[i] = '\0';
85 while ((c < cookieLength) && (cookie[c] == ' ')) {
88 if (!login && !strcmp(variableName, "login")) {
89 if ((login = malloc(strlen(variableValue) + 1)) != 0) {
90 strcpy(login, variableValue);
92 } else if (!password && !strcmp(variableName, "password")) {
93 if ((password = malloc(strlen(variableValue) + 1)) != 0) {
94 strcpy(password, variableValue);
99 /* IF LOGIN VALUE IS MISSING... */
101 /** ERROR | LOGIN VALUE IS MISSING > REDIRECT TO LOGIN PANEL **/
102 RedirectToLoginPanel();
104 /* OTHERWISE, IF LOGIN VALUE EXISTS... */
107 /* VERIFY LOGIN AND PASSWORD */
109 if (!(directory = malloc(strlen(login) + strlen(DIRECTORY) + 1))) {
110 /** ERROR | CANNOT ALLOCATE MEMORY FOR DIRECTORY NAME > REDIRECT TO LOGIN PANEL **/
111 RedirectToLoginPanel();
113 char *systemDirectory;
114 if (!(systemDirectory = malloc(strlen(login) + strlen(SYSTEM_DIRECTORY) + 1))) {
115 /** ERROR | CANNOT ALLOCATE MEMORY FOR SYSTEM DIRECTORY NAME > REDIRECT TO LOGIN PANEL **/
116 RedirectToLoginPanel();
118 strcpy(directory, DIRECTORY);
119 strcat(directory, login);
120 strcpy(systemDirectory, SYSTEM_DIRECTORY);
121 strcat(systemDirectory, login);
123 /* IF DIRECTORY CAN'T BE ACCESSED... */
124 if (access(directory, F_OK) || access(systemDirectory, F_OK)) {
125 /** ERROR | CANNOT ACCESS DIRECTORY > REDIRECT TO LOGIN PANEL **/
126 RedirectToLoginPanel();
128 /* OTHERWISE, IF DIRECTORY CAN BE ACCESSED... */
131 /* ATTEMPT TO ACCESS PASSWORD FILE */
132 char *passwordFileName;
133 if (!(passwordFileName = malloc(strlen(systemDirectory) + strlen(PASSWORD_FILE_NAME) + 1))) {
134 /** ERROR | CANNOT ALLOCATE MEMORY FOR FILE NAME > REDIRECT TO LOGIN PANEL **/
135 RedirectToLoginPanel();
137 strcpy(passwordFileName, systemDirectory);
138 strcat(passwordFileName, PASSWORD_FILE_NAME);
140 /* IF PASSWORD FILE CAN'T BE ACCESSED... */
141 if (access(passwordFileName, F_OK)) {
142 /** ERROR | CANNOT ACCESS FILE > REDIRECT TO LOGIN PANEL **/
143 RedirectToLoginPanel();
145 /* OTHERWISE, IF PASSWORD FILE CAN BE ACCESSED... */
148 /* ATTEMPT TO OPEN PASSWORD FILE FOR READING */
151 /* IF PASSWORD FILE CAN'T BE OPENED FOR READING... */
152 if (!(passwordFile = fopen(passwordFileName, "r"))) {
153 /** ERROR | CANNOT READ FILE > REDIRECT TO LOGIN PANEL **/
154 RedirectToLoginPanel();
156 /* OTHERWISE, IF PASSWORD FILE CAN BE OPENED FOR READING... */
159 if (!(filePassword = malloc(MAX_PASSWORD_SIZE + 1))) {
160 /** ERROR | CANNOT ALLOCATE MEMORY FOR PASSWORD FROM FILE > REDIRECT TO LOGIN PANEL **/
161 RedirectToLoginPanel();
166 /* READ PASSWORD FROM PASSWORD FILE */
167 while (((c = fgetc(passwordFile)) != '\n') && (i < MAX_PASSWORD_SIZE)) {
171 filePassword[i] = '\0';
172 fclose(passwordFile);
174 /* IF PASSWORD FAILS COMPARISON... */
175 if (strcmp(filePassword, password)) {
176 /** ERROR | PASSWORD FAILED > REDIRECT TO LOGIN PANEL **/
177 RedirectToLoginPanel();
179 /* OTHERWISE, IF PASSWORD PASSES COMPARISON... */
182 /* LOAD SETTINGS VALUES FROM FILES */
184 /* LOAD interos BOTTOM COMPONENTS FROM FILES */
186 /* DECLARE AND INITIALIZE QUERY VARIABLES */
187 char *status, *button;
188 status = button = NULL;
190 /* IF QUERY DATA EXISTS AND IS OF ACCEPTABLE LENGTH... */
191 if (getenv("QUERY_STRING") && (sizeof(strlen(getenv("QUERY_STRING"))) <= sizeof(INT))) {
193 INT queryLength = strlen(getenv("QUERY_STRING"));
194 if ((queryLength < 1) || !(query = malloc(queryLength + 1))) {
195 /** ERROR | CRUCIAL MEMORY ALLOCATION ERROR FOR QUERY DATA! > CONTINUE WITHOUT QUERY **/
197 strcpy(query, getenv("QUERY_STRING"));
199 if (!(variableName = malloc(queryLength + 1))) {
200 /** ERROR | CANNOT ALLOCATE MEMORY FOR VARIABLE NAME > CONTINUE WITHOUT QUERY **/
203 if (!(variableValue = malloc(queryLength + 1))) {
204 /** ERROR | CANNOT ALLOCATE MEMORY FOR VARIABLE VALUE > CONTINUE WITHOUT QUERY **/
206 /* IF SUFFICIENT MEMORY FOR QUERY VARIABLES... */
209 /* PROCESS QUERY DATA */
212 while ((q < queryLength) && (query[q] != '\0')) {
213 while ((q < queryLength) && (query[q] != '=') && (query[q] != '\0')) {
214 variableName[i] = query[q];
218 variableName[i] = '\0';
221 while ((query[q] != '&') && (query[q] != '\0')) {
222 variableValue[i] = query[q];
226 variableValue[i] = '\0';
227 if (query[q] != '\0') {
230 if (!status && !strcmp(variableName, "status")) {
231 if ((status = malloc(strlen(variableValue) + 1)) != 0) {
232 strcpy(status, variableValue);
234 } else if (!button && !strcmp(variableName, "button")) {
235 if ((button = malloc(strlen(variableValue) + 1)) != 0) {
236 strcpy(button, variableValue);
246 /* OUTPUT GUI COMPONENT(S) BASED ON VARIABLES */
248 if (!strcmp(button, "new")) {
249 OutputNewMenuButton();
250 } else if (!strcmp(button, "settings")) {
251 OutputSettingsMenuButton();
254 /* OUTPUT XHTML FOR interos BOTTOM BAR */
255 OutputBottom(status);
259 /* OUTPUT XHTML FOR interos BOTTOM BAR */
260 OutputBottom(status);
269 free(passwordFileName);
272 free(systemDirectory);
290 /* FUNCTION | REDIRECT TO LOGIN PANEL */
291 static void RedirectToLoginPanel(void) {
294 printf(" <a href=\"/login\" \n");
295 printf(" target=\"_top\">click here to login for interos bottom toolbar</a>\n");
299 /* FUNCTION | OUTPUT XHTML FOR interos BOTTOM TOOLBAR */
300 static void OutputBottom(char *status) {
303 printf(" <table id=\"bottomToolbar\" width=\"100%%\" \n");
304 printf(" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n");
306 printf(" <td width=\"72\" \n");
307 printf(" height=\"72\"><center>\n");
308 printf(" <a id=\"newButton\" \n");
309 printf(" href=\"/interos?menu=new\" \n");
310 printf(" style=\"padding: 26px 0 27px\" \n");
311 printf(" target=\"_top\"><strong>new</strong></a>\n");
312 printf(" </center></td>\n");
313 printf(" <td><center>\n");
314 printf(" <span class=\"hidden\">|</span> \n");
315 printf(" </center></td>\n");
316 printf(" <td width=\"72\" \n");
317 printf(" height=\"72\"><center>\n");
318 printf(" <a id=\"settingsButton\" \n");
319 printf(" href=\"/interos?menu=settings\" \n");
320 printf(" style=\"padding: 26px 0 27px\" \n");
321 printf(" target=\"_top\"><strong>settings</strong></a>\n");
322 printf(" </center></td>\n");
324 printf(" </table>\n");
328 /* FUNCTION | OUTPUT XHTML FOR NEW MENU BUTTON */
329 static void OutputNewMenuButton(void) {
331 printf(" <!--======================================================-->\n");
332 printf(" <!-- interos Standard Document Header - Markup -->\n");
333 printf(" <!--======================================================-->\n");
334 printf(" <!-- URIs: https://interos.com/bottom?button=new -->\n");
335 printf(" <!-- https://www.interos.com/bottom?button=new -->\n");
336 printf(" <!-- Title: interos new menu button -->\n");
337 printf(" <!-- Author: Brent Angeline -->\n");
338 printf(" <!-- Markup: W3C-Validated XHTML 1.0 Transitional -->\n");
339 printf(" <!--======================================================-->\n");
341 printf(" <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n");
342 printf(" <meta name=\"title\" content=\"interos new menu button\" />\n");
343 printf(" <meta name=\"description\" content=\"button for interos new menu\" />\n");
344 printf(" <meta name=\"author\" content=\"Brent Angeline\" />\n");
345 printf(" <meta name=\"copyright\" \n");
346 printf(" content=\"Copyright © 2001-2010 Brent Angeline and interos LLC\" />\n");
347 printf(" <meta name=\"robots\" content=\"noindex, nofollow, noarchive\" />\n");
348 printf(" <title>interos new menu button</title>\n");
349 printf(" <link rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/favicon.ico\" />\n");
350 printf(" <link rel=\"icon\" type=\"image/gif\" href=\"/images/favicon.gif\" />\n");
351 printf(" <link rel=\"stylesheet\" type=\"text/css\" href=\"/style/main.css\" \n");
352 printf(" media=\"screen, projection\" />\n");
353 printf(" <script type=\"text/javascript\" src=\"/js/bottom.js\"></script>\n");
354 printf(" </head>\n");
355 printf(" <body id=\"body\">\n");
356 printf(" <center>\n");
357 printf(" <table id=\"bottomToolbarFaded\" width=\"100%%\" \n");
358 printf(" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n");
360 printf(" <td width=\"72\" \n");
361 printf(" height=\"72\"><center>\n");
362 printf(" <a id=\"newMenuButton\" \n");
363 printf(" href=\"/main\" \n");
364 printf(" style=\"padding: 26px 0 27px\" \n");
365 printf(" target=\"_top\"><strong>« back</strong></a>\n");
366 printf(" </center></td>\n");
367 printf(" <td><center>\n");
368 printf(" <span class=\"hidden\">|</span> \n");
369 printf(" </center></td>\n");
370 printf(" <td id=\"bottomToolbarCornerFaded\" \n");
371 printf(" width=\"72\" \n");
372 printf(" height=\"72\"><p>\n");
374 printf(" </p></td>\n");
376 printf(" </table>\n");
380 /* FUNCTION | OUTPUT XHTML FOR SETTINGS MENU BUTTON */
381 static void OutputSettingsMenuButton(void) {
383 printf(" <!--===========================================================-->\n");
384 printf(" <!-- interos Standard Document Header - Markup -->\n");
385 printf(" <!--===========================================================-->\n");
386 printf(" <!-- URIs: https://interos.com/bottom?button=settings -->\n");
387 printf(" <!-- https://www.interos.com/bottom?button=settings -->\n");
388 printf(" <!-- Title: interos settings menu button -->\n");
389 printf(" <!-- Author: Brent Angeline -->\n");
390 printf(" <!-- Markup: W3C-Validated XHTML 1.0 Transitional -->\n");
391 printf(" <!--===========================================================-->\n");
393 printf(" <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n");
394 printf(" <meta name=\"title\" content=\"interos settings menu button\" />\n");
395 printf(" <meta name=\"description\" content=\"button for interos settings menu\" />\n");
396 printf(" <meta name=\"author\" content=\"Brent Angeline\" />\n");
397 printf(" <meta name=\"copyright\" \n");
398 printf(" content=\"Copyright © 2001-2010 Brent Angeline and interos LLC\" />\n");
399 printf(" <meta name=\"robots\" content=\"noindex, nofollow, noarchive\" />\n");
400 printf(" <title>interos settings menu button</title>\n");
401 printf(" <link rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/favicon.ico\" />\n");
402 printf(" <link rel=\"icon\" type=\"image/gif\" href=\"/images/favicon.gif\" />\n");
403 printf(" <link rel=\"stylesheet\" type=\"text/css\" href=\"/style/main.css\" \n");
404 printf(" media=\"screen, projection\" />\n");
405 printf(" <script type=\"text/javascript\" src=\"/js/bottom.js\"></script>\n");
406 printf(" </head>\n");
407 printf(" <body id=\"body\">\n");
408 printf(" <center>\n");
409 printf(" <table id=\"bottomToolbarFaded\" width=\"100%%\" \n");
410 printf(" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n");
412 printf(" <td id=\"bottomToolbarCornerFaded\" \n");
413 printf(" width=\"72\" \n");
414 printf(" height=\"72\"><p>\n");
416 printf(" </p></td>\n");
417 printf(" <td><center>\n");
418 printf(" <span class=\"hidden\">|</span> \n");
419 printf(" </center></td>\n");
420 printf(" <td width=\"72\" \n");
421 printf(" height=\"72\"><center>\n");
422 printf(" <a id=\"settingsMenuButton\" \n");
423 printf(" href=\"/main\" \n");
424 printf(" style=\"padding: 26px 0 27px\" \n");
425 printf(" target=\"_top\"><strong>« back</strong></a>\n");
426 printf(" </center></td>\n");
428 printf(" </table>\n");
432 /* FUNCTION | BEGIN XHTML OUTPUT */
433 static void BeginXHTMLOutput(void) {
434 printf("Content-Type: text/html; charset=utf-8\r\n\r\n");
435 printf("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
436 printf("<?xml-stylesheet type=\"text/css\" href=\"/style/main.css\"?>\n");
437 printf("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \n");
438 printf(" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n");
439 printf("<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en-US\" lang=\"en-US\">\n");
442 /* FUNCTION | BEGIN interos BOTTOM TOOLBAR OUTPUT */
443 static void BeginBottomOutput(void) {
444 printf(" <!--=================================================-->\n");
445 printf(" <!-- interos Standard Document Header - Markup -->\n");
446 printf(" <!--=================================================-->\n");
447 printf(" <!-- URIs: https://interos.com/bottom -->\n");
448 printf(" <!-- https://www.interos.com/bottom -->\n");
449 printf(" <!-- Title: interos bottom toolbar -->\n");
450 printf(" <!-- Author: Brent Angeline -->\n");
451 printf(" <!-- Markup: W3C-Validated XHTML 1.0 Transitional -->\n");
452 printf(" <!--=================================================-->\n");
454 printf(" <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n");
455 printf(" <meta name=\"title\" content=\"interos bottom toolbar\" />\n");
456 printf(" <meta name=\"description\" content=\"bottom toolbar for interos\" />\n");
457 printf(" <meta name=\"author\" content=\"Brent Angeline\" />\n");
458 printf(" <meta name=\"copyright\" \n");
459 printf(" content=\"Copyright © 2001-2010 Brent Angeline and interos LLC\" />\n");
460 printf(" <meta name=\"robots\" content=\"noindex, nofollow, noarchive\" />\n");
461 printf(" <title>interos bottom</title>\n");
462 printf(" <link rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/favicon.ico\" />\n");
463 printf(" <link rel=\"icon\" type=\"image/gif\" href=\"/images/favicon.gif\" />\n");
464 printf(" <link rel=\"stylesheet\" type=\"text/css\" href=\"/style/main.css\" \n");
465 printf(" media=\"screen, projection\" />\n");
466 printf(" <script type=\"text/javascript\" src=\"/js/bottom.js\"></script>\n");
467 printf(" </head>\n");
468 printf(" <body id=\"body\">\n");
469 printf(" <center>\n");
472 /* FUNCTION | FINISH XHTML OUTPUT */
473 static void FinishXHTMLOutput(void) {
474 printf(" </center>\n");
475 printf(" </body>\n");
476 printf(" <!--=====================================================================-->\n");
477 printf(" <!-- Copyright and Trademark Statement -->\n");
478 printf(" <!--=====================================================================-->\n");
479 printf(" <!-- -->\n");
480 printf(" <!-- All original textual and graphical site content: -->\n");
481 printf(" <!-- -->\n");
482 printf(" <!-- Copyright 2001-2010 Brent Angeline and interos LLC. All rights -->\n");
483 printf(" <!-- reserved. Reproduction in whole or in part without written -->\n");
484 printf(" <!-- permission is prohibited. interos and the interos logos are -->\n");
485 printf(" <!-- trademarks of Brent Angeline and interos LLC. All other company, -->\n");
486 printf(" <!-- product, and service names mentioned herein may be the properties -->\n");
487 printf(" <!-- of their respective owners. Comments in the interos.org forums -->\n");
488 printf(" <!-- are the properties of their respective authors. All software -->\n");
489 printf(" <!-- developed in the forums is open source and belongs to everyone. -->\n");
490 printf(" <!-- -->\n");
491 printf(" <!--=====================================================================-->\n");
492 printf(" <!-- e-mail: info@interos.com -->\n");
493 printf(" <!--=====================================================================-->\n");
497 /***********************************************************************/
498 /* Copyright and Trademark Statement */
499 /***********************************************************************/
501 /* All original textual and graphical site content: */
503 /* Copyright 2001-2010 Brent Angeline and interos LLC. All rights */
504 /* reserved. Reproduction in whole or in part without written */
505 /* permission is prohibited. interos and the interos logos are */
506 /* trademarks of Brent Angeline and interos LLC. All other company, */
507 /* product, and service names mentioned herein may be the properties */
508 /* of their respective owners. Comments in the interos.org forums */
509 /* are the properties of their respective authors. All software */
510 /* developed in the forums is open source and belongs to everyone. */
512 /***********************************************************************/
513 /* e-mail: info@interos.com */
514 /***********************************************************************/