/* FILE $Id$ (Built initially by unixservice.com mysqlRAD2) PURPOSE Non schema-dependent table and application table related functions. AUTHOR (C) 2001-2009 Gary Wallis and Hugo Urquiza. */ //ModuleFunctionProtos() #include #include static char cSearch[64]={""}; //Aux drop/pull downs static char cForClientPullDown[256]={""}; static unsigned uForClient=0; void tTablePullDownResellers(int unsigned uSelector); void tBlockNavList(void); void tBlockContextInfo(void); //Block assignment tool vars static char cIPBlock[256]={""}; static char cZone[256]={""}; static unsigned uZone=0; static unsigned uMathCheck=0; void UpdateSerialNum(unsigned uZone); void CustomerDropDown(unsigned uClient); void ExtProcesstBlockVars(pentry entries[], int x) { register int i; for(i=0;i=10) { ProcesstBlockVars(entries,x); guMode=2000; tBlock(LANG_NB_CONFIRMNEW); } else tBlock("Error: Denied by permissions settings"); } else if(!strcmp(gcCommand,LANG_NB_CONFIRMNEW)) { if(guPermLevel>=10) { ProcesstBlockVars(entries,x); guMode=2000; //Check entries here guMode=0; uBlock=0; uCreatedBy=guLoginClient; if(!uForClient) uOwner=guCompany; else uOwner=uForClient; uModBy=0;//Never modified uModDate=0;//Never modified NewtBlock(0); } else tBlock("Error: Denied by permissions settings"); } else if(!strcmp(gcCommand,LANG_NB_DELETE)) { ProcesstBlockVars(entries,x); if(uAllowDel(uOwner,uCreatedBy)) { guMode=2001; tBlock(LANG_NB_CONFIRMDEL); } else tBlock("Error: Denied by permissions settings"); } else if(!strcmp(gcCommand,LANG_NB_CONFIRMDEL)) { ProcesstBlockVars(entries,x); if(uAllowDel(uOwner,uCreatedBy)) { guMode=5; DeletetBlock(); } else tBlock("Error: Denied by permissions settings"); } else if(!strcmp(gcCommand,LANG_NB_MODIFY)) { ProcesstBlockVars(entries,x); if(uAllowMod(uOwner,uCreatedBy)) { guMode=2002; tBlock(LANG_NB_CONFIRMMOD); } else tBlock("Error: Denied by permissions settings"); } else if(!strcmp(gcCommand,LANG_NB_CONFIRMMOD)) { ProcesstBlockVars(entries,x); if(uAllowMod(uOwner,uCreatedBy)) { guMode=2002; //Check entries here guMode=0; if(uForClient) { sprintf(gcQuery,"UPDATE tBlock SET uOwner=%u WHERE uBlock=%u",uForClient,uBlock); mysql_query(&gMysql,gcQuery); if(mysql_errno(&gMysql)) tBlock(mysql_error(&gMysql)); uOwner=uForClient; } uModBy=guLoginClient; ModtBlock(); } else tBlock("Error: Denied by permissions settings"); } else if(!strcmp(gcCommand,"Block Assignment Tools")) { ProcesstZoneVars(entries,x); guMode=6000; tBlock(""); } else if(!strcmp(gcCommand,"Assign IP Block")) { unsigned uA=0; unsigned uB=0; unsigned uC=0; unsigned uD=0; unsigned uE=0; unsigned uNumIPs=0; unsigned uNumNets=0; unsigned uI=0; MYSQL_RES *res; ProcesstBlockVars(entries,x); if(!uForClient) { guMode=6000; tBlock("Must select a company first"); } if(!cIPBlock[0]) { guMode=6000; tBlock("Must enter a block in CIDR format"); } //remove extra spaces or any other junk in CIDR sscanf(cIPBlock,"%s",gcQuery); sprintf(cIPBlock,"%.99s",gcQuery); sscanf(cIPBlock,"%u.%u.%u.%u/%u",&uA,&uB,&uC,&uD,&uE); //Is this check actually required? /*if(uE<23) { guMode=4001; tBlock("This tool is only for larger than /24 blocks"); } */ if(!uA) { guMode=4001; tBlock("IP Block incorrect format"); } if((uA>255)||(uB>255)||(uC>255)||(uD>255)) { guMode=4001; tBlock("IP Block incorrect format"); } uNumIPs=uGetNumIPs(cIPBlock); uNumNets=uGetNumNets(cIPBlock); //Debug Only if(uMathCheck) { printf("Content-type: text/plain\n\n"); printf("Number of networks:%u\n",uNumNets); printf("Number of IPs:%u\n",uNumIPs); exit(0); } for(uI=uC;uI<((uC+uNumNets));uI++) { // //Create the tZone record if it not exists, otherwise update uOwner sprintf(cZone,"%u.%u.%u.in-addr.arpa",uI,uB,uA); sprintf(gcQuery,"SELECT uZone FROM tZone WHERE cZone='%s' AND uView=2",cZone); //printf("%s\n",gcQuery); mysql_query(&gMysql,gcQuery); if(mysql_errno(&gMysql)) htmlPlainTextError(mysql_error(&gMysql)); res=mysql_store_result(&gMysql); if(!mysql_num_rows(res)) { sprintf(gcQuery,"INSERT INTO tZone SET cZone='%s',uNSSet=1,cHostmaster='%s %s Assigned'," "uExpire=604800,uRefresh=28800,uTTL=86400,uRetry=7200,uZoneTTL=86400,uView=2," "uOwner='%u',uCreatedBy='%u',uCreatedDate=UNIX_TIMESTAMP(NOW())", cZone ,HOSTMASTER ,cIPBlock ,uForClient ,guLoginClient ); mysql_query(&gMysql,gcQuery); //printf("%s\n",gcQuery); if(mysql_errno(&gMysql)) htmlPlainTextError(mysql_error(&gMysql)); uZone=mysql_insert_id(&gMysql); UpdateSerialNum(uZone); SubmitJob("New",1,cZone,0,0); } else { MYSQL_ROW field; sprintf(gcQuery,"UPDATE tZone SET uOwner='%u',cHostmaster='%s %s Assigned',uModBy='%u'," "uModDate=UNIX_TIMESTAMP(NOW()) WHERE cZone='%s' AND uView=2", uForClient ,HOSTMASTER ,cIPBlock ,guLoginClient ,cZone ); mysql_query(&gMysql,gcQuery); //printf("%s\n",gcQuery); if(mysql_errno(&gMysql)) htmlPlainTextError(mysql_error(&gMysql)); //Should update zone serial here? field=mysql_fetch_row(res); sprintf(gcQuery,"UPDATE tResource SET uOwner='%u' WHERE uZone='%s'", uForClient ,field[0] ); //printf("%s\n",gcQuery); mysql_query(&gMysql,gcQuery); if(mysql_errno(&gMysql)) htmlPlainTextError(mysql_error(&gMysql)); } //Create the tBlock entry if it does not exists sprintf(cZone,"%u.%u.%u.0/24",uA,uB,uI); sprintf(gcQuery,"SELECT uBlock FROM tBlock WHERE cLabel='%s'",cZone); mysql_query(&gMysql,gcQuery); //printf("%s\n",gcQuery); if(mysql_errno(&gMysql)) htmlPlainTextError(mysql_error(&gMysql)); res=mysql_store_result(&gMysql); if(!mysql_num_rows(res)) sprintf(gcQuery,"INSERT INTO tBlock SET cLabel='%s',cComment='BlockAssign()',uCreatedBy='%u'," "uOwner='%u',uCreatedDate=UNIX_TIMESTAMP(NOW())" ,cZone ,guLoginClient ,uForClient ); else sprintf(gcQuery,"UPDATE tBlock SET uOwner='%u',uModBy='%u',uModDate=UNIX_TIMESTAMP(NOW()) WHERE cLabel='%s'", uForClient ,guLoginClient ,cZone ); //printf("%s\n",gcQuery); mysql_query(&gMysql,gcQuery); if(mysql_errno(&gMysql)) htmlPlainTextError(mysql_error(&gMysql)); }//for //exit(0); tBlock("CIDR IP Block Assigned OK"); } else if(!strcmp(gcCommand,"Remove Assigned IP Block")) { unsigned uA=0; unsigned uB=0; unsigned uC=0; unsigned uD=0; unsigned uE=0; unsigned uNumIPs=0; unsigned uNumNets=0; unsigned uI=0; MYSQL_RES *res; MYSQL_ROW field; ProcesstBlockVars(entries,x); if(!cIPBlock[0]) { guMode=6000; tBlock("Must enter a block in CIDR format"); } //remove extra spaces or any other junk in CIDR sscanf(cIPBlock,"%s",gcQuery); sprintf(cIPBlock,"%.99s",gcQuery); sscanf(cIPBlock,"%u.%u.%u.%u/%u",&uA,&uB,&uC,&uD,&uE); if(!uA) { guMode=4001; tBlock("IP Block incorrect format"); } if((uA>255)||(uB>255)||(uC>255)||(uD>255)) { guMode=4001; tBlock("IP Block incorrect format"); } uNumIPs=uGetNumIPs(cIPBlock); uNumNets=uGetNumNets(cIPBlock); if(uMathCheck) { printf("Content-type: text/plain\n\n"); printf("Number of networks:%u\n",uNumNets); printf("Number of IPs:%u\n",uNumIPs); exit(0); } for(uI=uC;uI<((uC+uNumNets));uI++) { // //Delete the tZone record sprintf(cZone,"%u.%u.%u.in-addr.arpa",uI,uB,uA); sprintf(gcQuery,"SELECT uZone FROM tZone WHERE cZone='%s' AND uView=2 AND cHostmaster LIKE '%%%s Assigned'", cZone ,cIPBlock ); //printf("%s\n",gcQuery); mysql_query(&gMysql,gcQuery); if(mysql_errno(&gMysql)) htmlPlainTextError(mysql_error(&gMysql)); res=mysql_store_result(&gMysql); if((field=mysql_fetch_row(res))) { sprintf(gcQuery,"DELETE FROM tZone WHERE uZone='%s'",field[0]); mysql_query(&gMysql,gcQuery); printf("%s\n",gcQuery); if(mysql_errno(&gMysql)) htmlPlainTextError(mysql_error(&gMysql)); //Delete orphan tResource records sprintf(gcQuery,"DELETE FROM tResource WHERE uZone='%s'",field[0]); mysql_query(&gMysql,gcQuery); //printf("%s\n",gcQuery); if(mysql_errno(&gMysql)) htmlPlainTextError(mysql_error(&gMysql)); SubmitJob("Del",1,cZone,0,0); }//if((field=mysql_fetch_row(res))) sprintf(cZone,"%u.%u.%u.0/24",uA,uB,uI); sprintf(gcQuery,"DELETE FROM tBlock WHERE cLabel='%s'",cZone); mysql_query(&gMysql,gcQuery); if(mysql_errno(&gMysql)) htmlPlainTextError(mysql_error(&gMysql)); } //exit(0); tBlock("CIDR IP Block Assignment Deleted OK"); } } }//void ExttBlockCommands(pentry entries[], int x) void ExttBlockButtons(void) { OpenFieldSet("tBlock Aux Panel",100); switch(guMode) { case 2000: printf("

Enter/mod data
"); if(guPermLevel>7) { printf("

Create for customer
"); tTablePullDownResellers(uForClient); } printf(LANG_NBB_CONFIRMNEW); break; case 2001: printf("

Think twice
"); printf(LANG_NBB_CONFIRMDEL); break; case 2002: printf("

Review changes
"); if(guPermLevel>7) { printf("

Change uOwner for customer
"); tTablePullDownResellers(uForClient); } printf(LANG_NBB_CONFIRMMOD); break; case 6000: printf("

Block Assignment Tools

\n"); printf("

By pressing the button below you confirm the assignment of the " "IP Block you have entered to the selected customer. If the " "reverse zones that are required for this assigment do not " "exist they will be created. Please note and take into account that " "existing zone ownership may be altered " "by using this tool. It will also create the required tBlock entries so the selected " "company can work with the zones using the idnsOrg interface
" "Warning:The assignment operation takes place immediately. " "There's no undo available. One job will be submitted for each created zone. " "Please be extremely careful when deleting an IP block assignment (Using the red button below.)
\n"); printf("

Assign to customer
\n"); tTablePullDownResellers(uForClient); printf("

CIDR IP Block
\n"); printf("

\n"); printf("

" "
\n"); printf("


\n"); break; default: printf("Table Tips
"); printf("Blocks of IPs are allocated to companies/organizations here. CIDR is spoken and certain " "in-addr.arpa zone operations require that the information here be correct.\n"); printf("

Search Tools
"); printf(" cSearch",cSearch); tBlockNavList(); printf("
\n"); tBlockContextInfo(); printf("

\n"); break; } CloseFieldSet(); }//void ExttBlockButtons(void) void ExttBlockAuxTable(void) { }//void ExttBlockAuxTable(void) void ExttBlockGetHook(entry gentries[], int x) { register int i; for(i=0;i"); if(strcmp(gcFilter,"uBlock")) printf(""); else printf(""); if(strcmp(gcFilter,"uOwner")) printf(""); else printf(""); if(strcmp(gcFilter,"cLabel")) printf(""); else printf(""); if(strcmp(gcFilter,"None")) printf(""); else printf(""); printf(""); }//void ExttBlockListFilter(void) void ExttBlockNavBar(void) { printf(LANG_NBB_SKIPFIRST); printf(LANG_NBB_SKIPBACK); printf(LANG_NBB_SEARCH); if(guPermLevel>=10 && !guListMode) printf(LANG_NBB_NEW); if(uAllowMod(uOwner,uCreatedBy)) printf(LANG_NBB_MODIFY); if(uAllowDel(uOwner,uCreatedBy)) printf(LANG_NBB_DELETE); if(uOwner) printf(LANG_NBB_LIST); printf(LANG_NBB_SKIPNEXT); printf(LANG_NBB_SKIPLAST); printf("   \n"); }//void ExttBlockNavBar(void) void tBlockNavList(void) { MYSQL_RES *res; MYSQL_ROW field; unsigned uCount=0; if(!cSearch[0]) { printf("

tBlockNavList
\n"); printf("Must restrict via cSearch
\n"); return; } ExtSelectSearch("tBlock","tBlock.uBlock,tBlock.cLabel","tBlock.cLabel",cSearch,NULL,0); mysql_query(&gMysql,gcQuery); if(mysql_errno(&gMysql)) { printf("

tBlockNavList
\n"); printf("%s",mysql_error(&gMysql)); return; } res=mysql_store_result(&gMysql); printf("

tBlockNavList
\n"); if(mysql_num_rows(res)) { while((field=mysql_fetch_row(res))) { uCount++; printf("%s
\n",field[0],cURLEncode(cSearch),field[1]); if(uCount>=100) { printf("More than 100 records: You must refine your search further
\n"); break; } } } else printf("No records found
"); mysql_free_result(res); }//void tBlockNavList(void) void tBlockContextInfo(void) { printf("Record Context Info
"); printf("No context info available
"); }//void tBlockContextInfo(void)