webserver.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /******************************************************************************
  2. # ______ __ __ #
  3. # /\ _ \/\ \__/\ \ #
  4. # __\ \ \L\ \ \ ,_\ \ \___ __ ___ __ #
  5. # /'__`\ \ __ \ \ \/\ \ _ `\ /'__`\/' _ `\ /'__`\ #
  6. # /\ __/\ \ \/\ \ \ \_\ \ \ \ \/\ __//\ \/\ \/\ \L\.\_ #
  7. # \ \____\\ \_\ \_\ \__\\ \_\ \_\ \____\ \_\ \_\ \__/.\_\ #
  8. # \/____/ \/_/\/_/\/__/ \/_/\/_/\/____/\/_/\/_/\/__/\/_/ #
  9. # eAthena Web Server (Second Edition) #
  10. # by MC Cameri #
  11. # ------------------------------------------------------- #
  12. # -Website/Forum- #
  13. # http://eathena.deltaanime.net/ #
  14. # -Download URL- #
  15. # http://eathena.systeminplace.net/ #
  16. # -IRC Channel- #
  17. # irc://irc.deltaanime.net/#athena #
  18. ******************************************************************************/
  19. #include <stdio.h>
  20. #include <strings.h>
  21. #include "../common/showmsg.h"
  22. #include "webserver.h"
  23. char ws_password[17] = "pass";
  24. char ws_header[128] = {'\0'};
  25. /* Displays the eAthena Logo */
  26. void ws_display_title(void)
  27. {
  28. printf("\033[2J");
  29. printf("\033[37;44m (=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=)\033[K\033[0m\n");
  30. printf("\033[0;44m (\033[1;33m (c)2004 eAthena Development Team presents \033[0;44m)\033[K\033[0m\n");
  31. printf("\033[0;44m (\033[1m ______ __ __ \033[0;44m)\033[K\033[0m\n");
  32. printf("\033[0;44m (\033[1m /\\ _ \\/\\ \\__/\\ \\ \033[0;44m)\033[K\033[0m\n");
  33. printf("\033[0;44m (\033[1m __\\ \\ \\_\\ \\ \\ ,_\\ \\ \\___ __ ___ __ \033[0;44m)\033[K\033[0m\n");
  34. printf("\033[0;44m (\033[1m /'__`\\ \\ __ \\ \\ \\/\\ \\ _ `\\ /'__`\\/' _ `\\ /'__`\\ \033[0;44m)\033[K\033[0m\n");
  35. printf("\033[0;44m (\033[1m /\\ __/\\ \\ \\/\\ \\ \\ \\_\\ \\ \\ \\ \\/\\ __//\\ \\/\\ \\/\\ \\_\\.\\_ \033[0;44m)\033[K\033[0m\n");
  36. printf("\033[0;44m (\033[1m \\ \\____\\\\ \\_\\ \\_\\ \\__\\\\ \\_\\ \\_\\ \\____\\ \\_\\ \\_\\ \\__/.\\_\\ \033[0;44m)\033[K\033[0m\n");
  37. printf("\033[0;44m (\033[1m \\/____/ \\/_/\\/_/\\/__/ \\/_/\\/_/\\/____/\\/_/\\/_/\\/__/\\/_/ \033[0;44m)\033[K\033[0m\n");
  38. printf("\033[0;44m (\033[1m _ _ _ _ _ _ _ _ _ _ _ _ _ \033[0;44m)\033[K\033[0m\n"); // 1: bold char, 0: normal char
  39. printf("\033[0;44m (\033[1m / \\ / \\ / \\ / \\ / \\ / \\ / \\ / \\ / \\ / \\ / \\ / \\ / \\ \033[0;44m)\033[K\033[0m\n"); // 1: bold char, 0: normal char
  40. printf("\033[0;44m (\033[1m ( e | n | g | l | i | s | h ) ( A | t | h | e | n | a ) \033[0;44m)\033[K\033[0m\n"); // 1: bold char, 0: normal char
  41. printf("\033[0;44m (\033[1m \\_/ \\_/ \\_/ \\_/ \\_/ \\_/ \\_/ \\_/ \\_/ \\_/ \\_/ \\_/ \\_/ \033[0;44m)\033[K\033[0m\n"); // 1: bold char, 0: normal char
  42. printf("\033[0;44m (\033[1m \033[0;44m)\033[K\033[0m\n"); // yellow writing (33)
  43. printf("\033[0;44m (\033[1;33m Advanced Fusion Maps (c) 2003-2004 The Fusion Project \033[0;44m)\033[K\033[0m\n"); // yellow writing (33)
  44. printf("\033[37;44m (=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=)\033[K\033[0m\n\n"); // reset color
  45. }
  46. /* Returns a boolean value given character string */
  47. int ws_config_switch(const char *str) {
  48. if (strcmpEx(str, "on") == 0 || strcmpEx(str, "yes") == 0 ||
  49. strcmpEx(str, "oui") == 0 || strcmpEx(str, "ja") == 0 ||
  50. strcmpEx(str, "si") == 0 || strcmpEx(str,"true") == 0)
  51. return 1;
  52. if (strcmpEx(str, "off") == 0 || strcmpEx(str, "no") == 0 ||
  53. strcmpEx(str, "non") == 0 || strcmpEx(str, "nein") == 0 ||
  54. strcmpEx(str, "false") == 0)
  55. return 0;
  56. return atoi(str);
  57. }
  58. /* Reads the eAthena Web Server's configuration file */
  59. int ws_config_read(const char *cfgName)
  60. {
  61. int i;
  62. char line[1024],w1[1024],w2[1024],temp[1024];
  63. FILE *fp;
  64. /* Default values */
  65. config.show_title=0;
  66. config.port=80;
  67. fp=fopen(cfgName,"r");
  68. if(fp==NULL){
  69. snprintf(temp,sizeof(temp),"Could not open \033[1;29m%s\033[0;0m, file not found.\n",cfgName);
  70. ShowMessage(temp,MSG_ERROR);
  71. return 1;
  72. }
  73. while(fgets(line,1020,fp)){
  74. const struct {
  75. char str[128];
  76. int *val;
  77. } data[] ={
  78. //List of variables
  79. { "show_title", &config.show_title },
  80. { "port", &config.port },
  81. };
  82. if((line[0] == '/' && line[1] == '/') || (line[0]=='#') ||
  83. (sscanf(line,"%1023[^:]:%1023[^\n]",w1,w2) !=2))
  84. continue;
  85. for(i=0;i<sizeof(data)/(sizeof(data[0]));i++) {
  86. if(strcmpEx(w1,data[i].str)==0){
  87. *data[i].val=ws_config_switch(w2);
  88. break;
  89. }
  90. }
  91. if(strcmpEx(w1,"import")==0) {
  92. ws_config_read(w2);
  93. continue;
  94. }
  95. if(strcmpEx(w1,"password")==0) {
  96. if (strlen(w2)>16) {
  97. ShowError("The Web Server password is too long, maximum passwor"
  98. "d length is 16 characters.\n");
  99. return 1;
  100. }
  101. strcpy(ws_password,w2);
  102. continue;
  103. }
  104. if(strcmpEx(w1,"header")==0) {
  105. if (strlen(w2)>127) {
  106. ShowError("The Web Server header is too long, maximum header"
  107. "d length is 127 characters.\n");
  108. return 1;
  109. }
  110. strcpy(ws_header,w2);
  111. continue;
  112. }
  113. }
  114. fclose(fp);
  115. //Correct values
  116. if(config.show_title < 0)
  117. config.show_title = 0;
  118. if(config.port < 1 || config.port > 65534)
  119. config.port=80;
  120. return 0;
  121. }
  122. void ws_sigchld_handler(int s)
  123. {
  124. while(wait(NULL) > 0);
  125. }