Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

flt_admin.c

Go to the documentation of this file.
00001 
00008 /* {{{ Initial comments */
00009 /*
00010  * $LastChangedDate: 2004-04-01 18:34:17 +0200 (Thu, 01 Apr 2004) $
00011  * $LastChangedRevision: 50 $
00012  * $LastChangedBy: ckruse $
00013  *
00014  */
00015 /* }}} */
00016 
00017 /* {{{ Includes */
00018 #include "config.h"
00019 #include "defines.h"
00020 
00021 #include <stdio.h>
00022 #include <stdlib.h>
00023 #include <unistd.h>
00024 #include <string.h>
00025 #include <time.h>
00026 #include <sys/types.h>
00027 
00028 #include "hashlib.h"
00029 #include "utils.h"
00030 #include "configparser.h"
00031 #include "cfcgi.h"
00032 #include "template.h"
00033 #include "readline.h"
00034 #include "clientlib.h"
00035 /* }}} */
00036 
00037 u_char **flt_admin_Admins = NULL;
00038 static size_t flt_admin_AdminNum = 0;
00039 static int my_errno = 0;
00040 static int is_admin = -1;
00041 
00042 int flt_admin_is_admin(const u_char *name) {
00043   size_t i;
00044 
00045   if(!name) return 0;
00046   if(is_admin != -1) return is_admin;
00047 
00048   if(flt_admin_Admins) {
00049     for(i=0;i<flt_admin_AdminNum;i++) {
00050       if(cf_strcmp(flt_admin_Admins[i],name) == 0) {
00051         is_admin = 1;
00052         return 1;
00053       }
00054     }
00055   }
00056 
00057   is_admin = 0;
00058   return 0;
00059 }
00060 
00061 int flt_admin_gogogo(t_cf_hash *cgi,t_configuration *dc,t_configuration *vc,int sock) {
00062   u_char *action = NULL,*tid,*mid,buff[512],*answer;
00063   size_t len;
00064   rline_t rl;
00065   int x;
00066   u_char *UserName = cf_hash_get(GlobalValues,"UserName",8);
00067 
00068   if(!flt_admin_is_admin(UserName)) return FLT_DECLINE;
00069 
00070   if(cgi) action = cf_cgi_get(cgi,"faa");
00071   if(action) {
00072     tid = cf_cgi_get(cgi,"t");
00073     mid = cf_cgi_get(cgi,"m");
00074 
00075     if(!tid || !mid) return FLT_DECLINE;
00076     if(strtol(tid,NULL,10) == 0 || strtol(mid,NULL,10) == 0) return FLT_DECLINE;
00077 
00078     memset(&rl,0,sizeof(rline_t));
00079 
00080     #ifdef CF_SHARED_MEM
00081     /* if in shared memory mode, the sock parameter is a pointer to the shared mem segment */
00082     sock = set_us_up_the_socket();
00083     #endif
00084 
00085     if(cf_strcmp(action,"del") == 0) {
00086       len = snprintf(buff,512,"DELETE t=%s m=%s\nUser-Name: %s\n",tid,mid,UserName);
00087       writen(sock,buff,len);
00088     }
00089     else if(cf_strcmp(action,"undel") == 0) {
00090       len = snprintf(buff,512,"UNDELETE t=%s m=%s\nUser-Name: %s\n",tid,mid,UserName);
00091       writen(sock,buff,len);
00092     }
00093     else if(cf_strcmp(action,"archive") == 0) {
00094       len = snprintf(buff,512,"ARCHIVE THREAD t=%s\nUser-Name: %s\n",tid,UserName);
00095       writen(sock,buff,len);
00096     }
00097 
00098     answer = readline(sock,&rl);
00099     if(!answer || ((x = atoi(answer)) != 200)) {
00100       if(!answer) my_errno = 500;
00101       else my_errno = x;
00102     }
00103     if(answer) free(answer);
00104 
00105     #ifdef CF_SHARED_MEM
00106     writen(sock,"QUIT\n",5);
00107     close(sock);
00108     reget_shm_ptr();
00109     #endif
00110 
00111     cf_hash_entry_delete(cgi,"t",1);
00112     cf_hash_entry_delete(cgi,"m",1);
00113 
00114     return FLT_OK;
00115   }
00116 
00117   return FLT_DECLINE;
00118 }
00119 
00120 int flt_admin_setvars(t_cf_hash *cgi,t_configuration *dc,t_configuration *vc,t_cf_template *top,t_cf_template *down) {
00121   u_char *msg,buff[256];
00122   size_t len,len1;
00123   u_char *UserName = cf_hash_get(GlobalValues,"UserName",8);
00124   int ShowInvisible = cf_hash_get(GlobalValues,"ShowInvisible",13) != NULL;
00125 
00126   if(flt_admin_is_admin(UserName)) {
00127     tpl_cf_setvar(top,"admin","1",1,0);
00128 
00129     if(ShowInvisible) {
00130       tpl_cf_setvar(top,"aaf","1",1,0);
00131     }
00132 
00133     if(my_errno) {
00134       len = snprintf(buff,256,"E_FO_%d",my_errno);
00135       msg = get_error_message(buff,len,&len1);
00136       if(msg) {
00137         tpl_cf_setvar(top,"flt_admin_errmsg",msg+len+1,len1-len-1,1);
00138         free(msg);
00139       }
00140     }
00141 
00142     return FLT_OK;
00143   }
00144 
00145   return FLT_DECLINE;
00146 }
00147 
00148 int flt_admin_init(t_cf_hash *cgi,t_configuration *dc,t_configuration *vc) {
00149   t_name_value *v = cfg_get_value(dc,"Administrators");
00150   u_char *val = NULL;
00151   u_char *UserName = cf_hash_get(GlobalValues,"UserName",8);
00152 
00153   cf_register_mod_api_ent("flt_admin","is_admin",(t_mod_api)flt_admin_is_admin);
00154 
00155   if(!UserName) return FLT_DECLINE;
00156 
00157   flt_admin_AdminNum = split(v->values[0],",",&flt_admin_Admins);
00158 
00159   if(!cgi)      return FLT_DECLINE;
00160 
00161   val = cf_cgi_get(cgi,"aaf");
00162 
00163   if(!val)      return FLT_DECLINE;
00164 
00165   if(!v) return FLT_DECLINE;
00166 
00167   /* ShowInvisible is imported from the client library */
00168   if(flt_admin_is_admin(UserName) && *val == '1') cf_hash_set(GlobalValues,"ShowInvisible",13,"1",1);
00169 
00170   return FLT_OK;
00171 }
00172 
00173 int flt_admin_posthandler(t_cf_hash *cgi,t_configuration *dc,t_configuration *vc,t_message *msg,u_int64_t tid,int mode) {
00174   u_char buff[256];
00175   size_t l;
00176   u_char *UserName = cf_hash_get(GlobalValues,"UserName",8);
00177   int ShowInvisible = cf_hash_get(GlobalValues,"ShowInvisible",13) != NULL;
00178 
00179   if(flt_admin_is_admin(UserName)) {
00180     tpl_cf_setvar(&msg->tpl,"admin","1",1,0);
00181 
00182     if(ShowInvisible) {
00183       tpl_cf_setvar(&msg->tpl,"aaf","1",1,0);
00184 
00185       l = snprintf(buff,256,"?t=%lld&m=%lld&aaf=1&faa=archive",tid,msg->mid);
00186       tpl_cf_setvar(&msg->tpl,"archive_link",buff,l,1);
00187 
00188       if(msg->invisible == 0) {
00189         l = snprintf(buff,256,"?t=%lld&m=%lld&aaf=1&faa=del",tid,msg->mid);
00190         tpl_cf_setvar(&msg->tpl,"visible","1",1,0);
00191         tpl_cf_setvar(&msg->tpl,"del_link",buff,l,1);
00192       }
00193       else {
00194         l = snprintf(buff,256,"?t=%lld&m=%lld&aaf=1&faa=undel",tid,msg->mid);
00195         tpl_cf_setvar(&msg->tpl,"undel_link",buff,l,1);
00196       }
00197     }
00198 
00199     return FLT_OK;
00200   }
00201 
00202   return FLT_DECLINE;
00203 }
00204 
00205 void flt_admin_finish(void) {
00206   size_t i;
00207   if(flt_admin_Admins) {
00208     for(i=0;i<flt_admin_AdminNum;i++) free(flt_admin_Admins[i]);
00209     free(flt_admin_Admins);
00210   }
00211 }
00212 
00213 int flt_admin_validator(t_cf_hash *head,t_configuration *dc,t_configuration *vc,time_t last_modified,int sock) {
00214   u_char *UserName = cf_hash_get(GlobalValues,"UserName",8);
00215   int ShowInvisible = cf_hash_get(GlobalValues,"ShowInvisible",13) != NULL;
00216 
00217   if(flt_admin_is_admin(UserName) && ShowInvisible) return FLT_EXIT;
00218   return FLT_DECLINE;
00219 }
00220 
00221 time_t flt_admin_lm(t_cf_hash *head,t_configuration *dc,t_configuration *vc,int sock) {
00222   return time(NULL);
00223 }
00224 
00225 t_conf_opt flt_admin_config[] = {
00226   { NULL, NULL, NULL }
00227 };
00228 
00229 t_handler_config flt_admin_handlers[] = {
00230   { CONNECT_INIT_HANDLER, flt_admin_gogogo },
00231   { INIT_HANDLER,         flt_admin_init },
00232   { VIEW_INIT_HANDLER,    flt_admin_setvars },
00233   { VIEW_LIST_HANDLER,    flt_admin_posthandler },
00234   { 0, NULL }
00235 };
00236 
00237 t_module_config flt_admin = {
00238   flt_admin_config,
00239   flt_admin_handlers,
00240   flt_admin_validator,
00241   flt_admin_lm,
00242   NULL,
00243   flt_admin_finish
00244 };
00245 
00246 /* eof */

Generated on Sun Apr 25 16:37:38 2004 for Classic Forum by doxygen 1.3.5