#include "gb-include.h" #include "Pages.h" #include "TcpSocket.h" #include "HttpRequest.h" #include "Collectiondb.h" //#include "CollectionRec.h" #include "Users.h" #include "Parms.h" bool sendPageAddDelColl ( TcpSocket *s , HttpRequest *r , bool add ) ; bool sendPageAddColl ( TcpSocket *s , HttpRequest *r ) { return sendPageAddDelColl ( s , r , true ); } bool sendPageDelColl ( TcpSocket *s , HttpRequest *r ) { return sendPageAddDelColl ( s , r , false ); } bool sendPageAddDelColl ( TcpSocket *s , HttpRequest *r , bool add ) { // get collection name //long nclen; //char *nc = r->getString ( "nc" , &nclen ); //long cpclen; //char *cpc = r->getString ( "cpc" , &cpclen ); g_errno = 0; //bool cast = r->getLong("cast",0); char *msg = NULL; // if any host in network is dead, do not do this //if ( g_hostdb.hasDeadHost() ) msg = "A host in the network is dead."; // . are we adding a collection? // . return if error adding, might already exist! // . g_errno should be set // . WE DO NOT NEED THIS ANYMORE. Pages.cpp now broadcasts // addcoll as CommandAddColl() parm. /* if ( nclen > 0 && add && ! cast ) { // do not allow "main" that is used for the "" collection // for backwards compatibility //if ( strcmp ( nc , "main" ) != 0 ) g_collectiondb.addRec (nc,cpc,cpclen,true,(collnum_t)-1, false , // isdump? true ) ;// save it? //else // log("admin: \"main\" collection is forbidden."); } if ( ! add && ! cast ) g_collectiondb.deleteRecs ( r ) ; */ char format = r->getReplyFormat(); if ( format == FORMAT_XML || format == FORMAT_JSON ) { // no addcoll given? long page = g_pages.getDynamicPageNumber ( r ); char *addcoll = r->getString("addcoll",NULL); char *delcoll = r->getString("delcoll",NULL); if ( ! addcoll ) addcoll = r->getString("addColl",NULL); if ( ! delcoll ) delcoll = r->getString("delColl",NULL); if ( page == PAGE_ADDCOLL && ! addcoll ) { g_errno = EBADENGINEER; char *msg = "no addcoll parm provided"; return g_httpServer.sendErrorReply(s,g_errno,msg,NULL); } if ( page == PAGE_DELCOLL && ! delcoll ) { g_errno = EBADENGINEER; char *msg = "no delcoll parm provided"; return g_httpServer.sendErrorReply(s,g_errno,msg,NULL); } return g_httpServer.sendSuccessReply(s,format); } // error? char *action = r->getString("action",NULL); char *addColl = r->getString("addcoll",NULL); char buf [ 64*1024 ]; SafeBuf p(buf, 64*1024); // // CLOUD SEARCH ENGIEN SUPPORT - GIGABOT ERRORS // SafeBuf gtmp; char *gmsg = NULL; // is it too big? if ( action && addColl && gbstrlen(addColl) > MAX_COLL_LEN ) { gtmp.safePrintf("search engine name is too long"); gmsg = gtmp.getBufStart(); } // from Collectiondb.cpp::addNewColl() ensure coll name is legit char *x = addColl; for ( ; x && *x ; x++ ) { if ( is_alnum_a(*x) ) continue; if ( *x == '-' ) continue; if ( *x == '_' ) continue; // underscore now allowed break; } if ( x && *x ) { g_errno = EBADENGINEER; gtmp.safePrintf("Error. \"%s\" is a " "malformed name because it " "contains the '%c' character.

", addColl,*x); gmsg = gtmp.getBufStart(); } // // END GIGABOT ERRORS // // // CLOUD SEARCH ENGINE SUPPORT // // if added the coll successfully, do not print same page, jump to // printing the basic settings page so they can add sites to it. // crap, this GET request, "r", is missing the "c" parm sometimes. // we need to use the "addcoll" parm anyway. maybe print a meta // redirect then? char guide = r->getLong("guide",0); // do not redirect if gmsg is set, there was a problem with the name if ( action && ! msg && format == FORMAT_HTML && guide && ! gmsg ) { //return g_parms.sendPageGeneric ( s, r, PAGE_BASIC_SETTINGS ); // just redirect to it if ( addColl ) p.safePrintf("", addColl); return g_httpServer.sendDynamicPage (s, p.getBufStart(), p.length()); } // print standard header g_pages.printAdminTop ( &p , s , r , NULL, "onload=document." "getElementById('acbox').focus();"); // gigabot error? //if ( gmsg ) // p.safePrintf("Gigabot says: %s

",gmsg); //long page = g_pages.getDynamicPageNumber ( r ); //char *coll = r->getString ( "c" ); //char *pwd = r->getString ( "pwd" ); //char *username = g_users.getUsername( r ); //long user = g_pages.getUserType ( s , r ); //if ( ! coll ) coll = ""; //if ( ! nc ) nc = ""; //if ( ! pwd ) pwd = ""; if ( g_errno ) msg = mstrerror(g_errno); if ( msg && ! guide ) { char *cc = "deleting"; if ( add ) cc = "adding"; p.safePrintf ( "
\n" "" "Error %s collection: %s. " "See log file for details." "" "

\n",cc,msg); } // // CLOUD SEARCH ENGINE SUPPORT // if ( add && guide ) printGigabotAdvice ( &p , PAGE_ADDCOLL , r , gmsg ); // print the add collection box if ( add /*&& (! nc[0] || g_errno ) */ ) { char *t1 = "Add Collection"; if ( guide ) t1 = "Add Search Engine"; p.safePrintf ( "
\n\n" "\n" ,TABLE_STYLE ,t1 ); char *t2 = "collection"; if ( guide ) t2 = "search engine"; char *str = addColl; if ( ! addColl ) str = ""; p.safePrintf ( "" "\n" "\n" , LIGHT_BLUE , t2 , str ); // don't show the clone box if we are under gigabot the guide if ( ! guide ) p.safePrintf( "" "\n" "" "" , LIGHT_BLUE ); // now list collections from which to copy the config //p.safePrintf ( // "\n" // "\n",coll); p.safePrintf ( "
" "
%s
" "
name of new %s to add" "
clone settings from this " "collection" "
Copy settings from " "this pre-existing collection. Leave " "blank to " "accept default values.
" "
copy configuration from this " // "collection
Leave blank to " // "accept default values.
" // "

\n"); // wrap up the form started by printAdminTop g_pages.printAdminBottom ( &p ); long bufLen = p.length(); return g_httpServer.sendDynamicPage (s,p.getBufStart(),bufLen); } // if we added a collection, print its page //if ( add && nc[0] && ! g_errno ) // return g_parms.sendPageGeneric2 ( s , r , PAGE_SEARCH , // nc , pwd ); if ( g_collectiondb.m_numRecsUsed <= 0 ) goto skip; // print all collections out in a checklist so you can check the // ones you want to delete, the values will be the id of that collectn p.safePrintf ( "
\n\n" "\n" "\n" "
Delete Collections" "
" "
Select the collections you wish to delete. " //"This feature is currently under " //"development." "
" // table within a table "
\n", TABLE_STYLE, LIGHT_BLUE, DARK_BLUE ); for ( long i = 0 ; i < g_collectiondb.m_numRecs ; i++ ) { CollectionRec *cr = g_collectiondb.m_recs[i]; if ( ! cr ) continue; p.safePrintf ( "\n", DARK_BLUE, cr->m_coll,cr->m_coll); } p.safePrintf( "
" " " "%s

\n" ); skip: // wrap up the form started by printAdminTop g_pages.printAdminBottom ( &p ); long bufLen = p.length(); return g_httpServer.sendDynamicPage (s,p.getBufStart(),bufLen); } bool sendPageCloneColl ( TcpSocket *s , HttpRequest *r ) { char format = r->getReplyFormat(); char *coll = r->getString("c"); if ( format == FORMAT_XML || format == FORMAT_JSON ) { if ( ! coll ) { g_errno = EBADENGINEER; char *msg = "no c parm provided"; return g_httpServer.sendErrorReply(s,g_errno,msg,NULL); } return g_httpServer.sendSuccessReply(s,format); } char buf [ 64*1024 ]; SafeBuf p(buf, 64*1024); // print standard header g_pages.printAdminTop ( &p , s , r ); char *msg = NULL; if ( g_errno ) msg = mstrerror(g_errno); if ( msg ) { p.safePrintf ( "
\n" "" "Error cloning collection: %s. " "See log file for details." "" "

\n",msg); } // print the clone box p.safePrintf ( "
\n\n" "\n", TABLE_STYLE); p.safePrintf ( "" "\n" "" "" , LIGHT_BLUE ); p.safePrintf ( "
" "
Clone Collection
" "
clone settings from this collection" "
Copy settings FROM this " "pre-existing collection into the currently " "selected collection." "
" "

\n"); // wrap up the form started by printAdminTop g_pages.printAdminBottom ( &p ); long bufLen = p.length(); return g_httpServer.sendDynamicPage (s,p.getBufStart(),bufLen); }