open-source-search-engine/Pages.h

415 lines
13 KiB
C
Raw Normal View History

2013-08-03 00:12:24 +04:00
// Copyright Matt Wells Sep 2004
// used for sending all dynamic html pages
#ifndef _PAGES_H_
#define _PAGES_H_
bool printRedBox2 ( SafeBuf *sb ,
class TcpSocket *sock ,
class HttpRequest *hr );
bool printRedBox ( SafeBuf *mb ,
class TcpSocket *sock ,
class HttpRequest *hr );
2014-04-06 05:09:04 +04:00
2013-08-03 00:12:24 +04:00
// for PageEvents.cpp and Accessdb.cpp
//#define RESULTSWIDTHSTR "550px"
#include "TcpSocket.h"
#include "HttpRequest.h"
#include "HttpServer.h"
#include "SafeBuf.h"
#include "PageCrawlBot.h" // sendPageCrawlBot()
2013-08-03 00:12:24 +04:00
2014-09-25 07:03:16 +04:00
#define GOLD "f3c734"
2014-01-20 06:00:56 +04:00
#define LIGHTER_BLUE "e8e8ff"
2013-08-03 00:12:24 +04:00
#define LIGHT_BLUE "d0d0e0"
#define DARK_BLUE "c0c0f0"
2014-01-19 12:38:02 +04:00
#define DARKER_BLUE "a0a0f0"
#define DARKEST_BLUE "8080f0"
2014-01-19 12:57:20 +04:00
#define TABLE_STYLE " style=\"border-radius:10px;border:#6060f0 2px solid;\" width=100% bgcolor=#a0a0f0 cellpadding=4 border=0 "
2013-08-03 00:12:24 +04:00
extern char *g_msg;
// . declare all dynamic functions here
// . these are all defined in Page*.cpp files
// . these are called to send a dynamic page
2014-09-02 04:04:08 +04:00
bool sendPageWidgets ( TcpSocket *socket , HttpRequest *hr ) ;
2014-02-09 02:10:06 +04:00
bool sendPageBasicSettings ( TcpSocket *s , HttpRequest *r );
bool sendPageBasicStatus ( TcpSocket *s , HttpRequest *r );
2014-02-10 02:09:48 +04:00
//bool sendPageBasicDiffbot ( TcpSocket *s , HttpRequest *r );
2014-02-09 02:10:06 +04:00
2014-11-11 01:45:11 +03:00
bool printGigabotAdvice ( SafeBuf *sb , int32_t page , HttpRequest *hr ,
2014-09-07 08:05:11 +04:00
char *gerrmsg ) ;
2014-02-09 02:10:06 +04:00
2013-08-03 00:12:24 +04:00
bool sendPageRoot ( TcpSocket *s , HttpRequest *r );
bool sendPageRoot ( TcpSocket *s , HttpRequest *r, char *cookie );
bool sendPageResults ( TcpSocket *s , HttpRequest *r );
2014-05-08 00:28:20 +04:00
//bool sendPageWidget ( TcpSocket *s , HttpRequest *r );
2013-08-03 00:12:24 +04:00
//bool sendPageEvents ( TcpSocket *s , HttpRequest *r );
bool sendPageAddUrl ( TcpSocket *s , HttpRequest *r );
bool sendPageGet ( TcpSocket *s , HttpRequest *r );
bool sendPageLogin ( TcpSocket *s , HttpRequest *r );
bool sendPageStats ( TcpSocket *s , HttpRequest *r );
bool sendPageHosts ( TcpSocket *s , HttpRequest *r );
bool sendPageSockets ( TcpSocket *s , HttpRequest *r );
bool sendPageLog ( TcpSocket *s , HttpRequest *r );
bool sendPageMaster ( TcpSocket *s , HttpRequest *r );
bool sendPageSitedb ( TcpSocket *s , HttpRequest *r );
//bool sendPageSync ( TcpSocket *s , HttpRequest *r );
bool sendPagePerf ( TcpSocket *s , HttpRequest *r );
bool sendPageIndexdb ( TcpSocket *s , HttpRequest *r );
bool sendPageTitledb ( TcpSocket *s , HttpRequest *r );
bool sendPageParser ( TcpSocket *s , HttpRequest *r );
bool sendPageSecurity ( TcpSocket *s , HttpRequest *r );
bool sendPageAddColl ( TcpSocket *s , HttpRequest *r );
bool sendPageDelColl ( TcpSocket *s , HttpRequest *r );
bool sendPageCloneColl( TcpSocket *s , HttpRequest *r );
2014-01-10 09:13:41 +04:00
//bool sendPageOverview ( TcpSocket *s , HttpRequest *r );
2013-08-03 00:12:24 +04:00
bool sendPageSpiderdb ( TcpSocket *s , HttpRequest *r );
bool sendPageFilters ( TcpSocket *s , HttpRequest *r );
bool sendPageReindex ( TcpSocket *s , HttpRequest *r );
bool sendPageInject ( TcpSocket *s , HttpRequest *r );
//bool sendPageMatchingQueries ( TcpSocket *s , HttpRequest *r );
bool sendPageSEO ( TcpSocket *s , HttpRequest *r );
bool sendPageAccess ( TcpSocket *s , HttpRequest *r );
bool sendPageSearch2 ( TcpSocket *s , HttpRequest *r );
bool sendPageAddUrl2 ( TcpSocket *s , HttpRequest *r );
bool sendPageGeneric ( TcpSocket *s , HttpRequest *r ); // in Parms.cpp
bool sendPageCatdb ( TcpSocket *s , HttpRequest *r );
bool sendPageDirectory ( TcpSocket *s , HttpRequest *r );
bool sendPageSpamr ( TcpSocket *s , HttpRequest *r );
bool sendPageAutoban ( TcpSocket *s , HttpRequest *r );
//bool sendPageTopDocs ( TcpSocket *s , HttpRequest *r );
bool sendPageTopics ( TcpSocket *s , HttpRequest *r );
//bool sendPageSpiderLocks ( TcpSocket *s , HttpRequest *r );
bool sendPageLogView ( TcpSocket *s , HttpRequest *r );
bool sendPageProfiler ( TcpSocket *s , HttpRequest *r );
bool sendPageReportSpam ( TcpSocket *s , HttpRequest *r );
bool sendPageSpam ( TcpSocket *s , HttpRequest *r );
bool sendPageThreads ( TcpSocket *s , HttpRequest *r );
bool sendPageNetTest ( TcpSocket *s , HttpRequest *r );
bool sendPageAPI ( TcpSocket *s , HttpRequest *r );
2014-08-03 21:42:45 +04:00
bool sendPageAdvanced ( TcpSocket *s , HttpRequest *r );
bool sendPageAbout ( TcpSocket *s , HttpRequest *r );
bool sendPageHelp ( TcpSocket *s , HttpRequest *r );
bool sendPageWordVec ( TcpSocket *s , HttpRequest *r );
2013-08-03 00:12:24 +04:00
bool sendPageQualityAgent ( TcpSocket *s , HttpRequest *r );
bool sendPageThesaurus ( TcpSocket *s , HttpRequest *r );
2014-07-05 21:16:21 +04:00
bool sendPageGraph ( TcpSocket *s , HttpRequest *r );
2014-07-26 04:39:29 +04:00
bool sendPageQA ( TcpSocket *sock , HttpRequest *hr ) ;
2013-08-03 00:12:24 +04:00
// values for m_usePost:
#define M_GET 0x00
#define M_POST 0x01
#define M_MULTI 0x02
2014-06-20 06:42:09 +04:00
// values for WebPage::m_flags
#define PG_NOAPI 0x01
2014-07-13 20:35:44 +04:00
#define PG_STATUS 0x02
#define PG_COLLADMIN 0x04
#define PG_MASTERADMIN 0x08
2014-06-20 06:42:09 +04:00
2013-08-03 00:12:24 +04:00
// . description of a dynamic page
// . we have a static array of these in Pages.cpp
class WebPage {
public:
char m_pageNum; // see enum array below for this
char *m_filename;
2014-11-11 01:45:11 +03:00
int32_t m_flen;
2013-08-03 00:12:24 +04:00
char *m_name; // for printing the links to the pages in admin sect.
bool m_cast; // broadcast input to all hosts?
char m_usePost; // use a POST request/reply instead of GET?
2013-08-03 00:12:24 +04:00
// used because GET's input is limited to a few k.
//char m_perm; // permissions, see USER_* #define's below
char *m_desc; // page description
bool (* m_function)(TcpSocket *s , HttpRequest *r);
2014-11-11 01:45:11 +03:00
int32_t m_niceness;
char *m_reserved1;
char *m_reserved2;
2014-06-20 06:42:09 +04:00
char m_pgflags;
2013-08-03 00:12:24 +04:00
};
class Pages {
public:
2014-11-11 01:45:11 +03:00
WebPage *getPage ( int32_t page ) ;
2013-08-03 00:12:24 +04:00
// . associate each page number (like PAGE_SEARCH) with a callback
// to which we pass the HttpRequest and TcpSocket
// . associate each page with a security level
void init ( );
// return page number for a filename
// returns -1 if page not found
2014-11-11 01:45:11 +03:00
int32_t getPageNumber ( char *filename );
2013-08-03 00:12:24 +04:00
// a request like "GET /sockets" should return PAGE_SOCKETS
2014-11-11 01:45:11 +03:00
int32_t getDynamicPageNumber ( HttpRequest *r ) ;
2013-08-03 00:12:24 +04:00
2014-11-11 01:45:11 +03:00
char *getPath ( int32_t page ) ;
2013-08-03 00:12:24 +04:00
2014-11-11 01:45:11 +03:00
int32_t getNumPages ( );
2013-08-03 00:12:24 +04:00
// this passes control to the dynamic page generation routine based
// on the path of the GET request
2014-11-11 01:45:11 +03:00
bool sendDynamicReply ( TcpSocket *s , HttpRequest *r , int32_t page );
2013-08-03 00:12:24 +04:00
// . each dynamic page generation routine MUST call this to send
// its reply to the requesting client's browser
// . returns false if blocked, true otherwise
// . sets g_errno on error
bool sendPage ( TcpSocket *s ,
char *page ,
2014-11-11 01:45:11 +03:00
int32_t pageLen ,
int32_t cacheTime ,
2013-08-03 00:12:24 +04:00
bool POSTReply ,
char *contentType ) ;
2014-11-11 01:45:11 +03:00
bool broadcastRequest ( TcpSocket *s , HttpRequest *r , int32_t page ) ;
2013-08-03 00:12:24 +04:00
// . returns USER_PUBLIC, USER_MASTER, USER_ADMIN or USER_SPAM
// . used to determine if the client browser has the permission
2014-11-11 01:45:11 +03:00
//int32_t getUserType ( TcpSocket *s , HttpRequest *r ) ;
2013-08-03 00:12:24 +04:00
2014-11-11 01:45:11 +03:00
bool getNiceness ( int32_t page );
2013-08-03 00:12:24 +04:00
//
// HTML generation utility routines
// . (always use the safebuf versions when possible)
// . also, modify both if you modify either!
bool printAdminTop ( SafeBuf *sb ,
2014-09-01 03:23:11 +04:00
TcpSocket *s ,
HttpRequest *r ,
char *qs = NULL,
char* bodyJavascript = "" );
2013-08-03 00:12:24 +04:00
bool printAdminTop2 ( SafeBuf *sb ,
TcpSocket *s ,
HttpRequest *r ,
char *qs = NULL,
char *scripts = NULL,
2014-11-11 01:45:11 +03:00
int32_t scriptsLen = 0);
2013-08-03 00:12:24 +04:00
bool printAdminTop2 ( SafeBuf *sb ,
2014-11-11 01:45:11 +03:00
int32_t page ,
//int32_t user ,
2013-08-03 00:12:24 +04:00
char *username,
char *coll ,
char *pwd ,
2014-11-11 01:45:11 +03:00
int32_t fromIp ,
2013-08-03 00:12:24 +04:00
char *qs = NULL,
char *scripts = NULL,
2014-11-11 01:45:11 +03:00
int32_t scriptsLen = 0);
2013-08-03 00:12:24 +04:00
void printFormTop( SafeBuf *sb, HttpRequest *r );
void printFormData( SafeBuf *sb, TcpSocket *s, HttpRequest *r );
2014-02-09 02:10:06 +04:00
//char *printAdminBottom ( char *p, char *pend, HttpRequest *r );
//char *printAdminBottom ( char *p, char *pend);
2013-08-03 00:12:24 +04:00
bool printAdminBottom ( SafeBuf *sb, HttpRequest *r );
bool printAdminBottom ( SafeBuf *sb);
bool printAdminBottom2 ( SafeBuf *sb, HttpRequest *r );
bool printAdminBottom2 ( SafeBuf *sb);
bool printTail ( SafeBuf* sb,
bool isLocal );
2014-03-10 07:35:45 +04:00
bool printSubmit ( SafeBuf *sb ) ;
2014-11-11 01:45:11 +03:00
//int32_t user ,
2013-08-03 00:12:24 +04:00
//char *username,
//char *pwd );
2014-02-09 02:10:06 +04:00
//char *printTail ( char *p ,
// char *pend ,
// bool isLocal );
2014-11-11 01:45:11 +03:00
//int32_t user ,
2013-08-03 00:12:24 +04:00
//char *username,
//char *pwd ) ;
bool printColors ( SafeBuf *sb , char* bodyJavascript = "" ) ;
2014-02-09 02:10:06 +04:00
//char *printColors ( char *p , char *pend ,
// char* bodyJavascript = "");
2013-08-03 00:12:24 +04:00
2014-02-09 02:10:06 +04:00
//char *printColors2 ( char *p , char *pend ) ;
2013-08-03 00:12:24 +04:00
bool printColors3 ( SafeBuf *sb ) ;
2014-02-09 02:10:06 +04:00
//char *printFocus ( char *p , char *pend ) ;
2013-08-03 00:12:24 +04:00
bool printLogo ( SafeBuf *sb, char *coll ) ;
2014-02-09 02:10:06 +04:00
//char *printLogo ( char *p , char *pend , char *coll ) ;
2013-08-03 00:12:24 +04:00
bool printHostLinks ( SafeBuf *sb ,
2014-11-11 01:45:11 +03:00
int32_t page ,
2013-08-03 00:12:24 +04:00
char *username ,
char *password ,
char *coll ,
char *pwd ,
2014-11-11 01:45:11 +03:00
int32_t fromIp ,
2013-08-03 00:12:24 +04:00
char *qs = NULL ) ;
2014-02-09 02:10:06 +04:00
/*
2013-08-03 00:12:24 +04:00
char *printHostLinks ( char *p ,
char *pend ,
2014-11-11 01:45:11 +03:00
int32_t page ,
2013-08-03 00:12:24 +04:00
char *coll ,
char *pwd ,
2014-11-11 01:45:11 +03:00
int32_t fromIp ,
2013-08-03 00:12:24 +04:00
char *qs = NULL ) ;
2014-02-09 02:10:06 +04:00
*/
2013-08-03 00:12:24 +04:00
bool printAdminLinks ( SafeBuf *sb,
2014-11-11 01:45:11 +03:00
int32_t page ,
2013-08-03 00:12:24 +04:00
char *coll ,
2014-02-10 02:09:48 +04:00
bool isBasic );
2014-02-09 02:10:06 +04:00
/*
2013-08-03 00:12:24 +04:00
char *printAdminLinks ( char *p ,
char *pend ,
2014-11-11 01:45:11 +03:00
int32_t page ,
//int32_t user ,
2013-08-03 00:12:24 +04:00
char *username,
char *coll ,
char *pwd ,
bool top ) ;
2014-02-09 02:10:06 +04:00
*/
2013-08-03 00:12:24 +04:00
bool printCollectionNavBar ( SafeBuf *sb ,
2014-11-11 01:45:11 +03:00
int32_t page ,
//int32_t user ,
2013-08-03 00:12:24 +04:00
char *username,
char *coll ,
char *pwd ,
2014-09-01 08:55:27 +04:00
char *qs ,
TcpSocket *sock ,
HttpRequest *hr );
2014-02-09 02:10:06 +04:00
/*
2013-08-03 00:12:24 +04:00
char *printCollectionNavBar ( char *p ,
char *pend ,
2014-11-11 01:45:11 +03:00
int32_t page ,
//int32_t user ,
2013-08-03 00:12:24 +04:00
char *username,
char *coll ,
char *pwd ,
char *qs = NULL );
2014-02-09 02:10:06 +04:00
*/
2013-08-03 00:12:24 +04:00
/*
bool printRulesetDropDown ( SafeBuf *sb ,
2014-11-11 01:45:11 +03:00
int32_t user ,
2013-08-03 00:12:24 +04:00
char *cgi ,
2014-11-11 01:45:11 +03:00
int32_t selectedNum ,
int32_t subscript );
2013-08-03 00:12:24 +04:00
char *printRulesetDropDown ( char *p ,
char *pend ,
2014-11-11 01:45:11 +03:00
int32_t user ,
2013-08-03 00:12:24 +04:00
char *cgi ,
2014-11-11 01:45:11 +03:00
int32_t selectedNum ,
int32_t subscript ) ;
2013-08-03 00:12:24 +04:00
2014-11-11 01:45:11 +03:00
char *printRulesetDescriptions ( char *p , char *pend , int32_t user ) ;
bool printRulesetDescriptions ( SafeBuf *sb , int32_t user ) ;
2013-08-03 00:12:24 +04:00
*/
};
extern class Pages g_pages;
// . each dynamic page has a number
// . some pages also have urls like /search to mean page=0
enum {
// dummy pages
//PAGE_NOHOSTLINKS = 0,
//PAGE_ADMIN ,
2013-08-03 00:12:24 +04:00
//PAGE_QUALITY ,
//PAGE_PUBLIC ,
2013-08-03 00:12:24 +04:00
// public pages
PAGE_ROOT =0,
2013-08-03 00:12:24 +04:00
PAGE_RESULTS ,
2014-05-08 00:28:20 +04:00
//PAGE_WIDGET,
PAGE_ADDURL , // 5
2013-08-03 00:12:24 +04:00
PAGE_GET ,
PAGE_LOGIN ,
PAGE_DIRECTORY ,
2013-08-03 00:12:24 +04:00
PAGE_REPORTSPAM ,
//PAGE_WORDVECTOR ,
2014-02-08 11:34:45 +04:00
// basic controls page /admin/basic
2014-09-09 18:11:41 +04:00
PAGE_BASIC_SETTINGS , //10
PAGE_BASIC_STATUS ,
2014-02-10 02:09:48 +04:00
//PAGE_BASIC_SEARCH , // TODO
//PAGE_BASIC_DIFFBOT , // TODO
2014-10-01 03:22:18 +04:00
PAGE_COLLPASSWORDS ,//BASIC_SECURITY ,
2014-04-06 05:09:04 +04:00
PAGE_BASIC_SEARCH ,
2014-02-08 11:34:45 +04:00
2013-08-03 00:12:24 +04:00
// master admin pages
2014-09-11 02:05:33 +04:00
PAGE_HOSTS ,
2014-01-10 05:29:18 +04:00
PAGE_MASTER ,
2014-09-09 18:11:41 +04:00
PAGE_SEARCH , // 15
PAGE_SPIDER ,
PAGE_SPIDERPROXIES ,
2014-04-06 05:09:04 +04:00
PAGE_LOG ,
2014-10-27 20:21:23 +03:00
PAGE_COLLPASSWORDS2 ,//BASIC_SECURITY ,
PAGE_MASTERPASSWORDS , // 19
2014-09-09 18:11:41 +04:00
PAGE_ADDCOLL , //20
2014-04-06 05:09:04 +04:00
PAGE_DELCOLL ,
PAGE_CLONECOLL ,
2014-04-06 05:09:04 +04:00
PAGE_REPAIR ,
2014-06-13 19:58:55 +04:00
//PAGE_SITES , // site filters
2014-04-06 05:09:04 +04:00
PAGE_FILTERS ,
PAGE_INJECT ,
2014-07-11 03:42:22 +04:00
PAGE_ADDURL2 , // 26
2014-04-06 05:09:04 +04:00
PAGE_REINDEX ,
2014-01-10 05:29:18 +04:00
PAGE_STATS , // 10
2014-07-05 21:16:21 +04:00
PAGE_GRAPH , // PAGE_STATSDB ,
2014-01-10 05:29:18 +04:00
PAGE_PERF ,
PAGE_SOCKETS ,
2014-04-06 05:09:04 +04:00
2014-01-10 05:29:18 +04:00
PAGE_LOGVIEW ,
2013-08-03 00:12:24 +04:00
// PAGE_SYNC ,
PAGE_AUTOBAN , // 20
2013-08-03 00:12:24 +04:00
//PAGE_SPIDERLOCKS ,
PAGE_PROFILER ,
2013-08-03 00:12:24 +04:00
PAGE_THREADS ,
2014-04-06 05:09:04 +04:00
2013-08-03 00:12:24 +04:00
// PAGE_THESAURUS ,
2014-07-26 04:39:29 +04:00
PAGE_QA,
2014-09-21 03:58:12 +04:00
PAGE_IMPORT,
2014-07-26 04:39:29 +04:00
2013-08-03 00:12:24 +04:00
// . non master-admin pages (collection controls)
// . PAGE_OVERVIEW acts as a cutoff point (search Parms.cpp for it)
2014-01-10 09:13:41 +04:00
//PAGE_OVERVIEW , //25
PAGE_API ,
2013-08-03 00:12:24 +04:00
PAGE_RULES ,
// PAGE_INDEXDB , //30
2013-08-03 00:12:24 +04:00
PAGE_TITLEDB ,
//PAGE_STATSDB ,
PAGE_CRAWLBOT , // 35
PAGE_SPIDERDB ,
2013-08-03 00:12:24 +04:00
//PAGE_PRIORITIES , // priority queue controls
//PAGE_KEYWORDS ,
PAGE_SEO ,
PAGE_ACCESS , //40
PAGE_SEARCHBOX ,
2014-01-10 05:29:18 +04:00
PAGE_PARSER ,
PAGE_SITEDB ,
PAGE_CATDB ,
2013-08-03 00:12:24 +04:00
PAGE_LOGIN2 ,
// PAGE_TOPDOCS ,
// PAGE_TOPICS ,
// PAGE_SPAM ,
// PAGE_QAGENT ,
// PAGE_NETTEST ,
//PAGE_ADFEED ,
// PAGE_TURK2 ,
PAGE_INFO ,
PAGE_NONE };
2014-11-11 01:45:11 +03:00
bool printApiForPage ( SafeBuf *sb , int32_t PAGENUM , CollectionRec *cr ) ;
2013-08-03 00:12:24 +04:00
#endif