Files

231 lines
6.7 KiB
C
Raw Permalink Normal View History

2013-08-02 13:12:24 -07:00
// Copyright Matt Wells Sep 2004
// used for sending all dynamic html pages
2016-03-08 22:14:30 +01:00
#ifndef GB_PAGES_H
#define GB_PAGES_H
2013-08-02 13:12:24 -07:00
2017-11-14 14:23:54 +01:00
#include <inttypes.h>
#include <stddef.h>
class TcpSocket;
class HttpRequest;
class SafeBuf;
class CollectionRec;
2017-07-20 17:39:55 +02:00
bool printRedBox2 ( SafeBuf *sb ,
class TcpSocket *sock ,
class HttpRequest *hr );
bool printRedBox ( SafeBuf *mb ,
class TcpSocket *sock ,
class HttpRequest *hr );
2014-04-05 18:09:04 -07:00
2014-09-24 20:03:16 -07:00
#define GOLD "f3c734"
2014-01-19 18:00:56 -08:00
#define LIGHTER_BLUE "e8e8ff"
2013-08-02 13:12:24 -07:00
#define LIGHT_BLUE "d0d0e0"
#define DARK_BLUE "c0c0f0"
2014-01-19 00:38:02 -08:00
#define DARKER_BLUE "a0a0f0"
#define DARKEST_BLUE "8080f0"
2014-01-19 00:57:20 -08:00
#define TABLE_STYLE " style=\"border-radius:10px;border:#6060f0 2px solid;\" width=100% bgcolor=#a0a0f0 cellpadding=4 border=0 "
2013-08-02 13:12:24 -07:00
2016-05-22 15:48:11 +02:00
extern const char *g_msg;
2013-08-02 13:12:24 -07:00
// . declare all dynamic functions here
// . these are all defined in Page*.cpp files
// . these are called to send a dynamic page
2014-09-01 17:04:08 -07:00
bool sendPageWidgets ( TcpSocket *socket , HttpRequest *hr ) ;
2014-02-08 15:10:06 -07:00
bool sendPageBasicStatus ( TcpSocket *s , HttpRequest *r );
2016-11-03 13:43:34 +01:00
bool printGigabotAdvice(SafeBuf *sb,
int32_t page,
const HttpRequest *hr,
const char *gerrmsg);
2014-02-08 15:10:06 -07:00
2013-08-02 13:12:24 -07:00
bool sendPageRoot ( TcpSocket *s , HttpRequest *r );
bool sendPageRoot ( TcpSocket *s , HttpRequest *r, char *cookie );
bool sendPageResults ( 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 sendPagePerf ( TcpSocket *s , HttpRequest *r );
bool sendPageTitledb ( TcpSocket *s , HttpRequest *r );
2017-12-28 14:10:06 +01:00
bool sendPageLinkdbLookup(TcpSocket *s, HttpRequest *r);
2017-09-19 15:11:32 +02:00
bool sendPageSpiderdbLookup(TcpSocket *s, HttpRequest *r);
2013-08-02 13:12:24 -07:00
bool sendPageParser ( TcpSocket *s , HttpRequest *r );
bool sendPageAddColl ( TcpSocket *s , HttpRequest *r );
bool sendPageDelColl ( TcpSocket *s , HttpRequest *r );
bool sendPageCloneColl( TcpSocket *s , HttpRequest *r );
2013-08-02 13:12:24 -07:00
bool sendPageSpiderdb ( TcpSocket *s , HttpRequest *r );
2017-07-21 15:06:27 +02:00
bool sendPageDoledbIPTable(TcpSocket *s, HttpRequest *r);
2013-08-02 13:12:24 -07:00
bool sendPageReindex ( TcpSocket *s , HttpRequest *r );
bool sendPageInject ( TcpSocket *s , HttpRequest *r );
bool sendPageAddUrl2 ( TcpSocket *s , HttpRequest *r );
bool sendPageGeneric ( TcpSocket *s , HttpRequest *r ); // in Parms.cpp
bool sendPageProfiler ( TcpSocket *s , HttpRequest *r );
bool sendPageThreads ( TcpSocket *s , HttpRequest *r );
bool sendPageAPI ( TcpSocket *s , HttpRequest *r );
2014-08-03 10:42:45 -07:00
bool sendPageHelp ( TcpSocket *s , HttpRequest *r );
bool sendPageHealthCheck ( TcpSocket *sock , HttpRequest *hr ) ;
bool sendPageDefaultCss(TcpSocket *s, HttpRequest *r);
bool sendPageDocProcess(TcpSocket *s, HttpRequest *r);
2013-08-02 13:12:24 -07:00
enum class page_method_t {
page_method_get = 1, //plain http get
page_method_post_url, //http post, with url-encoded form values
page_method_post_form //http post, with form-data attachement
};
2014-06-19 19:42:09 -07:00
// values for WebPage::m_flags
#define PG_NOAPI 0x01
2014-07-13 09:35:44 -07:00
#define PG_STATUS 0x02
#define PG_COLLADMIN 0x04
#define PG_MASTERADMIN 0x08
#define PG_ACTIVE 0x10
2014-06-19 19:42:09 -07:00
2013-08-02 13:12:24 -07: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
2016-05-22 22:17:23 +02:00
const char *m_filename;
2014-11-10 14:45:11 -08:00
int32_t m_flen;
2016-05-22 22:17:23 +02:00
const char *m_name; // for printing the links to the pages in admin sect.
2013-08-02 13:12:24 -07:00
bool m_cast; // broadcast input to all hosts?
page_method_t m_page_method; // use a POST request/reply instead of GET?
2013-08-02 13:12:24 -07:00
// used because GET's input is limited to a few k.
//char m_perm; // permissions, see USER_* #define's below
2016-05-22 22:17:23 +02:00
const char *m_desc; // page description
2013-08-02 13:12:24 -07:00
bool (* m_function)(TcpSocket *s , HttpRequest *r);
2014-06-19 19:42:09 -07:00
char m_pgflags;
2013-08-02 13:12:24 -07:00
};
class Pages {
public:
2016-05-22 22:17:23 +02:00
const WebPage *getPage ( int32_t page ) ;
2013-08-02 13:12:24 -07: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 ( );
// a request like "GET /sockets" should return PAGE_SOCKETS
2014-11-10 14:45:11 -08:00
int32_t getDynamicPageNumber ( HttpRequest *r ) ;
2013-08-02 13:12:24 -07:00
2016-05-22 22:17:23 +02:00
const char *getPath ( int32_t page ) ;
2013-08-02 13:12:24 -07:00
// this passes control to the dynamic page generation routine based
// on the path of the GET request
2014-11-10 14:45:11 -08:00
bool sendDynamicReply ( TcpSocket *s , HttpRequest *r , int32_t page );
2013-08-02 13:12:24 -07:00
//
// HTML generation utility routines
// . (always use the safebuf versions when possible)
// . also, modify both if you modify either!
bool printAdminTop ( SafeBuf *sb ,
2014-08-31 16:23:11 -07:00
TcpSocket *s ,
HttpRequest *r ,
const char *qs = NULL,
2016-05-11 12:05:36 +02:00
const char* bodyJavascript = "" );
2013-08-02 13:12:24 -07:00
bool printAdminBottom ( SafeBuf *sb);
bool printAdminBottom2 ( SafeBuf *sb);
bool printTail ( SafeBuf* sb, bool isLocal );
2014-03-09 20:35:45 -07:00
bool printSubmit ( SafeBuf *sb ) ;
2013-08-02 13:12:24 -07:00
2016-05-11 12:05:36 +02:00
bool printColors ( SafeBuf *sb , const char* bodyJavascript = "" ) ;
bool printLogo ( SafeBuf *sb, const char *coll ) ;
bool printHostLinks (SafeBuf *sb, int32_t page, const char *coll, int32_t fromIp, const char *qs) ;
2013-08-02 13:12:24 -07:00
bool printAdminLinks ( SafeBuf *sb,
2014-11-10 14:45:11 -08:00
int32_t page ,
const char *coll ,
2014-02-09 15:09:48 -07:00
bool isBasic );
bool printCollectionNavBar (SafeBuf *sb ,
2014-11-10 14:45:11 -08:00
int32_t page ,
const char *coll ,
const char *qs ,
2014-08-31 21:55:27 -07:00
TcpSocket *sock ,
HttpRequest *hr );
2013-08-02 13:12:24 -07:00
};
extern class Pages g_pages;
// . each dynamic page has a number
// . some pages also have urls like /search to mean page=0
enum {
// public pages
PAGE_ROOT =0,
2013-08-02 13:12:24 -07:00
PAGE_RESULTS ,
PAGE_ADDURL ,
2013-08-02 13:12:24 -07:00
PAGE_GET ,
PAGE_LOGIN ,
2014-02-08 00:34:45 -07:00
// basic controls page /admin/basic
PAGE_BASIC_SETTINGS ,
PAGE_BASIC_STATUS ,
2014-09-30 16:22:18 -07:00
PAGE_COLLPASSWORDS ,//BASIC_SECURITY ,
2014-04-05 18:09:04 -07:00
PAGE_BASIC_SEARCH ,
2014-02-08 00:34:45 -07:00
2013-08-02 13:12:24 -07:00
// master admin pages
2014-09-10 15:05:33 -07:00
PAGE_HOSTS ,
PAGE_MASTER ,
PAGE_RDB ,
PAGE_SEARCH ,
PAGE_WORD_VARIATIONS,
PAGE_RANKING ,
2014-09-09 07:11:41 -07:00
PAGE_SPIDER ,
PAGE_SPIDERPROXIES ,
2014-04-05 18:09:04 -07:00
PAGE_LOG ,
2014-10-27 11:21:23 -06:00
PAGE_COLLPASSWORDS2 ,//BASIC_SECURITY ,
PAGE_MASTERPASSWORDS ,
#ifndef PRIVACORE_SAFE_VERSION
PAGE_ADDCOLL ,
2014-04-05 18:09:04 -07:00
PAGE_DELCOLL ,
PAGE_CLONECOLL ,
#endif
PAGE_REPAIR ,
2014-04-05 18:09:04 -07:00
PAGE_FILTERS ,
PAGE_INJECT ,
PAGE_ADDURL2 ,
2014-04-05 18:09:04 -07:00
PAGE_REINDEX ,
PAGE_STATS ,
2014-01-09 17:29:18 -08:00
PAGE_PERF ,
PAGE_SOCKETS ,
2014-04-05 18:09:04 -07:00
PAGE_PROFILER ,
2013-08-02 13:12:24 -07:00
PAGE_THREADS ,
2014-04-05 18:09:04 -07:00
PAGE_API ,
2013-08-02 13:12:24 -07:00
PAGE_TITLEDB ,
2017-12-28 14:10:06 +01:00
PAGE_LINKDBLOOKUP,
2017-09-19 15:11:32 +02:00
PAGE_SPIDERDBLOOKUP,
PAGE_SPIDERDB ,
2017-07-21 15:06:27 +02:00
PAGE_DOLEIPTABLE ,
2013-08-02 13:12:24 -07:00
PAGE_SEARCHBOX ,
2014-01-09 17:29:18 -08:00
PAGE_PARSER ,
PAGE_DOCPROCESS ,
PAGE_SITEDB ,
PAGE_HEALTHCHECK ,
2013-08-02 13:12:24 -07:00
PAGE_NONE };
2014-11-10 14:45:11 -08:00
bool printApiForPage ( SafeBuf *sb , int32_t PAGENUM , CollectionRec *cr ) ;
2016-03-08 22:14:30 +01:00
#endif // GB_PAGES_H