added: notifications to users' emails
(core/notify.h core/notify.cpp) templatesnotify directory all notifications are managed by a second thread git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@512 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
parent
9902ce2b78
commit
85b678a8fb
5
Makefile
5
Makefile
|
@ -18,7 +18,8 @@ cmslu.a: FORCE
|
||||||
@cd content ; $(MAKE) -e
|
@cd content ; $(MAKE) -e
|
||||||
@cd confparser ; $(MAKE) -e
|
@cd confparser ; $(MAKE) -e
|
||||||
@cd templates ; $(MAKE) -e
|
@cd templates ; $(MAKE) -e
|
||||||
ar rcs cmslu.a core/*.o content/*.o templates/*.o confparser/*.o
|
@cd templatesnotify ; $(MAKE) -e
|
||||||
|
ar rcs cmslu.a core/*.o content/*.o templates/*.o templatesnotify/*.o confparser/*.o
|
||||||
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
@ -26,6 +27,7 @@ clean:
|
||||||
@cd content ; $(MAKE) -e clean
|
@cd content ; $(MAKE) -e clean
|
||||||
@cd confparser ; $(MAKE) -e clean
|
@cd confparser ; $(MAKE) -e clean
|
||||||
@cd templates ; $(MAKE) -e clean
|
@cd templates ; $(MAKE) -e clean
|
||||||
|
@cd templatesnotify ; $(MAKE) -e clean
|
||||||
rm -f cmslu.a
|
rm -f cmslu.a
|
||||||
|
|
||||||
|
|
||||||
|
@ -37,3 +39,4 @@ depend:
|
||||||
@cd content ; $(MAKE) -e depend
|
@cd content ; $(MAKE) -e depend
|
||||||
@cd confparser ; $(MAKE) -e depend
|
@cd confparser ; $(MAKE) -e depend
|
||||||
@cd templates ; $(MAKE) -e depend
|
@cd templates ; $(MAKE) -e depend
|
||||||
|
@cd templatesnotify ; $(MAKE) -e depend
|
||||||
|
|
|
@ -48,6 +48,8 @@ emacs.o: ../core/compress.h ../core/error.h ../core/db.h ../core/group.h
|
||||||
emacs.o: ../core/dircontainer.h ../core/ugcontainer.h ../core/data.h
|
emacs.o: ../core/dircontainer.h ../core/ugcontainer.h ../core/data.h
|
||||||
emacs.o: ../core/dirs.h ../core/users.h ../core/groups.h ../core/functions.h
|
emacs.o: ../core/dirs.h ../core/users.h ../core/groups.h ../core/functions.h
|
||||||
emacs.o: ../core/lastcontainer.h ../core/mounts.h ../core/mount.h
|
emacs.o: ../core/lastcontainer.h ../core/mounts.h ../core/mount.h
|
||||||
|
emacs.o: ../core/notify.h ../templatesnotify/templatesnotify.h
|
||||||
|
emacs.o: ../core/mount.h
|
||||||
last.o: content.h ../core/item.h ../templates/templates.h ../../ezc/src/ezc.h
|
last.o: content.h ../core/item.h ../templates/templates.h ../../ezc/src/ezc.h
|
||||||
last.o: ../templates/patterncacher.h ../app/templates.h ../core/thread.h
|
last.o: ../templates/patterncacher.h ../app/templates.h ../core/thread.h
|
||||||
login.o: content.h ../core/item.h ../templates/templates.h
|
login.o: content.h ../core/item.h ../templates/templates.h
|
||||||
|
@ -84,6 +86,8 @@ mkdir.o: ../core/compress.h ../core/error.h ../core/db.h ../core/group.h
|
||||||
mkdir.o: ../core/dircontainer.h ../core/ugcontainer.h ../core/data.h
|
mkdir.o: ../core/dircontainer.h ../core/ugcontainer.h ../core/data.h
|
||||||
mkdir.o: ../core/dirs.h ../core/users.h ../core/groups.h ../core/functions.h
|
mkdir.o: ../core/dirs.h ../core/users.h ../core/groups.h ../core/functions.h
|
||||||
mkdir.o: ../core/lastcontainer.h ../core/mounts.h ../core/mount.h
|
mkdir.o: ../core/lastcontainer.h ../core/mounts.h ../core/mount.h
|
||||||
|
mkdir.o: ../core/notify.h ../templatesnotify/templatesnotify.h
|
||||||
|
mkdir.o: ../core/mount.h
|
||||||
node.o: content.h ../core/item.h ../templates/templates.h ../../ezc/src/ezc.h
|
node.o: content.h ../core/item.h ../templates/templates.h ../../ezc/src/ezc.h
|
||||||
node.o: ../templates/patterncacher.h ../app/templates.h ../core/thread.h
|
node.o: ../templates/patterncacher.h ../app/templates.h ../core/thread.h
|
||||||
node.o: ../core/request.h ../core/requesttypes.h ../core/session.h
|
node.o: ../core/request.h ../core/requesttypes.h ../core/session.h
|
||||||
|
|
|
@ -18,12 +18,13 @@
|
||||||
#include "../templates/templates.h"
|
#include "../templates/templates.h"
|
||||||
#include "../core/thread.h"
|
#include "../core/thread.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Content
|
class Content
|
||||||
{
|
{
|
||||||
Templates templates;
|
Templates templates;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void PrepareUrl(Item & item);
|
void PrepareUrl(Item & item);
|
||||||
|
|
||||||
|
@ -76,12 +77,14 @@ class Content
|
||||||
void RedirectTo(const Item & item);
|
void RedirectTo(const Item & item);
|
||||||
void RedirectTo(long item_id);
|
void RedirectTo(long item_id);
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
bool Init();
|
bool Init();
|
||||||
|
|
||||||
void ReadAdditionalInfo();
|
void ReadAdditionalInfo();
|
||||||
void Make();
|
void Make();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
#include "../core/error.h"
|
#include "../core/error.h"
|
||||||
#include "../core/db.h"
|
#include "../core/db.h"
|
||||||
#include "../core/data.h"
|
#include "../core/data.h"
|
||||||
|
#include "../core/notify.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -47,6 +47,11 @@ void Content::PostFunEmacsAdd()
|
||||||
throw Error(Error::permision_denied);
|
throw Error(Error::permision_denied);
|
||||||
|
|
||||||
request.session->done_status = db.AddItem(request.item);
|
request.session->done_status = db.AddItem(request.item);
|
||||||
|
|
||||||
|
if( request.session->done_status == Error::ok )
|
||||||
|
{
|
||||||
|
request.notify_code |= CMSLU_NOTIFY_ITEM_ADD;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -64,7 +69,11 @@ void Content::PostFunEmacsEdit(bool with_url)
|
||||||
request.session->done_status = db.EditItemById(request.item, with_url);
|
request.session->done_status = db.EditItemById(request.item, with_url);
|
||||||
|
|
||||||
if( request.session->done_status == Error::ok )
|
if( request.session->done_status == Error::ok )
|
||||||
|
{
|
||||||
TemplatesFunctions::pattern_cacher.UpdatePattern(request.item);
|
TemplatesFunctions::pattern_cacher.UpdatePattern(request.item);
|
||||||
|
|
||||||
|
request.notify_code |= CMSLU_NOTIFY_ITEM_EDIT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -119,6 +128,8 @@ bool adding = true;
|
||||||
|
|
||||||
if( request.session->done_status == Error::ok )
|
if( request.session->done_status == Error::ok )
|
||||||
{
|
{
|
||||||
|
request.session->item = request.item;
|
||||||
|
|
||||||
if( data.mounts.CurrentMountType() == Mount::thread )
|
if( data.mounts.CurrentMountType() == Mount::thread )
|
||||||
{
|
{
|
||||||
if( adding )
|
if( adding )
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include "../core/error.h"
|
#include "../core/error.h"
|
||||||
#include "../core/db.h"
|
#include "../core/db.h"
|
||||||
#include "../core/data.h"
|
#include "../core/data.h"
|
||||||
|
#include "../core/notify.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -70,6 +71,8 @@ void Content::PostFunMkdir(bool add_to_dir_table, int mask)
|
||||||
|
|
||||||
request.session->item = item;
|
request.session->item = item;
|
||||||
request.session->done_timer = 2;
|
request.session->done_timer = 2;
|
||||||
|
request.notify_code |= CMSLU_NOTIFY_DIR_ADD;
|
||||||
|
|
||||||
RedirectTo(item);
|
RedirectTo(item);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -37,7 +37,8 @@ main.o: sessionmanager.h sessioncontainer.h session.h done.h item.h error.h
|
||||||
main.o: log.h user.h functionparser.h requesttypes.h ../app/content.h data.h
|
main.o: log.h user.h functionparser.h requesttypes.h ../app/content.h data.h
|
||||||
main.o: dirs.h dircontainer.h users.h ugcontainer.h groups.h group.h
|
main.o: dirs.h dircontainer.h users.h ugcontainer.h groups.h group.h
|
||||||
main.o: functions.h function.h lastcontainer.h mounts.h mount.h request.h
|
main.o: functions.h function.h lastcontainer.h mounts.h mount.h request.h
|
||||||
main.o: thread.h compress.h db.h config.h ../confparser/confparser.h
|
main.o: thread.h compress.h db.h config.h ../confparser/confparser.h notify.h
|
||||||
|
main.o: ../templatesnotify/templatesnotify.h ../core/mount.h
|
||||||
misc.o: misc.h item.h log.h
|
misc.o: misc.h item.h log.h
|
||||||
mount.o: mount.h
|
mount.o: mount.h
|
||||||
mountparser.o: mountparser.h mount.h item.h error.h log.h data.h dirs.h
|
mountparser.o: mountparser.h mount.h item.h error.h log.h data.h dirs.h
|
||||||
|
@ -47,6 +48,11 @@ 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: 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: lastcontainer.h request.h requesttypes.h session.h done.h error.h
|
||||||
mounts.o: thread.h compress.h mountparser.h
|
mounts.o: thread.h compress.h mountparser.h
|
||||||
|
notify.o: log.h notify.h ../templatesnotify/templatesnotify.h ../core/mount.h
|
||||||
|
notify.o: ../../ezc/src/ezc.h data.h dirs.h item.h dircontainer.h users.h
|
||||||
|
notify.o: user.h ugcontainer.h groups.h group.h functions.h function.h
|
||||||
|
notify.o: lastcontainer.h mounts.h mount.h misc.h request.h requesttypes.h
|
||||||
|
notify.o: session.h done.h error.h thread.h compress.h
|
||||||
request.o: request.h requesttypes.h session.h done.h item.h error.h log.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 getparser.h
|
request.o: user.h function.h thread.h compress.h getparser.h
|
||||||
request.o: httpsimpleparser.h postparser.h cookieparser.h data.h dirs.h
|
request.o: httpsimpleparser.h postparser.h cookieparser.h data.h dirs.h
|
||||||
|
@ -61,7 +67,8 @@ requestcontroller.o: functionparser.h requesttypes.h ../app/content.h data.h
|
||||||
requestcontroller.o: dirs.h dircontainer.h users.h ugcontainer.h groups.h
|
requestcontroller.o: dirs.h dircontainer.h users.h ugcontainer.h groups.h
|
||||||
requestcontroller.o: group.h functions.h function.h lastcontainer.h mounts.h
|
requestcontroller.o: group.h functions.h function.h lastcontainer.h mounts.h
|
||||||
requestcontroller.o: mount.h request.h thread.h compress.h postparser.h
|
requestcontroller.o: mount.h request.h thread.h compress.h postparser.h
|
||||||
requestcontroller.o: httpsimpleparser.h cookieparser.h
|
requestcontroller.o: httpsimpleparser.h 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
|
||||||
sessioncontainer.o: sessioncontainer.h session.h done.h item.h error.h log.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: user.h data.h dirs.h dircontainer.h users.h ugcontainer.h
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
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 main.o misc.o mount.o mountparser.o mounts.o request.o requestcontroller.o session.o sessioncontainer.o sessionmanager.o users.o
|
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 main.o misc.o mount.o mountparser.o mounts.o notify.o request.o requestcontroller.o session.o sessioncontainer.o sessionmanager.o users.o
|
||||||
|
|
|
@ -90,6 +90,7 @@ bool Config::ReadConfig(bool errors_to_stdout_)
|
||||||
void Config::AssignValues()
|
void Config::AssignValues()
|
||||||
{
|
{
|
||||||
data.log_file = Text("log_file");
|
data.log_file = Text("log_file");
|
||||||
|
data.log_notify_file = Text("log_notify_file");
|
||||||
data.fcgi_socket = Text("fcgi_socket");
|
data.fcgi_socket = Text("fcgi_socket");
|
||||||
data.fcgi_socket_chmod = Int("fcgi_socket_chmod");
|
data.fcgi_socket_chmod = Int("fcgi_socket_chmod");
|
||||||
data.fcgi_socket_user = Text("fcgi_socket_user");
|
data.fcgi_socket_user = Text("fcgi_socket_user");
|
||||||
|
|
|
@ -34,8 +34,8 @@ public:
|
||||||
// name of the config file (full path can be)
|
// name of the config file (full path can be)
|
||||||
std::string config_file;
|
std::string config_file;
|
||||||
|
|
||||||
// log file name
|
// log file name, log file name for notifications (sending emails, etc)
|
||||||
std::string log_file;
|
std::string log_file, log_notify_file;
|
||||||
|
|
||||||
// 1 - minimum
|
// 1 - minimum
|
||||||
// 2 - (default)
|
// 2 - (default)
|
||||||
|
|
|
@ -1227,7 +1227,7 @@ void Db::GetUsers(UGContainer<User> & user_table)
|
||||||
AssertConnection();
|
AssertConnection();
|
||||||
|
|
||||||
std::ostringstream query;
|
std::ostringstream query;
|
||||||
query << "select id, login, super_user, group_id from core.user left outer join core.group_mem on core.user.id = core.group_mem.user_id order by id asc;";
|
query << "select id, login, super_user, group_id, email, cms_notify, thread_notify from core.user left outer join core.group_mem on core.user.id = core.group_mem.user_id order by id asc;";
|
||||||
|
|
||||||
r = AssertQuery( query.str() );
|
r = AssertQuery( query.str() );
|
||||||
AssertResultStatus(r, PGRES_TUPLES_OK);
|
AssertResultStatus(r, PGRES_TUPLES_OK);
|
||||||
|
@ -1238,6 +1238,9 @@ void Db::GetUsers(UGContainer<User> & user_table)
|
||||||
int cname = AssertColumn(r, "login");
|
int cname = AssertColumn(r, "login");
|
||||||
int csuper_user = AssertColumn(r, "super_user");
|
int csuper_user = AssertColumn(r, "super_user");
|
||||||
int cgroup_id = AssertColumn(r, "group_id");
|
int cgroup_id = AssertColumn(r, "group_id");
|
||||||
|
int cemail = AssertColumn(r, "email");
|
||||||
|
int ccms_notify = AssertColumn(r, "cms_notify");
|
||||||
|
int cthread_notify = AssertColumn(r, "thread_notify");
|
||||||
|
|
||||||
User u;
|
User u;
|
||||||
long last_id = -1;
|
long last_id = -1;
|
||||||
|
@ -1251,6 +1254,10 @@ void Db::GetUsers(UGContainer<User> & user_table)
|
||||||
{
|
{
|
||||||
u.name = AssertValue(r, i, cname);
|
u.name = AssertValue(r, i, cname);
|
||||||
u.super_user = static_cast<bool>( atoi( AssertValue(r, i, csuper_user) ) );
|
u.super_user = static_cast<bool>( atoi( AssertValue(r, i, csuper_user) ) );
|
||||||
|
u.email = AssertValue(r, i, cemail);
|
||||||
|
u.cms_notify = atoi( AssertValue(r, i, ccms_notify) );
|
||||||
|
u.thread_notify = atoi( AssertValue(r, i, cthread_notify) );
|
||||||
|
|
||||||
log << log1 << "Db: get user: id:" << u.id << ", name:" << u.name << ", super_user:" << u.super_user << logend;
|
log << log1 << "Db: get user: id:" << u.id << ", name:" << u.name << ", super_user:" << u.super_user << logend;
|
||||||
|
|
||||||
iter = user_table.PushBack( u );
|
iter = user_table.PushBack( u );
|
||||||
|
|
18
core/log.cpp
18
core/log.cpp
|
@ -8,7 +8,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
#include <ctime>
|
||||||
|
|
||||||
|
|
||||||
Log::Log()
|
Log::Log()
|
||||||
|
@ -27,6 +27,22 @@ void Log::Init(int log_l, const std::string & log_f, bool log_std)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Log::PutDate(Manipulators m)
|
||||||
|
{
|
||||||
|
time_t t = std::time(0);
|
||||||
|
std::tm * loct = std::localtime(&t);
|
||||||
|
|
||||||
|
char buffer[70];
|
||||||
|
sprintf(buffer, "%d.%02d.%02d %02d:%02d:%02d ", int(loct->tm_year + 1900),
|
||||||
|
int(loct->tm_mon + 1),
|
||||||
|
int(loct->tm_mday),
|
||||||
|
int(loct->tm_hour),
|
||||||
|
int(loct->tm_min),
|
||||||
|
int(loct->tm_sec));
|
||||||
|
|
||||||
|
(*this) << m << buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Log & Log::operator<<(const char * s)
|
Log & Log::operator<<(const char * s)
|
||||||
|
|
|
@ -36,6 +36,7 @@ public:
|
||||||
|
|
||||||
void Init(int log_l, const std::string & log_f, bool log_std);
|
void Init(int log_l, const std::string & log_f, bool log_std);
|
||||||
|
|
||||||
|
void PutDate(Manipulators m);
|
||||||
Log & operator<<(const char * s);
|
Log & operator<<(const char * s);
|
||||||
Log & operator<<(const std::string & s);
|
Log & operator<<(const std::string & s);
|
||||||
Log & operator<<(int s);
|
Log & operator<<(int s);
|
||||||
|
@ -51,6 +52,7 @@ public:
|
||||||
|
|
||||||
|
|
||||||
extern Log log;
|
extern Log log;
|
||||||
|
extern Log nlog;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,16 +18,19 @@
|
||||||
#include "request.h"
|
#include "request.h"
|
||||||
#include "db.h"
|
#include "db.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "notify.h"
|
||||||
|
|
||||||
|
|
||||||
// singletons
|
// singletons
|
||||||
// first 'data' then 'log' then 'request'
|
// first 'data' then 'log' then 'request'
|
||||||
Data data;
|
Data data;
|
||||||
Log log;
|
Log log;
|
||||||
|
Log nlog; // notify log (used by another thread)
|
||||||
Request request;
|
Request request;
|
||||||
Db db;
|
Db db;
|
||||||
Config config;
|
Config config;
|
||||||
RequestController req_controller;
|
RequestController req_controller;
|
||||||
|
Notify notify;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -87,6 +90,16 @@ int main(int argv, char ** argc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
log.Init(data.log_level, data.log_file, data.log_stdout);
|
||||||
|
nlog.Init(data.log_level, data.log_notify_file, false);
|
||||||
|
db.Init(data.db_database, data.db_user, data.db_pass);
|
||||||
|
request.Init();
|
||||||
|
|
||||||
|
if( !req_controller.Init() )
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if( !notify.Init(data.templates) )
|
||||||
|
return 2;
|
||||||
|
|
||||||
signal(SIGTERM, signal_term);
|
signal(SIGTERM, signal_term);
|
||||||
signal(SIGINT, signal_term);
|
signal(SIGINT, signal_term);
|
||||||
|
@ -95,13 +108,6 @@ int main(int argv, char ** argc)
|
||||||
|
|
||||||
while( true )
|
while( true )
|
||||||
{
|
{
|
||||||
log.Init(data.log_level, data.log_file, data.log_stdout);
|
|
||||||
db.Init(data.db_database, data.db_user, data.db_pass);
|
|
||||||
request.Init();
|
|
||||||
|
|
||||||
if( !req_controller.Init() )
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
//log << log2 << "checking for table consistency:" << logend;
|
//log << log2 << "checking for table consistency:" << logend;
|
||||||
// !! zrobic wyjatek dla root
|
// !! zrobic wyjatek dla root
|
||||||
//db.CheckAllUrlSubject();
|
//db.CheckAllUrlSubject();
|
||||||
|
|
|
@ -358,3 +358,47 @@ std::string::size_type i;
|
||||||
s[i] = s[i] - 'A' + 'a';
|
s[i] = s[i] - 'A' + 'a';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool ValidateEmail(const std::string & email)
|
||||||
|
{
|
||||||
|
if( email.empty() )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
bool correct = true;
|
||||||
|
size_t i;
|
||||||
|
char allowed_chars[] = "!#$%&'*+-/=?^_`{|}~.@";
|
||||||
|
int at = 0;
|
||||||
|
|
||||||
|
for(i=0 ; i<email.length() && correct ; ++i)
|
||||||
|
{
|
||||||
|
correct = false;
|
||||||
|
|
||||||
|
if( (email[i] >= 'A' && email[i]<='Z') ||
|
||||||
|
(email[i] >= 'a' && email[i]<='z') ||
|
||||||
|
(email[i] >= '0' && email[i]<='9') )
|
||||||
|
{
|
||||||
|
correct = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for(size_t a=0 ; a < sizeof(allowed_chars)-1 ; ++a)
|
||||||
|
{
|
||||||
|
if( email[i] == allowed_chars[a] )
|
||||||
|
{
|
||||||
|
correct = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if( email[i] == '@' )
|
||||||
|
++at;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( at != 1 )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return correct;
|
||||||
|
}
|
||||||
|
|
|
@ -43,4 +43,6 @@ bool IsWhite(int s);
|
||||||
void TrimWhite(std::string & s);
|
void TrimWhite(std::string & s);
|
||||||
void ToSmall(std::string & s);
|
void ToSmall(std::string & s);
|
||||||
|
|
||||||
|
bool ValidateEmail(const std::string & email);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -0,0 +1,245 @@
|
||||||
|
/*
|
||||||
|
* 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 <pthread.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "log.h"
|
||||||
|
#include "notify.h"
|
||||||
|
#include "data.h"
|
||||||
|
#include "misc.h"
|
||||||
|
#include "request.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// the second thread uses this pointer to reference to 'this'
|
||||||
|
// (methods for the thread should be static)
|
||||||
|
Notify * Notify::obj;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
methods for second thread
|
||||||
|
|
||||||
|
second thread can reference to 'this' by using 'obj' pointer
|
||||||
|
*/
|
||||||
|
|
||||||
|
void * Notify::ThreadRoutine(void * arg)
|
||||||
|
{
|
||||||
|
obj = (Notify*)arg;
|
||||||
|
obj->templates_notify.Read(obj->templates_dir);
|
||||||
|
|
||||||
|
|
||||||
|
while( true )
|
||||||
|
{
|
||||||
|
CheckQueue();
|
||||||
|
sleep(30);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Notify::CheckQueue()
|
||||||
|
{
|
||||||
|
std::list<NotifyMsg>::iterator i = obj->notify_pool.begin();
|
||||||
|
|
||||||
|
|
||||||
|
while( i != obj->notify_pool.end() )
|
||||||
|
{
|
||||||
|
SendEmail(*i);
|
||||||
|
|
||||||
|
obj->Lock();
|
||||||
|
i = obj->notify_pool.erase(i);
|
||||||
|
obj->Unlock();
|
||||||
|
|
||||||
|
sleep(3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Notify::SendEmail(NotifyMsg & n)
|
||||||
|
{
|
||||||
|
TemplatesNotifyFunctions::notify_msg = &n;
|
||||||
|
|
||||||
|
obj->templates_notify.Generate();
|
||||||
|
SendEmail(n.email, obj->templates_notify.notify_str.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Notify::SendEmail(const std::string & email, const std::string & message)
|
||||||
|
{
|
||||||
|
nlog.PutDate(log1);
|
||||||
|
|
||||||
|
if( !ValidateEmail(email) )
|
||||||
|
{
|
||||||
|
nlog << "Notify: email: " << email << " is not correct" << logend;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
obj->command = "sendmail " + email;
|
||||||
|
FILE * sendmail = popen(obj->command.c_str(), "w");
|
||||||
|
|
||||||
|
if( !sendmail )
|
||||||
|
{
|
||||||
|
|
||||||
|
nlog << "Notify: can't run sendmail" << logend;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SendMessage(sendmail, message);
|
||||||
|
pclose(sendmail);
|
||||||
|
|
||||||
|
nlog << "Notify: email to: " << email << " has been sent" << logend;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Notify::SendMessage(FILE * sendmail, const std::string & message)
|
||||||
|
{
|
||||||
|
for(size_t i=0 ; i<message.length() ; ++i)
|
||||||
|
{
|
||||||
|
if( message[i] == '\n' )
|
||||||
|
fprintf(sendmail, "\r\n");
|
||||||
|
else
|
||||||
|
fputc(message[i], sendmail);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
methods for main thread
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Notify::Notify() : mutex(PTHREAD_MUTEX_INITIALIZER)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Notify::~Notify()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool Notify::Init(const std::string & tdir)
|
||||||
|
{
|
||||||
|
templates_dir = tdir;
|
||||||
|
|
||||||
|
int t = pthread_create(&thread, 0, ThreadRoutine, (void*)this);
|
||||||
|
|
||||||
|
if( t != 0 )
|
||||||
|
{
|
||||||
|
// log (not nlog) here
|
||||||
|
log << log1 << "Notify: can't create a thread" << logend;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool Notify::Lock()
|
||||||
|
{
|
||||||
|
if( pthread_mutex_lock(&mutex) != 0 )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Notify::Unlock()
|
||||||
|
{
|
||||||
|
pthread_mutex_unlock(&mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Notify::CreateItemDir(std::string & dir, bool clear)
|
||||||
|
{
|
||||||
|
if( clear )
|
||||||
|
dir.clear();
|
||||||
|
|
||||||
|
for(size_t a=0 ; a<request.dir_table.size() ; ++a)
|
||||||
|
{
|
||||||
|
dir += request.dir_table[a]->url;
|
||||||
|
dir += '/';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Notify::CreateItemLink(std::string & link)
|
||||||
|
{
|
||||||
|
link = data.base_url;
|
||||||
|
CreateItemDir(link, false);
|
||||||
|
link += request.item.url;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Notify::ItemChanged(int notify_code)
|
||||||
|
{
|
||||||
|
bool sending;
|
||||||
|
Users::Iterator i;
|
||||||
|
|
||||||
|
if( notify_code == 0 )
|
||||||
|
return;
|
||||||
|
|
||||||
|
n.notify_code = notify_code;
|
||||||
|
n.current_mount_type = data.mounts.CurrentMountType();
|
||||||
|
n.doc_base_url = data.base_url;
|
||||||
|
CreateItemDir(n.item_dir);
|
||||||
|
CreateItemLink(n.item_link);
|
||||||
|
|
||||||
|
|
||||||
|
Lock();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// don't clear notify_pool here -- it is used (and will be cleared) by the second thread
|
||||||
|
|
||||||
|
for(i=data.users.Begin() ; i != data.users.End() ; ++i)
|
||||||
|
{
|
||||||
|
sending = false;
|
||||||
|
|
||||||
|
if( data.mounts.CurrentMountType() == Mount::thread )
|
||||||
|
{
|
||||||
|
if( (i->thread_notify & notify_code) != 0 )
|
||||||
|
sending = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if( data.mounts.CurrentMountType() == Mount::cms )
|
||||||
|
{
|
||||||
|
if( (i->cms_notify & notify_code) != 0 )
|
||||||
|
sending = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( sending )
|
||||||
|
{
|
||||||
|
n.email = i->email;
|
||||||
|
notify_pool.insert(notify_pool.end(), n);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(...)
|
||||||
|
{
|
||||||
|
Unlock();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
|
Unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,76 @@
|
||||||
|
/*
|
||||||
|
* 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 headerfilecmslunotify
|
||||||
|
#define headerfilecmslunotify
|
||||||
|
|
||||||
|
#include <list>
|
||||||
|
#include <string>
|
||||||
|
#include <cstdio>
|
||||||
|
#include "../templatesnotify/templatesnotify.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define CMSLU_NOTIFY_ITEM_ADD 1
|
||||||
|
#define CMSLU_NOTIFY_ITEM_EDIT 2
|
||||||
|
#define CMSLU_NOTIFY_ITEM_DELETE 4
|
||||||
|
#define CMSLU_NOTIFY_DIR_ADD 8
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Notify
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
Notify();
|
||||||
|
~Notify();
|
||||||
|
|
||||||
|
bool Init(const std::string & tdir);
|
||||||
|
|
||||||
|
/*
|
||||||
|
this method added an item to our special pool
|
||||||
|
the pool is used by a second thread
|
||||||
|
*/
|
||||||
|
void ItemChanged(int notify_code);
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
|
||||||
|
static void * ThreadRoutine(void * arg);
|
||||||
|
bool Lock();
|
||||||
|
void Unlock();
|
||||||
|
static void CheckQueue();
|
||||||
|
static void SendEmail(NotifyMsg & n);
|
||||||
|
static void SendEmail(const std::string & email);
|
||||||
|
static void SendEmail(const std::string & email, const std::string & message);
|
||||||
|
static void SendMessage(FILE * sendmail, const std::string & message);
|
||||||
|
void CreateItemDir(std::string & dir, bool clear = true);
|
||||||
|
void CreateItemLink(std::string & link);
|
||||||
|
|
||||||
|
pthread_t thread;
|
||||||
|
pthread_mutex_t mutex;
|
||||||
|
NotifyMsg n;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
objects accessed by the second thread
|
||||||
|
*/
|
||||||
|
std::list<NotifyMsg> notify_pool;
|
||||||
|
static Notify * obj;
|
||||||
|
std::string command;
|
||||||
|
std::string templates_dir;
|
||||||
|
TemplatesNotify templates_notify;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
extern Notify notify;
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
|
@ -44,6 +44,7 @@ void Request::Clear()
|
||||||
headers.str("");
|
headers.str("");
|
||||||
page.str("");
|
page.str("");
|
||||||
debug.str("");
|
debug.str("");
|
||||||
|
notify.str("");
|
||||||
|
|
||||||
env_request_method = &char_empty;
|
env_request_method = &char_empty;
|
||||||
env_request_uri = &char_empty;
|
env_request_uri = &char_empty;
|
||||||
|
@ -75,6 +76,9 @@ void Request::Clear()
|
||||||
thread.Clear();
|
thread.Clear();
|
||||||
|
|
||||||
thread_tab.clear();
|
thread_tab.clear();
|
||||||
|
|
||||||
|
notify_code = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -283,18 +287,8 @@ void Request::ReadParameters()
|
||||||
|
|
||||||
void Request::StandardLog()
|
void Request::StandardLog()
|
||||||
{
|
{
|
||||||
time_t t = std::time(0);
|
log.PutDate(log1);
|
||||||
std::tm * loct = std::localtime(&t);
|
log << env_remote_addr << ' ' << env_request_method << ' ' << env_request_uri << ' ' << env_http_user_agent << logend;
|
||||||
|
|
||||||
char buffer[70];
|
|
||||||
sprintf(buffer, "%d.%02d.%02d %02d:%02d:%02d ", int(loct->tm_year + 1900),
|
|
||||||
int(loct->tm_mon + 1),
|
|
||||||
int(loct->tm_mday),
|
|
||||||
int(loct->tm_hour),
|
|
||||||
int(loct->tm_min),
|
|
||||||
int(loct->tm_sec));
|
|
||||||
|
|
||||||
log << log1 << buffer << env_remote_addr << ' ' << env_request_method << ' ' << env_request_uri << ' ' << env_http_user_agent << logend;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -357,6 +351,9 @@ void Request::SendAll()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool Request::IsParam(const char * s)
|
bool Request::IsParam(const char * s)
|
||||||
{
|
{
|
||||||
std::vector<std::string*>::iterator i;
|
std::vector<std::string*>::iterator i;
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
#include <fcgiapp.h>
|
#include <fcgiapp.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <ctime>
|
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
|
||||||
#include "requesttypes.h"
|
#include "requesttypes.h"
|
||||||
|
@ -43,7 +42,8 @@ struct Request
|
||||||
|
|
||||||
|
|
||||||
// headers, page and debug
|
// headers, page and debug
|
||||||
std::ostringstream headers, page, debug;
|
// notify (for mailing)
|
||||||
|
std::ostringstream headers, page, debug, notify;
|
||||||
|
|
||||||
|
|
||||||
GetTable get_table;
|
GetTable get_table;
|
||||||
|
@ -94,6 +94,10 @@ struct Request
|
||||||
|
|
||||||
Error status;
|
Error status;
|
||||||
|
|
||||||
|
// last notify
|
||||||
|
int notify_code;
|
||||||
|
|
||||||
|
|
||||||
// ------------------
|
// ------------------
|
||||||
|
|
||||||
// !! stare skladowe
|
// !! stare skladowe
|
||||||
|
@ -150,7 +154,7 @@ struct Request
|
||||||
void ReadParameters();
|
void ReadParameters();
|
||||||
void Read();
|
void Read();
|
||||||
void SendAll();
|
void SendAll();
|
||||||
|
void SendNotify();
|
||||||
|
|
||||||
bool CanChangeUser(const Item & item, long new_user_id);
|
bool CanChangeUser(const Item & item, long new_user_id);
|
||||||
bool CanChangeGroup(const Item & item, long new_group_id);
|
bool CanChangeGroup(const Item & item, long new_group_id);
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include "request.h"
|
#include "request.h"
|
||||||
#include "postparser.h"
|
#include "postparser.h"
|
||||||
#include "cookieparser.h"
|
#include "cookieparser.h"
|
||||||
|
#include "notify.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -165,6 +166,7 @@ void RequestController::Loop()
|
||||||
}
|
}
|
||||||
|
|
||||||
request.SendAll();
|
request.SendAll();
|
||||||
|
notify.ItemChanged(request.notify_code);
|
||||||
}
|
}
|
||||||
catch(const std::exception & e)
|
catch(const std::exception & e)
|
||||||
{
|
{
|
||||||
|
|
11
core/user.h
11
core/user.h
|
@ -14,13 +14,18 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct User
|
struct User
|
||||||
{
|
{
|
||||||
long id;
|
long id;
|
||||||
std::string name;
|
std::string name;
|
||||||
bool super_user;
|
bool super_user;
|
||||||
std::vector<long> groups;
|
std::vector<long> groups;
|
||||||
|
std::string email;
|
||||||
|
|
||||||
|
int cms_notify;
|
||||||
|
int thread_notify;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
User()
|
User()
|
||||||
{
|
{
|
||||||
|
@ -34,6 +39,9 @@ struct User
|
||||||
name.clear();
|
name.clear();
|
||||||
super_user = false;
|
super_user = false;
|
||||||
groups.clear();
|
groups.clear();
|
||||||
|
email.clear();
|
||||||
|
cms_notify = 0;
|
||||||
|
thread_notify = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,7 +56,6 @@ struct User
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,16 @@ void mount_param_thread_with_info(Info & i)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void mount_is_thread(Info & i)
|
||||||
|
{
|
||||||
|
i.result = data.mounts.CurrentMountType() == Mount::thread;
|
||||||
|
}
|
||||||
|
|
||||||
|
void mount_is_cms(Info & i)
|
||||||
|
{
|
||||||
|
i.result = data.mounts.CurrentMountType() == Mount::cms;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace TemplatesFunctions
|
} // namespace TemplatesFunctions
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,7 @@ Ezc::Pattern pat_item_info;
|
||||||
Ezc::Pattern pat_item_tab_info;
|
Ezc::Pattern pat_item_tab_info;
|
||||||
Ezc::Pattern pat_dir_last_info;
|
Ezc::Pattern pat_dir_last_info;
|
||||||
|
|
||||||
|
|
||||||
Ezc::Functions functions;
|
Ezc::Functions functions;
|
||||||
|
|
||||||
|
|
||||||
|
@ -379,7 +380,8 @@ void Templates::CreateFunctions()
|
||||||
functions.Insert("mount_param_withinfo", mount_param_withinfo);
|
functions.Insert("mount_param_withinfo", mount_param_withinfo);
|
||||||
functions.Insert("mount_param_thread_with_header", mount_param_thread_with_header);
|
functions.Insert("mount_param_thread_with_header", mount_param_thread_with_header);
|
||||||
functions.Insert("mount_param_thread_with_info", mount_param_thread_with_info);
|
functions.Insert("mount_param_thread_with_info", mount_param_thread_with_info);
|
||||||
|
functions.Insert("mount_is_thread", mount_is_thread);
|
||||||
|
functions.Insert("mount_is_cms", mount_is_cms);
|
||||||
|
|
||||||
|
|
||||||
// !! tymczasowa
|
// !! tymczasowa
|
||||||
|
@ -459,6 +461,7 @@ void Templates::Read()
|
||||||
pat_dir_last_info.Directory(data.templates);
|
pat_dir_last_info.Directory(data.templates);
|
||||||
pat_dir_last_info.ParseFile("dir_last_info.html");
|
pat_dir_last_info.ParseFile("dir_last_info.html");
|
||||||
|
|
||||||
|
|
||||||
CreateFunctions();
|
CreateFunctions();
|
||||||
|
|
||||||
#ifdef APPTEMPLATES
|
#ifdef APPTEMPLATES
|
||||||
|
@ -478,3 +481,5 @@ void Templates::Generate()
|
||||||
generator.Generate();
|
generator.Generate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ namespace TemplatesFunctions
|
||||||
extern Ezc::Pattern pat_item_info;
|
extern Ezc::Pattern pat_item_info;
|
||||||
extern Ezc::Pattern pat_item_tab_info;
|
extern Ezc::Pattern pat_item_tab_info;
|
||||||
extern Ezc::Pattern pat_dir_last_info;
|
extern Ezc::Pattern pat_dir_last_info;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -66,7 +67,7 @@ namespace TemplatesFunctions
|
||||||
void item_content_noescape(Info & i);
|
void item_content_noescape(Info & i);
|
||||||
void item_print_content(Info & i);
|
void item_print_content(Info & i);
|
||||||
void item_privileges(Info & i);
|
void item_privileges(Info & i);
|
||||||
void item_dir(Info & i); // the same as full_dir()
|
void item_dir(Info & i);
|
||||||
void item_url(Info & i);
|
void item_url(Info & i);
|
||||||
void item_link(Info & i);
|
void item_link(Info & i);
|
||||||
void item_can_read(Info & i);
|
void item_can_read(Info & i);
|
||||||
|
@ -213,6 +214,7 @@ namespace TemplatesFunctions
|
||||||
void thread_tab_last_item_user(Info & i);
|
void thread_tab_last_item_user(Info & i);
|
||||||
void thread_can_create(Info & i);
|
void thread_can_create(Info & i);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
mount
|
mount
|
||||||
*/
|
*/
|
||||||
|
@ -220,6 +222,9 @@ namespace TemplatesFunctions
|
||||||
void mount_param_withinfo(Info & i);
|
void mount_param_withinfo(Info & i);
|
||||||
void mount_param_thread_with_header(Info & i);
|
void mount_param_thread_with_header(Info & i);
|
||||||
void mount_param_thread_with_info(Info & i);
|
void mount_param_thread_with_info(Info & i);
|
||||||
|
void mount_is_thread(Info & i);
|
||||||
|
void mount_is_cms(Info & i);
|
||||||
|
|
||||||
|
|
||||||
} // namespace TemplatesFunctions
|
} // namespace TemplatesFunctions
|
||||||
|
|
||||||
|
@ -236,8 +241,10 @@ public:
|
||||||
void Read();
|
void Read();
|
||||||
void Generate();
|
void Generate();
|
||||||
|
|
||||||
void CreateFunctions();
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
void CreateFunctions();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
include Makefile.o.dep
|
||||||
|
|
||||||
|
|
||||||
|
all: $(o)
|
||||||
|
|
||||||
|
|
||||||
|
.SUFFIXES: .cpp .o
|
||||||
|
|
||||||
|
.cpp.o:
|
||||||
|
$(CXX) -c $(CXXFLAGS) $<
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
depend:
|
||||||
|
makedepend $(DEPMACROS) -Y. -f- *.cpp > Makefile.dep
|
||||||
|
echo -n "o = " > Makefile.o.dep
|
||||||
|
ls -1 *.cpp | xargs -I foo echo -n foo " " | sed -E "s/([^\.]*)\.cpp[ ]/\1\.o/g" >> Makefile.o.dep
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f *.o
|
||||||
|
|
||||||
|
include Makefile.dep
|
|
@ -0,0 +1,6 @@
|
||||||
|
# DO NOT DELETE
|
||||||
|
|
||||||
|
notify.o: templatesnotify.h ../core/mount.h ../../ezc/src/ezc.h
|
||||||
|
notify.o: ../core/notify.h ../templatesnotify/templatesnotify.h
|
||||||
|
templatesnotify.o: templatesnotify.h ../core/mount.h ../../ezc/src/ezc.h
|
||||||
|
templatesnotify.o: ../core/misc.h ../core/item.h
|
|
@ -0,0 +1 @@
|
||||||
|
o = notify.o templatesnotify.o
|
|
@ -0,0 +1,89 @@
|
||||||
|
/*
|
||||||
|
* 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 "templatesnotify.h"
|
||||||
|
#include "../core/notify.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace TemplatesNotifyFunctions
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void notify_item_added(Info & i)
|
||||||
|
{
|
||||||
|
i.result = (notify_msg->notify_code & CMSLU_NOTIFY_ITEM_ADD) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void notify_item_edited(Info & i)
|
||||||
|
{
|
||||||
|
i.result = (notify_msg->notify_code & CMSLU_NOTIFY_ITEM_EDIT) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void notify_item_deleted(Info & i)
|
||||||
|
{
|
||||||
|
i.result = (notify_msg->notify_code & CMSLU_NOTIFY_ITEM_DELETE) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void notify_dir_added(Info & i)
|
||||||
|
{
|
||||||
|
i.result = (notify_msg->notify_code & CMSLU_NOTIFY_DIR_ADD) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void notify_to(Info & i)
|
||||||
|
{
|
||||||
|
i.out << notify_msg->email;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void notify_mount_is_thread(Info & i)
|
||||||
|
{
|
||||||
|
i.result = notify_msg->current_mount_type == Mount::thread;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void notify_mount_is_cms(Info & i)
|
||||||
|
{
|
||||||
|
i.result = notify_msg->current_mount_type == Mount::cms;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void notify_doc_base_url(Info & i)
|
||||||
|
{
|
||||||
|
i.out << notify_msg->doc_base_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void notify_item_dir(Info & i)
|
||||||
|
{
|
||||||
|
i.out << notify_msg->item_dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void notify_item_link(Info & i)
|
||||||
|
{
|
||||||
|
i.out << notify_msg->item_link;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace TemplatesNotifyFunctions
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,81 @@
|
||||||
|
/*
|
||||||
|
* 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 "templatesnotify.h"
|
||||||
|
#include "../core/misc.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace TemplatesNotifyFunctions
|
||||||
|
{
|
||||||
|
Ezc::Pattern pat_notify_email;
|
||||||
|
Ezc::Functions functions;
|
||||||
|
|
||||||
|
|
||||||
|
// you can use this pointer in template functions (will be always valid)
|
||||||
|
NotifyMsg * notify_msg;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace TemplatesNotifyFunctions
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void TemplatesNotify::CreateFunctions()
|
||||||
|
{
|
||||||
|
using namespace TemplatesNotifyFunctions;
|
||||||
|
|
||||||
|
functions.Clear();
|
||||||
|
|
||||||
|
functions.Insert("notify_item_added", notify_item_added);
|
||||||
|
functions.Insert("notify_item_edited", notify_item_edited);
|
||||||
|
functions.Insert("notify_item_deleted", notify_item_deleted);
|
||||||
|
functions.Insert("notify_dir_added", notify_dir_added);
|
||||||
|
functions.Insert("notify_to", notify_to);
|
||||||
|
functions.Insert("notify_mount_is_thread", notify_mount_is_thread);
|
||||||
|
functions.Insert("notify_mount_is_cms", notify_mount_is_cms);
|
||||||
|
functions.Insert("notify_doc_base_url", notify_doc_base_url);
|
||||||
|
functions.Insert("notify_item_dir", notify_item_dir);
|
||||||
|
functions.Insert("notify_item_link", notify_item_link);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void TemplatesNotify::Read(const std::string & templates_dir)
|
||||||
|
{
|
||||||
|
using namespace TemplatesNotifyFunctions;
|
||||||
|
|
||||||
|
pat_notify_email.Directory(templates_dir);
|
||||||
|
pat_notify_email.ParseFile("notify_email.txt");
|
||||||
|
|
||||||
|
CreateFunctions();
|
||||||
|
notify_msg = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void TemplatesNotify::Generate()
|
||||||
|
{
|
||||||
|
using namespace TemplatesNotifyFunctions;
|
||||||
|
|
||||||
|
notify_str.str("");
|
||||||
|
|
||||||
|
if( !notify_msg )
|
||||||
|
return;
|
||||||
|
|
||||||
|
Ezc::Generator generator(notify_str, pat_notify_email, functions);
|
||||||
|
generator.Generate();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
/*
|
||||||
|
* 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 headerfilecmslutemplatestemplatesnotify
|
||||||
|
#define headerfilecmslutemplatestemplatesnotify
|
||||||
|
|
||||||
|
#include <iomanip>
|
||||||
|
#include <set>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "../core/mount.h"
|
||||||
|
#include "../../ezc/src/ezc.h"
|
||||||
|
|
||||||
|
|
||||||
|
struct NotifyMsg
|
||||||
|
{
|
||||||
|
std::string email;
|
||||||
|
int notify_code;
|
||||||
|
Mount::Type current_mount_type;
|
||||||
|
std::string doc_base_url;
|
||||||
|
std::string item_dir;
|
||||||
|
std::string item_link;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
namespace TemplatesNotifyFunctions
|
||||||
|
{
|
||||||
|
using Ezc::Info;
|
||||||
|
|
||||||
|
extern NotifyMsg * notify_msg;
|
||||||
|
|
||||||
|
void notify_item_added(Info & i);
|
||||||
|
void notify_item_edited(Info & i);
|
||||||
|
void notify_item_deleted(Info & i);
|
||||||
|
void notify_dir_added(Info & i);
|
||||||
|
void notify_to(Info & i);
|
||||||
|
void notify_mount_is_thread(Info & i);
|
||||||
|
void notify_mount_is_cms(Info & i);
|
||||||
|
void notify_doc_base_url(Info & i);
|
||||||
|
void notify_item_dir(Info & i);
|
||||||
|
void notify_item_link(Info & i);
|
||||||
|
|
||||||
|
} // namespace TemplatesNotifyFunctions
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class TemplatesNotify
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
void Read(const std::string & templates_dir);
|
||||||
|
void Generate();
|
||||||
|
|
||||||
|
std::ostringstream notify_str;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
void CreateFunctions();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue