Cuberite
A lightweight, fast and extensible game server for Minecraft
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
cWebAdmin Class Reference

#include <WebAdmin.h>

Inheritance diagram for cWebAdmin:
Inheritance graph
[legend]
Collaboration diagram for cWebAdmin:
Collaboration graph
[legend]

Classes

class  abstract
 Interface for getting the content of a single WebTab.
 
class  cWebTab
 Container for a single web tab. More...
 

Public Types

typedef std::shared_ptr< cWebTabcWebTabPtr
 
typedef std::vector< cWebTabPtrcWebTabPtrs
 

Public Member Functions

void AddWebTab (const AString &a_Title, const AString &a_UrlPath, const AString &a_PluginName, std::shared_ptr< cWebTabCallback > a_Callback)
 Adds a new WebTab handler. More...
 
 cWebAdmin (void)
 
bool DelWebTab (const AString &a_UrlPath)
 Removes the WebTab with the specified URL path. More...
 
cWebTabPtrs GetAllWebTabs (void)
 Returns a copy of all the registered web tabs. More...
 
sWebAdminPage GetPage (const HTTPRequest &a_Request)
 Returns the (inner) page contents for the specified request. More...
 
AString GetPorts (void) const
 Returns the list of ports on which the webadmin is configured to listen. More...
 
bool Init (void)
 Initializes the object. More...
 
bool LoadLoginPage (void)
 Loads the login template into m_LoginPage. More...
 
void Reload (void)
 Reloads m_IniFile, m_LoginPage and m_TemplateScript. More...
 
void RemoveAllPluginWebTabs (const AString &a_PluginName)
 Removes all WebTabs registered by the specified plugin. More...
 
bool Start (void)
 Starts the HTTP server taking care of the webadmin. More...
 
void Stop (void)
 Stops the HTTP server, if it was started. More...
 
virtual ~cWebAdmin () override
 
- Public Member Functions inherited from cHTTPServer::cCallbacks
virtual ~cCallbacks ()
 

Static Public Member Functions

static AString GetBaseURL (const AString &a_URL)
 Returns the prefix needed for making a link point to the webadmin root from the given URL ("../../../webadmin"-style). More...
 
static AString GetBaseURL (const AStringVector &a_URLSplit)
 Returns the prefix needed for making a link point to the webadmin root from the given URL ("../../../webadmin"-style) More...
 
static AString GetContentTypeFromFileExt (const AString &a_FileExtension)
 Returns the content type from the file extension. More...
 
static AString GetHTMLEscapedString (const AString &a_Input)
 Escapes text passed into it, so it can be embedded into html. More...
 
static AString GetURLEncodedString (const AString &a_Input)
 Escapes the string for use in an URL Exported to Lua in ManualBindings.cpp. More...
 

Protected Member Functions

void HandleFileRequest (cHTTPServerConnection &a_Connection, cHTTPIncomingRequest &a_Request)
 Handles requests for a file. More...
 
void HandleRootRequest (cHTTPServerConnection &a_Connection, cHTTPIncomingRequest &a_Request)
 Handles requests for the root page. More...
 
void HandleWebadminRequest (cHTTPServerConnection &a_Connection, cHTTPIncomingRequest &a_Request)
 Handles requests coming to the "/webadmin" or "/~webadmin" URLs. More...
 
bool HasUsers ()
 Checks inside the webadmin.ini file if there are users configured. More...
 
bool LoadIniFile (void)
 Loads webadmin.ini into m_IniFile. More...
 
virtual void OnRequestBegun (cHTTPServerConnection &a_Connection, cHTTPIncomingRequest &a_Request) override
 Called when a new request arrives over a connection and all its headers have been parsed. More...
 
virtual void OnRequestBody (cHTTPServerConnection &a_Connection, cHTTPIncomingRequest &a_Request, const char *a_Data, size_t a_Size) override
 Called when another part of request body has arrived. More...
 
virtual void OnRequestFinished (cHTTPServerConnection &a_Connection, cHTTPIncomingRequest &a_Request) override
 Called when the request body has been fully received in previous calls to OnRequestBody() More...
 

Protected Attributes

cCriticalSection m_CS
 Protects m_WebTabs, m_TemplateScript, m_LoginTemplate and m_IniFile against multithreaded access. More...
 
cHTTPServer m_HTTPServer
 The HTTP server which provides the underlying HTTP parsing, serialization and events. More...
 
cIniFile m_IniFile
 The webadmin.ini file, used for the settings and allowed logins. More...
 
bool m_IsInitialized
 Set to true if Init() succeeds and the webadmin isn't to be disabled. More...
 
bool m_IsRunning
 Set to true if Start() succeeds in starting the server, reset back to false in Stop(). More...
 
AString m_LoginPage
 The HTML page that provides the login. More...
 
AStringVector m_Ports
 The ports on which the webadmin is running. More...
 
cLuaState m_TemplateScript
 The Lua template script to provide templates. More...
 
cWebTabPtrs m_WebTabs
 All registered WebTab handlers. More...
 

Detailed Description

Definition at line 98 of file WebAdmin.h.

Member Typedef Documentation

◆ cWebTabPtr

typedef std::shared_ptr<cWebTab> cWebAdmin::cWebTabPtr

Definition at line 147 of file WebAdmin.h.

◆ cWebTabPtrs

typedef std::vector<cWebTabPtr> cWebAdmin::cWebTabPtrs

Definition at line 148 of file WebAdmin.h.

Constructor & Destructor Documentation

◆ cWebAdmin()

cWebAdmin::cWebAdmin ( void  )

Definition at line 61 of file WebAdmin.cpp.

◆ ~cWebAdmin()

cWebAdmin::~cWebAdmin ( )
overridevirtual

Definition at line 72 of file WebAdmin.cpp.

Member Function Documentation

◆ AddWebTab()

void cWebAdmin::AddWebTab ( const AString a_Title,
const AString a_UrlPath,
const AString a_PluginName,
std::shared_ptr< cWebTabCallback >  a_Callback 
)

Adds a new WebTab handler.

a_Title is the display title of the tab a_UrlPath is the part of the URL that uniquely identifies this tab. a_PluginName is the display name of the plugin creating this tab. a_Callback is used to provide the actual WebTab contents, when requested. Exported in ManualBindings.cpp.

Definition at line 538 of file WebAdmin.cpp.

◆ DelWebTab()

bool cWebAdmin::DelWebTab ( const AString a_UrlPath)

Removes the WebTab with the specified URL path.

Returns true if WebTab was found and removed, false if not found. Exported in ManualBindings.cpp

Definition at line 553 of file WebAdmin.cpp.

◆ GetAllWebTabs()

cWebTabPtrs cWebAdmin::GetAllWebTabs ( void  )
inline

Returns a copy of all the registered web tabs.

Exported to Lua in ManualBindings.cpp.

Definition at line 169 of file WebAdmin.h.

◆ GetBaseURL() [1/2]

AString cWebAdmin::GetBaseURL ( const AString a_URL)
static

Returns the prefix needed for making a link point to the webadmin root from the given URL ("../../../webadmin"-style).

Definition at line 529 of file WebAdmin.cpp.

◆ GetBaseURL() [2/2]

AString cWebAdmin::GetBaseURL ( const AStringVector a_URLSplit)
static

Returns the prefix needed for making a link point to the webadmin root from the given URL ("../../../webadmin"-style)

Definition at line 613 of file WebAdmin.cpp.

◆ GetContentTypeFromFileExt()

AString cWebAdmin::GetContentTypeFromFileExt ( const AString a_FileExtension)
static

Returns the content type from the file extension.

If the extension isn't in the list, the function returns an empty string.

Definition at line 439 of file WebAdmin.cpp.

◆ GetHTMLEscapedString()

AString cWebAdmin::GetHTMLEscapedString ( const AString a_Input)
static

Escapes text passed into it, so it can be embedded into html.

Definition at line 573 of file WebAdmin.cpp.

◆ GetPage()

sWebAdminPage cWebAdmin::GetPage ( const HTTPRequest a_Request)

Returns the (inner) page contents for the specified request.

Calls the appropriate WebTab handler to get the contents. Exported to Lua in ManualBindings.cpp.

Definition at line 478 of file WebAdmin.cpp.

◆ GetPorts()

AString cWebAdmin::GetPorts ( void  ) const
inline

Returns the list of ports on which the webadmin is configured to listen.

Definition at line 186 of file WebAdmin.h.

◆ GetURLEncodedString()

AString cWebAdmin::GetURLEncodedString ( const AString a_Input)
static

Escapes the string for use in an URL Exported to Lua in ManualBindings.cpp.

Definition at line 604 of file WebAdmin.cpp.

◆ HandleFileRequest()

void cWebAdmin::HandleFileRequest ( cHTTPServerConnection a_Connection,
cHTTPIncomingRequest a_Request 
)
protected

Handles requests for a file.

Definition at line 387 of file WebAdmin.cpp.

◆ HandleRootRequest()

void cWebAdmin::HandleRootRequest ( cHTTPServerConnection a_Connection,
cHTTPIncomingRequest a_Request 
)
protected

Handles requests for the root page.

Definition at line 372 of file WebAdmin.cpp.

◆ HandleWebadminRequest()

void cWebAdmin::HandleWebadminRequest ( cHTTPServerConnection a_Connection,
cHTTPIncomingRequest a_Request 
)
protected

Handles requests coming to the "/webadmin" or "/~webadmin" URLs.

Definition at line 275 of file WebAdmin.cpp.

◆ HasUsers()

bool cWebAdmin::HasUsers ( )
protected

Checks inside the webadmin.ini file if there are users configured.

Definition at line 258 of file WebAdmin.cpp.

◆ Init()

bool cWebAdmin::Init ( void  )

Initializes the object.

Returns true if successfully initialized and ready to start

Definition at line 81 of file WebAdmin.cpp.

◆ LoadIniFile()

bool cWebAdmin::LoadIniFile ( void  )
protected

Loads webadmin.ini into m_IniFile.

Creates a default file if it doesn't exist. Returns true if webadmin is enabled, false if disabled.

Definition at line 234 of file WebAdmin.cpp.

◆ LoadLoginPage()

bool cWebAdmin::LoadLoginPage ( void  )

Loads the login template into m_LoginPage.

Returns true if the loading succeeds, false if not.

Definition at line 144 of file WebAdmin.cpp.

◆ OnRequestBegun()

void cWebAdmin::OnRequestBegun ( cHTTPServerConnection a_Connection,
cHTTPIncomingRequest a_Request 
)
overrideprotectedvirtual

Called when a new request arrives over a connection and all its headers have been parsed.

The request body needn't have arrived yet.

Implements cHTTPServer::cCallbacks.

Definition at line 631 of file WebAdmin.cpp.

◆ OnRequestBody()

void cWebAdmin::OnRequestBody ( cHTTPServerConnection a_Connection,
cHTTPIncomingRequest a_Request,
const char *  a_Data,
size_t  a_Size 
)
overrideprotectedvirtual

Called when another part of request body has arrived.

May be called multiple times for a single request.

Implements cHTTPServer::cCallbacks.

Definition at line 655 of file WebAdmin.cpp.

◆ OnRequestFinished()

void cWebAdmin::OnRequestFinished ( cHTTPServerConnection a_Connection,
cHTTPIncomingRequest a_Request 
)
overrideprotectedvirtual

Called when the request body has been fully received in previous calls to OnRequestBody()

Implements cHTTPServer::cCallbacks.

Definition at line 670 of file WebAdmin.cpp.

◆ Reload()

void cWebAdmin::Reload ( void  )

Reloads m_IniFile, m_LoginPage and m_TemplateScript.

Note that reloading will not change the "enabled" state of the server, and it will not update listening ports.

Definition at line 182 of file WebAdmin.cpp.

◆ RemoveAllPluginWebTabs()

void cWebAdmin::RemoveAllPluginWebTabs ( const AString a_PluginName)

Removes all WebTabs registered by the specified plugin.

Definition at line 167 of file WebAdmin.cpp.

◆ Start()

bool cWebAdmin::Start ( void  )

Starts the HTTP server taking care of the webadmin.

Returns true if successful

Definition at line 110 of file WebAdmin.cpp.

◆ Stop()

void cWebAdmin::Stop ( void  )

Stops the HTTP server, if it was started.

Definition at line 128 of file WebAdmin.cpp.

Member Data Documentation

◆ m_CS

cCriticalSection cWebAdmin::m_CS
protected

Protects m_WebTabs, m_TemplateScript, m_LoginTemplate and m_IniFile against multithreaded access.

Definition at line 227 of file WebAdmin.h.

◆ m_HTTPServer

cHTTPServer cWebAdmin::m_HTTPServer
protected

The HTTP server which provides the underlying HTTP parsing, serialization and events.

Definition at line 255 of file WebAdmin.h.

◆ m_IniFile

cIniFile cWebAdmin::m_IniFile
protected

The webadmin.ini file, used for the settings and allowed logins.

Protected against multithreaded access by m_CS.

Definition at line 243 of file WebAdmin.h.

◆ m_IsInitialized

bool cWebAdmin::m_IsInitialized
protected

Set to true if Init() succeeds and the webadmin isn't to be disabled.

Definition at line 246 of file WebAdmin.h.

◆ m_IsRunning

bool cWebAdmin::m_IsRunning
protected

Set to true if Start() succeeds in starting the server, reset back to false in Stop().

Definition at line 249 of file WebAdmin.h.

◆ m_LoginPage

AString cWebAdmin::m_LoginPage
protected

The HTML page that provides the login.

Protected against multithreaded access by m_CS.

Definition at line 239 of file WebAdmin.h.

◆ m_Ports

AStringVector cWebAdmin::m_Ports
protected

The ports on which the webadmin is running.

Definition at line 252 of file WebAdmin.h.

◆ m_TemplateScript

cLuaState cWebAdmin::m_TemplateScript
protected

The Lua template script to provide templates.

Protected against multithreaded access by m_CS.

Definition at line 235 of file WebAdmin.h.

◆ m_WebTabs

cWebTabPtrs cWebAdmin::m_WebTabs
protected

All registered WebTab handlers.

Protected against multithreaded access by m_CS.

Definition at line 231 of file WebAdmin.h.


The documentation for this class was generated from the following files: