mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-29 08:21:12 +02:00
yWeb 2.8.a.4
- updated nhttpd - Code clean up - changes to nhttpd.conf - some changes for logo display git-svn-id: file:///home/bas/coolstream_public_svn/THIRDPARTY/applications/neutrino-experimental@416 e54a6e83-5905-42d5-8d5c-058d10e6a962
This commit is contained in:
@@ -11,18 +11,15 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// HOOK: response_hook
|
||||
//-----------------------------------------------------------------------------
|
||||
THandleStatus CmAuth::Hook_PrepareResponse(CyhookHandler *hh)
|
||||
{
|
||||
THandleStatus CmAuth::Hook_PrepareResponse(CyhookHandler *hh) {
|
||||
THandleStatus status = HANDLED_CONTINUE;
|
||||
|
||||
if(authenticate)
|
||||
{
|
||||
if( (hh->UrlData["clientaddr"]).find(IADDR_LOCAL)>0 &&
|
||||
(no_auth_client == "" ||
|
||||
(hh->UrlData["clientaddr"]).find(no_auth_client)>0)) // dont check local calls or calls from NoAuthClient
|
||||
if (authenticate) {
|
||||
if ((hh->UrlData["clientaddr"]).find(IADDR_LOCAL) > 0
|
||||
&& (no_auth_client == "" || (hh->UrlData["clientaddr"]).find(
|
||||
no_auth_client) > 0)) // dont check local calls or calls from NoAuthClient
|
||||
{
|
||||
if (!CheckAuth(hh))
|
||||
{
|
||||
if (!CheckAuth(hh)) {
|
||||
hh->SetError(HTTP_UNAUTHORIZED);
|
||||
status = HANDLED_ERROR;
|
||||
}
|
||||
@@ -35,62 +32,66 @@ THandleStatus CmAuth::Hook_PrepareResponse(CyhookHandler *hh)
|
||||
// HOOK: webserver_readconfig_hook Handler
|
||||
// This hook ist called from ReadConfig
|
||||
//-----------------------------------------------------------------------------
|
||||
THandleStatus CmAuth::Hook_ReadConfig(CConfigFile *Config, CStringList &ConfigList)
|
||||
{
|
||||
username = Config->getString("mod_auth.username", AUTHUSER);
|
||||
password = Config->getString("mod_auth.password", AUTHPASSWORD);
|
||||
no_auth_client = Config->getString("mod_auth.no_auth_client", "");
|
||||
authenticate = Config->getBool("mod_auth.authenticate", false);
|
||||
THandleStatus CmAuth::Hook_ReadConfig(CConfigFile *Config,
|
||||
CStringList &ConfigList) {
|
||||
username = Config->getString("mod_auth.username", AUTHUSER);
|
||||
password = Config->getString("mod_auth.password", AUTHPASSWORD);
|
||||
no_auth_client = Config->getString("mod_auth.no_auth_client", "");
|
||||
authenticate = Config->getBool("mod_auth.authenticate", false);
|
||||
ConfigList["mod_auth.username"] = username;
|
||||
ConfigList["mod_auth.password"] = password;
|
||||
ConfigList["mod_auth.no_auth_client"] = no_auth_client;
|
||||
ConfigList["mod_auth.authenticate"] = Config->getString("mod_auth.authenticate", "false");
|
||||
ConfigList["mod_auth.authenticate"] = Config->getString(
|
||||
"mod_auth.authenticate", "false");
|
||||
return HANDLED_CONTINUE;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// check if given username an pssword are valid
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CmAuth::CheckAuth(CyhookHandler *hh)
|
||||
{
|
||||
bool CmAuth::CheckAuth(CyhookHandler *hh) {
|
||||
if (hh->HeaderList["Authorization"] == "")
|
||||
return false;
|
||||
std::string encodet = hh->HeaderList["Authorization"].substr(6,hh->HeaderList["Authorization"].length() - 6);
|
||||
std::string encodet = hh->HeaderList["Authorization"].substr(6,
|
||||
hh->HeaderList["Authorization"].length() - 6);
|
||||
std::string decodet = decodeBase64(encodet.c_str());
|
||||
int pos = decodet.find_first_of(':');
|
||||
std::string user = decodet.substr(0,pos);
|
||||
std::string user = decodet.substr(0, pos);
|
||||
std::string passwd = decodet.substr(pos + 1, decodet.length() - pos - 1);
|
||||
return (user.compare(username) == 0 &&
|
||||
passwd.compare(password) == 0);
|
||||
}
|
||||
return (user.compare(username) == 0 && passwd.compare(password) == 0);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// decode Base64 buffer to String
|
||||
//-----------------------------------------------------------------------------
|
||||
std::string CmAuth::decodeBase64(const char *b64buffer)
|
||||
{
|
||||
std::string CmAuth::decodeBase64(const char *b64buffer) {
|
||||
char *newString, *org_newString; //shorter then b64buffer
|
||||
std::string result;
|
||||
if((newString = (char *)malloc(sizeof(char) * strlen(b64buffer) + 1) ) != NULL)
|
||||
{
|
||||
if ((newString = (char *) malloc(sizeof(char) * strlen(b64buffer) + 1))
|
||||
!= NULL) {
|
||||
org_newString = newString;
|
||||
int i = 0;
|
||||
unsigned long c = 0;
|
||||
|
||||
while (*b64buffer)
|
||||
{
|
||||
|
||||
while (*b64buffer) {
|
||||
int oneChar = *b64buffer++;
|
||||
if(oneChar >= '0' && oneChar <= '9') oneChar = oneChar - '0' + 52;
|
||||
else if(oneChar >= 'A' && oneChar <= 'Z') oneChar = oneChar - 'A';
|
||||
else if(oneChar >= 'a' && oneChar <= 'z') oneChar = oneChar - 'a' + 26;
|
||||
else if(oneChar == '+') oneChar = 62;
|
||||
else if(oneChar == '/') oneChar = 63;
|
||||
else if(oneChar == '=') oneChar = 0;
|
||||
else continue;
|
||||
if (oneChar >= '0' && oneChar <= '9')
|
||||
oneChar = oneChar - '0' + 52;
|
||||
else if (oneChar >= 'A' && oneChar <= 'Z')
|
||||
oneChar = oneChar - 'A';
|
||||
else if (oneChar >= 'a' && oneChar <= 'z')
|
||||
oneChar = oneChar - 'a' + 26;
|
||||
else if (oneChar == '+')
|
||||
oneChar = 62;
|
||||
else if (oneChar == '/')
|
||||
oneChar = 63;
|
||||
else if (oneChar == '=')
|
||||
oneChar = 0;
|
||||
else
|
||||
continue;
|
||||
|
||||
c = (c << 6) | oneChar;
|
||||
if (++i == 4)
|
||||
{
|
||||
if (++i == 4) {
|
||||
*newString++ = (char) (c >> 16);
|
||||
*newString++ = (char) (c >> 8);
|
||||
*newString++ = (char) c;
|
||||
@@ -101,8 +102,7 @@ std::string CmAuth::decodeBase64(const char *b64buffer)
|
||||
result = std::string(org_newString);
|
||||
free(org_newString);
|
||||
return result;
|
||||
}
|
||||
else
|
||||
} else
|
||||
return "";
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user