Ejemplo n.º 1
0
/* {{{ flt_cgiconfig_post */
int flt_cgiconfig_post(cf_hash_t *head,cf_configuration_t *cfg,cf_cl_thread_t *thread,cf_template_t *tpl) {
  u_char *UserName = cf_hash_get(GlobalValues,"UserName",8);
  u_char *link;
  cf_string_t *tmp = NULL;

  size_t l;
  int x = UserName ? 1 : 0;

  cf_cfg_config_value_t *cs = cf_cfg_get_value(cfg,"DF:ExternCharset");
  cf_readmode_t *rm = cf_hash_get(GlobalValues,"RM",2);

  cf_cfg_config_value_t *threaded_uri = cf_cfg_get_value(cfg,"DF:PostingURL");
  cf_cfg_config_value_t *list_uri = cf_cfg_get_first_value(cfg,"DF:PostingURL_List");
  cf_cfg_config_value_t *nested_uri = cf_cfg_get_first_value(cfg,"DF:PostingURL_Nested");

  /* {{{ ShowThread links */
  if((tmp = cf_cgi_get(head,"showthread")) != NULL) cf_remove_static_uri_flag("showthread");

  link = cf_advanced_get_link(rm->posting_uri[x],thread->tid,thread->threadmsg->mid,NULL,1,&l,"showthread","part");
  cf_set_variable(tpl,cs,"showthread_part",link,l,1);
  free(link);

  link = cf_advanced_get_link(rm->posting_uri[x],thread->tid,thread->threadmsg->mid,NULL,1,&l,"showthread","none");
  cf_set_variable(tpl,cs,"showthread_none",link,l,1);
  free(link);

  link = cf_advanced_get_link(rm->posting_uri[x],thread->tid,thread->threadmsg->mid,NULL,1,&l,"showthread","full");
  cf_set_variable(tpl,cs,"showthread_full",link,l,1);
  free(link);

  if(tmp) cf_add_static_uri_flag("showthread",tmp->content,0);
  /* }}} */

  /* {{{ ReadMode links */
  if((tmp = cf_cgi_get(head,"readmode")) != NULL) cf_remove_static_uri_flag("readmode");

  link = cf_advanced_get_link(list_uri->avals[x].sval,thread->tid,thread->threadmsg->mid,NULL,1,&l,"readmode","list");
  cf_set_variable(tpl,cs,"readmode_list",link,l,1);
  free(link);

  link = cf_advanced_get_link(nested_uri->avals[x].sval,thread->tid,thread->threadmsg->mid,NULL,1,&l,"readmode","nested");
  cf_set_variable(tpl,cs,"readmode_nested",link,l,1);
  free(link);

  link = cf_advanced_get_link(threaded_uri->avals[x].sval,thread->tid,thread->threadmsg->mid,NULL,1,&l,"readmode","thread");
  cf_set_variable(tpl,cs,"readmode_thread",link,l,1);
  free(link);

  if(tmp) cf_add_static_uri_flag("readmode",tmp->content,0);
  /* }}} */

  return FLT_OK;
}
Ejemplo n.º 2
0
int flt_http_validate(cf_hash_t *head,cf_configuration_t *dc,cf_configuration_t *vc,time_t last_modified,int sock) {
#else
int flt_http_validate(cf_hash_t *head,cf_configuration_t *dc,cf_configuration_t *vc,time_t last_modified,void *sock) {
#endif
  u_char *uname = cf_hash_get(GlobalValues,"UserName",8);
  u_char *uconffile = NULL;
  struct stat st;
  int ret = FLT_DECLINE;

  if(uname) {
    uconffile = cf_get_uconf_name(uname);

    if(uconffile) {
      if(stat(uconffile,&st) != -1) {
        if(st.st_mtime <= last_modified) ret = FLT_OK;
        else {
          printf("X-I-am-it: flt_http\015\012");
          ret = FLT_EXIT;
        }
      }

      free(uconffile);
    }
  }

  return ret;
}
Ejemplo n.º 3
0
/* {{{ flt_phpsessauth_getvar */
u_char *flt_phpsessauth_getvar(const u_char *vname) {
  cf_string_t path;
  int fd,rc;
  cf_hash_t *hash = cf_hash_new(NULL);
  u_char *start,*ptr,*name = NULL;
  struct stat st;

  cf_str_init_growth(&path,128);
  if(flt_phpsessauth_sesspath) cf_str_char_set(&path,flt_phpsessauth_sesspath,strlen(flt_phpsessauth_sesspath));
  else cf_str_char_set(&path,"/tmp",4);

  cf_str_chars_append(&path,"/sess_",6);
  cf_str_chars_append(&path,flt_phpsessauth_sid,strlen(flt_phpsessauth_sid));

  /* {{{ open file and map it into our memory */
  if((fd = open(path.content,O_RDONLY)) == -1) {
    fprintf(stderr,"flt_phpsessauth: open: could not open file '%s': %s\n",path.content,strerror(errno));
    cf_str_cleanup(&path);
    return NULL;
  }

  if(stat(path.content,&st) == -1) {
    fprintf(stderr,"flt_phpsessauth: stat: could not stat file '%s': %s\n",path.content,strerror(errno));
    close(fd);
    cf_str_cleanup(&path);
    return NULL;
  }

  if(st.st_size == 0) {
    fprintf(stderr,"flt_phpsessauth: file '%s' is empty!\n",path.content);
    close(fd);
    cf_str_cleanup(&path);
    return NULL;
  }

  if((caddr_t)(ptr = start = mmap(0,st.st_size+1,PROT_READ,MAP_FILE|MAP_SHARED,fd,0)) == (caddr_t)-1) {
    fprintf(stderr,"flt_phpsessauth: mmap: could not map file '%s': %s\n",path.content,strerror(errno));
    close(fd);
    cf_str_cleanup(&path);
    return NULL;
  }
  /* }}} */

  rc = flt_psa_parser(hash,&ptr);

  munmap(start,st.st_size);
  close(fd);
  cf_str_cleanup(&path);

  if(rc != 0) {
    cf_hash_destroy(hash);
    return NULL;
  }

  name = cf_hash_get(hash,(u_char *)vname,strlen(vname));
  if(name) name = strdup(name);
  cf_hash_destroy(hash);

  return name;
}
Ejemplo n.º 4
0
/* {{{ flt_tplmode_execute */
int flt_tplmode_execute(cf_hash_t *head,cf_configuration_t *dc,cf_configuration_t *vc) {
  cf_name_value_t *v,*v1;
  u_char *forum_name = cf_hash_get(GlobalValues,"FORUM_NAME",10);

  if(TPLMode) {
    v1 = cf_cfg_get_first_value(dc,forum_name,"DF:XHTMLMode");
    v  = cf_cfg_get_first_value(dc,forum_name,"DF:TemplateMode");

    free(v->values[0]);

    v->values[0] = strdup(TPLMode);

    if(strstr(TPLMode,"xhtml")) {
      free(v1->values[0]);
      v1->values[0] = strdup("yes");
    }
    else {
      free(v1->values[0]);
      v1->values[0] = strdup("no");
    }

    return FLT_OK;
  }

  return FLT_DECLINE;
}
Ejemplo n.º 5
0
/* {{{ flt_failsafe_handle_command */
int flt_failsafe_handle_command(cf_configfile_t *cf,cf_conf_opt_t *opt,const u_char *context,u_char **args,size_t argnum) {
  cf_failsafe_t *fl,fl1;
  u_char buff[512];

  if(flt_failsafe_hsh == NULL) flt_failsafe_hsh = cf_hash_new(flt_failsafe_cleanup_hash);

  if(argnum == 1) {
    if((fl = cf_hash_get(flt_failsafe_hsh,(u_char *)context,strlen(context))) == NULL) {
      fl1.BackupFile = strdup(args[0]);

      snprintf(buff,512,"BackupMutex_%s",context);
      cf_mutex_init(buff,&fl1.BackupMutex);

      cf_hash_set(flt_failsafe_hsh,(u_char *)context,strlen(context),&fl1,sizeof(fl1));
    }
    else {
      free(fl->BackupFile);
      fl->BackupFile = strdup(args[0]);
    }
  }
  else {
    cf_log(CF_ERR,__FILE__,__LINE__,"flt_failsafe: expecting one argument for directive BackupFile!\n");
  }

  return 0;
}
Ejemplo n.º 6
0
/* {{{ flt_failsafe_init */
int flt_failsafe_init(int main_socket) {
  FILE *fd;
  struct stat st;
  cf_name_value_t *forums = cf_cfg_get_first_value(&fo_server_conf,NULL,"DF:Forums");
  size_t i;
  cf_failsafe_t *fl;

  for(i=0;i<forums->valnum;++i) {
    fl = cf_hash_get(flt_failsafe_hsh,forums->values[i],strlen(forums->values[i]));

    if(stat(fl->BackupFile,&st) == 0) {
      fprintf(stderr,"flt_failsafe: There is a backup file, perhaps you should run fo_recovery!\n");
      flt_failsafe_error = 1;
      return FLT_EXIT;
    }

    if((fd = fopen(fl->BackupFile,"wb")) == NULL) {
      fprintf(stderr,"flt_failsafe: Could not open BackupFile %s: %s\n",fl->BackupFile,strerror(errno));
      flt_failsafe_error = 1;
      return FLT_EXIT;
    }

    fwrite("CFFS",4,1,fd);
    fwrite(CFFS_VERSION,3,1,fd);
    fclose(fd);
  }

  return FLT_DECLINE;
}
Ejemplo n.º 7
0
int main() {
  CFStack *stack = malloc(sizeof(CFStack));
  CFHashMap *words = cf_hash_new();

  cf_hash_add(words, "+", words_add);
  cf_hash_add(words, "-", words_minus);
  cf_hash_add(words, "*", words_multiply);
  cf_hash_add(words, "/", words_divide);
  cf_hash_add(words, ".", words_print);

  char commands[] = "2 3 + 4 * .";
  char *token = strtok(commands, " ");
  while (token != NULL) {
    ValueType word = cf_hash_get(words, token);
    if (word != NULL) {
      (*word)(stack);
    } else {
      int *entry = malloc(sizeof(int));
      *entry = atoi(token);
      cf_stack_push(stack, entry);
    }

    token = strtok(NULL, " ");
  }

  return 0;
}
Ejemplo n.º 8
0
long flt_http_get_lm(int sock) {
  rline_t tsd;
  u_char *line,buff[512];
  long ret = 0;
  size_t len;
  u_char *forum_name = cf_hash_get(GlobalValues,"FORUM_NAME",10);

  memset(&tsd,0,sizeof(tsd));

  len = snprintf(buff,512,"SELECT %s\n",forum_name);
  writen(sock,buff,len);

  line = readline(sock,&tsd);
  if(!line || ((ret = atoi(line)) != 200)) {
    if(line) free(line);
    return 0;
  }

  ret = 0;
  free(line);

  if(writen(sock,"GET LASTMODIFIED 0\n",19) > 0) {
    if((line = readline(sock,&tsd)) != NULL) {
      ret = strtol(line,NULL,0);
      free(line);
    }
  }

  return ret;
}
Ejemplo n.º 9
0
/* {{{ run_inline_directive_filters */
int cf_run_inline_directive_filters(cf_cfg_config_t *cfg,cf_cl_thread_t *thread,const u_char *directive,const u_char **parameters,cf_string_t *content,cf_string_t *cite,const u_char *qchars,int sig) {
  cf_directive_callback_t *cb;

  if((cb = cf_hash_get(registered_directives,(u_char *)directive,strlen(directive))) == NULL) return FLT_DECLINE;

  if(cb->type & CF_HTML_DIR_TYPE_INLINE) return cb->callback(cfg,thread,directive,parameters,1,NULL,NULL,content,cite,qchars,sig);
  return FLT_DECLINE;
}
Ejemplo n.º 10
0
/* {{{ run_validate_inline */
int cf_run_validate_inline(cf_cfg_config_t *cfg,const u_char *directive,const u_char **parameters,cf_tpl_variable_t *var) {
  cf_validator_callback_t *cb;

  if((cb = cf_hash_get(registered_validators,(u_char *)directive,strlen(directive))) == NULL) return FLT_DECLINE;

  if(cb->type & CF_HTML_DIR_TYPE_INLINE) return cb->callback(cfg,directive,parameters,1,var);
  return FLT_DECLINE;
}
Ejemplo n.º 11
0
int flt_urlrewrite_is_macro_true(flt_urlrewrite_macro_node_t *tree) {
  cf_string_t *data;
  int op_type;
  int *bool_value;

  if(!tree)
    return 0;

  switch(tree->type) {
    case MACRO_NODE_VALUE:
      data = (cf_string_t *)tree->data.ptr_data;
      if(!data->len)
        return 0;
      if(!cf_strcmp(data->content, "true")) {
        return 1;
      } else if(!cf_strcmp(data->content, "logged_in")) {
        return cf_hash_get(GlobalValues,"UserName",8) ? 1 : 0;
      } else {
        bool_value = (int *)cf_hash_get(GlobalValues,data->content,data->len);
        if (!bool_value) {
          return 0;
        } else {
          return *bool_value ? 1 : 0;
        }
      }
      return 0;
      break;
    case MACRO_NODE_OPERATOR: {
      op_type = tree->data.int_data;
      switch(op_type) {
        case MACRO_OP_NOT:
          return !flt_urlrewrite_is_macro_true(tree->right);
        case MACRO_OP_AND:
          return flt_urlrewrite_is_macro_true(tree->left) && flt_urlrewrite_is_macro_true(tree->right);
        case MACRO_OP_OR:
          return flt_urlrewrite_is_macro_true(tree->left) || flt_urlrewrite_is_macro_true(tree->right);
        default:
          return 0;
      }
      break;
    default:
      return 0;
    }
  }
}
Ejemplo n.º 12
0
/* {{{ flt_lf_handle_command */
int flt_lf_handle_command(cf_configfile_t *cf,cf_conf_opt_t *opt,const u_char *context,u_char **args,size_t argnum) {
  if(!flt_lf_fn) flt_lf_fn = cf_hash_get(GlobalValues,"FORUM_NAME",10);
  if(!context || cf_strcmp(flt_lf_fn,context) != 0) return 0;

  if(cf_strcmp(opt->name,"ActivateLiveFilter") == 0) flt_lf_active = cf_strcmp(args[0],"yes") == 0;
  else flt_lf_overwrite = cf_strcmp(args[0],"yes") == 0;

  return 0;
}
Ejemplo n.º 13
0
/* {{{ flt_xmlarc_handle */
int flt_xmlarc_handle(cf_configfile_t *cfile,cf_conf_opt_t *opt,const u_char *context,u_char **args,size_t argnum) {
  if(flt_xmlarc_fn == NULL) flt_xmlarc_fn = cf_hash_get(GlobalValues,"FORUM_NAME",10);
  if(!context || cf_strcmp(flt_xmlarc_fn,context) != 0) return 0;

  if(flt_xmlarc_apath) free(flt_xmlarc_apath);
  flt_xmlarc_apath = strdup(args[0]);

  return 0;
}
Ejemplo n.º 14
0
int flt_urlrewrite_handle(cf_configfile_t *cfile,cf_conf_opt_t *opt,const u_char *context,u_char **args,size_t argnum) {
  flt_urlrewrite_rule_t n_rewrite;
  const u_char *error;
  int err_offset;
  
  if(flt_urlrewrite_fname == NULL) flt_urlrewrite_fname = cf_hash_get(GlobalValues,"FORUM_NAME",10);
  if(!context || cf_strcmp(context,flt_urlrewrite_fname) != 0) return 0;
  
  if(argnum != 3) {
    return -1;
  }
  
  if(!flt_urlrewrite_rules) {
    flt_urlrewrite_rules = cf_alloc(NULL,sizeof(cf_array_t),1,CF_ALLOC_MALLOC);
    cf_array_init(flt_urlrewrite_rules,sizeof(flt_urlrewrite_rule_t),(void(*)(void *))flt_urlrewrite_destroy);
  }
  
  n_rewrite.macro_tree = flt_urlrewrite_parse_macro(args[2]);
  if(!n_rewrite.macro_tree) {
    return -1;
  }

  n_rewrite.replacement = strdup(args[1]);
  if(!n_rewrite.replacement) {
    flt_urlrewrite_free_macro_tree(n_rewrite.macro_tree);
  }

  n_rewrite.regexp = pcre_compile(args[0], 0, (const char **)&error, &err_offset, NULL);
  if(!n_rewrite.regexp) {
    fprintf(stderr,"flt_urlrewrite: Regexp error with \"%s\": %s\n", args[0], error);
    flt_urlrewrite_free_macro_tree(n_rewrite.macro_tree);
    free((void *)n_rewrite.replacement);
    return -1;
  }
  n_rewrite.regexp_extra = pcre_study(n_rewrite.regexp, 0, (const char **)&error);
  if(error) {
    fprintf(stderr,"Regexp study error with \"%s\": %s\n", args[0], error);
    pcre_free(n_rewrite.regexp);
    flt_urlrewrite_free_macro_tree(n_rewrite.macro_tree);
    free((void *)n_rewrite.replacement);
    return -1;
  }
  n_rewrite.match_count = 0;
  pcre_fullinfo(n_rewrite.regexp, n_rewrite.regexp_extra, PCRE_INFO_CAPTURECOUNT, &(n_rewrite.match_count));
  n_rewrite.match_arr = (int *)cf_alloc(NULL, sizeof(int),(n_rewrite.match_count + 1) * 3, CF_ALLOC_MALLOC);
  if(!n_rewrite.match_arr) {
    pcre_free(n_rewrite.regexp_extra);
    pcre_free(n_rewrite.regexp);
    flt_urlrewrite_free_macro_tree(n_rewrite.macro_tree);
    free((void *)n_rewrite.replacement);
    return -1;
  }

  cf_array_push(flt_urlrewrite_rules,&n_rewrite);

  return 0;
}
Ejemplo n.º 15
0
/* {{{ flt_tplmode_handle */
int flt_tplmode_handle(cf_configfile_t *cfile,cf_conf_opt_t *opt,const u_char *context,u_char **args,size_t argnum) {
  if(!flt_tplmode_fn) flt_tplmode_fn = cf_hash_get(GlobalValues,"FORUM_NAME",10);
  if(!context || cf_strcmp(flt_tplmode_fn,context) != 0) return 0;

  if(TPLMode) free(TPLMode);
  TPLMode = strdup(args[0]);

  return 0;
}
Ejemplo n.º 16
0
/* {{{ flt_moderated_handle */
int flt_modated_handle(cf_configfile_t *cfile,cf_conf_opt_t *opt,const u_char *context,u_char **args,size_t argnum) {
  if(flt_modated_fn == NULL) flt_modated_fn = cf_hash_get(GlobalValues,"FORUM_NAME",10);
  if(!context || cf_strcmp(flt_modated_fn,context) != 0) return 0;

  if(cf_strcmp(opt->name,"Moderation") == 0) {
    if(cf_strcmp(args[0],"threads") == 0) flt_moderated_cfg =  FLT_MOD_THREAD;
    else if(cf_strcmp(args[0],"posts") == 0) flt_moderated_cfg = FLT_MOD_POSTS;
  }
  else flt_moderated_dbname = strdup(args[0]);

  return 0;
}
Ejemplo n.º 17
0
/* {{{ cf_html_register_directive */
int cf_html_register_directive(const u_char *name,cf_directive_filter_t filter,int type) {
  cf_directive_callback_t clbck;
  size_t len = strlen(name);

  if(!registered_directives) registered_directives = cf_hash_new(NULL);
  if(cf_hash_get(registered_directives,(u_char *)name,len) != NULL) return -1;

  clbck.type = type;
  clbck.callback = filter;
  cf_hash_set(registered_directives,(u_char *)name,len,&clbck,sizeof(clbck));

  return 0;
}
Ejemplo n.º 18
0
void flt_failsafe_cleaner(forum_t *forum) {
  FILE *fd;
  cf_failsafe_t *fl = cf_hash_get(flt_failsafe_hsh,forum->name,strlen(forum->name));

  /* lock backup mutex */
  CF_LM(&fl->BackupMutex);

  if((fd = fopen(fl->BackupFile,"wb")) != NULL) {
    fwrite("CFFS",4,1,fd);
    fwrite(CFFS_VERSION,3,1,fd);
    fclose(fd);
  }

  CF_UM(&fl->BackupMutex);
}
Ejemplo n.º 19
0
int flt_categorycheck_execute(cf_hash_t *head,cf_configuration_t *cfg,cf_message_t *p,cf_cl_thread_t *thr,int sock,int mode)
#endif
{
  u_char *forum_name = cf_hash_get(GlobalValues,"FORUM_NAME",10);
  cf_cfg_config_value_t *v = cf_cfg_get_value(cfg,"DF:Categories");
  size_t i;

  if(!p->category.len) return FLT_DECLINE;
  for(i=0;i<v->alen;++i) {
    if(cf_strcmp(p->category.content,v->avals[i].sval) == 0) return FLT_OK;
  }

  strcpy(ErrorString,"E_posting_category");
  display_posting_form(head,p,NULL);
  return FLT_EXIT;
}
Ejemplo n.º 20
0
/* {{{ flt_mod_setlinks */
void flt_mod_setlinks(cf_tpl_variable_t *tpl,int ret,u_int64_t tid,u_int64_t mid) {
  cf_readmode_t *rm = cf_hash_get(GlobalValues,"RM",2);
  u_char *link;
  size_t l;

  if(ret == 0) {
    link = cf_advanced_get_link(rm->posting_uri[1],tid,mid,NULL,1,&l,"a","unapprove");
    cf_tpl_hashvar_setvalue(tpl,"unapprove_link",TPL_VARIABLE_STRING,link,l);
    free(link);
  }
  else {
    link = cf_advanced_get_link(rm->posting_uri[1],tid,mid,NULL,1,&l,"a","approve");
    cf_tpl_hashvar_setvalue(tpl,"approve_link",TPL_VARIABLE_STRING,link,l);
    free(link);
  }
}
Ejemplo n.º 21
0
/* {{{ flt_httpauth_run */
int flt_httpauth_run(cf_hash_t *head,cf_configuration_t *dc,cf_configuration_t *vc) {
    u_char *forum_name = cf_hash_get(GlobalValues,"FORUM_NAME",10);
    cf_name_value_t *v = cf_cfg_get_first_value(dc,forum_name,"DF:AuthMode");
    u_char *name,*path;

    if(!v || !v->values[0] || cf_strcmp(v->values[0],"http") != 0) return FLT_DECLINE;

    name = getenv("REMOTE_USER");
    if(name) {
        path = cf_get_uconf_name(name);

        if(path) {
            free(path);
            cf_hash_set(GlobalValues,"UserName",8,name,strlen(name)+1);
        }
    }

    return FLT_OK;
}
Ejemplo n.º 22
0
/* {{{ flt_phpsessauth_handle */
int flt_phpsessauth_handle(cf_configfile_t *cfile,cf_conf_opt_t *opt,const u_char *context,u_char **args,size_t argnum) {
  if(flt_phpsessauth_fn == NULL) flt_phpsessauth_fn = cf_hash_get(GlobalValues,"FORUM_NAME",10);
  if(!context || cf_strcmp(flt_phpsessauth_fn,context) != 0) return 0;

  if(cf_strcmp(opt->name,"SessionVName") == 0) {
    if(flt_phpsessauth_vname) free(flt_phpsessauth_vname);
    flt_phpsessauth_vname = strdup(args[0]);
  }
  else if(cf_strcmp(opt->name,"SessionPath") == 0) {
    if(flt_phpsessauth_sesspath) free(flt_phpsessauth_sesspath);
    flt_phpsessauth_sesspath = strdup(args[0]);
  }
  else {
    if(flt_phpsessauth_sessname) free(flt_phpsessauth_sessname);
    flt_phpsessauth_sessname = strdup(args[0]);
  }

  return 0;
}
Ejemplo n.º 23
0
time_t flt_http_lm(cf_hash_t *head,cf_configuration_t *dc,cf_configuration_t *vc,int sock) {
#else
time_t flt_http_lm(cf_hash_t *head,cf_configuration_t *dc,cf_configuration_t *vc,void *sock) {
#endif
  u_char *uname = cf_hash_get(GlobalValues,"UserName",8);
  u_char *uconffile = NULL;
  struct stat st;
  time_t ret = -1;

  if(uname) {
    uconffile = cf_get_uconf_name(uname);

    if(uconffile) {
      if(stat(uconffile,&st) != -1) ret = st.st_mtime;
      free(uconffile);
    }
  }

  return ret;
}
Ejemplo n.º 24
0
/* {{{ flt_failsafe_thread_handler */
int flt_failsafe_thread_handler(forum_t *forum,thread_t *t) {
  FILE *fd;
  cf_failsafe_t *fl = cf_hash_get(flt_failsafe_hsh,forum->name,strlen(forum->name));

  /* lock backup mutex */
  CF_LM(&fl->BackupMutex);

  if((fd = fopen(fl->BackupFile,"ab")) != NULL) {
    flt_failsafe_write(forum,fd,t->tid,0,t->postings);
    fclose(fd);

    /* Unlock the backup mutex */
    CF_UM(&fl->BackupMutex);
    return FLT_OK;
  }

  /* unlock backup mutex */
  CF_UM(&fl->BackupMutex);

  return FLT_DECLINE;
}
Ejemplo n.º 25
0
/* {{{ flt_list_rm_collector */
int flt_list_rm_collector(cf_hash_t *head,cf_configuration_t *dc,cf_configuration_t *vc,cf_readmode_t *rm_infos) {
  u_char *fn = cf_hash_get(GlobalValues,"FORUM_NAME",10);

  cf_name_value_t *rm = cf_cfg_get_first_value(vc,fn,"DF:ReadMode");
  cf_name_value_t *v;

  u_char buff[256];

  if(cf_strcmp(rm->values[0],"list") == 0) {
    v = cf_cfg_get_first_value(dc,fn,"DF:PostingURL_List");
    rm_infos->posting_uri[0] = v->values[0];

    v = cf_cfg_get_first_value(dc,fn,"UDF:PostingURL_List");
    rm_infos->posting_uri[1] = v->values[0];

    if((v = cf_cfg_get_first_value(vc,fn,"FV:TemplateForumBegin")) != NULL) {
      cf_gen_tpl_name(buff,256,v->values[0]);
      rm_infos->pre_threadlist_tpl = strdup(buff);
    }

    if((v = cf_cfg_get_first_value(vc,fn,"FV:TemplateForumThread")) != NULL) {
      cf_gen_tpl_name(buff,256,v->values[0]);
      rm_infos->thread_posting_tpl = rm_infos->threadlist_thread_tpl = strdup(buff);
    }

    if((v = cf_cfg_get_first_value(vc,fn,"FV:TemplateForumEnd")) != NULL) {
      cf_gen_tpl_name(buff,256,v->values[0]);
      rm_infos->post_threadlist_tpl = strdup(buff);
    }

    if(flt_list_tpl) {
      cf_gen_tpl_name(buff,256,flt_list_tpl);
      rm_infos->thread_tpl = strdup(buff);
    }

    return FLT_OK;
  }

  return FLT_DECLINE;
}
Ejemplo n.º 26
0
/* {{{ flt_failsafe_post_handler */
int flt_failsafe_post_handler(forum_t *forum,u_int64_t tid,posting_t *p) {
  FILE *fd;
  cf_failsafe_t *fl = cf_hash_get(flt_failsafe_hsh,forum->name,strlen(forum->name));

  /* lock backup mutex */
  CF_LM(&fl->BackupMutex);

  if((fd = fopen(fl->BackupFile,"ab")) != NULL) {
    flt_failsafe_write(forum,fd,tid,p->prev->mid,p);
    fclose(fd);

    /* Unlock the backup mutex */
    CF_UM(&fl->BackupMutex);
    return FLT_OK;
  }

  /* unlock backup mutex */
  CF_UM(&fl->BackupMutex);

  return FLT_DECLINE;

}
Ejemplo n.º 27
0
/* {{{ flt_moderated_posthandler */
int flt_moderated_posthandler(cf_hash_t *cgi,cf_configuration_t *dc,cf_configuration_t *vc,message_t *msg,u_int64_t tid,int mode) {
  int si = cf_hash_get(GlobalValues,"ShowInvisible",13) != NULL,ret;

  DBT key,data;
  cf_string_t str;

  if(flt_moderated_cfg != FLT_MOD_POSTS) return FLT_DECLINE;

  if(flt_moderated_db == NULL) {
    if(flt_mod_getdb(1) != FLT_OK) {
      if(si) flt_mod_setlinks(&msg->hashvar,1,tid,msg->mid);
      msg->may_show = 0;
      return FLT_DECLINE;
    }
  }

  cf_str_init_growth(&str,50);
  cf_str_char_append(&str,'t');
  cf_uint64_to_str(&str,tid);
  cf_str_char_append(&str,'m');
  cf_uint64_to_str(&str,msg->mid);

  memset(&key,0,sizeof(key));
  memset(&data,0,sizeof(data));

  key.data = str.content;
  key.size = str.len;

  ret = flt_moderated_db->get(flt_moderated_db,NULL,&key,&data,0);

  if(si) flt_mod_setlinks(&msg->hashvar,ret,tid,msg->mid);

  if(ret != 0) msg->may_show = 0;

  cf_str_cleanup(&str);

  return FLT_DECLINE;
}
Ejemplo n.º 28
0
/* {{{ flt_httpauth_run */
int flt_phpsessauth_run(cf_hash_t *head,cf_configuration_t *dc,cf_configuration_t *vc) {
  u_char *fn = cf_hash_get(GlobalValues,"FORUM_NAME",10);
  cf_name_value_t *v = cf_cfg_get_first_value(dc,fn,"DF:AuthMode");
  u_char *name = NULL,*path;
  cf_hash_t *cookies;
  cf_string_t *sess;

  if(!flt_phpsessauth_vname) return FLT_DECLINE;
  if(!v || !v->values[0] || cf_strcmp(v->values[0],"phpsess") != 0) return FLT_DECLINE;

  sess = cf_cgi_get(head,flt_phpsessauth_sessname);
  if(head == NULL || (flt_phpsessauth_sid = sess->content) == NULL) {
    cookies = cf_hash_new(cf_cgi_destroy_entry);
    cf_cgi_parse_cookies(cookies);

    if((sess = cf_cgi_get(cookies,flt_phpsessauth_sessname)) == NULL) {
      cf_hash_destroy(cookies);
      return FLT_DECLINE;
    }
    else flt_phpsessauth_sid = sess->content;

    cf_hash_destroy(cookies);
  }
  else cf_add_static_uri_flag(flt_phpsessauth_sessname,flt_phpsessauth_sid,0);

  if((name = flt_phpsessauth_getvar(flt_phpsessauth_vname)) != NULL) {
    path = cf_get_uconf_name(name);

    if(path) {
      free(path);
      cf_hash_set(GlobalValues,"UserName",8,name,strlen(name)+1);
    }

    free(name);
  }

  return FLT_OK;
}
Ejemplo n.º 29
0
/* {{{ flt_moderated_thread */
int flt_moderated_thread(cf_hash_t *head,cf_configuration_t *dc,cf_configuration_t *vc,cl_thread_t *thread,int mode) {
  int si = cf_hash_get(GlobalValues,"ShowInvisible",13) != NULL,ret;

  DBT key,data;
  cf_string_t str;

  if(flt_moderated_cfg != FLT_MOD_THREAD || (mode & CF_MODE_POST) == 0) return FLT_DECLINE;
  if(flt_moderated_db == NULL) {
    if(flt_mod_getdb(1) != FLT_OK) {
      if(si) flt_mod_setlinks(&thread->messages->hashvar,1,thread->tid,thread->messages->mid);
      thread->messages->may_show = 0;
      cf_msg_delete_subtree(thread->messages);
      return FLT_DECLINE;
    }
  }

  cf_str_init_growth(&str,50);
  cf_str_char_append(&str,'t');
  cf_uint64_to_str(&str,thread->tid);
  cf_str_char_append(&str,'m');
  cf_uint64_to_str(&str,thread->messages->mid);

  memset(&key,0,sizeof(key));
  memset(&data,0,sizeof(data));

  key.data = str.content;
  key.size = str.len;

  ret = flt_moderated_db->get(flt_moderated_db,NULL,&key,&data,0);
  if(si) flt_mod_setlinks(&thread->messages->hashvar,ret,thread->tid,thread->messages->mid);

  if(ret != 0) {
    thread->messages->may_show = 0;
    cf_msg_delete_subtree(thread->messages);
  }

  return FLT_OK;
}
Ejemplo n.º 30
0
/* {{{ flt_http_handle_command */
int flt_http_handle_command(cf_configfile_t *cfile,cf_conf_opt_t *opt,const u_char *context,u_char **args,size_t argnum) {
  u_char *ptr = NULL;

  if(!flt_http_fn) flt_http_fn = cf_hash_get(GlobalValues,"FORUM_NAME",10);
  if(!context || cf_strcmp(flt_http_fn,context) != 0) return 0;

  if(argnum == 1) {
    if(cf_strcmp(opt->name,"Http:SendLastModified") == 0) {
      http_config.send_last_modified = cf_strcasecmp(args[0],"yes") == 0;
    }
    else if(cf_strcmp(opt->name,"Http:SendExpires") == 0) {
      http_config.expires_set  = 1;
      http_config.send_expires = strtol(args[0],(char **)&ptr,10);

      if(ptr) {
        if(toupper(*ptr) == 'M') {
          http_config.send_expires *= 60L;
        }
        else if(toupper(*ptr) == 'H') {
          http_config.send_expires *= 60L * 60L;
        }
      }

    }
    else if(cf_strcmp(opt->name,"Http:HandleLastModifiedSince") == 0) {
      if(cf_strcmp(args[0],"yes") == 0) {
        http_config.handle_last_modified_since = 1;
      }
    }
  }
  else {
    fprintf(stderr,"flt_http: Expecting one argument for directive %s!\n",opt->name);
    return 1;
  }

  return 0;
}