00001
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "config.h"
00019 #include "defines.h"
00020
00021 #include <stdio.h>
00022 #include <stdlib.h>
00023 #include <string.h>
00024 #include <ctype.h>
00025 #include <time.h>
00026 #include <sys/types.h>
00027
00028 #include "readline.h"
00029 #include "hashlib.h"
00030 #include "utils.h"
00031 #include "configparser.h"
00032 #include "cfcgi.h"
00033 #include "template.h"
00034 #include "clientlib.h"
00035
00036
00037 int ShallFrameset = 0;
00038 u_char *TplFrameset;
00039 u_char *TplBlank;
00040
00041 void gen_tpl_name(u_char buff[256],u_char *tpl) {
00042 t_name_value *vn = cfg_get_value(&fo_default_conf,"TemplateMode");
00043
00044 if(vn) {
00045 snprintf(buff,256,tpl,"tpl_",vn->values[0]);
00046 }
00047 else {
00048 snprintf(buff,256,tpl,"","");
00049 }
00050 }
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064 int execute_filter(t_cf_hash *head,t_configuration *dc,t_configuration *vc) {
00065 u_char buff[256];
00066 u_char *UserName = cf_hash_get(GlobalValues,"UserName",8);
00067 t_name_value *cs = cfg_get_value(dc,"ExternCharset");
00068
00069 if(!ShallFrameset) {
00070 return FLT_DECLINE;
00071 }
00072
00073 if(!head) {
00074 gen_tpl_name(buff,TplFrameset);
00075
00076 if(buff) {
00077 t_name_value *x = cfg_get_value(dc,UserName?"UBaseURL":"BaseURL");
00078 t_cf_template tpl;
00079
00080 printf("Content-Type: text/html; charset=%s\n\n",cs->values[0]);
00081
00082 tpl_cf_init(&tpl,buff);
00083 tpl_cf_setvar(&tpl,"script",x->values[0],strlen(x->values[0]),0);
00084 tpl_cf_setvar(&tpl,"charset",cs->values[0],strlen(cs->values[0]),0);
00085 tpl_cf_parse(&tpl);
00086
00087 tpl_cf_finish(&tpl);
00088 return FLT_EXIT;
00089 }
00090 else {
00091 printf("Content-Type: text/html; charset=%s\n\n",cs->values[0]);
00092 str_error_message("E_TPL_NOT_FOUND",NULL,15);
00093 return FLT_EXIT;
00094 }
00095 }
00096 else {
00097 u_char *action = NULL;
00098 if(head) {
00099 action = cf_cgi_get(head,"a");
00100 }
00101
00102 if(action) {
00103 if(cf_strcmp(action,"b") == 0) {
00104 gen_tpl_name(buff,TplBlank);
00105
00106 printf("Content-Type: text/html; charset=%s\n\n",cs->values[0]);
00107 if(buff) {
00108 t_cf_template tpl;
00109 tpl_cf_init(&tpl,buff);
00110 tpl_cf_setvar(&tpl,"charset",cs->values[0],strlen(cs->values[0]),0);
00111
00112 if(tpl.tpl) {
00113 tpl_cf_parse(&tpl);
00114 tpl_cf_finish(&tpl);
00115 }
00116 else {
00117 printf("Sorry! Could not find template file!\n");
00118 }
00119 }
00120 else {
00121 printf("Sorry! Could not find template file!\n");
00122 }
00123
00124 return FLT_EXIT;
00125 }
00126 else {
00127 if(cf_strcmp(action,"f") == 0) {
00128 cf_hash_entry_delete(head,"a",1);
00129 return FLT_OK;
00130 }
00131 }
00132 }
00133 }
00134
00135 return FLT_DECLINE;
00136 }
00137
00138 int set_cf_variables(t_cf_hash *head,t_configuration *dc,t_configuration *vc,t_cf_template *top,t_cf_template *end) {
00139 if(ShallFrameset) {
00140 tpl_cf_setvar(top,"target","view",4,0);
00141 tpl_cf_setvar(top,"frame","1",1,0);
00142
00143 tpl_cf_setvar(end,"target","view",4,0);
00144
00145 return FLT_OK;
00146 }
00147
00148 return FLT_DECLINE;
00149 }
00150
00151 int set_posting_vars(t_cf_hash *head,t_configuration *dc,t_configuration *vc,t_cl_thread *thr,t_cf_template *tpl) {
00152 if(ShallFrameset) {
00153 tpl_cf_setvar(tpl,"frame","1",1,0);
00154 return FLT_OK;
00155 }
00156
00157 return FLT_DECLINE;
00158 }
00159
00160 int set_list_vars(t_cf_hash *head,t_configuration *dc,t_configuration *vc,t_message *msg,unsigned long long tid,int mode) {
00161 if(ShallFrameset && mode == 0) {
00162 tpl_cf_setvar(&msg->tpl,"target","view",4,0);
00163 return FLT_OK;
00164 }
00165
00166 return FLT_DECLINE;
00167 }
00168
00169 int get_conf(t_configfile *f,t_conf_opt *opt,u_char **args,int argnum) {
00170 ShallFrameset = cf_strcmp(args[0],"yes") == 0 ? 1 : 0;
00171 return 0;
00172 }
00173
00174 int get_tpls(t_configfile *f,t_conf_opt *opt,u_char **args,int argnum) {
00175 TplFrameset = strdup(args[0]);
00176 TplBlank = strdup(args[1]);
00177
00178 return 0;
00179 }
00180
00181 void finish(void) {
00182 if(TplFrameset) free(TplFrameset);
00183 if(TplBlank) free(TplBlank);
00184 }
00185
00186 t_conf_opt config[] = {
00187 { "ShowForumAsFrameset", get_conf, NULL },
00188 { "TemplatesFrameset", get_tpls, NULL },
00189 { NULL, NULL, NULL }
00190 };
00191
00192 t_handler_config handlers[] = {
00193 { INIT_HANDLER, execute_filter },
00194 { VIEW_INIT_HANDLER, set_cf_variables },
00195 { POSTING_HANDLER, set_posting_vars },
00196 { VIEW_LIST_HANDLER, set_list_vars },
00197 { 0, NULL }
00198 };
00199
00200 t_module_config flt_frameset = {
00201 config,
00202 handlers,
00203 NULL,
00204 NULL,
00205 NULL,
00206 finish
00207 };
00208
00209