📄 httpsvc.cxx
字号:
//////////////////////////////////////////////////////////////
PConfigSectionsPage::PConfigSectionsPage(PHTTPServiceProcess & app,
const PURL & url,
const PHTTPAuthority & auth,
const PString & prefix,
const PString & valueName,
const PURL & editSection,
const PURL & newSection,
const PString & newTitle,
PHTML & heading)
: PHTTPConfigSectionList(url, auth, prefix, valueName,
editSection, newSection, newTitle, heading),
process(app)
{
}
void PConfigSectionsPage::OnLoadedText(PHTTPRequest & request, PString & text)
{
PServiceHTML::ProcessMacros(request, text,
GetURL().AsString(PURL::PathOnly).Mid(1),
PServiceHTML::LoadFromFile);
PHTTPConfigSectionList::OnLoadedText(request, text);
}
BOOL PConfigSectionsPage::OnPOST(PHTTPServer & server,
const PURL & url,
const PMIMEInfo & info,
const PStringToString & data,
const PHTTPConnectionInfo & connectInfo)
{
PHTTPConfigSectionList::OnPOST(server, url, info, data, connectInfo);
return FALSE; // Make sure we break any persistent connections
}
BOOL PConfigSectionsPage::Post(PHTTPRequest & request,
const PStringToString & data,
PHTML & reply)
{
BOOL retval = PHTTPConfigSectionList::Post(request, data, reply);
if (request.code == PHTTP::RequestOK)
process.BeginRestartSystem();
return retval;
}
BOOL PConfigSectionsPage::GetExpirationDate(PTime & when)
{
// Well and truly before now....
when = ImmediateExpiryTime;
return TRUE;
}
//////////////////////////////////////////////////////////////
PRegisterPage::PRegisterPage(PHTTPServiceProcess & app,
const PHTTPAuthority & auth)
: PConfigPage(app, "register.html", "Secured Options", auth),
process(app)
{
}
PString PRegisterPage::LoadText(PHTTPRequest & request)
{
if (fields.GetSize() > 0)
return PConfigPage::LoadText(request);
PString mailURL = "mailto:" + process.GetEMailAddress();
PString orderURL = mailURL;
PString tempURL = mailURL;
if (process.GetHomePage() == HOME_PAGE) {
orderURL = "https://home.equival.com.au/purchase.html";
tempURL = "http://www.equival.com/" + process.GetName().ToLower() + "/register.html";
tempURL.Replace(" ", "", TRUE);
}
PServiceHTML regPage(process.GetName() & "Registration", NULL);
regPage << "<!--#registration start Permanent-->"
"Your registration key is permanent.<p>"
"Do not change your registration details or your key will not "
"operate correctly.<p>"
"If you need to "
<< PHTML::HotLink(orderURL)
<< "upgrade"
<< PHTML::HotLink()
<< " or "
<< PHTML::HotLink(mailURL)
<< "change"
<< PHTML::HotLink()
<< " your registration, then you may enter the new values sent "
<< " to you from "
<< process.GetManufacturer()
<< " into the fields "
"below, and then press the Accept button.<p>"
<< PHTML::HRule()
<< "<!--#registration end Permanent-->"
"<!--#registration start Temporary-->"
"Your registration key is temporary and will expire on "
"<!--#registration ExpiryDate-->.<p>"
"Do not change your registration details or your key will not "
"operate correctly.<p>"
"You may "
<< PHTML::HotLink(orderURL)
<< "order a permanent key"
<< PHTML::HotLink()
<< " and enter the new values sent to you from "
<< process.GetManufacturer()
<< " into the fields below, and then press the Accept button.<p>"
<< PHTML::HRule()
<< "<!--#registration end Temporary-->"
"<!--#registration start Expired-->"
"Your temporary registration key has expired.<p>"
"You may "
<< PHTML::HotLink(orderURL)
<< "order a permanent key"
<< PHTML::HotLink()
<< " and enter the new values sent to you from "
<< process.GetManufacturer()
<< " into the fields below, and then press the Accept button.<P>"
<< PHTML::HRule()
<< "<!--#registration end Expired-->";
PSecureConfig securedConf(process.GetProductKey(), process.GetSecuredKeys());
PString prefix;
if (securedConf.GetValidation() != PSecureConfig::IsValid)
prefix = securedConf.GetPendingPrefix();
AddFields(prefix);
Add(new PHTTPStringField("Validation", 40));
BuildHTML(regPage, InsertIntoHTML);
regPage << "<!--#registration start Invalid-->"
"You have entered the values sent to you from "
<< process.GetManufacturer()
<< " incorrectly. Please enter them again. Note, "
<< PHTML::Emphasis() << PHTML::Strong() << "all" << PHTML::Strong() << PHTML::Emphasis()
<< "the fields must be entered "
<< PHTML::Emphasis() << PHTML::Strong() << "exactly" << PHTML::Strong() << PHTML::Emphasis()
<< " as they appear in the e-mail from "
<< process.GetManufacturer()
<< ". We strongly recommend using copy and paste of all the fields, and then "
"press the Accept button."
"<!--#registration end Invalid-->"
"<!--#registration start Default-->"
"You may "
<< PHTML::HotLink(orderURL)
<< "order a permanent key"
<< PHTML::HotLink()
<< " or "
<< PHTML::HotLink(tempURL)
<< "obtain a temporary key"
<< PHTML::HotLink()
<< " and enter the values sent to you from "
<< process.GetManufacturer()
<< " into the fields above, and then press the Accept button.<p>"
"<!--#registration end Default-->"
<< PHTML::HRule()
<< PHTML::Heading(3) << "Disclaimer" << PHTML::Heading(3)
<< PHTML::Paragraph() << PHTML::Bold()
<< "The information and code herein is provided \"as is\" "
"without warranty of any kind, either expressed or implied, "
"including but not limited to the implied warrenties of "
"merchantability and fitness for a particular purpose. In "
"no event shall " << process.GetManufacturer() << " be liable "
"for any damages whatsoever including direct, indirect, "
"incidental, consequential, loss of business profits or special "
"damages, even if " << process.GetManufacturer() << " has been "
"advised of the possibility of such damages."
<< PHTML::Bold() << PHTML::Paragraph()
<< process.GetCopyrightText()
<< PHTML::Body();
SetString(regPage);
return PConfigPage::LoadText(request);
}
static BOOL FindSpliceBlock(const PRegularExpression & regex,
const PString & text,
PINDEX & pos,
PINDEX & len,
PINDEX & start,
PINDEX & finish)
{
if (!text.FindRegEx(regex, pos, len, 0))
return FALSE;
PINDEX endpos, endlen;
static PRegularExpression EndBlock("<?!--#registration[ \t\n]*end[ \t\n]*[a-z]*[ \t\n]*-->?",
PRegularExpression::Extended|PRegularExpression::IgnoreCase);
if (text.FindRegEx(EndBlock, endpos, endlen, pos)) {
start = pos+len;
finish = endpos-1;
len = endpos - pos + endlen;
}
return TRUE;
}
void PRegisterPage::OnLoadedText(PHTTPRequest & request, PString & text)
{
PString block;
PINDEX pos, len, start = 0, finish = 0;
PSecureConfig securedConf(process.GetProductKey(), process.GetSecuredKeys());
PTime expiry = securedConf.GetTime(securedConf.GetExpiryDateKey());
static PRegularExpression Default("<?!--#registration[ \t\n]*start[ \t\n]*Default[ \t\n]*-->?",
PRegularExpression::Extended|PRegularExpression::IgnoreCase);
static PRegularExpression Permanent("<?!--#registration[ \t\n]*start[ \t\n]*Permanent[ \t\n]*-->?",
PRegularExpression::Extended|PRegularExpression::IgnoreCase);
static PRegularExpression Temporary("<?!--#registration[ \t\n]*start[ \t\n]*Temporary[ \t\n]*-->?",
PRegularExpression::Extended|PRegularExpression::IgnoreCase);
static PRegularExpression Expired("<?!--#registration[ \t\n]*start[ \t\n]*Expired[ \t\n]*-->?",
PRegularExpression::Extended|PRegularExpression::IgnoreCase);
static PRegularExpression Invalid("<?!--#registration[ \t\n]*start[ \t\n]*Invalid[ \t\n]*-->?",
PRegularExpression::Extended|PRegularExpression::IgnoreCase);
static PRegularExpression Pending("name[ \t\n]*=[ \t\n]*\"" +
securedConf.GetPendingPrefix() +
"[^\"]+\"",
PRegularExpression::Extended|PRegularExpression::IgnoreCase);
PServiceHTML::ProcessMacros(request, text,
GetURL().AsString(PURL::PathOnly).Mid(1),
PServiceHTML::LoadFromFile);
switch (securedConf.GetValidation()) {
case PSecureConfig::Defaults :
while (FindSpliceBlock(Default, text, pos, len, start, finish))
text.Splice(text(start, finish), pos, len);
while (FindSpliceBlock(Permanent, text, pos, len, start, finish))
text.Delete(pos, len);
while (FindSpliceBlock(Temporary, text, pos, len, start, finish))
text.Delete(pos, len);
while (FindSpliceBlock(Expired, text, pos, len, start, finish))
text.Delete(pos, len);
while (FindSpliceBlock(Invalid, text, pos, len, start, finish))
text.Delete(pos, len);
break;
case PSecureConfig::Invalid :
case PSecureConfig::Pending :
while (FindSpliceBlock(Default, text, pos, len, start, finish))
text.Delete(pos, len);
while (FindSpliceBlock(Permanent, text, pos, len, start, finish))
text.Delete(pos, len);
while (FindSpliceBlock(Temporary, text, pos, len, start, finish))
text.Delete(pos, len);
while (FindSpliceBlock(Expired, text, pos, len, start, finish))
text.Delete(pos, len);
while (FindSpliceBlock(Invalid, text, pos, len, start, finish))
text.Splice(text(start, finish), pos, len);
break;
case PSecureConfig::Expired :
while (FindSpliceBlock(Default, text, pos, len, start, finish))
text.Delete(pos, len);
while (FindSpliceBlock(Permanent, text, pos, len, start, finish))
text.Delete(pos, len);
while (FindSpliceBlock(Temporary, text, pos, len, start, finish))
text.Delete(pos, len);
while (FindSpliceBlock(Expired, text, pos, len, start, finish))
text.Splice(text(start, finish), pos, len);
while (FindSpliceBlock(Invalid, text, pos, len, start, finish))
text.Delete(pos, len);
break;
case PSecureConfig::IsValid :
while (text.FindRegEx(Pending, pos, len)) {
static PINDEX pendingLength = securedConf.GetPendingPrefix().GetLength();
text.Delete(text.Find('"', pos)+1, pendingLength);
start = pos + len - pendingLength;
}
if (expiry.GetYear() < 2011) {
while (FindSpliceBlock(Default, text, pos, len, start, finish))
text.Delete(pos, len);
while (FindSpliceBlock(Permanent, text, pos, len, start, finish))
text.Delete(pos, len);
while (FindSpliceBlock(Temporary, text, pos, len, start, finish))
text.Splice(text(start, finish), pos, len);
while (FindSpliceBlock(Expired, text, pos, len, start, finish))
text.Delete(pos, len);
while (FindSpliceBlock(Invalid, text, pos, len, start, finish))
text.Delete(pos, len);
}
else {
while (FindSpliceBlock(Default, text, pos, len, start, finish))
text.Delete(pos, len);
while (FindSpliceBlock(Permanent, text, pos, len, start, finish))
text.Splice(text(start, finish), pos, len);
while (FindSpliceBlock(Temporary, text, pos, len, start, finish))
text.Delete(pos, len);
while (FindSpliceBlock(Expired, text, pos, len, start, finish))
text.Delete(pos, len);
while (FindSpliceBlock(Invalid, text, pos, len, start, finish))
text.Delete(pos, len);
}
}
static PRegularExpression ExpiryDate("<?!--#registration[ \t\n]*ExpiryDate[ \t\n]*-->?",
PRegularExpression::Extended|PRegularExpression::IgnoreCase);
while (text.FindRegEx(ExpiryDate, pos, len, 0))
text.Splice(expiry.AsString(PTime::LongDate), pos, len);
PHTTPConfig::OnLoadedText(request, text);
PServiceHTML::ProcessMacros(request, text, "", PServiceHTML::NoOptions);
}
BOOL PRegisterPage::Post(PHTTPRequest & request,
const PStringToString & data,
PHTML & reply)
{
if (fields.GetSize() == 0)
LoadText(request);
BOOL retval = PHTTPConfig::Post(request, data, reply);
if (request.code != PHTTP::RequestOK)
return FALSE;
PSecureConfig sconf(process.GetProductKey(), process.GetSecuredKeys());
switch (sconf.GetValidation()) {
case PSecureConfig::Defaults :
sconf.ResetPending();
break;
case PSecureConfig::IsValid :
break;
case PSecureConfig::Pending :
sconf.ValidatePending();
break;
default :
sconf.ResetPending();
}
RemoveAllFields();
LoadText(request);
OnLoadedText(request, reply);
return retval;
}
///////////////////////////////////////////////////////////////////
static void DigestSecuredKeys(PHTTPServiceProcess & process,
PString & reginfo,
PHTML * html)
{
const PStringArray & securedKeys = process.GetSecuredKeys();
PSecureConfig sconf(process.GetProductKey(), securedKeys);
PString prefix;
if (sconf.GetValidation() != PSecureConfig::IsValid)
prefix = sconf.GetPendingPrefix();
PMessageDigest5 digestor;
PStringStream info;
info << '"' << process.GetName() << "\" ===";
PINDEX i;
for (i = 0; i < securedKeys.GetSize(); i++) {
PString val = sconf.GetString(prefix + securedKeys[i]).Trim();
info << " \"" << val << '"';
if (html != NULL)
*html << PHTML::HiddenField(securedKeys[i], val);
digestor.Process(val);
}
PString digest = digestor.Complete();
if (html != NULL)
*html << PHTML::HiddenField("digest", digest);
info.Replace("===", digest);
reginfo = info;
}
///////////////////////////////////////////////////////////////////
PServiceHTML::PServiceHTML(const char * title, const char * help, const char * helpGif)
{
PHTTPServiceProcess::Current().GetPageHeader(*this, title);
ostream & this_stream = *this;
this_stream << PHTML::Heading(1) << title;
if (help != NULL)
this_stream << " "
<< PHTML::HotLink(help)
<< PHTML::Image(helpGif, "Help", 48, 23, "align=absmiddle")
<< PHTML::HotLink();
this_stream << PHTML::Heading(1) << PHTML::Paragraph();
}
PString PServiceHTML::ExtractSignature(PString & out)
{
return ExtractSignature(*this, out);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -