78 Commits
0.3.1 ... 0.4.5

Author SHA1 Message Date
8154c403d8 we can create links (hard links, symbolic links) now
added winix functions: ln

winix function 'default' can be used without redirecting now

added new tickets types: TypeProgress, TypeString, TypeMultistring, TypeImages, TypeFiles
now tickets are combined with files
added winix functions: showtickets

fixed mountpoints:
when the default root mount was created its parameter table was empty
and it caused accessing to a non-existing objects

fixed logger:
modifiers (log1, log2, log3) were incorrectly treated
added modifier: log4 (debug info)

now we are moving threads to a new plugin 'thread'
created directory: plugins/thread
(not finished yet)




git-svn-id: svn://ttmath.org/publicrep/winix/trunk@704 e52654a7-88a9-db11-a3e9-0013d4bc506e
2011-01-05 21:24:11 +00:00
bb83aed20d changed cat template
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@703 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-12-12 09:41:20 +00:00
600c9fc907 Thumb thread should check the exit signal
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@701 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-12-12 09:25:36 +00:00
5d09eb149c added a special thread for making thumbnails (thumb.h thumb.cpp)
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@700 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-12-11 22:55:48 +00:00
e854fe3681 changed makefile
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@698 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-12-10 21:20:01 +00:00
36c8822e6c changed organization of static files
removed: item.auth item.auth_path
added:   item.file_path, item.file_fs, item.file_type
now the path to a static file is a relative path
added: thumbnails (not finished yet)
fixed: db didn't correctly return the number of deleted items /DelItem() method/




git-svn-id: svn://ttmath.org/publicrep/winix/trunk@696 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-12-10 21:07:01 +00:00
9b29cce1a4 added a special default function: "-"
the proper default function will be selected automatically


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@695 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-12-07 18:18:45 +00:00
508f06339e added to config: session_max
how many sessions can be: default 1000000 (one milion)


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@694 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-12-07 17:41:28 +00:00
0a9cdd2f15 added: gc for sessions (another thread)
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@693 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-12-07 12:52:52 +00:00
7f77b6e3ec added ezc function: user_is_in_all_groups
changed: ezc function user_is_in_group (we can provide more than one group now)


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@691 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-12-06 01:37:30 +00:00
9507b0b1ba changed Makefile
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@690 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-12-06 00:32:12 +00:00
ad9d6f4301 db: core/user table has only 'notify' column now (previous was cms_notify, thread_notify)
added: notifications for tickets (not finished yet)


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@688 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-12-06 00:25:46 +00:00
b721fb6860 changed path templatesnotifiy/ to notify/
i forgot to add a file: notify/notify.cpp


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@687 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-12-02 02:36:49 +00:00
5f46cd2ea5 moved: templatesnotify -> notify
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@686 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-12-02 02:16:11 +00:00
35efed9fef - now the mess with threads has gone away
- we have a class BaseThread -- this is a base class -- we can inherit from it when
  creating a new thread
- others treads are correctly stopped (when signal comes) -- pthread_join
- we have a special thread only for signals



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@685 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-12-02 01:02:02 +00:00
08e53919e2 changed: updated to the new ezc api, this with O(1) when looking for a specific ezc function
changed: sessions are deleted at the end of a request (and only a few sessions)
         other sessions will be deleted after a next request


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@684 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 22:42:24 +00:00
933c8841ff added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
         int Toi(const std::string & str,  int base = 10);
         int Toi(const std::wstring & str, int base = 10);
         int Toi(const char * str,         int base = 10);
         int Toi(const wchar_t * str,      int base = 10);

         long Tol(const std::string & str,  int base = 10);
         long Tol(const std::wstring & str, int base = 10);
         long Tol(const char * str,         int base = 10);
         long Tol(const wchar_t * str,      int base = 10);

         template<class CharType>
         bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);

         template<class CharType>
         bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);

         template<class CharType>
         bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);

         template<class CharType>
         bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);

         const wchar_t * Toa(unsigned int value,  int base = 10);
         const wchar_t * Toa(unsigned long value, int base = 10);
         const wchar_t * Toa(int value,  int base = 10);
         const wchar_t * Toa(long value, int base = 10);

         void Toa(int  value, std::string & res,  int base = 10, bool clear = true);
         void Toa(long value, std::string & res,  int base = 10, bool clear = true);
         void Toa(int  value, std::wstring & res, int base = 10, bool clear = true);
         void Toa(long value, std::wstring & res, int base = 10, bool clear = true);

added:   HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
         this is a special stream for automatically escaping html tags
	     



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 01:34:46 +00:00
518281e101 fixed: when signal comes winix properly exits
fixed:   when winix exits the session data were not properly destroyed (memory leak)
         we should set request.session pointer to each session when deleting sessions
         from session_container
         the session data were not properly destroyed when winix checked for 
         outdated sessions (and when it was removing them)
fixed:   performance (memcpy used too often)
         in some places there were reserve method used (on std::wstring/std::string objects)
         especially in AssignString() method and TextStream<> object
         if we add a new string we should check the new size
         and only call reserve() if the new size will be greater than existing one
         (plus some constant)
changed: fcgi objects moved to App class (from Request)
         now we use thread safe methods (e.g. FCGX_Accept_r)
added:   log_plugin_call option to the config
         default: false
         when true winix log when a plugin function is called
added:   winix parameter 'nostat' for not calculating statistics
         (useful when making performance tests)


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@680 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-23 21:52:25 +00:00
515d4bab0d added ezc functions: winix_false, winix_true
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@679 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-22 01:12:46 +00:00
8e72a820dd added support for UTF-8
now the UTF-8 is a default charset


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@677 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-21 00:19:17 +00:00
f1f0fa34cb fixed: didn't compile
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@676 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-04 17:13:13 +00:00
5010ef93e8 added temporary debug info to Notify::ItemChanged() method
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@674 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-04 17:05:59 +00:00
e6679a3192 added a new winix function "vim" - an editor based on the WYMeditor
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@673 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-04 16:46:19 +00:00
7cf8d5d2d3 added: to htmlfilter: param tag has not an ending tag
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@672 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-10-25 18:00:23 +00:00
14198eca41 fixed: some log problems
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@671 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-10-24 19:31:43 +00:00
c6473f20dc now winix can demonize itself
parameter in the config: demonize (default: true)
 


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@669 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-10-24 19:26:54 +00:00
9c34cb5862 winix can drop privileges now (if started as the root)
added parameters to the config:
 user (string)
 group (string)
 additional_groups (bool)



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@668 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-10-24 17:49:38 +00:00
149fd1629f rm function can remove tickets now
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@667 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-10-23 23:51:44 +00:00
c48241f78a fixed: there were mktime() used on some dirs Items
so sometimes the time of the dir was changed

now for converting tm into time_t use:
time_t Time(const tm & par);
time_t Time(const tm * par);
tm     Time(time_t par);
from core/misc.h

now winix internally use GMT time
only when printing it is converted to local user time
temporarily all users use the same local time (config: time_zone_offset)
(only logs are genereted with local system time)

added to system:
time_t LocalTime(time_t gmt_time);
tm     LocalTime(const tm * ptm);
tm     LocalTime(const tm & ptm);
they convert GMT time to local user time




git-svn-id: svn://ttmath.org/publicrep/winix/trunk@666 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-10-23 23:12:47 +00:00
a1bee81a5b added 'stat' winix function
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@665 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-10-23 14:54:44 +00:00
1b053c03ba added: now plugin ticket uses a new horizontal table (plugins.ticket)
columns: dir_id, param, value
we are able to build complicated tickets 



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@664 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-10-19 00:31:20 +00:00
33057acd62 added ticket parser: plugins/ticket/ticketparser.h plugins/ticket/ticketparser.cpp
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@663 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-10-11 20:42:49 +00:00
07511a2eb0 fixed: DbBase::ConvertTime(tm) should not have been used in this way as it was
(it uses a static buffer)
       now DbTextStream can get tm struct so you don't have to use ConvertTime 


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@662 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-10-09 20:27:45 +00:00
69c634d53f added to core/misc:
bool EqualNoCase(const std::string & str1, const std::string & str2)


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@660 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-10-01 23:20:03 +00:00
7bc17a9202 fixed: ticket sets a default function only for directories
fixed: reading a new url and subject in Functions::ReadItem()
added: tickets are sorted now (by date)



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@659 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-09-30 20:58:20 +00:00
d94a08b991 moved: plugins/ticket/ticket.cpp -> plugins/ticket/templates.cpp
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@658 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-09-29 22:41:34 +00:00
a8b8c1feec tickets has been moved to a new plugin 'ticket'
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@657 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-09-29 21:24:34 +00:00
a589e5a090 added: TextStream a class similar to std::ostringstream
but with a Clear() method
       the dynamic allocated buffer can be easily reused
added: DbTextStream a special version of a stream
       used to create a database string query
       everything is escaped by default
added: DbBase a base class with some basic methods for communicating
       with the database
added: DbConn a class for managing connection to the database
changed: some refactoring in Db class       



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@655 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-09-18 00:51:12 +00:00
8b1db3304f creating winix/db directory (for the database class)
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@654 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-09-16 10:20:20 +00:00
23aedd68b0 changed: mount points
mount type and mount fs are of type 'int' now
they can be added by plugins


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@652 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-09-12 23:33:27 +00:00
f48f08a98b changed: notification's template
added: notifications in tickets


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@650 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-09-07 23:54:01 +00:00
81dd88d25a fixed: there was missing html/fun_editticket.html template
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@649 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-09-05 18:58:24 +00:00
c92081d6e1 added: to stats plugin: microsoft bing searcher
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@648 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-08-28 21:19:30 +00:00
d6e80f5a23 fixed: plugins path
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@647 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-08-17 23:48:42 +00:00
37cf71234c changed makefile
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@645 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-08-17 23:33:27 +00:00
3b655f39e1 added: plugins_dir to config
small changes in makefiles


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@643 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-08-17 22:32:47 +00:00
eec0ddf466 added: method ConfParser::UseEscapeChar(bool escape)
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@642 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-08-16 14:15:37 +00:00
ca4e53bb0f html code in editors (emacs, ckeditor...) is filtered now for normal users
(root is allowed to use any html code)


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@641 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-08-14 17:56:07 +00:00
d9f2e91806 removed some debug logs from emacs
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@640 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-08-14 17:07:13 +00:00
7bfed62526 emacs didn't correctly report errors from db
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@639 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-08-14 16:55:16 +00:00
b63ac98f40 now winix waites for the database to be ready (when the operating system starts)
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@638 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-08-14 16:23:18 +00:00
1e7d297c0e small changes in template winix function
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@637 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-08-14 14:45:25 +00:00
f3cd3b88b9 some improvement in templates
(now we have O(1) time for selecting the right html template)
added: winix function: template
for selecting a template for an item (file or dir)



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@636 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-08-13 20:04:57 +00:00
9a199cd834 part II of rewriting
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@635 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-08-12 19:10:12 +00:00
c3fac2e83f changed method: void PostMultiParser::ReadContentToFileLoop()
previous version was not clean


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@634 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-08-11 15:47:44 +00:00
c7f6d2727c fixed: PostMultiParser incorrectly logged the size of input items (those which were not files)
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@633 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-08-11 10:00:23 +00:00
9901c63ede removed some thread and ticket information from request
they are in FunThread and FunTicket classes now
added funtion FunUptime (I forgot about it)



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@631 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-08-10 20:43:38 +00:00
76897b8a83 I have forgotten to create classes: Ckeditor and Tinymce (in functions)
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@630 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-08-10 17:05:19 +00:00
217cf1420b the first part of reimplementing has been done
now we have app object and singletons are only: log logn plugin and app



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@628 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-08-10 16:12:50 +00:00
6897192364 added: [dir_last_url_is] to templates
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@626 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-08-02 18:36:17 +00:00
031ace3fe5 changed: the way how plugins work
all your plugin functions can have signature either:
void my_function(PluginInfo & info); or
void my_function();
only the main Init should have:
extern "C" void Init(PluginFunction & info);

added: directory 'plugins' for plugins
added: 'stats' plugin
		  


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@624 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-07-27 20:41:56 +00:00
e4683b9a05 fixed: in htmlfilter: <area> should be treated as single tag
changed: ConfParser is abble to recognize lists


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@623 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-07-21 17:24:16 +00:00
93da32cfb3 updated to the new version of ezc
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@621 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-07-19 23:07:34 +00:00
62a0e52092 added: progress bar (image) to tickets table
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@620 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-07-05 17:22:30 +00:00
262ba10443 small refactoring
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@619 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-07-05 15:21:06 +00:00
50cb88c5ed added: parameters consist of a name and a value now
sample: /dir/dir2/function/paramname:paramvalue
removed: TemplatesMisc namespace



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@618 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-07-04 20:27:14 +00:00
76e32703ac fixed: a mount parameter html_template() was not properly read when mountpoints were reloaded
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@617 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-07-01 15:40:18 +00:00
d9f5fbaf04 added: "edit" button on threads
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@616 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-06-30 19:56:32 +00:00
16bb238518 added: bbcode
files: core/bbcodeparser.h core/bbcodeparser.cpp


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@615 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-06-30 18:42:50 +00:00
759135fd7d struct Item has modification_user_id (long) now
this is the id of a user who has modified the item recently
this is only for information, persmissions don't use it


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@614 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-06-22 21:09:37 +00:00
56075857f2 debug
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@613 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-06-22 13:05:49 +00:00
8d3c7500d8 debugging info
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@612 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-06-22 13:01:56 +00:00
1e3f5e8695 added: mount option: html_template(file.html)
files: indexpatterns.h indexpatterns.cpp
removed: templates/index_root.html
        its content was moved to index.html


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@611 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-06-21 23:53:19 +00:00
08f5865c72 html templates
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@610 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-06-21 13:10:53 +00:00
ff3c141138 added: a new editor: tinymce (function tinymce)
added: html filter can check orphans: "i", "a", "o" ... in a text


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@607 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-06-20 22:47:24 +00:00
fe31e0e849 added: cp function for directories
added: emacs/mkdir uses group_id of the parent directory when creating new items
added: parameter 'dirls' to ls function


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@606 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-06-05 19:44:49 +00:00
2a26968c6c added: function cp (only for files)
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@605 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-06-03 17:38:18 +00:00
fe8774953a changed html templates
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@604 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-05-31 20:42:13 +00:00
366 changed files with 32241 additions and 14577 deletions

View File

@@ -9,32 +9,40 @@ CXXFLAGS = -fPIC -Wall -pedantic -O2 -I/usr/local/include -I/home/tomek/roboczy/
endif
export CXX
export CXXFLAGS
all: winix
winix: FORCE
@cd core ; $(MAKE) -e
@cd content ; $(MAKE) -e
@cd confparser ; $(MAKE) -e
@cd db ; $(MAKE) -e
@cd functions ; $(MAKE) -e
@cd templates ; $(MAKE) -e
@cd templatesnotify ; $(MAKE) -e
@cd notify ; $(MAKE) -e
@cd plugins/stats ; $(MAKE) -e
@cd plugins/ticket ; $(MAKE) -e
@cd ../ezc/src ; $(MAKE) -e
$(CXX) -shared -o winix.so $(CXXFLAGS) core/*.o content/*.o templates/*.o templatesnotify/*.o confparser/*.o ../ezc/src/ezc.a -lfcgi -lpq -lz -lpthread
$(CXX) -shared -o winix.so $(CXXFLAGS) core/*.o db/*.o functions/*.o templates/*.o notify/*.o ../ezc/src/ezc.a -lfcgi -lpq -lz -lpthread -lfetch
@cd main ; $(MAKE) -e
# use the full path with winix.so
$(CXX) -o winix $(CXXFLAGS) main/*.o /home/tomek/roboczy/winix/winix.so
clean:
@cd core ; $(MAKE) -e clean
@cd content ; $(MAKE) -e clean
@cd confparser ; $(MAKE) -e clean
@cd db ; $(MAKE) -e clean
@cd functions ; $(MAKE) -e clean
@cd templates ; $(MAKE) -e clean
@cd templatesnotify ; $(MAKE) -e clean
@cd notify ; $(MAKE) -e clean
@cd plugins/stats ; $(MAKE) -e clean
@cd plugins/ticket ; $(MAKE) -e clean
@cd ../ezc/src ; $(MAKE) -e clean
@cd main ; $(MAKE) -e clean
rm -f winix.so
@@ -46,16 +54,36 @@ FORCE:
depend:
@cd core ; $(MAKE) -e depend
@cd content ; $(MAKE) -e depend
@cd confparser ; $(MAKE) -e depend
@cd db ; $(MAKE) -e depend
@cd functions ; $(MAKE) -e depend
@cd templates ; $(MAKE) -e depend
@cd templatesnotify ; $(MAKE) -e depend
@cd notify ; $(MAKE) -e depend
@cd plugins/stats ; $(MAKE) -e depend
@cd plugins/ticket ; $(MAKE) -e depend
@cd ../ezc/src ; $(MAKE) -e depend
@cd main ; $(MAKE) -e depend
#install: all
# mkdir -p bin
# rm -f bin/winix.so
# rm -f bin/winix
# cp winix.so bin/
# cp winix bin/
install: all
# binaries
mkdir -p /usr/local/winix/bin
cp winix.so /usr/local/winix/bin
# use the full path with winix.so (we have to recompile winix with a new path to winix.so)
$(CXX) -o /usr/local/winix/bin/winix $(CXXFLAGS) main/*.o /usr/local/winix/bin/winix.so
# html templates
mkdir -p /usr/local/winix/html
cp -rf html/ /usr/local/winix/html/
find /usr/local/winix/html/ -type d -name ".svn" | xargs -I foo rm -fr foo
# txt templates
mkdir -p /usr/local/winix/txt
cp -rf txt/ /usr/local/winix/txt/
find /usr/local/winix/txt/ -type d -name ".svn" | xargs -I foo rm -fr foo
# locales
mkdir -p /usr/local/winix/locale
cp -rf locale/ /usr/local/winix/locale/
find /usr/local/winix/locale/ -type d -name ".svn" | xargs -I foo rm -fr foo
# plugins
mkdir -p /usr/local/winix/plugins
find plugins/ -name "*.so" | xargs -I foo cp foo /usr/local/winix/plugins/
# removed provileges for others
find /usr/local/winix -exec chmod o-r,o-x,o-w "{}" "+"

View File

@@ -1,3 +0,0 @@
# DO NOT DELETE
confparser.o: confparser.h

View File

@@ -1 +0,0 @@
o = confparser.o

View File

@@ -1,240 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "confparser.h"
ConfParser::ConfParser()
{
separator = '=';
commentary = '#';
}
ConfParser::Status ConfParser::Parse(const char * file_name)
{
line = 1;
table.clear();
file.clear();
file.open( file_name );
if( !file )
return cant_open_file;
ReadChar();
status = ParseFile();
file.close();
return status;
}
ConfParser::Status ConfParser::ParseFile()
{
while( lastc != -1 )
{
if( ReadVariable() )
{
if( lastc != separator )
return syntax_error;
ReadChar(); // skipping separator
if( !ReadValue() )
return syntax_error;
//table.insert( std::make_pair(variable, value) );
table[variable] = value;
}
if( lastc == commentary )
SkipLine();
if( lastc != -1 && lastc != '\n' )
return syntax_error;
ReadChar(); // skipping '\n' if was
}
return ok;
}
bool ConfParser::IsVariableChar(int c)
{
if( (c>='a' && c<='z') ||
(c>='A' && c<='Z') ||
(c>='0' && c<='9') ||
c=='.' || c==',' || c=='_' )
return true;
return false;
}
bool ConfParser::IsValueSimpleChar(int c)
{
//if( c==-1 || c=='\n' || IsWhite(c) || c==commentary )
if( c==-1 || c=='\n' || c==commentary )
return false;
return true;
}
bool ConfParser::ReadVariable()
{
variable.clear();
SkipWhite();
while( IsVariableChar(lastc) )
{
variable += lastc;
ReadChar();
}
SkipWhite();
return !variable.empty();
}
bool ConfParser::ReadValue()
{
value.clear();
SkipWhite();
if( lastc == '"' )
// quoted value
return ReadValueQuoted();
else
return ReadValueSimple();
}
bool ConfParser::ReadValueQuoted()
{
ReadChar(); // skipping the first quote
while( lastc != '\n' && lastc != '"' && lastc != -1 )
{
if( lastc == '\\' )
ReadChar();
value += lastc;
ReadChar();
}
if( lastc != '"' )
return false;
ReadChar(); // skipping the last quote
SkipWhite();
return true;
}
bool ConfParser::ReadValueSimple()
{
while( IsValueSimpleChar(lastc) )
{
value += lastc;
ReadChar();
}
Trim(value);
SkipWhite();
return true;
}
int ConfParser::ReadChar()
{
lastc = file.get();
if( lastc == '\n' )
++line;
return lastc;
}
bool ConfParser::IsWhite(int c)
{
if( c==' ' || c=='\t' || c==13 )
return true;
return false;
}
void ConfParser::SkipWhite()
{
while( IsWhite(lastc) )
ReadChar();
}
void ConfParser::SkipLine()
{
while( lastc != -1 && lastc != '\n' )
ReadChar();
}
void ConfParser::Trim(std::string & s)
{
std::string::size_type i;
if( s.empty() )
return;
// looking for white characters at the end
for(i=s.size()-1 ; i>0 && IsWhite(s[i]) ; --i);
if( i==0 && IsWhite(s[i]) )
{
// the whole string has white characters
s.clear();
return;
}
// deleting white characters at the end
if( i != s.size() - 1 )
s.erase(i+1, std::string::npos);
// looking for white characters at the beginning
for(i=0 ; i<s.size() && IsWhite(s[i]) ; ++i);
// deleting white characters at the beginning
if( i != 0 )
s.erase(0, i);
}

View File

@@ -1,74 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfileconfparser
#define headerfileconfparser
#include <fstream>
#include <string>
#include <map>
class ConfParser
{
public:
enum Status { ok, cant_open_file, syntax_error };
ConfParser();
Status Parse(const char * file_name);
// last status
Status status;
// line in which there is a syntax_error
int line;
typedef std::map<std::string, std::string> Table;
Table table;
private:
// last read variable, value
std::string variable, value;
// separator between a variable and a value, usually '='
int separator;
// commentary char
int commentary;
// last read char
int lastc;
// current file
std::ifstream file;
Status ParseFile();
bool IsVariableChar(int c);
bool IsValueSimpleChar(int c);
bool ReadVariable();
bool ReadValue();
bool ReadValueQuoted();
bool ReadValueSimple();
int ReadChar();
bool IsWhite(int c);
void SkipWhite();
void SkipLine();
void Trim(std::string & s);
};
#endif

View File

@@ -1,416 +0,0 @@
# DO NOT DELETE
adduser.o: content.h ../core/item.h ../templates/templates.h
adduser.o: ../templates/patterncacher.h ../templates/misc.h
adduser.o: ../templates/localefilter.h ../core/locale.h
adduser.o: ../confparser/confparser.h ../templates/ckeditorgetparser.h
adduser.o: ../core/httpsimpleparser.h ../core/log.h ../core/thread.h
adduser.o: ../core/ticket.h ../core/db.h ../core/item.h ../core/user.h
adduser.o: ../core/group.h ../core/thread.h ../core/error.h ../core/log.h
adduser.o: ../core/dircontainer.h ../core/ugcontainer.h ../core/ticket.h
adduser.o: ../core/request.h ../core/requesttypes.h ../core/session.h
adduser.o: ../core/rebus.h ../core/plugindata.h ../core/function.h
adduser.o: ../core/compress.h ../core/acceptencodingparser.h
adduser.o: ../core/acceptbaseparser.h ../core/htmlfilter.h
adduser.o: ../core/postmultiparser.h ../core/data.h ../core/dirs.h
adduser.o: ../core/users.h ../core/groups.h ../core/functions.h
adduser.o: ../core/lastcontainer.h ../core/mounts.h ../core/mount.h
adduser.o: ../core/loadavg.h
cat.o: content.h ../core/item.h ../templates/templates.h
cat.o: ../templates/patterncacher.h ../templates/misc.h
cat.o: ../templates/localefilter.h ../core/locale.h
cat.o: ../confparser/confparser.h ../templates/ckeditorgetparser.h
cat.o: ../core/httpsimpleparser.h ../core/log.h ../core/thread.h
cat.o: ../core/ticket.h ../core/db.h ../core/item.h ../core/user.h
cat.o: ../core/group.h ../core/thread.h ../core/error.h ../core/log.h
cat.o: ../core/dircontainer.h ../core/ugcontainer.h ../core/ticket.h
cat.o: ../core/request.h ../core/requesttypes.h ../core/session.h
cat.o: ../core/rebus.h ../core/plugindata.h ../core/function.h
cat.o: ../core/compress.h ../core/acceptencodingparser.h
cat.o: ../core/acceptbaseparser.h ../core/htmlfilter.h
cat.o: ../core/postmultiparser.h ../core/error.h ../core/data.h
cat.o: ../core/dirs.h ../core/users.h ../core/groups.h ../core/functions.h
cat.o: ../core/lastcontainer.h ../core/mounts.h ../core/mount.h
cat.o: ../core/loadavg.h
content.o: content.h ../core/item.h ../templates/templates.h
content.o: ../templates/patterncacher.h ../templates/misc.h
content.o: ../templates/localefilter.h ../core/locale.h
content.o: ../confparser/confparser.h ../templates/ckeditorgetparser.h
content.o: ../core/httpsimpleparser.h ../core/log.h ../core/thread.h
content.o: ../core/ticket.h ../core/db.h ../core/item.h ../core/user.h
content.o: ../core/group.h ../core/thread.h ../core/error.h ../core/log.h
content.o: ../core/dircontainer.h ../core/ugcontainer.h ../core/ticket.h
content.o: ../core/request.h ../core/requesttypes.h ../core/session.h
content.o: ../core/rebus.h ../core/plugindata.h ../core/function.h
content.o: ../core/compress.h ../core/acceptencodingparser.h
content.o: ../core/acceptbaseparser.h ../core/htmlfilter.h
content.o: ../core/postmultiparser.h ../core/error.h ../core/data.h
content.o: ../core/dirs.h ../core/users.h ../core/groups.h
content.o: ../core/functions.h ../core/lastcontainer.h ../core/mounts.h
content.o: ../core/mount.h ../core/loadavg.h ../core/misc.h ../core/plugin.h
content.o: ../core/request.h ../core/data.h ../core/pluginmsg.h
createthread.o: content.h ../core/item.h ../templates/templates.h
createthread.o: ../templates/patterncacher.h ../templates/misc.h
createthread.o: ../templates/localefilter.h ../core/locale.h
createthread.o: ../confparser/confparser.h ../templates/ckeditorgetparser.h
createthread.o: ../core/httpsimpleparser.h ../core/log.h ../core/thread.h
createthread.o: ../core/ticket.h ../core/db.h ../core/item.h ../core/user.h
createthread.o: ../core/group.h ../core/thread.h ../core/error.h
createthread.o: ../core/log.h ../core/dircontainer.h ../core/ugcontainer.h
createthread.o: ../core/ticket.h ../core/request.h ../core/requesttypes.h
createthread.o: ../core/session.h ../core/rebus.h ../core/plugindata.h
createthread.o: ../core/function.h ../core/compress.h
createthread.o: ../core/acceptencodingparser.h ../core/acceptbaseparser.h
createthread.o: ../core/htmlfilter.h ../core/postmultiparser.h
createthread.o: ../core/error.h ../core/mount.h ../core/data.h ../core/dirs.h
createthread.o: ../core/users.h ../core/groups.h ../core/functions.h
createthread.o: ../core/lastcontainer.h ../core/mounts.h ../core/mount.h
createthread.o: ../core/loadavg.h
createticket.o: content.h ../core/item.h ../templates/templates.h
createticket.o: ../templates/patterncacher.h ../templates/misc.h
createticket.o: ../templates/localefilter.h ../core/locale.h
createticket.o: ../confparser/confparser.h ../templates/ckeditorgetparser.h
createticket.o: ../core/httpsimpleparser.h ../core/log.h ../core/thread.h
createticket.o: ../core/ticket.h ../core/db.h ../core/item.h ../core/user.h
createticket.o: ../core/group.h ../core/thread.h ../core/error.h
createticket.o: ../core/log.h ../core/dircontainer.h ../core/ugcontainer.h
createticket.o: ../core/ticket.h ../core/request.h ../core/requesttypes.h
createticket.o: ../core/session.h ../core/rebus.h ../core/plugindata.h
createticket.o: ../core/function.h ../core/compress.h
createticket.o: ../core/acceptencodingparser.h ../core/acceptbaseparser.h
createticket.o: ../core/htmlfilter.h ../core/postmultiparser.h
createticket.o: ../core/error.h ../core/mount.h ../core/data.h ../core/dirs.h
createticket.o: ../core/users.h ../core/groups.h ../core/functions.h
createticket.o: ../core/lastcontainer.h ../core/mounts.h ../core/mount.h
createticket.o: ../core/loadavg.h
default.o: content.h ../core/item.h ../templates/templates.h
default.o: ../templates/patterncacher.h ../templates/misc.h
default.o: ../templates/localefilter.h ../core/locale.h
default.o: ../confparser/confparser.h ../templates/ckeditorgetparser.h
default.o: ../core/httpsimpleparser.h ../core/log.h ../core/thread.h
default.o: ../core/ticket.h ../core/db.h ../core/item.h ../core/user.h
default.o: ../core/group.h ../core/thread.h ../core/error.h ../core/log.h
default.o: ../core/dircontainer.h ../core/ugcontainer.h ../core/ticket.h
default.o: ../core/request.h ../core/requesttypes.h ../core/session.h
default.o: ../core/rebus.h ../core/plugindata.h ../core/function.h
default.o: ../core/compress.h ../core/acceptencodingparser.h
default.o: ../core/acceptbaseparser.h ../core/htmlfilter.h
default.o: ../core/postmultiparser.h ../core/error.h ../core/data.h
default.o: ../core/dirs.h ../core/users.h ../core/groups.h
default.o: ../core/functions.h ../core/lastcontainer.h ../core/mounts.h
default.o: ../core/mount.h ../core/loadavg.h
download.o: content.h ../core/item.h ../templates/templates.h
download.o: ../templates/patterncacher.h ../templates/misc.h
download.o: ../templates/localefilter.h ../core/locale.h
download.o: ../confparser/confparser.h ../templates/ckeditorgetparser.h
download.o: ../core/httpsimpleparser.h ../core/log.h ../core/thread.h
download.o: ../core/ticket.h ../core/db.h ../core/item.h ../core/user.h
download.o: ../core/group.h ../core/thread.h ../core/error.h ../core/log.h
download.o: ../core/dircontainer.h ../core/ugcontainer.h ../core/ticket.h
download.o: ../core/request.h ../core/requesttypes.h ../core/session.h
download.o: ../core/rebus.h ../core/plugindata.h ../core/function.h
download.o: ../core/compress.h ../core/acceptencodingparser.h
download.o: ../core/acceptbaseparser.h ../core/htmlfilter.h
download.o: ../core/postmultiparser.h ../core/data.h ../core/dirs.h
download.o: ../core/users.h ../core/groups.h ../core/functions.h
download.o: ../core/lastcontainer.h ../core/mounts.h ../core/mount.h
download.o: ../core/loadavg.h
editticket.o: content.h ../core/item.h ../templates/templates.h
editticket.o: ../templates/patterncacher.h ../templates/misc.h
editticket.o: ../templates/localefilter.h ../core/locale.h
editticket.o: ../confparser/confparser.h ../templates/ckeditorgetparser.h
editticket.o: ../core/httpsimpleparser.h ../core/log.h ../core/thread.h
editticket.o: ../core/ticket.h ../core/db.h ../core/item.h ../core/user.h
editticket.o: ../core/group.h ../core/thread.h ../core/error.h ../core/log.h
editticket.o: ../core/dircontainer.h ../core/ugcontainer.h ../core/ticket.h
editticket.o: ../core/request.h ../core/requesttypes.h ../core/session.h
editticket.o: ../core/rebus.h ../core/plugindata.h ../core/function.h
editticket.o: ../core/compress.h ../core/acceptencodingparser.h
editticket.o: ../core/acceptbaseparser.h ../core/htmlfilter.h
editticket.o: ../core/postmultiparser.h ../core/error.h ../core/mount.h
editticket.o: ../core/data.h ../core/dirs.h ../core/users.h ../core/groups.h
editticket.o: ../core/functions.h ../core/lastcontainer.h ../core/mounts.h
editticket.o: ../core/mount.h ../core/loadavg.h
emacs.o: content.h ../core/item.h ../templates/templates.h
emacs.o: ../templates/patterncacher.h ../templates/misc.h
emacs.o: ../templates/localefilter.h ../core/locale.h
emacs.o: ../confparser/confparser.h ../templates/ckeditorgetparser.h
emacs.o: ../core/httpsimpleparser.h ../core/log.h ../core/thread.h
emacs.o: ../core/ticket.h ../core/db.h ../core/item.h ../core/user.h
emacs.o: ../core/group.h ../core/thread.h ../core/error.h ../core/log.h
emacs.o: ../core/dircontainer.h ../core/ugcontainer.h ../core/ticket.h
emacs.o: ../core/request.h ../core/requesttypes.h ../core/session.h
emacs.o: ../core/rebus.h ../core/plugindata.h ../core/function.h
emacs.o: ../core/compress.h ../core/acceptencodingparser.h
emacs.o: ../core/acceptbaseparser.h ../core/htmlfilter.h
emacs.o: ../core/postmultiparser.h ../core/error.h ../core/data.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/loadavg.h ../core/notify.h
emacs.o: ../templatesnotify/templatesnotify.h ../core/mount.h
emacs.o: ../templates/misc.h ../core/misc.h
last.o: content.h ../core/item.h ../templates/templates.h
last.o: ../templates/patterncacher.h ../templates/misc.h
last.o: ../templates/localefilter.h ../core/locale.h
last.o: ../confparser/confparser.h ../templates/ckeditorgetparser.h
last.o: ../core/httpsimpleparser.h ../core/log.h ../core/thread.h
last.o: ../core/ticket.h ../core/db.h ../core/item.h ../core/user.h
last.o: ../core/group.h ../core/thread.h ../core/error.h ../core/log.h
last.o: ../core/dircontainer.h ../core/ugcontainer.h ../core/ticket.h
login.o: content.h ../core/item.h ../templates/templates.h
login.o: ../templates/patterncacher.h ../templates/misc.h
login.o: ../templates/localefilter.h ../core/locale.h
login.o: ../confparser/confparser.h ../templates/ckeditorgetparser.h
login.o: ../core/httpsimpleparser.h ../core/log.h ../core/thread.h
login.o: ../core/ticket.h ../core/db.h ../core/item.h ../core/user.h
login.o: ../core/group.h ../core/thread.h ../core/error.h ../core/log.h
login.o: ../core/dircontainer.h ../core/ugcontainer.h ../core/ticket.h
login.o: ../core/request.h ../core/requesttypes.h ../core/session.h
login.o: ../core/rebus.h ../core/plugindata.h ../core/function.h
login.o: ../core/compress.h ../core/acceptencodingparser.h
login.o: ../core/acceptbaseparser.h ../core/htmlfilter.h
login.o: ../core/postmultiparser.h ../core/error.h ../core/data.h
login.o: ../core/dirs.h ../core/users.h ../core/groups.h ../core/functions.h
login.o: ../core/lastcontainer.h ../core/mounts.h ../core/mount.h
login.o: ../core/loadavg.h
logout.o: content.h ../core/item.h ../templates/templates.h
logout.o: ../templates/patterncacher.h ../templates/misc.h
logout.o: ../templates/localefilter.h ../core/locale.h
logout.o: ../confparser/confparser.h ../templates/ckeditorgetparser.h
logout.o: ../core/httpsimpleparser.h ../core/log.h ../core/thread.h
logout.o: ../core/ticket.h ../core/db.h ../core/item.h ../core/user.h
logout.o: ../core/group.h ../core/thread.h ../core/error.h ../core/log.h
logout.o: ../core/dircontainer.h ../core/ugcontainer.h ../core/ticket.h
logout.o: ../core/request.h ../core/requesttypes.h ../core/session.h
logout.o: ../core/rebus.h ../core/plugindata.h ../core/function.h
logout.o: ../core/compress.h ../core/acceptencodingparser.h
logout.o: ../core/acceptbaseparser.h ../core/htmlfilter.h
logout.o: ../core/postmultiparser.h ../core/data.h ../core/dirs.h
logout.o: ../core/users.h ../core/groups.h ../core/functions.h
logout.o: ../core/lastcontainer.h ../core/mounts.h ../core/mount.h
logout.o: ../core/loadavg.h
ls.o: content.h ../core/item.h ../templates/templates.h
ls.o: ../templates/patterncacher.h ../templates/misc.h
ls.o: ../templates/localefilter.h ../core/locale.h ../confparser/confparser.h
ls.o: ../templates/ckeditorgetparser.h ../core/httpsimpleparser.h
ls.o: ../core/log.h ../core/thread.h ../core/ticket.h ../core/db.h
ls.o: ../core/item.h ../core/user.h ../core/group.h ../core/thread.h
ls.o: ../core/error.h ../core/log.h ../core/dircontainer.h
ls.o: ../core/ugcontainer.h ../core/ticket.h ../core/request.h
ls.o: ../core/requesttypes.h ../core/session.h ../core/rebus.h
ls.o: ../core/plugindata.h ../core/function.h ../core/compress.h
ls.o: ../core/acceptencodingparser.h ../core/acceptbaseparser.h
ls.o: ../core/htmlfilter.h ../core/postmultiparser.h
misc_item.o: content.h ../core/item.h ../templates/templates.h
misc_item.o: ../templates/patterncacher.h ../templates/misc.h
misc_item.o: ../templates/localefilter.h ../core/locale.h
misc_item.o: ../confparser/confparser.h ../templates/ckeditorgetparser.h
misc_item.o: ../core/httpsimpleparser.h ../core/log.h ../core/thread.h
misc_item.o: ../core/ticket.h ../core/db.h ../core/item.h ../core/user.h
misc_item.o: ../core/group.h ../core/thread.h ../core/error.h ../core/log.h
misc_item.o: ../core/dircontainer.h ../core/ugcontainer.h ../core/ticket.h
misc_item.o: ../core/request.h ../core/requesttypes.h ../core/session.h
misc_item.o: ../core/rebus.h ../core/plugindata.h ../core/function.h
misc_item.o: ../core/compress.h ../core/acceptencodingparser.h
misc_item.o: ../core/acceptbaseparser.h ../core/htmlfilter.h
misc_item.o: ../core/postmultiparser.h ../core/misc.h
misc_specialfile.o: content.h ../core/item.h ../templates/templates.h
misc_specialfile.o: ../templates/patterncacher.h ../templates/misc.h
misc_specialfile.o: ../templates/localefilter.h ../core/locale.h
misc_specialfile.o: ../confparser/confparser.h
misc_specialfile.o: ../templates/ckeditorgetparser.h
misc_specialfile.o: ../core/httpsimpleparser.h ../core/log.h ../core/thread.h
misc_specialfile.o: ../core/ticket.h ../core/db.h ../core/item.h
misc_specialfile.o: ../core/user.h ../core/group.h ../core/thread.h
misc_specialfile.o: ../core/error.h ../core/log.h ../core/dircontainer.h
misc_specialfile.o: ../core/ugcontainer.h ../core/ticket.h ../core/request.h
misc_specialfile.o: ../core/requesttypes.h ../core/session.h ../core/rebus.h
misc_specialfile.o: ../core/plugindata.h ../core/function.h
misc_specialfile.o: ../core/compress.h ../core/acceptencodingparser.h
misc_specialfile.o: ../core/acceptbaseparser.h ../core/htmlfilter.h
misc_specialfile.o: ../core/postmultiparser.h ../core/data.h ../core/dirs.h
misc_specialfile.o: ../core/users.h ../core/groups.h ../core/functions.h
misc_specialfile.o: ../core/lastcontainer.h ../core/mounts.h ../core/mount.h
misc_specialfile.o: ../core/loadavg.h
mkdir.o: content.h ../core/item.h ../templates/templates.h
mkdir.o: ../templates/patterncacher.h ../templates/misc.h
mkdir.o: ../templates/localefilter.h ../core/locale.h
mkdir.o: ../confparser/confparser.h ../templates/ckeditorgetparser.h
mkdir.o: ../core/httpsimpleparser.h ../core/log.h ../core/thread.h
mkdir.o: ../core/ticket.h ../core/db.h ../core/item.h ../core/user.h
mkdir.o: ../core/group.h ../core/thread.h ../core/error.h ../core/log.h
mkdir.o: ../core/dircontainer.h ../core/ugcontainer.h ../core/ticket.h
mkdir.o: ../core/request.h ../core/requesttypes.h ../core/session.h
mkdir.o: ../core/rebus.h ../core/plugindata.h ../core/function.h
mkdir.o: ../core/compress.h ../core/acceptencodingparser.h
mkdir.o: ../core/acceptbaseparser.h ../core/htmlfilter.h
mkdir.o: ../core/postmultiparser.h ../core/error.h ../core/data.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/loadavg.h ../core/notify.h
mkdir.o: ../templatesnotify/templatesnotify.h ../core/mount.h
mkdir.o: ../templates/misc.h
mv.o: content.h ../core/item.h ../templates/templates.h
mv.o: ../templates/patterncacher.h ../templates/misc.h
mv.o: ../templates/localefilter.h ../core/locale.h ../confparser/confparser.h
mv.o: ../templates/ckeditorgetparser.h ../core/httpsimpleparser.h
mv.o: ../core/log.h ../core/thread.h ../core/ticket.h ../core/db.h
mv.o: ../core/item.h ../core/user.h ../core/group.h ../core/thread.h
mv.o: ../core/error.h ../core/log.h ../core/dircontainer.h
mv.o: ../core/ugcontainer.h ../core/ticket.h ../core/request.h
mv.o: ../core/requesttypes.h ../core/session.h ../core/rebus.h
mv.o: ../core/plugindata.h ../core/function.h ../core/compress.h
mv.o: ../core/acceptencodingparser.h ../core/acceptbaseparser.h
mv.o: ../core/htmlfilter.h ../core/postmultiparser.h ../core/data.h
mv.o: ../core/dirs.h ../core/users.h ../core/groups.h ../core/functions.h
mv.o: ../core/lastcontainer.h ../core/mounts.h ../core/mount.h
mv.o: ../core/loadavg.h
node.o: content.h ../core/item.h ../templates/templates.h
node.o: ../templates/patterncacher.h ../templates/misc.h
node.o: ../templates/localefilter.h ../core/locale.h
node.o: ../confparser/confparser.h ../templates/ckeditorgetparser.h
node.o: ../core/httpsimpleparser.h ../core/log.h ../core/thread.h
node.o: ../core/ticket.h ../core/db.h ../core/item.h ../core/user.h
node.o: ../core/group.h ../core/thread.h ../core/error.h ../core/log.h
node.o: ../core/dircontainer.h ../core/ugcontainer.h ../core/ticket.h
node.o: ../core/request.h ../core/requesttypes.h ../core/session.h
node.o: ../core/rebus.h ../core/plugindata.h ../core/function.h
node.o: ../core/compress.h ../core/acceptencodingparser.h
node.o: ../core/acceptbaseparser.h ../core/htmlfilter.h
node.o: ../core/postmultiparser.h
priv.o: content.h ../core/item.h ../templates/templates.h
priv.o: ../templates/patterncacher.h ../templates/misc.h
priv.o: ../templates/localefilter.h ../core/locale.h
priv.o: ../confparser/confparser.h ../templates/ckeditorgetparser.h
priv.o: ../core/httpsimpleparser.h ../core/log.h ../core/thread.h
priv.o: ../core/ticket.h ../core/db.h ../core/item.h ../core/user.h
priv.o: ../core/group.h ../core/thread.h ../core/error.h ../core/log.h
priv.o: ../core/dircontainer.h ../core/ugcontainer.h ../core/ticket.h
priv.o: ../core/request.h ../core/requesttypes.h ../core/session.h
priv.o: ../core/rebus.h ../core/plugindata.h ../core/function.h
priv.o: ../core/compress.h ../core/acceptencodingparser.h
priv.o: ../core/acceptbaseparser.h ../core/htmlfilter.h
priv.o: ../core/postmultiparser.h ../core/error.h ../core/data.h
priv.o: ../core/dirs.h ../core/users.h ../core/groups.h ../core/functions.h
priv.o: ../core/lastcontainer.h ../core/mounts.h ../core/mount.h
priv.o: ../core/loadavg.h
reload.o: content.h ../core/item.h ../templates/templates.h
reload.o: ../templates/patterncacher.h ../templates/misc.h
reload.o: ../templates/localefilter.h ../core/locale.h
reload.o: ../confparser/confparser.h ../templates/ckeditorgetparser.h
reload.o: ../core/httpsimpleparser.h ../core/log.h ../core/thread.h
reload.o: ../core/ticket.h ../core/db.h ../core/item.h ../core/user.h
reload.o: ../core/group.h ../core/thread.h ../core/error.h ../core/log.h
reload.o: ../core/dircontainer.h ../core/ugcontainer.h ../core/ticket.h
reload.o: ../core/request.h ../core/requesttypes.h ../core/session.h
reload.o: ../core/rebus.h ../core/plugindata.h ../core/function.h
reload.o: ../core/compress.h ../core/acceptencodingparser.h
reload.o: ../core/acceptbaseparser.h ../core/htmlfilter.h
reload.o: ../core/postmultiparser.h ../core/error.h ../core/notify.h
reload.o: ../templatesnotify/templatesnotify.h ../core/mount.h
reload.o: ../templates/misc.h
rm.o: content.h ../core/item.h ../templates/templates.h
rm.o: ../templates/patterncacher.h ../templates/misc.h
rm.o: ../templates/localefilter.h ../core/locale.h ../confparser/confparser.h
rm.o: ../templates/ckeditorgetparser.h ../core/httpsimpleparser.h
rm.o: ../core/log.h ../core/thread.h ../core/ticket.h ../core/db.h
rm.o: ../core/item.h ../core/user.h ../core/group.h ../core/thread.h
rm.o: ../core/error.h ../core/log.h ../core/dircontainer.h
rm.o: ../core/ugcontainer.h ../core/ticket.h ../core/request.h
rm.o: ../core/requesttypes.h ../core/session.h ../core/rebus.h
rm.o: ../core/plugindata.h ../core/function.h ../core/compress.h
rm.o: ../core/acceptencodingparser.h ../core/acceptbaseparser.h
rm.o: ../core/htmlfilter.h ../core/postmultiparser.h ../core/error.h
rm.o: ../core/data.h ../core/dirs.h ../core/users.h ../core/groups.h
rm.o: ../core/functions.h ../core/lastcontainer.h ../core/mounts.h
rm.o: ../core/mount.h ../core/loadavg.h
run.o: content.h ../core/item.h ../templates/templates.h
run.o: ../templates/patterncacher.h ../templates/misc.h
run.o: ../templates/localefilter.h ../core/locale.h
run.o: ../confparser/confparser.h ../templates/ckeditorgetparser.h
run.o: ../core/httpsimpleparser.h ../core/log.h ../core/thread.h
run.o: ../core/ticket.h ../core/db.h ../core/item.h ../core/user.h
run.o: ../core/group.h ../core/thread.h ../core/error.h ../core/log.h
run.o: ../core/dircontainer.h ../core/ugcontainer.h ../core/ticket.h
run.o: ../core/request.h ../core/requesttypes.h ../core/session.h
run.o: ../core/rebus.h ../core/plugindata.h ../core/function.h
run.o: ../core/compress.h ../core/acceptencodingparser.h
run.o: ../core/acceptbaseparser.h ../core/htmlfilter.h
run.o: ../core/postmultiparser.h ../core/error.h
subject.o: content.h ../core/item.h ../templates/templates.h
subject.o: ../templates/patterncacher.h ../templates/misc.h
subject.o: ../templates/localefilter.h ../core/locale.h
subject.o: ../confparser/confparser.h ../templates/ckeditorgetparser.h
subject.o: ../core/httpsimpleparser.h ../core/log.h ../core/thread.h
subject.o: ../core/ticket.h ../core/db.h ../core/item.h ../core/user.h
subject.o: ../core/group.h ../core/thread.h ../core/error.h ../core/log.h
subject.o: ../core/dircontainer.h ../core/ugcontainer.h ../core/ticket.h
subject.o: ../core/request.h ../core/requesttypes.h ../core/session.h
subject.o: ../core/rebus.h ../core/plugindata.h ../core/function.h
subject.o: ../core/compress.h ../core/acceptencodingparser.h
subject.o: ../core/acceptbaseparser.h ../core/htmlfilter.h
subject.o: ../core/postmultiparser.h
thread.o: content.h ../core/item.h ../templates/templates.h
thread.o: ../templates/patterncacher.h ../templates/misc.h
thread.o: ../templates/localefilter.h ../core/locale.h
thread.o: ../confparser/confparser.h ../templates/ckeditorgetparser.h
thread.o: ../core/httpsimpleparser.h ../core/log.h ../core/thread.h
thread.o: ../core/ticket.h ../core/db.h ../core/item.h ../core/user.h
thread.o: ../core/group.h ../core/thread.h ../core/error.h ../core/log.h
thread.o: ../core/dircontainer.h ../core/ugcontainer.h ../core/ticket.h
thread.o: ../core/request.h ../core/requesttypes.h ../core/session.h
thread.o: ../core/rebus.h ../core/plugindata.h ../core/function.h
thread.o: ../core/compress.h ../core/acceptencodingparser.h
thread.o: ../core/acceptbaseparser.h ../core/htmlfilter.h
thread.o: ../core/postmultiparser.h ../core/data.h ../core/dirs.h
thread.o: ../core/users.h ../core/groups.h ../core/functions.h
thread.o: ../core/lastcontainer.h ../core/mounts.h ../core/mount.h
thread.o: ../core/loadavg.h ../core/mount.h
ticket.o: content.h ../core/item.h ../templates/templates.h
ticket.o: ../templates/patterncacher.h ../templates/misc.h
ticket.o: ../templates/localefilter.h ../core/locale.h
ticket.o: ../confparser/confparser.h ../templates/ckeditorgetparser.h
ticket.o: ../core/httpsimpleparser.h ../core/log.h ../core/thread.h
ticket.o: ../core/ticket.h ../core/db.h ../core/item.h ../core/user.h
ticket.o: ../core/group.h ../core/thread.h ../core/error.h ../core/log.h
ticket.o: ../core/dircontainer.h ../core/ugcontainer.h ../core/ticket.h
ticket.o: ../core/request.h ../core/requesttypes.h ../core/session.h
ticket.o: ../core/rebus.h ../core/plugindata.h ../core/function.h
ticket.o: ../core/compress.h ../core/acceptencodingparser.h
ticket.o: ../core/acceptbaseparser.h ../core/htmlfilter.h
ticket.o: ../core/postmultiparser.h ../core/data.h ../core/dirs.h
ticket.o: ../core/users.h ../core/groups.h ../core/functions.h
ticket.o: ../core/lastcontainer.h ../core/mounts.h ../core/mount.h
ticket.o: ../core/loadavg.h ../core/mount.h
uname.o: content.h ../core/item.h ../templates/templates.h
uname.o: ../templates/patterncacher.h ../templates/misc.h
uname.o: ../templates/localefilter.h ../core/locale.h
uname.o: ../confparser/confparser.h ../templates/ckeditorgetparser.h
uname.o: ../core/httpsimpleparser.h ../core/log.h ../core/thread.h
uname.o: ../core/ticket.h ../core/db.h ../core/item.h ../core/user.h
uname.o: ../core/group.h ../core/thread.h ../core/error.h ../core/log.h
uname.o: ../core/dircontainer.h ../core/ugcontainer.h ../core/ticket.h
upload.o: content.h ../core/item.h ../templates/templates.h
upload.o: ../templates/patterncacher.h ../templates/misc.h
upload.o: ../templates/localefilter.h ../core/locale.h
upload.o: ../confparser/confparser.h ../templates/ckeditorgetparser.h
upload.o: ../core/httpsimpleparser.h ../core/log.h ../core/thread.h
upload.o: ../core/ticket.h ../core/db.h ../core/item.h ../core/user.h
upload.o: ../core/group.h ../core/thread.h ../core/error.h ../core/log.h
upload.o: ../core/dircontainer.h ../core/ugcontainer.h ../core/ticket.h
upload.o: ../core/request.h ../core/requesttypes.h ../core/session.h
upload.o: ../core/rebus.h ../core/plugindata.h ../core/function.h
upload.o: ../core/compress.h ../core/acceptencodingparser.h
upload.o: ../core/acceptbaseparser.h ../core/htmlfilter.h
upload.o: ../core/postmultiparser.h ../core/data.h ../core/dirs.h
upload.o: ../core/users.h ../core/groups.h ../core/functions.h
upload.o: ../core/lastcontainer.h ../core/mounts.h ../core/mount.h
upload.o: ../core/loadavg.h ../core/misc.h
who.o: content.h ../core/item.h ../templates/templates.h
who.o: ../templates/patterncacher.h ../templates/misc.h
who.o: ../templates/localefilter.h ../core/locale.h
who.o: ../confparser/confparser.h ../templates/ckeditorgetparser.h
who.o: ../core/httpsimpleparser.h ../core/log.h ../core/thread.h
who.o: ../core/ticket.h ../core/db.h ../core/item.h ../core/user.h
who.o: ../core/group.h ../core/thread.h ../core/error.h ../core/log.h
who.o: ../core/dircontainer.h ../core/ugcontainer.h ../core/ticket.h

View File

@@ -1 +0,0 @@
o = adduser.o cat.o content.o createthread.o createticket.o default.o download.o editticket.o emacs.o last.o login.o logout.o ls.o misc_item.o misc_specialfile.o mkdir.o mv.o node.o priv.o reload.o rm.o run.o subject.o thread.o ticket.o uname.o upload.o who.o

View File

@@ -1,111 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "content.h"
#include "../core/request.h"
#include "../core/data.h"
#include "../core/db.h"
bool Content::CheckAddUserVars(const std::string * login, const std::string * pass, const std::string * conf_pass)
{
if( !login || !pass || !conf_pass )
{
request.status = WINIX_ERR_PERMISSION_DENIED;
return false;
}
if( login->empty() )
{
request.status = WINIX_ERR_LOGIN_EMPTY;
return false;
}
if( *pass != *conf_pass )
{
request.status = WINIX_ERR_PASSWORDS_DIFFERENT;
return false;
}
if( pass->size() < 5 )
{
request.status = WINIX_ERR_PASSWORD_TOO_SHORT;
return false;
}
if( data.users.IsUser(*login) )
{
request.status = WINIX_ERR_USER_EXISTS;
return false;
}
return true;
}
void Content::PostFunAddUser()
{
User user;
std::string * login = request.PostVar("login");
std::string * pass = request.PostVar("password");
std::string * conf_pass = request.PostVar("confirmpassword");
std::string * email = request.PostVar("email");
if( !CheckAddUserVars(login, pass, conf_pass) )
return;
user.name = *login;
if( email )
user.email = *email;
request.status = db.AddUser(user, *pass);
if( request.status == WINIX_ERR_OK )
{
if( data.users.AddUser(user) )
{
if( !request.session->puser )
LoginUser(user.id, false);
log << log2 << "Content: added a new user: " << user.name << logend;
}
else
{
log << log1 << "Content: I can't add to data.users: " << user.name
<< " but the user was added to the db correctly" << logend;
}
if( request.is_item )
RedirectTo(request.item);
else
RedirectToLastDir();
}
}
void Content::FunAddUser()
{
}

View File

@@ -1,37 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "content.h"
#include "../core/request.h"
#include "../core/error.h"
#include "../core/data.h"
void Content::FunCat()
{
if( !request.is_item )
{
log << log1 << "Content: cat function requires an item" << logend;
request.status = WINIX_ERR_NO_ITEM;
return;
}
if( !request.HasReadAccess(request.item) )
{
request.status = WINIX_ERR_PERMISSION_DENIED;
return;
}
request.send_as_attachment = request.IsParam("attachment");
}

View File

@@ -1,633 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "content.h"
#include "../core/request.h"
#include "../core/error.h"
#include "../core/db.h"
#include "../core/data.h"
#include "../core/misc.h"
#include "../core/plugin.h"
bool Content::Init()
{
templates.ReadTemplates();
templates.CreateFunctions();
return true;
}
bool Content::DirsHaveReadExecPerm()
{
std::vector<Item*>::iterator i;
for(i = request.dir_table.begin() ; i!=request.dir_table.end() ; ++i)
{
if( !request.HasReadExecAccess(**i) )
return false;
}
return true;
}
void Content::SetDefaultFunctionForFile()
{
if( request.item.auth != Item::auth_none )
request.pfunction = data.functions.GetFunction(FUN_DOWNLOAD);
else
if( request.HasReadExecAccess(request.item) )
request.pfunction = data.functions.GetFunction(FUN_RUN);
else
request.pfunction = data.functions.GetFunction(FUN_CAT);
if( request.pfunction )
log << log3 << "Content: default function: " << request.pfunction->item.url << logend;
}
void Content::SetDefaultFunctionForDir()
{
long default_item = request.dir_table.back()->default_item;
if( default_item != -1 )
{
log << log3 << "Content: Default item: id: " << default_item << logend;
RedirectTo(default_item);
return;
}
if( data.mounts.pmount->type == Mount::thread )
{
request.pfunction = data.functions.GetFunction(FUN_THREAD);
if( request.pfunction )
log << log3 << "Content: default function: " << request.pfunction->item.url << logend;
}
else
if( data.mounts.pmount->type == Mount::ticket )
{
request.pfunction = data.functions.GetFunction(FUN_TICKET);
if( request.pfunction )
log << log3 << "Content: default function: " << request.pfunction->item.url << logend;
}
else
{
// cms
request.pfunction = data.functions.GetFunction(FUN_LS);
if( request.pfunction )
log << log3 << "Content: default function: " << request.pfunction->item.url << logend;
}
}
void Content::SetDefaultFunction()
{
if( request.is_item )
{
SetDefaultFunctionForFile();
}
else
{
SetDefaultFunctionForDir();
}
}
void Content::MakeStandardFunction()
{
if( request.role == Request::authorizer )
{
// in authorizer mode only cat function is available
// (and must be default)
if( request.pfunction )
{
request.status = WINIX_ERR_NO_ITEM;
log << log1 << "Content: in authorizer mode only 'cat' funtion is available and must "
"be default (not in the url)" << logend;
return;
}
request.pfunction = data.functions.GetFunction(FUN_CAT);
}
if( !request.pfunction )
SetDefaultFunction();
if( !request.redirect_to.empty() )
return;
if( !request.pfunction )
{
request.status = WINIX_ERR_NO_FUNCTION;
log << log1 << "Content: no function (neither cat nor ls)" << logend;
return;
}
if( request.pfunction->code == FUN_LOGOUT )
FunLogout();
else
if( request.pfunction->code == FUN_CAT )
FunCat();
else
if( request.pfunction->code == FUN_LS )
FunLs();
else
if( request.pfunction->code == FUN_EMACS )
FunEmacs();
else
if( request.pfunction->code == FUN_MKDIR )
FunMkdir();
else
if( request.pfunction->code == FUN_DEFAULT )
FunDefault();
else
if( request.pfunction->code == FUN_PRIV )
FunPriv();
else
if( request.pfunction->code == FUN_RM )
FunRm();
else
if( request.pfunction->code == FUN_RUN )
FunRun();
else
if( request.pfunction->code == FUN_NODE )
FunNode();
else
if( request.pfunction->code == FUN_WHO )
FunWho();
else
if( request.pfunction->code == FUN_LAST )
FunLast();
else
if( request.pfunction->code == FUN_THREAD )
FunThread();
else
if( request.pfunction->code == FUN_RELOAD )
FunReload();
else
if( request.pfunction->code == FUN_CREATETHREAD )
FunCreateThread();
else
if( request.pfunction->code == FUN_UPLOAD )
FunUpload();
else
if( request.pfunction->code == FUN_CREATETICKET )
FunCreateTicket();
else
if( request.pfunction->code == FUN_EDITTICKET )
FunEditTicket();
else
if( request.pfunction->code == FUN_TICKET )
FunTicket();
else
if( request.pfunction->code == FUN_CKEDITOR )
FunEmacs();
else
if( request.pfunction->code == FUN_LOGIN )
FunLogin();
else
if( request.pfunction->code == FUN_UPTIME )
{ /* do nothing */ }
else
if( request.pfunction->code == FUN_MV )
FunMv();
else
if( request.pfunction->code == FUN_UNAME )
FunUname();
else
if( request.pfunction->code == FUN_CHMOD )
FunPriv();
else
if( request.pfunction->code == FUN_CHOWN )
FunPriv();
else
if( request.pfunction->code == FUN_DOWNLOAD )
FunDownload();
else
if( request.pfunction->code == FUN_ADDUSER )
FunAddUser();
else
if( request.pfunction->code == FUN_SUBJECT )
FunSubject();
else
request.status = WINIX_ERR_PERMISSION_DENIED;
}
void Content::MakePost()
{
if( request.role == Request::authorizer )
{
request.status = WINIX_ERR_PERMISSION_DENIED;
return;
}
if( !request.pfunction )
SetDefaultFunction();
if( !request.pfunction )
{
request.status = WINIX_ERR_NO_FUNCTION;
log << log1 << "Content: MakePost: no function" << logend;
return;
}
switch( request.pfunction->code )
{
case FUN_RUN:
PostFunRun();
break;
case FUN_EMACS:
PostFunEmacs();
break;
case FUN_MKDIR:
PostFunMkdir();
break;
case FUN_DEFAULT:
PostFunDefault();
break;
case FUN_PRIV:
case FUN_CHMOD:
case FUN_CHOWN:
PostFunPriv();
break;
case FUN_LOGIN:
PostFunLogin();
break;
case FUN_CREATETHREAD:
PostFunCreateThread();
break;
case FUN_UPLOAD:
PostFunUpload();
break;
case FUN_CREATETICKET:
PostFunCreateTicket();
break;
case FUN_EDITTICKET:
PostFunEditTicket();
break;
case FUN_CKEDITOR:
PostFunEmacs();
break;
case FUN_ADDUSER:
PostFunAddUser();
break;
case FUN_MV:
PostFunMv();
break;
case FUN_SUBJECT:
PostFunSubject();
break;
default:
log << log1 << "Content: unknown post function" << logend;
break;
}
}
void Content::MakePage()
{
bool sent = false;
if( !request.redirect_to.empty() ||
!request.x_sendfile.empty() )
return;
if( request.is_item && request.item.auth == Item::auth_none &&
request.item.content_type == Item::ct_raw && request.status == WINIX_ERR_OK && request.pfunction )
{
if( request.pfunction->code == FUN_CAT )
{
request.page << request.item.content;
sent = true;
}
else
if( request.pfunction->code == FUN_RUN )
{
templates.GenerateRunRaw();
sent = true;
}
}
if( !sent )
{
templates.Generate();
}
}
void Content::Make()
{
if( request.dir_table.empty() )
{
log << log1 << "Content: there is no a root dir (dir_table is empty)" << logend;
return;
}
// request.status can be changed by function_parser
if( request.status == WINIX_ERR_OK )
{
if( DirsHaveReadExecPerm() )
{
if( request.method == Request::post )
MakePost();
if( request.redirect_to.empty() && request.status == WINIX_ERR_OK )
MakeStandardFunction();
}
else
request.status = WINIX_ERR_PERMISSION_DENIED;
}
if( request.session->spam_score > 0 )
log << log1 << "Content: spam score: " << request.session->spam_score << logend;
if( request.IsParam("noredirect") )
request.redirect_to.clear();
if( !request.redirect_to.empty() )
return;
if( request.dir_table.empty() )
{
log << log1 << "Content: there is no a root dir (dir_table is empty -- after calling some standard functions)" << logend;
return;
}
plugin.Call(WINIX_CONTENT_MAKE);
MakePage();
//request.PrintGetTable();
//request.PrintEnv();
//request.PrintIn();
}
// !! mozna zrobic jakas obsluge kiedy nie mozemy sie redirectnac, np gdy wystapil blad
// !! moze zwracac jakas wartosc?
void Content::RedirectTo(const Item & item, const char * postfix)
{
std::string path;
request.redirect_to = data.base_url;
if( item.type == Item::dir )
{
// item_id is pointing to a directory
data.dirs.MakePath(item.id, path);
request.redirect_to += path;
}
else
{
if( !data.dirs.MakePath(item.parent_id, path) )
log << log1 << "Content: Can't redirect: no dirs for item id: " << item.id << logend;
request.redirect_to += path;
request.redirect_to += item.url;
}
if( postfix )
request.redirect_to += postfix;
}
void Content::RedirectTo(long item_id, const char * postfix)
{
std::string path;
Item * pdir;
request.redirect_to = data.base_url;
pdir = data.dirs.GetDir(item_id);
if( pdir )
{
// item_id is pointing to a directory
data.dirs.MakePath(pdir->id, path);
request.redirect_to += path;
}
else
{
// !! zrobic nowy interfejs
// !! GetItem pozamieniac na GetFile
db.GetItem(request.item_table, item_id);
if( !request.item_table.empty() )
{
if( !data.dirs.MakePath(request.item_table[0].parent_id, path) )
log << log1 << "Content: Can't redirect: no dirs for item id: " << request.item_table[0].id << ", requested directory id: " << request.item_table[0].parent_id << logend;
request.redirect_to += path + request.item_table[0].url;
}
else
{
log << log1 << "Content: Can't redirect: no such item: id: " << item_id << logend;
}
}
if( postfix )
request.redirect_to += postfix;
}
void Content::RedirectToLastDir()
{
RedirectTo( *request.dir_table.back() );
}
void Content::ReadAdditionalInfo()
{
if( request.dir_table.empty() )
return;
if( data.mounts.pmount->type == Mount::thread )
{
if( db.GetThreadByDirId(request.dir_table.back()->id, request.thread) == WINIX_ERR_OK )
request.is_thread = true;
}
else
if( data.mounts.pmount->type == Mount::ticket )
{
if( db.GetTicketByDirId(request.dir_table.back()->id, request.ticket) == WINIX_ERR_OK )
{
request.is_ticket = true;
if( !request.is_item && (!request.pfunction || request.pfunction->code == FUN_TICKET) )
{
db.GetItemById(request.ticket.item_id, request.item);
// don't set request.is_item here
}
}
}
}
void Content::PrepareUrl(Item & item)
{
TrimWhite(item.url);
if( item.url.empty() )
item.url = item.subject; // if the subject is empty then the url will be corrected by CorrectUrlOnlyAllowedChar()
CorrectUrlOnlyAllowedChar(item.url);
if( data.functions.GetFunction(item.url) )
{
// the name provided by an user is the same as a name of a function
// we add one underscore character at the beginning
// names of functions should not begin with an underscore '_'
// and we can simply add one '_' at the beginning
// and the name will be unique
item.url.insert(item.url.begin(), '_');
}
}
bool Content::CheckRebus()
{
if( request.session->puser )
// logged user don't have to use the rebus
return true;
if( request.session->rebus_checked )
return true;
request.session->rebus_checked = true;
if( !request.session->rebus_item )
{
log << log1 << "Content: rebus not set" << logend;
return false;
}
try
{
std::string * answer = request.PostVar("rebus");
if( answer && data.rebus.IsAnswerOk(request.session->rebus_item, *answer) )
return true;
}
catch(const Error &)
{
}
log << log1 << "Content: rebus has an incorrect answer" << logend;
// don't add request.session->spam_score when the rebus has incorrect answer
// a user could have made a mistake
return false;
}
void Content::SetUser(Item & item)
{
if( request.session->puser )
{
item.user_id = request.session->puser->id;
item.guest_name.clear();
}
else
{
item.user_id = -1;
request.PostVar("guestname", item.guest_name);
}
}
void Content::CheckGetPostTimes(time_t difference)
{
time_t now = std::time(0);
if( request.session->puser )
return;
if( request.method != Request::post )
return;
if( now - request.session->last_time_get >= (time_t)difference )
return;
if( request.AllPostVarEmpty() )
return;
request.session->spam_score += 1;
log << log1 << "Content: spam +1: POST after GET sent too fast" << logend;
}
/*
bool Content::CreateFile(const std::string & path, const std::string & content)
{
std::ofstream file(path.c_str(), std::ios_base::binary | std::ios_base::out);
if( !file )
{
log << log1 << "Content: can't create file: " << path << logend;
return false;
}
file << content;
file.close();
// !! dodac sprawdzenie prawidlowosci zapisania pliku
return true;
}
*/

View File

@@ -1,248 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslucontentcontent
#define headerfilecmslucontentcontent
#include <cstdlib>
#include <fcgiapp.h>
#include <ctime>
#include "../core/item.h"
#include "../templates/templates.h"
#include "../core/thread.h"
#include "../core/ticket.h"
#include "../core/db.h"
class Content
{
Templates templates;
std::string temp;
void FunDownload();
void CheckSpecialFile();
void PrepareUrl(Item & item);
bool CheckAddUserVars(const std::string * login, const std::string * pass, const std::string * conf_pass);
void PostFunAddUser();
void FunAddUser();
/*
mv
*/
bool MoveIsTheSameFile(const Item & item);
void MoveAuth(Item & item);
void MoveFile(Item & item, bool redirect = true);
void MoveDir(Item & item, bool redirect = true);
void MoveAuthPrepareQuery();
void MoveAuthContentOfDir(const Item & item);
bool MoveParseDir(long & dir_id, std::string & dir, std::string & file);
bool MoveCheckAccessFromToDir();
bool MoveCheckAccessFrom();
bool MoveCheckAccessTo(long dir_id);
bool MoveCheckMountPoints(long dir_id);
void MoveContentOfDir();
void PostFunMv();
void FunMv();
std::string mv_dir;
std::string mv_file;
std::string mv_new_path;
long mv_dir_id;
std::vector<Item> mv_auth;
Db::ItemQuery mv_auth_iq;
void SetDefaultFunctionForFile();
void SetDefaultFunctionForDir();
void SetDefaultFunction();
bool DirsHaveReadExecPerm();
void MakeStandardFunction();
void SetUser(Item & item);
bool CheckRebus();
void MakePost();
void FunCat();
void FunLogout();
void FunLs();
void FunEmacs();
void AddPathToAuth(std::string & path);
void FunCKEditor();
void FunUname();
bool SubjectCheckAccess();
void EditDirSubject();
void EditFileSubject();
void PostFunSubject();
void FunSubject();
/*
rm
*/
bool RemoveCheckAccess();
void RemoveAllDirs();
void RemoveAllDirs(long dir_id);
void RemoveDir();
void RemoveAuthPrepareQuery();
void RemoveAuth(Item & item);
void RemoveFile();
void FunRm();
Db::ItemQuery rm_auth_iq;
void FunNode();
void FunMkdir();
void FunDefault();
void FunRun();
void PostFunRun();
void FunWho();
void FunLast();
void FunReloadTemplates();
void FunReload();
static bool FunThreadSort(const Thread & t1, const Thread & t2);
void FunThread();
void FunCreateThread();
bool FunUploadCheckAccess();
void FunUpload();
bool ReadItemUrlSubject(Item & item, Item::Type item_type);
bool ReadItem(Item & item, Item::Type item_type);
void CheckAccessToItems();
void LoginUser(long user_id, bool remember_me);
void FunLogin();
void PostFunLogin();
void ReadItemContentWithType(Item & item);
bool FunEmacsCheckAccess();
void PostFunEmacsAdd();
void PostFunEmacsEdit(bool with_url);
bool PostEmacsCheckAbuse(bool adding);
void PostFunEmacsModifyMountPoint(bool adding);
void PostFunEmacs();
bool FunMkdirCheckAccess();
void PostFunMkdir(bool add_to_dir_table = false, int privileges = 0755 );
void Mkdir(Item & item, bool add_to_dir_table);
long PostFunDefaultParsePath();
void PostFunDefault();
/*
function: priv, chmod, chown
*/
bool PrivCheckAccess();
void PrivLogStart(const char * what, long user, long group, int priv);
void PrivLog(const char * what, long id, const std::string & url);
bool ChangeOwner(Item & item, long user_id, long group_id);
bool ChangePrivileges(Item & item, int privileges);
void ChangePriv(Item & item, long user_id, long group_id, int privileges);
void PostFunPriv();
void PrivFilesInDir(long parent_id);
void PrivDir(long parent_id);
bool ReadPriv(const char * user_in, const char * group_in, const char * priv_in, long & user_id, long & group_id, int & priv);
void PrivDir();
void PrivOneItem();
void FunPriv();
long user_id_file, group_id_file, user_id_dir, group_id_dir;
int priv_file, priv_dir;
bool subdirectories;
bool change_owner, change_priv;
bool FunCreateThreadCheckAccess();
bool FunCreateThreadCheckAbuse();
void ReadThread(Thread & thread);
void AddThread();
void PostFunCreateThreadLogAndRedirect();
void PostFunCreateThread();
bool UploadCreatePath();
void UploadSaveFile(const std::string & tmp_filename, const std::string & destination);
void UploadMulti();
void UploadSingle();
bool FunUploadCheckAbuse();
void PostFunUpload();
bool FunCreateTicketCheckAccess();
void FunCreateTicket();
bool FunCreateTicketCheckAbuse();
void PostFunCreateTicketLogAndRedirect();
void PostFunCreateTicket();
void FunTicket();
void TicketDeleteFirst();
bool FunEditTicketCheckAccess();
void PostFunEditTicketLogAndRedirect();
void EditTicketCheckFirstItem();
void EditTicketModTicket();
void EditTicketModDir();
void EditTicketModFirstItem();
void PostFunEditTicket();
void FunEditTicket();
void AddTicket();
void ReadTicket(Ticket & ticket);
void ReadTicketType(Ticket & ticket);
void ReadTicketStatus(Ticket & ticket);
void ReadTicketPriority(Ticket & ticket);
void ReadTicketCategory(Ticket & ticket);
void ReadTicketExpected(Ticket & ticket);
void ReadTicketProgress(Ticket & ticket);
void RedirectTo(const Item & item, const char * postfix = 0);
void RedirectTo(long item_id, const char * postfix = 0);
void RedirectToLastDir();
void CheckGetPostTimes(time_t difference = 10);
// bool CreateFile(const std::string & path, const std::string & content);
void MakePage();
public:
bool Init();
void ReadAdditionalInfo();
void Make();
};
#endif

View File

@@ -1,136 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "content.h"
#include "../core/request.h"
#include "../core/error.h"
#include "../core/db.h"
#include "../core/mount.h"
#include "../core/data.h"
bool Content::FunCreateThreadCheckAccess()
{
if( !request.CanCreateThread() )
{
request.status = WINIX_ERR_PERMISSION_DENIED;
return false;
}
return true;
}
bool Content::FunCreateThreadCheckAbuse()
{
if( !CheckRebus() )
{
request.status = WINIX_ERR_INCORRECT_REBUS;
return false;
}
CheckGetPostTimes();
if( request.session->spam_score > 0 )
{
request.status = WINIX_ERR_SPAM;
log << log1 << "Content: ignoring due to suspected spamming" << logend;
return false;
}
return true;
}
void Content::ReadThread(Thread & thread)
{
thread.parent_id = request.dir_table.back()->id;
}
void Content::AddThread()
{
request.thread.dir_id = request.dir_table.back()->id;
request.thread.closed = false;
request.thread.items = 1;
request.thread.last_item = request.item; // set by PostFunEmacsAdd()
request.status = db.AddThread(request.thread);
}
void Content::PostFunCreateThreadLogAndRedirect()
{
if( request.status == WINIX_ERR_OK )
{
log << log2 << "Content: added a new thread" << logend;
RedirectToLastDir();
}
else
{
log << log1 << "Content: problem with adding a new thread, error code: "
<< request.status << logend;
}
}
void Content::PostFunCreateThread()
{
if( !FunCreateThreadCheckAccess() )
return;
ReadItem(request.item, Item::dir);
ReadThread(request.thread);
request.item.privileges = 0777; // !! tymczasowo 777 aby wszyscy mogli wysylac posty
if( !FunCreateThreadCheckAbuse() )
{
ReadItemContentWithType(request.item); // for correctly displaying the form
return;
}
Mkdir(request.item, true);
if( request.status == WINIX_ERR_OK )
{
ReadItemContentWithType(request.item);
request.item.type = Item::file;
request.item.privileges = 0644; // !! tymczasowo
request.item.parent_id = request.dir_table.back()->id;
PostFunEmacsAdd();
if( request.status == WINIX_ERR_OK )
AddThread();
}
PostFunCreateThreadLogAndRedirect();
}
void Content::FunCreateThread()
{
FunCreateThreadCheckAccess();
}

View File

@@ -1,221 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "content.h"
#include "../core/request.h"
#include "../core/error.h"
#include "../core/db.h"
#include "../core/mount.h"
#include "../core/data.h"
bool Content::FunCreateTicketCheckAccess()
{
if( !request.CanCreateTicket() )
{
request.status = WINIX_ERR_PERMISSION_DENIED;
return false;
}
return true;
}
bool Content::FunCreateTicketCheckAbuse()
{
if( !CheckRebus() )
{
request.status = WINIX_ERR_INCORRECT_REBUS;
return false;
}
CheckGetPostTimes();
if( request.session->spam_score > 0 )
{
request.status = WINIX_ERR_SPAM;
log << log1 << "Content: ignoring due to suspected spamming" << logend;
return false;
}
return true;
}
void Content::ReadTicketType(Ticket & ticket)
{
static std::string temp;
request.PostVar("type", temp);
ticket.type = atoi(temp.c_str());
if( ticket.type >= data.mounts.pmount->param[Mount::par_ticket_type].arg.size() )
ticket.type = data.mounts.pmount->param[Mount::par_ticket_type].arg.size();
}
void Content::ReadTicketStatus(Ticket & ticket)
{
static std::string temp;
request.PostVar("status", temp);
ticket.status = atoi(temp.c_str());
if( ticket.status >= data.mounts.pmount->param[Mount::par_ticket_status].arg.size() )
ticket.status = data.mounts.pmount->param[Mount::par_ticket_status].arg.size();
}
void Content::ReadTicketPriority(Ticket & ticket)
{
static std::string temp;
request.PostVar("priority", temp);
ticket.priority = atoi(temp.c_str());
if( ticket.priority >= data.mounts.pmount->param[Mount::par_ticket_priority].arg.size() )
ticket.priority = data.mounts.pmount->param[Mount::par_ticket_priority].arg.size();
}
void Content::ReadTicketCategory(Ticket & ticket)
{
static std::string temp;
request.PostVar("category", temp);
ticket.category = atoi(temp.c_str());
if( ticket.category >= data.mounts.pmount->param[Mount::par_ticket_category].arg.size() )
ticket.category = data.mounts.pmount->param[Mount::par_ticket_category].arg.size();
}
void Content::ReadTicketExpected(Ticket & ticket)
{
static std::string temp;
request.PostVar("expected", temp);
ticket.expected = atoi(temp.c_str());
if( ticket.expected >= data.mounts.pmount->param[Mount::par_ticket_expected].arg.size() )
ticket.expected = data.mounts.pmount->param[Mount::par_ticket_expected].arg.size();
}
void Content::ReadTicketProgress(Ticket & ticket)
{
static std::string temp;
request.PostVar("progress", temp);
int p = atoi(temp.c_str());
if( p < 0 )
p = 0;
if( p > 100 )
p = 100;
ticket.progress = p;
}
void Content::ReadTicket(Ticket & ticket)
{
ticket.parent_id = request.dir_table.back()->id;
ReadTicketType(ticket);
ReadTicketStatus(ticket);
ReadTicketPriority(ticket);
ReadTicketCategory(ticket);
ReadTicketExpected(ticket);
ReadTicketProgress(ticket);
}
void Content::AddTicket()
{
static std::string temp;
request.ticket.dir_id = request.dir_table.back()->id; // a new directory created by Mkdir()
request.ticket.item_id = request.item.id; // this id is set by PostFunEmacsAdd()
request.status = db.AddTicket(request.ticket);
}
void Content::PostFunCreateTicketLogAndRedirect()
{
if( request.status == WINIX_ERR_OK )
{
log << log2 << "Content: added a new ticket" << logend;
RedirectToLastDir();
}
else
{
log << log1 << "Content: problem with adding a new ticket, error code: "
<< request.status << logend;
}
}
void Content::PostFunCreateTicket()
{
if( !FunCreateTicketCheckAccess() )
return;
ReadItem(request.item, Item::dir);
ReadTicket(request.ticket);
request.item.privileges = 0777; // !! tymczasowo 777 aby wszyscy mogli wysylac posty
if( !FunCreateTicketCheckAbuse() )
{
ReadItemContentWithType(request.item); // for correctly displaying the form
return;
}
Mkdir(request.item, true);
if( request.status == WINIX_ERR_OK )
{
ReadItemContentWithType(request.item);
request.item.type = Item::file;
request.item.privileges = 0644; // !! tymczasowo
request.item.parent_id = request.dir_table.back()->id;
PostFunEmacsAdd();
if( request.status == WINIX_ERR_OK )
AddTicket();
}
PostFunCreateTicketLogAndRedirect();
}
void Content::FunCreateTicket()
{
FunCreateTicketCheckAccess();
}

View File

@@ -1,110 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "content.h"
#include "../core/request.h"
#include "../core/error.h"
#include "../core/db.h"
#include "../core/data.h"
long Content::PostFunDefaultParsePath()
{
Item * pdir, * pdir2;
long defaultid = -1;
std::string * path = request.PostVar("defaultitem");
if( path && !path->empty() )
{
std::string dir, file;
Dirs::SplitPath(*path, dir, file);
pdir = data.dirs.GetDir(dir);
if( !pdir )
throw Error(WINIX_ERR_INCORRECT_DIR);
if( file.empty() )
{
defaultid = pdir->id;
}
else
{
// checking whether the file is a directory too (the method SplitPath does not check it)
pdir2 = data.dirs.GetDir(file, pdir->id);
if( !pdir2 )
{
defaultid = db.GetFileId(pdir->id, file);
if( defaultid == -1 )
throw Error(WINIX_ERR_NO_ITEM);
}
else
{
// file is a directory
defaultid = pdir2->id;
}
}
}
return defaultid;
}
void Content::PostFunDefault()
{
if( !request.HasWriteAccess(*request.dir_table.back()) )
{
request.status = WINIX_ERR_PERMISSION_DENIED;
return;
}
try
{
long defaultid = PostFunDefaultParsePath();
request.status = db.EditDefaultItem(request.dir_table.back()->id, defaultid);
if( request.status == WINIX_ERR_OK )
request.dir_table.back()->default_item = defaultid;
}
catch(const Error & e)
{
request.status = e;
}
if( request.status == WINIX_ERR_OK )
RedirectTo(*request.dir_table.back());
else
log << log1 << "Content: PostFunDefaultItem: Error: " << request.status << logend;
}
void Content::FunDefault()
{
if( !request.HasWriteAccess(*request.dir_table.back()) )
{
request.status = WINIX_ERR_PERMISSION_DENIED;
return;
}
}

View File

@@ -1,43 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "content.h"
#include "../core/request.h"
#include "../core/data.h"
void Content::FunDownload()
{
// !! moze wywalic to no_item i wszedzie w takich miejscach dac poprostu permission_denied?
if( !request.is_item )
{
log << log1 << "Content: download function requires an item" << logend;
request.status = WINIX_ERR_NO_ITEM;
return;
}
if( !request.HasReadAccess(request.item) ||
request.item.auth == Item::auth_none ||
request.item.auth_path.empty() )
{
request.status = WINIX_ERR_PERMISSION_DENIED;
return;
}
request.send_as_attachment = request.IsParam("attachment");
request.x_sendfile = request.item.auth_path;
}

View File

@@ -1,174 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "content.h"
#include "../core/request.h"
#include "../core/error.h"
#include "../core/db.h"
#include "../core/mount.h"
#include "../core/data.h"
bool Content::FunEditTicketCheckAccess()
{
if( !request.CanEditTicket() )
{
request.status = WINIX_ERR_PERMISSION_DENIED;
return false;
}
return true;
}
void Content::EditTicketCheckFirstItem()
{
if( request.status != WINIX_ERR_OK )
return;
if( request.ticket.item_id == -1 )
{
// creating a new item (the item was deleted by a user)
Item item;
item.parent_id = request.dir_table.back()->id;
item.subject = request.dir_table.back()->subject;
item.type = Item::file;
item.privileges = 0644; // !! tymczasowo
SetUser(item);
PrepareUrl(item);
request.status = db.AddItem(item);
if( request.status == WINIX_ERR_OK )
{
log << log2 << "Content: added the first item with content for the ticket, item.id: " << item.id << logend;
request.ticket.item_id = item.id;
}
}
}
void Content::EditTicketModTicket()
{
if( request.status != WINIX_ERR_OK )
return;
Ticket ticket;
ReadTicket(ticket);
request.ticket.type = ticket.type;
request.ticket.status = ticket.status;
request.ticket.priority = ticket.priority;
request.ticket.category = ticket.category;
request.ticket.expected = ticket.expected;
request.ticket.progress = ticket.progress;
request.status = db.EditTicketById(request.ticket);
}
void Content::EditTicketModDir()
{
if( request.status != WINIX_ERR_OK )
return;
// we don't modify the url
Item & dir = *request.dir_table.back();
bool edit_dir_subject = (dir.subject != request.item.subject);
if( edit_dir_subject )
{
dir.subject = request.item.subject;
request.status = db.EditItemById(dir, false);
}
}
void Content::EditTicketModFirstItem()
{
if( request.status != WINIX_ERR_OK )
return;
// modyfing the first item (the one with content)
ReadItemContentWithType(request.item);
Item item;
db.GetItemById(request.ticket.item_id, item);
item.subject = request.item.subject;
item.content = request.item.content;
item.content_type = request.item.content_type;
// the url doesn't matter
db.EditItemById(item, false);
}
void Content::PostFunEditTicketLogAndRedirect()
{
if( request.status == WINIX_ERR_OK )
{
log << log2 << "Content: edited a ticket" << logend;
RedirectToLastDir();
}
else
{
log << log1 << "Content: problem with editing a ticket, error code: "
<< request.status << logend;
}
}
void Content::PostFunEditTicket()
{
if( !FunEditTicketCheckAccess() )
return;
ReadItem(request.item, Item::dir);
if( !FunCreateTicketCheckAbuse() )
{
ReadItemContentWithType(request.item); // for correctly displaying the form
return;
}
if( db.GetTicketByDirId(request.dir_table.back()->id, request.ticket) != WINIX_ERR_OK )
{
request.status = WINIX_ERR_PERMISSION_DENIED;
return;
}
EditTicketCheckFirstItem();
EditTicketModTicket();
EditTicketModDir();
EditTicketModFirstItem();
PostFunEditTicketLogAndRedirect();
}
void Content::FunEditTicket()
{
FunEditTicketCheckAccess();
db.GetItemById(request.ticket.item_id, request.item);
// the subject we get from the last directory
request.item.subject = request.dir_table.back()->subject;
}

View File

@@ -1,162 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "content.h"
#include "../core/request.h"
#include "../core/error.h"
#include "../core/db.h"
#include "../core/data.h"
#include "../core/notify.h"
#include "../core/misc.h"
bool Content::FunEmacsCheckAccess()
{
if( !request.is_item )
{
// adding a new item
if( !request.CanUseEmacs(*request.dir_table.back()) )
{
request.status = WINIX_ERR_PERMISSION_DENIED;
return false;
}
}
else // editing an existing item
if( !request.CanUseEmacs(request.item) )
{
request.status = WINIX_ERR_PERMISSION_DENIED;
return false;
}
return true;
}
void Content::PostFunEmacsAdd()
{
request.status = db.AddItem(request.item);
if( request.status == WINIX_ERR_OK )
{
log << log2 << "Content: added a new item" << logend;
request.notify_code |= WINIX_NOTIFY_ITEM_ADD;
}
}
void Content::PostFunEmacsEdit(bool with_url)
{
request.item.SetDateModifyToNow();
request.status = db.EditItemById(request.item, with_url);
if( request.status == WINIX_ERR_OK )
{
TemplatesFunctions::pattern_cacher.UpdatePattern(request.item);
log << log2 << "Content: modified an item" << logend;
request.notify_code |= WINIX_NOTIFY_ITEM_EDIT;
}
}
bool Content::PostEmacsCheckAbuse(bool adding)
{
if( !CheckRebus() )
{
request.status = WINIX_ERR_INCORRECT_REBUS;
return false;
}
// !! is tested in createthread once
CheckGetPostTimes();
if( request.session->spam_score > 0 )
{
request.status = WINIX_ERR_SPAM;
log << log1 << "Content: ignoring due to suspected spamming" << logend;
return false;
}
return true;
}
void Content::PostFunEmacsModifyMountPoint(bool adding)
{
if( data.mounts.pmount->type == Mount::thread )
{
if( adding )
db.EditThreadAddItem(request.dir_table.back()->id, request.item.id);
RedirectToLastDir();
}
else
if( data.mounts.pmount->type == Mount::ticket )
{
RedirectToLastDir();
}
else
{
// Mount::cms
RedirectTo(request.item);
}
}
void Content::PostFunEmacs()
{
if( !FunEmacsCheckAccess() )
return;
bool adding = !request.is_item;
bool edit_with_url = ReadItem(request.item, Item::file);
if( !PostEmacsCheckAbuse(adding) )
return;
if( adding )
{
request.is_item = true;
request.item.privileges = 0644; // !! tymczasowo, bedzie uzyte umask
PostFunEmacsAdd();
}
else
{
PostFunEmacsEdit(edit_with_url);
}
if( request.status == WINIX_ERR_OK )
{
PostFunEmacsModifyMountPoint(adding);
CheckSpecialFile();
}
else
{
log << log1 << "Content: PostFunEmacs: Error: "
<< request.status << logend;
}
}
void Content::FunEmacs()
{
FunEmacsCheckAccess();
}

View File

@@ -1,71 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include <arpa/inet.h>
#include "content.h"
#include "../core/request.h"
#include "../core/error.h"
#include "../core/db.h"
#include "../core/data.h"
void Content::LoginUser(long user_id, bool remember_me)
{
request.session->puser = data.users.GetUser(user_id);
request.session->spam_score = 0;
if( !request.session->puser )
{
log << log1 << "Content: user id: " << user_id << " is not in data.users" << logend;
return;
}
request.session->remember_me = remember_me;
data.last.UserLogin(user_id, request.session->puser->name, inet_addr(request.env_remote_addr), request.session->id);
data.how_many_logged += 1;
log << log2 << "User " << request.session->puser->name << " (id: " << user_id << ") logged" << logend;
}
void Content::PostFunLogin()
{
try
{
std::string * login = request.PostVar("login");
std::string * pass = request.PostVar("password");
std::string * remem = request.PostVar("rememberme");
long user_id;
if( login && pass && db.CheckUser(*login, *pass, user_id) )
LoginUser(user_id, remem != 0);
// !! moze zglosic komunikat o nie poprawnym logowaniu
}
catch(const Error &)
{
}
if( request.is_item )
RedirectTo(request.item);
else
RedirectTo(*request.dir_table.back());
}
void Content::FunLogin()
{
}

View File

@@ -1,49 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "content.h"
#include "../core/request.h"
#include "../core/data.h"
void Content::FunLogout()
{
if( request.session->puser )
{
log << log2 << "User: " << request.session->puser->name << ", id: " << request.session->puser->id << " logged out" << logend;
data.last.UserLogout(request.session->puser->id, request.session->id);
if( data.how_many_logged > 0 ) // for safety
data.how_many_logged -= 1;
request.session->puser = 0;
request.session->remember_me = 0;
}
std::string path;
data.dirs.MakePath(request.dir_table.back()->id, path);
request.redirect_to = data.base_url + path;
if( request.is_item )
request.redirect_to += request.item.url;
}

View File

@@ -1,45 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "content.h"
#include "../core/request.h"
#include "../core/db.h"
void Content::FunLs()
{
if( !request.is_item )
{
Db::ItemQuery iq;
iq.sel_content = false;
iq.WhereParentId(request.dir_table.back()->id);
iq.WhereType(Item::file);
if( request.IsParam("ckeditor_browse") )
{
iq.WhereAuth(Item::auth_image);
db.GetItems(request.item_table, iq);
}
else
{
db.GetItems(request.item_table, iq);
}
}
}

View File

@@ -1,143 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "content.h"
#include "../core/request.h"
#include "../core/misc.h"
#include "../core/db.h"
// returning true if the 'url' has to be changed
bool Content::ReadItemUrlSubject(Item & item, Item::Type item_type)
{
bool with_url = false;
std::string * new_url = request.PostVar("url");
std::string * new_subject = request.PostVar("subject");
if( item_type == Item::file )
{
if( !request.is_item || (new_url && *new_url != item.url) )
with_url = true;
}
else
{
with_url = true;
}
if( new_url )
item.url = *new_url;
if( new_subject )
item.subject = *new_subject;
if( item.subject.empty() )
{
item.subject = request.dir_table.back()->subject;
item.subject += "_msg_";
item.subject += ToStr(db.Size(request.dir_table.back()->id, Item::file));
}
// if item.url is empty then it will be set from item.subject
PrepareUrl(item);
return with_url;
}
void Content::ReadItemContentWithType(Item & item)
{
item.content_type = Item::ct_formatted_text; // default is formatted text
request.PostVar("itemcontent", request.item.content);
request.PostVar("contenttype", temp);
// ct_text and ct_formatted_text can use everyone
if( temp == "0" )
item.content_type = Item::ct_text;
else
if( temp == "1" )
item.content_type = Item::ct_formatted_text;
// those below need special privileges
if( !request.session->puser )
return;
long user_id = request.session->puser->id;
if( temp == "2" )
{
if( request.CanUseHtml(user_id) )
item.content_type = Item::ct_html;
}
else
if( temp == "3" )
{
if( request.CanUseBBCode(user_id) )
item.content_type = Item::ct_bbcode;
}
else
if( temp == "4" )
{
if( request.CanUseRaw(user_id) )
item.content_type = Item::ct_raw;
}
}
// item_type - the type of an item you are expecting to read
// returns true if the url has to be changed
// at the moment this is only checked for Item::file - for Item::dir it returns always true
bool Content::ReadItem(Item & item, Item::Type item_type)
{
if( item_type == Item::none )
return false;
item.type = item_type;
item.parent_id = request.dir_table.back()->id;
bool edit_with_url = ReadItemUrlSubject(item, item_type);
SetUser(item);
if( item_type == Item::file )
ReadItemContentWithType(item);
return edit_with_url;
}
// if we don't have access we only remove the item from the table
void Content::CheckAccessToItems()
{
size_t i = 0;
while( i < request.item_table.size() )
{
if( !request.HasReadAccess(request.item_table[i]) )
{
request.item_table.erase(request.item_table.begin() + i);
}
else
{
i += 1;
}
}
}

View File

@@ -1,35 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "content.h"
#include "../core/request.h"
#include "../core/data.h"
void Content::CheckSpecialFile()
{
static std::string fstab = "fstab";
Item * etc = data.dirs.GetEtcDir();
if( !etc )
return;
if( request.item.parent_id != etc->id )
return;
if( request.item.url == fstab )
{
log << log3 << "Content: reloading mount points" << logend;
request.status = data.mounts.ReadMounts(request.item.content);
}
}

View File

@@ -1,80 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "content.h"
#include "../core/request.h"
#include "../core/error.h"
#include "../core/db.h"
#include "../core/data.h"
#include "../core/notify.h"
bool Content::FunMkdirCheckAccess()
{
if( request.is_item || !request.CanUseMkdir(*request.dir_table.back()) )
{
request.status = WINIX_ERR_PERMISSION_DENIED;
return false;
}
return true;
}
void Content::Mkdir(Item & item, bool add_to_dir_table)
{
request.status = db.AddItem(item);
if( request.status == WINIX_ERR_OK )
{
Item * pdir = data.dirs.AddDir(item);
if( add_to_dir_table )
request.dir_table.push_back(pdir);
}
}
void Content::PostFunMkdir(bool add_to_dir_table, int privileges)
{
if( !FunMkdirCheckAccess() )
return;
ReadItem(request.item, Item::dir);
request.item.privileges = privileges;
Mkdir(request.item, add_to_dir_table);
if( request.status == WINIX_ERR_OK )
{
request.notify_code |= WINIX_NOTIFY_DIR_ADD;
RedirectTo(request.item);
}
else
{
log << log1 << "Content: PostFunMkdir: Error: " << request.status << logend;
}
}
void Content::FunMkdir()
{
FunMkdirCheckAccess();
}

View File

@@ -1,363 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include <errno.h>
#include "content.h"
#include "../core/request.h"
#include "../core/data.h"
bool Content::MoveCheckAccessFromToDir()
{
Item * last;
Item * last_but_one = 0;
last = request.dir_table[request.dir_table.size()-1];
if( request.dir_table.size() >= 2 )
last_but_one = request.dir_table[request.dir_table.size()-2];
if( request.method != Request::post )
{
// used in GET (HEAD in the future?)
if( !request.HasWriteAccess(*last) &&
(!last_but_one || !request.HasWriteAccess(*last_but_one)) )
return false;
}
else
{
// used in POST when the moving is performed
if( request.IsPostVar("onlycontent") )
return request.HasWriteAccess(*last);
else
if( last_but_one )
return request.HasWriteAccess(*last_but_one);
else
return false; // you cannot move the root directory
}
return true;
}
bool Content::MoveCheckAccessFrom()
{
if( request.is_item )
{
// moving a file
if( !request.HasWriteAccess(*request.dir_table.back()) )
{
request.status = WINIX_ERR_PERMISSION_DENIED;
return false;
}
}
else
{
if( !MoveCheckAccessFromToDir() )
{
request.status = WINIX_ERR_PERMISSION_DENIED;
return false;
}
}
return true;
}
bool Content::MoveCheckAccessTo(long dir_id)
{
Item * pdir = data.dirs.GetDir(dir_id);
if( !pdir )
{
request.status = WINIX_ERR_INCORRECT_DIR;
return false;
}
if( !request.HasReadExecAccessToPath(dir_id) || !request.HasWriteAccess(*pdir) )
{
request.status = WINIX_ERR_PERMISSION_DENIED;
return false;
}
return true;
}
bool Content::MoveCheckMountPoints(long dir_id)
{
/*
Mount * new_mount = data.mounts.CalcMount(dir_id);
if( !new_mount )
{
if( data.mounts.pmount->type != Mount::cms )
{
request.status = WINIX_DIFFERENT_MOUNT_POINTS;
return false;
}
return true;
}
if( new_mount->type != data.mounts.pmount->type )
{
request.status = WINIX_DIFFERENT_MOUNT_POINTS;
return false;
}
*/
return true;
}
bool Content::MoveParseDir(long & dir_id, std::string & dir, std::string & file)
{
std::string * move_to = request.PostVar("moveto");
if( !move_to )
{
request.status = WINIX_ERR_PERMISSION_DENIED;
return false;
}
int res = data.dirs.AnalyzePath(*move_to, dir_id, dir, file);
if( res == 1 )
request.status = WINIX_ERR_NO_ROOT_DIR;
else
if( res != 0 )
request.status = WINIX_ERR_INCORRECT_DIR;
return res == 0;
}
void Content::MoveAuth(Item & item)
{
if( !request.MakePath(item, mv_new_path, true) )
{
request.status = WINIX_ERR_PERMISSION_DENIED;
return;
}
if( rename(item.auth_path.c_str(), mv_new_path.c_str()) == 0 )
{
log << log1 << "Content: moved static file from: " << item.auth_path << ", to: " << mv_new_path << logend;
item.auth_path = mv_new_path;
request.status = db.EditAuthById(item, item.id);
}
else
{
int err = errno;
log << log1 << "Content: can't move a file from: " << item.auth_path << ", to: " << mv_new_path << ", ";
log.SystemErr(err);
log << logend;
request.status = WINIX_ERR_PERMISSION_DENIED;
}
}
bool Content::MoveIsTheSameFile(const Item & item)
{
if( mv_file.empty() )
{
if( item.parent_id == mv_dir_id )
return true; // nothing to do
}
else
{
if( item.parent_id == mv_dir_id && item.url == mv_file )
return true; // nothing to do
}
return false;
}
void Content::MoveFile(Item & item, bool redirect)
{
if( MoveIsTheSameFile(item) )
return;
if( !mv_file.empty() )
{
item.url = mv_file;
PrepareUrl(item);
}
item.parent_id = mv_dir_id;
request.status = db.EditParentUrlById(item, item.id);
if( request.status == WINIX_ERR_OK )
{
log << log2 << "Content: the file was moved to: " << mv_dir << item.url << logend;
if( item.auth != Item::auth_none )
MoveAuth(item);
if( redirect )
RedirectTo(item);
}
}
void Content::MoveContentOfDir()
{
Db::ItemQuery iq;
iq.sel_parent_id = true;
iq.sel_type = true;
iq.sel_url = true;
iq.sel_auth = true;
iq.WhereParentId(request.dir_table.back()->id);
db.GetItems(request.item_table, iq);
for(size_t i=0 ; i<request.item_table.size() ; ++i)
{
if( request.item_table[i].type == Item::dir )
MoveDir(request.item_table[i], false);
else
MoveFile(request.item_table[i], false);
}
RedirectToLastDir();
}
void Content::MoveAuthPrepareQuery()
{
mv_auth_iq.SetAll(true, false);
mv_auth_iq.sel_parent_id = true;
mv_auth_iq.sel_type = true;
mv_auth_iq.sel_url = true;
mv_auth_iq.sel_auth = true;
mv_auth_iq.WhereType(Item::file);
mv_auth_iq.WhereAuth(Item::auth_none, false);
}
void Content::MoveAuthContentOfDir(const Item & item)
{
DirContainer::ParentIterator i = data.dirs.FindFirstParent(item.id);
// go through all directories
for( ; i != data.dirs.ParentEnd() ; i = data.dirs.NextParent(i) )
MoveAuthContentOfDir(*(i->second));
mv_auth_iq.WhereParentId(item.id);
// don't use request.item here (is used in MoveContentOfDir())
db.GetItems(mv_auth, mv_auth_iq);
for(size_t i=0 ; i<mv_auth.size() ; ++i)
MoveAuth(mv_auth[i]);
mv_auth.clear();
}
void Content::MoveDir(Item & item, bool redirect)
{
if( mv_file.empty() && mv_dir_id == item.id )
return; // nothing to do
if( mv_dir_id == item.id || data.dirs.HasParent(mv_dir_id, item.id) )
{
log << log1 << "Content: cannot move directory to inside it" << logend;
request.status = WINIX_ERR_INCORRECT_DIR;
return;
}
if( !data.dirs.ChangeParent(item.id, mv_dir_id) )
{
request.status = WINIX_ERR_INCORRECT_DIR;
return;
}
item.parent_id = mv_dir_id;
if( !mv_file.empty() )
{
item.url = mv_file;
PrepareUrl(item);
}
request.status = db.EditParentUrlById(item, item.id);
if( request.status == WINIX_ERR_OK )
{
log << log2 << "Content: the directory was moved to: " << mv_dir << item.url << logend;
MoveAuthContentOfDir(item);
if( redirect )
RedirectToLastDir();
}
}
void Content::PostFunMv()
{
if( MoveCheckAccessFrom() &&
MoveParseDir(mv_dir_id, mv_dir, mv_file) &&
MoveCheckAccessTo(mv_dir_id) &&
MoveCheckMountPoints(mv_dir_id) )
{
if( request.is_item )
{
MoveFile(request.item);
}
else
{
MoveAuthPrepareQuery();
if( request.IsPostVar("onlycontent") )
{
if( mv_file.empty() )
MoveContentOfDir();
else
request.status = WINIX_ERR_INCORRECT_DIR;
}
else
{
MoveDir(*request.dir_table.back());
}
}
}
}
void Content::FunMv()
{
MoveCheckAccessFrom();
}

View File

@@ -1,30 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "content.h"
#include "../core/request.h"
void Content::FunNode()
{
if( request.param_table.empty() )
{
//request.status = Error
//!!zglosic 404
return;
}
long id = atol( request.param_table[0]->c_str() );
RedirectTo(id);
}

View File

@@ -1,311 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "content.h"
#include "../core/request.h"
#include "../core/error.h"
#include "../core/db.h"
#include "../core/data.h"
bool Content::PrivCheckAccess()
{
// we do not check permissions here
// permissions depends on the user, group, and privileges
// but we cannot use parameter 'r' on files
// and only logged users can change permissions
if( !request.session->puser || (request.is_item && request.IsParam("r")) )
{
request.status = WINIX_ERR_PERMISSION_DENIED;
return false;
}
return true;
}
bool Content::ChangeOwner(Item & item, long user_id, long group_id)
{
if( user_id!=item.user_id || group_id!=item.group_id )
{
if( !request.CanChangeUser(item, user_id) )
{
log << log3 << "Content: can't change the user" << logend;
return false;
}
if( !request.CanChangeGroup(item, group_id) )
{
log << log3 << "Content: can't change the group" << logend;
return false;
}
}
item.user_id = user_id;
item.group_id = group_id;
return true;
}
bool Content::ChangePrivileges(Item & item, int privileges)
{
if( privileges != item.privileges )
{
if( !request.CanChangePrivileges(item, privileges) )
{
log << log3 << "Content: can't change privileges" << logend;
return false;
}
}
item.privileges = privileges;
return true;
}
void Content::ChangePriv(Item & item, long user_id, long group_id, int privileges)
{
if( change_owner )
{
if( !ChangeOwner(item, user_id, group_id) )
return;
}
if( change_priv )
{
if( !ChangePrivileges(item, privileges) )
return;
}
request.status = db.EditPrivById(item, item.id);
}
void Content::PrivLogStart(const char * what, long user, long group, int priv)
{
log << log2 << what;
if( change_owner )
{
User * puser = data.users.GetUser(user);
Group * pgroup = data.groups.GetGroup(group);
log << "new user: ";
if( puser )
log << puser->name;
else
log << "id: " << user;
log << ", new group: ";
if( pgroup )
log << pgroup->name;
else
log << "id: " << group;
if( change_priv )
log << ", ";
}
if( change_priv )
{
char buf[30];
sprintf(buf, "0%o", priv);
log << "privileges: " << buf;
}
log << logend;
}
void Content::PrivLog(const char * what, long id, const std::string & url)
{
Item * root = 0;
if( id != -1 )
root = data.dirs.GetRootDir();
log << log3 << "Content: " << what;
if( root && root->id == id )
log << "(root)";
else
log << url;
log << logend;
}
void Content::PrivFilesInDir(long parent_id)
{
Db::ItemQuery iq;
iq.SetAll(false, false);
iq.sel_user_id = iq.sel_group_id = iq.sel_guest_name = iq.sel_privileges = true;
iq.WhereParentId(parent_id);
iq.WhereType(Item::file);
db.GetItems(request.item_table, iq);
std::vector<Item>::iterator i = request.item_table.begin();
for( ; i != request.item_table.end() ; ++i)
{
PrivLog("changed file: ", -1, i->url);
ChangePriv(*i, user_id_file, group_id_file, priv_file);
}
}
// recurrence
void Content::PrivDir(long parent_id)
{
PrivFilesInDir(parent_id);
DirContainer::ParentIterator i = data.dirs.FindFirstParent(parent_id);
for( ; i != data.dirs.ParentEnd() ; i = data.dirs.NextParent(i) )
{
PrivLog("changed dir: ", -1, i->second->url);
ChangePriv(*(i->second), user_id_dir, group_id_dir, priv_dir);
if( subdirectories )
PrivDir(i->second->id);
}
}
bool Content::ReadPriv(const char * user_in, const char * group_in, const char * priv_in,
long & user_id, long & group_id, int & priv)
{
std::string * user_str = request.PostVar(user_in);
std::string * group_str = request.PostVar(group_in);
std::string * priv_str = request.PostVar(priv_in);
if( change_owner && (!user_str || !group_str) )
{
log << log1 << "Content: PostFunPriv: there is no some post variables for changing the owner" << logend;
return false;
}
if( change_priv && !priv_str )
{
log << log1 << "Content: PostFunPriv: there is no some post variables for changing privileges" << logend;
return false;
}
if( change_owner )
{
user_id = data.users.GetUserId( *user_str );
group_id = data.groups.GetGroupId( *group_str );
}
if( change_priv )
priv = strtol( priv_str->c_str() , 0, 8);
return true;
}
void Content::PrivDir()
{
if( !ReadPriv("userfile", "groupfile", "privilegesfile", user_id_file, group_id_file, priv_file) )
return;
if( !ReadPriv("userdir", "groupdir", "privilegesdir", user_id_dir, group_id_dir, priv_dir) )
return;
PrivLogStart("Content: changes for files: ", user_id_file, group_id_file, priv_file);
PrivLogStart("Content: changes for dirs: ", user_id_dir, group_id_dir, priv_dir);
if( request.IsPostVar("changecurrentdir") )
{
Item & last_dir = *request.dir_table.back();
PrivLog("changed dir: ", last_dir.id, last_dir.url);
ChangePriv(*request.dir_table.back(), user_id_dir, group_id_dir, priv_dir);
}
subdirectories = request.IsPostVar("changesubdirs");
// go through all directories
PrivDir(request.dir_table.back()->id);
RedirectToLastDir();
}
// changing only one item (either a dir or file)
void Content::PrivOneItem()
{
if( !ReadPriv("user", "group", "privileges", user_id_file, group_id_file, priv_file) )
return;
PrivLogStart("Content: changes: ", user_id_file, group_id_file, priv_file);
if( request.is_item )
{
ChangePriv(request.item, user_id_file, group_id_file, priv_file);
RedirectTo(request.item);
}
else
{
ChangePriv(*request.dir_table.back(), user_id_file, group_id_file, priv_file);
RedirectToLastDir();
}
}
void Content::PostFunPriv()
{
if( !PrivCheckAccess() )
return;
change_owner = (request.pfunction->code == FUN_PRIV || request.pfunction->code == FUN_CHOWN);
change_priv = (request.pfunction->code == FUN_PRIV || request.pfunction->code == FUN_CHMOD);
if( request.IsParam("r") )
{
PrivDir();
}
else
{
PrivOneItem();
}
data.dirs.CheckRootDir();
}
void Content::FunPriv()
{
PrivCheckAccess();
}

View File

@@ -1,45 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "content.h"
#include "../core/request.h"
#include "../core/error.h"
#include "../core/notify.h"
void Content::FunReloadTemplates()
{
log << log1 << "Content: reloading html templates" << logend;
templates.ReadTemplates();
notify.ReadTemplates(); // make sure that ReadTemplates() is using some kind of locking
}
void Content::FunReload()
{
// !! temporarily only an admin has access
if( !request.session->puser || !request.session->puser->super_user )
{
log << log1 << "Content: Only an admin has access to reload function" << logend;
request.status = WINIX_ERR_PERMISSION_DENIED;
return;
}
if( request.IsParam("templates") )
FunReloadTemplates();
}

View File

@@ -1,204 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include <cstdio>
#include <errno.h>
#include "content.h"
#include "../core/request.h"
#include "../core/error.h"
#include "../core/data.h"
bool Content::RemoveCheckAccess()
{
if( !request.is_item )
{
if( !request.CanRemove(*request.dir_table.back()) )
{
request.status = WINIX_ERR_PERMISSION_DENIED;
return false;
}
}
else
if( !request.CanRemove(request.item) )
{
request.status = WINIX_ERR_PERMISSION_DENIED;
return false;
}
return true;
}
void Content::RemoveAuthPrepareQuery()
{
rm_auth_iq.SetAll(true, false);
rm_auth_iq.sel_parent_id = true;
rm_auth_iq.sel_type = true;
rm_auth_iq.sel_auth = true;
rm_auth_iq.WhereType(Item::file);
rm_auth_iq.WhereAuth(Item::auth_none, false);
}
void Content::RemoveAllDirs(long dir_id)
{
DirContainer::ParentIterator pnext, p = data.dirs.FindFirstParent(dir_id);
for( ; p != data.dirs.ParentEnd() ; p = pnext )
{
// this iterator p will be deleted by the next DeleteDir(p->second->id)
// (the next iterator we must calculate beforehand)
pnext = data.dirs.NextParent(p);
RemoveAllDirs(p->second->id);
}
rm_auth_iq.WhereParentId(dir_id);
db.GetItems(request.item_table, rm_auth_iq);
for(size_t i=0 ; i<request.item_table.size() ; ++i)
RemoveAuth(request.item_table[i]);
if( db.DelDirById(dir_id) == WINIX_ERR_OK )
{
data.dirs.DelDir(dir_id);
db.RemoveThread(dir_id);
db.RemoveTicket(dir_id);
}
}
void Content::RemoveAllDirs()
{
RemoveAuthPrepareQuery();
// this method deletes recursively all directories
RemoveAllDirs(request.dir_table.back()->id);
request.dir_table.erase(--request.dir_table.end());
if( request.dir_table.empty() )
{
// we have deleted the root directory
data.dirs.CheckRootDir(); // adding a new root dir
Item * proot = data.dirs.GetRootDir();
if( proot )
request.dir_table.push_back(proot);
else
// there is no a root dir
// CheckRootDir() didn't add the root dir (probably problem with the database)
// make sure that Content::Make() will check that the dir_table is empty and returns
return;
}
RedirectToLastDir();
}
void Content::RemoveDir()
{
if( request.param_table.empty() )
request.status = WINIX_ERR_PERMISSION_DENIED; // use parameter "r" for removing a directory
else
if( request.IsParam("r") )
RemoveAllDirs();
else
request.status = WINIX_ERR_UNKNOWN_PARAM;
}
void Content::RemoveAuth(Item & item)
{
if( item.auth_path.empty() )
{
log << log1 << "Content: can't remove a static file: auth_path is empty" << logend;
return;
}
if( remove(item.auth_path.c_str()) == 0 )
{
log << log1 << "Content: removed static file: " << item.auth_path << logend;
item.auth_path.clear();
item.auth = Item::auth_none;
// we don't store it to db (will be removed or is removed already)
}
else
{
int err = errno;
log << log1 << "Content: can't remove a file: " << item.auth_path;
log.SystemErr(err);
log << logend;
request.status = WINIX_ERR_PERMISSION_DENIED;
}
}
void Content::RemoveFile()
{
// for safety we check if param_table is empty
// a user can use "confirm" but can make a mistake when typing
if( !request.param_table.empty() )
{
request.status = WINIX_ERR_UNKNOWN_PARAM;
return;
}
if( db.DelItem( request.item ) )
{
log << log2 << "Content: deleted item: subject: " << request.item.subject << ", id: " << request.item.id << logend;
TemplatesFunctions::pattern_cacher.DeletePattern(request.item);
if( data.mounts.pmount->type == Mount::thread )
db.EditThreadRemoveItem(request.item.parent_id);
else
if( data.mounts.pmount->type == Mount::ticket )
db.EditTicketRemoveItem(request.item.id);
if( request.item.auth != Item::auth_none )
RemoveAuth(request.item);
}
else
{
request.status = WINIX_ERR_NO_ITEM;
}
RedirectToLastDir();
}
void Content::FunRm()
{
if( !RemoveCheckAccess() )
return;
if( request.IsParam("confirm") )
return; // show confirmation dialog
if( request.is_item )
RemoveFile();
else
RemoveDir();
}

View File

@@ -1,38 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "content.h"
#include "../core/request.h"
#include "../core/error.h"
void Content::FunRun()
{
if( !request.is_item )
{
log << log1 << "Content: Run function requires an item" << logend;
request.status = WINIX_ERR_NO_ITEM;
return;
}
if( !request.HasReadExecAccess(request.item) )
{
request.status = WINIX_ERR_PERMISSION_DENIED;
return;
}
}
void Content::PostFunRun()
{
FunRun();
}

View File

@@ -1,81 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "content.h"
#include "../core/request.h"
#include "../core/db.h"
#include "../core/log.h"
bool Content::SubjectCheckAccess()
{
// super user can always
if( request.session->puser && request.session->puser->super_user )
return true;
bool access;
if( request.is_item )
access = request.HasWriteAccess(request.item);
else
access = request.HasWriteAccess(*request.dir_table.back());
if( !access )
request.status = WINIX_ERR_PERMISSION_DENIED;
return access;
}
void Content::EditDirSubject()
{
Item & dir = *request.dir_table.back();
request.PostVar("subject", dir.subject);
db.EditSubjectById(dir, dir.id);
RedirectToLastDir();
}
void Content::EditFileSubject()
{
request.PostVar("subject", request.item.subject);
db.EditSubjectById(request.item, request.item.id);
RedirectTo(request.item);
}
void Content::PostFunSubject()
{
if( !SubjectCheckAccess() )
return;
if( request.is_item )
EditFileSubject();
else
EditDirSubject();
}
void Content::FunSubject()
{
SubjectCheckAccess();
}

View File

@@ -1,61 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "content.h"
#include "../core/request.h"
#include "../core/db.h"
#include "../core/data.h"
#include "../core/mount.h"
#include <algorithm>
bool Content::FunThreadSort(const Thread & t1, const Thread & t2)
{
Item * pdir1 = data.dirs.GetDir(t1.dir_id);
Item * pdir2 = data.dirs.GetDir(t2.dir_id);
if( !pdir1 || !pdir2 )
return false;
time_t time1 = mktime(&pdir1->date_creation);
time_t time2 = mktime(&pdir2->date_creation);
return time1 > time2;
}
void Content::FunThread()
{
if( request.is_item )
{
request.status = WINIX_ERR_PERMISSION_DENIED;
return;
}
Db::ItemQuery iq;
if( data.mounts.pmount->IsArg(Mount::par_thread, "sort_desc") )
iq.sort_asc = false;
iq.WhereParentId(request.dir_table.back()->id);
iq.WhereType(Item::file);
iq.WhereAuth(Item::auth_none);
db.GetItems(request.item_table, iq);
db.GetThreads(request.dir_table.back()->id, request.thread_tab);
CheckAccessToItems();
std::sort(request.thread_tab.begin(), request.thread_tab.end(), FunThreadSort);
}

View File

@@ -1,68 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "content.h"
#include "../core/request.h"
#include "../core/db.h"
#include "../core/data.h"
#include "../core/mount.h"
void Content::TicketDeleteFirst()
{
if( !request.is_ticket )
return;
for(size_t i=0 ; i<request.item_table.size() ; ++i)
{
if( request.item_table[i].id == request.ticket.item_id )
{
// this is the first item with the content for the ticket
if( !request.HasReadAccess(request.item_table[i]) )
{
request.status = WINIX_ERR_PERMISSION_DENIED;
}
request.item_table.erase(request.item_table.begin() + i);
break;
}
}
}
void Content::FunTicket()
{
if( request.is_item || data.mounts.pmount->type != Mount::ticket )
{
request.status = WINIX_ERR_PERMISSION_DENIED;
return;
}
Db::ItemQuery iq;
iq.WhereParentId(request.dir_table.back()->id);
iq.WhereType(Item::file);
iq.WhereAuth(Item::auth_none);
db.GetItems(request.item_table, iq);
db.GetTickets(request.dir_table.back()->id, request.ticket_tab);
TicketDeleteFirst();
CheckAccessToItems();
}

View File

@@ -1,199 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <cstdio>
#include <errno.h>
#include "content.h"
#include "../core/request.h"
#include "../core/data.h"
#include "../core/misc.h"
bool Content::FunUploadCheckAccess()
{
if( request.is_item || !request.CanUseUpload(*request.dir_table.back()) )
{
request.status = WINIX_ERR_PERMISSION_DENIED;
return false;
}
return true;
}
bool Content::UploadCreatePath()
{
if( !request.MakePath(request.item, true) )
{
request.status = WINIX_ERR_PERMISSION_DENIED;
return false;
}
return true;
}
void Content::UploadSaveFile(const std::string & tmp_filename, const std::string & destination)
{
if( rename(tmp_filename.c_str(), destination.c_str()) == 0 )
{
log << log1 << "Content: uploaded a new file: " << destination << logend;
}
else
{
int err = errno;
// !! skasowac takze plik z bazy danych?
log << log1 << "Content: can't move the tmp file from: " << tmp_filename << ", to: " << destination << ", ";
log.SystemErr(err);
log << logend;
request.status = WINIX_ERR_PERMISSION_DENIED;
}
}
bool Content::FunUploadCheckAbuse()
{
if( !CheckRebus() )
{
request.status = WINIX_ERR_INCORRECT_REBUS;
return false;
}
CheckGetPostTimes(4);
if( request.session->spam_score > 0 )
{
request.status = WINIX_ERR_SPAM;
log << log1 << "Content: ignoring due to suspected spamming" << logend;
return false;
}
return true;
}
void Content::UploadMulti()
{
request.item.Clear(); // clearing and setting date
request.item.parent_id = request.dir_table.back()->id;
request.item.type = Item::file;
request.item.privileges = 0644; // !! tymczasowo
SetUser(request.item);
PostFileTable::iterator i = request.post_file_table.begin();
for( ; i != request.post_file_table.end() ; ++i)
{
const char * file_name = i->second.filename.c_str();
request.item.subject = file_name;
request.item.url = file_name;
request.item.auth = SelectFileType(file_name);
PrepareUrl(request.item);
PostFunEmacsAdd(); // always adding a new item
if( !UploadCreatePath() )
return;
if( request.status == WINIX_ERR_OK )
{
UploadSaveFile(i->second.tmp_filename, request.item.auth_path);
request.status = db.EditAuthById(request.item, request.item.id);
}
}
RedirectToLastDir();
}
void Content::UploadSingle()
{
std::string * new_subject = request.PostVar("subject");
std::string * new_url = request.PostVar("url");
bool has_subject = (new_subject && (*new_subject)[0] != 0 );
bool has_url = (new_url && (*new_url)[0] != 0 );
ReadItem(request.item, Item::file); // ReadItem() changes the url if it is empty
request.item.privileges = 0644; // !! tymczasowo
const char * file_name = request.post_file_table.begin()->second.filename.c_str();
request.item.auth = SelectFileType(file_name);
if( !has_subject )
request.item.subject = file_name;
if( !has_url )
{
request.item.url = file_name;
PrepareUrl(request.item);
}
PostFunEmacsAdd(); // always adding a new item
// url can be changed by PostFunEmacsAdd()
if( !UploadCreatePath() )
return;
if( request.status == WINIX_ERR_OK )
{
const std::string & tmp_filename = request.post_file_table.begin()->second.tmp_filename;
UploadSaveFile(tmp_filename, request.item.auth_path);
request.status = db.EditAuthById(request.item, request.item.id);
}
if( request.status == WINIX_ERR_OK )
RedirectTo(request.item, "/cat");
}
// !! dodac usuwanie plikow statycznych przez rm
void Content::PostFunUpload()
{
if( !FunUploadCheckAccess() )
return;
if( request.post_file_table.empty() )
{
request.status = WINIX_ERR_PERMISSION_DENIED;
return;
}
if( !FunUploadCheckAbuse() )
return;
if( request.post_file_table.size() > 1 )
UploadMulti();
else
UploadSingle();
}
void Content::FunUpload()
{
FunUploadCheckAccess();
}

View File

@@ -12,7 +12,7 @@ all: $(o)
depend:
makedepend -Y. -f- *.cpp > Makefile.dep
makedepend -Y. -I.. -I../../ezc/src -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

View File

@@ -1,125 +1,406 @@
# DO NOT DELETE
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 error.h
config.o: rebus.h loadavg.h plugin.h request.h requesttypes.h session.h
config.o: plugindata.h thread.h compress.h acceptencodingparser.h
config.o: acceptbaseparser.h htmlfilter.h postmultiparser.h ticket.h
config.o: pluginmsg.h misc.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 error.h rebus.h loadavg.h
db.o: db.h item.h user.h group.h thread.h error.h log.h dircontainer.h
db.o: ugcontainer.h ticket.h misc.h
db_itemcolumns.o: db.h item.h user.h group.h thread.h error.h log.h
db_itemcolumns.o: dircontainer.h ugcontainer.h ticket.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 ticket.h data.h users.h groups.h functions.h
dirs.o: function.h lastcontainer.h mounts.h mount.h rebus.h loadavg.h
dirs.o: request.h requesttypes.h session.h plugindata.h compress.h
dirs.o: acceptencodingparser.h acceptbaseparser.h htmlfilter.h
dirs.o: postmultiparser.h
function.o: function.h item.h
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 rebus.h loadavg.h db.h thread.h ticket.h request.h
functionparser.o: session.h plugindata.h compress.h acceptencodingparser.h
functionparser.o: acceptbaseparser.h htmlfilter.h postmultiparser.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 ticket.h
app.o: app.h config.h confparser.h htmlfilter.h system.h dirs.h item.h
app.o: dircontainer.h ../db/db.h ../db/dbbase.h ../db/dbconn.h
app.o: ../db/dbtextstream.h ../core/textstream.h misc.h ../core/error.h log.h
app.o: textstream.h ../db/dbitemquery.h ../core/item.h ../db/dbitemcolumns.h
app.o: ../core/user.h ../core/group.h ../core/thread.h ../core/dircontainer.h
app.o: ../core/ugcontainer.h request.h requesttypes.h session.h error.h
app.o: user.h plugindata.h rebus.h ../templates/htmltextstream.h
app.o: ../notify/notify.h ../notify/notifypool.h ../templates/locale.h
app.o: ../core/confparser.h ../templates/misc.h ../templates/localefilter.h
app.o: ../templates/locale.h ../../ezc/src/ezc.h ../../ezc/src/utf8.h
app.o: ../../ezc/src/generator.h ../../ezc/src/pattern.h
app.o: ../../ezc/src/functions.h ../../ezc/src/funinfo.h
app.o: ../../ezc/src/stringconv.h ../templates/htmltextstream.h
app.o: ../notify/notifythread.h ../core/basethread.h synchro.h
app.o: ../notify/templatesnotify.h ../core/config.h ../core/users.h
app.o: ugcontainer.h lastcontainer.h mounts.h mount.h mountparser.h users.h
app.o: groups.h group.h loadavg.h thumb.h basethread.h sessionmanager.h
app.o: sessioncontainer.h ../functions/functions.h
app.o: ../functions/functionbase.h ../core/request.h ../core/system.h
app.o: ../core/synchro.h ../functions/functionparser.h ../functions/adduser.h
app.o: ../functions/cat.h ../functions/chmod.h ../functions/privchanger.h
app.o: ../functions/chown.h ../functions/ckeditor.h ../functions/cp.h
app.o: ../functions/createthread.h ../functions/functionbase.h
app.o: ../functions/default.h ../functions/download.h ../functions/emacs.h
app.o: ../functions/last.h ../functions/login.h ../functions/logout.h
app.o: ../functions/ln.h ../functions/ls.h ../functions/mkdir.h
app.o: ../functions/mv.h ../functions/node.h ../functions/priv.h
app.o: ../functions/reload.h ../functions/rm.h ../functions/run.h
app.o: ../functions/specialdefault.h ../functions/stat.h
app.o: ../functions/subject.h ../functions/funthread.h
app.o: ../functions/template.h ../functions/tinymce.h ../functions/uname.h
app.o: ../functions/upload.h ../functions/uptime.h ../functions/who.h
app.o: ../functions/vim.h ../core/htmlfilter.h ../templates/templates.h
app.o: ../templates/patterncacher.h ../templates/ckeditorgetparser.h
app.o: ../core/httpsimpleparser.h ../core/log.h ../templates/indexpatterns.h
app.o: ../core/sessionmanager.h compress.h getparser.h httpsimpleparser.h
app.o: postparser.h cookieparser.h postmultiparser.h acceptencodingparser.h
app.o: acceptbaseparser.h plugin.h pluginmsg.h
basethread.o: basethread.h log.h textstream.h
bbcodeparser.o: bbcodeparser.h htmlfilter.h
compress.o: compress.h log.h textstream.h
config.o: config.h confparser.h htmlfilter.h log.h textstream.h plugin.h
config.o: pluginmsg.h plugindata.h request.h requesttypes.h session.h item.h
config.o: error.h user.h rebus.h ../templates/htmltextstream.h
config.o: ../core/textstream.h misc.h system.h dirs.h dircontainer.h
config.o: ../db/db.h ../db/dbbase.h ../db/dbconn.h ../db/dbtextstream.h
config.o: ../core/error.h ../db/dbitemquery.h ../core/item.h
config.o: ../db/dbitemcolumns.h ../core/user.h ../core/group.h
config.o: ../core/thread.h ../core/dircontainer.h ../core/ugcontainer.h
config.o: ../notify/notify.h ../notify/notifypool.h ../templates/locale.h
config.o: ../core/confparser.h ../templates/misc.h
config.o: ../templates/localefilter.h ../templates/locale.h
config.o: ../../ezc/src/ezc.h ../../ezc/src/utf8.h ../../ezc/src/generator.h
config.o: ../../ezc/src/pattern.h ../../ezc/src/functions.h
config.o: ../../ezc/src/funinfo.h ../../ezc/src/stringconv.h
config.o: ../templates/htmltextstream.h ../notify/notifythread.h
config.o: ../core/basethread.h synchro.h ../notify/templatesnotify.h
config.o: ../core/config.h ../core/users.h ugcontainer.h lastcontainer.h
config.o: mounts.h mount.h mountparser.h users.h groups.h group.h loadavg.h
config.o: thumb.h basethread.h sessionmanager.h sessioncontainer.h
config.o: ../functions/functions.h ../functions/functionbase.h
config.o: ../core/request.h ../core/system.h ../core/synchro.h
config.o: ../functions/functionparser.h ../functions/adduser.h
config.o: ../functions/cat.h ../functions/chmod.h ../functions/privchanger.h
config.o: ../functions/chown.h ../functions/ckeditor.h ../functions/cp.h
config.o: ../functions/createthread.h ../functions/functionbase.h
config.o: ../functions/default.h ../functions/download.h ../functions/emacs.h
config.o: ../functions/last.h ../functions/login.h ../functions/logout.h
config.o: ../functions/ln.h ../functions/ls.h ../functions/mkdir.h
config.o: ../functions/mv.h ../functions/node.h ../functions/priv.h
config.o: ../functions/reload.h ../functions/rm.h ../functions/run.h
config.o: ../functions/specialdefault.h ../functions/stat.h
config.o: ../functions/subject.h ../functions/funthread.h
config.o: ../functions/template.h ../functions/tinymce.h ../functions/uname.h
config.o: ../functions/upload.h ../functions/uptime.h ../functions/who.h
config.o: ../functions/vim.h ../core/htmlfilter.h ../templates/templates.h
config.o: ../templates/patterncacher.h ../templates/ckeditorgetparser.h
config.o: ../core/httpsimpleparser.h ../core/log.h
config.o: ../templates/indexpatterns.h ../core/sessionmanager.h
confparser.o: confparser.h misc.h item.h ../../ezc/src/utf8.h
dircontainer.o: dircontainer.h item.h log.h textstream.h
dirs.o: dirs.h item.h dircontainer.h ../db/db.h ../db/dbbase.h ../db/dbconn.h
dirs.o: ../db/dbtextstream.h ../core/textstream.h misc.h ../core/error.h
dirs.o: log.h textstream.h ../db/dbitemquery.h ../core/item.h
dirs.o: ../db/dbitemcolumns.h ../core/user.h ../core/group.h ../core/thread.h
dirs.o: ../core/dircontainer.h ../core/ugcontainer.h request.h requesttypes.h
dirs.o: session.h error.h user.h plugindata.h rebus.h config.h confparser.h
dirs.o: htmlfilter.h ../templates/htmltextstream.h ../notify/notify.h
dirs.o: ../notify/notifypool.h ../templates/locale.h ../core/confparser.h
dirs.o: ../templates/misc.h ../templates/localefilter.h ../templates/locale.h
dirs.o: ../../ezc/src/ezc.h ../../ezc/src/utf8.h ../../ezc/src/generator.h
dirs.o: ../../ezc/src/pattern.h ../../ezc/src/functions.h
dirs.o: ../../ezc/src/funinfo.h ../../ezc/src/stringconv.h
dirs.o: ../templates/htmltextstream.h ../notify/notifythread.h
dirs.o: ../core/basethread.h synchro.h ../notify/templatesnotify.h
dirs.o: ../core/config.h ../core/users.h ugcontainer.h lastcontainer.h
groups.o: groups.h group.h ugcontainer.h ../db/db.h ../db/dbbase.h
groups.o: ../db/dbconn.h ../db/dbtextstream.h ../core/textstream.h misc.h
groups.o: item.h ../core/error.h log.h textstream.h ../db/dbitemquery.h
groups.o: ../core/item.h ../db/dbitemcolumns.h ../core/user.h ../core/group.h
groups.o: ../core/thread.h ../core/dircontainer.h ../core/ugcontainer.h
htmlfilter.o: htmlfilter.h
httpsimpleparser.o: httpsimpleparser.h
lastcontainer.o: lastcontainer.h log.h
loadavg.o: loadavg.h log.h
locale.o: locale.h ../confparser/confparser.h log.h
log.o: log.h
misc.o: misc.h item.h log.h data.h dirs.h dircontainer.h users.h user.h
misc.o: ugcontainer.h groups.h group.h functions.h function.h lastcontainer.h
misc.o: mounts.h mount.h error.h rebus.h loadavg.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 rebus.h
mountparser.o: loadavg.h misc.h
mounts.o: mounts.h mount.h error.h log.h data.h dirs.h item.h dircontainer.h
mounts.o: users.h user.h ugcontainer.h groups.h group.h functions.h
mounts.o: function.h lastcontainer.h rebus.h loadavg.h request.h
mounts.o: requesttypes.h session.h plugindata.h thread.h compress.h
mounts.o: acceptencodingparser.h acceptbaseparser.h htmlfilter.h
mounts.o: postmultiparser.h ticket.h mountparser.h db.h
notify.o: log.h notify.h ../templatesnotify/templatesnotify.h ../core/mount.h
notify.o: ../core/locale.h ../confparser/confparser.h ../templates/misc.h
notify.o: ../templates/localefilter.h data.h dirs.h item.h dircontainer.h
notify.o: users.h user.h ugcontainer.h groups.h group.h functions.h
notify.o: function.h lastcontainer.h mounts.h mount.h error.h rebus.h
notify.o: loadavg.h misc.h request.h requesttypes.h session.h plugindata.h
notify.o: thread.h compress.h acceptencodingparser.h acceptbaseparser.h
notify.o: htmlfilter.h postmultiparser.h ticket.h
plugin.o: plugin.h request.h requesttypes.h session.h item.h error.h log.h
plugin.o: user.h rebus.h plugindata.h function.h thread.h compress.h
plugin.o: acceptencodingparser.h acceptbaseparser.h htmlfilter.h
plugin.o: postmultiparser.h ticket.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 loadavg.h pluginmsg.h
plugindata.o: plugindata.h plugin.h request.h requesttypes.h session.h item.h
plugindata.o: error.h log.h user.h rebus.h function.h thread.h compress.h
plugindata.o: acceptencodingparser.h acceptbaseparser.h htmlfilter.h
plugindata.o: postmultiparser.h ticket.h data.h dirs.h dircontainer.h users.h
plugindata.o: ugcontainer.h groups.h group.h functions.h lastcontainer.h
plugindata.o: mounts.h mount.h loadavg.h pluginmsg.h
postmultiparser.o: postmultiparser.h error.h log.h requesttypes.h data.h
postmultiparser.o: dirs.h item.h dircontainer.h users.h user.h ugcontainer.h
postmultiparser.o: groups.h group.h functions.h function.h lastcontainer.h
postmultiparser.o: mounts.h mount.h rebus.h loadavg.h
rebus.o: log.h rebus.h misc.h item.h
request.o: request.h requesttypes.h session.h item.h error.h log.h user.h
request.o: rebus.h plugindata.h function.h thread.h compress.h
request.o: acceptencodingparser.h acceptbaseparser.h htmlfilter.h
request.o: postmultiparser.h ticket.h getparser.h httpsimpleparser.h
request.o: postparser.h cookieparser.h data.h dirs.h dircontainer.h users.h
request.o: ugcontainer.h groups.h group.h functions.h lastcontainer.h
request.o: mounts.h mount.h loadavg.h plugin.h pluginmsg.h misc.h db.h
requestcontroller.o: requestcontroller.h ../content/content.h ../core/item.h
requestcontroller.o: ../templates/templates.h ../templates/patterncacher.h
requestcontroller.o: misc.h item.h ../templates/ckeditorgetparser.h
requestcontroller.o: ../core/httpsimpleparser.h ../core/log.h
requestcontroller.o: ../core/locale.h ../confparser/confparser.h
requestcontroller.o: ../core/thread.h ../core/ticket.h ../core/db.h user.h
requestcontroller.o: group.h thread.h error.h log.h dircontainer.h
requestcontroller.o: ugcontainer.h ticket.h sessionmanager.h
requestcontroller.o: sessioncontainer.h session.h rebus.h plugindata.h
requestcontroller.o: functionparser.h requesttypes.h data.h dirs.h users.h
requestcontroller.o: groups.h functions.h function.h lastcontainer.h mounts.h
requestcontroller.o: mount.h loadavg.h request.h compress.h
requestcontroller.o: acceptencodingparser.h acceptbaseparser.h htmlfilter.h
requestcontroller.o: postmultiparser.h postparser.h httpsimpleparser.h
requestcontroller.o: cookieparser.h notify.h
requestcontroller.o: ../templatesnotify/templatesnotify.h ../core/mount.h
requestcontroller.o: ../templates/misc.h ../templates/localefilter.h
session.o: session.h item.h error.h log.h user.h rebus.h plugindata.h
sessioncontainer.o: sessioncontainer.h session.h item.h error.h log.h user.h
sessioncontainer.o: rebus.h plugindata.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 loadavg.h
item.o: item.h misc.h
lastcontainer.o: lastcontainer.h log.h textstream.h misc.h item.h
loadavg.o: loadavg.h log.h textstream.h
log.o: log.h textstream.h ../../ezc/src/utf8.h
misc.o: misc.h item.h log.h textstream.h ../templates/templates.h
misc.o: ../../ezc/src/ezc.h ../../ezc/src/utf8.h ../../ezc/src/generator.h
misc.o: ../../ezc/src/pattern.h ../../ezc/src/functions.h
misc.o: ../../ezc/src/funinfo.h ../../ezc/src/stringconv.h
misc.o: ../templates/patterncacher.h ../core/item.h
misc.o: ../templates/ckeditorgetparser.h ../core/httpsimpleparser.h
misc.o: ../core/log.h ../templates/indexpatterns.h
misc.o: ../templates/localefilter.h ../templates/locale.h ../core/config.h
misc.o: ../db/db.h ../db/dbbase.h ../db/dbconn.h ../db/dbtextstream.h
misc.o: ../core/textstream.h ../core/error.h ../db/dbitemquery.h
misc.o: ../db/dbitemcolumns.h ../core/user.h ../core/group.h ../core/thread.h
misc.o: ../core/dircontainer.h ../core/ugcontainer.h
misc.o: ../templates/htmltextstream.h ../core/request.h ../core/system.h
misc.o: ../core/sessionmanager.h
mount.o: mount.h misc.h item.h
mountparser.o: mountparser.h mount.h item.h error.h dirs.h dircontainer.h
mountparser.o: ../db/db.h ../db/dbbase.h ../db/dbconn.h ../db/dbtextstream.h
mountparser.o: ../core/textstream.h misc.h ../core/error.h log.h textstream.h
mountparser.o: ../db/dbitemquery.h ../core/item.h ../db/dbitemcolumns.h
mountparser.o: ../core/user.h ../core/group.h ../core/thread.h
mountparser.o: ../core/dircontainer.h ../core/ugcontainer.h request.h
mountparser.o: requesttypes.h session.h user.h plugindata.h rebus.h config.h
mountparser.o: confparser.h htmlfilter.h ../templates/htmltextstream.h
mountparser.o: ../notify/notify.h ../notify/notifypool.h
mountparser.o: ../templates/locale.h ../core/confparser.h ../templates/misc.h
mountparser.o: ../templates/localefilter.h ../templates/locale.h
mountparser.o: ../../ezc/src/ezc.h ../../ezc/src/utf8.h
mountparser.o: ../../ezc/src/generator.h ../../ezc/src/pattern.h
mountparser.o: ../../ezc/src/functions.h ../../ezc/src/funinfo.h
mountparser.o: ../../ezc/src/stringconv.h ../templates/htmltextstream.h
mountparser.o: ../notify/notifythread.h ../core/basethread.h synchro.h
mountparser.o: ../notify/templatesnotify.h ../core/config.h ../core/users.h
mountparser.o: ugcontainer.h lastcontainer.h
mounts.o: mounts.h mount.h error.h dirs.h item.h dircontainer.h ../db/db.h
mounts.o: ../db/dbbase.h ../db/dbconn.h ../db/dbtextstream.h
mounts.o: ../core/textstream.h misc.h ../core/error.h log.h textstream.h
mounts.o: ../db/dbitemquery.h ../core/item.h ../db/dbitemcolumns.h
mounts.o: ../core/user.h ../core/group.h ../core/thread.h
mounts.o: ../core/dircontainer.h ../core/ugcontainer.h request.h
mounts.o: requesttypes.h session.h user.h plugindata.h rebus.h config.h
mounts.o: confparser.h htmlfilter.h ../templates/htmltextstream.h
mounts.o: ../notify/notify.h ../notify/notifypool.h ../templates/locale.h
mounts.o: ../core/confparser.h ../templates/misc.h
mounts.o: ../templates/localefilter.h ../templates/locale.h
mounts.o: ../../ezc/src/ezc.h ../../ezc/src/utf8.h ../../ezc/src/generator.h
mounts.o: ../../ezc/src/pattern.h ../../ezc/src/functions.h
mounts.o: ../../ezc/src/funinfo.h ../../ezc/src/stringconv.h
mounts.o: ../templates/htmltextstream.h ../notify/notifythread.h
mounts.o: ../core/basethread.h synchro.h ../notify/templatesnotify.h
mounts.o: ../core/config.h ../core/users.h ugcontainer.h lastcontainer.h
mounts.o: mountparser.h plugin.h pluginmsg.h system.h users.h groups.h
mounts.o: group.h loadavg.h thumb.h basethread.h sessionmanager.h
mounts.o: sessioncontainer.h ../functions/functions.h
mounts.o: ../functions/functionbase.h ../core/request.h ../core/system.h
mounts.o: ../core/synchro.h ../functions/functionparser.h
mounts.o: ../functions/adduser.h ../functions/cat.h ../functions/chmod.h
mounts.o: ../functions/privchanger.h ../functions/chown.h
mounts.o: ../functions/ckeditor.h ../functions/cp.h
mounts.o: ../functions/createthread.h ../functions/functionbase.h
mounts.o: ../functions/default.h ../functions/download.h ../functions/emacs.h
mounts.o: ../functions/last.h ../functions/login.h ../functions/logout.h
mounts.o: ../functions/ln.h ../functions/ls.h ../functions/mkdir.h
mounts.o: ../functions/mv.h ../functions/node.h ../functions/priv.h
mounts.o: ../functions/reload.h ../functions/rm.h ../functions/run.h
mounts.o: ../functions/specialdefault.h ../functions/stat.h
mounts.o: ../functions/subject.h ../functions/funthread.h
mounts.o: ../functions/template.h ../functions/tinymce.h ../functions/uname.h
mounts.o: ../functions/upload.h ../functions/uptime.h ../functions/who.h
mounts.o: ../functions/vim.h ../core/htmlfilter.h ../templates/templates.h
mounts.o: ../templates/patterncacher.h ../templates/ckeditorgetparser.h
mounts.o: ../core/httpsimpleparser.h ../core/log.h
mounts.o: ../templates/indexpatterns.h ../core/sessionmanager.h
plugin.o: plugin.h pluginmsg.h log.h textstream.h plugindata.h config.h
plugin.o: confparser.h htmlfilter.h request.h requesttypes.h session.h item.h
plugin.o: error.h user.h rebus.h ../templates/htmltextstream.h
plugin.o: ../core/textstream.h misc.h system.h dirs.h dircontainer.h
plugin.o: ../db/db.h ../db/dbbase.h ../db/dbconn.h ../db/dbtextstream.h
plugin.o: ../core/error.h ../db/dbitemquery.h ../core/item.h
plugin.o: ../db/dbitemcolumns.h ../core/user.h ../core/group.h
plugin.o: ../core/thread.h ../core/dircontainer.h ../core/ugcontainer.h
plugin.o: ../notify/notify.h ../notify/notifypool.h ../templates/locale.h
plugin.o: ../core/confparser.h ../templates/misc.h
plugin.o: ../templates/localefilter.h ../templates/locale.h
plugin.o: ../../ezc/src/ezc.h ../../ezc/src/utf8.h ../../ezc/src/generator.h
plugin.o: ../../ezc/src/pattern.h ../../ezc/src/functions.h
plugin.o: ../../ezc/src/funinfo.h ../../ezc/src/stringconv.h
plugin.o: ../templates/htmltextstream.h ../notify/notifythread.h
plugin.o: ../core/basethread.h synchro.h ../notify/templatesnotify.h
plugin.o: ../core/config.h ../core/users.h ugcontainer.h lastcontainer.h
plugin.o: mounts.h mount.h mountparser.h users.h groups.h group.h loadavg.h
plugin.o: thumb.h basethread.h sessionmanager.h sessioncontainer.h
plugin.o: ../functions/functions.h ../functions/functionbase.h
plugin.o: ../core/request.h ../core/system.h ../core/synchro.h
plugin.o: ../functions/functionparser.h ../functions/adduser.h
plugin.o: ../functions/cat.h ../functions/chmod.h ../functions/privchanger.h
plugin.o: ../functions/chown.h ../functions/ckeditor.h ../functions/cp.h
plugin.o: ../functions/createthread.h ../functions/functionbase.h
plugin.o: ../functions/default.h ../functions/download.h ../functions/emacs.h
plugin.o: ../functions/last.h ../functions/login.h ../functions/logout.h
plugin.o: ../functions/ln.h ../functions/ls.h ../functions/mkdir.h
plugin.o: ../functions/mv.h ../functions/node.h ../functions/priv.h
plugin.o: ../functions/reload.h ../functions/rm.h ../functions/run.h
plugin.o: ../functions/specialdefault.h ../functions/stat.h
plugin.o: ../functions/subject.h ../functions/funthread.h
plugin.o: ../functions/template.h ../functions/tinymce.h ../functions/uname.h
plugin.o: ../functions/upload.h ../functions/uptime.h ../functions/who.h
plugin.o: ../functions/vim.h ../core/htmlfilter.h ../templates/templates.h
plugin.o: ../templates/patterncacher.h ../templates/ckeditorgetparser.h
plugin.o: ../core/httpsimpleparser.h ../core/log.h
plugin.o: ../templates/indexpatterns.h ../core/sessionmanager.h
plugindata.o: plugindata.h plugin.h pluginmsg.h log.h textstream.h config.h
plugindata.o: confparser.h htmlfilter.h request.h requesttypes.h session.h
plugindata.o: item.h error.h user.h rebus.h ../templates/htmltextstream.h
plugindata.o: ../core/textstream.h misc.h system.h dirs.h dircontainer.h
plugindata.o: ../db/db.h ../db/dbbase.h ../db/dbconn.h ../db/dbtextstream.h
plugindata.o: ../core/error.h ../db/dbitemquery.h ../core/item.h
plugindata.o: ../db/dbitemcolumns.h ../core/user.h ../core/group.h
plugindata.o: ../core/thread.h ../core/dircontainer.h ../core/ugcontainer.h
plugindata.o: ../notify/notify.h ../notify/notifypool.h ../templates/locale.h
plugindata.o: ../core/confparser.h ../templates/misc.h
plugindata.o: ../templates/localefilter.h ../templates/locale.h
plugindata.o: ../../ezc/src/ezc.h ../../ezc/src/utf8.h
plugindata.o: ../../ezc/src/generator.h ../../ezc/src/pattern.h
plugindata.o: ../../ezc/src/functions.h ../../ezc/src/funinfo.h
plugindata.o: ../../ezc/src/stringconv.h ../templates/htmltextstream.h
plugindata.o: ../notify/notifythread.h ../core/basethread.h synchro.h
plugindata.o: ../notify/templatesnotify.h ../core/config.h ../core/users.h
plugindata.o: ugcontainer.h lastcontainer.h mounts.h mount.h mountparser.h
plugindata.o: users.h groups.h group.h loadavg.h thumb.h basethread.h
plugindata.o: sessionmanager.h sessioncontainer.h ../functions/functions.h
plugindata.o: ../functions/functionbase.h ../core/request.h ../core/system.h
plugindata.o: ../core/synchro.h ../functions/functionparser.h
plugindata.o: ../functions/adduser.h ../functions/cat.h ../functions/chmod.h
plugindata.o: ../functions/privchanger.h ../functions/chown.h
plugindata.o: ../functions/ckeditor.h ../functions/cp.h
plugindata.o: ../functions/createthread.h ../functions/functionbase.h
plugindata.o: ../functions/default.h ../functions/download.h
plugindata.o: ../functions/emacs.h ../functions/last.h ../functions/login.h
plugindata.o: ../functions/logout.h ../functions/ln.h ../functions/ls.h
plugindata.o: ../functions/mkdir.h ../functions/mv.h ../functions/node.h
plugindata.o: ../functions/priv.h ../functions/reload.h ../functions/rm.h
plugindata.o: ../functions/run.h ../functions/specialdefault.h
plugindata.o: ../functions/stat.h ../functions/subject.h
plugindata.o: ../functions/funthread.h ../functions/template.h
plugindata.o: ../functions/tinymce.h ../functions/uname.h
plugindata.o: ../functions/upload.h ../functions/uptime.h ../functions/who.h
plugindata.o: ../functions/vim.h ../core/htmlfilter.h
plugindata.o: ../templates/templates.h ../templates/patterncacher.h
plugindata.o: ../templates/ckeditorgetparser.h ../core/httpsimpleparser.h
plugindata.o: ../core/log.h ../templates/indexpatterns.h
plugindata.o: ../core/sessionmanager.h
postmultiparser.o: postmultiparser.h error.h requesttypes.h config.h
postmultiparser.o: confparser.h htmlfilter.h log.h textstream.h
postmultiparser.o: ../../ezc/src/utf8.h misc.h item.h
rebus.o: log.h textstream.h rebus.h misc.h item.h request.h requesttypes.h
rebus.o: session.h error.h user.h plugindata.h config.h confparser.h
rebus.o: htmlfilter.h ../templates/htmltextstream.h ../core/textstream.h
request.o: request.h requesttypes.h session.h item.h error.h user.h
request.o: plugindata.h rebus.h config.h confparser.h htmlfilter.h
request.o: textstream.h ../templates/htmltextstream.h ../core/textstream.h
request.o: misc.h log.h plugin.h pluginmsg.h system.h dirs.h dircontainer.h
request.o: ../db/db.h ../db/dbbase.h ../db/dbconn.h ../db/dbtextstream.h
request.o: ../core/error.h ../db/dbitemquery.h ../core/item.h
request.o: ../db/dbitemcolumns.h ../core/user.h ../core/group.h
request.o: ../core/thread.h ../core/dircontainer.h ../core/ugcontainer.h
request.o: ../notify/notify.h ../notify/notifypool.h ../templates/locale.h
request.o: ../core/confparser.h ../templates/misc.h
request.o: ../templates/localefilter.h ../templates/locale.h
request.o: ../../ezc/src/ezc.h ../../ezc/src/utf8.h ../../ezc/src/generator.h
request.o: ../../ezc/src/pattern.h ../../ezc/src/functions.h
request.o: ../../ezc/src/funinfo.h ../../ezc/src/stringconv.h
request.o: ../templates/htmltextstream.h ../notify/notifythread.h
request.o: ../core/basethread.h synchro.h ../notify/templatesnotify.h
request.o: ../core/config.h ../core/users.h ugcontainer.h lastcontainer.h
request.o: mounts.h mount.h mountparser.h users.h groups.h group.h loadavg.h
request.o: thumb.h basethread.h sessionmanager.h sessioncontainer.h
request.o: ../functions/functions.h ../functions/functionbase.h
request.o: ../core/request.h ../core/system.h ../core/synchro.h
request.o: ../functions/functionparser.h ../functions/adduser.h
request.o: ../functions/cat.h ../functions/chmod.h ../functions/privchanger.h
request.o: ../functions/chown.h ../functions/ckeditor.h ../functions/cp.h
request.o: ../functions/createthread.h ../functions/functionbase.h
request.o: ../functions/default.h ../functions/download.h
request.o: ../functions/emacs.h ../functions/last.h ../functions/login.h
request.o: ../functions/logout.h ../functions/ln.h ../functions/ls.h
request.o: ../functions/mkdir.h ../functions/mv.h ../functions/node.h
request.o: ../functions/priv.h ../functions/reload.h ../functions/rm.h
request.o: ../functions/run.h ../functions/specialdefault.h
request.o: ../functions/stat.h ../functions/subject.h
request.o: ../functions/funthread.h ../functions/template.h
request.o: ../functions/tinymce.h ../functions/uname.h ../functions/upload.h
request.o: ../functions/uptime.h ../functions/who.h ../functions/vim.h
request.o: ../core/htmlfilter.h ../templates/templates.h
request.o: ../templates/patterncacher.h ../templates/ckeditorgetparser.h
request.o: ../core/httpsimpleparser.h ../core/log.h
request.o: ../templates/indexpatterns.h ../core/sessionmanager.h
session.o: session.h item.h error.h user.h plugindata.h rebus.h misc.h
sessioncontainer.o: sessioncontainer.h session.h item.h error.h user.h
sessioncontainer.o: plugindata.h rebus.h lastcontainer.h request.h
sessioncontainer.o: requesttypes.h config.h confparser.h htmlfilter.h
sessioncontainer.o: textstream.h ../templates/htmltextstream.h
sessioncontainer.o: ../core/textstream.h misc.h basethread.h log.h
sessionmanager.o: sessionmanager.h sessioncontainer.h session.h item.h
sessionmanager.o: error.h log.h user.h rebus.h plugindata.h request.h
sessionmanager.o: requesttypes.h function.h thread.h compress.h
sessionmanager.o: acceptencodingparser.h acceptbaseparser.h htmlfilter.h
sessionmanager.o: postmultiparser.h ticket.h data.h dirs.h dircontainer.h
sessionmanager.o: users.h ugcontainer.h groups.h group.h functions.h
sessionmanager.o: lastcontainer.h mounts.h mount.h loadavg.h sessionparser.h
sessionmanager.o: plugin.h pluginmsg.h
sessionparser.o: sessionparser.h session.h item.h error.h log.h user.h
sessionparser.o: rebus.h plugindata.h sessioncontainer.h data.h dirs.h
sessionparser.o: dircontainer.h users.h ugcontainer.h groups.h group.h
sessionparser.o: functions.h function.h lastcontainer.h mounts.h mount.h
sessionparser.o: loadavg.h
users.o: users.h user.h ugcontainer.h log.h db.h item.h group.h thread.h
users.o: error.h dircontainer.h ticket.h
sessionmanager.o: error.h user.h plugindata.h rebus.h lastcontainer.h
sessionmanager.o: request.h requesttypes.h config.h confparser.h htmlfilter.h
sessionmanager.o: textstream.h ../templates/htmltextstream.h
sessionmanager.o: ../core/textstream.h misc.h basethread.h system.h dirs.h
sessionmanager.o: dircontainer.h ../db/db.h ../db/dbbase.h ../db/dbconn.h
sessionmanager.o: ../db/dbtextstream.h ../core/error.h log.h
sessionmanager.o: ../db/dbitemquery.h ../core/item.h ../db/dbitemcolumns.h
sessionmanager.o: ../core/user.h ../core/group.h ../core/thread.h
sessionmanager.o: ../core/dircontainer.h ../core/ugcontainer.h
sessionmanager.o: ../notify/notify.h ../notify/notifypool.h
sessionmanager.o: ../templates/locale.h ../core/confparser.h
sessionmanager.o: ../templates/misc.h ../templates/localefilter.h
sessionmanager.o: ../templates/locale.h ../../ezc/src/ezc.h
sessionmanager.o: ../../ezc/src/utf8.h ../../ezc/src/generator.h
sessionmanager.o: ../../ezc/src/pattern.h ../../ezc/src/functions.h
sessionmanager.o: ../../ezc/src/funinfo.h ../../ezc/src/stringconv.h
sessionmanager.o: ../templates/htmltextstream.h ../notify/notifythread.h
sessionmanager.o: ../core/basethread.h synchro.h ../notify/templatesnotify.h
sessionmanager.o: ../core/config.h ../core/users.h ugcontainer.h mounts.h
sessionmanager.o: mount.h mountparser.h users.h groups.h group.h loadavg.h
sessionmanager.o: thumb.h sessionparser.h plugin.h pluginmsg.h
sessionmanager.o: ../functions/functions.h ../functions/functionbase.h
sessionmanager.o: ../core/request.h ../core/system.h ../core/synchro.h
sessionmanager.o: ../functions/functionparser.h ../functions/adduser.h
sessionmanager.o: ../functions/cat.h ../functions/chmod.h
sessionmanager.o: ../functions/privchanger.h ../functions/chown.h
sessionmanager.o: ../functions/ckeditor.h ../functions/cp.h
sessionmanager.o: ../functions/createthread.h ../functions/functionbase.h
sessionmanager.o: ../functions/default.h ../functions/download.h
sessionmanager.o: ../functions/emacs.h ../functions/last.h
sessionmanager.o: ../functions/login.h ../functions/logout.h
sessionmanager.o: ../functions/ln.h ../functions/ls.h ../functions/mkdir.h
sessionmanager.o: ../functions/mv.h ../functions/node.h ../functions/priv.h
sessionmanager.o: ../functions/reload.h ../functions/rm.h ../functions/run.h
sessionmanager.o: ../functions/specialdefault.h ../functions/stat.h
sessionmanager.o: ../functions/subject.h ../functions/funthread.h
sessionmanager.o: ../functions/template.h ../functions/tinymce.h
sessionmanager.o: ../functions/uname.h ../functions/upload.h
sessionmanager.o: ../functions/uptime.h ../functions/who.h ../functions/vim.h
sessionmanager.o: ../core/htmlfilter.h ../templates/templates.h
sessionmanager.o: ../templates/patterncacher.h
sessionmanager.o: ../templates/ckeditorgetparser.h ../core/httpsimpleparser.h
sessionmanager.o: ../core/log.h ../templates/indexpatterns.h
sessionmanager.o: ../core/sessionmanager.h
sessionparser.o: sessionparser.h session.h item.h error.h user.h plugindata.h
sessionparser.o: rebus.h sessioncontainer.h lastcontainer.h request.h
sessionparser.o: requesttypes.h config.h confparser.h htmlfilter.h
sessionparser.o: textstream.h ../templates/htmltextstream.h
sessionparser.o: ../core/textstream.h misc.h basethread.h users.h log.h
synchro.o: synchro.h
system.o: system.h dirs.h item.h dircontainer.h ../db/db.h ../db/dbbase.h
system.o: ../db/dbconn.h ../db/dbtextstream.h ../core/textstream.h misc.h
system.o: ../core/error.h log.h textstream.h ../db/dbitemquery.h
system.o: ../core/item.h ../db/dbitemcolumns.h ../core/user.h ../core/group.h
system.o: ../core/thread.h ../core/dircontainer.h ../core/ugcontainer.h
system.o: request.h requesttypes.h session.h error.h user.h plugindata.h
system.o: rebus.h config.h confparser.h htmlfilter.h
system.o: ../templates/htmltextstream.h ../notify/notify.h
system.o: ../notify/notifypool.h ../templates/locale.h ../core/confparser.h
system.o: ../templates/misc.h ../templates/localefilter.h
system.o: ../templates/locale.h ../../ezc/src/ezc.h ../../ezc/src/utf8.h
system.o: ../../ezc/src/generator.h ../../ezc/src/pattern.h
system.o: ../../ezc/src/functions.h ../../ezc/src/funinfo.h
system.o: ../../ezc/src/stringconv.h ../templates/htmltextstream.h
system.o: ../notify/notifythread.h ../core/basethread.h synchro.h
system.o: ../notify/templatesnotify.h ../core/config.h ../core/users.h
system.o: ugcontainer.h lastcontainer.h mounts.h mount.h mountparser.h
system.o: users.h groups.h group.h loadavg.h thumb.h basethread.h
system.o: ../templates/templates.h ../templates/patterncacher.h
system.o: ../templates/ckeditorgetparser.h ../core/httpsimpleparser.h
system.o: ../core/log.h ../templates/indexpatterns.h ../core/request.h
system.o: ../core/system.h ../core/sessionmanager.h
system.o: ../functions/functionbase.h
textstream.o: textstream.h misc.h item.h
thumb.o: thumb.h basethread.h textstream.h ../db/db.h ../db/dbbase.h
thumb.o: ../db/dbconn.h ../db/dbtextstream.h ../core/textstream.h misc.h
thumb.o: item.h ../core/error.h log.h ../db/dbitemquery.h ../core/item.h
thumb.o: ../db/dbitemcolumns.h ../core/user.h ../core/group.h
thumb.o: ../core/thread.h ../core/dircontainer.h ../core/ugcontainer.h
thumb.o: ../core/config.h ../../ezc/src/utf8.h system.h dirs.h dircontainer.h
thumb.o: request.h requesttypes.h session.h error.h user.h plugindata.h
thumb.o: rebus.h config.h confparser.h htmlfilter.h
thumb.o: ../templates/htmltextstream.h ../notify/notify.h
thumb.o: ../notify/notifypool.h ../templates/locale.h ../core/confparser.h
thumb.o: ../templates/misc.h ../templates/localefilter.h
thumb.o: ../templates/locale.h ../../ezc/src/ezc.h ../../ezc/src/generator.h
thumb.o: ../../ezc/src/pattern.h ../../ezc/src/functions.h
thumb.o: ../../ezc/src/funinfo.h ../../ezc/src/stringconv.h
thumb.o: ../templates/htmltextstream.h ../notify/notifythread.h
thumb.o: ../core/basethread.h synchro.h ../notify/templatesnotify.h
thumb.o: ../core/users.h ugcontainer.h lastcontainer.h mounts.h mount.h
thumb.o: mountparser.h users.h groups.h group.h loadavg.h
users.o: users.h

View File

@@ -1 +1 @@
o = acceptbaseparser.o compress.o config.o data.o db.o db_itemcolumns.o dircontainer.o dirs.o function.o functioncodeparser.o functionparser.o functions.o groups.o htmlfilter.o httpsimpleparser.o lastcontainer.o loadavg.o locale.o log.o misc.o mount.o mountparser.o mounts.o notify.o plugin.o plugindata.o postmultiparser.o rebus.o request.o requestcontroller.o session.o sessioncontainer.o sessionmanager.o sessionparser.o users.o
o = acceptbaseparser.o app.o basethread.o bbcodeparser.o compress.o config.o confparser.o dircontainer.o dirs.o groups.o htmlfilter.o httpsimpleparser.o item.o lastcontainer.o loadavg.o log.o misc.o mount.o mountparser.o mounts.o plugin.o plugindata.o postmultiparser.o rebus.o request.o session.o sessioncontainer.o sessionmanager.o sessionparser.o synchro.o system.o textstream.o thumb.o users.o

1061
core/app.cpp Executable file

File diff suppressed because it is too large Load Diff

177
core/app.h Executable file
View File

@@ -0,0 +1,177 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslucoreapp
#define headerfilecmslucoreapp
#include <iostream>
#include <ctime>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <pwd.h>
#include <grp.h>
#include <errno.h>
#include <fcgiapp.h>
#include "config.h"
#include "system.h"
#include "mounts.h"
#include "request.h"
#include "synchro.h"
#include "sessionmanager.h"
#include "db/db.h"
#include "functions/functions.h"
#include "templates/templates.h"
#include "compress.h"
#include "htmlfilter.h"
#include "getparser.h"
#include "postparser.h"
#include "cookieparser.h"
#include "postmultiparser.h"
#include "acceptencodingparser.h"
class App
{
public:
App();
bool InitFCGI();
bool DropPrivileges();
bool Init();
void Start();
void Close();
void LogUserGroups();
bool Demonize();
void SetStopSignal();
bool WasStopSignal();
bool Lock();
void Unlock();
void StartThreads();
void WaitForThreads();
// configuration read from a config file
Config config;
// current request
Request request;
// users sessions
SessionManager session_manager;
// database
Db db;
DbConn db_conn;
/*
model
*/
// file system
System system;
// false at the beginning
// !! moze to do loggera dac?
bool stdout_is_closed;
/*
controllers
(note that the whole app object is actually a controller too)
*/
// functions (ls, cat, emacs, ...)
Functions functions;
/*
view
*/
Templates templates;
private:
enum Header
{
h_200,
h_404,
h_403
};
GetParser get_parser;
PostParser post_parser;
PostMultiParser post_multi_parser;
CookieParser cookie_parser;
AcceptEncodingParser accept_encoding_parser;
Compress compress;
HTMLFilter html_filter;
std::wstring clean_html, html_with_debug;
FCGX_Request fcgi_request;
int fcgi_socket;
Synchro synchro;
pthread_t signal_thread;
std::string url_to_fetch_on_exit;
void ProcessRequestThrow();
void ProcessRequest();
bool BaseUrlRedirect();
void MakePage();
void Make();
void SaveSessionsIfNeeded(); // !! wywalic do menagera sesji??
void LogAccess();
void ReadRequest();
void SendAnswer();
void SetEnv(const char * & env, const char * name);
void ReadEnvVariables();
void ReadGetPostVars();
void CheckIE();
void CheckKonqueror();
void CheckRequestMethod();
void CheckFCGIRole();
void SetHtmlFilterConf();
void PrepareSessionCookie();
void AddDebugInfo(std::wstring & out);
void FilterCompressSend(bool compressing, const std::wstring & source_ref);
void SendHeaders(bool compressing, Header header);
bool IsCompressionAllowed(const std::wstring & source);
bool CanSendContent(Header header);
void LogUser(const char * msg, uid_t id);
void LogGroup(const char * msg, gid_t id, bool put_logend = true);
void LogUsers();
void LogEffectiveGroups(std::vector<gid_t> & tab);
void LogGroups();
bool DropPrivileges(const std::string & user, uid_t uid, gid_t gid, bool additional_groups);
static void * SpecialThreadForSignals(void*);
void FetchPageOnExit();
void CreateStaticTree();
// !! dodac do session managera?
time_t last_sessions_save;
};
#endif

229
core/basethread.cpp Executable file
View File

@@ -0,0 +1,229 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2010, Tomasz Sowa
* All rights reserved.
*
*/
#include <errno.h>
#include "basethread.h"
#include "log.h"
BaseThread::BaseThread() : thread_signal(PTHREAD_COND_INITIALIZER)
{
synchro = 0;
thread_id = 0;
work_mode = 0;
wake_up_was_called = false;
}
void BaseThread::SetSynchro(Synchro * psynchro)
{
synchro = psynchro;
}
void BaseThread::Mode(int mode)
{
work_mode = mode;
}
bool BaseThread::Lock()
{
return synchro->Lock();
}
void BaseThread::Unlock()
{
synchro->Unlock();
}
bool BaseThread::IsExitSignal()
{
bool res = true;
if( Lock() )
{
res = synchro->was_stop_signal;
Unlock();
}
return res;
}
bool BaseThread::BaseInit()
{
bool init_status = false;
if( Lock() )
{
init_status = Init(); // your virtual method
Unlock();
}
return init_status;
}
void BaseThread::BaseUninit()
{
if( Lock() )
{
Uninit(); // your virtual method
Unlock();
}
}
bool BaseThread::BaseSignalReceived()
{
bool make_do = false;
wake_up_was_called = false;
try
{
make_do = SignalReceived(); // your short-time virtual method (objects are locked)
}
catch(...)
{
}
return make_do;
}
// this is called only if your SignalReceived() returned true
void BaseThread::BaseDo()
{
try
{
Do(); // your long-time virtual method (objects are *not* locked)
}
catch(...)
{
}
}
// use it with Lock and Unlock
bool BaseThread::WaitForSignal()
{
if( synchro->was_stop_signal || wake_up_was_called )
return true;
return pthread_cond_wait(&thread_signal, &synchro->mutex) == 0;
}
// you should use this method with: synchro->Lock() and Unlock()
void BaseThread::WakeUpThread()
{
wake_up_was_called = true;
pthread_cond_signal(&thread_signal);
}
// use it with Lock and Unlock
// it breaks only if there was a stop signal or the time has expired
bool BaseThread::WaitForSignalSleep(time_t second)
{
timespec t;
int res;
t.tv_sec = time(0) + second;
t.tv_nsec = 0;
do
{
res = pthread_cond_timedwait(&thread_signal, &synchro->mutex, &t);
}
while( res == 0 && !synchro->was_stop_signal );
// above condition means there was a signal
// but it was not a stop signal so we should still wait
return res == 0 || res == ETIMEDOUT;
}
void BaseThread::WaitForThread()
{
pthread_join(thread_id, 0);
}
void BaseThread::SignalLoop()
{
bool make_do;
do
{
if( Lock() )
{
make_do = false;
if( WaitForSignal() ) // automatically unlock, wait and lock again when signal comes
if( !synchro->was_stop_signal )
make_do = BaseSignalReceived(); // your short-time virtual method will be called (objects locked)
Unlock(); // unlocking from WaitForSignal()
if( make_do )
BaseDo(); // your long-time virtual method will be called (objects *not* locked)
}
}
while( !IsExitSignal() );
}
void * BaseThread::StartRoutine(void * this_object)
{
BaseThread * base = reinterpret_cast<BaseThread*>(this_object);
if( base->synchro )
{
if( base->BaseInit() )
{
if( base->work_mode == 0 )
base->SignalLoop();
else
base->Work();
base->BaseUninit();
}
}
pthread_exit(0);
return 0;
}
bool BaseThread::StartThread()
{
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
int res = pthread_create(&thread_id, &attr, StartRoutine, this);
pthread_attr_destroy(&attr);
return res == 0;
}

121
core/basethread.h Executable file
View File

@@ -0,0 +1,121 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslucorebasethread
#define headerfilecmslucorebasethread
#include <pthread.h>
#include "synchro.h"
class BaseThread
{
public:
BaseThread();
// synchro object (must be set)
void SetSynchro(Synchro * psynchro);
// work mode
// we have two modes:
// 0 - there is a loop with SignalReceived() and Do()
// if SignalReceived() returns true then Do() is called
// 1 - only Work() method is called
// the thread exits after Work() has finished
// default: 0
void Mode(int mode);
// starting the second thread
bool StartThread();
// wake up the second thread
// (if it waits for the signal)
// you should use it with: synchro->Lock() and Unlock()
// if the thread doesn't wait on a signal then nothing is done
void WakeUpThread();
// waiting until the thread exits
// you should call WakeUpThread() before
void WaitForThread();
// virtual methods which should/can be inherited by your class
// the methods will be called from the other thread
// initialize the thread
// (global objects are locked)
// if it returns false then the thread immediately exits
// default: true
virtual bool Init() { return true; }
// uninitialize the thread
// this is called before the thread is prepare to detach
// (global objects are locked)
// it's called only if Init() returned true
virtual void Uninit() {}
protected:
// signal came (work mode = 0 - default)
// signal comes when an other thread calls WakeUpThread() method
// check specific job and return true to call Do() next
// (global objects are locked -- copy some global objects to local variables)
virtual bool SignalReceived() { return false; };
// if SignalReceived() returned true then this method is called
// global objects are *not* locked -- use only your local variables
// if you have to do something on global objects use synchro->Lock() and synchro->Unlock()
virtual void Do() {}
// this method is called after Init() when Mode(1) is used
// this is for long-time job
// this method is called only once
// global objects are *not* locked
virtual void Work() {}
protected:
Synchro * synchro;
pthread_t thread_id; // thread id - set by StartThread()
pthread_cond_t thread_signal;
int work_mode;
bool wake_up_was_called;
void SignalLoop();
static void * StartRoutine(void *);
bool BaseInit();
void BaseUninit();
bool BaseSignalReceived();
void BaseDo();
bool WaitForSignal();
bool WaitForSignalSleep(time_t second);
bool Lock();
void Unlock();
// if the work done by Do() is long time consuming you should periodically check
// wheter there was a signal for exiting, and if it was just simply return from Do()
// (it's checking with locking and unlocking)
bool IsExitSignal();
};
#endif

577
core/bbcodeparser.cpp Executable file
View File

@@ -0,0 +1,577 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "bbcodeparser.h"
bool BBCODEParser::Equal(const wchar_t * str1, const wchar_t * str2)
{
while( *str1 == *str2 && *str1 != 0 )
{
str1 += 1;
str2 += 1;
}
return *str1 == *str2;
}
bool BBCODEParser::IsValidCharForName(int c)
{
if( (c>='a' && c<='z') ||
(c>='A' && c<='Z') ||
c=='*' || c=='_')
return true;
return false;
}
bool BBCODEParser::IsOpeningTagMark()
{
return (*pchar == '[');
}
// there are no commentaries in bbcode
bool BBCODEParser::IsOpeningCommentaryTagMark()
{
return false;
}
bool BBCODEParser::SkipCommentaryTagIfExists()
{
return false;
}
bool BBCODEParser::IsClosingTagMark()
{
return (*pchar == ']');
}
bool BBCODEParser::IsClosingXmlSimpleTagMark()
{
return false;
}
// one enter will generate one <br>
// two enters or more will generate only two br (<br><br>)
void BBCODEParser::PutNormalText(const wchar_t * str, const wchar_t * end)
{
int br_len;
if( *pchar == 0 )
{
// trimming last white characters at end of the user text
while( str<end && (IsWhite(*(end-1)) || *(end-1)==10) )
--end;
}
while( str < end )
{
if( *str == 10 )
{
++str;
br_len = 1;
// skipping white characters without a new line character
while( str < end && IsWhite(*str) )
++str;
if( str < end && *str == 10 )
{
br_len = 2;
// skipping white characters with new line characters
while( str < end && (IsWhite(*str) || *str==10) )
++str;
}
if( !has_open_ol_tag && !has_open_ul_tag && !has_open_li_tag )
{
for(int i=0 ; i < br_len ; ++i)
(*out_string) += L"<br>\n";
}
}
else
{
PrintEscape(*str);
++str;
}
}
}
void BBCODEParser::PutNormalTextTrim(const wchar_t * str, const wchar_t * end)
{
// we don't use trimming in bbcode parser
PutNormalText(str, end);
}
void BBCODEParser::ReadNormalTextSkipWhite(const wchar_t * & start, const wchar_t * & last_non_white)
{
}
void BBCODEParser::CheckExceptions()
{
if( stack_len >= 2 )
{
if( pstack[stack_len-1].type == Item::opening &&
pstack[stack_len-2].type == Item::opening &&
IsNameEqual(L"*", pstack[stack_len-1].name) &&
IsNameEqual(L"*", pstack[stack_len-2].name) )
{
// removing the last [*] from the stack
// </li> was put automatically
PopStack();
}
}
}
/*
bbcode format:
[bbcodetag=value]some text[/bbcodetag]
the value can be quoted, e.g.
[bbcodetag="value"]some text[/bbcodetag], or
[bbcodetag='value']some text[/bbcodetag]
the third string below (in tags table) is 'html_argument' from Tags,
it can contain a special character % followed by a string which means:
%1 - "value" escaped as for html
%2 - "some text" escaped as for html
%u1 - "value" trimmed and escaped as for url-es
%u2 - "some text" trimmed and escaped as for url-es
%% - one %
if you are using %2 or %u2 then "some text" is not treated as bbcode, e.g.
[bbcodetag=value]some [b]text[/b][/bbcodetag] will produce:
<htmltag arg="value">some [b]text[/b]</htmltag> (the inner tags [b][/b] were not parsed)
also when using %2 or %u2 the closing bbcode tag is skipped
(if you want this tag then you can put it in 'html_argument')
and when using u (%u1 or %u2) the argument is trimmed from whitespaces and new lines
at the beginning and at the end
(because otherwise a space would be changed to %20 and this were probably not what you really wanted)
*/
const BBCODEParser::Tags * BBCODEParser::FindTag(const wchar_t * tag)
{
static Tags tags[] = {
{L"*", L"li", L">", false},
{L"b", L"em", L">", true},
{L"i", L"span", L" class=\"bbitalic\">", true},
{L"u", L"span", L" class=\"bbunderline\">", true},
{L"s", L"span", L" class=\"bbstrike\">", true},
{L"code", L"code", L" class=\"bbcode\">", false},
{L"list", L"ul", L" class=\"bblist\">", false},
{L"color", L"span", L" class=\"bbcol%1\">", true},
{L"url", L"a", L" href=\"%u1\">", true},
{L"img", L"img", L" alt=\"%1\" src=\"%u2\">", true},
{L"quote", L"div", L" class=\"bbquote\">\n<span class=\"bbquotewho\">%1</span><br>\n", false},
};
size_t i;
size_t len = sizeof(tags) / sizeof(Tags);
for(i=0 ; i<len ; ++i)
{
if( Equal(tag, tags[i].bbcode) )
return &tags[i];
}
return 0;
}
void BBCODEParser::PrintArgumentCheckQuotes(const wchar_t * & start, const wchar_t * & end)
{
// skipping white characters from the argument
while( start<end && IsWhite(*start) )
++start;
// skipping first '=' character if exists
if( start<end && *start == '=' )
++start;
// skipping white characters from the argument
// at the beginning
while( start<end && IsWhite(*start) )
++start;
// and at the end
while( start<end && IsWhite(*(end-1)) )
--end;
if( start<end && (*start=='\'' || *start=='\"') )
{
++start;
if( start<end && *(start-1) == *(end-1) )
--end;
// skipping white characters after a first quote char [url = " ww...."]
while( start<end && IsWhite(*start) )
++start;
}
}
void BBCODEParser::PrintEncode(int c)
{
if( c == '&' )
{
(*out_string) += L"&amp;";
}
else
if( (c>='a' && c<='z') ||
(c>='A' && c<='Z') ||
(c>='0' && c<='9') ||
(c=='_' || c=='?' || c=='.' || c==',' || c=='/' || c=='-' ||
c=='+' || c=='*' || c=='(' || c==')' || c=='=' || c==':')
)
{
(*out_string) += c;
}
else
{
wchar_t buffer[20];
swprintf(buffer, 20, L"%02X", c);
(*out_string) += '%';
(*out_string) += buffer;
}
}
void BBCODEParser::PrintEscape(int c, bool change_quote)
{
if( c == '<' )
{
(*out_string) += L"&lt;";
}
else
if( c == '>' )
{
(*out_string) += L"&gt;";
}
else
if( c == '&' )
{
(*out_string) += L"&amp;";
}
else
if( c == '\"' && change_quote )
{
(*out_string) += L"&quot;";
}
else
{
(*out_string) += c;
}
}
void BBCODEParser::PrintArgumentEncode(const wchar_t * start, const wchar_t * end)
{
PrintArgumentCheckQuotes(start, end);
TrimWhiteWithNewLines(start, end);
for( ; start<end ; ++start )
PrintEncode(*start);
}
void BBCODEParser::PrintArgumentEscape(const wchar_t * start, const wchar_t * end)
{
PrintArgumentCheckQuotes(start, end);
for( ; start<end ; ++start )
PrintEscape(*start, true); // quotes are escaped as well here
}
void BBCODEParser::CheckOpeningTag(const Tags * tag, const wchar_t * tag_name, bool & condition)
{
if( Equal(tag->html_tag, tag_name) )
{
if( condition )
{
PutClosingTag(tag);
(*out_string) += '\n';
}
condition = true;
}
}
void BBCODEParser::CheckOpeningTag(const Tags * tag)
{
bool has_list_tag = has_open_ul_tag || has_open_ol_tag;
CheckOpeningTag(tag, L"li", has_open_li_tag);
CheckOpeningTag(tag, L"ul", has_open_ul_tag);
CheckOpeningTag(tag, L"ol", has_open_ol_tag);
if( has_open_li_tag && !has_list_tag )
{
(*out_string) += L"<ul>\n";
has_open_ul_tag = true;
}
}
void BBCODEParser::PrintEscape(const wchar_t * start, const wchar_t * end, bool change_quote)
{
for( ; start < end ; ++start)
PrintEscape(*start, change_quote);
}
void BBCODEParser::PrintEncode(const wchar_t * start, const wchar_t * end)
{
for( ; start < end ; ++start)
PrintEncode(*start);
}
void BBCODEParser::PutOpeningTagFromEzc(const wchar_t * start, const wchar_t * end)
{
// this can be a tag from Ezc templates system
(*out_string) += '[';
(*out_string) += LastItem().name;
if( start != end )
{
(*out_string) += ' ';
PrintEscape(start, end);
}
(*out_string) += ']';
}
void BBCODEParser::PutHtmlArgument1(const wchar_t * arg_start, const wchar_t * arg_end, bool has_u)
{
if( has_u )
PrintArgumentEncode(arg_start, arg_end);
else
PrintArgumentEscape(arg_start, arg_end);
}
void BBCODEParser::TrimWhiteWithNewLines(const wchar_t * & start, const wchar_t * & end)
{
while( start < end && (IsWhite(*start) || *start==10) )
++start;
while( start < end && (IsWhite(*(end-1)) || *(end-1)==10) )
--end;
}
void BBCODEParser::PutHtmlArgument2(const Tags * tag, bool has_u)
{
const wchar_t * start = pchar;
const wchar_t * end = pchar;
bool first_tag_removed = false;
while( *pchar != 0 )
{
if( IsOpeningTagMark() )
{
if( IsClosingTagForLastItem() )
{
// the last tag is skipped when using patterns with %2 or %u2
PopStack(); // removing opening tag from the stack
first_tag_removed = true;
break;
}
}
else
{
pchar += 1;
end = pchar;
}
}
if( !first_tag_removed )
PopStack(); // user has forgotten to close the tag
if( has_u )
{
TrimWhiteWithNewLines(start, end);
PrintEncode(start, end);
}
else
{
PrintEscape(start, end);
}
}
void BBCODEParser::PutHtmlArgument(const Tags * tag, const wchar_t * arg_start, const wchar_t * arg_end)
{
const wchar_t * pattern = tag->html_argument;
bool has_u;
while( *pattern )
{
if( *pattern == '%' )
{
++pattern;
has_u = false;
if( *pattern == 'u' )
{
++pattern;
has_u = true;
}
if( *pattern == '1' )
{
++pattern;
PutHtmlArgument1(arg_start, arg_end, has_u);
}
else
if( *pattern == '2' )
{
++pattern;
PutHtmlArgument2(tag, has_u);
}
else
if( *pattern == '%' )
{
(*out_string) += '%';
++pattern;
}
// else unrecognized, will be printed next time as a normal character
}
else
{
(*out_string) += *pattern;
++pattern;
}
}
}
void BBCODEParser::PutOpeningTagFromBBCode(const Tags * tag, const wchar_t * start, const wchar_t * end)
{
CheckOpeningTag(tag);
PutOpeningTagMark();
(*out_string) += tag->html_tag;
PutHtmlArgument(tag, start, end);
if( !tag->inline_tag )
{
(*out_string) += L"\n";
SkipWhiteLines();
}
}
void BBCODEParser::PutOpeningTag(const wchar_t * start, const wchar_t * end)
{
const Tags * tag = FindTag(LastItem().name);
if( !tag )
{
PutOpeningTagFromEzc(start, end);
}
else
{
PutOpeningTagFromBBCode(tag, start, end);
}
}
void BBCODEParser::PutClosingTag(const Tags * tag)
{
if( !tag )
return; // skipping the tag
PutOpeningTagMark();
(*out_string) += '/';
(*out_string) += tag->html_tag;
PutClosingTagMark();
if( !tag->inline_tag )
{
(*out_string) += L"\n";
SkipWhiteLines();
}
if( Equal(tag->html_tag, L"li") )
has_open_li_tag = false;
if( Equal(tag->html_tag, L"ol") )
has_open_ol_tag = false;
if( Equal(tag->html_tag, L"ul") )
has_open_ul_tag = false;
}
void BBCODEParser::PutClosingTag(const wchar_t * tag_name)
{
const Tags * tag = FindTag(tag_name);
PutClosingTag(tag);
}
void BBCODEParser::Init()
{
has_open_li_tag = false;
has_open_ol_tag = false;
has_open_ul_tag = false;
SkipWhiteLines();
}
void BBCODEParser::Deinit()
{
if( has_open_li_tag )
(*out_string) += L"</li>\n";
if( has_open_ol_tag )
(*out_string) += L"</ol>\n";
if( has_open_ul_tag )
(*out_string) += L"</ul>\n";
}

97
core/bbcodeparser.h Executable file
View File

@@ -0,0 +1,97 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslucorebbcodeparser
#define headerfilecmslucorebbcodeparser
#include "htmlfilter.h"
class BBCODEParser : public HTMLFilter
{
//using HTMLFilter::pchar;
struct Tags
{
/*
const wchar_t * bbcode;
const wchar_t * html_tag;
const wchar_t * html_arg_prefix;
const wchar_t * html_arg_postfix;
const wchar_t * additional_html_tag_prefix;
const wchar_t * additional_html_tag_postfix;
bool inline_tag;
*/
const wchar_t * bbcode;
const wchar_t * html_tag;
const wchar_t * html_argument; // with closing '>'
bool inline_tag;
};
bool Equal(const wchar_t * str1, const wchar_t * str2);
virtual bool IsValidCharForName(int c);
virtual bool IsOpeningTagMark();
virtual bool IsOpeningCommentaryTagMark();
virtual bool SkipCommentaryTagIfExists();
virtual bool IsClosingTagMark();
virtual bool IsClosingXmlSimpleTagMark();
void PutHtmlArgument1(const wchar_t * arg_start, const wchar_t * arg_end, bool has_u);
void PutHtmlArgument2(const Tags * tag, bool has_u);
void PutHtmlArgument(const Tags * tag, const wchar_t * arg_start, const wchar_t * arg_end);
void PutOpeningTagFromEzc(const wchar_t * start, const wchar_t * end);
void PutOpeningTagFromBBCode(const Tags * tag, const wchar_t * start, const wchar_t * end);
virtual void PutOpeningTag(const wchar_t * start, const wchar_t * end);
virtual void PutClosingTag(const wchar_t * tag);
const Tags * FindTag(const wchar_t * tag);
void PrintArgumentCheckQuotes(const wchar_t * & start, const wchar_t * & end);
void PrintEscape(int c, bool change_quote = false);
void PrintEncode(int c);
void PrintEscape(const wchar_t * start, const wchar_t * end, bool change_quote = false);
void PrintEncode(const wchar_t * start, const wchar_t * end);
void PrintArgumentEncode(const wchar_t * start, const wchar_t * end);
void PrintArgumentEscape(const wchar_t * start, const wchar_t * end);
virtual void ReadNormalTextSkipWhite(const wchar_t * & start, const wchar_t * & last_non_white);
virtual void PutNormalText(const wchar_t * str, const wchar_t * end);
virtual void PutNormalTextTrim(const wchar_t * str, const wchar_t * end);
virtual void CheckExceptions();
virtual void Init();
virtual void Deinit();
void PutClosingTag(const Tags * tag);
void CheckOpeningTag(const Tags * tag, const wchar_t * tag_name, bool & condition);
void CheckOpeningTag(const Tags * tag);
void TrimWhiteWithNewLines(const wchar_t * & start, const wchar_t * & end);
bool has_open_ol_tag; // has open html <ol> tag
bool has_open_ul_tag; // has open html <ul> tag
bool has_open_li_tag; // has open html <li> tag
};
#endif

View File

@@ -9,7 +9,6 @@
#include "config.h"
#include "log.h"
#include "data.h"
#include "plugin.h"
#include "misc.h"
@@ -17,10 +16,6 @@
Config::Config()
{
default_str.clear();
default_int = 0;
default_bool = false;
errors_to_stdout = true;
}
@@ -33,7 +28,7 @@ Config::Config()
void Config::ShowError()
{
switch( conf_parser.status )
switch( parser.status )
{
case ConfParser::ok:
log << log2 << "Config: syntax ok" << logend;
@@ -41,16 +36,16 @@ void Config::ShowError()
case ConfParser::cant_open_file:
if( errors_to_stdout )
std::cout << "Config: cant open a config file: " << data.config_file << std::endl;
std::cout << "Config: cant open a config file: " << config_file << std::endl;
log << log1 << "Config: cant open a config file: " << data.config_file << logend;
log << log1 << "Config: cant open a config file: " << config_file << logend;
break;
case ConfParser::syntax_error:
if( errors_to_stdout )
std::cout << "Config: syntax error, line: " << conf_parser.line << std::endl;
std::cout << "Config: syntax error, line: " << parser.line << std::endl;
log << log1 << "Config: syntax error, line: " << conf_parser.line << logend;
log << log1 << "Config: syntax error, line: " << parser.line << logend;
break;
}
}
@@ -60,11 +55,11 @@ void Config::ShowError()
bool Config::ReadConfig(bool errors_to_stdout_)
bool Config::ReadConfig(bool errors_to_stdout_, bool stdout_is_closed)
{
errors_to_stdout = errors_to_stdout_;
if( data.config_file.empty() )
if( config_file.empty() )
{
log << log2 << "Config: name of the config file is empty" << logend;
return false;
@@ -72,14 +67,15 @@ bool Config::ReadConfig(bool errors_to_stdout_)
log << log2 << "Config: reading a config file" << logend;
ConfParser::Status status = conf_parser.Parse( data.config_file.c_str() );
parser.SplitSingle(true);
parser.UTF8(true); // config is always read in UTF-8
ConfParser::Status status = parser.Parse( config_file );
if( status == ConfParser::ok )
{
AssignValues();
data.SetAdditionalVariables();
AssignValues(stdout_is_closed);
SetAdditionalVariables();
return true;
}
else
@@ -92,188 +88,257 @@ bool Config::ReadConfig(bool errors_to_stdout_)
void Config::AssignValues()
void Config::AssignValues(bool stdout_is_closed)
{
data.log_file = Text("log_file");
data.log_notify_file = Text("log_notify_file");
data.fcgi_socket = Text("fcgi_socket");
data.fcgi_socket_chmod = Int("fcgi_socket_chmod", 0770);
data.fcgi_socket_user = Text("fcgi_socket_user");
data.fcgi_socket_group = Text("fcgi_socket_group");
data.log_level = Int("log_level", 1);
data.log_request = Int("log_request", 1);
demonize = Bool(L"demonize", true);
user = AText(L"user");
group = AText(L"group");
additional_groups = Bool(L"additional_groups", true);
log_file = AText(L"log_file");
log_notify_file = AText(L"log_notify_file");
log_delimiter = Text(L"log_delimiter", L"---------------------------------------------------------------------------------");
fcgi_socket = AText(L"fcgi_socket");
fcgi_socket_chmod = Int(L"fcgi_socket_chmod", 0770);
fcgi_socket_user = AText(L"fcgi_socket_user");
fcgi_socket_group = AText(L"fcgi_socket_group");
log_level = Int(L"log_level", 1);
log_request = Int(L"log_request", 1);
log_save_each_line = Bool(L"log_save_each_line", false);
log_stdout = Bool(L"log_stdout", false);
log_db_query = Bool(L"log_db_query", false);
log_plugin_call = Bool(L"log_plugin_call", false);
if( !data.stdout_is_closed )
data.log_stdout = Bool("log_stdout", false);
post_file_max = Size(L"post_file_max", 8388608); // 8 MB
upload_dir = Text(L"upload_dir");
upload_dirs_chmod = Int(L"upload_dirs_chmod", 0750);
upload_files_chmod = Int(L"upload_files_chmod", 0640);
create_thumb = Bool(L"create_thumb", true);
thumb_mode = Int(L"thumb_mode", 2);
thumb_cx = Size(L"thumb_cx", 150);
thumb_cy = Size(L"thumb_cy", 150);
convert_cmd = Text(L"convert_cmd", L"/usr/local/bin/convert");
templates_dir = Text(L"templates_dir");
templates_dir_default = Text(L"templates_dir_default");
txt_templates_dir = Text(L"txt_templates_dir");
txt_templates_dir_default = Text(L"txt_templates_dir_default");
templates_fun_prefix = Text(L"templates_fun_prefix", L"fun_");
templates_fun_postfix = Text(L"templates_fun_postfix", L".html");
templates_index = Text(L"templates_index", L"index.html");
template_only_root_use_template_fun = Bool(L"template_only_root_use_template_fun", false);
http_session_id_name = AText(L"http_session_id_name");
db_database = AText(L"db_database");
db_user = AText(L"db_user");
db_pass = AText(L"db_pass");
item_url_empty = Text(L"item_url_empty");
base_server = Text(L"base_server");
base_url = Text(L"base_url");
base_url_static = Text(L"base_url_static");
base_url_common = Text(L"base_url_common");
NoLastSlash(base_server);
NoLastSlash(base_url);
NoLastSlash(base_url_static);
NoLastSlash(base_url_common);
priv_no_user = Text(L"priv_no_user", L"-- no user --");
priv_no_group = Text(L"priv_no_group", L"-- no group --");
session_max_idle = Int(L"session_max_idle", 10800); // 3h
session_remember_max_idle = Int(L"session_remember_max_idle", 16070400); // 3 months
session_file = AText(L"session_file");
session_max = Size(L"session_max", 1000000);
compression = Bool(L"compression", true);
compression_page_min_size = Int(L"compression_page_min_size", 512);
html_filter = Bool(L"html_filter", true);
html_filter_trim_white = Bool(L"html_filter_trim_white", true);
html_filter_break_lines = Int(L"html_filter_break_lines", 60);
html_filter_tabs = Size(L"html_filter_tabs", 2);
html_filter_orphans = Bool(L"html_filter_orphans", false);
html_filter_orphans_lang_str = AText(L"html_filter_orphans_lang", L"pl");
html_filter_orphans_mode_str = AText(L"html_filter_orphans_mode_str", L"nbsp");
locale_str = Text(L"locale", L"en");
locale_dir = Text(L"locale_dir");
locale_dir_default = Text(L"locale_dir_default");
title_separator = Text(L"title_separator", L" / ");
http_header_send_file = Text(L"http_header_send_file", L"X-LIGHTTPD-send-file");
password_min_size = Size(L"password_min_size", 5);
debug_info = Bool(L"debug_info", false);
editors_html_safe_mode = Bool(L"editors_html_safe_mode", true);
editors_html_safe_mode_skip_root = Bool(L"editors_html_safe_mode_skip_root", true);
plugins_dir = Text(L"plugins_dir", L"/usr/local/winix/plugins");
NoLastSlash(plugins_dir);
parser.ListText(L"plugins", plugin_file);
time_zone_offset = Int(L"time_zone_offset", 0);
time_zone_offset_guest = Int(L"time_zone_offset_guest", 0);
utf8 = Bool(L"utf8", true);
symlinks_follow_max = Size(L"symlinks_follow_max", 20);
ticket_form_prefix = Text(L"ticket_form_prefix", L"ticketparam");
}
void Config::SetAdditionalVariables()
{
SetHttpHost(base_url, base_url_http_host);
if( html_filter_orphans_lang_str == "pl" )
html_filter_orphans_lang = HTMLFilter::lang_pl;
else
data.log_stdout = false;
data.post_file_max = Int("post_file_max", 8388608); // 8 MB
data.auth_simplefs_dir = Text("auth_simplefs_dir");
data.auth_hashfs_dir = Text("auth_hashfs_dir");
data.auth_tmp_dir = Text("auth_tmp_dir");
data.templates_dir = Text("templates_dir");
data.templates_dir_default = Text("templates_dir_default");
data.http_session_id_name = Text("http_session_id_name");
data.db_database = Text("db_database");
data.db_user = Text("db_user");
data.db_pass = Text("db_pass");
data.item_url_empty = Text("item_url_empty");
data.base_server = Text("base_server");
data.base_url = Text("base_url");
data.base_url_auth = Text("base_url_auth");
data.base_url_static = Text("base_url_static");
data.base_url_common = Text("base_url_common");
NoLastSlash(data.base_server);
NoLastSlash(data.base_url);
NoLastSlash(data.base_url_auth);
NoLastSlash(data.base_url_static);
NoLastSlash(data.base_url_common);
data.priv_no_user = Text("priv_no_user", "-- no user --");
data.priv_no_group = Text("priv_no_group", "-- no group --");
data.session_max_idle = Int("session_max_idle", 10800); // 3h
data.session_remember_max_idle = Int("session_remember_max_idle", 16070400); // 3 months
data.session_file = Text("session_file");
data.compression = Bool("compression", true);
std::string p = Text("plugin");
data.plugin_file.push_back(p);
data.html_filter = Bool("html_filter", true);
data.locale_str = Text("locale", "en");
data.locale_dir = Text("locale_dir");
data.locale_dir_default = Text("locale_dir_default");
data.title_separator = Text("title_separator", " / ");
if( html_filter_orphans_lang_str == "cz" )
html_filter_orphans_lang = HTMLFilter::lang_cz;
else
if( html_filter_orphans_lang_str == "sk" )
html_filter_orphans_lang = HTMLFilter::lang_sk;
else
html_filter_orphans_lang = HTMLFilter::lang_none;
if( html_filter_orphans_mode_str == "160" )
html_filter_orphans_mode = HTMLFilter::orphan_160space;
else
html_filter_orphans_mode = HTMLFilter::orphan_nbsp;
}
std::string Config::Text(const char * name)
void Config::SetHttpHost(const std::wstring & in, std::wstring & out)
{
return Text(std::string(name), default_str);
}
std::string Config::Text(const char * name, const char * def)
{
return Text(std::string(name), std::string(def));
}
std::string Config::Text(const std::string & name, const std::string & def)
{
ConfParser::Table::iterator i = conf_parser.table.find(name);
if( i == conf_parser.table.end() )
return def;
return i->second;
}
int Config::Int(const char * name)
{
return Int(std::string(name), default_int);
}
int Config::Int(const char * name, int def)
{
return Int(std::string(name), def);
}
int Config::Int(const std::string & name, int def)
{
ConfParser::Table::iterator i = conf_parser.table.find(name);
if( i == conf_parser.table.end() || i->second.empty() )
return def;
long res = (i->second[0] == '0')? strtol(i->second.c_str() + 1, 0, 8) : strtol(i->second.c_str(), 0, 10);
return res;
}
bool Config::Bool(const char * name)
{
return Bool(std::string(name), default_bool);
}
bool Config::Bool(const char * name, bool def)
{
return Bool(std::string(name), def);
}
bool Config::Bool(const std::string & name, bool def)
{
ConfParser::Table::iterator i = conf_parser.table.find(name);
if( i == conf_parser.table.end() || i->second.empty() )
return def;
bool res = false;
if( EqualNoCase(i->second.c_str(), "true") ||
EqualNoCase(i->second.c_str(), "yes") ||
EqualNoCase(i->second.c_str(), "1")
)
res = true;
return res;
}
void Config::NoLastSlash(std::string & s)
{
if( s.empty() )
return;
size_t i = s.size();
for( ; i>0 && s[i-1]=='/' ; --i);
if( i < s.size() )
s.erase(i);
}
void Config::NoFirstHttp(std::string & s)
{
if( s.empty() )
return;
const char http[] = "http://";
const char https[] = "https://";
size_t http_len = sizeof(http) / sizeof(char) - 1;
size_t https_len = sizeof(https) / sizeof(char) - 1;
if( IsSubStringNoCase(http, s.c_str()) )
{
s.erase(0, sizeof(http)/sizeof(char));
}
if( IsSubString(http, in.c_str()) )
out = in.substr(http_len);
else
if( IsSubStringNoCase(https, s.c_str()) )
{
s.erase(0, sizeof(https)/sizeof(char));
}
if( IsSubString(https, in.c_str()) )
out = in.substr(https_len);
else
out.clear(); // if empty the RequestController::BaseUrlRedirect() returns false and no redirecting will be done
}
std::wstring Config::Text(const wchar_t * name)
{
return parser.Text(name);
}
std::wstring Config::Text(const wchar_t * name, const wchar_t * def)
{
return parser.Text(name, def);
}
std::wstring Config::Text(const std::wstring & name, const std::wstring & def)
{
return parser.Text(name, def);
}
std::string Config::AText(const wchar_t * name)
{
return parser.AText(name);
}
std::string Config::AText(const wchar_t * name, const wchar_t * def)
{
return parser.AText(name, def);
}
std::string Config::AText(const std::wstring & name, const std::wstring & def)
{
return parser.AText(name, def);
}
int Config::Int(const wchar_t * name)
{
return parser.Int(name);
}
int Config::Int(const wchar_t * name, int def)
{
return parser.Int(name, def);
}
int Config::Int(const std::wstring & name, int def)
{
return parser.Int(name, def);
}
size_t Config::Size(const wchar_t * name)
{
return parser.Size(name);
}
size_t Config::Size(const wchar_t * name, size_t def)
{
return parser.Size(name, def);
}
size_t Config::Size(const std::wstring & name, size_t def)
{
return parser.Size(name, def);
}
bool Config::Bool(const wchar_t * name)
{
return parser.Bool(name);
}
bool Config::Bool(const wchar_t * name, bool def)
{
return parser.Bool(name, def);
}
bool Config::Bool(const std::wstring & name, bool def)
{
return parser.Bool(name, def);
}
void Config::ListText(const wchar_t * name, std::vector<std::wstring> & list)
{
parser.ListText(name, list);
}
void Config::ListText(const std::wstring & name, std::vector<std::wstring> & list)
{
parser.ListText(name, list);
}
void Config::Print(std::ostream & out)
{
parser.Print(out);
}
@@ -282,4 +347,3 @@ void Config::NoFirstHttp(std::string & s)

View File

@@ -11,50 +11,346 @@
#define headerfilecmslucoreconfig
#include <string>
#include "confparser.h"
#include "htmlfilter.h"
#include "../confparser/confparser.h"
class Config
{
public:
// name of the config file
// this is the parameter passed to winix programm
std::string config_file;
// start as a demon (in the background)
// default: true
bool demonize;
// system user name (to which drop privileges)
// used only if winix is started as the root
std::string user;
// system group name (to which drop privileges)
// used only if winix is started as the root
std::string group;
// setting additional effective groups from /etc/group
// by using initgroups()
// used only if winix is started as the root
// default: true
bool additional_groups;
// log file name, log file name for notifications (sending emails, etc)
std::string log_file, log_notify_file;
// 1 - minimum
// 2 - (default)
// 3 - maximum - all logs
int log_level;
// logging to stdout too
// only if demonize is 'false'
// default: false
bool log_stdout;
// how many requests should be saved in the same time
// default: 1
int log_request;
// whether to save each line of the config (use it for debug purposes)
// default: false
bool log_save_each_line;
// logging db queries
// default: false
bool log_db_query;
// logging when a plugin function is called
// default: false
bool log_plugin_call;
// request delimiter in the log file, default "---------"
std::wstring log_delimiter;
// fast cgi: socket (unix domain)
std::string fcgi_socket;
// fast cgi: socket permissions
int fcgi_socket_chmod;
// fast cgi: owner of the socket
std::string fcgi_socket_user;
// fast cgi: group of the socket
std::string fcgi_socket_group;
std::wstring templates_dir;
std::wstring templates_dir_default; // html templates from winix
std::wstring txt_templates_dir;
std::wstring txt_templates_dir_default; // txt (notifications) templates from winix
// prefix and postfix for functions templates
// default:
// prefix: "fun_"
// postfix: ".html"
std::wstring templates_fun_prefix;
std::wstring templates_fun_postfix;
// main html template
// default: index.html
std::wstring templates_index;
// if true then only root can use 'template' function
// default: false
bool template_only_root_use_template_fun;
std::string db_database;
std::string db_user;
std::string db_pass;
std::string http_session_id_name;
// when the HOST_HTTP environment variable doesn't point into 'base_url' (the part 'http://' and the last slash is removed)
// the server will redirect into 'base_url' + 'REQUEST_URI'
// it's useful when you want to redirect from 'mydomain.tld' into 'www.mydomain.tld' etc.
bool base_url_redirect;
// string used in a place where is a user (or group) selected
std::wstring priv_no_user;
std::wstring priv_no_group;
// time in seconds when the user will be automatically logged out (iddle time)
int session_max_idle;
// time in seconds when the user will be automatically logged out (when he selected 'remember me' option)
// this time is usually greater than session_max_idle
int session_remember_max_idle;
// this file is used when the program is starting and ending
std::string session_file;
// how many sessions can be (zero turn off this checking)
// default: 1000000 (one milion)
size_t session_max;
// allow the html ouput to be compressed
bool compression;
// if the output is shorter than this value then it will not be compressed
int compression_page_min_size;
// plugins directory
// default: /usr/local/winix/plugins
std::wstring plugins_dir;
// plugins
// you can provide either a relative path (plugins_dir will be used)
// or a full path to a plugin
std::vector<std::wstring> plugin_file;
// should the html code be cleaned by the html filter
bool html_filter;
// should white characters be trimmed
bool html_filter_trim_white;
// when long lines (lines without a white character) should be break (inserted a space)
// default: after 60 non white characters will be put a space
// set zero to turn off
int html_filter_break_lines;
// how many spaces will be put at one tree level
// default: 2
size_t html_filter_tabs;
// use checking for 'orphans' for a specicic language
// default: false
bool html_filter_orphans;
// language for html orphans
// default: pl
// can be either: "pl" or "cz" or "sk"
std::string html_filter_orphans_lang_str;
HTMLFilter::Lang html_filter_orphans_lang;
// orphans mode
// either: "nbsp" or "160"
// default: "nbsp"
std::string html_filter_orphans_mode_str;
HTMLFilter::OrphanMode html_filter_orphans_mode;
// the url of a new empty item (if there is not the subject too)
std::wstring item_url_empty;
// maximum length of a file send by post multipart form
// 0 - not used
size_t post_file_max;
// directory for static files
std::wstring upload_dir;
// chmod of newly created directories (under upload_dir)
// default: 0750
int upload_dirs_chmod;
// chmod of newly created files (under upload_dir)
// default: 0640
int upload_files_chmod;
// create a thumbnail from an image
// default: true
bool create_thumb;
// the mode of creating a thumbnail
// width means thumb_cx, height means thumb_cy
// 1: Width given, height automagically selected to preserve aspect ratio.
// 2: Height given, width automagically selected to preserve aspect ratio.
// 3: Maximum values of height and width given, aspect ratio preserved.
// 4: Minimum values of width and height given, aspect ratio preserved.
// 5: Width and height emphatically given, original aspect ratio ignored.
// 6: Change as per widthxheight (3) but only if an image dimension exceeds a specified dimension.
// 7: Change dimensions only if both image dimensions are less than specified dimensions.
// default: 2
int thumb_mode;
// width of thumbnails
// default: 150
size_t thumb_cx;
// height of thumbnails
// default: 150
size_t thumb_cy;
// the convert program
// default: /usr/local/bin/convert
std::wstring convert_cmd;
// locale: en, pl
// default: en
std::wstring locale_str;
// directory with locale files
std::wstring locale_dir;
// directory with default locale files (those from winix)
std::wstring locale_dir_default;
// the main address of the server (e.g. someserver.com) (without the 'www' part etc)
std::wstring base_server;
// the main address of the site (e.g. http://www.someserver.com)
std::wstring base_url;
// static content not authorized by winix
std::wstring base_url_static;
// additional static server for common content (not authorized)
std::wstring base_url_common;
// separator used in <title> html tag
std::wstring title_separator;
// http header recognized by www server as a file to send back
// default: X-LIGHTTPD-send-file
std::wstring http_header_send_file;
// the minimum size of a password for new users (function: adduser)
// default: 5
size_t password_min_size;
// prints additional information (in the end of the html page as a commentary)
bool debug_info;
// in editors (emacs, ckeditor,...) the html will be filtered and unsafe tags
// will be dropped (script, frame, etc.)
// default: true;
bool editors_html_safe_mode;
// don't filter the html code for root
// default: true
// (if true the html code for root is not filtered)
bool editors_html_safe_mode_skip_root;
// temporarily we do not support time zones per user
// there is one offset for all users
// default: 0
int time_zone_offset;
// time zone offset for guests (not logged users)
// default: 0
int time_zone_offset_guest;
// charset used in templates, locales, logs etc.
// default: true (UTF-8)
// if false it means 8-bit ASCII
bool utf8;
// how many maximum symlinks can be followed
// (symlinks on directories as well)
// default: 20
size_t symlinks_follow_max;
// the prefix of a name of html form controls used in the ticket plugin
// default: ticketparam
std::wstring ticket_form_prefix;
/*
*/
// based on base_url
// set by SetAdditionalVariables()
// without the first part http:// (or https://) or the whole string is empty
std::wstring base_url_http_host;
Config();
bool ReadConfig(bool errors_to_stdout_);
bool ReadConfig(bool errors_to_stdout_, bool stdout_is_closed = true);
std::wstring Text(const wchar_t * name);
std::wstring Text(const wchar_t * name, const wchar_t * def);
std::wstring Text(const std::wstring & name, const std::wstring & def);
std::string AText(const wchar_t * name);
std::string AText(const wchar_t * name, const wchar_t * def);
std::string AText(const std::wstring & name, const std::wstring & def);
int Int(const wchar_t *);
int Int(const wchar_t * name, int def);
int Int(const std::wstring & name, int def);
size_t Size(const wchar_t *);
size_t Size(const wchar_t * name, size_t def);
size_t Size(const std::wstring & name, size_t def);
bool Bool(const wchar_t *);
bool Bool(const wchar_t * name, bool def);
bool Bool(const std::wstring & name, bool def);
void ListText(const wchar_t * name, std::vector<std::wstring> & list);
void ListText(const std::wstring & name, std::vector<std::wstring> & list);
// for debug
void Print(std::ostream & out);
private:
ConfParser conf_parser;
void ShowError();
void AssignValues();
std::string Text(const char * name);
std::string Text(const char * name, const char * def);
std::string Text(const std::string & name, const std::string & def);
void AssignValues(bool stdout_is_closed);
void SetHttpHost(const std::wstring & in, std::wstring & out);
void SetAdditionalVariables();
int Int(const char *);
int Int(const char * name, int def);
int Int(const std::string & name, int def);
bool Bool(const char *);
bool Bool(const char * name, bool def);
bool Bool(const std::string & name, bool def);
ConfParser parser;
std::string default_str;
int default_int;
bool default_bool;
bool errors_to_stdout;
void NoLastSlash(std::string & s);
void NoFirstHttp(std::string & s);
};
#endif

729
core/confparser.cpp Executable file
View File

@@ -0,0 +1,729 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include <cstdlib>
#include <wchar.h>
#include "confparser.h"
#include "misc.h"
#include "utf8.h"
ConfParser::ConfParser()
{
// you can change this separators to what you want
// you shoud not use only white characters here (as expected by IsWhite() method)
// and new line characters ('\n')
separator = '=';
commentary = '#';
list_start = '(';
list_end = ')';
list_delimiter = ',';
split_single = false;
skip_empty = false;
use_escape_char = true;
input_as_utf8 = false;
default_str = L"";
default_int = 0;
default_size = 0;
default_bool = false;
}
void ConfParser::SplitSingle(bool split)
{
split_single = split;
}
void ConfParser::SkipEmpty(bool skip)
{
skip_empty = skip;
}
void ConfParser::UseEscapeChar(bool escape)
{
use_escape_char = escape;
}
ConfParser::Status ConfParser::Parse(const char * file_name)
{
line = 1;
table.clear();
table_single.clear();
file.clear();
file.open( file_name );
if( file )
{
status = ParseFile();
file.close();
}
else
{
status = cant_open_file;
}
return status;
}
ConfParser::Status ConfParser::Parse(const std::string & file_name)
{
return Parse(file_name.c_str());
}
ConfParser::Status ConfParser::Parse(const wchar_t * file_name)
{
Ezc::WideToUTF8(file_name, afile_name);
return Parse(afile_name.c_str());
}
ConfParser::Status ConfParser::Parse(const std::wstring & file_name)
{
return Parse(file_name.c_str());
}
ConfParser::Status ConfParser::ParseFile()
{
ReadChar();
SkipWhiteLines();
while( lastc != -1 )
{
if( !ReadVariable() )
return syntax_error;
if( lastc != separator )
return syntax_error;
if( !ReadValue() )
return syntax_error;
AddOption();
SkipWhite();
if( lastc != -1 && lastc != '\n' )
return syntax_error; // some characters have left at the end of an option
SkipWhiteLines();
}
return ok;
}
bool ConfParser::IsVariableChar(int c)
{
if( (c>='a' && c<='z') ||
(c>='A' && c<='Z') ||
(c>='0' && c<='9') ||
c=='.' || c==',' || c=='_' )
return true;
return false;
}
void ConfParser::AddOption()
{
if( value.empty() && skip_empty )
{
DeleteFromTable(variable);
DeleteFromTableSingle(variable);
return;
}
if( split_single && value.size() == 1 )
{
table_single[variable] = value[0];
DeleteFromTable(variable);
}
else
{
table[variable] = value;
DeleteFromTableSingle(variable);
}
}
void ConfParser::DeleteFromTable(const std::wstring & var)
{
Table::iterator i = table.find(var);
if( i != table.end() )
table.erase(i);
}
void ConfParser::DeleteFromTableSingle(const std::wstring & var)
{
TableSingle::iterator i = table_single.find(var);
if( i != table_single.end() )
table_single.erase(i);
}
bool ConfParser::ReadVariable()
{
variable.clear();
SkipWhite();
while( IsVariableChar(lastc) )
{
variable += lastc;
ReadChar();
}
SkipWhite();
return !variable.empty();
}
bool ConfParser::ReadValue()
{
value.clear();
ReadChar(); // skipping separator '='
SkipWhite();
if( lastc == list_start )
return ReadValueList();
else
return ReadValueNoList();
}
bool ConfParser::ReadValueList()
{
ReadChar(); // skipping first list character '('
SkipWhiteLines(); // lists can be split into several lines
while( lastc != -1 && lastc != list_end )
{
if( !ReadValueNoList(true) )
return false;
if( lastc == list_delimiter )
ReadChar();
SkipWhiteLines();
}
if( lastc != list_end )
return false;
ReadChar(); // skipping last list character ')'
SkipWhite();
return true;
}
bool ConfParser::ReadValueNoList(bool use_list_delimiter)
{
bool res;
value_item.clear();
if( lastc == '"' )
{
res = ReadValueQuoted(); // quoted value
if( res )
value.push_back(value_item);
}
else
{
res = ReadValueSimple(use_list_delimiter);
if( res && !value_item.empty() )
value.push_back(value_item);
}
return res;
}
bool ConfParser::ReadValueQuoted()
{
ReadChar(); // skipping the first quote
while( lastc != '"' && lastc != -1 )
{
if( use_escape_char && lastc == '\\' )
ReadChar();
value_item += lastc;
ReadChar();
}
if( lastc != '"' )
return false;
ReadChar(); // skipping the last quote
SkipWhite();
return true;
}
bool ConfParser::ReadValueSimple(bool use_list_delimiter)
{
int list_delimiter1 = -1;
int list_delimiter2 = -1;
if( use_list_delimiter )
{
list_delimiter1 = list_delimiter;
list_delimiter2 = list_end;
}
while( lastc!=-1 && lastc!='\n' && lastc!=commentary &&
lastc!=list_delimiter1 && lastc!=list_delimiter2 )
{
value_item += lastc;
ReadChar();
}
Trim(value_item);
SkipWhite();
return true;
}
int ConfParser::ReadUTF8Char()
{
int c;
bool correct;
lastc = -1;
do
{
Ezc::UTF8ToInt(file, c, correct);
if( !file )
return lastc;
}
while( !correct );
lastc = c;
if( lastc == '\n' )
++line;
return lastc;
}
int ConfParser::ReadASCIIChar()
{
lastc = file.get();
if( lastc == '\n' )
++line;
return lastc;
}
int ConfParser::ReadChar()
{
if( input_as_utf8 )
return ReadUTF8Char();
return ReadASCIIChar();
}
bool ConfParser::IsWhite(int c)
{
// dont use '\n' here
// 13 (\r) is at the end of a line in a dos file \r\n
// 160 is an unbreakable space
if( c==' ' || c=='\t' || c==13 || c==160 )
return true;
return false;
}
void ConfParser::SkipWhite()
{
while( IsWhite(lastc) || lastc == commentary )
{
if( lastc == commentary )
SkipLine();
else
ReadChar();
}
}
void ConfParser::SkipWhiteLines()
{
while( IsWhite(lastc) || lastc == commentary || lastc=='\n' )
{
if( lastc == commentary )
SkipLine();
else
ReadChar();
}
}
void ConfParser::SkipLine()
{
while( lastc != -1 && lastc != '\n' )
ReadChar();
}
void ConfParser::Trim(std::wstring & s)
{
std::wstring::size_type i;
if( s.empty() )
return;
// looking for white characters at the end
for(i=s.size()-1 ; i>0 && IsWhite(s[i]) ; --i);
if( i==0 && IsWhite(s[i]) )
{
// the whole string has white characters
s.clear();
return;
}
// deleting white characters at the end
if( i != s.size() - 1 )
s.erase(i+1, std::wstring::npos);
// looking for white characters at the beginning
for(i=0 ; i<s.size() && IsWhite(s[i]) ; ++i);
// deleting white characters at the beginning
if( i != 0 )
s.erase(0, i);
}
std::wstring ConfParser::Text(const wchar_t * name)
{
return Text(std::wstring(name), default_str);
}
std::wstring ConfParser::Text(const wchar_t * name, const wchar_t * def)
{
return Text(std::wstring(name), std::wstring(def));
}
std::wstring ConfParser::Text(const std::wstring & name, const std::wstring & def)
{
TableSingle::iterator i = table_single.find(name);
if( i == table_single.end() )
{
Table::iterator t = table.find(name);
if( t == table.end() || t->second.empty() )
return def;
return t->second[0];
}
return i->second;
}
std::string ConfParser::AText(const wchar_t * name)
{
std::wstring res = Text(name);
std::string ares;
Ezc::WideToUTF8(res, ares);
return ares;
}
std::string ConfParser::AText(const wchar_t * name, const wchar_t * def)
{
std::wstring res = Text(name, def);
std::string ares;
Ezc::WideToUTF8(res, ares);
return ares;
}
std::string ConfParser::AText(const std::wstring & name, const std::wstring & def)
{
std::wstring res = Text(name, def);
std::string ares;
Ezc::WideToUTF8(res, ares);
return ares;
}
int ConfParser::Int(const wchar_t * name)
{
return Int(std::wstring(name), default_int);
}
int ConfParser::Int(const wchar_t * name, int def)
{
return Int(std::wstring(name), def);
}
int ConfParser::ToInt(const std::wstring & value)
{
long res = (value[0] == '0')? wcstol(value.c_str() + 1, 0, 8) : wcstol(value.c_str(), 0, 10);
return static_cast<int>(res);
}
int ConfParser::Int(const std::wstring & name, int def)
{
TableSingle::iterator i = table_single.find(name);
if( i == table_single.end() )
{
Table::iterator t = table.find(name);
if( t == table.end() || t->second.empty() )
return def;
return ToInt(t->second[0]);
}
return ToInt(i->second);
}
size_t ConfParser::Size(const wchar_t * name)
{
return Size(std::wstring(name), default_size);
}
size_t ConfParser::Size(const wchar_t * name, size_t def)
{
return Size(std::wstring(name), def);
}
size_t ConfParser::ToSize(const std::wstring & value)
{
unsigned long res = (value[0] == '0')? wcstoul(value.c_str() + 1, 0, 8) : wcstoul(value.c_str(), 0, 10);
return static_cast<size_t>(res);
}
size_t ConfParser::Size(const std::wstring & name, size_t def)
{
TableSingle::iterator i = table_single.find(name);
if( i == table_single.end() )
{
Table::iterator t = table.find(name);
if( t == table.end() || t->second.empty() )
return def;
return ToSize(t->second[0]);
}
return ToSize(i->second);
}
bool ConfParser::Bool(const wchar_t * name)
{
return Bool(std::wstring(name), default_bool);
}
bool ConfParser::Bool(const wchar_t * name, bool def)
{
return Bool(std::wstring(name), def);
}
bool ConfParser::ToBool(const std::wstring & value)
{
return ( EqualNoCase(value.c_str(), L"true") ||
EqualNoCase(value.c_str(), L"yes") ||
EqualNoCase(value.c_str(), L"1")
);
}
bool ConfParser::Bool(const std::wstring & name, bool def)
{
TableSingle::iterator i = table_single.find(name);
if( i == table_single.end() )
{
Table::iterator t = table.find(name);
if( t == table.end() || t->second.empty() )
return def;
return ToBool(t->second[0]);
}
return ToBool(i->second);
}
void ConfParser::SetDefaultText(const std::wstring & def)
{
default_str = def;
}
void ConfParser::SetDefaultInt(int def)
{
default_int = def;
}
void ConfParser::SetDefaultSize(size_t def)
{
default_size = def;
}
void ConfParser::SetDefaultBool(bool def)
{
default_bool = def;
}
// in lists we don't use default values
void ConfParser::ListText(const wchar_t * name, std::vector<std::wstring> & list)
{
ListText(std::wstring(name), list);
}
void ConfParser::ListText(const std::wstring & name, std::vector<std::wstring> & list)
{
list.clear();
ConfParser::TableSingle::iterator i = table_single.find(name);
if( i != table_single.end() )
{
list.push_back(i->second);
return;
}
ConfParser::Table::iterator z = table.find(name);
if( z != table.end() )
{
list = z->second;
return;
}
}
void ConfParser::UTF8(bool utf)
{
input_as_utf8 = utf;
}
void ConfParser::Print(std::ostream & out)
{
TableSingle::iterator i1;
for(i1 = table_single.begin() ; i1 != table_single.end() ; ++i1)
{
Ezc::WideToUTF8(i1->first, out);
out << '=';
Ezc::WideToUTF8(i1->second, out);
out << std::endl;
}
Table::iterator i2;
Value::iterator i3;
for(i2 = table.begin() ; i2 != table.end() ; ++i2)
{
Ezc::WideToUTF8(i2->first, out);
out << '=';
for(i3 = i2->second.begin() ; i3 != i2->second.end() ; ++i3)
{
Ezc::WideToUTF8(*i3, out);
out << ',';
}
out << std::endl;
}
}

406
core/confparser.h Executable file
View File

@@ -0,0 +1,406 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfileconfparser
#define headerfileconfparser
#include <fstream>
#include <string>
#include <vector>
#include <map>
/*
A parser for parsing config files.
A config file can look like this:
variable1 = value 1
variable2 = " value 2 "
variable3 = (value 1, value 2)
variable4 = (" value 1 " , "value2", value 3)
sample of use:
ConfParser parser;
parser.Parse("/path/to/config");
if( parser.status == ConfParser::ok )
{
// the whole config we have in parser.table (parser.table_single)
}
config syntax:
option = list
list can consists of any number of items, if you're using more than one item you should
use brackets ()
for one item the brackets can be ommited:
option = value
white characters at the beginning of the value (and at the end) will be trimmed,
or you can use quotes:
option = "value"
option2 = "value with spaces at the end "
the form without quotes:
option = value
should be written in one line, so this is not allowed:
option =
value
you can use a new line characters only between brackets and quotes:
option = "this is
a multiline string"
option = ( value1,
value2 )
but there is one requirement: the first character " or ( should be in the same line,
so this is not allowed
option =
"this is wrong"
but this is ok:
option = "
that is ok"
empty lists:
option = ()
this creates an empty list: parser.table['option'].empty() == true
option =
this creates an empty list too (the same as previously)
option = ""
but this doesn't create an empty list, it creates a list with one (empty) item
commentaries:
# this is a commentary (until the end of the line)
option = value # this is a commentary too
commentaries are treated as white characters, other example:
option = ( # this is my list
"value 1" # this is a value one
value 2 # and this is a value two
) # end of my list
overwriting:
option1 = some value
option1 = other value
# always the last option is used so option1 is "other value"
list delimiter:
option1 = (value1, value2, value3)
option2 = ("value1", "value2", "value3")
above we're using a comma ',' as a list delimiter but when using quotes (second line)
the commas can be omitted:
option2 = ("value1" "value2" "value3")
white characters:
the name of an option cannot consist of white characters
some option = value # this is wrong
some_option = value # this is ok
which characters are allowed in an option name is defined by IsVariableChar() method
you can use white characters in values
option = value with spaces or tabs
white characters at the beginning and at the end will be trimmed,
so if you want them use quotes:
option = " other value with spaces "
special characters in quoted strings:
option = "this is a string with \" a quote inside"
the option will be: this is a string with " a quote inside
\\ - means one \
basically: \char produces char
so:
"\a" gives "a"
"\\" gives "\"
"\Z" gives "Z" and so on
you can call UseEscapeChar(false) to turn this off
*/
class ConfParser
{
public:
ConfParser();
/*
status of parsing
*/
enum Status { ok, cant_open_file, syntax_error };
/*
the last status of parsing, set by Parse() methods
*/
Status status;
/*
the main methods used to parse
file_name is the path to a file
*/
Status Parse(const char * file_name);
Status Parse(const std::string & file_name);
Status Parse(const wchar_t * file_name);
Status Parse(const std::wstring & file_name);
/*
a number of a line in which there is a syntax_error
*/
int line;
/*
this is the table which represents your config file
in the Table map: the first (key) is your 'option' and the second is 'list'
*/
typedef std::vector<std::wstring> Value;
typedef std::map<std::wstring, Value> Table;
Table table;
/*
if your config file consists mainly of single forms such as:
option = value
option2 = value2
then you can call SplitSingle(true) for not inserting single values to
previous 'table' but instead to 'table_single'
table_single as the second parameter takes only std::wstring (instead of the whole std::vector)
so you can save a little memory from not using std::vector
*/
typedef std::map<std::wstring, std::wstring> TableSingle;
TableSingle table_single;
/*
if your list consists of only one item, e.g:
option1 = value 1
option2 = "value 2"
option3 = ( "value 3" )
then if you call SplitSingle(true) then such values will be stored in
'table_single' instead of 'table' map
default: false
*/
void SplitSingle(bool split);
/*
if true then empty lists, e.g:
option =
option2 = ()
will be omitted (not inserted to 'table' or 'table_single')
default: false
*/
void SkipEmpty(bool skip);
/*
'\' character is used to escape other characters in a quoted string
so "some \t t\"ext" will produce "some t t"ext"
(this is only use in quoted string)
default: true
*/
void UseEscapeChar(bool escape);
/*
those methods are used to extract information from table or table_single
as a parameter they take the name of an option
and a default value (if there is no such a parameter),
they return appropriate value (either text, int or boolean)
(in lists they return the first item if exists)
*/
std::wstring Text(const wchar_t * name);
std::wstring Text(const wchar_t * name, const wchar_t * def);
std::wstring Text(const std::wstring & name, const std::wstring & def);
std::string AText(const wchar_t * name);
std::string AText(const wchar_t * name, const wchar_t * def);
std::string AText(const std::wstring & name, const std::wstring & def);
int Int(const wchar_t *);
int Int(const wchar_t * name, int def);
int Int(const std::wstring & name, int def);
size_t Size(const wchar_t *);
size_t Size(const wchar_t * name, size_t def);
size_t Size(const std::wstring & name, size_t def);
bool Bool(const wchar_t *);
bool Bool(const wchar_t * name, bool def);
bool Bool(const std::wstring & name, bool def);
/*
some default values
used in Text() Int() or Bool() when you don't explicitly set the default value
if you don't set it directly then:
default text is: "" (empty)
default int or size is: 0
default bool is: false
*/
void SetDefaultText(const std::wstring & def);
void SetDefaultInt(int def);
void SetDefaultSize(size_t def);
void SetDefaultBool(bool def);
/*
those methods are used to extract lists
note: if there is one option in table_single they will return it
*/
void ListText(const wchar_t * name, std::vector<std::wstring> & list);
void ListText(const std::wstring & name, std::vector<std::wstring> & list);
/*
if true then the input file is treated as UTF-8
*/
void UTF8(bool utf);
/*
printing the content
(for debug purposes)
*/
void Print(std::ostream & out);
private:
/*
last read variable (option)
*/
std::wstring variable;
/*
last read list item
*/
std::wstring value_item;
/*
last read list
*/
Value value;
/*
separator between a variable and a value, default: '='
*/
int separator;
/*
commentary char, default: '#'
*/
int commentary;
/*
list starting character, default: '('
*/
int list_start;
/*
list ending character, default: ')'
*/
int list_end;
/*
list delimiter, default: ','
*/
int list_delimiter;
/*
last read char
or -1 if the end
*/
int lastc;
/*
current file
*/
std::ifstream file;
/*
if true then lists with one item will be put into 'table_single' table
default: false
*/
bool split_single;
/*
if true then empty lists, e.g:
option =
option2 = ()
will be omitted (not inserted to 'table' or 'table_single')
default: false
*/
bool skip_empty;
/*
input file is in UTF-8
default: false
*/
bool input_as_utf8;
/*
if true you can use an escape character '\' in quoted values
*/
bool use_escape_char;
std::string afile_name;
std::wstring default_str;
int default_int;
size_t default_size;
bool default_bool;
int ToInt(const std::wstring & value);
size_t ToSize(const std::wstring & value);
bool ToBool(const std::wstring & value);
Status ParseFile();
void AddOption();
void DeleteFromTable(const std::wstring & var);
void DeleteFromTableSingle(const std::wstring & var);
bool ReadVariable();
bool ReadValue();
bool ReadValueList();
bool ReadValueNoList(bool use_list_delimiter = false);
bool ReadValueQuoted();
bool ReadValueSimple(bool use_list_delimiter = false);
int ReadUTF8Char();
int ReadASCIIChar();
int ReadChar();
bool IsWhite(int c);
bool IsVariableChar(int c);
void SkipWhite();
void SkipWhiteLines();
void SkipLine();
void Trim(std::wstring & s);
};
#endif

View File

@@ -21,7 +21,7 @@ class CookieParser : public HttpSimpleParser
{
const char * cookie_string;
CookieTable & cookie_table;
CookieTab * cookie_tab;
protected:
@@ -41,7 +41,7 @@ protected:
// Cookie names are case insensitive according to section 3.1 of RFC 2965
ToLower(name);
std::pair<CookieTable::iterator, bool> res = cookie_table.insert( std::make_pair(name, value) );
std::pair<CookieTab::iterator, bool> res = cookie_tab->insert( std::make_pair(name, value) );
log << log2 << "Cookie, name: \"" << name << "\", value: \"" << value << "\"";
@@ -58,7 +58,7 @@ protected:
public:
CookieParser(const char * cookie_string_, CookieTable & cookie_table_) : cookie_string(cookie_string_), cookie_table(cookie_table_)
CookieParser()
{
HttpSimpleParser::separator = ';';
HttpSimpleParser::value_can_be_quoted = true;
@@ -66,6 +66,16 @@ public:
HttpSimpleParser::recognize_special_chars = false;
}
// cookie_string can be null
void Parse(const char * cookie_string_, CookieTab & cookie_tab_)
{
cookie_string = cookie_string_;
cookie_tab = &cookie_tab_;
HttpSimpleParser::Parse();
}
};

View File

@@ -1,44 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "data.h"
Data::Data()
{
signal_hup = false;
stdout_is_closed = false;
how_many_logged = 0;
// the rest will be read from a config file
}
void Data::SetAdditionalVariables()
{
SetHttpHost(base_url, base_url_http_host);
SetHttpHost(base_url_auth, base_url_auth_http_host);
}
void Data::SetHttpHost(const std::string & in, std::string & out)
{
if( strncmp(in.c_str(), "http://", 7) == 0 )
out = in.substr(7);
else
if( strncmp(in.c_str(), "https://", 8) == 0 )
out = in.substr(8);
else
out.clear(); // if empty the RequestController::BaseUrlRedirect() returns false and no redirecting will be done
}

View File

@@ -1,213 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslucoredata
#define headerfilecmslucoredata
#include <string>
#include <vector>
#include <map>
#include <string.h>
#include "dirs.h"
#include "users.h"
#include "groups.h"
#include "functions.h"
#include "lastcontainer.h"
#include "mounts.h"
#include "rebus.h"
#include "loadavg.h"
class Data
{
public:
// -----------------------------------------------------------------
// members read from a config file
// name of the config file (full path can be)
std::string config_file;
// log file name, log file name for notifications (sending emails, etc)
std::string log_file, log_notify_file;
// 1 - minimum
// 2 - (default)
// 3 - maximum - all logs
int log_level;
// logging to stdout too
bool log_stdout;
// how many requests should be logged in the same time
// default: 1
int log_request;
// fast cgi: socket (unix domain)
std::string fcgi_socket;
// fast cgi: socket permissions
int fcgi_socket_chmod;
// fast cgi: owner of the socket
std::string fcgi_socket_user;
// fast cgi: group of the socket
std::string fcgi_socket_group;
std::string templates_dir;
std::string templates_dir_default; // templates from winix
std::string db_database;
std::string db_user;
std::string db_pass;
std::string http_session_id_name;
// when the HOST_HTTP environment variable doesn't point into 'base_url' (the part 'http://' and the last slash is removed)
// the server will redirect into 'base_url' + 'REQUEST_URI'
// it's useful when you want to redirect from 'mydomain.tld' into 'www.mydomain.tld' etc.
bool base_url_redirect;
// string used in a place where is a user (or group) selected
std::string priv_no_user;
std::string priv_no_group;
// time in seconds when the user will be automatically logged out (iddle time)
int session_max_idle;
// time in seconds when the user will be automatically logged out (when he selected 'remember me' option)
// this time is usually greater than session_max_idle
int session_remember_max_idle;
// this file is used when the program is starting and ending
std::string session_file;
// allow the html ouput to be compressed
bool compression;
// plugins
std::vector<std::string> plugin_file;
// the html code is cleaned by our filter
bool html_filter;
// the url of a new empty item (if there is not the subject too)
std::string item_url_empty;
// maximum length of a file send by post multipart form
// 0 - not used
int post_file_max;
// directories for static files
std::string auth_simplefs_dir;
std::string auth_hashfs_dir;
// temporary directory for static content used by the upload function
// should be on the same partition as auth_simplefs_dir and auth_hashfs_dir
std::string auth_tmp_dir;
// default locale: en pl
std::string locale_str;
// directory with locale files
std::string locale_dir;
// directory with default locale files (those from winix)
std::string locale_dir_default;
// the main address of the server (e.g. someserver.com) (without the 'www' part etc)
std::string base_server;
// the main address of the site (e.g. http://www.someserver.com)
std::string base_url;
// static content authorized by winix
std::string base_url_auth;
// static content not authorized by winix
std::string base_url_static;
// additional static server for common content (not authorized)
std::string base_url_common;
// separator used in <title> html tag
std::string title_separator;
// end config members
// -----------------------------------------------------------------
// false at the beginning
bool stdout_is_closed;
// true if there was SIGHUP signal
volatile bool signal_hup;
// contains current directories tree
Dirs dirs;
// based on base_url
// set by SetAdditionalVariables()
// without the first part http:// (or https://) or the whole string is empty
std::string base_url_http_host;
std::string base_url_auth_http_host;
// call this method after the config file is read
void SetAdditionalVariables();
// users
Users users;
// groups
Groups groups;
// functions (ls, cat, etc)
Functions functions;
// for 'last' function
LastContainer last;
// mount points
Mounts mounts;
// rebus (captcha)
Rebus rebus;
// the time when the winix starts
time_t system_start;
// how many logged users
long how_many_logged;
// load averages
LoadAvg load_avg;
Data();
private:
void SetHttpHost(const std::string & in, std::string & out);
};
extern Data data;
#endif

File diff suppressed because it is too large Load Diff

248
core/db.h
View File

@@ -1,248 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslucoredb
#define headerfilecmslucoredb
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <libpq-fe.h>
#include <cstdio>
#include <ctime>
#include <cstring>
#include "item.h"
#include "user.h"
#include "group.h"
#include "thread.h"
#include "error.h"
#include "dircontainer.h"
#include "ugcontainer.h"
#include "ticket.h"
class Db
{
public:
Db(bool close_at_end_ = true);
~Db();
// !! przerobic tak aby GetItem zwracalo wszystkie pozycja
// !! GetFile tylko dla plikow
// !! GetDir tylko dla katalogow
// !! GetFile i GetDir beda uzywac GetItem
void Init(const std::string & database, const std::string & user, const std::string & pass);
bool CheckUser(std::string & login, std::string & password, long & user_id);
Error AddUser(User & user, const std::string & password);
Error AddItem(Item & item);
Error EditItemById(Item & item, bool with_url = true);
Error EditItemByUrl(Item & item, bool with_url = true);
void CheckAllUrlSubject();
struct ItemQuery
{
// id is selected always
bool sel_parent_id; // parent_id
bool sel_user_id; // user_id
bool sel_group_id; // group_id
bool sel_guest_name; // guest_name
bool sel_privileges; // privileges
bool sel_date; // date_creation, date_modification
bool sel_subject; // subject
bool sel_content; // content, content_type, (content_id)
bool sel_url; // url
bool sel_type; // type (dir, file, none)
bool sel_default_item; // default_item
bool sel_auth; // auth, auth_path
bool where_id; //
bool where_parent_id; //
bool where_type;
bool where_auth;
long id; // if where_id is true
long parent_id; // if where_parent_id is true
Item::Type type;
Item::Auth auth;
bool auth_equal; // if true means auth should be equal
bool sort_asc;
void SetAll(bool sel, bool where_)
{
sel_parent_id = sel;
sel_user_id = sel;
sel_group_id = sel;
sel_guest_name = sel;
sel_privileges = sel;
sel_date = sel;
sel_subject = sel;
sel_content = sel;
sel_url = sel;
sel_type = sel;
sel_default_item= sel;
sel_auth = sel;
where_id = where_;
where_parent_id = where_;
where_type = where_;
where_auth = where_;
}
void WhereId(long id_) { where_id = true; id = id_; }
void WhereParentId(long parent_id_) { where_parent_id = true; parent_id = parent_id_; }
void WhereType(Item::Type type_) { where_type = true; type = type_; }
void WhereAuth(Item::Auth st,
bool equal = true) { where_auth = true; auth = st; auth_equal = equal; }
ItemQuery()
{
sort_asc = true;
auth_equal = true;
SetAll(true, false);
id = -1;
parent_id = -1;
type = Item::none;
auth = Item::auth_none;
}
};
void GetItems(std::vector<Item> & item_table, const ItemQuery & item_query);
// !! pobiera tylko jeden item (cos wymyslec innego z nazwa albo argumentem)
void GetItem(std::vector<Item> & item_table, long id);
bool GetPriv(Item & item, long id);
Error EditPrivById(Item & item, long id);
Error EditParentUrlById(Item & item, long id);
Error EditAuthById(Item & item, long id);
Error DelDirById(long id);
Error EditSubjectById(Item & item, long id);
bool DelItem(const Item & item);
void GetDirs(DirContainer & dir_table);
void GetUsers(UGContainer<User> & user_table);
void GetGroups(UGContainer<Group> & group_table);
// !! nowy interfejs
long Size(long parent_id, Item::Type type = Item::none);
Error GetItemById(long item_id, Item & item);
Error GetItem(long parent_id, const std::string & url, Item & item);
Error EditDefaultItem(long id, long new_default_item);
long GetItemId(long parent_id, const std::string & url, Item::Type type);
long GetFileId(long parent_id, const std::string & url);
long GetDirId(long parent_id, const std::string & url);
static tm ConvertTime(const char * str);
static const char * ConvertTime(const tm & t);
PGconn * GetPGconn();
virtual void Connect();
Error AddThread(Thread & thread);
Error GetThreadByDirId(long dir_id, Thread & thread);
Error GetThreads(long parent_id, std::vector<Thread> & thread_tab);
Error EditThreadAddItem(long dir_id, long item_id);
Error EditThreadRemoveItem(long dir_id);
Error RemoveThread(long dir_id);
Error GetTicketByDirId(long dir_id, Ticket & ticket);
Error GetTickets(long parent_id, std::vector<Ticket> & ticket_tab);
//bool IsTicket(long dir_id);
Error AddTicket(Ticket & ticket);
Error EditTicketById(Ticket & ticket);
Error EditTicketRemoveItem(long item_id);
Error RemoveTicket(long dir_id);
protected:
PGconn * pg_conn;
std::string db_database, db_user, db_pass;
bool close_at_end;
void SetDbParameters();
void Close();
void AssertConnection();
std::string Escape(const std::string & s);
std::string Escape(const char * s);
PGresult * AssertQuery(const std::string & q);
void AssertResultStatus(PGresult * r, ExecStatusType t);
static int AssertColumn(PGresult * r, const char * column_name);
static const char * AssertValue(PGresult * r, int row, int col);
void ClearResult(PGresult * r);
long AssertCurrval(const char * table);
bool AddItemCreateUrlSubject(Item & item);
Error AddItemIntoContent(Item & item);
Error AddItemIntoItem(Item & item);
Error EditItemInItem(Item & item, bool with_url);
Error EditItemInContent(Item & item);
Error EditItemGetId(Item & item);
Error EditItemGetContentId(Item & item);
void CheckAllUrlSubjectModifyItem(Item & item);
PGresult * GetItemsQuery(const ItemQuery & iq);
bool DelItemDelItem(const Item & item);
void DelItemDelContent(const Item & item);
Error DelItemCountContents(const Item & item, long & contents);
struct ItemColumns
{
int id, user_id, group_id, privileges, date_creation, date_modification, url, type, parent_id,
content_id, default_item, subject, content, content_type, guest_name, auth, auth_path;
void SetColumns(PGresult * r);
void SetItem(PGresult * r, long row, Item & item);
};
struct TicketColumns
{
int id, dir_id, parent_id, type, status, priority, category, expected, progress, item_id;
void SetColumns(PGresult * r);
void SetTicket(PGresult * r, long row, Ticket & ticket);
};
}; // class Db
extern Db db;
#endif

View File

@@ -1,95 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "db.h"
void Db::ItemColumns::SetColumns(PGresult * r)
{
// PQfnumber returns -1 if there is no such a column
id = PQfnumber(r, "id");
user_id = PQfnumber(r, "user_id");
group_id = PQfnumber(r, "group_id");
privileges = PQfnumber(r, "privileges");
date_creation = PQfnumber(r, "date_creation");
date_modification = PQfnumber(r, "date_modification");
url = PQfnumber(r, "url");
type = PQfnumber(r, "type");
parent_id = PQfnumber(r, "parent_id");
content_id = PQfnumber(r, "content_id");
default_item = PQfnumber(r, "default_item");
subject = PQfnumber(r, "subject");
content = PQfnumber(r, "content");
content_type = PQfnumber(r, "content_type");
guest_name = PQfnumber(r, "guest_name");
auth = PQfnumber(r, "auth");
auth_path = PQfnumber(r, "auth_path");
}
void Db::ItemColumns::SetItem(PGresult * r, long row, Item & item)
{
if( id != -1 ) item.id = atol( Db::AssertValue(r, row, id) );
if( user_id != -1 ) item.user_id = atol( Db::AssertValue(r, row, user_id) );
if( group_id != -1 ) item.group_id = atol( Db::AssertValue(r, row, group_id) );
if( privileges != -1 ) item.privileges = atoi( Db::AssertValue(r, row, privileges) );
if( date_creation != -1 ) item.date_creation = ConvertTime( Db::AssertValue(r, row, date_creation) );
if( date_modification != -1 ) item.date_modification = ConvertTime( Db::AssertValue(r, row, date_modification) );
if( url != -1 ) item.url = Db::AssertValue(r, row, url);
if( type != -1 ) item.type = static_cast<Item::Type>( atoi(Db::AssertValue(r, row, type)) );
if( parent_id != -1 ) item.parent_id = atol( Db::AssertValue(r, row, parent_id) );
if( content_id != -1 ) item.content_id = atol( Db::AssertValue(r, row, content_id) );
if( default_item != -1 ) item.default_item = atol( Db::AssertValue(r, row, default_item) );
if( subject != -1 ) item.subject = Db::AssertValue(r, row, subject);
if( content != -1 ) item.content = Db::AssertValue(r, row, content);
if( content_type != -1 ) item.content_type = static_cast<Item::ContentType>( atoi(Db::AssertValue(r, row, content_type)) );
if( guest_name != -1 ) item.guest_name = Db::AssertValue(r, row, guest_name);
if( auth != -1 ) item.auth = static_cast<Item::Auth>( atoi(Db::AssertValue(r, row, auth)) );
if( auth_path != -1 ) item.auth_path = Db::AssertValue(r, row, auth_path);
}
void Db::TicketColumns::SetColumns(PGresult * r)
{
// PQfnumber returns -1 if there is no such a column
id = PQfnumber(r, "id");
dir_id = PQfnumber(r, "dir_id");
parent_id = PQfnumber(r, "parent_id");
type = PQfnumber(r, "type");
status = PQfnumber(r, "status");
priority = PQfnumber(r, "priority");
category = PQfnumber(r, "category");
expected = PQfnumber(r, "expected");
progress = PQfnumber(r, "progress");
item_id = PQfnumber(r, "item_id");
}
void Db::TicketColumns::SetTicket(PGresult * r, long row, Ticket & ticket)
{
if( id != -1 ) ticket.id = atol( Db::AssertValue(r, row, id) );
if( dir_id != -1 ) ticket.dir_id = atol( Db::AssertValue(r, row, dir_id) );
if( parent_id != -1 ) ticket.parent_id = atol( Db::AssertValue(r, row, parent_id) );
if( type != -1 ) ticket.type = atoi( Db::AssertValue(r, row, type) );
if( status != -1 ) ticket.status = atoi( Db::AssertValue(r, row, status) );
if( priority != -1 ) ticket.priority = atoi( Db::AssertValue(r, row, priority) );
if( category != -1 ) ticket.category = atoi( Db::AssertValue(r, row, category) );
if( expected != -1 ) ticket.expected = atoi( Db::AssertValue(r, row, expected) );
if( progress != -1 ) ticket.progress = atoi( Db::AssertValue(r, row, progress) );
if( item_id != -1 ) ticket.item_id = atol( Db::AssertValue(r, row, item_id) );
}

View File

@@ -11,13 +11,15 @@
#include "log.h"
std::string DirContainer::dir_etc = "etc";
std::wstring DirContainer::dir_etc = L"etc";
std::wstring DirContainer::dir_var = L"var";
DirContainer::DirContainer()
{
is_root = false;
is_etc = false;
is_var = false;
}
@@ -40,6 +42,15 @@ return etc_iter;
}
DirContainer::Iterator DirContainer::GetVar()
{
if( !is_var )
return table.end();
return var_iter;
}
DirContainer::Iterator DirContainer::Begin()
{
return table.begin();
@@ -54,7 +65,7 @@ DirContainer::Iterator DirContainer::End()
DirContainer::SizeType DirContainer::Size()
{
return table.size();
return table.size(); // !! warning: it has O(n)
}
bool DirContainer::Empty()
@@ -63,25 +74,37 @@ bool DirContainer::Empty()
}
bool DirContainer::IsNameOfSpecialFolder(const std::wstring & name)
{
return name == dir_etc || name == dir_var;
}
// looking for '/etc'
// 'root' is found beforehand
// CheckSpecialFolder() may not find everything (when the first is a special folder and then the root)
void DirContainer::FindSpecialFolders()
{
is_etc = false;
is_var = false;
if( !is_root )
return;
DirContainer::ParentIterator i = FindFirstParent(root_iter->id);
DirContainer::ParentIterator i = FindFirstChild(root_iter->id);
for( ; i!=ParentEnd() ; i = NextParent(i) )
for( ; i!=ParentEnd() ; i = NextChild(i) )
{
if( i->second->url == dir_etc )
{
is_etc = true;
etc_iter = i->second;
break;
}
else
if( i->second->url == dir_var )
{
is_var = true;
var_iter = i->second;
}
}
}
@@ -103,8 +126,16 @@ void DirContainer::CheckSpecialFolder(const Item & item, Iterator iter)
{
is_etc = true;
etc_iter = iter;
log << log1 << "DirCont: added special folder: /etc" << logend;
log << log2 << "DirCont: added special folder: /etc" << logend;
}
if( item.parent_id==root_iter->id && item.url==dir_var )
{
is_var = true;
var_iter = iter;
log << log2 << "DirCont: added special folder: /var" << logend;
}
}
@@ -141,10 +172,10 @@ bool DirContainer::ChangeParent(long dir_id, long new_parent_id)
if( i->parent_id == new_parent_id )
return true; // nothing to do
ParentIterator p = FindFirstParent(i->parent_id);
ParentIterator p = FindFirstChild(i->parent_id);
bool found = false;
for( ; p != table_parent.end() ; p = NextParent(p) )
for( ; p != table_parent.end() ; p = NextChild(p) )
{
if( p->second->id == dir_id )
{
@@ -157,7 +188,7 @@ bool DirContainer::ChangeParent(long dir_id, long new_parent_id)
found = true;
if( i->url == "etc" ) // !! in the future can be more special folders
if( IsNameOfSpecialFolder(i->url) )
FindSpecialFolders();
break; // that iterator (p) is only one
@@ -220,7 +251,7 @@ bool DirContainer::ParentEmpty()
}
DirContainer::ParentIterator DirContainer::FindFirstParent(long parent)
DirContainer::ParentIterator DirContainer::FindFirstChild(long parent)
{
ParentIterator i = table_parent.lower_bound(parent);
@@ -231,7 +262,7 @@ return i;
}
DirContainer::ParentIterator DirContainer::NextParent(ParentIterator i)
DirContainer::ParentIterator DirContainer::NextChild(ParentIterator i)
{
if( i == table_parent.end() )
return table_parent.end();

View File

@@ -34,6 +34,7 @@ public:
Iterator GetRoot();
Iterator GetEtc();
Iterator GetVar();
Iterator Begin();
Iterator End();
@@ -51,9 +52,10 @@ public:
ParentIterator ParentEnd();
ParentSizeType ParentSize();
bool ParentEmpty();
ParentIterator FindFirstParent(long parent);
ParentIterator NextParent(ParentIterator pi);
ParentIterator FindFirstChild(long parent);
ParentIterator NextChild(ParentIterator pi);
bool IsNameOfSpecialFolder(const std::wstring & name);
void FindSpecialFolders();
private:
@@ -75,12 +77,18 @@ private:
// etc
Iterator etc_iter;
// true if there is a var dir in the table
bool is_var;
// var
Iterator var_iter;
// indexes
TableId table_id;
TableParent table_parent;
// names of folders
static std::string dir_etc;
static std::wstring dir_etc, dir_var;
};

View File

@@ -10,29 +10,51 @@
#include "dirs.h"
#include "error.h"
#include "log.h"
#include "db.h"
#include "data.h"
#include "request.h"
void Dirs::SetDb(Db * pdb)
{
db = pdb;
}
void Dirs::SetRequest(Request * prequest)
{
request = prequest;
}
void Dirs::SetNotify(Notify * pnotify)
{
notify = pnotify;
}
void Dirs::Clear()
{
dir_table.Clear();
dir_tab.Clear();
}
bool Dirs::HasReadExecAccessForRoot(const Item & item)
{
// there must be at least one 'x' (for the root)
return (item.privileges & 01111) != 0; // !! in the future there'll be another 'x'
}
void Dirs::CheckRootDir()
{
DirContainer::Iterator i = dir_table.GetRoot();
DirContainer::Iterator i = dir_tab.GetRoot();
if( i != dir_table.End() )
if( i != dir_tab.End() )
{
if( !request.HasReadExecAccessForRoot(*i) )
if( !HasReadExecAccessForRoot(*i) )
{
i->privileges = 0755;
log << log1 << "Dirs: there is no access for root (admin) to the root dir, setting 0755 for root dir" << logend;
db.EditPrivById(*i, i->id);
db->EditPrivById(*i, i->id);
}
return;
@@ -48,13 +70,12 @@ void Dirs::CheckRootDir()
root.user_id = -1;
root.group_id = -1;
root.privileges = 0755;
root.default_item = -1;
// !! upewnic sie ze baza nie zmieni url (gdyby wczesniej juz byl w bazie pusty url)
// !! zrobic jakis wyjatek do wprowadzania roota?
if( db.AddItem(root) == WINIX_ERR_OK )
if( db->AddItem(root) == WINIX_ERR_OK )
{
dir_table.PushBack(root);
dir_tab.PushBack(root);
}
}
@@ -65,13 +86,13 @@ void Dirs::ReadDirs()
{
Clear();
db.GetDirs(dir_table);
db->GetDirs(dir_tab);
CheckRootDir();
dir_table.FindSpecialFolders();
dir_tab.FindSpecialFolders();
}
bool Dirs::ExtractName(const char * & s, std::string & name)
bool Dirs::ExtractName(const wchar_t * & s, std::wstring & name)
{
name.clear();
@@ -90,9 +111,9 @@ return !name.empty();
bool Dirs::IsDir(long id)
{
DirContainer::Iterator i = dir_table.FindId(id);
DirContainer::Iterator i = dir_tab.FindId(id);
if( i == dir_table.End() )
if( i == dir_tab.End() )
return false;
return true;
@@ -100,38 +121,39 @@ return true;
bool Dirs::GetDirChilds(long parent, std::vector<Item*> & childs_table)
// !! dac clearowanie childs_tab
// !! ewentualnie mozna dodac trzeci domyslny parametr bool clear_tab = true
bool Dirs::GetDirChilds(long parent, std::vector<Item*> & childs_tab)
{
if( parent != -1 && !IsDir(parent) )
return false;
DirContainer::ParentIterator i = dir_table.FindFirstParent(parent);
DirContainer::ParentIterator i = dir_tab.FindFirstChild(parent);
for( ; i != dir_table.ParentEnd() ; i = dir_table.NextParent(i) )
childs_table.push_back( &(*i->second) );
for( ; i != dir_tab.ParentEnd() ; i = dir_tab.NextChild(i) )
childs_tab.push_back( &(*i->second) );
return true;
}
DirContainer::ParentIterator Dirs::FindFirstParent(long parent_id)
DirContainer::ParentIterator Dirs::FindFirstChild(long parent_id)
{
DirContainer::ParentIterator i = dir_table.FindFirstParent(parent_id);
DirContainer::ParentIterator i = dir_tab.FindFirstChild(parent_id);
return i;
}
DirContainer::ParentIterator Dirs::NextParent(DirContainer::ParentIterator i)
DirContainer::ParentIterator Dirs::NextChild(DirContainer::ParentIterator i)
{
return dir_table.NextParent(i);
return dir_tab.NextChild(i);
}
DirContainer::ParentIterator Dirs::ParentEnd()
{
return dir_table.ParentEnd();
return dir_tab.ParentEnd();
}
@@ -139,28 +161,36 @@ DirContainer::ParentIterator Dirs::ParentEnd()
// albo tutaj stringa nie czyscic?
// O(m * log n) (m- how many parts are in 'id')
// path with a slash at the end
bool Dirs::MakePath(long id, std::string & path)
bool Dirs::MakePath(long id, std::wstring & path, bool clear_path)
{
DirContainer::Iterator i;
path = '/';
if( clear_path )
path.clear();
temp_path = '/';
while( true )
{
i = dir_table.FindId(id);
i = dir_tab.FindId(id);
if( i == dir_table.End() ||
if( i == dir_tab.End() ||
i->parent_id == id ) // means a loop (something wrong in the db)
{
// we don't change path if there is no such a directory
return false;
}
if( i->parent_id == -1 )
{
path += temp_path;
return true;
}
id = i->parent_id;
path.insert(0, i->url);
path.insert(path.begin(), '/');
temp_path.insert(0, i->url);
temp_path.insert(temp_path.begin(), '/');
}
}
@@ -168,7 +198,7 @@ DirContainer::Iterator i;
bool Dirs::ChangeParent(long dir_id, long new_parent_id)
{
return dir_table.ChangeParent(dir_id, new_parent_id);
return dir_tab.ChangeParent(dir_id, new_parent_id);
}
@@ -182,9 +212,9 @@ DirContainer::Iterator i;
while( true )
{
i = dir_table.FindId(dir_id);
i = dir_tab.FindId(dir_id);
if( i==dir_table.End() || i->parent_id==-1 )
if( i==dir_tab.End() || i->parent_id==-1 )
return false;
if( i->parent_id == parent_id )
@@ -197,11 +227,38 @@ DirContainer::Iterator i;
bool Dirs::CreateDirTab(long dir_id, std::vector<Item*> & out_dir_tab)
{
DirContainer::Iterator i;
out_dir_tab.clear();
do
{
i = dir_tab.FindId(dir_id);
if( i == dir_tab.End() )
return false;
if( out_dir_tab.empty() )
out_dir_tab.insert(out_dir_tab.end(), &(*i)); // !! I am not sure whether begin() can be used on an empty container
else
out_dir_tab.insert(out_dir_tab.begin(), &(*i));
dir_id = i->parent_id;
}
while( dir_id != -1 );
return true;
}
Item * Dirs::GetRootDir()
{
DirContainer::Iterator root = dir_table.GetRoot();
DirContainer::Iterator root = dir_tab.GetRoot();
if( root == dir_table.End() )
if( root == dir_tab.End() )
return 0;
return &(*root);
@@ -210,20 +267,31 @@ return &(*root);
Item * Dirs::GetEtcDir()
{
DirContainer::Iterator etc = dir_table.GetEtc();
DirContainer::Iterator etc = dir_tab.GetEtc();
if( etc == dir_table.End() )
if( etc == dir_tab.End() )
return 0;
return &(*etc);
}
Item * Dirs::GetDir(const std::string & name, long parent)
Item * Dirs::GetVarDir()
{
DirContainer::ParentIterator i = dir_table.FindFirstParent(parent);
DirContainer::Iterator etc = dir_tab.GetVar();
for( ; i!=dir_table.ParentEnd() ; i = dir_table.NextParent(i) )
if( etc == dir_tab.End() )
return 0;
return &(*etc);
}
Item * Dirs::GetDir(const std::wstring & name, long parent)
{
DirContainer::ParentIterator i = dir_tab.FindFirstChild(parent);
for( ; i!=dir_tab.ParentEnd() ; i = dir_tab.NextChild(i) )
if( i->second->url == name )
return &(*i->second);
@@ -232,18 +300,18 @@ return 0;
Item * Dirs::GetDir(const std::string & path)
Item * Dirs::GetDir(const std::wstring & path)
{
DirContainer::Iterator root = dir_table.GetRoot();
DirContainer::Iterator root = dir_tab.GetRoot();
if( root == dir_table.End() )
if( root == dir_tab.End() )
// ops, we do not have a root dir
return 0;
Item * pitem = &(*root);
std::string name;
const char * s = path.c_str();
std::wstring name; // !! dodac jako skladowa klasy
const wchar_t * s = path.c_str();
while( ExtractName(s, name) )
{
@@ -253,16 +321,15 @@ Item * Dirs::GetDir(const std::string & path)
return 0;
}
return pitem;
}
Item * Dirs::GetDir(long id)
{
DirContainer::Iterator i = dir_table.FindId(id);
DirContainer::Iterator i = dir_tab.FindId(id);
if( i == dir_table.End() )
if( i == dir_tab.End() )
return 0;
return &(*i);
@@ -273,13 +340,13 @@ return &(*i);
Item * Dirs::AddDir(const Item & item)
{
return &(*dir_table.PushBack(item));
return &(*dir_tab.PushBack(item));
}
size_t Dirs::AnalyzeDir(Item * pdir, const std::string & path, long & dir_id, std::string & dir)
size_t Dirs::AnalyzeDir(Item * pdir, const std::wstring & path, long & dir_id, std::wstring & dir)
{
size_t i = 0;
size_t old_i;
@@ -301,7 +368,7 @@ size_t Dirs::AnalyzeDir(Item * pdir, const std::string & path, long & dir_id, st
for( ; i<path.size() && path[i] != '/' ; ++i)
analyze_temp += path[i];
pdir = data.dirs.GetDir(analyze_temp, pdir->id);
pdir = GetDir(analyze_temp, pdir->id);
if( !pdir )
return old_i; // analyze_temp is not a directory
@@ -325,9 +392,9 @@ size_t Dirs::AnalyzeDir(Item * pdir, const std::string & path, long & dir_id, st
2 - the path is empty
3 - there is not such a directory
*/
int Dirs::AnalyzePath(const std::string & path, long & dir_id, std::string & dir, std::string & file)
int Dirs::AnalyzePath(const std::wstring & path, long & dir_id, std::wstring & dir, std::wstring & file)
{
Item * pdir = data.dirs.GetRootDir();
Item * pdir = GetRootDir();
dir = '/';
file.clear();
@@ -358,10 +425,139 @@ return 0;
void Dirs::SplitPath(const std::string & path, std::string & dir, std::string & file)
// current_dir_tab can be the same container as out_dir_tab
void Dirs::CopyDirTab(const std::vector<Item*> & in, std::vector<Item*> & out)
{
std::string::size_type i;
if( &in != &out )
{
out.resize(in.size());
for(size_t i=0 ; i<in.size() ; ++i)
out[i] = in[i];
}
}
size_t Dirs::AnalyzeDir(std::vector<Item*> & dir_tab, const std::wstring & link_to)
{
if( dir_tab.empty() )
return 0;
size_t i = 0;
size_t old_i;
while( true )
{
// skipping slashes
for( ; i<link_to.size() && link_to[i] == '/' ; ++i);
if( i == link_to.size() )
return i; // end of the path
// creating a name
old_i = i;
analyze_temp.clear();
for( ; i<link_to.size() && link_to[i] != '/' ; ++i)
analyze_temp += link_to[i];
Item * pdir = GetDir(analyze_temp, dir_tab.back()->id);
if( !pdir )
return old_i; // analyze_temp is not a directory
dir_tab.push_back(pdir);
}
}
int Dirs::FollowLink(std::vector<Item*> & dir_tab, const std::wstring & link_to, std::wstring & out_item)
{
size_t i = AnalyzeDir(dir_tab, link_to);
if( i < link_to.size() )
{
// checking if at least one slash has left
for(size_t a=i ; a < link_to.size() ; ++a)
if( link_to[a] == '/' )
return 2; // there is not such a directory
// the rest of the path is a file name
out_item = link_to.c_str() + i;
return 1;
}
return 0;
}
/*
return codes:
ok:
0 - the link_to is a path to a directory (out_item skipped, out_dir_tab will not be empty)
1 - the link_to is a path to a file (out_item is used, out_dir_tab will not be empty)
error:
2 - incorrect link_to
3 - there is not a root dir
4 - current_dir_tab was empty
current_dir_tab can be the same container as out_dir_tab
link_to can be a relative path (without the first slash)
*/
int Dirs::FollowLink(const std::vector<Item*> & current_dir_tab, const std::wstring & link_to,
std::vector<Item*> & out_dir_tab, std::wstring & out_item)
{
temp_link_to = link_to; // link_to can be from the out_item and would be cleared next
out_item.clear();
if( current_dir_tab.empty() )
return 4;
if( temp_link_to.empty() )
{
CopyDirTab(current_dir_tab, out_dir_tab);
return 0;
}
if( temp_link_to[0] == '/' )
{
// temp_link_to is an absolute path
Item * pdir = GetRootDir();
if( !pdir )
return 3;
out_dir_tab.clear();
out_dir_tab.push_back(pdir);
}
else
{
// temp_link_to is a relative path
CopyDirTab(current_dir_tab, out_dir_tab);
}
return FollowLink(out_dir_tab, temp_link_to, out_item);
}
void Dirs::SplitPath(const std::wstring & path, std::wstring & dir, std::wstring & file)
{
std::wstring::size_type i;
dir.clear();
file.clear();
@@ -386,15 +582,78 @@ void Dirs::SplitPath(const std::string & path, std::string & dir, std::string &
}
// !! dodac kasowanie z bazy
bool Dirs::DelDir(long dir_id)
{
return dir_table.DelById(dir_id);
return dir_tab.DelById(dir_id);
}
Error Dirs::AddDirectory(Item & item, bool add_to_dir_tab, Item ** pdir, int notify_code)
{
if( pdir )
*pdir = 0;
if( item.type != Item::dir )
return WINIX_ERR_DIR_EXPECTED;
Error status = db->AddItem(item);
if( status == WINIX_ERR_OK )
{
Item * d = AddDir(item);
if( add_to_dir_tab && !request->dir_tab.empty() && request->dir_tab.back()->id == item.parent_id )
request->dir_tab.push_back(d);
if( pdir )
*pdir = d;
if( notify_code )
notify->ItemChanged(notify_code, item);
}
return status;
}
Item * Dirs::CreateVarDir()
{
Item * var = GetVarDir();
if( var )
return var;
Item v;
Item * root = GetRootDir();
if( root )
{
v.parent_id = root->id;
v.user_id = -1;
v.group_id = -1;
v.privileges = 0755;
v.subject = L"var";
v.url = L"var";
v.type = Item::dir;
AddDirectory(v, false, &var);
}
return var;
}
// printing first and last slash
void Dirs::LogDir(const std::vector<Item*> & dir_tab)
{
log << '/';
// skipping the first (root) directory
for(size_t i=1 ; i<dir_tab.size() ; ++i)
log << dir_tab[i]->url << '/';
}

View File

@@ -17,6 +17,9 @@
#include "item.h"
#include "dircontainer.h"
#include "db/db.h"
#include "request.h"
#include "notify/notify.h"
// we do not support '..' in a path (for simplicity and security reasons)
@@ -28,44 +31,71 @@ public:
void Clear();
void ReadDirs();
void SetRequest(Request * prequest);
void SetDb(Db * pdb);
void SetNotify(Notify * pnotify);
// these methods return false if there is no such a dir
bool IsDir(long dir_id);
bool GetDirChilds(long parent_id, std::vector<Item*> & childs_table);
bool MakePath(long dir_id, std::string & path);
bool GetDirChilds(long parent_id, std::vector<Item*> & childs_tab); // !! zamienic na GetChilds()
bool MakePath(long dir_id, std::wstring & path, bool clear_path = true);
bool ChangeParent(long dir_id, long new_parent_id);
bool HasParent(long dir_id, long parent_id);
bool DelDir(long dir_id);
int AnalyzePath(const std::string & path, long & dir_id, std::string & dir, std::string & file);
static void SplitPath(const std::string & path, std::string & dir, std::string & file);
bool CreateDirTab(long dir_id, std::vector<Item*> & out_dir_tab);
DirContainer::ParentIterator FindFirstParent(long parent_id);
DirContainer::ParentIterator NextParent(DirContainer::ParentIterator i);
void LogDir(const std::vector<Item*> & dir_tab);
int AnalyzePath(const std::wstring & path, long & dir_id, std::wstring & dir, std::wstring & file);
int FollowLink(const std::vector<Item*> & current_dir_tab, const std::wstring & link_to,
std::vector<Item*> & out_dir_tab, std::wstring & out_item);
static void SplitPath(const std::wstring & path, std::wstring & dir, std::wstring & file);
DirContainer::ParentIterator FindFirstChild(long parent_id); // !! zmienic w koncu nazwe na FindFirstChild
DirContainer::ParentIterator NextChild(DirContainer::ParentIterator i);
DirContainer::ParentIterator ParentEnd();
// these methods return null if there is no such a dir
// !! zmienic nazwy wskazujace ze operujemy tylko na lokalnej tablicy
Item * GetRootDir();
Item * GetEtcDir();
Item * GetDir(const std::string & name, long parent);
Item * GetDir(const std::string & path);
Item * GetVarDir();
Item * GetDir(const std::wstring & name, long parent);
Item * GetDir(const std::wstring & path);
Item * GetDir(long id);
Item * AddDir(const Item & item);
void CheckRootDir();
Item * CreateVarDir();
// !! jak juz wczesniejsze nazwy beda zmienione to tutaj damy AddDir() /AddDir() juz istnieje przeciez?/
Error AddDirectory(Item & item, bool add_to_dir_tab = false, Item ** pdir = 0, int notify_code = 0);
private:
DirContainer dir_table;
Request * request;
Db * db;
Notify * notify;
size_t AnalyzeDir(Item * pdir, const std::string & path, long & dir_id, std::string & dir);
std::string analyze_temp;
DirContainer dir_tab;
std::wstring temp_path;
std::wstring temp_link_to;
bool ExtractName(const char * & s, std::string & name);
size_t AnalyzeDir(Item * pdir, const std::wstring & path, long & dir_id, std::wstring & dir);
size_t AnalyzeDir(std::vector<Item*> & dir_tab, const std::wstring & link_to);
std::wstring analyze_temp;
void CopyDirTab(const std::vector<Item*> & in, std::vector<Item*> & out);
int FollowLink(std::vector<Item*> & dir_tab, const std::wstring & link_to, std::wstring & out_item);
bool ExtractName(const wchar_t * & s, std::wstring & name);
bool HasReadExecAccessForRoot(const Item & item);
};

View File

@@ -55,7 +55,6 @@
#define WINIX_DIFFERENT_MOUNT_POINTS 29
#define WINIX_ERR_DB_FATAL_ERROR_DURING_CONNECTING 100
#define WINIX_ERR_DB_INCORRECT_QUERY 101
#define WINIX_ERR_DB_INCORRENT_RESULT_STATUS 102
@@ -64,8 +63,12 @@
#define WINIX_ERR_DB_MORE_THAN_ONE_LOGIN 105
#define WINIX_ERR_DB_ERR_CURRVAL 106
#define WINIX_ERR_FILE_EXPECTED 107
#define WINIX_ERR_DIR_EXPECTED 108
//#define WINIX_ERR_UNKNOWN 1000
#define WINIX_NOTHING_TO_DO 109
typedef int Error;

View File

@@ -1,59 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "function.h"
Function::Function()
{
code = FUN_NONE;
}
void Function::Clear()
{
code = FUN_NONE;
item.Clear();
}
Function::Function(const Function & f)
{
code = f.code;
item = f.item;
}
Function & Function::operator=(const Function & f)
{
code = f.code;
item = f.item;
return *this;
}

View File

@@ -1,69 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslucorefunction
#define headerfilecmslucorefunction
#include <iostream>
#include "item.h"
#define FUN_NONE 0
#define FUN_LS 1
#define FUN_CAT 2
#define FUN_NODE 3
#define FUN_EMACS 4
#define FUN_MKDIR 5
#define FUN_DEFAULT 6
#define FUN_PRIV 7
#define FUN_RM 8
#define FUN_LOGIN 9
#define FUN_LOGOUT 10
#define FUN_RUN 11
#define FUN_WHO 12
#define FUN_LAST 13
#define FUN_CREATETHREAD 14
#define FUN_THREAD 15
#define FUN_RELOAD 16
#define FUN_UPLOAD 17
#define FUN_CREATETICKET 18
#define FUN_EDITTICKET 19
#define FUN_TICKET 20
#define FUN_UPTIME 21
#define FUN_MV 23
#define FUN_UNAME 24
#define FUN_CHMOD 25
#define FUN_CHOWN 26
#define FUN_CKEDITOR 27
#define FUN_DOWNLOAD 28
#define FUN_ADDUSER 29
#define FUN_SUBJECT 30
class Function
{
public:
int code;
Item item;
void Clear();
Function();
Function(const Function & f);
Function & operator=(const Function & f);
};
#endif

View File

@@ -1,58 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "functioncodeparser.h"
#include "function.h"
#include "log.h"
bool FunctionCodeParser::ContentHasOneRow(const Item & item)
{
for(size_t i=0 ; i<item.content.size() ; ++i)
if( item.content[i] == '\n' )
return false;
return true;
}
int FunctionCodeParser::ParseValue(const char * s)
{
if( strncmp(s, "[fun:", 5) != 0 )
return FUN_NONE;
const char * send;
int result = strtol(s+5, (char**)&send, 10);
if( send==s+5 || strcmp(send, "]") != 0 )
return FUN_NONE;
log << log2 << "FCP: function code: " << result << logend;
return result;
}
int FunctionCodeParser::Parse(const Item & item)
{
// format: [fun:1]
// minimum size: 7 characters
if( item.content.size() < 7 )
return FUN_NONE;
if( !ContentHasOneRow(item) )
return FUN_NONE;
return ParseValue(item.content.c_str());
}

View File

@@ -1,34 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslucorefunctioncodeparser
#define headerfilecmslucorefunctioncodeparser
#include <cstring>
#include <cstdlib>
#include "item.h"
class FunctionCodeParser
{
bool ContentHasOneRow(const Item & item);
int ParseValue(const char * s);
public:
int Parse(const Item & item);
};
#endif

View File

@@ -1,195 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "functionparser.h"
#include "log.h"
#include "item.h"
#include "error.h"
#include "data.h"
#include "db.h"
#include "request.h"
void FunctionParser::SkipEmptyString(const char * msg)
{
for( ; get_index != get_table_len && request.get_table[get_index].empty() ; ++get_index )
log << log3 << msg << logend;
}
void FunctionParser::ParseDirectories()
{
Item * pdir = data.dirs.GetRootDir();
if( !pdir )
{
// there is no the root dir
request.status = WINIX_ERR_NO_ROOT_DIR;
return;
}
while( true )
{
request.dir_table.push_back( pdir );
log << log3 << "FP: Directory: ";
if( pdir->parent_id == -1 )
log << "(root)" << logend;
else
log << pdir->url << logend;
SkipEmptyString("FP: Directory: skipped empty string");
if( get_index == get_table_len )
break;
pdir = data.dirs.GetDir(request.get_table[get_index], pdir->id);
if( !pdir )
break;
++get_index;
}
}
void FunctionParser::ParseItem()
{
SkipEmptyString("FP: Item: skipped empty string");
if( get_index == get_table_len )
return;
// request.dir_table has at least one element
long parent_id = request.dir_table.back()->id;
const std::string & url = request.get_table[get_index];
request.status = db.GetItem(parent_id, url, request.item);
if( request.status == WINIX_ERR_OK )
{
if( request.role == Request::authorizer && request.item.auth == Item::auth_none )
{
log << log1 << "FP: item.url: " << url << " exists but has not a static content (authorizer role)" << logend;
request.status = WINIX_ERR_NO_ITEM;
return;
}
++get_index;
request.is_item = true;
log << log3 << "FP: Item: id: " << request.item.id << ", url: " << request.item.url << logend;
}
else
{
log << log3 << "FP: No Item: url: " << url << logend;
}
}
void FunctionParser::ParseFunction()
{
SkipEmptyString("FP: Function: skipped empty string");
if( get_index == get_table_len )
return;
request.pfunction = data.functions.GetFunction(request.get_table[get_index]);
if( request.pfunction )
{
++get_index;
log << log3 << "FP: Function: " << request.pfunction->item.url << logend;
}
}
void FunctionParser::ParseParams()
{
while( true )
{
SkipEmptyString("FP: Params: skipped empty string");
if( get_index == get_table_len )
break;
request.param_table.push_back( &request.get_table[get_index] );
log << log3 << "FP: Params: " << request.get_table[get_index] << logend;
++get_index;
}
}
void FunctionParser::Parse()
{
request.status = WINIX_ERR_OK;
get_index = 0;
get_table_len = request.get_table.size();
request.pfunction = 0;
request.is_item = false;
ParseDirectories();
if( request.status != WINIX_ERR_OK )
return;
ParseFunction();
if( !request.pfunction )
{
ParseItem();
if( request.status != WINIX_ERR_OK )
return;
ParseFunction();
if( !request.pfunction && get_index != get_table_len )
{
request.status = WINIX_ERR_NO_FUNCTION;
log << log3 << "FP: Parse: unknown function: \"" << request.get_table[get_index] << "\"" << logend;
return;
}
}
ParseParams();
}

View File

@@ -1,125 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "functions.h"
void Functions::Clear()
{
table.clear();
}
void Functions::AddFun(int code, const char * url)
{
fun.code = code;
fun.item.url = url;
table.insert( std::make_pair(fun.item.url, fun) );
}
// in the future we will read these functions from the database
void Functions::ReadFunctions()
{
Clear();
fun.item.user_id = -1;
fun.item.group_id = -1;
fun.item.privileges = 0755;
fun.item.parent_id = -1; // !! temporarily doesn't matter
fun.item.id = -1;
fun.item.type = Item::file;
AddFun(FUN_LS, "ls");
AddFun(FUN_CAT, "cat");
AddFun(FUN_NODE, "node");
AddFun(FUN_EMACS, "emacs");
AddFun(FUN_MKDIR, "mkdir");
AddFun(FUN_DEFAULT, "default");
AddFun(FUN_PRIV, "priv");
AddFun(FUN_RM, "rm");
AddFun(FUN_LOGOUT, "logout");
AddFun(FUN_LOGIN, "login");
AddFun(FUN_RUN, "run");
AddFun(FUN_WHO, "who");
AddFun(FUN_LAST, "last");
AddFun(FUN_CREATETHREAD, "createthread");
AddFun(FUN_THREAD, "thread");
AddFun(FUN_UPLOAD, "upload");
AddFun(FUN_CREATETICKET, "createticket");
AddFun(FUN_EDITTICKET, "editticket");
AddFun(FUN_TICKET, "ticket");
AddFun(FUN_UPTIME, "uptime");
AddFun(FUN_MV, "mv");
AddFun(FUN_UNAME, "uname");
AddFun(FUN_CHMOD, "chmod");
AddFun(FUN_CHOWN, "chown");
AddFun(FUN_CKEDITOR, "ckeditor");
AddFun(FUN_DOWNLOAD, "download");
AddFun(FUN_ADDUSER, "adduser");
AddFun(FUN_SUBJECT, "subject");
// functions which need more privileges
fun.item.privileges = 0700;
AddFun(FUN_RELOAD, "reload");
}
Function * Functions::GetFunction(const std::string & name)
{
Table::iterator i = table.find(name);
if( i == table.end() )
return 0;
return &(i->second);
}
// !! in the future there will be a special container where we can search through the Code object
Function * Functions::GetFunction(int code)
{
Table::iterator i = table.begin();
for( ; i != table.end() ; ++i )
{
if( i->second.code == code )
return &(i->second);
}
return 0;
}

View File

@@ -1,43 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslucorefunctions
#define headerfilecmslucorefunctions
#include <map>
#include <string>
#include "function.h"
class Functions
{
typedef std::map<std::string, Function> Table;
Table table;
Function fun;
void AddFun(int code, const char * url);
public:
void Clear();
void ReadFunctions();
Function * GetFunction(const std::string & name);
Function * GetFunction(int code);
};
#endif

View File

@@ -12,13 +12,17 @@
#include "httpsimpleparser.h"
#include "requesttypes.h"
#include "misc.h"
#include "utf8.h"
class GetParser : public HttpSimpleParser
{
const char * get_string;
GetTable & get_table;
GetTab * get_tab;
std::wstring temp;
bool input_as_utf8;
protected:
@@ -33,22 +37,47 @@ protected:
virtual void Parameter(std::string &, std::string & value)
{
get_table.push_back(value);
log << log2 << "Get, value: \"" << value << "\"" << logend;
if( input_as_utf8 )
Ezc::UTF8ToWide(value, temp);
else
AssignString(value, temp);
get_tab->push_back(temp);
log << log2 << "Get, value: \"" << temp << "\"" << logend;
}
public:
GetParser(const char * get_string_, GetTable & get_table_) : get_string(get_string_), get_table(get_table_)
GetParser()
{
HttpSimpleParser::separator = '/';
HttpSimpleParser::read_name = false;
if( get_string && *get_string == separator ) // one '/' at the beginning
input_as_utf8 = false;
}
void UTF8(bool utf)
{
input_as_utf8 = utf;
}
// get_string_ can be null
void Parse(const char * get_string_, GetTab & get_tab_)
{
get_string = get_string_;
get_tab = &get_tab_;
if( get_string && *get_string == separator )
{
// skipping one '/' at the beginning
++get_string;
}
HttpSimpleParser::Parse();
}
};

View File

@@ -18,7 +18,7 @@
struct Group
{
long id;
std::string name; // group name
std::wstring name; // group name
std::vector<long> members; // users id
Group()

View File

@@ -8,7 +8,6 @@
*/
#include "groups.h"
#include "db.h"
@@ -25,11 +24,11 @@ void Groups::Clear()
}
void Groups::ReadGroups()
void Groups::ReadGroups(Db * db)
{
Clear();
db.GetGroups(table);
db->GetGroups(table);
}
@@ -44,7 +43,7 @@ return &(*i);
}
Group * Groups::GetGroup(const std::string & name)
Group * Groups::GetGroup(const std::wstring & name)
{
Table::Iterator i = table.FindName(name);
@@ -55,7 +54,7 @@ return &(*i);
}
long Groups::GetGroupId(const std::string & name)
long Groups::GetGroupId(const std::wstring & name)
{
Group * pgroup = GetGroup(name);

View File

@@ -14,6 +14,8 @@
#include "group.h"
#include "ugcontainer.h"
#include "db/db.h"
class Groups
@@ -29,10 +31,10 @@ public:
Groups();
void Clear();
void ReadGroups();
void ReadGroups(Db * db);
Group * GetGroup(long group_id);
Group * GetGroup(const std::string & name);
long GetGroupId(const std::string & name);
Group * GetGroup(const std::wstring & name);
long GetGroupId(const std::wstring & name);
Iterator Begin();
Iterator End();
SizeType Size();

File diff suppressed because it is too large Load Diff

View File

@@ -23,7 +23,7 @@
// length of a buffer used for printing
// it should be at least: WINIX_HTMLFILTER_ITEM_MAXLEN+3
#define WINIX_HTMLFILTER_BUFFER_MAXLEN 1024
#define WINIX_HTMLFILTER_BUFFER_MAXLEN 2048
@@ -48,20 +48,40 @@ class HTMLFilter
{
public:
// for checking orphans
enum Lang
{
lang_pl,
lang_cz,
lang_sk,
lang_none
};
enum OrphanMode
{
orphan_nbsp, // putting "&nbsp;" string
orphan_160space // putting 160 ascii code
};
HTMLFilter();
HTMLFilter(const HTMLFilter & f);
HTMLFilter & operator=(const HTMLFilter & f);
~HTMLFilter();
// main methods used for filtering
void Filter(const char * in, std::string & out);
void Filter(const std::string & in, std::string & out);
void Filter(const wchar_t * in, std::wstring & out);
void Filter(const std::wstring & in, std::wstring & out);
// insert a white space into long lines
// only between html tags
// skipped in such tags: script, pre, textarea
// false by default
void BreakLongLines(bool break_lines);
// break_after - after how many characters insert a space (0 - off)
void BreakLines(size_t break_after_);
// trimming white characters (with new lines)
// at the beginning, at the end and in the middle of a string
@@ -71,19 +91,30 @@ public:
// false by default
void TrimWhite(bool trim);
// first tabs in a tree
// default: 2 (spaces)
// set 0 to turn off
void InsertTabs(size_t tabsize);
// check 'orphans' for the specicic language
// if an orphan is detected then the non-break space ("&nbsp;" or ascii 160 code) will be put
// default disable (lang_none)
void CheckOrphans(Lang lang_, OrphanMode mode = orphan_nbsp);
// skipping some unsafe tags
// (script, iframe, frame, frameset, applet, head, meta, html, link, body, ...)
void SafeMode(bool safe_mode_);
protected:
struct Item
{
char name[WINIX_HTMLFILTER_ITEM_MAXLEN];
wchar_t name[WINIX_HTMLFILTER_ITEM_MAXLEN];
size_t name_len;
enum Type
@@ -104,60 +135,84 @@ protected:
// only this method have direct access to the output string
// you can easily change the output from a std::string to something else
void Put(const char * str, const char * end);
// you can easily change the output from a std::wstring to something else
virtual void Put(const wchar_t * str, const wchar_t * end);
Item & GetItem(size_t i);
Item & LastItem();
int ToLower(int c);
bool IsNameEqual(const char * name1, const char * name2);
bool IsNameEqual(const char * name1, const char * name2, size_t len);
bool IsLastTag(const char * name);
wchar_t ToLower(wchar_t c);
bool IsNameEqual(const wchar_t * name1, const wchar_t * name2);
bool IsNameEqual(const wchar_t * name1, const wchar_t * name2, size_t len);
bool IsLastTag(const wchar_t * name);
bool IsTagSafe(const wchar_t * tag);
int CheckOrphan(const wchar_t * str, const wchar_t * end, const wchar_t * orphan);
bool CheckOrphanTable(const wchar_t * str, const wchar_t * end, const wchar_t ** table, size_t o1, size_t o2);
bool CheckOrphanLangPl(const wchar_t * str, const wchar_t * end);
bool CheckOrphanLangCz(const wchar_t * str, const wchar_t * end);
bool CheckOrphan(const wchar_t * str, const wchar_t * end);
bool IsWhite(int c);
void SkipWhite();
void SkipWhiteLines();
bool SkipTagCheck();
void SkipNormalText();
bool IsOpeningCommentaryTag();
void SkipWhiteWithFirstNewLine();
bool IsClosingTagForLastItem();
virtual bool IsOpeningTagMark();
virtual bool IsOpeningCommentaryTagMark();
size_t OpeningCommentaryTagMarkSize();
virtual bool IsClosingTagMark();
virtual bool IsClosingXmlSimpleTagMark();
bool SkipCommentaryTagIfExists();
void SkipItem();
void SkipItemCheckXmlSimple();
const wchar_t * SkipItemCheckXmlSimple();
void PopStack();
bool PushStack();
bool IsValidCharForName(int c);
virtual bool IsValidCharForName(int c);
void CheckNewLine();
void CheckExceptions();
virtual void CheckExceptions();
void CheckStackPrintRest();
void AddForgottenTags();
void CheckClosingTags();
virtual void ReadNormalTextSkipWhite(const wchar_t * & start, const wchar_t * & last_non_white);
void ReadNormalText();
void PrintRest();
void PrintItem(const char * start, const char * end);
bool PrintRest();
void PrintItem(const wchar_t * start, const wchar_t * end);
void ReadItemName();
bool ReadItem();
virtual void Init();
virtual void Deinit();
void Read();
size_t PutTrimFillBuffer(const char * & str, const char * & end);
void PutTrim(const char * str, const char * end);
size_t PutNormalTextTrimFillBuffer(const wchar_t * & str, const wchar_t * & end);
size_t PutNormalTextFillBuffer(const wchar_t * & str, const wchar_t * & end);
virtual void PutNormalText(const wchar_t * str, const wchar_t * end);
virtual void PutNormalTextTrim(const wchar_t * str, const wchar_t * end);
void PutLastTagWithClosingTag();
void PutOpeningTag(const char * tag);
void PutClosingTag(const char * tag);
virtual void PutOpeningTagMark();
virtual void PutClosingTagMark();
virtual void PutTagName(const wchar_t * name);
virtual void PutOpeningTag(const wchar_t * start, const wchar_t * end);
virtual void PutClosingTag(const wchar_t * tag);
size_t PutTabsToBuffer(size_t index, size_t len);
size_t PutNonBreakSpaceToBuffer(size_t index);
void PutTabs(size_t len);
void PutNewLine();
const char * pchar;
const wchar_t * pchar;
Item empty;
Item * pstack; // stack pointer
size_t stack_len; // length of the stack
char * buffer; // buffer used when printing
std::string * out_string;
wchar_t * buffer; // buffer used when printing
std::wstring * out_string;
bool last_new_line;
bool break_long_lines; // insert a space into long lines
bool trim_white; // trimming white characters
size_t break_after; // insert a space into long lines after break_after characters
bool trim_white; // trimming white characters
size_t tab_size;
Lang lang; // current language for checking orphans
OrphanMode orphan_mode;
bool safe_mode; // skipping some unsafe tags
};

View File

@@ -46,7 +46,7 @@ protected:
void TrimWhiteChars(std::string & s);
void CheckSpecialChar();
void Parse();
public:
@@ -60,12 +60,6 @@ public:
skip_white_chars = false;
recognize_special_chars = true;
}
void Parse();
};

72
core/item.cpp Executable file
View File

@@ -0,0 +1,72 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "item.h"
#include "misc.h"
Item::Item()
{
Clear();
}
void Item::SetDateToNow()
{
date_creation = Time(std::time(0));
date_modification = date_creation;
}
void Item::SetDateModifyToNow()
{
date_modification = Time(std::time(0));
}
void Item::Clear()
{
id = -1;
user_id = -1;
group_id = -1;
privileges = 0;
modification_user_id = -1;
guest_name.clear();
subject.clear();
content.clear();
modify_index = 0;
url.clear();
content_type = ct_formatted_text;
type = none;
parent_id = -1;
link_to.clear();
link_redirect = false;
content_id = -1;
ref = 1;
file_path.clear();
file_fs = -1;
file_type = WINIX_ITEM_FILETYPE_NONE;
has_thumb = false;
html_template.clear();
SetDateToNow();
}

View File

@@ -13,6 +13,12 @@
#include <string>
#define WINIX_ITEM_FILETYPE_NONE 0
#define WINIX_ITEM_FILETYPE_IMAGE 1
#define WINIX_ITEM_FILETYPE_DOCUMENT 2
#define WINIX_ITEM_FILETYPE_UNKNOWN 3
struct Item
@@ -23,17 +29,20 @@ long parent_id;
long user_id;
long group_id;
std::string guest_name; // used as a user name when user_id is equal -1
std::wstring guest_name; // used as a user name when user_id is equal -1
long modification_user_id; // who has modified the item last (not taken into account when checking permissions)
int privileges;
tm date_creation;
tm date_modification;
std::string subject;
std::string content;
long content_id; // used by the database
std::string url;
std::wstring subject;
std::wstring content;
std::wstring url;
int modify_index;
enum ContentType
{
@@ -52,89 +61,44 @@ enum Type
{
dir = 0,
file = 1,
symlink = 2,
none = 1000 // !! pozbyc sie tego
none = 1000
};
Type type;
long default_item;
// used when type is symlink or to a directory too (function 'default')
std::wstring link_to;
int link_redirect;
// static file (if exists)
std::wstring file_path; // relative file path
int file_fs; // file system type where the file was saved
int file_type; // file type (none, image, doc, etc)
bool has_thumb;
// external static file authorized by winix
enum Auth
{
auth_none = 0, /* there is not an external file */
auth_image = 1, /* png, gif, jpg - only types available to render by a web browser*/
auth_document = 2, /* pdf doc xls txt */
auth_other = 3 /* other file */
};
Auth auth;
std::string auth_path; // path to a file (if auth!=auth_none)
// methods
Item()
{
Clear();
}
void SetDateToNow()
{
time_t t = std::time(0);
date_creation = *std::localtime( &t );
date_modification = date_creation;
}
void SetDateModifyToNow()
{
time_t t = std::time(0);
date_modification = *std::localtime( &t );
}
void Clear()
{
id = -1;
user_id = -1;
group_id = -1;
privileges = 0;
guest_name.clear();
subject.clear();
content.clear();
url.clear();
content_type = ct_formatted_text;
type = none;
parent_id = -1;
default_item = -1;
content_id = -1;
auth = auth_none;
auth_path.clear();
SetDateToNow();
}
std::wstring html_template;
// methods
Item();
void SetDateToNow();
void SetDateModifyToNow();
void Clear();
private:
// used by the database
long content_id; // content id in 'content' table
int ref; // content references
friend class Db;
friend class DbItemColumns;
};

View File

@@ -10,7 +10,7 @@
#include "lastcontainer.h"
#include "log.h"
#include "misc.h"
LastItem::LastItem()
@@ -68,7 +68,7 @@ return last_tab.end();
void LastContainer::UserLogin(long user_id, const std::string & name, unsigned int ip, long session_id)
void LastContainer::UserLogin(long user_id, const std::wstring & name, unsigned int ip, long session_id)
{
LastTab::iterator i = FindNotLoggedOut(user_id, session_id);
@@ -78,7 +78,7 @@ LastTab::iterator i = FindNotLoggedOut(user_id, session_id);
return;
}
if( last_tab.size() >= LAST_TABLE_SIZE )
if( last_tab.size() >= LAST_TABLE_SIZE ) // last_tab has O(n) complexity
last_tab.erase(last_tab.begin());
LastItem li;
@@ -87,9 +87,7 @@ LastTab::iterator i = FindNotLoggedOut(user_id, session_id);
li.name = name;
li.ip = ip;
li.session_id = session_id;
time_t t = std::time(0);
li.start = *localtime(&t);
li.start = Time(std::time(0));
last_tab.insert(last_tab.end(), li);
@@ -105,8 +103,7 @@ LastTab::iterator i = FindNotLoggedOut(user_id, session_id);
if( i != last_tab.end() )
{
time_t t = std::time(0);
i->end = *localtime(&t);
i->end = Time(std::time(0));
}
else
{

View File

@@ -28,7 +28,7 @@ struct LastItem
// additional we store the whole string-name
// (you can delete a user from the database but we can still print the name)
std::string name;
std::wstring name;
// ip address
unsigned int ip;
@@ -62,7 +62,7 @@ public:
Iterator Begin();
Iterator End();
void UserLogin(long user_id, const std::string & name, unsigned int ip, long session_id);
void UserLogin(long user_id, const std::wstring & name, unsigned int ip, long session_id);
void UserLogout(long user_id, long session_id);

View File

@@ -1,237 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "locale.h"
#include "log.h"
Locale::Locale()
{
loc_tab.resize(lang_unknown);
default_lang = lang_en;
current_lang = lang_en;
}
void Locale::AddLocale(Lang lang)
{
ConfParser::Table::iterator i = loc_parser.table.begin();
for( ; i != loc_parser.table.end() ; ++i)
loc_tab[lang][i->first] = i->second;
}
void Locale::ReadFile(const char * dir, const char * dir_def, Lang lang, const char * file)
{
if( static_cast<size_t>(lang) >= loc_tab.size() )
{
// ops, something wrong
return;
}
loc_tab[lang].clear();
bool read = false;
if( dir_def )
{
file_name = dir_def;
file_name += '/';
file_name += file;
if( loc_parser.Parse(file_name.c_str()) == ConfParser::ok )
{
read = true;
AddLocale(lang);
log << log3 << "Locale: read locale from: " << file_name << logend;
}
}
if( dir )
{
file_name = dir;
file_name += '/';
file_name += file;
if( loc_parser.Parse(file_name.c_str()) == ConfParser::ok )
{
read = true;
AddLocale(lang);
log << log3 << "Locale: read locale from: " << file_name << logend;
}
}
if( !read )
log << log1 << "Locale: cant open file for locale: " << file << logend;
}
void Locale::Read(const char * dir, const char * dir_def)
{
ReadFile(dir, dir_def, lang_pl, "pl");
ReadFile(dir, dir_def, lang_en, "en");
}
void Locale::Read(const std::string & dir, const std::string & dir_def)
{
if( dir_def.empty() )
Read(dir.c_str());
else
Read(dir.c_str(), dir_def.c_str());
}
void Locale::SetLang(Lang lang)
{
current_lang = lang;
}
Locale::Lang Locale::GetLang()
{
return current_lang;
}
void Locale::SetLangDef(Lang lang)
{
default_lang = lang_en;
}
bool Locale::IsKey(const std::string & key) const
{
return IsKey(key, current_lang);
}
bool Locale::IsKey(const std::string & key, Lang lang) const
{
if( static_cast<size_t>(lang) >= loc_tab.size() )
{
// ops, something wrong
return false;
}
// looking in the lang language
ConfParser::Table::const_iterator i = loc_tab[lang].find(key);
if( i != loc_tab[lang].end() )
return true;
if( lang == default_lang )
return false;
if( static_cast<size_t>(default_lang) >= loc_tab.size() )
{
// ops, something wrong
return false;
}
// looking in a default language
i = loc_tab[default_lang].find(key);
if( i != loc_tab[default_lang].end() )
return true;
// there is no such a key
return false;
}
const std::string & Locale::Get(const std::string & key) const
{
return Get(key, current_lang);
}
const std::string & Locale::Get(const std::string & key, Lang lang) const
{
if( static_cast<size_t>(lang) >= loc_tab.size() )
{
// ops, something wrong
return empty;
}
// looking in the lang language
ConfParser::Table::const_iterator i = loc_tab[lang].find(key);
if( i != loc_tab[lang].end() )
return i->second;
if( lang == default_lang )
return empty;
if( static_cast<size_t>(default_lang) >= loc_tab.size() )
{
// ops, something wrong
return empty;
}
// looking in a default language
i = loc_tab[default_lang].find(key);
if( i != loc_tab[default_lang].end() )
return i->second;
// there is no such a key
return empty;
}
Locale::Lang Locale::StrToLang(const std::string & str)
{
if( str == "en" )
return lang_en;
else
if( str == "pl" )
return lang_pl;
return lang_unknown;
}
const char * Locale::LangToStr(Lang lang)
{
static char buffer[30];
switch(lang)
{
case lang_en:
sprintf(buffer, "en");
break;
case lang_pl:
sprintf(buffer, "pl");
break;
default:
sprintf(buffer, "unknown");
}
return buffer;
}
size_t Locale::Size()
{
return loc_tab.size();
}

View File

@@ -1,70 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslucorelocale
#define headerfilecmslucorelocale
#include "../confparser/confparser.h"
#include <vector>
#include <string>
class Locale
{
public:
enum Lang
{
lang_en = 0,
lang_pl,
lang_unknown // should be last
};
Locale();
void Read(const char * dir, const char * dir_def = 0);
void Read(const std::string & dir, const std::string & dir_def);
bool IsKey(const std::string & key) const;
bool IsKey(const std::string & key, Lang lang) const;
const std::string & Get(const std::string & key) const;
const std::string & Get(const std::string & key, Lang lang) const;
// default is english
void SetLang(Lang lang);
Lang GetLang();
// which language is used instead if there is no a key in an other language
// default: lang_en
void SetLangDef(Lang lang);
static Lang StrToLang(const std::string & str);
static const char * LangToStr(Lang lang);
size_t Size();
private:
void AddLocale(Lang lang);
void ReadFile(const char * dir, const char * dir_def, Lang lang, const char * file);
std::vector<ConfParser::Table> loc_tab;
ConfParser loc_parser;
std::string file_name;
std::string empty;
Lang default_lang;
Lang current_lang;
};
#endif

View File

@@ -10,38 +10,54 @@
#include "log.h"
#include <ctime>
#include <string.h>
#include "utf8.h"
Log::Log()
{
log_level = 3;
current_level = 4; // nothing to log (call Init() first)
item = 0;
item_save = 1;
log_level = 1;
current_level = 100; // nothing to log (call Init() first)
request = 0;
max_requests = 1;
lines = 0;
max_lines = 5000;
log_file_open = false;
}
void Log::Init(int log_l, const std::string & log_f, bool log_std, int log_request)
Log::~Log()
{
log_level = log_l;
log_file = log_f;
log_stdout = log_std;
item_save = log_request;
SaveLogAndClear();
}
OpenFile();
void Log::Init(int log_level_, bool save_each_line_, const std::string & log_file_, bool log_std, int log_max_requests)
{
log_level = log_level_;
log_file = log_file_;
log_stdout = log_std;
max_requests = log_max_requests;
save_each_line = save_each_line_;
// don't open the file here
// because it would be created with the root as an owner
}
void Log::OpenFile()
{
if( !log_file.empty() )
{
file.open( log_file.c_str(), std::ios_base::out | std::ios_base::app );
log_file_open = true;
}
}
void Log::PutDate(Manipulators m)
{
// logs are related to localtime
time_t t = std::time(0);
std::tm * loct = std::localtime(&t);
@@ -57,10 +73,22 @@ void Log::PutDate(Manipulators m)
}
Log & Log::operator<<(const void * s)
{
if( current_level > log_level )
return *this;
buffer << s;
return *this;
}
Log & Log::operator<<(const char * s)
{
if( current_level > log_level )
return *this;
if( !s )
return *this;
@@ -73,8 +101,10 @@ return *this;
Log & Log::operator<<(const std::string & s)
{
buffer << s;
if( current_level > log_level )
return *this;
buffer << s;
return *this;
}
@@ -82,23 +112,63 @@ Log & Log::operator<<(const std::string & s)
Log & Log::operator<<(const std::string * s)
{
buffer << *s;
if( current_level > log_level )
return *this;
buffer << *s;
return *this;
}
Log & Log::operator<<(const void * s)
Log & Log::operator<<(const wchar_t * s)
{
buffer << s;
if( current_level <= log_level )
{
if( s )
buffer << s;
}
return *this;
}
Log & Log::operator<<(const std::wstring & s)
{
if( current_level <= log_level )
{
buffer << s;
}
return *this;
}
Log & Log::operator<<(const std::wstring * s)
{
if( current_level <= log_level )
{
buffer << *s;
}
return *this;
}
Log & Log::operator<<(int s)
{
buffer << s;
if( current_level <= log_level )
{
buffer << s;
}
return *this;
}
@@ -107,7 +177,10 @@ Log & Log::operator<<(int s)
Log & Log::operator<<(long s)
{
buffer << s;
if( current_level <= log_level )
{
buffer << s;
}
return *this;
}
@@ -117,7 +190,10 @@ Log & Log::operator<<(long s)
Log & Log::operator<<(char s)
{
buffer << s;
if( current_level <= log_level )
{
buffer << s;
}
return *this;
}
@@ -126,7 +202,10 @@ Log & Log::operator<<(char s)
Log & Log::operator<<(size_t s)
{
buffer << s;
if( current_level <= log_level )
{
buffer << s;
}
return *this;
}
@@ -135,7 +214,10 @@ Log & Log::operator<<(size_t s)
Log & Log::operator<<(double s)
{
buffer << s;
if( current_level <= log_level )
{
buffer << s;
}
return *this;
}
@@ -147,27 +229,23 @@ Log & Log::operator<<(Manipulators m)
switch(m)
{
case logend:
buffer << '\n';
lines += 1;
break;
if( current_level <= log_level )
{
buffer << '\n';
lines += 1;
case logsavenow:
SaveLog();
buffer.str( "" );
item = 0;
lines = 0;
if( save_each_line )
SaveLogAndClear();
}
break;
case logsave:
item += 1;
SaveLogAndClear();
break;
if( item >= item_save || lines > 3000 )
{
SaveLog();
buffer.str( "" );
item = 0;
lines = 0;
}
case logendrequest:
if( ++request >= max_requests || lines > max_lines )
SaveLogAndClear();
break;
case log1:
@@ -181,6 +259,10 @@ Log & Log::operator<<(Manipulators m)
case log3:
current_level = 3;
break;
case log4:
current_level = 4;
break;
}
return *this;
@@ -198,23 +280,28 @@ void Log::SystemErr(int err)
}
void Log::SaveLogAndClear()
{
SaveLog();
buffer.Clear();
request = 0;
lines = 0;
}
void Log::SaveLog()
{
if( current_level > log_level )
return;
const std::string & source = buffer.str();
if( source.empty() )
if( buffer.Str().empty() )
return;
if( log_stdout )
std::cout << source;
Ezc::WideToUTF8(buffer.Str(), std::cout);
if( log_file.empty() )
return;
if( !file )
if( !log_file_open || !file )
{
file.close();
file.clear();
@@ -225,7 +312,8 @@ void Log::SaveLog()
return;
}
file << source << std::endl;
Ezc::WideToUTF8(buffer.Str(), file);
file.flush();
}

View File

@@ -15,37 +15,36 @@
#include <fstream>
#include <iostream>
#include <string>
#include "textstream.h"
// !! dodac manipulator logsave, logi zostana zapisane pod koniec wykonywania jednego requesta (albo po kilku w zaleznosci od jakiejs opcji w konfigu)
// logsave zostanie wywolane w requestcontroller.cpp przy konczeniu wykonywania requesta
enum Manipulators { logsave, logsavenow, logend, log1, log2, log3 };
// log1 - the first level
// log2
// log3
// log4 - the last level (debug level)
// logend - the end of a line
// logendrequest - end of a current request
// logsave - current log buffer is saved and cleared
enum Manipulators { log1, log2, log3, log4, logend, logendrequest, logsave };
class Log
{
std::ostringstream buffer;
int log_level, current_level;
int item, item_save;
std::string log_file;
bool log_stdout;
std::ofstream file;
int lines;
void OpenFile();
public:
Log();
void Init(int log_l, const std::string & log_f, bool log_std, int log_request);
~Log();
void Init(int log_level_, bool save_each_line_, const std::string & log_file_, bool log_std, int log_max_requests);
void PutDate(Manipulators m);
Log & operator<<(const char * s);
Log & operator<<(const void * s);
Log & operator<<(const char * s);
Log & operator<<(const std::string * s);
Log & operator<<(const std::string & s);
Log & operator<<(const wchar_t * s);
Log & operator<<(const std::wstring * s);
Log & operator<<(const std::wstring & s);
Log & operator<<(int s);
Log & operator<<(long s);
Log & operator<<(char s);
@@ -54,8 +53,49 @@ public:
Log & operator<<(Manipulators m);
void SystemErr(int err);
void SaveLog();
void SaveLogAndClear();
private:
// buffer for the log
TextStream<std::wstring> buffer;
// log lovel from the config file
int log_level;
// current level set by a modifier (e.g. log << log3)
int current_level;
// current request for logging
// starts from zero and incremented after logendrequest modifier
int request;
// how many request to save at once
int max_requests;
// file log
std::string log_file;
std::ofstream file;
// logging to stdout
bool log_stdout;
// how many lines there are in the buffer
int lines;
// is the config file already open
bool log_file_open;
// how many lines can be in the config buffer
// default: 5000
int max_lines;
// whether to save each line (for debug)
bool save_each_line;
void OpenFile();
};

File diff suppressed because it is too large Load Diff

View File

@@ -14,57 +14,417 @@
#include <string>
#include <sstream>
#include <ctime>
#include <cstdio>
#include "item.h"
void ToString(std::string & s, int value);
void ToString(std::string & s, long value);
int ChangeLocalChar(unsigned char c);
/*
conversions between text and numbers
*/
bool CorrectUrlChar(char c);
void CorrectUrlDots(std::string & url);
void CorrectUrlChars(std::string & url);
void CorrectUrlOnlyAllowedChar(std::string & url);
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
void HtmlEscape(std::ostringstream & out, const std::string & in);
void HtmlEscapeFormTxt(std::ostringstream & out, const std::string & in);
std::string HtmlEscape(const std::string & in);
std::string HtmlEscapeFormTxt(const std::string & in);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
const char * DateToStr(int year, int month, int day);
const char * DateToStr(int year, int month, int day, int hour, int min, int sec);
const char * DateToStr(tm * ptm);
const char * DateToStr(time_t t);
// if the buffer is too small it will be terminated at the beginning (empty string)
// and the function returns false
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10)
{
size_t i1, i2;
long rest;
if( buf_len == 0 )
return false;
i1 = i2 = 0;
if( base < 2 ) base = 2;
if( base > 16 ) base = 16;
do
{
rest = value % base;
value = value / base;
buffer[i2++] = (rest < 10) ? char(rest) + '0' : char(rest) - 10 + 'A';
}
while(value != 0 && i2 < buf_len);
if( i2 >= buf_len )
{
buffer[0] = 0; // ops, the buffer was too small
return false;
}
buffer[i2--] = 0;
for( ; i1 < i2 ; ++i1, --i2)
{
CharType temp = buffer[i1];
buffer[i1] = buffer[i2];
buffer[i2] = temp;
}
return true;
}
// if the buffer is too small it will be terminated at the beginning (empty string)
// and the function returns false
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10)
{
if( buf_len == 0 )
return false;
CharType * buf = buffer;
if( value < 0 )
{
buffer[0] = '-';
buf += 1;
buf_len -= 1;
value = -value;
}
bool res = Toa(static_cast<unsigned long>(value), buf, buf_len, base);
if( !res )
buffer[0] = 0;
return res;
}
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10)
{
return Toa(static_cast<unsigned long>(value), buffer, buf_len, base);
}
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10)
{
return Toa(static_cast<long>(value), buffer, buf_len, base);
}
// warning: it uses its own static buffer
// one buffer for both these functions
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
/*
conversions between ascii text and wide characters
(destination is always std::string or std::wstring)
characters are copied as they are without any locales checking
*/
void AssignString(const char * src, size_t len, std::wstring & dst, bool clear = true);
void AssignString(const char * src, std::wstring & dst, bool clear = true);
void AssignString(const std::string & src, std::wstring & dst, bool clear = true);
void AssignString(const wchar_t * src, size_t len, std::string & dst, bool clear = true);
void AssignString(const wchar_t * src, std::string & dst, bool clear = true);
void AssignString(const std::wstring & src, std::string & dst, bool clear = true);
void AssignString(const char * src, size_t len, std::string & dst, bool clear = true);
void AssignString(const char * src, std::string & dst, bool clear = true);
void AssignString(const std::string & src, std::string & dst, bool clear = true);
void AssignString(const wchar_t * src, size_t len, std::wstring & dst, bool clear = true);
void AssignString(const wchar_t * src, std::wstring & dst, bool clear = true);
void AssignString(const std::wstring & src, std::wstring & dst, bool clear = true);
bool CorrectUrlChar(wchar_t c);
void CorrectUrlDots(std::wstring & url);
void CorrectUrlChars(std::wstring & url);
void CorrectUrlOnlyAllowedChar(std::wstring & url);
const wchar_t * DateToStr(int year, int month, int day);
const wchar_t * DateToStr(int year, int month, int day, int hour, int min, int sec);
const wchar_t * DateToStr(const tm * ptm);
const wchar_t * DateToStr(const tm & rtm);
const wchar_t * DateToStr(time_t t);
const wchar_t * DateToStrWithoutHours(const tm * ptm);
const wchar_t * DateToStrWithoutHours(const tm & rtm);
const wchar_t * DateToStrWithoutHours(time_t t);
const char * DateToStrCookie(int year, int month, int day, int hour, int min, int sec);
const char * DateToStrCookie(tm * ptm);
const char * DateToStrCookie(const tm * ptm);
const char * DateToStrCookie(const tm & rtm);
const char * DateToStrCookie(time_t t);
const char * IpToStr(unsigned int ip_);
const wchar_t * IpToStr(unsigned int ip_);
bool IsWhite(wchar_t s);
template<class StringType>
void TrimWhite(StringType & s)
{
typename StringType::size_type i;
if( s.empty() )
return;
// looking for white characters at the end
for(i=s.size()-1 ; i>0 && IsWhite(s[i]) ; --i);
if( i==0 && IsWhite(s[i]) )
{
// the whole string has white characters
s.clear();
return;
}
// deleting white characters at the end
if( i != s.size() - 1 )
s.erase(i+1, StringType::npos);
// looking for white characters at the beginning
for(i=0 ; i<s.size() && IsWhite(s[i]) ; ++i);
// deleting white characters at the beginning
if( i != 0 )
s.erase(0, i);
}
template<class StringType>
void Trim(StringType & s, wchar_t c)
{
typename StringType::size_type i;
if( s.empty() )
return;
// looking for the 'c' characters at the end
for(i=s.size()-1 ; i>0 && s[i]==c ; --i);
if( i==0 && s[i]==c )
{
// the whole string has the 'c' characters
s.clear();
return;
}
// deleting 'c' characters at the end
if( i != s.size() - 1 )
s.erase(i+1, StringType::npos);
// looking for the 'c' characters at the beginning
for(i=0 ; i<s.size() && s[i]==c ; ++i);
// deleting the 'c' characters at the beginning
if( i != 0 )
s.erase(0, i);
}
wchar_t ToSmall(wchar_t c);
void ToSmall(std::wstring & s);
bool IsWhite(int s);
void TrimWhite(std::string & s);
void Trim(std::string & s, char c);
int ToSmall(int c);
void ToSmall(std::string & s);
const char * SkipWhite(const char * s);
const char * ToStr(int value);
const wchar_t * SkipWhite(const wchar_t * s);
bool IsSubString(const char * short_str, const char * long_str);
bool IsSubStringNoCase(const char * short_str, const char * long_str);
bool EqualNoCase(const char * str1, const char * str2);
bool ValidateEmail(const std::string & email);
bool IsFile(const char * file);
bool IsFile(const std::string & file);
bool CreateDir(const char * dir, int priv);
bool CreateDir(const std::string & dir, int priv);
bool CreateDirs(const char * base_dir, const char * dirs, int priv);
bool CreateDirs(const std::string & base_dir, const std::string & dirs, int priv);
template<class StringType1, class StringType2>
bool IsSubString(const StringType1 * short_str, const StringType2 * long_str)
{
while( *short_str && *long_str && wchar_t(*short_str) == wchar_t(*long_str) )
{
++short_str;
++long_str;
}
if( *short_str == 0 )
return true;
return false;
}
template<class StringType1, class StringType2>
bool IsSubString(const StringType1 & short_str, const StringType2 & long_str)
{
return IsSubString(short_str.c_str(), long_str.c_str());
}
template<class StringType1, class StringType2>
bool IsSubStringNoCase(const StringType1 * short_str, const StringType2 * long_str)
{
while( *short_str && *long_str && ToSmall(*short_str) == ToSmall(*long_str) )
{
++short_str;
++long_str;
}
if( *short_str == 0 )
return true;
return false;
}
template<class StringType1, class StringType2>
bool IsSubStringNoCase(const StringType1 & short_str, const StringType2 & long_str)
{
return IsSubStringNoCase(short_str.c_str(), long_str.c_str());
}
template<class StringType1, class StringType2>
bool Equal(const StringType1 * str1, const StringType2 * str2)
{
while( *str1 && *str2 && wchar_t(*str1) == wchar_t(*str2) )
{
++str1;
++str2;
}
if( *str1 == 0 && *str2 == 0 )
return true;
return false;
}
template<class StringType1, class StringType2>
bool Equal(const StringType1 & str1, const StringType2 & str2)
{
return Equal(str1.c_str(), str2.c_str());
}
template<class StringType1, class StringType2>
bool EqualNoCase(const StringType1 * str1, const StringType2 * str2)
{
while( *str1 && *str2 && ToSmall(*str1) == ToSmall(*str2) )
{
++str1;
++str2;
}
if( *str1 == 0 && *str2 == 0 )
return true;
return false;
}
template<class StringType1, class StringType2>
bool EqualNoCase(const StringType1 & str1, const StringType2 & str2)
{
return EqualNoCase(str1.c_str(), str2.c_str());
}
template<class StringType>
void NoLastSlash(StringType & s)
{
if( s.empty() )
return;
size_t i = s.size();
for( ; i>0 && s[i-1]=='/' ; --i);
if( i < s.size() )
s.erase(i);
}
template<class StringType>
void NoFirstHttp(StringType & s)
{
if( s.empty() )
return;
const char http[] = "http://";
const char https[] = "https://";
if( IsSubStringNoCase(http, s.c_str()) )
{
s.erase(0, sizeof(http)/sizeof(char));
}
else
if( IsSubStringNoCase(https, s.c_str()) )
{
s.erase(0, sizeof(https)/sizeof(char));
}
}
bool ValidateEmail(const std::wstring & email);
bool IsFile(const wchar_t * file);
bool IsFile(const std::wstring & file);
bool CreateDir(const wchar_t * dir, int priv);
bool CreateDir(const std::wstring & dir, int priv);
// creating directories (dirs) under base_dir (base_dir must exist)
// if skip_last == true then last part from dir is treated as a file (the last directory is not created)
bool CreateDirs(const wchar_t * base_dir, const wchar_t * dirs, int priv = 0755, bool skip_last = false);
bool CreateDirs(const std::wstring & base_dir, const std::wstring & dirs, int priv = 0755, bool skip_last = false);
bool CopyFile(FILE * in, FILE * out);
bool CopyFile(const wchar_t * src, const wchar_t * dst);
bool CopyFile(const std::wstring & src, const std::wstring & dst);
bool RemoveFile(const wchar_t * file);
bool RemoveFile(const std::wstring & file);
bool RenameFile(const wchar_t * from, const wchar_t * to);
bool RenameFile(const std::wstring & from, const std::wstring & to);
const wchar_t * GetFileExt(const wchar_t * name);
int SelectFileType(const wchar_t * file_name);
int SelectFileType(const std::wstring & file_name);
time_t Time(const tm & par);
time_t Time(const tm * par);
tm Time(time_t par);
void UrlEncode(const std::string & in, std::string & out, bool clear_out = true);
void UrlEncode(const std::wstring & in, std::string & out, bool clear_out = true);
const char * GetFileExt(const char * name);
Item::Auth SelectFileType(const char * file_name);
#endif

View File

@@ -2,117 +2,21 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2009, Tomasz Sowa
* Copyright (c) 2009-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "mount.h"
#include "misc.h"
Mount::Mount()
{
type = cms;
dir_id = -1;
fs = simplefs;
param.resize(par_none);
}
const char * Mount::TypeToStr()
{
static char buffer[30];
switch( type )
{
case cms:
sprintf(buffer, "cms");
break;
case thread:
sprintf(buffer, "thread");
break;
case ticket:
sprintf(buffer, "ticket");
break;
default:
sprintf(buffer, "unknown");
break;
}
return buffer;
}
const char * Mount::FsToStr()
{
static char buffer[30];
switch( fs )
{
case simplefs:
sprintf(buffer, "simplefs");
break;
case hashfs:
sprintf(buffer, "hashfs");
break;
default:
sprintf(buffer, "unknown");
break;
}
return buffer;
}
Mount::ParamCode Mount::ParseParam(const char * param_name)
{
struct ParName
{
ParamCode param_code;
const char * name;
};
static ParName par_name_tab[] = {
{ par_page, "page" },
{ par_thread, "thread" },
{ par_ticket, "ticket" },
{ par_ticket_type, "ticket_type" },
{ par_ticket_type_default, "ticket_type_default" },
{ par_ticket_status, "ticket_status" },
{ par_ticket_status_default, "ticket_status_default" },
{ par_ticket_priority, "ticket_priority" },
{ par_ticket_priority_default, "ticket_priority_default" },
{ par_ticket_category, "ticket_category" },
{ par_ticket_category_default, "ticket_category_default" },
{ par_ticket_expected, "ticket_expected" },
{ par_ticket_expected_default, "ticket_expected_default" },
{ par_createthread_on, "createthread_on" },
{ par_createticket_on, "createticket_on" },
{ par_only_root_remove, "only_root_remove" },
{ par_emacs_on, "emacs_on" },
{ par_mkdir_on, "mkdir_on" },
{ par_app, "app" }
};
size_t i, len = sizeof(par_name_tab) / sizeof(ParName);
for(i=0 ; i<len ; ++i)
{
if( strcmp(par_name_tab[i].name, param_name) == 0 )
return par_name_tab[i].param_code;
}
return par_none;
type = -1;
fs = -1;
}
@@ -126,8 +30,11 @@ size_t i;
}
bool Mount::IsPar(Mount::ParamCode code)
bool Mount::IsPar(int code)
{
if( code < 0 || code >= (int)param.size() )
return false;
if( !param[code].defined )
return false;
@@ -136,9 +43,12 @@ return true;
bool Mount::IsArg(Mount::ParamCode code, const char * arg)
bool Mount::IsArg(int code, const wchar_t * arg)
{
ParamArg::iterator i;
ParamRow::ParamArg::iterator i;
if( code < 0 || code >= (int)param.size() )
return false;
if( !param[code].defined )
return false;
@@ -153,22 +63,25 @@ return false;
}
bool Mount::IsArg(Mount::ParamCode code, const std::string & arg)
bool Mount::IsArg(int code, const std::wstring & arg)
{
return IsArg(code, arg.c_str());
}
bool Mount::IsArg(Mount::ParamCode code, int arg)
bool Mount::IsArg(int code, int arg)
{
ParamArg::iterator i;
ParamRow::ParamArg::iterator i;
if( code < 0 || code >= (int)param.size() )
return false;
if( !param[code].defined )
return false;
for(i=param[code].arg.begin() ; i!=param[code].arg.end() ; ++i)
{
if( atoi(i->c_str()) == arg )
if( Toi(*i) == arg )
return true;
}
@@ -176,3 +89,23 @@ return false;
}
const std::wstring & Mount::Arg(int code, int arg) const
{
if( code < 0 || code >= (int)param.size() )
return empty_str;
if( !param[code].defined )
return empty_str;
if( arg >= (int)param[code].arg.size() )
return empty_str;
return param[code].arg[arg];
}
const std::wstring & Mount::FirstArg(int code) const
{
return Arg(code, 0);
}

View File

@@ -2,7 +2,7 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2009, Tomasz Sowa
* Copyright (c) 2009-2010, Tomasz Sowa
* All rights reserved.
*
*/
@@ -17,58 +17,14 @@
class Mount
{
public:
enum Type
{
cms = 0,
thread,
ticket
};
enum Fs
{
simplefs = 0,
hashfs
};
// the first should be with 0 index
// the last should be 'none'
enum ParamCode
{
par_page = 0,
par_thread,
par_ticket,
par_ticket_type,
par_ticket_type_default,
par_ticket_status,
par_ticket_status_default,
par_ticket_priority,
par_ticket_priority_default,
par_ticket_category,
par_ticket_category_default,
par_ticket_expected,
par_ticket_expected_default,
par_createthread_on,
par_createticket_on,
par_only_root_remove,
par_emacs_on,
par_mkdir_on,
par_app,
par_none
};
typedef std::vector<std::string> ParamArg;
struct ParamRow
{
typedef std::vector<std::wstring> ParamArg;
bool defined;
ParamArg arg;
@@ -77,28 +33,36 @@ public:
};
typedef std::vector<ParamRow> Param;
long dir_id;
int type;
int fs;
Param param;
long dir_id;
Type type;
Fs fs;
Mount();
const char * TypeToStr();
const char * FsToStr();
static ParamCode ParseParam(const char * param);
void ClearParams();
bool IsPar(int code);
bool IsPar(Mount::ParamCode code);
bool IsArg(int code, const wchar_t * arg);
bool IsArg(int code, const std::wstring & arg);
bool IsArg(int code, int arg);
bool IsArg(Mount::ParamCode code, const char * arg);
bool IsArg(Mount::ParamCode code, const std::string & arg);
bool IsArg(Mount::ParamCode code, int arg);
// returning the arg argument if defined (or an empty string)
const std::wstring & Arg(int code, int arg) const;
// returning the first argument (arg=0) if defined (or an empty string)
const std::wstring & FirstArg(int code) const;
private:
// for Arg() methods when the argument is not defined
const std::wstring empty_str;
};

View File

@@ -8,14 +8,47 @@
*/
#include "mountparser.h"
#include "data.h"
#include "log.h"
#include "misc.h"
MountParser::MountParser()
{
dirs = 0;
mount_type_tab = 0;
mount_fs_tab = 0;
mount_par_tab = 0;
}
void MountParser::SetDirs(Dirs * pdirs)
{
dirs = pdirs;
}
void MountParser::SetMountTypeTab(const std::vector<std::wstring> & tab)
{
mount_type_tab = &tab;
}
void MountParser::SetMountFsTab(const std::vector<std::wstring> & tab)
{
mount_fs_tab = &tab;
}
void MountParser::SetMountParTab(const std::vector<std::wstring> & tab)
{
mount_par_tab = &tab;
}
bool MountParser::IsWhite(int c)
{
if( c==' ' || c=='\t' || c==13 )
if( c==' ' || c=='\t' || c==13 || c==160 )
return true;
return false;
@@ -39,7 +72,7 @@ void MountParser::SkipLine()
}
void MountParser::ReadWordQuote(std::string & res)
void MountParser::ReadWordQuote(std::wstring & res)
{
++pinput;
@@ -69,7 +102,7 @@ void MountParser::ReadWordQuote(std::string & res)
// a white character is the separator
void MountParser::ReadWordWhite(std::string & res)
void MountParser::ReadWordWhite(std::wstring & res)
{
while( *pinput && *pinput!=10 && !IsWhite(*pinput) )
{
@@ -80,7 +113,7 @@ void MountParser::ReadWordWhite(std::string & res)
// the comma or the second bracket ')' are the separators
void MountParser::ReadWordComma(std::string & res)
void MountParser::ReadWordComma(std::wstring & res)
{
while( *pinput && *pinput!=10 && *pinput!=',' && *pinput!=')' )
{
@@ -94,7 +127,7 @@ void MountParser::ReadWordComma(std::string & res)
}
void MountParser::ReadWord(std::string & res, bool comma_bracket_separator)
void MountParser::ReadWord(std::wstring & res, bool comma_bracket_separator)
{
res.clear();
SkipWhite();
@@ -117,7 +150,7 @@ void MountParser::ReadWord(std::string & res, bool comma_bracket_separator)
void MountParser::ReadParamArgsLoop(Mount::ParamArg & args)
void MountParser::ReadParamArgsLoop(Mount::ParamRow::ParamArg & args)
{
SkipWhite();
@@ -134,7 +167,7 @@ void MountParser::ReadParamArgsLoop(Mount::ParamArg & args)
}
void MountParser::ReadParamArgs(Mount::ParamArg & args)
void MountParser::ReadParamArgs(Mount::ParamRow::ParamArg & args)
{
SkipWhite();
args.clear();
@@ -159,7 +192,7 @@ void MountParser::ReadParamArgs(Mount::ParamArg & args)
void MountParser::ReadParamName(std::string & res)
void MountParser::ReadParamName(std::wstring & res)
{
SkipWhite();
res.clear();
@@ -172,7 +205,7 @@ void MountParser::ReadParamName(std::string & res)
}
void MountParser::ReadParam(std::string & res, Mount::ParamArg & args)
void MountParser::ReadParam(std::wstring & res, Mount::ParamRow::ParamArg & args)
{
ReadParamName(res);
@@ -188,6 +221,17 @@ void MountParser::ReadParam(std::string & res, Mount::ParamArg & args)
}
int MountParser::FindIndex(const std::vector<std::wstring> * tab, const std::wstring & value)
{
for(size_t i=0 ; i < tab->size() ; ++i)
{
if( (*tab)[i] == value )
return static_cast<int>(i);
}
return -1;
}
void MountParser::ReadMountType()
{
@@ -197,24 +241,14 @@ void MountParser::ReadMountType()
{
// an empty line (some white characters only)
err = WINIX_ERR_EMPTY;
return;
}
else
if( temp == "cms" )
mount.type = FindIndex(mount_type_tab, temp);
if( mount.type != -1 )
{
mount.type = Mount::cms;
log << log3 << "MP: mount type: cms" << logend;
}
else
if( temp == "thread" )
{
mount.type = Mount::thread;
log << log3 << "MP: mount type: thread" << logend;
}
else
if( temp == "ticket" )
{
mount.type = Mount::ticket;
log << log3 << "MP: mount type: ticket" << logend;
log << log3 << "MP: mount type: " << (*mount_type_tab)[mount.type] << logend;
}
else
{
@@ -229,17 +263,17 @@ void MountParser::ReadMountPoint()
{
ReadWord(temp);
pdir = data.dirs.GetDir(temp);
pdir = dirs->GetDir(temp);
if( pdir )
{
mount.dir_id = pdir->id;
log << log3 << "MP: mount point: " << temp << logend;
log << log3 << "MP: mount point (directory): " << temp << logend;
}
else
{
err = WINIX_ERR_NO_MOUNTPOINT;
log << log1 << "MP: there is no such a mount point: " << temp << logend;
log << log1 << "MP: there is no such a mount point (directory): " << temp << logend;
}
}
@@ -248,17 +282,11 @@ void MountParser::ReadMountPoint()
void MountParser::ReadFs()
{
ReadWord(temp);
mount.fs = FindIndex(mount_fs_tab, temp);
if( temp == "simplefs" )
if( mount.fs != -1 )
{
mount.fs = Mount::simplefs;
log << log1 << "MP: file system: simplefs" << logend;
}
else
if( temp == "hashfs" )
{
mount.fs = Mount::hashfs;
log << log1 << "MP: file system: hashfs" << logend;
log << log2 << "MP: file system: " << (*mount_fs_tab)[mount.fs] << logend;
}
else
{
@@ -294,12 +322,12 @@ void MountParser::ReadMountParams()
for( ReadParam(temp, param_args) ; !temp.empty() ; ReadParam(temp, param_args) )
{
Mount::ParamCode p = Mount::ParseParam(temp.c_str());
int code = FindIndex(mount_par_tab, temp);
if( p != Mount::par_none )
if( code != -1 )
{
mount.param[p].defined = true;
mount.param[p].arg = param_args;
mount.param[code].defined = true;
mount.param[code].arg = param_args;
LogMountParams();
}
else
@@ -345,15 +373,30 @@ void MountParser::ReadRow(std::map<long, Mount> & output)
Error MountParser::Parse(const std::string & input, std::map<long, Mount> & output)
Error MountParser::Parse(const std::wstring & input, std::map<long, Mount> & output)
{
if( !dirs || !mount_type_tab || !mount_fs_tab || !mount_par_tab )
{
log << log1 << "pdir: " << pdir << logend;
log << log1 << "type: " << mount_type_tab << logend;
log << log1 << "fs: " << mount_fs_tab << logend;
log << log1 << "par: " << mount_par_tab << logend;
log << log1 << "MP: input tables not set" << logend;
return WINIX_NOTHING_TO_DO; // !! may a better code?
}
pinput = input.c_str();
err = WINIX_ERR_OK;
mount.param.resize(mount_par_tab->size());
mount.ClearParams();
output.clear();
while( *pinput && err == WINIX_ERR_OK )
ReadRow(output);
return err;
}

View File

@@ -19,6 +19,7 @@
#include "mount.h"
#include "item.h"
#include "error.h"
#include "dirs.h"
@@ -26,22 +27,33 @@ class MountParser
{
public:
Error Parse(const std::string & input, std::map<long, Mount> & output);
MountParser();
Error Parse(const std::wstring & input, std::map<long, Mount> & output);
void SetDirs(Dirs * pdirs);
void SetMountTypeTab(const std::vector<std::wstring> & tab);
void SetMountFsTab(const std::vector<std::wstring> & tab);
void SetMountParTab(const std::vector<std::wstring> & tab);
private:
Dirs * dirs;
const std::vector<std::wstring> * mount_type_tab;
const std::vector<std::wstring> * mount_fs_tab;
const std::vector<std::wstring> * mount_par_tab;
bool IsWhite(int c);
void SkipWhite();
void SkipLine();
void ReadWordQuote(std::string & res);
void ReadWordWhite(std::string & res);
void ReadWordComma(std::string & res);
void ReadWord(std::string & res, bool comma_bracket_separator = false);
void ReadParamArgsLoop(Mount::ParamArg & args);
void ReadParamArgs(Mount::ParamArg & args);
void ReadParamName(std::string & res);
void ReadParam(std::string & res, Mount::ParamArg & args);
void ReadWordQuote(std::wstring & res);
void ReadWordWhite(std::wstring & res);
void ReadWordComma(std::wstring & res);
void ReadWord(std::wstring & res, bool comma_bracket_separator = false);
void ReadParamArgsLoop(Mount::ParamRow::ParamArg & args);
void ReadParamArgs(Mount::ParamRow::ParamArg & args);
void ReadParamName(std::wstring & res);
void ReadParam(std::wstring & res, Mount::ParamRow::ParamArg & args);
int FindIndex(const std::vector<std::wstring> * tab, const std::wstring & value);
void ReadMountType();
void ReadMountPoint();
void ReadFs();
@@ -49,10 +61,10 @@ private:
void ReadMountParams();
void ReadRow(std::map<long, Mount> & output);
const char * pinput;
std::string temp;
std::string temp_arg;
Mount::ParamArg param_args;
const wchar_t * pinput;
std::wstring temp;
std::wstring temp_arg;
Mount::ParamRow::ParamArg param_args;
Mount mount;

View File

@@ -2,17 +2,17 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2009, Tomasz Sowa
* Copyright (c) 2009-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "mounts.h"
#include "data.h"
#include "request.h"
#include "log.h"
#include "mountparser.h"
#include "db.h"
#include "db/db.h"
#include "plugin.h"
@@ -22,12 +22,153 @@ Mounts::Mounts()
}
void Mounts::CreateMountType()
{
mount_type_cms = AddMountType(L"cms");
mount_type_thread = AddMountType(L"thread");
}
void Mounts::CreateMountFs()
{
mount_fs_simplefs = AddMountFs(L"simplefs");
mount_fs_hashfs = AddMountFs(L"hashfs");
}
void Mounts::CreateMountPar()
{
mount_par_page = AddMountPar(L"page");
mount_par_thread = AddMountPar(L"thread");
mount_par_createthread_on = AddMountPar(L"createthread_on");
mount_par_only_root_remove = AddMountPar(L"only_root_remove");
mount_par_emacs_on = AddMountPar(L"emacs_on");
mount_par_mkdir_on = AddMountPar(L"mkdir_on");
mount_par_app = AddMountPar(L"app");
mount_par_html_template = AddMountPar(L"html_template");
}
void Mounts::CreateMounts()
{
CreateMountType();
CreateMountFs();
CreateMountPar();
plugin.Call(WINIX_ADD_MOUNTS);
}
void Mounts::SetDirs(Dirs * pdirs)
{
dirs = pdirs;
}
void Mounts::SetDb(Db * pdb)
{
db = pdb;
}
void Mounts::SetRequest(Request * prequest)
{
request = prequest;
}
int Mounts::AddMountType(const wchar_t * type)
{
mount_type_tab.push_back(type);
return static_cast<int>(mount_type_tab.size()) - 1;
}
int Mounts::AddMountType(const std::wstring & type)
{
return AddMountType(type.c_str());
}
int Mounts::AddMountFs(const wchar_t * fs)
{
mount_fs_tab.push_back(fs);
return static_cast<int>(mount_fs_tab.size()) - 1;
}
const std::wstring & Mounts::GetMountType(int id)
{
if( id < 0 || id >= (int)mount_type_tab.size() )
return empty_str;
return mount_type_tab[id];
}
int Mounts::FindMountType(const std::wstring & type)
{
for(size_t i=0 ; i<mount_type_tab.size() ; ++i)
if( mount_type_tab[i] == type )
return (int)i;
return -1;
}
int Mounts::AddMountFs(const std::wstring & fs)
{
return AddMountFs(fs.c_str());
}
const std::wstring & Mounts::GetMountFs(int id)
{
if( id < 0 || id >= (int)mount_fs_tab.size() )
return empty_str;
return mount_fs_tab[id];
}
int Mounts::AddMountPar(const wchar_t * par)
{
mount_par_tab.push_back(par);
return static_cast<int>(mount_par_tab.size()) - 1;
}
int Mounts::AddMountPar(const std::wstring & par)
{
return AddMountPar(par.c_str());
}
const std::wstring & Mounts::GetMountPar(int id)
{
if( id < 0 || id >= (int)mount_par_tab.size() )
return empty_str;
return mount_par_tab[id];
}
// reading from 'mounts'
Error Mounts::ReadMounts(const std::string & mounts)
Error Mounts::ReadMounts(const std::wstring & mounts)
{
MountParser mp;
Error err = mp.Parse(mounts, mount_tab);
mount_parser.SetDirs(dirs);
mount_parser.SetMountTypeTab(mount_type_tab);
mount_parser.SetMountFsTab(mount_fs_tab);
mount_parser.SetMountParTab(mount_par_tab);
Error err = mount_parser.Parse(mounts, mount_tab);
if( err != WINIX_ERR_OK )
{
@@ -36,6 +177,7 @@ Error Mounts::ReadMounts(const std::string & mounts)
}
CalcCurMount();
plugin.Call(WINIX_FSTAB_CHANGED);
return err;
}
@@ -45,9 +187,9 @@ return err;
// reading from /etc/fstab
Error Mounts::ReadMounts()
{
static std::string file = "fstab";
static std::wstring file = L"fstab";
Item * etc = data.dirs.GetEtcDir();
Item * etc = dirs->GetEtcDir();
if( !etc )
{
@@ -56,7 +198,7 @@ Error Mounts::ReadMounts()
}
Item fstab;
Error err = db.GetItem(etc->id, file, fstab);
Error err = db->GetItem(etc->id, file, fstab);
if( err == WINIX_ERR_NO_ITEM )
{
@@ -77,10 +219,10 @@ Error Mounts::ReadMounts()
void Mounts::MountCmsForRoot()
{
Mount mount;
mount.type = Mount::cms;
mount.fs = Mount::simplefs;
mount.type = MountTypeCms();
mount.fs = MountFsSimplefs();
Item * proot = data.dirs.GetRootDir();
Item * proot = dirs->GetRootDir();
if( proot )
mount.dir_id = proot->id;
@@ -90,6 +232,9 @@ void Mounts::MountCmsForRoot()
log << log1 << "M: there is no a root dir" << logend;
}
mount.param.resize(mount_par_tab.size());
mount.ClearParams();
std::pair<MountTab::iterator, bool> res = mount_tab.insert( std::make_pair(mount.dir_id, mount) );
pmount = &(res.first->second);
}
@@ -101,20 +246,20 @@ void Mounts::CalcCurMount()
{
std::vector<Item*>::reverse_iterator i;
// when the program starts (when the dir_table is empty()
// when the program starts (when the dir_tab is empty()
// we don't want to call MountCmsForRoot()
if( request.dir_table.empty() )
if( request->dir_tab.empty() )
return;
for(i = request.dir_table.rbegin() ; i!=request.dir_table.rend() ; ++i)
for(i = request->dir_tab.rbegin() ; i!=request->dir_tab.rend() ; ++i)
{
std::map<long, Mount>::iterator m = mount_tab.find( (*i)->id );
if( m != mount_tab.end() )
{
pmount = &(m->second);
log << log2 << "M: current mount point is: " << pmount->TypeToStr()
<< ", fs: " << pmount->FsToStr() << logend;
log << log2 << "M: current mount point is: " << GetMountType(pmount->type)
<< ", fs: " << GetMountFs(pmount->fs) << logend;
return;
}
}
@@ -122,8 +267,8 @@ std::vector<Item*>::reverse_iterator i;
// if nothing was found
// we assume that 'cms' mount point is used
MountCmsForRoot();
log << log2 << "M: current mount point is: " << pmount->TypeToStr() << " (default)"
<< ", fs: " << pmount->FsToStr() << logend;
log << log2 << "M: current mount point is: " << GetMountType(pmount->type) << " (default)"
<< ", fs: " << GetMountFs(pmount->fs) << logend;
}
@@ -133,7 +278,7 @@ Mount * Mounts::CalcMount(long dir_id)
{
while( true )
{
Item * pdir = data.dirs.GetDir(dir_id);
Item * pdir = dirs->GetDir(dir_id);
if( !pdir )
return 0;
@@ -146,3 +291,11 @@ Mount * Mounts::CalcMount(long dir_id)
dir_id = pdir->parent_id;
}
}
const Mounts::MountTab * Mounts::GetMountTab()
{
return &mount_tab;
}

View File

@@ -2,7 +2,7 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2009, Tomasz Sowa
* Copyright (c) 2009-2010, Tomasz Sowa
* All rights reserved.
*
*/
@@ -14,16 +14,76 @@
#include <map>
#include <string>
#include <vector>
#include "mount.h"
#include "error.h"
#include "dirs.h"
#include "db/db.h"
#include "request.h"
#include "mountparser.h"
class Mounts
{
public:
/*
mount point's types
*/
int AddMountType(const wchar_t * type);
int AddMountType(const std::wstring & type);
const std::wstring & GetMountType(int id);
// id of a specific mount type (the id is always valid)
int MountTypeCms() { return mount_type_cms; }
int MountTypeThread() { return mount_type_thread; }
// return -1 if there is no such a mount type
// or index otherwhise
int FindMountType(const std::wstring & type);
/*
file systems
*/
int AddMountFs(const wchar_t * fs);
int AddMountFs(const std::wstring & fs);
const std::wstring & GetMountFs(int id);
// id of a specific file system (the id is always valid)
int MountFsSimplefs() { return mount_fs_simplefs; }
int MountFsHashfs() { return mount_fs_hashfs; }
/*
mount point's parameters
*/
int AddMountPar(const wchar_t * par);
int AddMountPar(const std::wstring & par);
const std::wstring & GetMountPar(int id);
int MountParPage() { return mount_par_page; }
int MountParThread() { return mount_par_thread; }
int MountParCreatethreadOn() { return mount_par_createthread_on; }
int MountParOnlyRootRemove() { return mount_par_only_root_remove; }
int MountParEmacsOn() { return mount_par_emacs_on; }
int MountParMkdirOn() { return mount_par_mkdir_on; }
int MountParApp() { return mount_par_app; }
int MountParHtmlTemplate() { return mount_par_html_template; }
void SetDirs(Dirs * pdirs);
void SetDb(Db * pdb);
void SetRequest(Request * prequest);
// dir_id, mount_point
typedef std::map<long, Mount> MountTab;
Mounts();
Error ReadMounts(const std::string & mounts);
void CreateMounts();
Error ReadMounts(const std::wstring & mounts);
Error ReadMounts();
void CalcCurMount();
@@ -33,12 +93,52 @@ public:
// will not be null after calling CalcCurMount() or ReadMounts([...])
Mount * pmount;
const MountTab * GetMountTab();
private:
// dir_id, mount_point
typedef std::map<long, Mount> MountTab;
Db * db;
Dirs * dirs;
Request * request;
const std::wstring empty_str;
MountParser mount_parser;
// cms
// thread
std::vector<std::wstring> mount_type_tab;
int mount_type_cms;
int mount_type_thread;
// simplefs
// hashfs
std::vector<std::wstring> mount_fs_tab;
int mount_fs_simplefs;
int mount_fs_hashfs;
// page
// thread
std::vector<std::wstring> mount_par_tab;
int mount_par_page;
int mount_par_thread;
int mount_par_createthread_on;
int mount_par_only_root_remove;
int mount_par_emacs_on;
int mount_par_mkdir_on;
int mount_par_app;
int mount_par_html_template;
MountTab mount_tab;
void CreateMountType();
void CreateMountFs();
void CreateMountPar();
void MountCmsForRoot();
};

View File

@@ -1,265 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, 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 the second thread
the thread can reference to 'this' by using 'obj' pointer
*/
void * Notify::ThreadRoutine(void * arg)
{
obj = (Notify*)arg;
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->Lock(); // templates can be reloaded from the first thread
obj->templates_notify.Generate(n.lang);
obj->Unlock();
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;
nlog << logsave;
}
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()
{
}
void Notify::ReadTemplates()
{
// we are in the first thread here
// the second thread can use our templates and we must Lock()
// (the second thread is using Lock() too)
Lock();
templates_notify.Read();
Unlock();
}
bool Notify::Init()
{
templates_notify.CreateFunctions();
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.pmount->type;
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.pmount->type == Mount::thread )
{
if( (i->thread_notify & notify_code) != 0 )
sending = true;
}
else
if( data.mounts.pmount->type == Mount::cms )
{
if( (i->cms_notify & notify_code) != 0 )
sending = true;
}
if( sending )
{
n.email = i->email;
n.lang = Locale::StrToLang(data.locale_str);// !! bedzie osobno dla kazdego uzytkownika
if( n.lang == Locale::lang_unknown )
n.lang = Locale::lang_en;
notify_pool.insert(notify_pool.end(), n);
}
}
}
catch(...)
{
Unlock();
throw;
}
Unlock();
}

View File

@@ -1,77 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslunotify
#define headerfilecmslunotify
#include <list>
#include <string>
#include <cstdio>
#include "../templatesnotify/templatesnotify.h"
#define WINIX_NOTIFY_ITEM_ADD 1
#define WINIX_NOTIFY_ITEM_EDIT 2
#define WINIX_NOTIFY_ITEM_DELETE 4
#define WINIX_NOTIFY_DIR_ADD 8
class Notify
{
public:
Notify();
~Notify();
void ReadTemplates();
bool Init();
/*
this method addes 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;
TemplatesNotify templates_notify;
};
extern Notify notify;
#endif

View File

@@ -8,8 +8,10 @@
*/
#include <dlfcn.h>
#include <string.h>
#include "plugin.h"
#include "pluginmsg.h"
#include "misc.h"
@@ -21,7 +23,7 @@ size_t i;
slots.clear();
for(i=0 ; i<plugins.size() ; ++i)
dlclose(plugins[i]);
dlclose(plugins[i].handle);
plugins.clear();
}
@@ -30,6 +32,16 @@ size_t i;
Plugin::Plugin()
{
current_plugin = -1;
request = 0;
db = 0;
config = 0;
request = 0;
system = 0;
functions = 0;
templates = 0;
synchro = 0;
session_manager = 0;
}
@@ -39,12 +51,92 @@ Plugin::~Plugin()
}
void Plugin::LoadPlugins(const std::vector<std::string> & plugins)
void Plugin::SetDb(Db * pdb)
{
size_t i;
db = pdb;
}
for(i=0 ; i<plugins.size() ; ++i)
LoadPlugin(plugins[i]);
void Plugin::SetConfig(Config * pconfig)
{
config = pconfig;
}
void Plugin::SetRequest(Request * prequest)
{
request = prequest;
}
void Plugin::SetSystem(System * psystem)
{
system = psystem;
}
void Plugin::SetFunctions(Functions * pfunctions)
{
functions = pfunctions;
}
void Plugin::SetTemplates(Templates * ptemplates)
{
templates = ptemplates;
}
void Plugin::SetSynchro(Synchro * psynchro)
{
synchro = psynchro;
}
void Plugin::SetSessionManager(SessionManager * psession_manager)
{
session_manager = psession_manager;
}
bool Plugin::SetPointers(PluginInfo & info)
{
// for safety we call a plugin function only when all our pointers are not null
bool res = (db && config && request && system && functions && templates && synchro && session_manager);
if( !res )
log << log1 << "Plugin: cannot call a function - some of the winix pointers are null" << logend;
info.db = db;
info.config = config;
info.request = request;
info.system = system;
info.functions = functions;
info.templates = templates;
info.synchro = synchro;
info.session_manager = session_manager;
return res;
}
void Plugin::LoadPlugins(const std::wstring & plugins_dir, const std::vector<std::wstring> & plugins)
{
for(size_t i=0 ; i<plugins.size() ; ++i)
{
if( !plugins[i].empty() && plugins[i][0] == '/' )
{
LoadPlugin(plugins[i]);
}
else
{
temp_path = plugins_dir;
temp_path += '/';
temp_path += plugins[i];
LoadPlugin(temp_path);
}
}
}
@@ -54,88 +146,214 @@ void Plugin::LoadPlugin(const std::string & filename)
}
void Plugin::LoadPlugin(const char * filename)
void * Plugin::LoadInitFun(const char * filename, Fun1 & fun_init)
{
void * p = dlopen(filename, RTLD_NOW | RTLD_LOCAL);
if( !p )
{
log << log1 << "Pl: cannot load a plugin: " << filename << logend;
/*
const char * t = dlerror();
if( t )
log << log1 << t << logend;
*/
return;
log << log1 << "Plugin: cannot load a plugin: \"" << filename << "\"" << logend;
log << log1 << "Plugin: dlerror: " << dlerror() << logend;
return 0;
}
Fun fun = (Fun)dlfunc(p, "Init");
fun_init = (Fun1)dlfunc(p, "Init");
if( !fun )
if( !fun_init )
{
log << log1 << "Pl: cannot load a plugin: " << filename << " (there is no Init() function)" << logend;
log << log1 << "Plugin: cannot load a plugin: " << filename
<< " (there is no Init() function)" << logend;
dlclose(p);
return 0;
}
log << log2 << "Plugin: plugin loaded"
<< ", file: " << filename
<< ", index: " << plugins.size() << logend;
return p;
}
void Plugin::LoadPlugin(const char * filename)
{
Fun1 fun_init;
void * plugin_handle;
int old_current_plugin;
if( !SetPointers(info) )
return;
}
arg.Clear();
int old_current_plugin = current_plugin;
if( !(plugin_handle = LoadInitFun(filename, fun_init)) )
return;
current_plugin = (int)plugins.size();
arg.plugin_id = current_plugin;
info.Clear();
old_current_plugin = current_plugin;
current_plugin = (int)plugins.size();
info.plugin_id = current_plugin;
if( fun(&arg) )
{
log << log1 << "Pl: plugin loaded: " << filename << ", index: " << plugins.size() << logend;
plugins.push_back(p);
}
else
{
log << log1 << "Pl: plugin Init() returned false (" << filename << ") " << logend;
dlclose(p);
}
fun_init(info);
PluginsItem item;
item.handle = plugin_handle;
item.plugin_name = reinterpret_cast<const wchar_t *>(info.p1);
plugins.push_back(item);
current_plugin = old_current_plugin;
}
void Plugin::LoadPlugin(const wchar_t * filename)
{
AssignString(filename, afilename);
LoadPlugin(afilename.c_str());
}
Arg * Plugin::Call(int message, void * a, void * a2, void * a3)
void Plugin::LoadPlugin(const std::wstring & filename)
{
LoadPlugin(filename.c_str());
}
bool Plugin::HasPlugin(const wchar_t * name)
{
if( *name == 0 )
return false;
for(size_t i=0 ; i<plugins.size() ; ++i)
{
if( plugins[i].plugin_name && Equal(plugins[i].plugin_name, name) )
return true;
}
return false;
}
bool Plugin::HasPlugin(const std::wstring & name)
{
return HasPlugin(name.c_str());
}
void Plugin::Call(int message, Slots::iterator & slot)
{
if( !SetPointers(info) )
return;
current_plugin = slot->second.index;
info.plugin_id = current_plugin;
if( request && request->session && current_plugin != -1 )
info.plugin_data_base = request->session->plugin_data.Get(current_plugin);
else
info.plugin_data_base = 0;
if( !slot->second.is_running )
{
if( config->log_plugin_call )
log << log1 << "Plugin: calling plugin id: " << slot->second.index << ", message: " << message << logend;
slot->second.is_running = true;
if( slot->second.fun1 )
slot->second.fun1(info);
if( slot->second.fun2 )
slot->second.fun2();
slot->second.is_running = false;
if( config->log_plugin_call )
log << log1 << "Plugin: returning from plugin id: " << slot->second.index << ", message: " << message << logend;
}
else
{
log << log1 << "Plugin: id: " << slot->second.index
<< ", message: " << message
<< ", recurrences are not allowed" << logend;
}
}
void Plugin::Call(int message, void * p1_, void * p2_, long l1_, long l2_)
{
Slots::iterator i = slots.lower_bound(message);
arg.Clear();
int old_current_plugin = current_plugin;
for( ; i!=slots.end() && i->first==message ; ++i )
{
arg.app = a;
arg.app2 = a2;
arg.app3 = a3;
current_plugin = i->second.index;
arg.plugin_id = current_plugin;
info.Clear();
info.p1 = p1_;
info.p2 = p2_;
info.l1 = l1_;
info.l2 = l2_;
if( request.session && current_plugin != -1 )
arg.plugin_data_base = request.session->plugin_data.Get(current_plugin);
else
arg.plugin_data_base = 0;
if( i->second.fun(&arg) )
arg.ret_true++;
else
arg.ret_false++;
Call(message, i);
}
current_plugin = old_current_plugin;
return &arg;
}
void Plugin::Call(int message)
{
Call(message, 0, 0, 0, 0);
}
void Plugin::Call(int message, void * p1_)
{
Call(message, p1_, 0, 0, 0);
}
void Plugin::Call(int message, void * p1_, void * p2_)
{
Call(message, p1_, p2_, 0, 0);
}
void Plugin::Call(int message, long l1_)
{
Call(message, 0, 0, l1_, 0);
}
void Plugin::Call(int message, long l1_, long l2_)
{
Call(message, 0, 0, l1_, l2_);
}
void Plugin::Call(int message, void * p1_, long l1_)
{
Call(message, p1_, 0, l1_, 0);
}
void Plugin::Call(int message, void * p1_, long l1_, long l2_)
{
Call(message, p1_, 0, l1_, l2_);
}
void Plugin::Call(int message, void * p1_, void * p2_, long l1_)
{
Call(message, p1_, p2_, l1_, 0);
}
size_t Plugin::Size()
{
return plugins.size();
@@ -143,14 +361,32 @@ size_t Plugin::Size()
void Plugin::Assign(int message, Fun fun)
void Plugin::Assign(int message, Fun1 fun1)
{
Slot s;
Slot s;
s.fun = fun;
if( current_plugin == -1 )
return;
s.fun1 = fun1;
s.index = current_plugin;
slots.insert( std::make_pair(message, s) );
log << log3 << "Plugin: added function for message: " << message << ", plugin index: " << s.index << logend;
}
void Plugin::Assign(int message, Fun2 fun2)
{
Slot s;
if( current_plugin == -1 )
return;
s.fun2 = fun2;
s.index = current_plugin;
slots.insert( std::make_pair(message, s) );
log << log3 << "Plugin: added function for message: " << message << ", plugin index: " << s.index << logend;
}

View File

@@ -14,37 +14,82 @@
#include <vector>
#include <string>
#include <map>
#include "request.h"
#include "data.h"
#include "pluginmsg.h"
#include "log.h"
#include "plugindata.h"
#include "config.h"
#include "request.h"
#include "system.h"
#include "sessionmanager.h"
#include "synchro.h"
#include "functions/functions.h"
#include "templates/templates.h"
// plugin arguments
struct Arg
/*
all your plugin functions can have signature either:
void my_function(PluginInfo & info); or
void my_function();
only the main Init should have:
extern "C" void Init(PluginFunction & info);
in the Init you can add your own functions by using plugin.Assign() method
and you can set the name of the plugin by setting info.p1 pointer
to a string buffer (const char *)
(this buffer will not be copied so it should not be destroyed after Init finishes)
also in Init you can only use logger (log) info.config and info.db objects
(the rest winix objects are not initialized yet)
*/
struct PluginInfo
{
void * app; // used for some purposes
void * app2; // used for some purposes
void * app3; // used for some purposes
// these variables are used for some purposes
// depending on a hook in which they are used
void * p1;
void * p2;
long l1;
long l2;
// unique plugin identifier
int plugin_id;
int plugin_id; // unique plugin identifier
// objects from winix which are accessible from a plugin
Db * db;
Config * config;
Request * request;
System * system;
Functions * functions;
Templates * templates;
Synchro * synchro;
SessionManager * session_manager;
// pointer to the plugin session (can be null if not set by the plugin)
// you should use WINIX_SESSION_CREATED and WINIX_SESSION_REMOVE
// to create your plugin's session data
PluginDataBase * plugin_data_base; // !! zmienic nazwe na plugin_session_base ? a moze session_base; a moze plugin_session?
PluginDataBase * plugin_data_base; // pointer to the plugin session
int ret_true; // how many plugins returned true
int ret_false; // how many plugins returned false
// function return status
// default: false (if not set by the plugin)
bool ret;
void Clear()
{
app = 0;
app2 = 0;
app3 = 0;
ret_true = 0;
ret_false = 0;
// pointers to winix objects are not cleared here
p1 = 0;
p2 = 0;
l1 = 0;
l2 = 0;
plugin_id = -1;
plugin_data_base = 0;
ret = false;
}
};
@@ -58,46 +103,102 @@ public:
// normally: -1
int current_plugin;
// Fun is a type of a function you should provide in your plugin
typedef void (*Fun1)(PluginInfo &);
typedef void (*Fun2)(void);
// !! zmienic sygnature funkcji (niech nie zwraca zadnej wartosci, bo to tylko wkurwia)
// albo dodac jeszcze inna sygnature (niech nie pobiera zadnego argumentu)
typedef bool (*Fun)(Arg *);
//typedef void (*Fun2)();
struct Slot
{
Fun fun;
// Fun2 fun2; // dla drugiej sygnatury
int index; // plugin index
Fun1 fun1;
Fun2 fun2;
int index; // plugin index (which plugin has inserted the slot)
bool is_running;
Slot()
{
fun1 = 0;
fun2 = 0;
index = -1;
is_running = false;
}
};
Plugin();
~Plugin();
void SetDb(Db * pdb);
void SetConfig(Config * pconfig);
void SetRequest(Request * prequest);
void SetSystem(System * psystem);
void SetFunctions(Functions * pfunctions);
void SetTemplates(Templates * ptemplates);
void SetSynchro(Synchro * psynchro);
void SetSessionManager(SessionManager * psession_manager);
void LoadPlugin(const char * filename);
void LoadPlugin(const std::string & filename);
void LoadPlugins(const std::vector<std::string> & plugins);
void LoadPlugin(const wchar_t * filename);
void LoadPlugin(const std::wstring & filename);
void LoadPlugins(const std::wstring & plugins_dir, const std::vector<std::wstring> & plugins);
void UnloadPlugins();
Arg * Call(int message, void * a=0, void * a2=0, void * a3=0);
bool HasPlugin(const wchar_t * name);
bool HasPlugin(const std::wstring & name);
void Call(int message);
void Call(int message, void * p1_);
void Call(int message, void * p1_, void * p2_);
void Call(int message, long l1_);
void Call(int message, long l1_, long l2_);
void Call(int message, void * p1_, long l1_);
void Call(int message, void * p1_, long l1_, long l2_);
void Call(int message, void * p1_, void * p2_, long l1_);
void Call(int message, void * p1_, void * p2_, long l1_, long l2_);
// how many plugins there are
size_t Size();
void Assign(int message, Fun);
// assign a function to a message
// you can assign more than one function to a specific message
void Assign(int message, Fun1);
void Assign(int message, Fun2);
private:
Db * db;
Config * config;
Request * request;
System * system;
Functions * functions;
Templates * templates;
Synchro * synchro;
SessionManager * session_manager;
typedef std::vector<void*> Plugins;
std::wstring temp_path;
struct PluginsItem
{
void * handle;
const wchar_t * plugin_name; // plugin name (can be null if was not set by the plugin)
};
typedef std::vector<PluginsItem> Plugins;
Plugins plugins;
typedef std::multimap<int, Slot> Slots;
Slots slots;
Arg arg;
PluginInfo info;
std::string afilename;
void * LoadInitFun(const char * filename, Fun1 & fun_init);
void Call(int message, Slots::iterator & slot);
bool SetPointers(PluginInfo & info);
};

View File

@@ -11,12 +11,36 @@
#ifndef headerfilecmslupluginmsg
#define headerfilecmslupluginmsg
// here you can add your own EZC functions ([function])
// PluginInfo.p1 is a pointer to Ezc::Functions object
#define WINIX_TEMPLATES_CREATEFUNCTIONS 999
#define WINIX_REQUEST_CLEAR 1000
#define WINIX_CONTENT_MAKE 2000
// here you can add your own EZC functions to notify system
// warning: this functions will be called from an other thread
// so you should use synchro->Lock() and synchro->Unlock()
// when attempting to winix objects
// PluginInfo.p1 is a pointer to Ezc::Functions object
// which is defined as:
// Ezc::Functions<NotifyStream> ezc_functions;
// and Notify Stream is:
// typedef TextStream<std::wstring> NotifyStream;
#define WINIX_NOTIFY_TEMPLATES_CREATEFUNCTIONS 998
// winix function and parameters have been parsed
// the request.status is OK
// (the winix function was not called yet)
#define WINIX_PREPARE_REQUEST 2000
// post and get functions have done their jobs
// now you can act
// this is called only if the request.status is OK
#define WINIX_PROCESS_REQUEST 2001
// prepere your content for displaying
// this is called after WINIX_PROCESS_REQUEST
// and when there is not a redirect
// request.status is not checked here
#define WINIX_CONTENT_MAKE 2002
// here you can attach your own session data (based on PluginDataBase class)
// call request.session->plugin_data.Assign(pointer)
@@ -28,12 +52,45 @@
// when a session is changed (you can save a pointer to your data here)
#define WINIX_SESSION_CHANGED 3002
// the winix is closing
// the is not any session available (request->session is null)
#define WINIX_CLOSE 3004
// item was removed (rm function)
// PluginInfo::l1 is the file (item) id
#define WINIX_FILE_REMOVED 3005
// directory was removed (rm function)
// PluginInfo::l1 is the dir id
#define WINIX_DIR_REMOVED 3006
// preparing to remove a directory (rm function)
// PluginInfo::l1 is the dir id
#define WINIX_DIR_PREPARE_TO_REMOVE 3007
// winix is initialized,
// now you can initialize your plugin
#define WINIX_PLUGIN_INIT 3008
// here you can add your own mount point, file systems, mount parameters
// for adding a new mount type call: system->mounts.AddMountType("new_mount_name")
#define WINIX_ADD_MOUNTS 3009
// add plugin functions here
#define WINIX_CREATE_FUNCTIONS 3010
// choose a default function
// if you do not select it then it will be choosen by winix
#define WINIX_SELECT_DEFAULT_FUNCTION 3011
// /etc/fstab has been changed
// now we have new mount points
#define WINIX_FSTAB_CHANGED 3012
// here you add your own template to notification system
// call system->notify.AddTemplate() method
// with a template file name
#define WINIX_NOTIFY_ADD_TEMPLATE 3013
#endif

View File

@@ -9,7 +9,8 @@
#include "postmultiparser.h"
#include "log.h"
#include "data.h"
#include "utf8.h"
#include "misc.h"
PostMultiParser::PostMultiParser()
@@ -18,16 +19,17 @@ PostMultiParser::PostMultiParser()
}
PostMultiParser::PostMultiParser(const PostMultiParser &)
PostMultiParser::PostMultiParser(const PostMultiParser & p)
{
in_buffer = new unsigned char[WINIX_POSTMULTI_INPUT_BUFFER];
config = p.config;
}
PostMultiParser & PostMultiParser::operator=(const PostMultiParser &)
PostMultiParser & PostMultiParser::operator=(const PostMultiParser & p)
{
in_buffer = new unsigned char[WINIX_POSTMULTI_INPUT_BUFFER];
config = p.config;
return *this;
}
@@ -39,6 +41,11 @@ PostMultiParser::~PostMultiParser()
}
void PostMultiParser::SetConfig(Config * pconfig)
{
config = pconfig;
}
void PostMultiParser::ReadBoundary()
{
@@ -232,16 +239,24 @@ size_t i;
void PostMultiParser::ReadContentSkipBoundary(bool has_boundary)
{
if( has_boundary )
if( has_boundary && content.size() >= boundary.size() )
{
content.erase(content.size()-boundary.size());
content_len -= boundary.size();
}
// the last new line character doesn't belong to the content
// this is a new line character before the boundary
if( !content.empty() && content[content.size()-1] == 10 )
{
content.erase(content.size()-1);
content_len -= 1;
if( line_end_dos && !content.empty() && content[content.size()-1] == 13 )
{
content.erase(content.size()-1);
content_len -= 1;
}
}
}
@@ -251,22 +266,28 @@ void PostMultiParser::ReadContentToFileLoop()
bool has_boundary = false;
while( last!=-1 && !(has_boundary=HasBoundary()) )
while( last!=-1 )
{
content += last;
content_len += 1;
ReadChar();
if( content.size() > WINIX_POSTMULTI_OUTPUT_BUFFER + boundary.size() + 2 ) // +2 for the new line character
if( HasBoundary() )
{
tmp_file.write(content.c_str(), WINIX_POSTMULTI_OUTPUT_BUFFER);
content_len += WINIX_POSTMULTI_OUTPUT_BUFFER;
content.erase(0, WINIX_POSTMULTI_OUTPUT_BUFFER);
has_boundary = true;
break;
}
if( data.post_file_max != 0 && content_len > (size_t)data.post_file_max )
if( content.size() >= WINIX_POSTMULTI_OUTPUT_BUFFER )
{
tmp_file.write(content.c_str(), content.size());
content.clear();
}
if( config->post_file_max != 0 && content_len > config->post_file_max )
{
err = WINIX_ERR_INPUT_TOO_LARGE;
log << log1 << "PMP: content greater than " << data.post_file_max << " (skipping)" << logend;
log << log1 << "PMP: content greater than " << config->post_file_max << " (skipping)" << logend;
return;
}
}
@@ -277,7 +298,6 @@ bool has_boundary = false;
if( !content.empty() )
{
tmp_file.write(content.c_str(), content.size());
content_len += content.size();
content.clear();
}
}
@@ -290,7 +310,7 @@ void PostMultiParser::ReadContentToFile()
time_t t1, t2;
content.clear();
content.reserve(WINIX_POSTMULTI_OUTPUT_BUFFER + boundary.size());
content.reserve(WINIX_POSTMULTI_OUTPUT_BUFFER);
content_len = 0;
t1 = time(0);
@@ -317,10 +337,10 @@ bool has_boundary = false;
content_len += 1;
ReadChar();
if( data.post_file_max != 0 && content_len > (size_t)data.post_file_max )
if( config->post_file_max != 0 && content_len > (size_t)config->post_file_max )
{
err = WINIX_ERR_INPUT_TOO_LARGE;
log << log1 << "PMP: content greater than " << data.post_file_max << " (skipping)" << logend;
log << log1 << "PMP: content greater than " << config->post_file_max << " (skipping)" << logend;
return;
}
}
@@ -343,17 +363,29 @@ void PostMultiParser::ReadContent()
void PostMultiParser::AddNormalPostVar()
{
if( post_table->size() >= WINIX_POSTTABLE_MAXSIZE )
if( post_tab->size() >= WINIX_POSTTABLE_MAXSIZE )
{
err = WINIX_ERR_INPUT_TOO_LARGE;
log << log1 << "PMP: more than " << WINIX_POSTTABLE_MAXSIZE << " post variables (skipping)" << logend;
return;
}
std::pair<PostTable::iterator, bool> res = post_table->insert( std::make_pair(name, content) );
if( config->utf8 )
{
Ezc::UTF8ToWide(name, namew);
Ezc::UTF8ToWide(content, contentw);
}
else
{
AssignString(name, namew);
AssignString(content, contentw);
}
std::pair<PostTab::iterator, bool> res = post_tab->insert( std::make_pair(namew, contentw) );
bool added = res.second;
log << log2 << "PMP: POST var, name: \"" << name << "\"";
log << log2 << "PMP: POST var, name: \"" << namew << "\"";
if( !added )
log << log2 << " (skipped)";
@@ -364,19 +396,29 @@ void PostMultiParser::AddNormalPostVar()
void PostMultiParser::AddFilePostVar()
{
if( post_file_table->size() >= WINIX_POSTTABLE_MAXSIZE )
if( post_file_tab->size() >= WINIX_POSTTABLE_MAXSIZE )
{
err = WINIX_ERR_INPUT_TOO_LARGE;
log << log1 << "PMP: more than " << WINIX_POSTTABLE_MAXSIZE << " post file variables (skipping)" << logend;
return;
}
post_file_temp.filename = filename;
if( config->utf8 )
{
Ezc::UTF8ToWide(name, namew);
Ezc::UTF8ToWide(filename, post_file_temp.filename);
}
else
{
AssignString(name, namew);
AssignString(filename, post_file_temp.filename);
}
post_file_temp.tmp_filename = tmp_filename;
std::pair<PostFileTable::iterator, bool> res = post_file_table->insert( std::make_pair(name, post_file_temp) );
std::pair<PostFileTab::iterator, bool> res = post_file_tab->insert( std::make_pair(namew, post_file_temp) );
bool added = res.second;
log << log2 << "PMP: POST FILE var, name: \"" << name << "\"";
log << log2 << "PMP: POST FILE var, name: \"" << namew << "\"";
if( !added )
log << log2 << " (skipped)";
@@ -431,32 +473,38 @@ void PostMultiParser::CheckBoundaryEnd()
void PostMultiParser::CreateTmpFile()
{
char buf[100];
wchar_t buf[1024];
size_t buf_len = sizeof(buf)/sizeof(wchar_t);
if( data.auth_tmp_dir.empty() )
if( config->upload_dir.empty() )
{
log << log1 << "PMP: auth_tmp_dir is not set in the config" << logend;
log << log1 << "PMP: upload_dir is not set in the config" << logend;
err = WINIX_ERR_CANT_CREATE_FILE;
return;
}
sprintf(buf, "%s/winix_%u_%d_%u", data.auth_tmp_dir.c_str(), (unsigned)getpid(), tmp_filename_postfix, rand());
swprintf(buf, buf_len, L"%ls/tmp/pmp_%u_%d_%u", config->upload_dir.c_str(), (unsigned)getpid(), tmp_filename_postfix, rand());
tmp_filename_postfix += 1;
tmp_file.open(buf, std::ios_base::binary | std::ios_base::out);
tmp_filename = buf;
Ezc::WideToUTF8(tmp_filename, atmp_filename);
tmp_file.open(atmp_filename.c_str(), std::ios_base::binary | std::ios_base::out);
// !! dodac ustawienie chmod config.upload_files_chmod dla tymczasowego pliku
if( !tmp_file )
{
log << log1 << "PMP: can't create a temporary file: " << tmp_filename << logend;
log << log1 << "PMP: can't create a temporary file: " << atmp_filename << logend;
err = WINIX_ERR_CANT_CREATE_FILE;
return;
}
log << log3 << "PMP: using temporary file for the content: " << tmp_filename << logend;
log << log3 << "PMP: using temporary file for the content: " << atmp_filename << logend;
}
void PostMultiParser::ReadPart()
{
name.clear();
@@ -488,7 +536,7 @@ void PostMultiParser::ReadPart()
if( err != WINIX_ERR_OK && !filename.empty() )
{
log << log1 << "PMP: deleting the tmp file: " << tmp_filename << logend;
unlink(tmp_filename.c_str());
RemoveFile(tmp_filename);
}
}
@@ -523,7 +571,8 @@ void PostMultiParser::ReadChar()
Error PostMultiParser::Parse(FCGX_Stream * in_, PostTable & post_table_, PostFileTable & post_file_table_)
Error PostMultiParser::Parse(FCGX_Stream * in_, PostTab & post_tab_, PostFileTab & post_file_tab_)
{
in = in_;
last = 0;
@@ -531,8 +580,8 @@ Error PostMultiParser::Parse(FCGX_Stream * in_, PostTable & post_table_, PostFil
line_end_dos = false;
in_buffer_ind = WINIX_POSTMULTI_INPUT_BUFFER;
in_buffer_len = WINIX_POSTMULTI_INPUT_BUFFER;
post_table = &post_table_;
post_file_table = &post_file_table_;
post_tab = &post_tab_;
post_file_tab = &post_file_tab_;
tmp_filename_postfix = 1;
ReadChar();
@@ -546,8 +595,8 @@ Error PostMultiParser::Parse(FCGX_Stream * in_, PostTable & post_table_, PostFil
if( err != WINIX_ERR_OK )
{
post_table->clear();
post_file_table->clear();
post_tab->clear();
post_file_tab->clear();
if( err != WINIX_ERR_INPUT_TOO_LARGE && err != WINIX_ERR_CANT_CREATE_FILE )
log << log1 << "PMP: syntax error" << logend;

View File

@@ -15,6 +15,8 @@
#include <fstream>
#include "error.h"
#include "requesttypes.h"
#include "config.h"
// 2 MB
#define WINIX_POSTMULTI_INPUT_BUFFER 2097152
@@ -31,20 +33,24 @@ public:
PostMultiParser & operator=(const PostMultiParser &);
~PostMultiParser();
Error Parse(FCGX_Stream * in_, PostTable & post_table_, PostFileTable & post_file_table_);
void SetConfig(Config * pconfig);
Error Parse(FCGX_Stream * in_, PostTab & post_tab_, PostFileTab & post_file_tab_);
private:
Config * config;
FCGX_Stream * in;
unsigned char * in_buffer;
std::ofstream tmp_file;
std::string tmp_filename;
std::wstring tmp_filename;
std::string atmp_filename;
int tmp_filename_postfix;
size_t in_buffer_ind;
size_t in_buffer_len;
PostTable * post_table;
PostFileTable * post_file_table;
PostTab * post_tab;
PostFileTab * post_file_tab;
int last; // last read character
@@ -57,6 +63,7 @@ private:
Error err;
std::string name, filename;
std::wstring namew, contentw;
PostFile post_file_temp;
void LogFirst(const std::string & to_log, size_t len);

View File

@@ -14,7 +14,7 @@
#include <string>
#include "httpsimpleparser.h"
#include "requesttypes.h"
#include "misc.h"
@@ -22,7 +22,9 @@ class PostParser : public HttpSimpleParser
{
FCGX_Stream * in;
PostTable & post_table;
PostTab * post_tab;
std::wstring temp_name, temp_value;
bool input_as_utf8;
protected:
@@ -35,9 +37,20 @@ protected:
virtual void Parameter(std::string & name, std::string & value)
{
std::pair<PostTable::iterator, bool> res = post_table.insert( std::make_pair(name, value) );
if( input_as_utf8 )
{
Ezc::UTF8ToWide(name, temp_name);
Ezc::UTF8ToWide(value, temp_value);
}
else
{
AssignString(name, temp_name);
AssignString(value, temp_value);
}
std::pair<PostTab::iterator, bool> res = post_tab->insert( std::make_pair(temp_name, temp_value) );
log << log2 << "Method POST, name: \"" << name << "\", value: \"" << value << "\"";
log << log2 << "Method POST, name: \"" << temp_name << "\", value: \"" << temp_value << "\"";
if( res.second == false )
log << log2 << " (skipped)";
@@ -48,8 +61,24 @@ protected:
public:
PostParser(FCGX_Stream * in_, PostTable & post_table_) : in(in_), post_table(post_table_)
PostParser()
{
input_as_utf8 = false;
}
void UTF8(bool utf)
{
input_as_utf8 = utf;
}
void Parse(FCGX_Stream * in_, PostTab & post_tab_)
{
in = in_;
post_tab = &post_tab_;
HttpSimpleParser::Parse();
}
};

View File

@@ -12,17 +12,25 @@
#include "log.h"
#include "rebus.h"
#include "misc.h"
#include "request.h"
void Rebus::SetRequest(Request * prequest)
{
request = prequest;
}
bool Rebus::InitPair(int a, int b, Item & item)
{
char buffer[100];
wchar_t buffer[100];
size_t buffer_len = sizeof(buffer) / sizeof(wchar_t);
bool add = false;
if( a+b <= 15 )
{
sprintf(buffer, "%d+%d", a, b);
swprintf(buffer, buffer_len, L"%d+%d", a, b);
item.question = buffer;
item.answer = a+b;
add = true;
@@ -30,7 +38,7 @@ bool add = false;
if( a-b >= 0 )
{
sprintf(buffer, "%d-%d", a, b);
swprintf(buffer, buffer_len, L"%d-%d", a, b);
item.question = buffer;
item.answer = a-b;
add = true;
@@ -84,23 +92,23 @@ return &table[0] + i;
bool Rebus::IsAnswerOk(Rebus::Item * item, const std::string & answer)
bool Rebus::IsAnswerOk(Rebus::Item * item, const std::wstring & answer)
{
if( item == 0 )
return false;
char * end;
const char * a = answer.c_str();
wchar_t * end;
const wchar_t * a = answer.c_str();
a = SkipWhite(a);
int value = (int)strtol(a, &end, 10);
int value = (int)wcstol(a, &end, 10);
if( a == end )
// nothing has been read
return false;
log << log2 << "Rebus: your answer is: " << value << logend;
end = (char*)SkipWhite(end);
end = (wchar_t*)SkipWhite(end);
if( *end != 0 )
{
@@ -118,6 +126,35 @@ return result;
bool Rebus::CheckRebus()
{
if( !request->session )
return false;
if( request->session->puser )
// logged users don't have to use the rebus
return true;
if( request->session->rebus_checked )
return true;
request->session->rebus_checked = true;
if( !request->session->rebus_item )
{
log << log1 << "Rebus: rebus not set" << logend;
return false;
}
if( IsAnswerOk(request->session->rebus_item, request->PostVar(L"rebus")) )
return true;
log << log1 << "Rebus: rebus has an incorrect answer" << logend;
// don't add request->session->spam_score when the rebus has incorrect answer
// a user could have made a mistake
return false;
}

View File

@@ -15,6 +15,9 @@
#include <vector>
class Request;
class Rebus
{
public:
@@ -22,17 +25,22 @@ public:
struct Item
{
int key;
std::string question;
std::wstring question;
int answer;
};
void SetRequest(Request * prequest);
void Init();
Item * Rand();
bool IsAnswerOk(Item * item, const std::string & answer);
bool IsAnswerOk(Item * item, const std::wstring & answer);
bool CheckRebus();
private:
Request * request;
bool InitPair(int a, int b, Item & item);
std::vector<Item> table;

File diff suppressed because it is too large Load Diff

View File

@@ -13,19 +13,18 @@
#include <fcgiapp.h>
#include <sstream>
#include <vector>
#include <iomanip>
#include "requesttypes.h"
#include "session.h"
#include "item.h"
#include "error.h"
#include "function.h"
#include "thread.h"
#include "compress.h"
#include "acceptencodingparser.h"
#include "htmlfilter.h"
#include "postmultiparser.h"
#include "ticket.h"
#include "config.h"
#include "textstream.h"
#include "templates/htmltextstream.h"
class FunctionBase;
struct Request
@@ -33,26 +32,23 @@ struct Request
// request id
// is incremented for each request and is never 0
// (from -1 will be incremented twice)
// it's used for some optimalization e.g. in templates
// it's used for some optimalizations e.g. in templates
size_t id;
FCGX_Stream * in, * out, * err;
FCGX_ParamArray env; // defined as 'char **'
enum Method { get, post, none } method;
// !! moze pozbyc sie tego none?
enum Method { get, post, head, none } method;
enum Role { responder, authorizer } role;
// headers, page and debug
// notify (for mailing)
std::ostringstream headers, page, debug, notify;
//std::ostringstream headers, page, debug;
TextStream<std::string> headers;
HtmlTextStream page, debug;
GetTable get_table;
PostTable post_table;
PostFileTable post_file_table;
CookieTable cookie_table;
// raw parameters
GetTab get_tab;
PostTab post_tab;
PostFileTab post_file_tab;
CookieTab cookie_tab;
// environment variables
// they are not null -- when the server doesn't have such a variable
@@ -74,150 +70,87 @@ struct Request
bool browser_konqueror;
// current session
// is set after calling session_manager.SetSession()
Session * session;
// current directory
std::vector<Item*> dir_table;
std::vector<Item*> dir_tab;
// true if a file exists
bool is_item;
// this item is used for many purposes such as editing, adding an item etc.
// current file (if exists)
Item item;
// current winix function
// null if there is no a function
Function * pfunction;
// !! moze nazwac to poprostu param?
std::vector<std::string*> param_table;
FunctionBase * function;
// parameters (name:value)
ParamTab param_tab;
// request status
Error status;
// last notify
int notify_code;
// items in the current directory
// maybe without contents?
std::vector<Item> item_table;
// current thread (if exists)
bool is_thread;
Thread thread;
std::vector<Thread> thread_tab;
// current ticket (if exists)
bool is_ticket;
Ticket ticket;
std::vector<Ticket> ticket_tab;
// usually items in the current directory (depends on the function)
std::vector<Item> item_tab;
// if not empty means an address for redirecting to
std::string redirect_to;
std::wstring redirect_to;
std::string aredirect_to;
// send header X-LIGHTTPD-send-file with path to a file
std::string x_sendfile;
std::wstring x_sendfile;
// send as attachment (causing header: content-disposition: attachment)
bool send_as_attachment;
// for debugging
void PrintGetTable();
void PrintEnv();
void PrintIn();
// this is a pointer either to the item (if exists) or to the last directory
Item * last_item;
Request();
void ClearPostFileTmp();
void SetConfig(Config * pconfig);
void Clear();
void Init();
// for debugging
void PrintGetTab();
//void PrintEnv();
bool IsParam(const char * s);
bool IsParam(const wchar_t * param_name);
bool IsParam(const std::wstring & param_name);
const std::wstring & ParamValue(const wchar_t * param_name); // returns empty string if there is no such a parameter
void SetCookie(const char * name, const char * value, tm * expires = 0);
void SetCookie(const char * name, long value, tm * expires = 0);
bool IsPostVar(const char * var);
std::string * PostVar(const char * var); // it can return null when there is no such a post variable
bool PostVar(const char * var, std::string & result);
bool IsPostVar(const wchar_t * var);
const std::wstring & PostVar(const wchar_t * var); // !! zamienic na referencje nie do sta³ej (bez const)
bool PostVar(const wchar_t * var, std::wstring & result);
std::wstring * PostVarp(const wchar_t * var);
bool AllPostVarEmpty(); // returning true if all post vars are empty
void ReadEnvVariables();
void CheckMethod();
void ReadParameters();
void Read();
void SendAll();
void SendNotify();
bool CanChangeUser(const Item & item, long new_user_id);
bool CanChangeGroup(const Item & item, long new_group_id);
bool CanChangePrivileges(const Item & item, int new_priv);
bool HasAccess(const Item & item, int mask);
bool HasReadAccess(const Item & item);
bool HasWriteAccess(const Item & item);
bool HasReadWriteAccess(const Item & item);
bool HasReadExecAccess(const Item & item);
bool HasReadExecAccessForRoot(const Item & item);
bool HasReadExecAccessToPath(long dir_id);
bool CanCreateThread(bool check_root = false);
bool CanCreateTicket(bool check_root = false);
bool CanEditTicket();
bool CanRemove(const Item & item);
bool CanUseEmacs(const Item & item, bool check_root = false);
bool CanUseMkdir(const Item & item, bool check_root = false);
bool CanUseUpload(const Item & item, bool check_root = false);
bool CanUseHtml(long user_id);
bool CanUseBBCode(long user_id);
bool CanUseRaw(long user_id);
bool MakePathSimpleFs(std::string & path, long dir_id, bool create_dir = false);
bool MakePathHashFs(std::string & path, long id, bool create_dir = false);
bool MakePath(const Item & item, std::string & path, bool create_dir = false);
bool MakePath(Item & item, bool create_dir = false);
private:
enum Header
{
h_200,
h_404,
h_403
};
Config * config;
bool CanUse(long user_id, const char * group_name);
void ClearPostFileTmp();
void SendSessionCookie();
void CheckIE();
void CheckKonqueror();
void SendHeaders(bool compressing, Header header);
void AddDebugInfo();
void SendPage(bool compressing, const std::string & source_ref);
// used to set some env_* variables into it, when the server didn't set that variable
// it contains '\0'
// contains '\0'
// used to set env_* pointers to the empty value
const char char_empty;
PostMultiParser post_multi_parser;
const char * SetEnvVar(const char * var);
void StandardLog();
Compress compress;
AcceptEncodingParser accept_encoding_parser;
HTMLFilter html_filter;
// html after filtering
std::string clean_html;
// used in ParamValue() and PostVar() when there is no such a param
const std::wstring str_empty;
};
extern Request request;

View File

@@ -1,260 +0,0 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "requestcontroller.h"
#include "data.h"
#include "log.h"
#include "request.h"
#include "postparser.h"
#include "cookieparser.h"
#include "notify.h"
RequestController::RequestController()
{
last_sessions_save = time(0);
}
RequestController::~RequestController()
{
Close();
}
void RequestController::Close()
{
// don't call close(0)
// it will be closed next time during dup(s,0)
// if you closed the descriptor here
// then the database would have that descriptor (during connecting)
// and there'll be a problem in the next loop (after SIGHUP)
}
bool RequestController::Init()
{
const char * sock = data.fcgi_socket.c_str();
unlink(sock);
int s = FCGX_OpenSocket(sock, 10);
if( s < 0 )
{
log << log1 << "An error during creating a socket" << logend;
return false;
}
chmod(sock, data.fcgi_socket_chmod);
passwd * pw = getpwnam(data.fcgi_socket_user.c_str());
if( !pw )
{
log << log1 << "There is no user: " << data.fcgi_socket_user << logend;
return false;
}
group * gr = getgrnam(data.fcgi_socket_group.c_str());
if( !gr )
{
log << log1 << "There is no group: " << data.fcgi_socket_group << logend;
return false;
}
chown(sock, pw->pw_uid, gr->gr_gid);
if( setuid(pw->pw_uid) < 0 )
{
log << log1 << "I can't change the user into: " << data.fcgi_socket_user << logend;
return false;
}
/*
if( setgid(gr->gr_gid) < 0 )
{
int e = errno;
log << log1 << "I can't change the group into: " << data.fcgi_socket_group << " " << gr->gr_gid << logend;
log << log1 << "errno: " << e << logend;
return false;
}
*/
dup2(s, 0);
//
data.dirs.ReadDirs();
data.users.ReadUsers();
data.groups.ReadGroups();
data.functions.ReadFunctions();
data.mounts.ReadMounts();
data.rebus.Init();
//
if( !content.Init() )
return false;
return true;
}
void RequestController::LoadSessions()
{
session_manager.LoadSessions();
}
void RequestController::SaveSessions()
{
session_manager.SaveSessions();
}
void RequestController::DeleteAllPluginsData()
{
session_manager.DeleteAllPluginsData();
}
void RequestController::SaveSessionsIfNeeded()
{
time_t t = time(0);
if( last_sessions_save + 86400 > t )
return;
// saving once a day for safety
last_sessions_save = t;
SaveSessions();
}
bool RequestController::BaseUrlRedirect()
{
if( request.role == Request::responder )
{
if( data.base_url_http_host.empty() )
return false;
if( data.base_url_http_host == request.env_http_host )
return false;
request.redirect_to = data.base_url + request.env_request_uri;
}
else
{
// authorizer
if( data.base_url_auth_http_host.empty() )
return false;
if( data.base_url_auth_http_host == request.env_http_host )
return false;
request.redirect_to = data.base_url_auth + request.env_request_uri;
}
log << log3 << "RC: BaseUrlRedirect from: " << request.env_http_host << logend;
return true;
}
void RequestController::Loop()
{
while( FCGX_Accept(&request.in, &request.out, &request.err, &request.env) == 0 )
{
data.load_avg.StartRequest();
log << log2 << "---------------------------------------------------------------------------------" << logend;
try
{
request.Clear();
request.Read();
// when BaseUrlRedirect() return true we didn't have to set everything in request.Read()
// in the future request.Read() can be split and at the beginning only environment variables will be read
// and then BaseUrlRedirect() will be called (for performance)
if( !BaseUrlRedirect() )
{
session_manager.DeleteOldSessions();
session_manager.SetSession(); // set request.session as well
function_parser.Parse();
data.mounts.CalcCurMount();
content.ReadAdditionalInfo();
content.Make();
}
request.SendAll();
notify.ItemChanged(request.notify_code);
}
catch(const std::logic_error & e)
{
log << log1 << "std logic exception: " << e.what() << logend;
}
catch(const std::exception & e)
{
log << log1 << "std exception: " << e.what() << logend;
}
catch(const Error & e)
{
log << log1 << "exception: Error: " << e << logend;
}
catch(...)
{
log << log1 << "uncaught unknown exception" << logend;
}
SaveSessionsIfNeeded();
// !! this should be immediately after FCGX_Accept() but signals don't want to break FCGX_Accept
if( data.signal_hup )
{
log << logsave;
FCGX_Finish();
return;
}
request.ClearPostFileTmp();
data.load_avg.StopRequest();
log << logsave;
}
}
SessionContainer::Iterator RequestController::SessionBegin()
{
return session_manager.SessionBegin();
}
SessionContainer::Iterator RequestController::SessionEnd()
{
return session_manager.SessionEnd();
}

Some files were not shown because too many files have changed in this diff Show More