/* FILE tAccess source code of mysqlSendmail.cgi (built by mysqlRAD2.cgi (c) Gary Wallis 2001,2002 GPL Licensed) $Id: taccess.c 6 2005-11-24 00:02:59Z ggw $ (tAuthorize.cPasswd template set member) PURPOSE */ #include "mysqlrad.h" //Table Variables //uAccess: Primary Key static unsigned uAccess=0; //cDomainIP: Domain or IP: Class C class B of full IP static char cDomainIP[65]={""}; //cRelayAttr: Allow, reject or other error message static char cRelayAttr[65]={""}; //uServer: Server account is on static unsigned uServer=0; static char cuServerPullDown[256]={""}; //uExpireDate: Expire this tAccess entry at this time static long unsigned uExpireDate=0; //uSource: Where this record came from static unsigned uSource=0; //uOwner: Record owner static unsigned uOwner=0; //uCreatedBy: uClient for last insert static unsigned uCreatedBy=0; #define ISM3FIELDS //uCreatedDate: Unix seconds date last insert static long unsigned uCreatedDate=0; //uModBy: uClient for last update static unsigned uModBy=0; //uModDate: Unix seconds date last update static long unsigned uModDate=0; #define VAR_LIST_tAccess "tAccess.uAccess,tAccess.cDomainIP,tAccess.cRelayAttr,tAccess.uServer,tAccess.uExpireDate,tAccess.uSource,tAccess.uOwner,tAccess.uCreatedBy,tAccess.uCreatedDate,tAccess.uModBy,tAccess.uModDate" //Local only void Insert_tAccess(void); void Update_tAccess(char *rowid); int InsertUpdate_tAccess(char *cKey); void ProcesstAccessListVars(pentry entries[], int x); //In tAccessfunc.h file included below void ExtProcesstAccessVars(pentry entries[], int x); void ExttAccessCommands(pentry entries[], int x); void ExttAccessButtons(void); void ExttAccessNavBar(void); void ExttAccessGetHook(entry gentries[], int x); void ExttAccessSelect(void); void ExttAccessSelectRow(void); void ExttAccessListSelect(void); void ExttAccessListFilter(void); void ExttAccessAuxTable(void); #include "taccessfunc.h" //Table Variables Assignment Function void ProcesstAccessVars(pentry entries[], int x) { register int i; for(i=0;i\n"); printf("\n"); printf(""); printf("
"); ExttAccessNavBar(); printf(""); printf("",rowid); if(i) { printf(" "); if(mode==6) //printf(" Found"); printf(LANG_NBR_FOUND); else if(mode==5) //printf(" Modified"); printf(LANG_NBR_MODIFIED); else if(mode==4) //printf(" New"); printf(LANG_NBR_NEW); printf(LANG_NBRF_SHOWING,rowid,i); } else { if(!result[0]) //printf(" No records found"); printf(LANG_NBR_NORECS); } if(result[0]) printf(" %s",result); printf("
"); ExttAccessButtons(); printf(""); printf("\n"); if(mode==2000 || mode==2002) tAccessInputContent(); else tAccessContent(); printf("
\n"); printf("
\n"); //Bottom table ExttAccessAuxTable(); printf("\n"); Footer_ism3(); }//end of tAccess(); void tAccessContent(void) { OpenRow(LANG_FL_tAccess_uAccess,"white"); printf("%u\n",uAccess,uAccess); printf("  "); OpenRow(LANG_FL_tAccess_cDomainIP,EmptyString(cDomainIP)); printf("%s",cDomainIP,EncodeDoubleQuotes(cDomainIP)); printf("  "); OpenRow(LANG_FL_tAccess_cRelayAttr,EmptyString(cRelayAttr)); printf("%s",cRelayAttr,EncodeDoubleQuotes(cRelayAttr)); printf("  "); OpenRow(LANG_FL_tAccess_uServer,IsZero(uServer)); tTablePullDownReadOnly("tServer;cuServerPullDown","cLabel","cLabel",uServer); printf("  "); OpenRow(LANG_FL_tAccess_uExpireDate,"white"); if(uExpireDate) printf("%s\n\n",ctime((time_t *)&uExpireDate)); else printf("---\n\n"); printf("\n",uExpireDate); printf("  "); OpenRow(LANG_FL_tAccess_uSource,"white"); printf("%u\n",uSource,uSource); printf("  "); OpenRow(LANG_FL_tAccess_uOwner,"white"); printf("%s\n",ForeignKey("tClient","cLabel",uOwner),uOwner); printf("  "); OpenRow(LANG_FL_tAccess_uCreatedBy,"white"); printf("%s\n",ForeignKey("tClient","cLabel",uCreatedBy),uCreatedBy); printf("  "); OpenRow(LANG_FL_tAccess_uCreatedDate,"white"); if(uCreatedDate) printf("%s\n\n",ctime((time_t *)&uCreatedDate)); else printf("---\n\n"); printf("\n",uCreatedDate); printf("  "); OpenRow(LANG_FL_tAccess_uModBy,"white"); printf("%s\n",ForeignKey("tClient","cLabel",uModBy),uModBy); printf("  "); OpenRow(LANG_FL_tAccess_uModDate,"white"); if(uModDate) printf("%s\n\n",ctime((time_t *)&uModDate)); else printf("---\n\n"); printf("\n",uModDate); printf("  "); printf("\n"); }//tAccessContent() void tAccessInputContent(void) { OpenRow(LANG_FL_tAccess_uAccess,"white"); if(uPermLevel>=20) printf("\n",LANG_FT_tAccess_uAccess,uAccess); else printf("%u\n",uAccess,uAccess); OpenRow(LANG_FL_tAccess_cDomainIP,EmptyString(cDomainIP)); if(uPermLevel>9) printf("\n",LANG_FT_tAccess_cDomainIP,EncodeDoubleQuotes(cDomainIP)); else printf("%s",cDomainIP,EncodeDoubleQuotes(cDomainIP)); OpenRow(LANG_FL_tAccess_cRelayAttr,EmptyString(cRelayAttr)); if(uPermLevel>9) printf("\n",LANG_FT_tAccess_cRelayAttr,EncodeDoubleQuotes(cRelayAttr)); else printf("%s",cRelayAttr,EncodeDoubleQuotes(cRelayAttr)); OpenRow(LANG_FL_tAccess_uServer,IsZero(uServer)); if(uPermLevel>9) tTablePullDown("tServer;cuServerPullDown","cLabel","cLabel",uServer); else { tTablePullDownReadOnly("tServer;cuServerPullDown","cLabel","cLabel",uServer); } OpenRow(LANG_FL_tAccess_uExpireDate,"white"); if(uExpireDate) printf("%s\n\n",ctime((time_t *)&uExpireDate)); else printf("---\n\n"); printf("\n",uExpireDate); OpenRow(LANG_FL_tAccess_uSource,"white"); if(uPermLevel>=20) printf("\n",LANG_FT_tAccess_uSource,uSource); else printf("%u\n",uSource,uSource); OpenRow(LANG_FL_tAccess_uOwner,"white"); printf("%s\n",ForeignKey("tClient","cLabel",uOwner),uOwner); OpenRow(LANG_FL_tAccess_uCreatedBy,"white"); printf("%s\n",ForeignKey("tClient","cLabel",uCreatedBy),uCreatedBy); OpenRow(LANG_FL_tAccess_uCreatedDate,"white"); if(uCreatedDate) printf("%s\n\n",ctime((time_t *)&uCreatedDate)); else printf("---\n\n"); printf("\n",uCreatedDate); OpenRow(LANG_FL_tAccess_uModBy,"white"); printf("%s\n",ForeignKey("tClient","cLabel",uModBy),uModBy); OpenRow(LANG_FL_tAccess_uModDate,"white"); if(uModDate) printf("%s\n\n",ctime((time_t *)&uModDate)); else printf("---\n\n"); printf("\n",uModDate); printf("\n"); }//void tAccessInputContent(void) void NewtAccess(unsigned uMode) { register int i=0; MYSQL_RES *res; //New select sprintf(query,"SELECT uAccess FROM tAccess\ WHERE uAccess=%u" ,uAccess); mysql_query(&mysql,query); if(mysql_errno(&mysql)) mysqlSendmail(mysql_error(&mysql)); res=mysql_store_result(&mysql); i=mysql_num_rows(res); if(i) //tAccess("Record already exists"); tAccess(LANG_NBR_RECEXISTS); //insert query Insert_tAccess(); if(mysql_errno(&mysql)) mysqlSendmail(mysql_error(&mysql)); //sprintf(query,"New record %u added"); uAccess=mysql_insert_id(&mysql); if(!uMode) { sprintf(query,LANG_NBR_NEWRECADDED,uAccess); tAccess(query); } }//NewtAccess(unsigned uMode) void DeletetAccess(void) { #ifdef ISM3FIELDS sprintf(query,"DELETE FROM tAccess WHERE uAccess=%u AND ( uOwner=%u OR %u>9 )" ,uAccess,uLoginClient,uPermLevel); #else sprintf(query,"DELETE FROM tAccess WHERE uAccess=%u" ,uAccess); #endif mysql_query(&mysql,query); if(mysql_errno(&mysql)) mysqlSendmail(mysql_error(&mysql)); //tAccess("Record Deleted"); if(mysql_affected_rows(&mysql)>0) tAccess(LANG_NBR_RECDELETED); else tAccess(LANG_NBR_RECNOTDELETED); }//void DeletetAccess(void) void Insert_tAccess(void) { #ifdef ISM3FIELDS time_t clock; time(&clock); #endif //insert query //insert query sprintf(query,"INSERT INTO tAccess SET uAccess=%u, cDomainIP='%s', cRelayAttr='%s', uServer=%u, uExpireDate=%lu, uSource=%u, uOwner=%u, uCreatedBy=%u, uCreatedDate=%lu, uModBy=%u, uModDate=0", uAccess ,TextAreaSave(cDomainIP) ,TextAreaSave(cRelayAttr) ,uServer ,uExpireDate ,uSource ,uOwner ,uCreatedBy ,(long unsigned)clock ,uModBy ); mysql_query(&mysql,query); #ifdef ISM3FIELDS uCreatedDate=clock; #endif }//void Insert_tAccess(void) void Update_tAccess(char *rowid) { #ifdef ISM3FIELDS time_t clock; time(&clock); #endif //update query //update query sprintf(query,"UPDATE tAccess SET uAccess=%u,cDomainIP='%s',cRelayAttr='%s',uServer=%u,uExpireDate=%lu,uSource=%u,uModBy=%u,uModDate=%lu WHERE _rowid=%s", uAccess ,TextAreaSave(cDomainIP) ,TextAreaSave(cRelayAttr) ,uServer ,uExpireDate ,uSource ,uModBy ,(long unsigned)clock ,rowid); mysql_query(&mysql,query); #ifdef ISM3FIELDS uModDate=clock; #endif }//void Update_tAccess(void) void ModtAccess(void) { register int i=0; MYSQL_RES *res; MYSQL_ROW field; #ifdef ISM3FIELDS unsigned uPreModDate=0; //Mod select query if(uPermLevel<10) sprintf(query,"SELECT tAccess.uAccess,\ tAccess.uModDate\ FROM tAccess,tClient\ WHERE tAccess.uAccess=%u\ AND tAccess.uOwner=tClient.uClient\ AND (tClient.uOwner=%u OR tClient.uClient=%u)" ,uAccess,uLoginClient,uLoginClient); else sprintf(query,"SELECT uAccess,uModDate FROM tAccess\ WHERE uAccess=%u" ,uAccess); #else sprintf(query,"SELECT uAccess FROM tAccess\ WHERE uAccess=%u" ,uAccess); #endif mysql_query(&mysql,query); if(mysql_errno(&mysql)) mysqlSendmail(mysql_error(&mysql)); res=mysql_store_result(&mysql); i=mysql_num_rows(res); //if(i<1) tAccess("Record does not exist"); if(i<1) tAccess(LANG_NBR_RECNOTEXIST); //if(i>1) tAccess("Multiple rows!"); if(i>1) tAccess(LANG_NBR_MULTRECS); field=mysql_fetch_row(res); #ifdef ISM3FIELDS sscanf(field[1],"%u",&uPreModDate); if(uPreModDate!=uModDate) tAccess(LANG_NBR_EXTMOD); #endif Update_tAccess(field[0]); if(mysql_errno(&mysql)) mysqlSendmail(mysql_error(&mysql)); //sprintf(query,"record %s modified",field[0]); sprintf(query,LANG_NBRF_REC_MODIFIED,field[0]); tAccess(query); }//ModtAccess(void) void tAccessList(void) { MYSQL_RES *res; MYSQL_ROW field; unsigned long uExpireDate=0; unsigned long uCreatedDate=0; unsigned long uModDate=0; char cExpireDate[33]={""}; char cCreatedDate[33]={""}; char cModDate[33]={""}; ExttAccessListSelect(); mysql_query(&mysql,query); if(mysql_error(&mysql)[0]) mysqlSendmail(mysql_error(&mysql)); res=mysql_store_result(&mysql); i=mysql_num_rows(res); PageMachine("tAccessList",1,"");//1 is auto header list mode. Opens table! //Filter select drop down ExttAccessListFilter(); printf("",command); printf("\n"); printf("\n"); printf(""); mysql_data_seek(res,start-1); for(n=0;n<(end-start+1);n++) { field=mysql_fetch_row(res); if(!field) { printf("
uAccesscDomainIPcRelayAttruServeruExpireDateuSourceuOwneruCreatedByuCreatedDateuModByuModDate
End of data
"); Footer_ism3(); } sscanf(field[4],"%lu",&uExpireDate); sscanf(field[8],"%lu",&uCreatedDate); sscanf(field[10],"%lu",&uModDate); if(uExpireDate) sprintf(cExpireDate,"%.32s",ctime((time_t *)&uExpireDate)); else strcpy(cExpireDate,"0"); if(uCreatedDate) sprintf(cCreatedDate,"%.32s",ctime((time_t *)&uCreatedDate)); else strcpy(cCreatedDate,"0"); if(uModDate) sprintf(cModDate,"%.32s",ctime((time_t *)&uModDate)); else strcpy(cModDate,"0"); if(n % 2) printf(""); else printf(""); printf(" %s%s%s%s%s%s%s%s%s%s%s" ,field[0] ,field[0] ,field[1] ,field[2] ,field[3] ,cExpireDate ,field[5] ,field[6] ,field[7] ,cCreatedDate ,field[9] ,cModDate ); } printf("\n"); Footer_ism3(); }//tAccessList() void CreatetAccess(void) { sprintf(query,"CREATE TABLE tAccess ( uAccess int unsigned PRIMARY KEY AUTO_INCREMENT, cDomainIP varchar(64) NOT NULL DEFAULT '',unique (cDomainIP,uServer), uOwner int unsigned NOT NULL DEFAULT 0,index (uOwner), uCreatedBy int unsigned NOT NULL DEFAULT 0, uCreatedDate int unsigned NOT NULL DEFAULT 0, uModBy int unsigned NOT NULL DEFAULT 0, uModDate int unsigned NOT NULL DEFAULT 0, uServer int unsigned NOT NULL DEFAULT 0,index (uServer), cRelayAttr varchar(64) NOT NULL DEFAULT '', uExpireDate int unsigned NOT NULL DEFAULT 0, uSource int unsigned NOT NULL DEFAULT 0 )"); mysql_query(&mysql,qstr); if(mysql_errno(&mysql)) mysqlSendmail(mysql_error(&mysql)); }//CreatetAccess() //sedall patch1