added: Rebus
(when no logged user wants to send a message then he is asked a question) git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@521 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
@@ -4,12 +4,12 @@ acceptbaseparser.o: acceptbaseparser.h
|
||||
compress.o: compress.h log.h
|
||||
config.o: config.h ../confparser/confparser.h log.h data.h dirs.h item.h
|
||||
config.o: dircontainer.h users.h user.h ugcontainer.h groups.h group.h
|
||||
config.o: functions.h function.h lastcontainer.h mounts.h mount.h plugin.h
|
||||
config.o: request.h requesttypes.h session.h done.h error.h thread.h
|
||||
config.o: functions.h function.h lastcontainer.h mounts.h mount.h rebus.h
|
||||
config.o: plugin.h request.h requesttypes.h session.h done.h error.h thread.h
|
||||
config.o: compress.h acceptencodingparser.h acceptbaseparser.h pluginmsg.h
|
||||
data.o: data.h dirs.h item.h dircontainer.h users.h user.h ugcontainer.h
|
||||
data.o: log.h groups.h group.h functions.h function.h lastcontainer.h
|
||||
data.o: mounts.h mount.h
|
||||
data.o: mounts.h mount.h rebus.h
|
||||
db.o: db.h item.h user.h group.h thread.h error.h log.h dircontainer.h
|
||||
db.o: ugcontainer.h misc.h
|
||||
db_itemcolumns.o: db.h item.h user.h group.h thread.h error.h log.h
|
||||
@@ -17,7 +17,7 @@ db_itemcolumns.o: dircontainer.h ugcontainer.h
|
||||
dircontainer.o: dircontainer.h item.h log.h
|
||||
dirs.o: dirs.h item.h dircontainer.h error.h log.h db.h user.h group.h
|
||||
dirs.o: thread.h ugcontainer.h data.h users.h groups.h functions.h function.h
|
||||
dirs.o: lastcontainer.h mounts.h mount.h
|
||||
dirs.o: lastcontainer.h mounts.h mount.h rebus.h
|
||||
done.o: done.h
|
||||
error.o: error.h log.h
|
||||
function.o: function.h item.h
|
||||
@@ -25,8 +25,8 @@ functioncodeparser.o: functioncodeparser.h item.h function.h log.h
|
||||
functionparser.o: functionparser.h requesttypes.h log.h item.h error.h data.h
|
||||
functionparser.o: dirs.h dircontainer.h users.h user.h ugcontainer.h groups.h
|
||||
functionparser.o: group.h functions.h function.h lastcontainer.h mounts.h
|
||||
functionparser.o: mount.h db.h thread.h request.h session.h done.h compress.h
|
||||
functionparser.o: acceptencodingparser.h acceptbaseparser.h
|
||||
functionparser.o: mount.h rebus.h db.h thread.h request.h session.h done.h
|
||||
functionparser.o: compress.h acceptencodingparser.h acceptbaseparser.h
|
||||
functions.o: functions.h function.h item.h
|
||||
groups.o: groups.h group.h ugcontainer.h log.h db.h item.h user.h thread.h
|
||||
groups.o: error.h dircontainer.h
|
||||
@@ -37,32 +37,34 @@ misc.o: misc.h item.h log.h
|
||||
mount.o: mount.h
|
||||
mountparser.o: mountparser.h mount.h item.h error.h log.h data.h dirs.h
|
||||
mountparser.o: dircontainer.h users.h user.h ugcontainer.h groups.h group.h
|
||||
mountparser.o: functions.h function.h lastcontainer.h mounts.h
|
||||
mountparser.o: functions.h function.h lastcontainer.h mounts.h rebus.h
|
||||
mounts.o: mounts.h mount.h data.h dirs.h item.h dircontainer.h users.h user.h
|
||||
mounts.o: ugcontainer.h log.h groups.h group.h functions.h function.h
|
||||
mounts.o: lastcontainer.h request.h requesttypes.h session.h done.h error.h
|
||||
mounts.o: thread.h compress.h acceptencodingparser.h acceptbaseparser.h
|
||||
mounts.o: mountparser.h db.h
|
||||
mounts.o: lastcontainer.h rebus.h request.h requesttypes.h session.h done.h
|
||||
mounts.o: error.h thread.h compress.h acceptencodingparser.h
|
||||
mounts.o: acceptbaseparser.h mountparser.h db.h
|
||||
notify.o: log.h notify.h ../templatesnotify/templatesnotify.h ../core/mount.h
|
||||
notify.o: data.h dirs.h item.h dircontainer.h users.h user.h ugcontainer.h
|
||||
notify.o: groups.h group.h functions.h function.h lastcontainer.h mounts.h
|
||||
notify.o: mount.h misc.h request.h requesttypes.h session.h done.h error.h
|
||||
notify.o: thread.h compress.h acceptencodingparser.h acceptbaseparser.h
|
||||
notify.o: mount.h rebus.h misc.h request.h requesttypes.h session.h done.h
|
||||
notify.o: error.h thread.h compress.h acceptencodingparser.h
|
||||
notify.o: acceptbaseparser.h
|
||||
plugin.o: plugin.h request.h requesttypes.h session.h done.h item.h error.h
|
||||
plugin.o: log.h user.h function.h thread.h compress.h acceptencodingparser.h
|
||||
plugin.o: acceptbaseparser.h data.h dirs.h dircontainer.h users.h
|
||||
plugin.o: ugcontainer.h groups.h group.h functions.h lastcontainer.h mounts.h
|
||||
plugin.o: mount.h pluginmsg.h
|
||||
plugin.o: log.h user.h rebus.h function.h thread.h compress.h
|
||||
plugin.o: acceptencodingparser.h acceptbaseparser.h data.h dirs.h
|
||||
plugin.o: dircontainer.h users.h ugcontainer.h groups.h group.h functions.h
|
||||
plugin.o: lastcontainer.h mounts.h mount.h pluginmsg.h
|
||||
rebus.o: log.h rebus.h misc.h item.h
|
||||
request.o: request.h requesttypes.h session.h done.h item.h error.h log.h
|
||||
request.o: user.h function.h thread.h compress.h acceptencodingparser.h
|
||||
request.o: acceptbaseparser.h getparser.h httpsimpleparser.h postparser.h
|
||||
request.o: cookieparser.h data.h dirs.h dircontainer.h users.h ugcontainer.h
|
||||
request.o: groups.h group.h functions.h lastcontainer.h mounts.h mount.h
|
||||
request.o: plugin.h pluginmsg.h
|
||||
request.o: user.h rebus.h function.h thread.h compress.h
|
||||
request.o: acceptencodingparser.h acceptbaseparser.h getparser.h
|
||||
request.o: httpsimpleparser.h postparser.h cookieparser.h data.h dirs.h
|
||||
request.o: dircontainer.h users.h ugcontainer.h groups.h group.h functions.h
|
||||
request.o: lastcontainer.h mounts.h mount.h plugin.h pluginmsg.h
|
||||
requestcontroller.o: requestcontroller.h ../content/content.h ../core/item.h
|
||||
requestcontroller.o: ../templates/templates.h ../templates/patterncacher.h
|
||||
requestcontroller.o: ../core/thread.h sessionmanager.h sessioncontainer.h
|
||||
requestcontroller.o: session.h done.h item.h error.h log.h user.h
|
||||
requestcontroller.o: session.h done.h item.h error.h log.h user.h rebus.h
|
||||
requestcontroller.o: functionparser.h requesttypes.h data.h dirs.h
|
||||
requestcontroller.o: dircontainer.h users.h ugcontainer.h groups.h group.h
|
||||
requestcontroller.o: functions.h function.h lastcontainer.h mounts.h mount.h
|
||||
@@ -70,14 +72,14 @@ requestcontroller.o: request.h thread.h compress.h acceptencodingparser.h
|
||||
requestcontroller.o: acceptbaseparser.h postparser.h httpsimpleparser.h
|
||||
requestcontroller.o: cookieparser.h notify.h
|
||||
requestcontroller.o: ../templatesnotify/templatesnotify.h ../core/mount.h
|
||||
session.o: session.h done.h item.h error.h log.h user.h
|
||||
session.o: session.h done.h item.h error.h log.h user.h rebus.h
|
||||
sessioncontainer.o: sessioncontainer.h session.h done.h item.h error.h log.h
|
||||
sessioncontainer.o: user.h data.h dirs.h dircontainer.h users.h ugcontainer.h
|
||||
sessioncontainer.o: groups.h group.h functions.h function.h lastcontainer.h
|
||||
sessioncontainer.o: mounts.h mount.h
|
||||
sessioncontainer.o: user.h rebus.h data.h dirs.h dircontainer.h users.h
|
||||
sessioncontainer.o: ugcontainer.h groups.h group.h functions.h function.h
|
||||
sessioncontainer.o: lastcontainer.h mounts.h mount.h
|
||||
sessionmanager.o: sessionmanager.h sessioncontainer.h session.h done.h item.h
|
||||
sessionmanager.o: error.h log.h user.h request.h requesttypes.h function.h
|
||||
sessionmanager.o: thread.h compress.h acceptencodingparser.h
|
||||
sessionmanager.o: error.h log.h user.h rebus.h request.h requesttypes.h
|
||||
sessionmanager.o: function.h thread.h compress.h acceptencodingparser.h
|
||||
sessionmanager.o: acceptbaseparser.h data.h dirs.h dircontainer.h users.h
|
||||
sessionmanager.o: ugcontainer.h groups.h group.h functions.h lastcontainer.h
|
||||
sessionmanager.o: mounts.h mount.h
|
||||
|
||||
@@ -1 +1 @@
|
||||
o = acceptbaseparser.o compress.o config.o data.o db.o db_itemcolumns.o dircontainer.o dirs.o done.o error.o function.o functioncodeparser.o functionparser.o functions.o groups.o httpsimpleparser.o lastcontainer.o log.o misc.o mount.o mountparser.o mounts.o notify.o plugin.o request.o requestcontroller.o session.o sessioncontainer.o sessionmanager.o users.o
|
||||
o = acceptbaseparser.o compress.o config.o data.o db.o db_itemcolumns.o dircontainer.o dirs.o done.o error.o function.o functioncodeparser.o functionparser.o functions.o groups.o httpsimpleparser.o lastcontainer.o log.o misc.o mount.o mountparser.o mounts.o notify.o plugin.o rebus.o request.o requestcontroller.o session.o sessioncontainer.o sessionmanager.o users.o
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include "functions.h"
|
||||
#include "lastcontainer.h"
|
||||
#include "mounts.h"
|
||||
|
||||
#include "rebus.h"
|
||||
|
||||
|
||||
class Data
|
||||
@@ -127,6 +127,8 @@ public:
|
||||
// mount points
|
||||
Mounts mounts;
|
||||
|
||||
// rebus (captcha)
|
||||
Rebus rebus;
|
||||
|
||||
|
||||
Data();
|
||||
|
||||
@@ -51,6 +51,8 @@ public:
|
||||
|
||||
no_thread,
|
||||
empty,
|
||||
rebus_bad_answer,
|
||||
|
||||
unknown = 1000
|
||||
|
||||
|
||||
|
||||
@@ -348,6 +348,15 @@ std::string::size_type i;
|
||||
}
|
||||
|
||||
|
||||
const char * SkipWhite(const char * s)
|
||||
{
|
||||
while( IsWhite(*s) )
|
||||
++s;
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
void ToSmall(std::string & s)
|
||||
{
|
||||
std::string::size_type i;
|
||||
|
||||
@@ -42,6 +42,7 @@ const char * IpToStr(unsigned int ip_);
|
||||
bool IsWhite(int s);
|
||||
void TrimWhite(std::string & s);
|
||||
void ToSmall(std::string & s);
|
||||
const char * SkipWhite(const char * s);
|
||||
|
||||
bool ValidateEmail(const std::string & email);
|
||||
|
||||
|
||||
131
core/rebus.cpp
Executable file
131
core/rebus.cpp
Executable file
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008-2009, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <cstdlib>
|
||||
#include <limits.h>
|
||||
#include "log.h"
|
||||
#include "rebus.h"
|
||||
#include "misc.h"
|
||||
|
||||
|
||||
|
||||
bool Rebus::InitPair(int a, int b, Item & item)
|
||||
{
|
||||
char buffer[100];
|
||||
bool add = false;
|
||||
|
||||
if( a+b <= 15 )
|
||||
{
|
||||
sprintf(buffer, "%d+%d", a, b);
|
||||
item.question = buffer;
|
||||
item.answer = a+b;
|
||||
add = true;
|
||||
}
|
||||
|
||||
if( a-b >= 0 )
|
||||
{
|
||||
sprintf(buffer, "%d-%d", a, b);
|
||||
item.question = buffer;
|
||||
item.answer = a-b;
|
||||
add = true;
|
||||
}
|
||||
|
||||
return add;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Rebus::Init()
|
||||
{
|
||||
int a, b;
|
||||
Item item;
|
||||
|
||||
item.key = 0;
|
||||
|
||||
for(a=1 ; a<10 ; ++a)
|
||||
{
|
||||
for(b=1 ; b<10 ; ++b)
|
||||
{
|
||||
if( InitPair(a, b, item) )
|
||||
{
|
||||
table.push_back(item);
|
||||
item.key += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Rebus::Item * Rebus::Rand()
|
||||
{
|
||||
size_t len = table.size();
|
||||
|
||||
if( len == 0 )
|
||||
// empty table, call Init() first
|
||||
return 0;
|
||||
|
||||
size_t i = size_t( ((double)rand()*(double)len) / (double(RAND_MAX)+1.0) );
|
||||
|
||||
if( i >= table.size() )
|
||||
{
|
||||
log << log1 << "Rebus: Rand() index too big" << logend;
|
||||
// oops, it should not be greater then table.size()
|
||||
return &table[0];
|
||||
}
|
||||
|
||||
return &table[0] + i;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Rebus::IsAnswerOk(Rebus::Item * item, const std::string & answer)
|
||||
{
|
||||
if( item == 0 )
|
||||
return false;
|
||||
|
||||
char * end;
|
||||
const char * a = answer.c_str();
|
||||
a = SkipWhite(a);
|
||||
|
||||
int value = (int)strtol(a, &end, 10);
|
||||
|
||||
if( a == end )
|
||||
// nothing has been read
|
||||
return false;
|
||||
|
||||
log << log2 << "Rebus: your answer is: " << value << logend;
|
||||
end = (char*)SkipWhite(end);
|
||||
|
||||
if( *end != 0 )
|
||||
{
|
||||
// something is at the end
|
||||
return false;
|
||||
}
|
||||
|
||||
bool result = (item->answer == value);
|
||||
|
||||
if( result )
|
||||
log << log3 << "Rebus: the answer is correct" << logend;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
43
core/rebus.h
Executable file
43
core/rebus.h
Executable file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008-2009, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfilecmslucorerebus
|
||||
#define headerfilecmslucorerebus
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
class Rebus
|
||||
{
|
||||
public:
|
||||
|
||||
struct Item
|
||||
{
|
||||
int key;
|
||||
std::string question;
|
||||
int answer;
|
||||
};
|
||||
|
||||
|
||||
void Init();
|
||||
Item * Rand();
|
||||
bool IsAnswerOk(Item * item, const std::string & answer);
|
||||
|
||||
private:
|
||||
|
||||
bool InitPair(int a, int b, Item & item);
|
||||
|
||||
std::vector<Item> table;
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -86,6 +86,10 @@ void Request::Clear()
|
||||
|
||||
browser_msie = false;
|
||||
|
||||
// should be always empty
|
||||
// this is only for safety
|
||||
//string_empty.clear();
|
||||
|
||||
plugin.Call(CMSLU_REQUEST_CLEAR);
|
||||
}
|
||||
|
||||
@@ -167,7 +171,10 @@ bool Request::PostVar(const char * var, std::string & result)
|
||||
p = post_table.find(var);
|
||||
|
||||
if( p == post_table.end() )
|
||||
{
|
||||
result.clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
result = p->second;
|
||||
|
||||
|
||||
@@ -187,6 +187,9 @@ private:
|
||||
// it contains '\0'
|
||||
const char char_empty;
|
||||
|
||||
// used when returning a reference to std::string (when the string doesn't exist)
|
||||
const std::string string_empty;
|
||||
|
||||
const char * SetEnvVar(const char * var);
|
||||
|
||||
void StandardLog();
|
||||
|
||||
@@ -107,6 +107,8 @@ bool RequestController::Init()
|
||||
data.groups.ReadGroups();
|
||||
data.functions.ReadFunctions();
|
||||
data.mounts.ReadMounts();
|
||||
|
||||
data.rebus.Init();
|
||||
//
|
||||
|
||||
|
||||
|
||||
@@ -32,7 +32,8 @@ void Session::Clear()
|
||||
done_status = Error::ok;
|
||||
item.Clear();
|
||||
done_timer = 0;
|
||||
|
||||
rebus_item = 0;
|
||||
|
||||
dir_old.clear();
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#include "item.h"
|
||||
#include "error.h"
|
||||
#include "user.h"
|
||||
|
||||
#include "rebus.h"
|
||||
|
||||
|
||||
struct Session
|
||||
@@ -48,6 +48,8 @@ struct Session
|
||||
Item item;
|
||||
|
||||
|
||||
Rebus::Item * rebus_item;
|
||||
|
||||
std::string dir_old;
|
||||
|
||||
// -------------------
|
||||
|
||||
Reference in New Issue
Block a user