Files
znc/include/znc/WebModules.h
Alexey Sokolov b2dcad5fd4 Change ZNC license to Apache 2.0
The following people agreed with the change, in alphabetical order:
(people who approved in several ways are listed only once)
By email:
- Adam (from Anope)
- Austin Morton
- Brian Campbell
- Christian Walde
- Daniel Holbert
- Daniel Wallace
- Falk Seidel
- Heiko Hund
- Ingmar Runge
- Jim Hull
- Kyle Fuller
- Lee Aylward
- Martin Martimeo
- Matt Harper
- Michael J Edgar
- Michael Ziegler
- Nick Bebout
- Paul Driver
- Perry Nguyen
- Philippe (cycomate)
- Reuben Morais
- Roland Hieber
- Sebastian Ramacher
- Stefan Rado
- Stéphan Kochen
- Thomas Ward
- Toon Schoenmakers
- Veit Wahlich
- Wulf C. Krueger

By IRC:
- CNU
- Jonas Gorski
- Joshua M. Clulow
- Prozac/SHiZNO
- SilverLeo
- Uli Schlachter

At https://github.com/znc/znc/issues/311 :
- Alexey Sokolov
- Elizabeth Myers
- flakes
- Jens-Andre Koch
- Jyzee
- KindOne/ineedalifetoday
- Lee Williams
- Mantas Mikulėnas
- md-5
- Reed Loden

At the last few pull requests' comments:
- Allan Odgaard
- Jacob Baines
- Lluís Batlle i Rossell
- ravomavain
- protomouse

The following commits' authors didn't respond:
Trivial changes:
- f70f1086fd
- 4ca8b50e45

The changes which are not presented in master anymore:
- 5512ed2ea0
- 960a4498f7
- 0f739de2c0
- 7f53cc810b

Fix #311
Fix #218
2013-06-14 00:43:34 +04:00

168 lines
4.9 KiB
C++

/*
* Copyright (C) 2004-2013 ZNC, see the NOTICE file for details.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _WEBMODULES_H
#define _WEBMODULES_H
#include <znc/zncconfig.h>
#include <znc/Template.h>
#include <znc/HTTPSock.h>
class CAuthBase;
class CUser;
class CWebSock;
class CModule;
class CWebSubPage;
typedef CSmartPtr<CWebSubPage> TWebSubPage;
typedef std::vector<TWebSubPage> VWebSubPages;
class CZNCTagHandler : public CTemplateTagHandler {
public:
CZNCTagHandler(CWebSock& pWebSock);
virtual ~CZNCTagHandler() {}
virtual bool HandleTag(CTemplate& Tmpl, const CString& sName, const CString& sArgs, CString& sOutput);
private:
CWebSock& m_WebSock;
};
class CWebSession {
public:
CWebSession(const CString& sId, const CString& sIP);
~CWebSession();
const CString& GetId() const { return m_sId; }
const CString& GetIP() const { return m_sIP; }
CUser* GetUser() const { return m_pUser; }
bool IsLoggedIn() const { return m_pUser != NULL; }
bool IsAdmin() const;
CUser* SetUser(CUser* p) { m_pUser = p; return m_pUser; }
void ClearMessageLoops();
void FillMessageLoops(CTemplate& Tmpl);
size_t AddError(const CString& sMessage);
size_t AddSuccess(const CString& sMessage);
private:
CString m_sId;
CString m_sIP;
CUser* m_pUser;
VCString m_vsErrorMsgs;
VCString m_vsSuccessMsgs;
};
class CWebSubPage {
public:
CWebSubPage(const CString& sName, const CString& sTitle = "", unsigned int uFlags = 0) : m_sName(sName), m_sTitle(sTitle) {
m_uFlags = uFlags;
}
CWebSubPage(const CString& sName, const CString& sTitle, const VPair& vParams, unsigned int uFlags = 0) : m_sName(sName), m_sTitle(sTitle), m_vParams(vParams) {
m_uFlags = uFlags;
}
virtual ~CWebSubPage() {}
enum {
F_ADMIN = 1
};
void SetName(const CString& s) { m_sName = s; }
void SetTitle(const CString& s) { m_sTitle = s; }
void AddParam(const CString& sName, const CString& sValue) { m_vParams.push_back(make_pair(sName, sValue)); }
bool RequiresAdmin() const { return m_uFlags & F_ADMIN; }
const CString& GetName() const { return m_sName; }
const CString& GetTitle() const { return m_sTitle; }
const VPair& GetParams() const { return m_vParams; }
private:
unsigned int m_uFlags;
CString m_sName;
CString m_sTitle;
VPair m_vParams;
};
class CWebSessionMap : public TCacheMap<CString, CSmartPtr<CWebSession> > {
public:
CWebSessionMap(unsigned int uTTL = 5000) : TCacheMap<CString, CSmartPtr<CWebSession> >(uTTL) {}
void FinishUserSessions(const CUser& User);
};
class CWebSock : public CHTTPSock {
public:
enum EPageReqResult {
PAGE_NOTFOUND, // print 404 and Close()
PAGE_PRINT, // print page contents and Close()
PAGE_DEFERRED, // async processing, Close() will be called from a different place
PAGE_DONE // all stuff has been done
};
CWebSock();
virtual ~CWebSock();
virtual bool ForceLogin();
virtual bool OnLogin(const CString& sUser, const CString& sPass);
virtual void OnPageRequest(const CString& sURI);
EPageReqResult PrintTemplate(const CString& sPageName, CString& sPageRet, CModule* pModule = NULL);
EPageReqResult PrintStaticFile(const CString& sPath, CString& sPageRet, CModule* pModule = NULL);
CString FindTmpl(CModule* pModule, const CString& sName);
void PrintErrorPage(const CString& sMessage);
CSmartPtr<CWebSession> GetSession();
virtual Csock* GetSockObj(const CString& sHost, unsigned short uPort);
static CString GetSkinPath(const CString& sSkinName);
CModule* GetModule() const { return (CModule*) m_pModule; }
void GetAvailSkins(VCString& vRet) const;
CString GetSkinName();
CString GetRequestCookie(const CString& sKey);
bool SendCookie(const CString& sKey, const CString& sValue);
static void FinishUserSessions(const CUser& User);
protected:
using CHTTPSock::PrintErrorPage;
bool AddModLoop(const CString& sLoopName, CModule& Module, CTemplate *pTemplate = NULL);
VCString GetDirs(CModule* pModule, bool bIsTemplate);
void SetPaths(CModule* pModule, bool bIsTemplate = false);
void SetVars();
CString GetCSRFCheck();
private:
EPageReqResult OnPageRequestInternal(const CString& sURI, CString& sPageRet);
bool m_bPathsSet;
CTemplate m_Template;
CSmartPtr<CAuthBase> m_spAuth;
CString m_sModName;
CString m_sPath;
CString m_sPage;
CSmartPtr<CWebSession> m_spSession;
static const unsigned int m_uiMaxSessions;
};
#endif // !_WEBMODULES_H