95 Commits
0.2.0 ... 0.4.0

Author SHA1 Message Date
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
4a7f036561 updated to new version of Ezc
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@602 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-05-30 21:07:46 +00:00
612f260938 added function: uname
added function: subject - for changing a subject


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@600 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-05-20 18:28:19 +00:00
2ad666d221 added: sessions data for plugins (plugindata.h plugindata.cpp)
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@598 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-05-04 21:58:22 +00:00
aff4cc516e added: 'rm' function can remove auth content now
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@597 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-03-15 17:09:45 +00:00
6fbcffe63b added: to the Item: auth_path - a path to a static file (if auth is different from auth_none)
added: function 'mv' (move)



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@596 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-03-15 01:47:26 +00:00
ebd868fa33 removed: Done class (core/done.h, core/done.cpp)
removed: from Session: done, done_status, timers



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@594 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-02-28 21:33:06 +00:00
71a63cc70e added: function adduser
changed: errors (removed enum, there are macros now)
added: error messages to locales (winix_err_NN)
removed: templates: err_abuse.html err_others.html


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@593 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-02-28 00:08:10 +00:00
3702efc5be added: parameter 'l' to 'ls' function
added: Db::ItemQuery struct for querying items
changed: some refactoring (renamed some config variables)




git-svn-id: svn://ttmath.org/publicrep/winix/trunk@589 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-02-22 22:52:09 +00:00
16e51cd4e5 added: to mount points: file systems
we have two file systems now:
       - simplefs - the files stored on the hard drive have the same structure as in the database (dir1/dir2/file)
       - hashfs - files are stored in special directories
extented: the mountparser can read file system 
added: function download
       this is a default function for items which have static content
  


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@588 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-02-18 23:30:22 +00:00
87747fab06 added: functions: chmod, chown
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@587 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-02-16 18:34:41 +00:00
4fe3d4339f added: parameter 'r' to priv function
all directories and files can be changed


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@586 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-02-16 00:37:00 +00:00
a276fb6b79 modified templates
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@585 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-02-15 18:22:16 +00:00
fa8d8f9ea0 fixed: Config::Text() returned a reference to a local variable (std::string)
added: 'static' directory with *.css and images
       we have a default layout
moved: locale from data to templates       
       notification templates have its own locale object
added: reload function reloades locale now too
added: 'nice' form of item_info in templates



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@582 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-02-15 00:31:14 +00:00
c58031cbf4 added static dir
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@581 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-02-14 14:28:43 +00:00
4aae12fc63 I forgot to commit loadavg.h and loadavg.cpp
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@579 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-02-13 20:14:44 +00:00
256a8fb5c5 added: calculation of load averages and requests per second
(uptime function shows it)


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@577 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-02-13 20:12:15 +00:00
3c5a7cd664 changed: upload function
select file type by the extension
         param: multi
fixed:   uptime function
         it showed incorrect uptime time (minuts were badly calculated)


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@575 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-02-12 23:16:13 +00:00
796985472a added to config: parameter static_auth_dir_tmp
with a path to directory for tmp files (for upload functino)



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@572 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-02-12 17:05:32 +00:00
7e0014865e added: loggin to upload.cpp
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@571 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-02-12 16:39:09 +00:00
cd74d1887a fixed: sprintf %d in uptime function
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@569 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-02-11 21:04:53 +00:00
adf36e71ce added: functions: ckeditor, uptime
added: for function: login - a html pattern for GET request


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@567 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-02-11 20:56:52 +00:00
fc3c303d30 added: to templates: item_url_is and dir_last_url
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@566 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-02-08 20:02:16 +00:00
0e50977779 added: 'rm' function can work with tickets
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@565 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-02-06 14:08:44 +00:00
ed9feaf542 changed: log is saved after some requests (config: log_request value) (performance)
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@563 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-01-28 21:09:48 +00:00
09d427b4ba changed: rename cmslu to winix
changed: html templates are a part of winix now
         and the user can provide special html templates for its site
added:   locales
added:   html templates are using HtmlFilter now (locales)
changed: now we have html templates for each language



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@560 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-01-28 15:39:01 +00:00
5dac8af300 renaming cmslu to winix
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@559 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-01-26 19:07:40 +00:00
1493a6180a moving html templates to cmslu
git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@558 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-01-26 19:02:21 +00:00
848ddcebd7 fixed: not logged users cannot edit a ticket
git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@557 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-01-25 07:27:18 +00:00
71763d340e fixed: not logged users are not allowed to remove anything
(temporarily - we're waiting for the sticky bit)


git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@556 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-01-25 07:04:34 +00:00
89daf6489d added: issues ticket system
added functions: ticket, createticket, editticket
         (there is no 'rm' function working for tickets yet)
changed: mount parser and mount points
         now we have more parameters (arguments in parameters)
some refactoring in functions 'emacs' and 'mkdir'



git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@554 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-01-25 04:52:17 +00:00
356e93914b fixed: there was a wrong template used for 404 header
git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@553 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-01-11 16:41:23 +00:00
5523d0c27a fixed: access to content type should not be checked when generating a page
git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@552 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-01-11 15:09:31 +00:00
590a94523e fixed: content type was always 'formatted text' (in emacs when creating a new item)
git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@551 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-01-11 14:59:19 +00:00
3c95b84633 added: item content type: raw
git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@549 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-01-11 14:47:52 +00:00
59943c87cd added: default values for variables read from the config file
git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@547 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-01-07 14:45:00 +00:00
3f9a46b1f7 added: static_auth_dir to config
git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@545 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-01-06 19:36:29 +00:00
81faca041a added: parser for multipart forms, files: postmultiparser.h postmultiparser.cpp
added: function: upload




git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@543 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-01-06 19:17:53 +00:00
60fccea703 fixed: dots in url-es (now only one dot is available in the whole name and it cannot be only one dot ".")
added:   cmslu can act as an authorizer (fast cgi authorize role)
added:   Item::static_auth we can have additional static content on the file system
         this content is authorized through cmslu (fastcgi authorizer mode)
changed: some changes in config
changed: the way how the www server is using cmslu
         added new virtuals: static static_auth
changed: cmslu returns correct http headers (200, 404, 403)
changed: in cookie parser: we get the last cookie (if the server has more than one cookie with the same name)



git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@540 e52654a7-88a9-db11-a3e9-0013d4bc506e
2009-12-30 20:46:12 +00:00
118bf1fc65 added: exception for the Konqueror browser
it has a problem with deflate compression


git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@539 e52654a7-88a9-db11-a3e9-0013d4bc506e
2009-12-19 19:46:15 +00:00
ce7ae3edd4 changed: notification times
git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@536 e52654a7-88a9-db11-a3e9-0013d4bc506e
2009-12-09 00:52:00 +00:00
717eb526fb * added: class HTMLFilter
files: htmlfilter.h htmlfilter.cpp
         this is an html filter used to make the html output looking better
         this is a very lightweight filter
         (without using any dynamic memory - some memory is allocated only at the beginning - in ctors)
         this filter has O(n) complexity over the whole html string
* added: antyspamming method
         if the POST request is sent too fast after the GET
         it is treated as a spam
         only for no logged users and only in 'emacs' and 'createthread' functions
       


git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@534 e52654a7-88a9-db11-a3e9-0013d4bc506e
2009-12-09 00:42:40 +00:00
9241fddb1e small changes in Makefile
now the binaries are in local 'bin' directory
(use make install)


git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@532 e52654a7-88a9-db11-a3e9-0013d4bc506e
2009-12-04 05:03:44 +00:00
2dff0bed72 changed: SessionParser::ReadLong() can read negative values
git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@531 e52654a7-88a9-db11-a3e9-0013d4bc506e
2009-11-21 00:08:08 +00:00
4827c116f0 added: 'remember me' flag when logging
added: the session file
       sessions can still be available between starting and stopping the cmslu system


git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@529 e52654a7-88a9-db11-a3e9-0013d4bc506e
2009-11-20 23:09:52 +00:00
848afac803 removed: hidden variable 'old_url' in emacs template
git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@527 e52654a7-88a9-db11-a3e9-0013d4bc506e
2009-11-18 01:58:38 +00:00
13b0204427 I have forgotten to add templates/rebus.cpp to the repository
git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@525 e52654a7-88a9-db11-a3e9-0013d4bc506e
2009-11-17 01:07:29 +00:00
dc5f002de3 refactoring
git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@523 e52654a7-88a9-db11-a3e9-0013d4bc506e
2009-11-17 01:04:01 +00:00
2ca44ec361 added: Rebus
(when no logged user wants to send a message then he is asked a question)


git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@521 e52654a7-88a9-db11-a3e9-0013d4bc506e
2009-11-16 23:36:38 +00:00
c62d48160a fixed: the core didn't test for special folder when system was running
(now mkdir addes correctly special folders)
added: function 'reload'
       param: 'templates' - reloading templates


git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@519 e52654a7-88a9-db11-a3e9-0013d4bc506e
2009-11-16 17:43:23 +00:00
9129f1b82a added: mount points are read from db: /etc/fstab
changed: mount points parser allows empty lines (with some white characters)


git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@518 e52654a7-88a9-db11-a3e9-0013d4bc506e
2009-11-15 23:55:11 +00:00
378cfc0c3d added: plugin mechanism
files: core/plugin.h core/plugin.cpp core/pluginmsg.h
added: directory 'main' with main.cpp (moved from 'core' directory)
changed: the way of building
       nearly everything is in cmslu.so
       only main() is in cmslu and is dynamically linked with cmslu.so



git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@516 e52654a7-88a9-db11-a3e9-0013d4bc506e
2009-11-13 20:40:11 +00:00
7db71d43e0 added: acceptbaseparser.h acceptbaseparser.cpp
class AcceptBaseParser for parsing http accept* headers
added: acceptencodingparser.h
       class AcceptEncodingParser for parsing HTTP_ACCEPT_ENCODING header
added: compresion only when HTTP_ACCEPT_ENCODING has 'deflate'
       and the browser is not the Internet Explorer


git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@515 e52654a7-88a9-db11-a3e9-0013d4bc506e
2009-10-08 17:59:10 +00:00
85b678a8fb added: notifications to users' emails
(core/notify.h core/notify.cpp)
       templatesnotify directory
       all notifications are managed by a second thread


git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@512 e52654a7-88a9-db11-a3e9-0013d4bc506e
2009-09-30 22:31:20 +00:00
9902ce2b78 added: support for output compression
git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@511 e52654a7-88a9-db11-a3e9-0013d4bc506e
2009-09-21 23:05:05 +00:00
394c7b22a2 changed: mount points
git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@508 e52654a7-88a9-db11-a3e9-0013d4bc506e
2009-06-07 22:17:07 +00:00
f99c993d96 added: column 'guest_name' to 'item' table
used when user_id is -1
added: mount parameters: thread_with_info, thread_with_header
added: function rm can remove threads



git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@506 e52654a7-88a9-db11-a3e9-0013d4bc506e
2009-06-07 02:40:27 +00:00
1eb42446f8 added: forum
added: mount params can have arguments (in parentheses)
added: mount params: withheader, withinfo, restrictcreatethread, only_root_can_remove,
       can_use_emacs_on(level), can_use_mkdir_on(level), 
added: table Item has 'subject' column now
removed: column 'subject' from table Content




git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@505 e52654a7-88a9-db11-a3e9-0013d4bc506e
2009-06-05 20:29:06 +00:00
3d001e7458 added: macro APPPREPARE
void AppFunction(int code);



git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@503 e52654a7-88a9-db11-a3e9-0013d4bc506e
2009-05-21 19:27:16 +00:00
2dd3fc7df8 changed: the way of building
core.a content.a templates.a confparser.a have gone away
	 there is only: cmslu.a now (in the global directory 'cmslu')
changed: the way of building
         in Makefile(s) we dont longer use explicitly a variable 'o = file1.o file2.o...'
	 it was put into Makefile.o.dep and is generated automatically 
         when 'make depend' is invoked
changed: some #include "..." directives were put from *.h to *.cpp files
         fewer dependences


git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@501 e52654a7-88a9-db11-a3e9-0013d4bc506e
2009-04-21 20:50:55 +00:00
f46677dfc0 added: mount points have parameters now
added: to the database: table 'thread'



git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@499 e52654a7-88a9-db11-a3e9-0013d4bc506e
2009-04-20 23:49:28 +00:00
e94ccc86f8 fixed: a small problem in mountparser (it coused core dumped when there was a wrong mount point supplied)
fixed: 'default' funtion can take a directory now (there was an error early)


git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@497 e52654a7-88a9-db11-a3e9-0013d4bc506e
2009-04-20 21:10:31 +00:00
e778903dab added: put info about logging out a user (to 'last' table) (when a session expires)
git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@496 e52654a7-88a9-db11-a3e9-0013d4bc506e
2009-04-20 20:22:35 +00:00
a1ea298a43 added: mount points
(reading /etc/fstab from db not working yet)
       core/mount.h
       core/mountparser.h
       core/mountparser.cpp
       core/mounts.h
       core/mounts.cpp
       content/thread.cpp
       content/createthread.cpp
       templates/thread.cpp       



git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@495 e52654a7-88a9-db11-a3e9-0013d4bc506e
2009-04-19 22:13:21 +00:00
7a4a8e0fe2 added: container LastContainer (lastcontainer.h lastcontainer.cpp)
it consists of last logged users
added: function 'last'


git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@492 e52654a7-88a9-db11-a3e9-0013d4bc506e
2009-04-16 01:59:42 +00:00
bbaefd0f77 added: date_creation and date_modification to items
changed: function 'run' is using a template: fun_run.html
         there is: [item_run] called from this template


git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@489 e52654a7-88a9-db11-a3e9-0013d4bc506e
2009-03-22 23:54:15 +00:00
951d0e8653 changed: DirContainer - uses std::list instead of std::vector as the main container
we do not have to rebuild indexes after deleting some items
added:   DirContainer::DelById(long id)
changed: Dirs::CheckRootDir() addes the root dir if there is no one
added:   Dirs::DeleteDir(long id) - deletes specified directory (and its contents)
         (from the cache and the database)
added:   Db::DelDirById(long id) - deletes a dir from the database 
         and its first children
added:   standard function rm can delete directories


git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@487 e52654a7-88a9-db11-a3e9-0013d4bc506e
2009-02-06 13:12:03 +00:00
7d73d048c8 added: SessionContainer special container used by SessionManager
sessions are indexed by id and time (last used time)
changed: old sessions are deleted
       parameter: session_max_iddle in the config file
added: function 'who'


git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@483 e52654a7-88a9-db11-a3e9-0013d4bc506e
2009-01-31 06:53:36 +00:00
a48766871d fixed: the way AppDb works (pg_conn and Connect method)
git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@482 e52654a7-88a9-db11-a3e9-0013d4bc506e
2009-01-27 18:43:44 +00:00
406cb4a619 changed: not logging (headers and body)
git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@480 e52654a7-88a9-db11-a3e9-0013d4bc506e
2009-01-26 21:21:07 +00:00
9418cc7a69 default.item has to be default.cpp
git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@479 e52654a7-88a9-db11-a3e9-0013d4bc506e
2009-01-26 21:08:42 +00:00
20f6fbcf84 changed: the way of building the cmslu
main Makefile is in an application directory
         in cmslu/ there are only libraries:
         core.a content.a confparser.a templates.a
added:   macros APPTEMPLATES APPFUNCTIONS
         defined in the application's Makefile
added:   PatternCacher
added:   cmslu function 'run'
         files which have exec permissions
         can be run (run is a default function)
         after read from the database the content is parsed
         into Ezc::Pattern object, this object is then cached
         in PatternCacher
added:   FunctionCodeParser - will be used to parse the code
         from standard functions (ls/cat/...)


git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@475 e52654a7-88a9-db11-a3e9-0013d4bc506e
2009-01-26 20:49:28 +00:00
327f18525c changed: cmslu building
Makefile from cmslu/ builds only: confparser.a content.a core.a templates.a
         the proper *.fcgi file is created from an application
changed: all cmslu functions have english names (ls, emacs, etc)
fixed:   function: login/logout are placed where there are permissions


git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@474 e52654a7-88a9-db11-a3e9-0013d4bc506e
2009-01-14 20:11:12 +00:00
8a0ea59c77 added: function: default
changes the default item in a directory


git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@473 e52654a7-88a9-db11-a3e9-0013d4bc506e
2008-12-31 18:28:12 +00:00
f6ad846927 I forgot to commit content/mkdir.cpp
git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@472 e52654a7-88a9-db11-a3e9-0013d4bc506e
2008-12-31 13:40:23 +00:00
114b5724f8 added: function: mkdir
git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@471 e52654a7-88a9-db11-a3e9-0013d4bc506e
2008-12-31 13:36:46 +00:00
284 changed files with 27976 additions and 4311 deletions

View File

@@ -1,53 +1,62 @@
CC = g++
CFLAGS = -Wall -pedantic -g -I/usr/local/include -L/usr/local/lib
name = cmslu.fcgi
# Makefile for GNU make
export CC
export CFLAGS
ifndef CXX
CXX = g++
endif
ifndef CXXFLAGS
#CXXFLAGS = -fPIC -Wall -pedantic -O2 -I/usr/local/include -I/home/tomek/roboczy/winix -I/home/tomek/roboczy/ezc/src -L/usr/local/lib -DEZC_USE_WINIX_LOGGER
CXXFLAGS = -fPIC -Wall -pedantic -O0 -g -I/usr/local/include -I/home/tomek/roboczy/winix -I/home/tomek/roboczy/ezc/src -L/usr/local/lib -DEZC_USE_WINIX_LOGGER
endif
all: $(name)
export CXX
export CXXFLAGS
$(name): core content confparser templates ezc
g++ -o $(name) $(CFLAGS) core/core.a content/content.a confparser/confparser.a templates/templates.a ../ezc/src/ezc.a -lfcgi -lpq
all: winix
core: FORCE
winix: FORCE
@cd core ; $(MAKE) -e
templates: FORCE
@cd functions ; $(MAKE) -e
@cd templates ; $(MAKE) -e
confparser: FORCE
@cd confparser ; $(MAKE) -e
content: FORCE
@cd content ; $(MAKE) -e
ezc: FORCE
@cd templatesnotify ; $(MAKE) -e
@cd plugins/stats ; $(MAKE) -e
@cd ../ezc/src ; $(MAKE) -e
$(CXX) -shared -o winix.so $(CXXFLAGS) core/*.o functions/*.o templates/*.o templatesnotify/*.o ../ezc/src/ezc.a -lfcgi -lpq -lz -lpthread
@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 functions ; $(MAKE) -e clean
@cd templates ; $(MAKE) -e clean
@cd confparser ; $(MAKE) -e clean
@cd content ; $(MAKE) -e clean
@cd templatesnotify ; $(MAKE) -e clean
@cd plugins/stats ; $(MAKE) -e clean
@cd ../ezc/src ; $(MAKE) -e clean
rm -f $(name)
@cd main ; $(MAKE) -e clean
rm -f winix.so
rm -f winix
FORCE:
depend:
cd core ; $(MAKE) -e depend
cd templates ; $(MAKE) -e depend
cd confparser ; $(MAKE) -e depend
cd content ; $(MAKE) -e depend
cd ../ezc/src ; $(MAKE) -e depend
@cd core ; $(MAKE) -e depend
@cd functions ; $(MAKE) -e depend
@cd templates ; $(MAKE) -e depend
@cd templatesnotify ; $(MAKE) -e depend
@cd plugins/stats ; $(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/

View File

@@ -1,29 +1,22 @@
o = confparser.o
include Makefile.o.dep
all: confparser.a
confparser.a: $(o)
ar rcs confparser.a $(o)
all: $(o)
.SUFFIXES: .cpp .o
.cpp.o:
$(CC) -c $(CFLAGS) $<
$(CXX) -c $(CXXFLAGS) $<
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
clean:
rm -f *.o
rm -f *.a
include Makefile.dep

View File

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

1
confparser/Makefile.o.dep Executable file
View File

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

View File

@@ -1,208 +0,0 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* All rights reserved.
*
*/
#include "confparser.h"
ConfParser::ConfParser()
{
separator = '=';
commentary = '#';
}
ConfParser::Status ConfParser::Parse(const char * file_name)
{
file.open( file_name );
if( !file )
return cant_open_file;
line = 1;
table.clear();
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) );
}
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 )
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();
}
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();
}

View File

@@ -1,74 +0,0 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* and is not publicly distributed
*
* Copyright (c) 2008, 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();
};
#endif

View File

@@ -1,26 +0,0 @@
o = content.o privileges.o emacs.o login.o rm.o cat.o logout.o ls.o node.o
all: content.a
content.a: $(o)
ar rcs content.a $(o)
.SUFFIXES: .cpp .o
.cpp.o:
$(CC) -c $(CFLAGS) $<
depend:
makedepend -Y. -f- *.cpp > Makefile.dep
clean:
rm -f *.o
rm -f *.a
include Makefile.dep

View File

@@ -1,108 +0,0 @@
# DO NOT DELETE
cat.o: content.h ../templates/templates.h ../../ezc/src/ezc.h ../core/data.h
cat.o: ../core/misc.h ../core/log.h ../core/item.h ../core/error.h
cat.o: ../core/dirs.h ../core/db.h ../core/dircontainer.h ../core/user.h
cat.o: ../core/group.h ../core/ugcontainer.h ../core/users.h ../core/groups.h
cat.o: ../core/functions.h ../core/function.h ../core/request.h
cat.o: ../core/requesttypes.h ../core/session.h ../core/done.h
cat.o: ../core/getparser.h ../core/httpsimpleparser.h ../core/postparser.h
cat.o: ../core/cookieparser.h ../core/item.h ../core/db.h ../core/error.h
cat.o: ../core/user.h ../core/group.h ../core/users.h ../core/groups.h
cat.o: ../core/log.h ../core/misc.h ../core/function.h
cat.o: ../core/functionparser.h ../core/request.h ../core/data.h
content.o: content.h ../templates/templates.h ../../ezc/src/ezc.h
content.o: ../core/data.h ../core/misc.h ../core/log.h ../core/item.h
content.o: ../core/error.h ../core/dirs.h ../core/db.h ../core/dircontainer.h
content.o: ../core/user.h ../core/group.h ../core/ugcontainer.h
content.o: ../core/users.h ../core/groups.h ../core/functions.h
content.o: ../core/function.h ../core/request.h ../core/requesttypes.h
content.o: ../core/session.h ../core/done.h ../core/getparser.h
content.o: ../core/httpsimpleparser.h ../core/postparser.h
content.o: ../core/cookieparser.h ../core/item.h ../core/db.h ../core/error.h
content.o: ../core/user.h ../core/group.h ../core/users.h ../core/groups.h
content.o: ../core/log.h ../core/misc.h ../core/function.h
content.o: ../core/functionparser.h ../core/request.h ../core/data.h
emacs.o: content.h ../templates/templates.h ../../ezc/src/ezc.h
emacs.o: ../core/data.h ../core/misc.h ../core/log.h ../core/item.h
emacs.o: ../core/error.h ../core/dirs.h ../core/db.h ../core/dircontainer.h
emacs.o: ../core/user.h ../core/group.h ../core/ugcontainer.h ../core/users.h
emacs.o: ../core/groups.h ../core/functions.h ../core/function.h
emacs.o: ../core/request.h ../core/requesttypes.h ../core/session.h
emacs.o: ../core/done.h ../core/getparser.h ../core/httpsimpleparser.h
emacs.o: ../core/postparser.h ../core/cookieparser.h ../core/item.h
emacs.o: ../core/db.h ../core/error.h ../core/user.h ../core/group.h
emacs.o: ../core/users.h ../core/groups.h ../core/log.h ../core/misc.h
emacs.o: ../core/function.h ../core/functionparser.h ../core/request.h
emacs.o: ../core/data.h
login.o: content.h ../templates/templates.h ../../ezc/src/ezc.h
login.o: ../core/data.h ../core/misc.h ../core/log.h ../core/item.h
login.o: ../core/error.h ../core/dirs.h ../core/db.h ../core/dircontainer.h
login.o: ../core/user.h ../core/group.h ../core/ugcontainer.h ../core/users.h
login.o: ../core/groups.h ../core/functions.h ../core/function.h
login.o: ../core/request.h ../core/requesttypes.h ../core/session.h
login.o: ../core/done.h ../core/getparser.h ../core/httpsimpleparser.h
login.o: ../core/postparser.h ../core/cookieparser.h ../core/item.h
login.o: ../core/db.h ../core/error.h ../core/user.h ../core/group.h
login.o: ../core/users.h ../core/groups.h ../core/log.h ../core/misc.h
login.o: ../core/function.h ../core/functionparser.h ../core/request.h
login.o: ../core/data.h
logout.o: content.h ../templates/templates.h ../../ezc/src/ezc.h
logout.o: ../core/data.h ../core/misc.h ../core/log.h ../core/item.h
logout.o: ../core/error.h ../core/dirs.h ../core/db.h ../core/dircontainer.h
logout.o: ../core/user.h ../core/group.h ../core/ugcontainer.h
logout.o: ../core/users.h ../core/groups.h ../core/functions.h
logout.o: ../core/function.h ../core/request.h ../core/requesttypes.h
logout.o: ../core/session.h ../core/done.h ../core/getparser.h
logout.o: ../core/httpsimpleparser.h ../core/postparser.h
logout.o: ../core/cookieparser.h ../core/item.h ../core/db.h ../core/error.h
logout.o: ../core/user.h ../core/group.h ../core/users.h ../core/groups.h
logout.o: ../core/log.h ../core/misc.h ../core/function.h
logout.o: ../core/functionparser.h ../core/request.h ../core/data.h
ls.o: content.h ../templates/templates.h ../../ezc/src/ezc.h ../core/data.h
ls.o: ../core/misc.h ../core/log.h ../core/item.h ../core/error.h
ls.o: ../core/dirs.h ../core/db.h ../core/dircontainer.h ../core/user.h
ls.o: ../core/group.h ../core/ugcontainer.h ../core/users.h ../core/groups.h
ls.o: ../core/functions.h ../core/function.h ../core/request.h
ls.o: ../core/requesttypes.h ../core/session.h ../core/done.h
ls.o: ../core/getparser.h ../core/httpsimpleparser.h ../core/postparser.h
ls.o: ../core/cookieparser.h ../core/item.h ../core/db.h ../core/error.h
ls.o: ../core/user.h ../core/group.h ../core/users.h ../core/groups.h
ls.o: ../core/log.h ../core/misc.h ../core/function.h
ls.o: ../core/functionparser.h ../core/request.h ../core/data.h
node.o: content.h ../templates/templates.h ../../ezc/src/ezc.h ../core/data.h
node.o: ../core/misc.h ../core/log.h ../core/item.h ../core/error.h
node.o: ../core/dirs.h ../core/db.h ../core/dircontainer.h ../core/user.h
node.o: ../core/group.h ../core/ugcontainer.h ../core/users.h
node.o: ../core/groups.h ../core/functions.h ../core/function.h
node.o: ../core/request.h ../core/requesttypes.h ../core/session.h
node.o: ../core/done.h ../core/getparser.h ../core/httpsimpleparser.h
node.o: ../core/postparser.h ../core/cookieparser.h ../core/item.h
node.o: ../core/db.h ../core/error.h ../core/user.h ../core/group.h
node.o: ../core/users.h ../core/groups.h ../core/log.h ../core/misc.h
node.o: ../core/function.h ../core/functionparser.h ../core/request.h
node.o: ../core/data.h
privileges.o: content.h ../templates/templates.h ../../ezc/src/ezc.h
privileges.o: ../core/data.h ../core/misc.h ../core/log.h ../core/item.h
privileges.o: ../core/error.h ../core/dirs.h ../core/db.h
privileges.o: ../core/dircontainer.h ../core/user.h ../core/group.h
privileges.o: ../core/ugcontainer.h ../core/users.h ../core/groups.h
privileges.o: ../core/functions.h ../core/function.h ../core/request.h
privileges.o: ../core/requesttypes.h ../core/session.h ../core/done.h
privileges.o: ../core/getparser.h ../core/httpsimpleparser.h
privileges.o: ../core/postparser.h ../core/cookieparser.h ../core/item.h
privileges.o: ../core/db.h ../core/error.h ../core/user.h ../core/group.h
privileges.o: ../core/users.h ../core/groups.h ../core/log.h ../core/misc.h
privileges.o: ../core/function.h ../core/functionparser.h ../core/request.h
privileges.o: ../core/data.h
rm.o: content.h ../templates/templates.h ../../ezc/src/ezc.h ../core/data.h
rm.o: ../core/misc.h ../core/log.h ../core/item.h ../core/error.h
rm.o: ../core/dirs.h ../core/db.h ../core/dircontainer.h ../core/user.h
rm.o: ../core/group.h ../core/ugcontainer.h ../core/users.h ../core/groups.h
rm.o: ../core/functions.h ../core/function.h ../core/request.h
rm.o: ../core/requesttypes.h ../core/session.h ../core/done.h
rm.o: ../core/getparser.h ../core/httpsimpleparser.h ../core/postparser.h
rm.o: ../core/cookieparser.h ../core/item.h ../core/db.h ../core/error.h
rm.o: ../core/user.h ../core/group.h ../core/users.h ../core/groups.h
rm.o: ../core/log.h ../core/misc.h ../core/function.h
rm.o: ../core/functionparser.h ../core/request.h ../core/data.h

View File

@@ -1,38 +0,0 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* All rights reserved.
*
*/
#include "content.h"
void Content::FunCat()
{
if( !request.is_item )
{
log << log1 << "Content: Cat function requires an item" << logend;
request.status = Error::item_required;
return;
}
if( !request.HasReadAccess(request.item) )
{
request.status = Error::permision_denied;
return;
}
}

View File

@@ -1,256 +0,0 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* All rights reserved.
*
*/
#include "content.h"
bool Content::Init()
{
templates.Read();
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::SetDefaultFunction()
{
if( request.is_item )
{
request.pfunction = data.functions.GetFunction(Function::cat);
if( request.pfunction )
log << log3 << "Content: default function: " << request.pfunction->item.url << logend;
}
else
{
long default_item = request.dir_table.back()->default_item;
if( default_item == -1 )
{
request.pfunction = data.functions.GetFunction(Function::ls);
if( request.pfunction )
log << log3 << "Content: default function: " << request.pfunction->item.url << logend;
}
else
{
log << log3 << "Content: Default item: id: " << default_item << logend;
RedirectTo(default_item);
}
}
}
void Content::MakeStandardFunction()
{
if( !request.pfunction )
SetDefaultFunction();
if( request.result == Request::redirect )
return;
if( !request.pfunction )
{
log << log1 << "Content: no function (neither cat nor ls)" << logend;
return;
}
if( request.pfunction->code == Function::logout )
FunLogout();
else
if( request.pfunction->code == Function::cat )
FunCat();
else
if( request.pfunction->code == Function::ls )
FunLs();
else
if( request.pfunction->code == Function::emacs )
FunEmacs();
else
if( request.pfunction->code == Function::privileges )
FunPrivileges();
else
if( request.pfunction->code == Function::rm )
FunRm();
else
if( request.pfunction->code == Function::node )
FunNode();
}
void Content::MakePost()
{
if( !request.pfunction )
{
log << log1 << "Content: MakePost: no function" << logend;
request.status = Error::no_function;
return;
}
switch( request.pfunction->code )
{
case Function::emacs:
PostFunEmacs();
break;
case Function::privileges:
PostFunPrivileges();
break;
case Function::login:
PostFunLogin();
break;
default:
log << log1 << "Content: unknown post function" << logend;
break;
}
}
void Content::Make()
{
if( request.dir_table.empty() )
{
log << log1 << "Content: there is no a root dir" << logend;
return;
}
// request.status can be changed by function_parser
if( request.status == Error::ok )
{
if( DirsHaveReadExecPerm() )
{
if( request.method == Request::post )
MakePost();
if( request.result == Request::redirect )
return;
if( request.status == Error::ok )
MakeStandardFunction();
}
else
request.status = Error::permision_denied;
}
if( request.result == Request::redirect )
return;
templates.Generate();
//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)
{
std::string path;
request.result = Request::redirect;
request.str = data.base_url;
if( item.type == Item::dir )
{
// item_id is pointing to a directory
data.dirs.MakePath(item.id, path);
request.str += 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.str += path;
request.str += item.url;
}
}
void Content::RedirectTo(long item_id)
{
std::string path;
Item * pdir;
request.result = Request::redirect;
request.str = 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.str += 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.str += path + request.item_table[0].url;
}
else
{
log << log1 << "Content: Can't redirect: no such item: id: " << item_id << logend;
}
}
}

View File

@@ -1,73 +0,0 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecontent
#define headerfilecontent
#include <cstdlib>
#include <fcgiapp.h>
#include "../templates/templates.h"
#include "../core/request.h"
#include "../core/error.h"
#include "../core/misc.h"
#include "../core/db.h"
#include "../core/user.h"
#include "../core/function.h"
#include "../core/functionparser.h"
class Content
{
Templates templates;
void PrepareUrl(Item & item);
void SetDefaultFunction();
bool DirsHaveReadExecPerm();
void MakeStandardFunction();
void MakePost();
void FunCat();
void FunLogout();
void FunLs();
void FunEmacs();
void FunPrivileges();
void FunRm();
void FunNode();
void PostFunLogin();
void PostFunEmacsAdd();
void PostFunEmacsEdit(bool with_url);
void PostFunEmacs();
void PostFunPrivileges();
void RedirectTo(const Item & item);
void RedirectTo(long item_id);
public:
bool Init();
void Make();
};
#endif

View File

@@ -1,133 +0,0 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* All rights reserved.
*
*/
#include "content.h"
void Content::PrepareUrl(Item & item)
{
CorrectUrl(item);
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(), '_');
}
}
void Content::PostFunEmacsAdd()
{
request.session->done = Done::added_item;
request.is_item = true;
request.item.user_id = request.session->puser ? request.session->puser->id : -1;
request.item.group_id = -1;
request.item.privileges = 0644; // !! tymczasowo, bedzie uzyte umask
request.item.parent_id = request.dir_table.back()->id;
request.item.type = Item::file;
if( !request.HasWriteAccess(*request.dir_table.back() ) )
throw Error(Error::permision_denied);
request.session->done_status = db.AddItem(request.item);
}
void Content::PostFunEmacsEdit(bool with_url)
{
request.session->done = Done::edited_item;
if( !request.HasWriteAccess(request.item) )
throw Error(Error::permision_denied);
request.session->done_status = db.EditItemById(request.item, with_url);
}
void Content::PostFunEmacs()
{
try
{
// these old values are ignored (if exists)
request.item.url = request.PostVar("url");
request.item.subject = request.PostVar("subject");
request.item.content = request.PostVar("content");
bool with_url = false;
if( !request.is_item || request.PostVar("old_url") != request.item.url )
with_url = true;
PrepareUrl(request.item);
if( request.is_item )
PostFunEmacsEdit(with_url);
else
PostFunEmacsAdd();
}
catch(const Error & e)
{
request.session->done_status = e;
}
if( request.session->done_status == Error::ok )
{
request.session->item = request.item;
request.session->done_timer = 2;
RedirectTo(request.item);
}
else
{
log << log1 << "Content: PostFunEmacs: Error: " << request.session->done_status << logend;
}
}
void Content::FunEmacs()
{
if( !request.is_item )
{
// adding a new item
if( !request.HasReadWriteAccess(*request.dir_table.back()) )
request.status = Error::permision_denied;
return;
}
// editing an existing item
if( !request.HasReadWriteAccess(request.item) )
{
request.status = Error::permision_denied;
return;
}
}

View File

@@ -1,51 +0,0 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* All rights reserved.
*
*/
#include "content.h"
void Content::PostFunLogin()
{
try
{
std::string & login = request.PostVar("login");
std::string & pass = request.PostVar("password");
long user_id;
if( db.CheckUser(login, pass, user_id) )
{
request.session->puser = data.users.GetUser(user_id);
if( !request.session->puser )
{
log << log1 << "Content: user: " << login << " is in the database but is not in data.users" << logend;
return;
}
log << log2 << "User " << login << " (id: " << user_id << ") logged" << logend;
if( request.is_item )
{
RedirectTo(request.item);
}
else
{
RedirectTo(*request.dir_table.back());
}
}
}
catch(const Error &)
{
}
}

View File

@@ -1,45 +0,0 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* All rights reserved.
*
*/
#include "content.h"
void Content::FunLogout()
{
if( request.session->puser )
{
log << log2 << "User: " << request.session->puser->name << ", id: " << request.session->puser->id << " logged out" << logend;
request.session->puser = 0;
}
request.result = Request::redirect;
std::string path;
data.dirs.MakePath(request.dir_table.back()->id, path);
request.str = data.base_url + path;
if( request.is_item )
request.str += request.item.url;
request.session->done = Done::loggedout;
request.session->done_timer = 2;
}

View File

@@ -1,47 +0,0 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* All rights reserved.
*
*/
#include "content.h"
void Content::FunLs()
{
if( request.is_item )
{
// we're showing only the item
request.item_table.push_back( request.item );
return;
}
// we're showing the whole directory
Item item_ref;
item_ref.parent_id = request.dir_table.back()->id;
// !! zrobic inna metode, inny interfejs (jako parametr niech bierze parent_id), i zeby nie odczytywala contentu i subjectu (a moze tylko subject? przyda sie przy ls -l)
db.GetItems(request.item_table, item_ref);
}

View File

@@ -1,30 +0,0 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* All rights reserved.
*
*/
#include "content.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,83 +0,0 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* All rights reserved.
*
*/
#include "content.h"
void Content::PostFunPrivileges()
{
// !! narazie tylko dla plikow
if( !request.is_item )
return;
try
{
long user_id = data.users.GetUserId( request.PostVar("user") );
long group_id = data.groups.GetGroupId( request.PostVar("group") );
int privileges = strtol( request.PostVar("privileges").c_str() , 0, 8);
if( !request.CanChangeUser(request.item, user_id) )
throw Error(Error::cant_change_user);
if( !request.CanChangeGroup(request.item, group_id) )
throw Error(Error::cant_change_group);
if( !request.CanChangePrivileges(request.item, privileges) )
throw Error(Error::cant_change_privileges);
request.item.user_id = user_id;
request.item.group_id = group_id;
request.item.privileges = privileges;
request.session->done = Done::privileged_item;
request.session->done_status = db.EditPrivById(request.item, request.item.id);
}
catch(const Error & e)
{
log << log1 << "Content: FunChmod: Error: " << e << logend;
request.session->done_status = e;
}
if( request.session->done_status == Error::ok )
{
request.session->item = request.item;
request.session->done_timer = 2;
RedirectTo(request.item);
}
else
{
log << log1 << "Content: PostFunPrivileges: Error: " << static_cast<int>(request.session->done_status) << logend;
}
}
void Content::FunPrivileges()
{
if( !request.is_item )
{
// !! chwilowi tylko dla plikow
request.status == Error::item_required;
return;
}
// you must be an owner of the item (or a superuser)
// !! moze wykorzystac request.CanChangeUser() ?
if( !request.session->puser || (!request.session->puser->super_user && request.session->puser->id != request.item.user_id) )
{
request.status = Error::permision_denied;
return;
}
}

View File

@@ -1,69 +0,0 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* All rights reserved.
*
*/
#include "content.h"
void Content::FunRm()
{
// !! narazie usuwanie tylko dla plikow
if( !request.is_item )
{
request.status = Error::permision_denied;
return;
}
if( !request.HasWriteAccess(*request.dir_table.back()) || !request.HasWriteAccess(request.item) )
{
request.status = Error::permision_denied;
return;
}
if( request.param_table.empty() )
{
// we'll put some information about the deleted item (on the next page)
request.session->item = request.item;
// !! zmienic interfejs dla db.DelItem
if( db.DelItem( request.item ) )
{
request.session->done_status = Error::ok;
log << log2 << "Content: deleted item: subject: " << request.item.subject << ", id: " << request.item.id << logend;
}
else
{
request.session->done_status = Error::db_no_item;
}
request.session->done = Done::deleted_item;
request.result = Request::redirect;
RedirectTo(*request.dir_table.back());
request.session->done_timer = 2;
}
else
{
if( request.IsParam("potwierdz") )
{
//request.result = Request::del_item_confirm;
}
else
request.result = Request::err404;
}
}

View File

@@ -1,26 +1,22 @@
o = data.o log.o sessionmanager.o requestcontroller.o dircontainer.o session.o main.o done.o request.o misc.o httpsimpleparser.o db.o error.o db_itemcolumns.o users.o config.o dirs.o groups.o function.o functionparser.o functions.o
include Makefile.o.dep
all: $(o)
all: core.a
core.a: $(o)
ar rcs core.a $(o)
.SUFFIXES: .cpp .o
.cpp.o:
$(CC) -c $(CFLAGS) $<
$(CXX) -c $(CXXFLAGS) $<
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
clean:
rm -f *.o
rm -f *.a
include Makefile.dep

View File

@@ -1,61 +1,261 @@
# DO NOT DELETE
config.o: config.h ../confparser/confparser.h error.h log.h data.h misc.h
config.o: item.h dirs.h db.h dircontainer.h user.h group.h ugcontainer.h
config.o: users.h groups.h functions.h function.h
data.o: data.h misc.h log.h item.h error.h dirs.h db.h dircontainer.h user.h
data.o: group.h ugcontainer.h users.h groups.h functions.h function.h
db.o: db.h log.h item.h misc.h error.h dircontainer.h user.h group.h
db.o: ugcontainer.h
db_itemcolumns.o: db.h log.h item.h misc.h error.h dircontainer.h user.h
db_itemcolumns.o: group.h ugcontainer.h
Kopia config.o: ../core/log.h ../core/request.h requesttypes.h session.h
Kopia config.o: item.h error.h log.h user.h plugindata.h rebus.h thread.h
Kopia config.o: compress.h acceptencodingparser.h acceptbaseparser.h
Kopia config.o: htmlfilter.h postmultiparser.h config.h confparser.h ticket.h
Kopia config.o: ../core/config.h ../core/db.h group.h dircontainer.h
Kopia config.o: ugcontainer.h
acceptbaseparser.o: acceptbaseparser.h
app.o: app.h config.h confparser.h system.h dirs.h item.h dircontainer.h db.h
app.o: user.h group.h thread.h error.h log.h ugcontainer.h ticket.h request.h
app.o: requesttypes.h session.h plugindata.h rebus.h compress.h
app.o: acceptencodingparser.h acceptbaseparser.h htmlfilter.h
app.o: postmultiparser.h mounts.h mount.h users.h lastcontainer.h groups.h
app.o: loadavg.h sessionmanager.h sessioncontainer.h notify.h
app.o: ../templatesnotify/templatesnotify.h ../../ezc/src/ezc.h
app.o: ../core/mount.h ../core/locale.h ../core/config.h ../templates/misc.h
app.o: ../templates/localefilter.h ../core/locale.h ../functions/functions.h
app.o: ../functions/functionbase.h ../core/item.h ../core/db.h
app.o: ../core/request.h ../core/system.h ../core/notify.h
app.o: ../functions/functionparser.h ../functions/adduser.h
app.o: ../functions/cat.h ../functions/chmod.h ../functions/privchanger.h
app.o: ../functions/chown.h ../functions/cp.h ../functions/createthread.h
app.o: ../functions/createticket.h ../functions/default.h
app.o: ../functions/download.h ../functions/editticket.h ../functions/emacs.h
app.o: ../functions/last.h ../functions/login.h ../functions/logout.h
app.o: ../functions/ls.h ../functions/mkdir.h ../functions/mv.h
app.o: ../functions/node.h ../functions/priv.h ../functions/reload.h
app.o: ../functions/rm.h ../functions/run.h ../functions/subject.h
app.o: ../functions/funthread.h ../core/thread.h ../functions/funticket.h
app.o: ../functions/uname.h ../functions/upload.h ../functions/who.h
app.o: ../templates/templates.h ../templates/patterncacher.h ../core/item.h
app.o: misc.h ../templates/ckeditorgetparser.h ../core/httpsimpleparser.h
app.o: ../core/log.h ../templates/indexpatterns.h ../core/sessionmanager.h
app.o: plugin.h pluginmsg.h
bbcodeparser.o: bbcodeparser.h htmlfilter.h
compress.o: compress.h log.h
config.o: config.h confparser.h log.h plugin.h pluginmsg.h plugindata.h
config.o: request.h requesttypes.h session.h item.h error.h user.h rebus.h
config.o: thread.h compress.h acceptencodingparser.h acceptbaseparser.h
config.o: htmlfilter.h postmultiparser.h ticket.h system.h dirs.h
config.o: dircontainer.h db.h group.h ugcontainer.h mounts.h mount.h users.h
config.o: lastcontainer.h groups.h loadavg.h sessionmanager.h
config.o: sessioncontainer.h ../functions/functions.h
config.o: ../functions/functionbase.h ../core/item.h ../core/db.h
config.o: ../core/request.h ../core/config.h ../core/system.h
config.o: ../core/notify.h ../../ezc/src/ezc.h ../functions/functionparser.h
config.o: ../functions/adduser.h ../functions/cat.h ../functions/chmod.h
config.o: ../functions/privchanger.h ../functions/chown.h ../functions/cp.h
config.o: ../functions/createthread.h ../functions/createticket.h
config.o: ../functions/default.h ../functions/download.h
config.o: ../functions/editticket.h ../functions/emacs.h ../functions/last.h
config.o: ../functions/login.h ../functions/logout.h ../functions/ls.h
config.o: ../functions/mkdir.h ../functions/mv.h ../functions/node.h
config.o: ../functions/priv.h ../functions/reload.h ../functions/rm.h
config.o: ../functions/run.h ../functions/subject.h ../functions/funthread.h
config.o: ../core/thread.h ../functions/funticket.h ../functions/uname.h
config.o: ../functions/upload.h ../functions/who.h ../templates/templates.h
config.o: ../templates/patterncacher.h ../core/item.h misc.h
config.o: ../templates/ckeditorgetparser.h ../core/httpsimpleparser.h
config.o: ../core/log.h ../templates/indexpatterns.h
config.o: ../templates/localefilter.h ../core/locale.h ../core/locale.h
config.o: ../core/sessionmanager.h
confparser.o: confparser.h misc.h item.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 error.h log.h db.h misc.h dircontainer.h user.h group.h
dirs.o: ugcontainer.h
done.o: done.h
error.o: error.h log.h
function.o: function.h log.h item.h
functionparser.o: functionparser.h request.h requesttypes.h log.h session.h
functionparser.o: error.h item.h done.h user.h getparser.h httpsimpleparser.h
functionparser.o: postparser.h cookieparser.h function.h data.h misc.h dirs.h
functionparser.o: db.h dircontainer.h group.h ugcontainer.h users.h groups.h
functionparser.o: functions.h
functions.o: functions.h function.h log.h item.h
groups.o: groups.h group.h db.h log.h item.h misc.h error.h dircontainer.h
groups.o: user.h ugcontainer.h
dirs.o: dirs.h item.h dircontainer.h db.h user.h group.h thread.h error.h
dirs.o: log.h ugcontainer.h ticket.h request.h requesttypes.h session.h
dirs.o: plugindata.h rebus.h compress.h acceptencodingparser.h
dirs.o: acceptbaseparser.h htmlfilter.h postmultiparser.h config.h
dirs.o: confparser.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
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.h log.h
log.o: log.h
main.o: requestcontroller.h data.h misc.h log.h item.h error.h dirs.h db.h
main.o: dircontainer.h user.h group.h ugcontainer.h users.h groups.h
main.o: functions.h function.h request.h requesttypes.h session.h done.h
main.o: getparser.h httpsimpleparser.h postparser.h cookieparser.h
main.o: ../content/content.h ../templates/templates.h ../../ezc/src/ezc.h
main.o: ../core/data.h ../core/request.h ../core/item.h ../core/db.h
main.o: ../core/error.h ../core/user.h ../core/group.h ../core/users.h
main.o: ../core/groups.h ../core/log.h ../core/misc.h ../core/function.h
main.o: ../core/functionparser.h sessionmanager.h config.h
main.o: ../confparser/confparser.h
misc.o: misc.h log.h item.h
request.o: request.h requesttypes.h log.h session.h error.h item.h done.h
request.o: user.h getparser.h httpsimpleparser.h postparser.h cookieparser.h
request.o: function.h
requestcontroller.o: requestcontroller.h data.h misc.h log.h item.h error.h
requestcontroller.o: dirs.h db.h dircontainer.h user.h group.h ugcontainer.h
requestcontroller.o: users.h groups.h functions.h function.h request.h
requestcontroller.o: requesttypes.h session.h done.h getparser.h
requestcontroller.o: httpsimpleparser.h postparser.h cookieparser.h
requestcontroller.o: ../content/content.h ../templates/templates.h
requestcontroller.o: ../../ezc/src/ezc.h ../core/data.h ../core/request.h
requestcontroller.o: ../core/item.h ../core/db.h ../core/error.h
requestcontroller.o: ../core/user.h ../core/group.h ../core/users.h
requestcontroller.o: ../core/groups.h ../core/log.h ../core/misc.h
requestcontroller.o: ../core/function.h ../core/functionparser.h
requestcontroller.o: sessionmanager.h
session.o: session.h requesttypes.h error.h log.h item.h done.h user.h
sessionmanager.o: sessionmanager.h request.h requesttypes.h log.h session.h
sessionmanager.o: error.h item.h done.h user.h getparser.h httpsimpleparser.h
sessionmanager.o: postparser.h cookieparser.h function.h data.h misc.h dirs.h
sessionmanager.o: db.h dircontainer.h group.h ugcontainer.h users.h groups.h
sessionmanager.o: functions.h
users.o: users.h user.h db.h log.h item.h misc.h error.h dircontainer.h
users.o: group.h ugcontainer.h
misc.o: misc.h item.h log.h
mount.o: mount.h
mountparser.o: mountparser.h mount.h item.h error.h log.h dirs.h
mountparser.o: dircontainer.h db.h user.h group.h thread.h ugcontainer.h
mountparser.o: ticket.h request.h requesttypes.h session.h plugindata.h
mountparser.o: rebus.h compress.h acceptencodingparser.h acceptbaseparser.h
mountparser.o: htmlfilter.h postmultiparser.h config.h confparser.h misc.h
mounts.o: mounts.h mount.h error.h log.h dirs.h item.h dircontainer.h db.h
mounts.o: user.h group.h thread.h ugcontainer.h ticket.h request.h
mounts.o: requesttypes.h session.h plugindata.h rebus.h compress.h
mounts.o: acceptencodingparser.h acceptbaseparser.h htmlfilter.h
mounts.o: postmultiparser.h config.h confparser.h mountparser.h
notify.o: log.h notify.h ../templatesnotify/templatesnotify.h
notify.o: ../../ezc/src/ezc.h ../core/mount.h ../core/locale.h confparser.h
notify.o: ../core/config.h ../templates/misc.h ../templates/localefilter.h
notify.o: ../core/locale.h request.h requesttypes.h session.h item.h error.h
notify.o: user.h plugindata.h rebus.h thread.h compress.h
notify.o: acceptencodingparser.h acceptbaseparser.h htmlfilter.h
notify.o: postmultiparser.h config.h ticket.h system.h dirs.h dircontainer.h
notify.o: db.h group.h ugcontainer.h mounts.h mount.h users.h lastcontainer.h
notify.o: groups.h loadavg.h misc.h
plugin.o: plugin.h pluginmsg.h log.h plugindata.h config.h confparser.h
plugin.o: request.h requesttypes.h session.h item.h error.h user.h rebus.h
plugin.o: thread.h compress.h acceptencodingparser.h acceptbaseparser.h
plugin.o: htmlfilter.h postmultiparser.h ticket.h system.h dirs.h
plugin.o: dircontainer.h db.h group.h ugcontainer.h mounts.h mount.h users.h
plugin.o: lastcontainer.h groups.h loadavg.h sessionmanager.h
plugin.o: sessioncontainer.h ../functions/functions.h
plugin.o: ../functions/functionbase.h ../core/item.h ../core/db.h
plugin.o: ../core/request.h ../core/config.h ../core/system.h
plugin.o: ../core/notify.h ../../ezc/src/ezc.h ../functions/functionparser.h
plugin.o: ../functions/adduser.h ../functions/cat.h ../functions/chmod.h
plugin.o: ../functions/privchanger.h ../functions/chown.h ../functions/cp.h
plugin.o: ../functions/createthread.h ../functions/createticket.h
plugin.o: ../functions/default.h ../functions/download.h
plugin.o: ../functions/editticket.h ../functions/emacs.h ../functions/last.h
plugin.o: ../functions/login.h ../functions/logout.h ../functions/ls.h
plugin.o: ../functions/mkdir.h ../functions/mv.h ../functions/node.h
plugin.o: ../functions/priv.h ../functions/reload.h ../functions/rm.h
plugin.o: ../functions/run.h ../functions/subject.h ../functions/funthread.h
plugin.o: ../core/thread.h ../functions/funticket.h ../functions/uname.h
plugin.o: ../functions/upload.h ../functions/who.h ../templates/templates.h
plugin.o: ../templates/patterncacher.h ../core/item.h misc.h
plugin.o: ../templates/ckeditorgetparser.h ../core/httpsimpleparser.h
plugin.o: ../core/log.h ../templates/indexpatterns.h
plugin.o: ../templates/localefilter.h ../core/locale.h ../core/locale.h
plugin.o: ../core/sessionmanager.h
plugindata.o: plugindata.h plugin.h pluginmsg.h log.h config.h confparser.h
plugindata.o: request.h requesttypes.h session.h item.h error.h user.h
plugindata.o: rebus.h thread.h compress.h acceptencodingparser.h
plugindata.o: acceptbaseparser.h htmlfilter.h postmultiparser.h ticket.h
plugindata.o: system.h dirs.h dircontainer.h db.h group.h ugcontainer.h
plugindata.o: mounts.h mount.h users.h lastcontainer.h groups.h loadavg.h
plugindata.o: sessionmanager.h sessioncontainer.h ../functions/functions.h
plugindata.o: ../functions/functionbase.h ../core/item.h ../core/db.h
plugindata.o: ../core/request.h ../core/config.h ../core/system.h
plugindata.o: ../core/notify.h ../../ezc/src/ezc.h
plugindata.o: ../functions/functionparser.h ../functions/adduser.h
plugindata.o: ../functions/cat.h ../functions/chmod.h
plugindata.o: ../functions/privchanger.h ../functions/chown.h
plugindata.o: ../functions/cp.h ../functions/createthread.h
plugindata.o: ../functions/createticket.h ../functions/default.h
plugindata.o: ../functions/download.h ../functions/editticket.h
plugindata.o: ../functions/emacs.h ../functions/last.h ../functions/login.h
plugindata.o: ../functions/logout.h ../functions/ls.h ../functions/mkdir.h
plugindata.o: ../functions/mv.h ../functions/node.h ../functions/priv.h
plugindata.o: ../functions/reload.h ../functions/rm.h ../functions/run.h
plugindata.o: ../functions/subject.h ../functions/funthread.h
plugindata.o: ../core/thread.h ../functions/funticket.h ../functions/uname.h
plugindata.o: ../functions/upload.h ../functions/who.h
plugindata.o: ../templates/templates.h ../templates/patterncacher.h
plugindata.o: ../core/item.h misc.h ../templates/ckeditorgetparser.h
plugindata.o: ../core/httpsimpleparser.h ../core/log.h
plugindata.o: ../templates/indexpatterns.h ../templates/localefilter.h
plugindata.o: ../core/locale.h ../core/locale.h ../core/sessionmanager.h
postmultiparser.o: postmultiparser.h error.h log.h requesttypes.h config.h
postmultiparser.o: confparser.h
rebus.o: log.h rebus.h misc.h item.h request.h requesttypes.h session.h
rebus.o: error.h user.h plugindata.h thread.h compress.h
rebus.o: acceptencodingparser.h acceptbaseparser.h htmlfilter.h
rebus.o: postmultiparser.h config.h confparser.h ticket.h
request.o: request.h requesttypes.h session.h item.h error.h log.h user.h
request.o: plugindata.h rebus.h thread.h compress.h acceptencodingparser.h
request.o: acceptbaseparser.h htmlfilter.h postmultiparser.h config.h
request.o: confparser.h ticket.h getparser.h httpsimpleparser.h postparser.h
request.o: cookieparser.h plugin.h pluginmsg.h system.h dirs.h dircontainer.h
request.o: db.h group.h ugcontainer.h mounts.h mount.h users.h
request.o: lastcontainer.h groups.h loadavg.h sessionmanager.h
request.o: sessioncontainer.h ../functions/functions.h
request.o: ../functions/functionbase.h ../core/item.h ../core/db.h
request.o: ../core/request.h ../core/config.h ../core/system.h
request.o: ../core/notify.h ../../ezc/src/ezc.h ../functions/functionparser.h
request.o: ../functions/adduser.h ../functions/cat.h ../functions/chmod.h
request.o: ../functions/privchanger.h ../functions/chown.h ../functions/cp.h
request.o: ../functions/createthread.h ../functions/createticket.h
request.o: ../functions/default.h ../functions/download.h
request.o: ../functions/editticket.h ../functions/emacs.h ../functions/last.h
request.o: ../functions/login.h ../functions/logout.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/subject.h ../functions/funthread.h
request.o: ../core/thread.h ../functions/funticket.h ../functions/uname.h
request.o: ../functions/upload.h ../functions/who.h ../templates/templates.h
request.o: ../templates/patterncacher.h ../core/item.h misc.h
request.o: ../templates/ckeditorgetparser.h ../core/httpsimpleparser.h
request.o: ../core/log.h ../templates/indexpatterns.h
request.o: ../templates/localefilter.h ../core/locale.h ../core/locale.h
request.o: ../core/sessionmanager.h ../functions/functionbase.h
session.o: session.h item.h error.h log.h user.h plugindata.h rebus.h
sessioncontainer.o: sessioncontainer.h session.h item.h error.h log.h user.h
sessioncontainer.o: plugindata.h rebus.h lastcontainer.h
sessionmanager.o: sessionmanager.h sessioncontainer.h session.h item.h
sessionmanager.o: error.h log.h user.h plugindata.h rebus.h lastcontainer.h
sessionmanager.o: config.h confparser.h request.h requesttypes.h thread.h
sessionmanager.o: compress.h acceptencodingparser.h acceptbaseparser.h
sessionmanager.o: htmlfilter.h postmultiparser.h ticket.h system.h dirs.h
sessionmanager.o: dircontainer.h db.h group.h ugcontainer.h mounts.h mount.h
sessionmanager.o: users.h groups.h loadavg.h sessionparser.h plugin.h
sessionmanager.o: pluginmsg.h ../functions/functions.h
sessionmanager.o: ../functions/functionbase.h ../core/item.h ../core/db.h
sessionmanager.o: ../core/request.h ../core/config.h ../core/system.h
sessionmanager.o: ../core/notify.h ../../ezc/src/ezc.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/cp.h ../functions/createthread.h
sessionmanager.o: ../functions/createticket.h ../functions/default.h
sessionmanager.o: ../functions/download.h ../functions/editticket.h
sessionmanager.o: ../functions/emacs.h ../functions/last.h
sessionmanager.o: ../functions/login.h ../functions/logout.h
sessionmanager.o: ../functions/ls.h ../functions/mkdir.h ../functions/mv.h
sessionmanager.o: ../functions/node.h ../functions/priv.h
sessionmanager.o: ../functions/reload.h ../functions/rm.h ../functions/run.h
sessionmanager.o: ../functions/subject.h ../functions/funthread.h
sessionmanager.o: ../core/thread.h ../functions/funticket.h
sessionmanager.o: ../functions/uname.h ../functions/upload.h
sessionmanager.o: ../functions/who.h ../templates/templates.h
sessionmanager.o: ../templates/patterncacher.h ../core/item.h misc.h
sessionmanager.o: ../templates/ckeditorgetparser.h ../core/httpsimpleparser.h
sessionmanager.o: ../core/log.h ../templates/indexpatterns.h
sessionmanager.o: ../templates/localefilter.h ../core/locale.h
sessionmanager.o: ../core/locale.h ../core/sessionmanager.h
sessionparser.o: sessionparser.h session.h item.h error.h log.h user.h
sessionparser.o: plugindata.h rebus.h sessioncontainer.h lastcontainer.h
sessionparser.o: users.h ugcontainer.h request.h requesttypes.h thread.h
sessionparser.o: compress.h acceptencodingparser.h acceptbaseparser.h
sessionparser.o: htmlfilter.h postmultiparser.h config.h confparser.h
sessionparser.o: ticket.h db.h group.h dircontainer.h
system.o: system.h dirs.h item.h dircontainer.h db.h user.h group.h thread.h
system.o: error.h log.h ugcontainer.h ticket.h request.h requesttypes.h
system.o: session.h plugindata.h rebus.h compress.h acceptencodingparser.h
system.o: acceptbaseparser.h htmlfilter.h postmultiparser.h config.h
system.o: confparser.h mounts.h mount.h users.h lastcontainer.h groups.h
system.o: loadavg.h misc.h notify.h ../templatesnotify/templatesnotify.h
system.o: ../../ezc/src/ezc.h ../core/mount.h ../core/locale.h
system.o: ../core/config.h ../templates/misc.h ../templates/localefilter.h
system.o: ../core/locale.h ../functions/functions.h
system.o: ../functions/functionbase.h ../core/item.h ../core/db.h
system.o: ../core/request.h ../core/system.h ../core/notify.h
system.o: ../functions/functionparser.h ../functions/adduser.h
system.o: ../functions/cat.h ../functions/chmod.h ../functions/privchanger.h
system.o: ../functions/chown.h ../functions/cp.h ../functions/createthread.h
system.o: ../functions/createticket.h ../functions/default.h
system.o: ../functions/download.h ../functions/editticket.h
system.o: ../functions/emacs.h ../functions/last.h ../functions/login.h
system.o: ../functions/logout.h ../functions/ls.h ../functions/mkdir.h
system.o: ../functions/mv.h ../functions/node.h ../functions/priv.h
system.o: ../functions/reload.h ../functions/rm.h ../functions/run.h
system.o: ../functions/subject.h ../functions/funthread.h ../core/thread.h
system.o: ../functions/funticket.h ../functions/uname.h ../functions/upload.h
system.o: ../functions/who.h ../templates/templates.h
system.o: ../templates/patterncacher.h ../core/item.h
system.o: ../templates/ckeditorgetparser.h ../core/httpsimpleparser.h
system.o: ../core/log.h ../templates/indexpatterns.h ../core/sessionmanager.h
users.o: users.h user.h ugcontainer.h log.h lastcontainer.h request.h
users.o: requesttypes.h session.h item.h error.h plugindata.h rebus.h
users.o: thread.h compress.h acceptencodingparser.h acceptbaseparser.h
users.o: htmlfilter.h postmultiparser.h config.h confparser.h ticket.h db.h
users.o: group.h dircontainer.h

1
core/Makefile.o.dep Executable file
View File

@@ -0,0 +1 @@
o = Kopia config.o acceptbaseparser.o app.o bbcodeparser.o compress.o config.o confparser.o db.o db_itemcolumns.o dircontainer.o dirs.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 session.o sessioncontainer.o sessionmanager.o sessionparser.o system.o users.o

113
core/acceptbaseparser.cpp Executable file
View File

@@ -0,0 +1,113 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "acceptbaseparser.h"
bool AcceptBaseParser::IsWhite(int c)
{
if( c==' ' || c=='\t' )
return true;
return false;
}
void AcceptBaseParser::SkipWhite()
{
while( IsWhite(*text) )
++text;
}
void AcceptBaseParser::RemoveWhiteFromEnd(std::string & str)
{
if( str.empty() )
return;
size_t i = str.size() - 1;
for( ; i!=0 && IsWhite(str[i]) ; --i);
if( !IsWhite(str[i]) )
++i;
if( i < str.size() )
str.erase(i); // erasing until the end of the string
}
void AcceptBaseParser::ReadParameter()
{
param.clear();
SkipWhite();
while( *text!=0 && *text!=',' && *text!=';' )
{
param += *text;
++text;
}
RemoveWhiteFromEnd(param);
}
void AcceptBaseParser::ReadQ()
{
q = 1.0;
SkipWhite();
if( *text != ';' )
return;
++text; // skipping a semicolon
while( *text!=0 && *text!=',' && *text!='=' )
// skipping until ',' or '='
++text;
if( *text==0 || *text==',' )
return;
++text; // skipping '='
SkipWhite();
q = strtod(text, (char**)&text);
}
void AcceptBaseParser::SkipParam()
{
SkipWhite();
if( *text == ',' )
++text;
}
void AcceptBaseParser::Parse(const char * str)
{
text = str;
Init();
while( *text != 0 )
{
ReadParameter();
ReadQ();
SkipParam();
Param(param, q);
}
}

47
core/acceptbaseparser.h Executable file
View File

@@ -0,0 +1,47 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslucoreacceptbaseparser
#define headerfilecmslucoreacceptbaseparser
#include <string>
// sample (you must create your own class derived from this one):
// object.Parse(" text/html ; , ; q = 45, application / xhtml+xml ; q = 0.4 , application/xml ; q = 0.9 , */* ; q = 0.8 ");
class AcceptBaseParser
{
public:
void Parse(const char * str);
private:
virtual void Init() {} ;
virtual void Param(const std::string & param, double q) = 0;
bool IsWhite(int c);
void SkipWhite();
void RemoveWhiteFromEnd(std::string & str);
void ReadParameter();
void ReadQ();
void SkipParam();
const char * text;
std::string param;
double q;
};
#endif

49
core/acceptencodingparser.h Executable file
View File

@@ -0,0 +1,49 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslucoreacceptencodingparser
#define headerfilecmslucoreacceptencodingparser
#include "acceptbaseparser.h"
#include "log.h"
class AcceptEncodingParser : public AcceptBaseParser
{
public:
bool AcceptDeflate()
{
return accept_deflate;
}
private:
void Init()
{
accept_deflate = false;
}
void Param(const std::string & param, double q)
{
if( param=="deflate" && q!=0 )
{
accept_deflate = true;
log << log3 << "AEP: accept deflate" << logend;
}
}
bool accept_deflate;
};
#endif

398
core/app.cpp Executable file
View File

@@ -0,0 +1,398 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "app.h"
#include "plugin.h"
App::App()
{
stdout_is_closed = false;
last_sessions_save = time(0);
plugin.SetDb(&db);
plugin.SetConfig(&config);
plugin.SetRequest(&request);
plugin.SetSystem(&system);
plugin.SetFunctions(&functions);
plugin.SetTemplates(&templates);
plugin.SetSessionManager(&session_manager);
request.SetConfig(&config);
functions.SetConfig(&config);
functions.SetRequest(&request);
functions.SetDb(&db);
functions.SetSystem(&system);
functions.SetTemplates(&templates);
functions.SetNotify(&notify);
system.SetConfig(&config);
system.SetRequest(&request);
system.SetDb(&db);
system.SetFunctions(&functions); // !! czy model musi cos wiedziec o funkcjach?
system.SetTemplates(&templates);
templates_notify.SetConfig(&config);
notify.SetRequest(&request);
notify.SetConfig(&config);
notify.SetSystem(&system);
notify.SetTemplatesNotify(&templates_notify);
templates.SetConfig(&config);
templates.SetRequest(&request);
templates.SetDb(&db);
templates.SetSystem(&system);
templates.SetFunctions(&functions);
templates.SetSessionManager(&session_manager);
session_manager.SetLastContainer(&system.users.last);
session_manager.SetConfig(&config);
session_manager.SetRequest(&request);
session_manager.SetSystem(&system);
}
bool App::CreateFCGISocket()
{
const char * sock = config.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, config.fcgi_socket_chmod);
passwd * pw = getpwnam(config.fcgi_socket_user.c_str());
if( !pw )
{
log << log1 << "There is no user: " << config.fcgi_socket_user << logend;
return false;
}
group * gr = getgrnam(config.fcgi_socket_group.c_str());
if( !gr )
{
log << log1 << "There is no group: " << config.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: " << config.fcgi_socket_user << logend;
return false;
}
/*
if( setgid(gr->gr_gid) < 0 )
{
int e = errno;
log << log1 << "I can't change the group into: " << config.fcgi_socket_group << " " << gr->gr_gid << logend;
log << log1 << "errno: " << e << logend;
return false;
}
*/
dup2(s, 0);
return true;
}
bool App::Init()
{
request.Init();
if( !CreateFCGISocket() )
return false;
system.Init();
functions.Create();
// !! teraz mamy dwa katalogi z templetami
// !! o co chodzilo?
if( !notify.Init() )
return false;
templates.ReadIndexFileNames();
templates.ReadTemplates();
templates.CreateFunctions();
session_manager.LoadSessions();
return true;
}
void App::Close()
{
session_manager.SaveSessions();
session_manager.DeleteAllPluginsData();
}
bool App::BaseUrlRedirect()
{
if( request.role == Request::responder )
{
if( config.base_url_http_host.empty() )
return false;
if( config.base_url_http_host == request.env_http_host )
return false;
request.redirect_to = config.base_url + request.env_request_uri;
}
else
{
// authorizer
if( config.base_url_auth_http_host.empty() )
return false;
if( config.base_url_auth_http_host == request.env_http_host )
return false;
request.redirect_to = config.base_url_auth + request.env_request_uri;
}
log << log3 << "RC: BaseUrlRedirect from: " << request.env_http_host << logend;
return true;
}
void App::ProcessRequest()
{
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
// !! tutaj dodac to ustawianie request.session
functions.Parse();
system.mounts.CalcCurMount();
ReadAdditionalInfo();
Make();
}
request.SendAll(); // !! czemu request sam sie chce wyslac? wrzucic to tutaj do app
notify.ItemChanged(request.notify_code);
}
void App::Start()
{
while( FCGX_Accept(&request.in, &request.out, &request.err, &request.env) == 0 )
{
system.load_avg.StartRequest();
log << log2 << "---------------------------------------------------------------------------------" << logend;
try
{
ProcessRequest();
}
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( signal_hup )
if( false )
{
log << logsave;
FCGX_Finish();
return;
}
request.ClearPostFileTmp();
system.load_avg.StopRequest();
log << logsave;
}
}
void App::SaveSessionsIfNeeded()
{
time_t t = time(0);
if( last_sessions_save + 86400 > t )
return;
// saving once a day for safety
last_sessions_save = t;
session_manager.SaveSessions();
}
// !! zmienic na lepsza nazwe
void App::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->fun.url == "cat" )
{
request.page << request.item.content;
sent = true;
}
else
if( request.pfunction->fun.url == "run" )
{
templates.GenerateRunRaw();
sent = true;
}
}
if( !sent )
{
templates.Generate();
}
}
void App::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( system.DirsHaveReadExecPerm() )
{
if( request.method == Request::post )
functions.MakePost();
if( request.redirect_to.empty() && request.status == WINIX_ERR_OK )
functions.MakeGet();
}
else
request.status = WINIX_ERR_PERMISSION_DENIED;
}
if( request.session->spam_score > 0 )
log << log1 << "App: 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 << "App: there is no a root dir (dir_table is empty -- after calling a function)" << logend;
return;
}
plugin.Call(WINIX_CONTENT_MAKE);
MakePage();
// !! dodac parametr do konfiga wlaczajacy te informacje
//request->PrintGetTable();
//request->PrintEnv();
//request->PrintIn();
}
// !! dac lepsza nazwe i czy napewno w app to ma byc?
void App::ReadAdditionalInfo()
{
if( request.dir_table.empty() )
return;
if( system.mounts.pmount->type == Mount::thread )
{
if( db.GetThreadByDirId(request.dir_table.back()->id, request.thread) == WINIX_ERR_OK )
request.is_thread = true;
}
else
if( system.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->fun.url == "ticket") )
{
db.GetItemById(request.ticket.item_id, request.item);
// don't set request->is_item here
}
}
}
}

111
core/app.h Executable file
View File

@@ -0,0 +1,111 @@
/*
* 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 "config.h"
#include "system.h"
#include "mounts.h"
#include "request.h"
#include "sessionmanager.h"
#include "notify.h"
#include "db.h"
#include "functions/functions.h"
#include "templates/templates.h"
#include "templatesnotify/templatesnotify.h"
class App
{
public:
App();
bool Init();
void Start();
void Close();
// configuration read from a config file
Config config;
// current request
Request request;
// users sessions
SessionManager session_manager;
// notifications (by emails)
Notify notify;
// database
Db db;
/*
model
*/
// file system
System system;
// false at the beginning
bool stdout_is_closed;
/*
controller
*/
// functions (ls, cat, emacs, ...)
Functions functions;
/*
view
*/
Templates templates;
TemplatesNotify templates_notify;
private:
bool CreateFCGISocket();
void ProcessRequest();
bool BaseUrlRedirect();
void DeleteAllPluginsData();
void MakePage();
void Make();
void ReadAdditionalInfo();
void SaveSessionsIfNeeded(); // !! wywalic do managara sesji??
// !! dodac do session managera?
time_t last_sessions_save;
};
#endif

566
core/bbcodeparser.cpp Executable file
View File

@@ -0,0 +1,566 @@
/*
* 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::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 char * str, const char * 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) += "<br>\n";
}
}
else
{
PrintEscape(*str);
++str;
}
}
}
void BBCODEParser::PutNormalTextTrim(const char * str, const char * end)
{
// we don't use trimming in bbcode parser
PutNormalText(str, end);
}
void BBCODEParser::ReadNormalTextSkipWhite(const char * & start, const char * & 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("*", pstack[stack_len-1].name) &&
IsNameEqual("*", 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 char * tag)
{
static Tags tags[] = {
{"*", "li", ">", false},
{"b", "em", ">", true},
{"i", "span", " class=\"bbitalic\">", true},
{"u", "span", " class=\"bbunderline\">", true},
{"s", "span", " class=\"bbstrike\">", true},
{"code", "code", " class=\"bbcode\">", false},
{"list", "ul", " class=\"bblist\">", false},
{"color", "span", " class=\"bbcol%1\">", true},
{"url", "a", " href=\"%u1\">", true},
{"img", "img", " alt=\"%1\" src=\"%u2\">", true},
{"quote", "div", " 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( strcmp(tag, tags[i].bbcode) == 0 )
return &tags[i];
}
return 0;
}
void BBCODEParser::PrintArgumentCheckQuotes(const char * & start, const char * & 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) += "&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
{
char buffer[20];
sprintf(buffer, "%02X", c);
(*out_string) += '%';
(*out_string) += buffer;
}
}
void BBCODEParser::PrintEscape(int c, bool change_quote)
{
if( c == '<' )
{
(*out_string) += "&lt;";
}
else
if( c == '>' )
{
(*out_string) += "&gt;";
}
else
if( c == '&' )
{
(*out_string) += "&amp;";
}
else
if( c == '\"' && change_quote )
{
(*out_string) += "&quot;";
}
else
{
(*out_string) += c;
}
}
void BBCODEParser::PrintArgumentEncode(const char * start, const char * end)
{
PrintArgumentCheckQuotes(start, end);
TrimWhiteWithNewLines(start, end);
for( ; start<end ; ++start )
PrintEncode(*start);
}
void BBCODEParser::PrintArgumentEscape(const char * start, const char * end)
{
PrintArgumentCheckQuotes(start, end);
for( ; start<end ; ++start )
PrintEscape(*start, true); // quotes are escaped as well here
}
void BBCODEParser::CheckOpeningTag(const Tags * tag, const char * tag_name, bool & condition)
{
if( strcmp(tag->html_tag, tag_name) == 0 )
{
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, "li", has_open_li_tag);
CheckOpeningTag(tag, "ul", has_open_ul_tag);
CheckOpeningTag(tag, "ol", has_open_ol_tag);
if( has_open_li_tag && !has_list_tag )
{
(*out_string) += "<ul>\n";
has_open_ul_tag = true;
}
}
void BBCODEParser::PrintEscape(const char * start, const char * end, bool change_quote)
{
for( ; start < end ; ++start)
PrintEscape(*start, change_quote);
}
void BBCODEParser::PrintEncode(const char * start, const char * end)
{
for( ; start < end ; ++start)
PrintEncode(*start);
}
void BBCODEParser::PutOpeningTagFromEzc(const char * start, const char * 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 char * arg_start, const char * arg_end, bool has_u)
{
if( has_u )
PrintArgumentEncode(arg_start, arg_end);
else
PrintArgumentEscape(arg_start, arg_end);
}
void BBCODEParser::TrimWhiteWithNewLines(const char * & start, const char * & 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 char * start = pchar;
const char * 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 char * arg_start, const char * arg_end)
{
const char * 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 char * start, const char * end)
{
CheckOpeningTag(tag);
PutOpeningTagMark();
(*out_string) += tag->html_tag;
PutHtmlArgument(tag, start, end);
if( !tag->inline_tag )
{
(*out_string) += "\n";
SkipWhiteLines();
}
}
void BBCODEParser::PutOpeningTag(const char * start, const char * 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) += "\n";
SkipWhiteLines();
}
if( strcmp(tag->html_tag, "li") == 0 )
has_open_li_tag = false;
if( strcmp(tag->html_tag, "ol") == 0 )
has_open_ol_tag = false;
if( strcmp(tag->html_tag, "ul") == 0 )
has_open_ul_tag = false;
}
void BBCODEParser::PutClosingTag(const char * 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) += "</li>\n";
if( has_open_ol_tag )
(*out_string) += "</ol>\n";
if( has_open_ul_tag )
(*out_string) += "</ul>\n";
}

95
core/bbcodeparser.h Executable file
View File

@@ -0,0 +1,95 @@
/*
* 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 char * bbcode;
const char * html_tag;
const char * html_arg_prefix;
const char * html_arg_postfix;
const char * additional_html_tag_prefix;
const char * additional_html_tag_postfix;
bool inline_tag;
*/
const char * bbcode;
const char * html_tag;
const char * html_argument; // with closing '>'
bool inline_tag;
};
virtual bool IsValidCharForName(int c);
virtual bool IsOpeningTagMark();
virtual bool IsOpeningCommentaryTagMark();
virtual bool SkipCommentaryTagIfExists();
virtual bool IsClosingTagMark();
virtual bool IsClosingXmlSimpleTagMark();
void PutHtmlArgument1(const char * arg_start, const char * arg_end, bool has_u);
void PutHtmlArgument2(const Tags * tag, bool has_u);
void PutHtmlArgument(const Tags * tag, const char * arg_start, const char * arg_end);
void PutOpeningTagFromEzc(const char * start, const char * end);
void PutOpeningTagFromBBCode(const Tags * tag, const char * start, const char * end);
virtual void PutOpeningTag(const char * start, const char * end);
virtual void PutClosingTag(const char * tag);
const Tags * FindTag(const char * tag);
void PrintArgumentCheckQuotes(const char * & start, const char * & end);
void PrintEscape(int c, bool change_quote = false);
void PrintEncode(int c);
void PrintEscape(const char * start, const char * end, bool change_quote = false);
void PrintEncode(const char * start, const char * end);
void PrintArgumentEncode(const char * start, const char * end);
void PrintArgumentEscape(const char * start, const char * end);
virtual void ReadNormalTextSkipWhite(const char * & start, const char * & last_non_white);
virtual void PutNormalText(const char * str, const char * end);
virtual void PutNormalTextTrim(const char * str, const char * end);
virtual void CheckExceptions();
virtual void Init();
virtual void Deinit();
void PutClosingTag(const Tags * tag);
void CheckOpeningTag(const Tags * tag, const char * tag_name, bool & condition);
void CheckOpeningTag(const Tags * tag);
void TrimWhiteWithNewLines(const char * & start, const char * & 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

175
core/compress.cpp Executable file
View File

@@ -0,0 +1,175 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "compress.h"
#include "log.h"
Compress::Compress()
{
buffer = 0;
buffer_max_len = 65536; // 64KB
ready_for_compress = false;
}
Compress::~Compress()
{
if( buffer )
delete [] buffer;
}
bool Compress::AllocateMemory()
{
if( buffer )
delete [] buffer;
try
{
buffer = new char[buffer_max_len];
}
catch(const std::bad_alloc &)
{
log << log1 << "Compress: can't allocate memory" << logend;
buffer = 0;
return false;
}
return true;
}
/*
return:
0 - ok;
1 - can't allocate memory
100 - unknown
*/
int Compress::Init(int compress_level)
{
if( buffer == 0 )
if( !AllocateMemory() )
return 1;
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
int ret = deflateInit(&strm, compress_level);
if( ret != Z_OK )
log << log1 << "Compress: problem with deflateInit()" << logend;
if( ret == Z_MEM_ERROR )
return 1;
if( ret != Z_OK )
return 100;
ready_for_compress = true;
return 0;
}
int Compress::MakeCompress(const char * source, size_t source_len, FCGX_Stream * out_stream)
{
int ret, flush;
size_t have;
do
{
strm.avail_in = (source_len > buffer_max_len) ? buffer_max_len : source_len;
source_len -= strm.avail_in;
flush = (source_len == 0) ? Z_FINISH : Z_NO_FLUSH;
strm.next_in = (Bytef*)source;
source += strm.avail_in;
do
{
strm.avail_out = buffer_max_len;
strm.next_out = (Bytef*)buffer;
ret = deflate(&strm, flush);
if( ret == Z_STREAM_ERROR || ret == Z_BUF_ERROR )
{
log << log1 << "Compress: problem with deflate()" << logend;
return 2;
}
have = buffer_max_len - strm.avail_out;
last_out_size += have;
FCGX_PutStr(buffer, have, out_stream);
}
while( strm.avail_out == 0 );
if( strm.avail_in != 0 )
{
log << log1 << "Compress: problem with deflate() - not all input is used" << logend;
return 2;
}
}
while( flush != Z_FINISH );
if( ret != Z_STREAM_END )
{
log << log1 << "Compress: problem with deflate() - stream not complete" << logend;
return 2;
}
return 0;
}
/*
return:
0 - ok;
1 - can't allocate memory
2 - error during compressing
3 - not inited (use Init() first)
100 - unknown
*/
int Compress::CompressAndPut(const char * source, size_t source_len, FCGX_Stream * out_stream, int level)
{
int ret;
last_out_size = 0;
if( !ready_for_compress )
{
log << log1 << "Compress: not ready yet" << logend;
return 3;
}
if( source_len == 0 )
return 0;
ret = MakeCompress(source, source_len, out_stream);
if( deflateReset(&strm) != Z_OK )
log << log1 << "Compress: problem with deflateReset()" << logend;
double ratio = 100.0 - (double(last_out_size) / double(source_len) * 100.0);
char buffer[30];
sprintf(buffer, "%.1f", ratio);
log << log2 << "Compress: original size: " << source_len << ", compress size: " << (int)last_out_size << ", ratio: " << buffer << "%" << logend;
return ret;
}

43
core/compress.h Executable file
View File

@@ -0,0 +1,43 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslucorecompress
#define headerfilecmslucorecompress
#include <cstring>
#include <fcgiapp.h>
#include <zlib.h>
class Compress
{
public:
Compress();
~Compress();
int Init(int compress_level = 6);
int CompressAndPut(const char * source, size_t source_len, FCGX_Stream * out_stream, int level = 6);
size_t last_out_size;
private:
bool AllocateMemory();
int MakeCompress(const char * source, size_t source_len, FCGX_Stream * out_stream);
size_t buffer_max_len;
char * buffer;
z_stream strm;
bool ready_for_compress;
};
#endif

View File

@@ -1,20 +1,21 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "config.h"
#include "log.h"
#include "plugin.h"
#include "misc.h"
Config::Config()
{
default_int = 0;
default_bool = false;
errors_to_stdout = true;
}
@@ -27,7 +28,7 @@ Config::Config()
void Config::ShowError()
{
switch( conf_parser.status )
switch( parser.status )
{
case ConfParser::ok:
log << log2 << "Config: syntax ok" << logend;
@@ -35,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;
}
}
@@ -54,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;
@@ -66,14 +67,14 @@ 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);
ConfParser::Status status = parser.Parse( config_file );
if( status == ConfParser::ok )
{
AssignValues();
data.SetAdditionalVariables();
AssignValues(stdout_is_closed);
SetAdditionalVariables();
return true;
}
else
@@ -85,107 +86,186 @@ bool Config::ReadConfig(bool errors_to_stdout_)
void Config::AssignValues()
void Config::AssignValues(bool stdout_is_closed)
{
data.log_file = Text("log_file");
data.fcgi_socket = Text("fcgi_socket");
data.fcgi_socket_chmod = Int("fcgi_socket_chmod");
data.fcgi_socket_user = Text("fcgi_socket_user");
data.fcgi_socket_group = Text("fcgi_socket_group");
data.log_level = Int("log_level");
log_file = Text("log_file");
log_notify_file = Text("log_notify_file");
fcgi_socket = Text("fcgi_socket");
fcgi_socket_chmod = Int("fcgi_socket_chmod", 0770);
fcgi_socket_user = Text("fcgi_socket_user");
fcgi_socket_group = Text("fcgi_socket_group");
log_level = Int("log_level", 1);
log_request = Int("log_request", 1);
log_stdout = Bool("log_stdout", false);
if( !data.stdout_is_closed )
data.log_stdout = Bool("log_stdout");
post_file_max = Int("post_file_max", 8388608); // 8 MB
auth_simplefs_dir = Text("auth_simplefs_dir");
auth_hashfs_dir = Text("auth_hashfs_dir");
auth_tmp_dir = Text("auth_tmp_dir");
templates_dir = Text("templates_dir");
templates_dir_default = Text("templates_dir_default");
http_session_id_name = Text("http_session_id_name");
db_database = Text("db_database");
db_user = Text("db_user");
db_pass = Text("db_pass");
item_url_empty = Text("item_url_empty");
base_server = Text("base_server");
base_url = Text("base_url");
base_url_auth = Text("base_url_auth");
base_url_static = Text("base_url_static");
base_url_common = Text("base_url_common");
NoLastSlash(base_server);
NoLastSlash(base_url);
NoLastSlash(base_url_auth);
NoLastSlash(base_url_static);
NoLastSlash(base_url_common);
priv_no_user = Text("priv_no_user", "-- no user --");
priv_no_group = Text("priv_no_group", "-- no group --");
session_max_idle = Int("session_max_idle", 10800); // 3h
session_remember_max_idle = Int("session_remember_max_idle", 16070400); // 3 months
session_file = Text("session_file");
compression = Bool("compression", true);
html_filter = Bool("html_filter", true);
locale_str = Text("locale", "en");
locale_dir = Text("locale_dir");
locale_dir_default = Text("locale_dir_default");
title_separator = Text("title_separator", " / ");
parser.ListText("plugins", plugin_file);
}
void Config::SetAdditionalVariables()
{
SetHttpHost(base_url, base_url_http_host);
SetHttpHost(base_url_auth, base_url_auth_http_host);
}
void Config::SetHttpHost(const std::string & in, std::string & out)
{
if( strncmp(in.c_str(), "http://", 7) == 0 )
out = in.substr(7);
else
data.log_stdout = false;
data.templates = Text("templates");
data.default_index = Text("default_index");
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.base_url = Text("base_url");
NoLastSlash(data.base_url);
data.one_item_is_showed = Bool("one_item_is_showed");
data.priv_no_user = Text("priv_no_user");
data.priv_no_group = Text("priv_no_group");
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
}
std::string & Config::Text(const char * name)
std::string Config::Text(const char * name)
{
ConfParser::Table::iterator i = conf_parser.table.find(name);
if( i == conf_parser.table.end() )
{
log << log2 << "Config: warning: " << name << " is not defined in the config, default will be: \"" << default_str << "\"" << logend;
return default_str;
}
log << log3 << "Config: " << name << "=" << i->second << logend;
return i->second;
return parser.Text(name);
}
std::string Config::Text(const char * name, const char * def)
{
return parser.Text(name, def);
}
std::string Config::Text(const std::string & name, const std::string & def)
{
return parser.Text(name, def);
}
int Config::Int(const char * name)
{
ConfParser::Table::iterator i = conf_parser.table.find(name);
if( i == conf_parser.table.end() || i->second.empty() )
{
log << log2 << "Config: warning: " << name << " is not defined in the config, default will be: " << default_int << logend;
return default_int;
}
long res = (i->second[0] == '0')? strtol(i->second.c_str() + 1, 0, 8) : strtol(i->second.c_str(), 0, 10);
log << log3 << "Config: " << name << "=" << res << logend;
return res;
return parser.Int(name);
}
int Config::Int(const char * name, int def)
{
return parser.Int(name, def);
}
int Config::Int(const std::string & name, int def)
{
return parser.Int(name, def);
}
bool Config::Bool(const char * name)
{
ConfParser::Table::iterator i = conf_parser.table.find(name);
if( i == conf_parser.table.end() )
{
log << log2 << "Config: warning: " << name << " is not defined in the config, default will be: " << (default_bool?"true":"false") << logend;
return default_int;
}
bool res = default_int;
if( i->second == "true" || i->second == "1" || i->second == "yes" )
res = true;
log << log3 << "Config: " << name << "=" << (res?"true":"false") << logend;
return res;
return parser.Bool(name);
}
bool Config::Bool(const char * name, bool def)
{
return parser.Bool(name, def);
}
bool Config::Bool(const std::string & name, bool def)
{
return parser.Bool(name, def);
}
void Config::ListText(const char * name, std::vector<std::string> & list)
{
parser.ListText(name, list);
}
void Config::ListText(const std::string & name, std::vector<std::string> & list)
{
parser.ListText(name, list);
}
void Config::NoLastSlash(std::string & s)
{
if( s.empty() )
return;
log << log2 << "Config: removing the last slash from: " << s << logend;
if( *(--s.end()) == '/' )
s.erase(--s.end());
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://";
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));
}
}
@@ -195,5 +275,3 @@ void Config::NoLastSlash(std::string & s)

View File

@@ -1,55 +1,179 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfileconfig
#define headerfileconfig
#include "../confparser/confparser.h"
#include "error.h"
#include "data.h"
#include "log.h"
#ifndef headerfilecmslucoreconfig
#define headerfilecmslucoreconfig
#include <string>
#include "confparser.h"
class Config
{
public:
// 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;
// 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;
Config();
bool ReadConfig(bool errors_to_stdout_);
bool ReadConfig(bool errors_to_stdout_, bool stdout_is_closed = true);
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);
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);
void ListText(const char * name, std::vector<std::string> & list);
void ListText(const std::string & name, std::vector<std::string> & list);
void NoLastSlash(std::string & s);
void NoFirstHttp(std::string & s);
private:
ConfParser conf_parser;
void ShowError();
void AssignValues();
std::string & Text(const char *);
int Int(const char *);
bool Bool(const char *);
void AssignValues(bool stdout_is_closed);
void SetHttpHost(const std::string & in, std::string & out);
void SetAdditionalVariables();
ConfParser parser;
std::string default_str;
int default_int;
int default_int;
bool default_bool;
bool errors_to_stdout;
void NoLastSlash(std::string & s);
};
#endif

541
core/confparser.cpp Executable file
View File

@@ -0,0 +1,541 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "confparser.h"
#include "misc.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;
default_str = "";
default_int = 0;
default_bool = false;
}
void ConfParser::SplitSingle(bool split)
{
split_single = split;
}
void ConfParser::SkipEmpty(bool skip)
{
skip_empty = skip;
}
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::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::string & var)
{
Table::iterator i = table.find(var);
if( i != table.end() )
table.erase(i);
}
void ConfParser::DeleteFromTableSingle(const std::string & 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( 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::ReadChar()
{
lastc = file.get();
if( lastc == '\n' )
++line;
return lastc;
}
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::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);
}
std::string ConfParser::Text(const char * name)
{
return Text(std::string(name), default_str);
}
std::string ConfParser::Text(const char * name, const char * def)
{
return Text(std::string(name), std::string(def));
}
std::string ConfParser::Text(const std::string & name, const std::string & 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;
}
int ConfParser::Int(const char * name)
{
return Int(std::string(name), default_int);
}
int ConfParser::Int(const char * name, int def)
{
return Int(std::string(name), def);
}
int ConfParser::ToInt(const std::string & value)
{
long res = (value[0] == '0')? strtol(value.c_str() + 1, 0, 8) : strtol(value.c_str(), 0, 10);
return res;
}
int ConfParser::Int(const std::string & 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);
}
bool ConfParser::Bool(const char * name)
{
return Bool(std::string(name), default_bool);
}
bool ConfParser::Bool(const char * name, bool def)
{
return Bool(std::string(name), def);
}
bool ConfParser::ToBool(const std::string & value)
{
return ( EqualNoCase(value.c_str(), "true") ||
EqualNoCase(value.c_str(), "yes") ||
EqualNoCase(value.c_str(), "1")
);
}
bool ConfParser::Bool(const std::string & 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::string & def)
{
default_str = def;
}
void ConfParser::SetDefaultInt(int def)
{
default_int = def;
}
void ConfParser::SetDefaultBool(bool def)
{
default_bool = def;
}
// in lists we don't use default values
void ConfParser::ListText(const char * name, std::vector<std::string> & list)
{
ListText(std::string(name), list);
}
void ConfParser::ListText(const std::string & name, std::vector<std::string> & 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;
}
}

356
core/confparser.h Executable file
View File

@@ -0,0 +1,356 @@
/*
* 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
*/
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);
/*
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::string> Value;
typedef std::map<std::string, 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::string (instead of the whole std::vector)
so you can save a little memory from not using std::vector
*/
typedef std::map<std::string, std::string> 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);
/*
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::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);
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);
/*
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 is: 0
default bool is: false
*/
void SetDefaultText(const std::string & def);
void SetDefaultInt(int 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 char * name, std::vector<std::string> & list);
void ListText(const std::string & name, std::vector<std::string> & list);
private:
/*
last read variable (option)
*/
std::string variable;
/*
last read list item
*/
std::string 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
*/
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;
std::string default_str;
int default_int;
bool default_bool;
int ToInt(const std::string & value);
bool ToBool(const std::string & value);
Status ParseFile();
void AddOption();
void DeleteFromTable(const std::string & var);
void DeleteFromTableSingle(const std::string & var);
bool ReadVariable();
bool ReadValue();
bool ReadValueList();
bool ReadValueNoList(bool use_list_delimiter = false);
bool ReadValueQuoted();
bool ReadValueSimple(bool use_list_delimiter = false);
int ReadChar();
bool IsWhite(int c);
bool IsVariableChar(int c);
void SkipWhite();
void SkipWhiteLines();
void SkipLine();
void Trim(std::string & s);
};
#endif

View File

@@ -1,19 +1,19 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecookieparser
#define headerfilecookieparser
#ifndef headerfilecmslucorecookieparser
#define headerfilecmslucorecookieparser
#include <fcgiapp.h>
#include "httpsimpleparser.h"
#include "requesttypes.h"
#include "log.h"
@@ -46,9 +46,12 @@ protected:
log << log2 << "Cookie, name: \"" << name << "\", value: \"" << value << "\"";
if( res.second == false )
log << log2 << " (skipped)";
{
res.first->second = value;
log << " (overwritten)";
}
log << log2 << logend;
log << logend;
}

View File

@@ -1,47 +0,0 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* All rights reserved.
*
*/
#include "data.h"
Data::Data()
{
signal_hup = false;
stdout_is_closed = false;
// the rest will be read from a config file
}
void Data::SetAdditionalVariables()
{
SetHttpHost();
}
void Data::SetHttpHost()
{
if( strncmp(base_url.c_str(), "http://", 7) == 0 )
base_url_http_host = base_url.substr(7);
else
if( strncmp(base_url.c_str(), "https://", 8) == 0 )
base_url_http_host = base_url.substr(8);
else
base_url_http_host.clear();
if( base_url_http_host.empty() )
return;
// removing the last slash (if it is present)
if( base_url_http_host[ base_url_http_host.size() - 1 ] == '/' )
base_url_http_host.erase( base_url_http_host.end() - 1 );
}

View File

@@ -1,132 +0,0 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfiledata
#define headerfiledata
#include <string>
#include <vector>
#include <map>
#include <string.h>
#include "misc.h"
#include "item.h"
#include "error.h"
#include "dirs.h"
#include "users.h"
#include "groups.h"
#include "functions.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
std::string log_file;
// 1 - minimum
// 2 - (default)
// 3 - maximum - all logs
int log_level;
// logging to stdout too
bool log_stdout;
// 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;
std::string default_index;
std::string db_database;
std::string db_user;
std::string db_pass;
std::string base_url;
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;
// if there is one item in a directory
// it will be showed
// (instead of showing directory contents)
// !! wywalic to, nie bedzie uzywane
bool one_item_is_showed;
// string used in a place where is a user (or group) selected
std::string priv_no_user;
std::string priv_no_group;
// 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()
std::string base_url_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;
Data();
private:
void SetHttpHost();
};
extern Data data;
#endif

File diff suppressed because it is too large Load Diff

190
core/db.h
View File

@@ -1,14 +1,14 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecoredb
#define headerfilecoredb
#ifndef headerfilecmslucoredb
#define headerfilecmslucoredb
#include <string>
@@ -17,52 +17,189 @@
#include <sstream>
#include <libpq-fe.h>
#include <cstdio>
#include <ctime>
#include <cstring>
#include "log.h"
#include "item.h"
#include "misc.h"
#include "error.h"
#include "dircontainer.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();
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_subject = true);
Error EditItemByUrl(Item & item, bool with_subject = true);
Error EditItemById(Item & item, bool with_url = true);
Error EditItemByUrl(Item & item, bool with_url = true);
void CheckAllUrlSubject();
void GetItems(std::vector<Item> & item_table, Item & item_ref);
struct ItemQuery
{
// id is selected always
bool sel_parent_id; // parent_id
bool sel_user_id; // user_id, modification_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 SetAllSel(bool sel)
{
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;
}
void SetAllWhere(bool where_)
{
where_id = where_;
where_parent_id = where_;
where_type = where_;
where_auth = where_;
}
void SetAll(bool sel, bool where_)
{
SetAllSel(sel);
SetAllWhere(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);
void GetItems(std::vector<long> & 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
Error GetItem(long parent_id, const std::string & url, Item & item);
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 Connect();
void Close();
void AssertConnection();
std::string Escape(const std::string & s);
std::string Escape(const char * s);
@@ -77,15 +214,15 @@ protected:
Error AddItemIntoContent(Item & item);
Error AddItemIntoItem(Item & item);
Error EditItemInItem(Item & item, bool with_subject);
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(Item & item_ref);
PGresult * GetItemsQuery(const ItemQuery & iq, bool skip_other_sel = false);
bool DelItemDelItem(const Item & item);
void DelItemDelContent(const Item & item);
Error DelItemCountContents(const Item & item, long & contents);
@@ -93,17 +230,26 @@ protected:
struct ItemColumns
{
int id, user_id, group_id, privileges, url, type, parent_id, content_id, default_item, subject, content, content_type;
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, modification_user_id;
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,3 +1,12 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "db.h"
@@ -5,36 +14,48 @@
void Db::ItemColumns::SetColumns(PGresult * r)
{
// PQfnumber returns -1 if there is no such a column
id = PQfnumber(r, "id"); // !! why item.id doesn't work?
user_id = PQfnumber(r, "user_id");
group_id = PQfnumber(r, "group_id");
privileges = PQfnumber(r, "privileges");
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");
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");
modification_user_id = PQfnumber(r, "modification_user_id");
}
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( 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 = atoi( Db::AssertValue(r, row, content_type) );
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);
if( modification_user_id != -1 ) item.modification_user_id = atol( Db::AssertValue(r, row, modification_user_id) );
}
@@ -42,5 +63,35 @@ void Db::ItemColumns::SetItem(PGresult * r, long row, Item & item)
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

@@ -1,19 +1,23 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "dircontainer.h"
#include "log.h"
std::string DirContainer::dir_etc = "etc";
DirContainer::DirContainer()
{
is_root = false;
is_etc = false;
}
@@ -22,11 +26,19 @@ DirContainer::Iterator DirContainer::GetRoot()
{
if( !is_root )
return table.end();
return table.begin() + root_index;
return root_iter;
}
DirContainer::Iterator DirContainer::GetEtc()
{
if( !is_etc )
return table.end();
return etc_iter;
}
DirContainer::Iterator DirContainer::Begin()
{
@@ -51,37 +63,112 @@ bool DirContainer::Empty()
}
void DirContainer::PushBack(const Item & item)
// 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()
{
bool rebuild_indexes = false;
is_etc = false;
if( table.size() == table.capacity() )
rebuild_indexes = true;
if( !is_root )
return;
if( item.parent_id == -1 )
DirContainer::ParentIterator i = FindFirstParent(root_iter->id);
for( ; i!=ParentEnd() ; i = NextParent(i) )
{
if( is_root )
log << log1 << "DirCont: more than one root dir - skipped, id: " << item.id << logend;
else
if( i->second->url == dir_etc )
{
is_root = true;
root_index = table.size();
is_etc = true;
etc_iter = i->second;
break;
}
}
table.push_back(item);
log << log2 << "DirCont: added item, id: " << item.id << ", parent_id: " << item.parent_id << logend;
if( rebuild_indexes )
RebuildIndexes();
else
AddIndexes( --table.end() );
}
// this is used with PushBack() method
void DirContainer::CheckSpecialFolder(const Item & item, Iterator iter)
{
if( item.parent_id == -1 )
{
is_root = true;
root_iter = iter;
}
if( !is_root )
return;
if( item.parent_id==root_iter->id && item.url==dir_etc )
{
is_etc = true;
etc_iter = iter;
log << log1 << "DirCont: added special folder: /etc" << logend;
}
}
DirContainer::Iterator DirContainer::PushBack(const Item & item)
{
if( item.parent_id == -1 && is_root )
{
log << log1 << "DirCont: more than one root dir - skipped, id: " << item.id << logend;
return root_iter;
}
Iterator last_iter = table.insert(table.end(), item);
CheckSpecialFolder(item, last_iter);
log << log2 << "DirCont: added dir, url: " << item.url << ", id: " << item.id << ", parent_id: " << item.parent_id << logend;
table_id.insert( std::make_pair(last_iter->id, last_iter) );
table_parent.insert( std::make_pair(last_iter->parent_id, last_iter) );
log << log3 << "DirCont: added indexes to dir, id: " << last_iter->id << ", parent_id: " << last_iter->parent_id << logend;
return last_iter;
}
bool DirContainer::ChangeParent(long dir_id, long new_parent_id)
{
Iterator i = FindId(dir_id);
if( i == table.end() )
return false;
if( i->parent_id == new_parent_id )
return true; // nothing to do
ParentIterator p = FindFirstParent(i->parent_id);
bool found = false;
for( ; p != table_parent.end() ; p = NextParent(p) )
{
if( p->second->id == dir_id )
{
table_parent.erase(p);
log << log3 << "DirCont: removed parent index to dir: " << i->id << logend;
i->parent_id = new_parent_id;
table_parent.insert( std::make_pair(new_parent_id, i) );
log << log3 << "DirCont: added parent index to dir, id: " << i->id << ", parent_id: " << i->parent_id << logend;
found = true;
if( i->url == "etc" ) // !! in the future can be more special folders
FindSpecialFolders();
break; // that iterator (p) is only one
}
}
if( !found )
log << log1 << "DirCont: cannot find parent_id: " << i->parent_id << " in parent indexes" << logend;
return found;
}
@@ -90,6 +177,7 @@ void DirContainer::Clear()
table.clear();
table_id.clear();
table_parent.clear();
is_root = false;
}
@@ -107,34 +195,6 @@ return i->second;
void DirContainer::AddIndexes(Iterator item)
{
table_id.insert( std::make_pair(item->id, item) );
table_parent.insert( std::make_pair(item->parent_id, item) );
log << log2 << "DirCont: added indexes to item, id: " << item->id << ", parent_id: " << item->parent_id << logend;
}
void DirContainer::RebuildIndexes()
{
Iterator i;
log << log2 << "DirCont: rebuilding indexes" << logend;
table_id.clear();
table_parent.clear();
for(i=table.begin() ; i!=table.end() ; ++i)
AddIndexes( i );
log << log2 << "DirCont: indexes rebuilt, table.size: " << table.size() << ", table_id.size: " << table_id.size() << ", table_parent.size: " << table_parent.size() << logend;
}
DirContainer::ParentIterator DirContainer::ParentBegin()
{
return table_parent.begin();
@@ -184,3 +244,56 @@ DirContainer::ParentIterator DirContainer::NextParent(ParentIterator i)
return i;
}
bool DirContainer::DelById(long id)
{
TableId::iterator i = table_id.find(id);
if( i == table_id.end() )
{
log << log1 << "DirCont: delete: there is no directory with id: " << id << logend;
return false;
}
long parent_id = i->second->parent_id;
TableParent::iterator z = table_parent.lower_bound(parent_id);
bool found = false;
for( ; z != table_parent.end() && z->first == parent_id ; ++z )
{
if( z->second == i->second )
{
log << log2 << "DirCont: deleted directory id: " << id << ", url: " << i->second->url;
if( i->second->parent_id == -1 )
{
log << log2 << " (root directory)";
is_root = false;
}
log << log2 << logend;
table.erase(i->second);
log << log3 << "DirCont: deleted indexes into directory id: " << id << logend;
table_id.erase(i);
table_parent.erase(z);
found = true;
break;
}
}
if( !found )
{
log << log1 << "DirCont: can't find an index_parent into directory id: " << id << ", url: " << i->second->url << " (deleting skipped)" << logend;
return false;
}
return true;
}

View File

@@ -1,28 +1,28 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfiledircontainer
#define headerfiledircontainer
#ifndef headerfilecmslucoredircontainer
#define headerfilecmslucoredircontainer
#include <vector>
#include <list>
#include <map>
#include "item.h"
#include "log.h"
class DirContainer
{
public:
typedef std::vector<Item> Table;
typedef Table::iterator Iterator;
typedef Table::size_type SizeType;
typedef std::list<Item> Table;
typedef Table::iterator Iterator;
typedef Table::size_type SizeType;
typedef std::map<long, Iterator> TableId;
typedef std::multimap<long, Iterator> TableParent;
@@ -33,16 +33,20 @@ public:
DirContainer();
Iterator GetRoot();
Iterator GetEtc();
Iterator Begin();
Iterator End();
SizeType Size();
bool Empty();
void PushBack(const Item & item);
Iterator PushBack(const Item & item);
bool ChangeParent(long dir_id, long new_parent_id);
void Clear();
Iterator FindId(long id);
bool DelById(long id);
ParentIterator ParentBegin();
ParentIterator ParentEnd();
ParentSizeType ParentSize();
@@ -50,11 +54,11 @@ public:
ParentIterator FindFirstParent(long parent);
ParentIterator NextParent(ParentIterator pi);
void FindSpecialFolders();
private:
void AddIndexes(Iterator item);
void RebuildIndexes();
void CheckSpecialFolder(const Item & item, Iterator iter);
// main table with dirs
Table table;
@@ -62,12 +66,21 @@ private:
// true if there is a root dir in the table
bool is_root;
// root dir
SizeType root_index;
// root
Iterator root_iter;
// true if there is a etc dir in the table
bool is_etc;
// etc
Iterator etc_iter;
// indexes
TableId table_id;
TableParent table_parent;
// names of folders
static std::string dir_etc;
};

View File

@@ -1,13 +1,28 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "dirs.h"
#include "error.h"
#include "log.h"
void Dirs::SetDb(Db * pdb)
{
db = pdb;
}
void Dirs::SetRequest(Request * prequest)
{
request = prequest;
}
void Dirs::Clear()
@@ -16,26 +31,46 @@ void Dirs::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::ParentIterator i;
long roots = 0;
for( i=dir_table.FindFirstParent(-1) ; i!=dir_table.ParentEnd() ; i=dir_table.NextParent(i) )
++roots;
if( roots == 0 )
DirContainer::Iterator i = dir_table.GetRoot();
if( i != dir_table.End() )
{
log << log1 << "Dirs: there is no a root dir in the database" << logend;
Clear();
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);
}
return;
}
else
if( roots > 1 )
log << log1 << "Dirs: there is no a root dir in the database (creating one)" << logend;
Item root;
root.type = Item::dir;
root.parent_id = -1;
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 )
{
log << log1 << "Dirs: there are more than one root dir in the database" << logend;
Clear();
dir_table.PushBack(root);
}
}
@@ -46,36 +81,9 @@ void Dirs::ReadDirs()
{
Clear();
db.GetDirs(dir_table);
db->GetDirs(dir_table);
CheckRootDir();
}
bool Dirs::GetRootDir(Item ** item)
{
DirContainer::Iterator root = dir_table.GetRoot();
if( root == dir_table.End() )
return false;
*item = &(*root);
return true;
}
bool Dirs::GetDir(const std::string & name, long parent, Item ** item)
{
DirContainer::ParentIterator i = dir_table.FindFirstParent(parent);
for( ; i!=dir_table.ParentEnd() ; i = dir_table.NextParent(i) )
if( i->second->url == name )
{
*item = &(*i->second);
return true;
}
return false;
dir_table.FindSpecialFolders();
}
@@ -94,62 +102,6 @@ return !name.empty();
// !! moze lepiej zwracac wskaznik do Item i kiedy nie ma katalogu to zwracac 0 ?
bool Dirs::GetDir(const std::string & path, Item ** item)
{
DirContainer::Iterator root = dir_table.GetRoot();
if( root == dir_table.End() )
// ops, we do not have a root dir
return false;
Item * pitem = &(*root);
std::string name;
const char * s = path.c_str();
while( ExtractName(s, name) )
{
if( !GetDir(name, pitem->id, &pitem) )
return false;
}
*item = pitem;
return true;
}
// !! ten interfejs jes bylejaki
// !! moze lepiej zwracac id i kiedy nie ma katalogu to -1 (przeciez to jest wartosc ktora nie moze pojawic sie w indeksie)
bool Dirs::GetDirId(const std::string & path, long * id)
{
Item * pitem;
if( !GetDir(path, &pitem) )
return false;
*id = pitem->id;
return true;
}
bool Dirs::GetDirId(const std::string & name, long parent, long * id)
{
Item * pitem;
if( !GetDir(name, parent, &pitem) )
return false;
*id = pitem->id;
return true;
}
bool Dirs::IsDir(long id)
@@ -165,20 +117,6 @@ return true;
bool Dirs::GetDirChilds(long parent, std::vector<Item> & childs_table)
{
if( parent != -1 && !IsDir(parent) )
return false;
DirContainer::ParentIterator i = dir_table.FindFirstParent(parent);
for( ; i != dir_table.ParentEnd() ; i = dir_table.NextParent(i) )
childs_table.push_back( *i->second );
return true;
}
bool Dirs::GetDirChilds(long parent, std::vector<Item*> & childs_table)
{
if( parent != -1 && !IsDir(parent) )
@@ -193,10 +131,30 @@ return true;
}
DirContainer::ParentIterator Dirs::FindFirstParent(long parent_id)
{
DirContainer::ParentIterator i = dir_table.FindFirstParent(parent_id);
return i;
}
DirContainer::ParentIterator Dirs::NextParent(DirContainer::ParentIterator i)
{
return dir_table.NextParent(i);
}
DirContainer::ParentIterator Dirs::ParentEnd()
{
return dir_table.ParentEnd();
}
// dodatkowo moze metoda AppendPath dodajaca sciezke do biezacego stringa?
// 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)
{
DirContainer::Iterator i;
@@ -207,7 +165,8 @@ DirContainer::Iterator i;
{
i = dir_table.FindId(id);
if( i == dir_table.End() )
if( i == dir_table.End() ||
i->parent_id == id ) // means a loop (something wrong in the db)
return false;
if( i->parent_id == -1 )
@@ -223,55 +182,34 @@ DirContainer::Iterator i;
// with exceptions
Item * Dirs::GetDirT(const std::string & path)
bool Dirs::ChangeParent(long dir_id, long new_parent_id)
{
Item * pitem;
if( !GetDir(path, &pitem) )
throw Error(Error::incorrect_dir);
return pitem;
}
Item * Dirs::GetDirT(const std::string & name, long parent)
{
Item * pitem;
if( !GetDir(name, parent, &pitem) )
throw Error(Error::incorrect_dir);
return pitem;
}
long Dirs::GetDirIdT(const std::string & path)
{
long id;
if( !GetDirId(path, &id) )
throw Error(Error::incorrect_dir);
return id;
}
long Dirs::GetDirIdT(const std::string & name, long parent)
{
long id;
if( !GetDirId(name, parent, &id) )
throw Error(Error::incorrect_dir);
return id;
return dir_table.ChangeParent(dir_id, new_parent_id);
}
// !! nowy interfejs
/*
checking whether dir_id has a parent parent_id (somewhere in the path)
*/
bool Dirs::HasParent(long dir_id, long parent_id)
{
DirContainer::Iterator i;
while( true )
{
i = dir_table.FindId(dir_id);
if( i==dir_table.End() || i->parent_id==-1 )
return false;
if( i->parent_id == parent_id )
return true;
dir_id = i->parent_id;
}
}
@@ -286,6 +224,17 @@ return &(*root);
}
Item * Dirs::GetEtcDir()
{
DirContainer::Iterator etc = dir_table.GetEtc();
if( etc == dir_table.End() )
return 0;
return &(*etc);
}
Item * Dirs::GetDir(const std::string & name, long parent)
{
DirContainer::ParentIterator i = dir_table.FindFirstParent(parent);
@@ -335,3 +284,150 @@ Item * Dirs::GetDir(long id)
return &(*i);
}
Item * Dirs::AddDir(const Item & item)
{
return &(*dir_table.PushBack(item));
}
size_t Dirs::AnalyzeDir(Item * pdir, const std::string & path, long & dir_id, std::string & dir)
{
size_t i = 0;
size_t old_i;
while( true )
{
dir_id = pdir->id;
// skipping slashes
for( ; i<path.size() && path[i] == '/' ; ++i );
if( i == path.size() )
return i; // end of the path
// creating a name
old_i = i;
analyze_temp.clear();
for( ; i<path.size() && path[i] != '/' ; ++i)
analyze_temp += path[i];
pdir = GetDir(analyze_temp, pdir->id);
if( !pdir )
return old_i; // analyze_temp is not a directory
dir += analyze_temp;
dir += '/';
}
}
/*
the path should begin with a slash
return values:
0 - directory exists
dir_id - id of the directory
dir - the path to the directory (with a slash at the end)
file - if not empty means a file name (we don't check if the file really exists)
1 - there is not a root dir
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)
{
Item * pdir = GetRootDir();
dir = '/';
file.clear();
if( !pdir )
return 1;
if( path.empty() )
return 2;
if( path[0] != '/' )
return 3;
size_t i = AnalyzeDir(pdir, path, dir_id, dir);
if( i < path.size() )
{
// checking if at least one slash has left
for(size_t a=i ; a < path.size() ; ++a)
if( path[a] == '/' )
return 3; // there is not such a directory
// the rest of the path is a file name
file = path.c_str() + i;
}
return 0;
}
void Dirs::SplitPath(const std::string & path, std::string & dir, std::string & file)
{
std::string::size_type i;
dir.clear();
file.clear();
if( path.empty() )
// !! moze dir ustawic na '/' ?
return;
for( i=path.size()-1 ; i>0 && path[i]!='/' ; --i);
if( path[i] != '/' )
{
// we do not have any slashes '/'
file = path;
return;
}
dir.assign(path, 0, i + 1); // +1 means with a slash at the end
if( i < path.size() - 1 )
file.assign(path, i+1, path.size() - i - 1);
}
// !! dodac kasowanie z bazy
bool Dirs::DelDir(long dir_id)
{
return dir_table.DelById(dir_id);
}
Error Dirs::AddDirectory(Item & item, bool add_to_dir_table)
{
if( item.type != Item::dir )
return WINIX_ERR_DIR_EXPECTED;
Error status = db->AddItem(item);
if( status == WINIX_ERR_OK )
{
Item * pdir = AddDir(item);
if( add_to_dir_table && request->dir_table.back()->id == item.parent_id )
request->dir_table.push_back(pdir);
}
return status;
}

View File

@@ -1,88 +1,83 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfiledirs
#define headerfiledirs
#ifndef headerfilecmslucoredirs
#define headerfilecmslucoredirs
#include <vector>
#include <map>
#include <string>
#include "item.h"
#include "error.h"
#include "log.h"
#include "db.h"
#include "dircontainer.h"
#include "item.h"
#include "dircontainer.h"
#include "db.h"
#include "request.h"
// we do not support '..' in a path (for simplicity and security reasons)
class Dirs
{
private:
public: // !! temporarily
DirContainer dir_table;
bool ExtractName(const char * & s, std::string & name);
void CheckRootDir();
public:
void Clear();
void ReadDirs();
// without any exceptions
// these methods return false in a case the path or name (with a specific parent) are invalid
// we do not support '..' in a path (for security reason)
bool IsDir(long id);
bool GetRootDir(Item ** item);
bool GetDir(const std::string & path, Item ** item);
bool GetDir(const std::string & name, long parent, Item ** item);
bool GetDirId(const std::string & path, long * id);
bool GetDirId(const std::string & name, long parent, long * id);
void SetRequest(Request * prequest);
void SetDb(Db * pdb);
//!! ta nie bedzie chyba potrzebna
bool GetDirChilds(long parent, std::vector<Item> & childs_table); // only returns dir-children
// 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 ChangeParent(long dir_id, long new_parent_id);
bool HasParent(long dir_id, long parent_id);
bool DelDir(long dir_id);
bool GetDirChilds(long parent, std::vector<Item*> & childs_table); // only returns dir-children
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 MakePath(long id, std::string & path);
DirContainer::ParentIterator FindFirstParent(long parent_id);
DirContainer::ParentIterator NextParent(DirContainer::ParentIterator i);
DirContainer::ParentIterator ParentEnd();
// with an Error exception
// if the path or name are invalid these methods throw an exception
Item * GetDirT(const std::string & path);
Item * GetDirT(const std::string & name, long parent);
long GetDirIdT(const std::string & path);
long GetDirIdT(const std::string & name, long parent);
// !! nowy interfejs
// returns null if there is no a root dir
// 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 * GetDir(long id);
Item * AddDir(const Item & item);
void CheckRootDir();
// !! jak juz wczesniejsze nazwy beda zmienione to tutaj damy AddDir()
Error AddDirectory(Item & item, bool add_to_dir_table = false);
private:
Request * request;
Db * db;
DirContainer dir_table;
size_t AnalyzeDir(Item * pdir, const std::string & path, long & dir_id, std::string & dir);
std::string analyze_temp;
bool ExtractName(const char * & s, std::string & name);
bool HasReadExecAccessForRoot(const Item & item);
};

View File

@@ -1,47 +0,0 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* All rights reserved.
*
*/
#include "done.h"
Done::Done()
{
}
Done::Done(Code c) : code(c)
{
}
Done & Done::operator=(Code c)
{
code = c;
return *this;
}
bool Done::operator==(Code c) const
{
return code == c;
}
bool Done::operator!=(Code c) const
{
return code != c;
}
Done::operator int()
{
return static_cast<int>( code );
}

View File

@@ -1,47 +0,0 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfiledone
#define headerfiledone
// what has been done
class Done
{
public:
enum Code
{
none = 0,
added_item,
edited_item,
deleted_item,
privileged_item,
loggedout
};
Done();
Done(Code c);
Done & operator=(Code c);
bool operator==(Code c) const;
bool operator!=(Code c) const;
operator int();
private:
Code code;
};
#endif

View File

@@ -1,94 +0,0 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* All rights reserved.
*
*/
#include "error.h"
Error::Error()
{
code = unknown;
}
Error::Error(Code c) : code(c)
{
}
Error::Error(int i)
{
code = static_cast<Code>(i);
}
Error::Error(const Error & e)
{
code = e.code;
}
Error::operator int() const
{
return static_cast<int>(code);
}
Error & Error::operator=(Code c)
{
code = c;
return *this;
}
Error & Error::operator=(const Error & e)
{
code = e.code;
return *this;
}
bool Error::operator==(Code c) const
{
return code == c;
}
bool Error::operator!=(Code c) const
{
return code != c;
}
bool Error::operator==(const Error & e) const
{
return code == e.code;
}
bool Error::operator!=(const Error & e) const
{
return code != e.code;
}
std::ostream & operator<<(std::ostream & out, const Error & e)
{
out << static_cast<int>(e.code);
return out;
}
Log & operator<<(Log & out, const Error & e)
{
out << static_cast<int>(e.code);
return out;
}

View File

@@ -1,79 +1,76 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfileerror
#define headerfileerror
#ifndef headerfilecmslucoreerror
#define headerfilecmslucoreerror
#include <iostream>
#include "log.h"
#define WINIX_ERR_OK 0
//#define WINIX_ERR_INCORRECT_PATH 1
//#define WINIX_ERR_NO_POSTVAR 2
#define WINIX_ERR_INCORRECT_DIR 3
#define WINIX_ERR_CANT_CHANGE_USER 4
#define WINIX_ERR_CANT_CHANGE_GROUP 5
#define WINIX_ERR_CANT_CHANGE_PRIVILEGES 6
#define WINIX_ERR_PERMISSION_DENIED 7
#define WINIX_ERR_NO_ROOT_DIR 8
#define WINIX_ERR_NO_FUNCTION 9
#define WINIX_ERR_NO_ITEM 10
#define WINIX_ERR_UNKNOWN_PARAM 11
#define WINIX_ERR_MOUNT_UNKNOWN 12
#define WINIX_ERR_UNKNOWN_FILESYSTEM 13
#define WINIX_ERR_NO_MOUNTPOINT 14
//#define WINIX_ERR_MOUNT_NO_PARAM 15
#define WINIX_ERR_NO_THREAD 16
#define WINIX_ERR_EMPTY 17
#define WINIX_ERR_SPAM 18
#define WINIX_ERR_INCORRECT_REBUS 19
class Error
{
#define WINIX_ERR_NO_BOUNDARY 20
#define WINIX_ERR_BROKEN_INPUT 21
#define WINIX_ERR_INPUT_TOO_LARGE 22
#define WINIX_ERR_CANT_CREATE_FILE 23
public:
#define WINIX_ERR_NO_TICKET 24
enum Code
{
ok = 0,
incorrect_path,
db_fatal_error_during_connecting,
db_incorrect_query,
db_incorrent_result_status,
db_no_column,
db_no_item, // !! zamienic na no_item
db_incorrect_login,
db_more_than_one_login,
db_err_currval,
no_postvar,
incorrect_dir,
cant_change_user,
cant_change_group,
cant_change_privileges,
permision_denied, // !! permission_denied (dwa ss)
no_root_dir,
no_function, // !! zamienic na no_function
item_required, // !! zamienic na no_item (i usunac db_no_item)
unknown = 1000
};
Error();
Error(Code c);
Error(int i);
Error(const Error & e);
Error & operator=(Code c);
Error & operator=(const Error & e);
operator int() const;
bool operator==(Code c) const;
bool operator!=(Code c) const;
bool operator==(const Error & e) const;
bool operator!=(const Error & e) const;
friend std::ostream & operator<<(std::ostream & out, const Error & e);
friend Log & operator<<(Log & out, const Error & e);
#define WINIX_ERR_PASSWORDS_DIFFERENT 25
#define WINIX_ERR_PASSWORD_TOO_SHORT 26
#define WINIX_ERR_USER_EXISTS 27
#define WINIX_ERR_LOGIN_EMPTY 28
#define WINIX_DIFFERENT_MOUNT_POINTS 29
private:
#define WINIX_ERR_DB_FATAL_ERROR_DURING_CONNECTING 100
#define WINIX_ERR_DB_INCORRECT_QUERY 101
#define WINIX_ERR_DB_INCORRENT_RESULT_STATUS 102
#define WINIX_ERR_DB_NO_COLUMN 103
#define WINIX_ERR_DB_INCORRECT_LOGIN 104
#define WINIX_ERR_DB_MORE_THAN_ONE_LOGIN 105
#define WINIX_ERR_DB_ERR_CURRVAL 106
Code code;
#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,53 +0,0 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* All rights reserved.
*
*/
#include "function.h"
Function::Function()
{
code = none;
}
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,52 +0,0 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilefunction
#define headerfilefunction
#include <iostream>
#include "log.h"
#include "item.h"
class Function
{
public:
enum Code
{
none,
ls,
cat,
node,
emacs,
privileges,
rm,
login,
logout
};
Code code;
Item item;
Function();
Function(const Function & f);
Function & operator=(const Function & f);
};
#endif

View File

@@ -1,181 +0,0 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* All rights reserved.
*
*/
#include "functionparser.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 = Error::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 == Error::ok )
{
++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 = Error::ok;
get_index = 0;
get_table_len = request.get_table.size();
request.pfunction = 0;
request.is_item = false;
ParseDirectories();
if( request.status != Error::ok )
return;
ParseFunction();
if( !request.pfunction )
{
ParseItem();
if( request.status != Error::ok )
return;
ParseFunction();
if( !request.pfunction && get_index != get_table_len )
{
request.status = Error::no_function;
log << log3 << "FP: Parse: unknown function: \"" << request.get_table[get_index] << "\"" << logend;
return;
}
}
ParseParams();
}

View File

@@ -1,45 +0,0 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilefunctionparser
#define headerfilefunctionparser
#include "request.h"
#include "log.h"
#include "item.h"
#include "error.h"
#include "data.h"
#include "db.h"
class FunctionParser
{
GetTable::size_type get_index;
GetTable::size_type get_table_len;
void SkipEmptyString(const char * msg);
void ParseDirectories();
void ParseItem();
void ParseFunction();
void ParseParams();
public:
void Parse();
};
#endif

View File

@@ -1,113 +0,0 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* All rights reserved.
*
*/
#include "functions.h"
void Functions::Clear()
{
table.clear();
}
void Functions::ReadFunctions()
{
Clear();
Function f;
f.item.user_id = -1;
f.item.group_id = -1;
f.item.privileges = 0644;
f.item.parent_id = -1; // !! temporarily doesn't matter
f.item.id = -1;
f.item.type = Item::file;
// in the future we will read these functions from the database
f.code = Function::ls;
f.item.url = "list";
table.insert( std::make_pair(f.item.url, f) );
f.code = Function::cat;
f.item.url = "wyswietl";
table.insert( std::make_pair(f.item.url, f) );
f.code = Function::node;
f.item.url = "node";
table.insert( std::make_pair(f.item.url, f) );
f.code = Function::emacs;
f.item.url = "edytuj";
table.insert( std::make_pair(f.item.url, f) );
f.code = Function::privileges;
f.item.url = "uprawnienia";
table.insert( std::make_pair(f.item.url, f) );
f.code = Function::rm;
f.item.url = "usun";
table.insert( std::make_pair(f.item.url, f) );
f.code = Function::logout;
f.item.url = "wyloguj";
table.insert( std::make_pair(f.item.url, f) );
f.code = Function::login;
f.item.url = "login";
table.insert( std::make_pair(f.item.url, f) );
}
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(Function::Code code)
{
Table::iterator i = table.begin();
for( ; i != table.end() ; ++i )
{
if( i->second.code == code )
return &(i->second);
}
return 0;
}

View File

@@ -1,42 +0,0 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilefunctions
#define headerfilefunctions
#include <map>
#include <string>
#include "function.h"
class Functions
{
typedef std::map<std::string, Function> Table;
Table table;
public:
void Clear();
void ReadFunctions();
Function * GetFunction(const std::string & name);
Function * GetFunction(Function::Code code);
};
#endif

View File

@@ -1,14 +1,14 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilegetparser
#define headerfilegetparser
#ifndef headerfilecmslucoregetparser
#define headerfilecmslucoregetparser
#include "httpsimpleparser.h"
#include "requesttypes.h"

View File

@@ -1,14 +1,14 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilegroup
#define headerfilegroup
#ifndef headerfilecmslucoregroup
#define headerfilecmslucoregroup
#include <string>
#include <vector>

View File

@@ -1,8 +1,8 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
@@ -12,8 +12,6 @@
Groups::Groups()
{
Clear();
@@ -26,11 +24,11 @@ void Groups::Clear()
}
void Groups::ReadGroups()
void Groups::ReadGroups(Db * db)
{
Clear();
db.GetGroups(table);
db->GetGroups(table);
}

View File

@@ -1,19 +1,21 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilegroups
#define headerfilegroups
#ifndef headerfilecmslucoregroups
#define headerfilecmslucoregroups
#include <map>
#include "group.h"
#include "db.h"
#include "ugcontainer.h"
#include "db.h"
class Groups
@@ -29,7 +31,7 @@ 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);

1208
core/htmlfilter.cpp Executable file

File diff suppressed because it is too large Load Diff

221
core/htmlfilter.h Executable file
View File

@@ -0,0 +1,221 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslucorehtmlfilter
#define headerfilecmslucorehtmlfilter
#include <string>
// max length of a name of a html tag (with terminating null)
#define WINIX_HTMLFILTER_ITEM_MAXLEN 30
// depth of the html tree
#define WINIX_HTMLFILTER_STACK_MAXLEN 100
// length of a buffer used for printing
// it should be at least: WINIX_HTMLFILTER_ITEM_MAXLEN+3
#define WINIX_HTMLFILTER_BUFFER_MAXLEN 2048
/*!
very lightweight filter for html
(without using any dynamic memory - some memory is allocated only at the beginning - in ctors)
this filter has O(n) complexity over the whole html string
such tags as: <script> <pre> <textarea> are treated in a special way
all characters between the opening and closing tag (<script>....</script>) are untouched
if the filter finds that there are not closed tags it will close them,
if the filter finds a closing tag which doesn't have an opening tag - it will skip it
tags which don't need to be closed: meta, input, br, img, link
look at CheckExceptions() method
the filter recognizes xml simple tags (with / at the end) such as: <br />
*/
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);
// insert a white space into long lines
// only between html tags
// skipped in such tags: script, pre, textarea
// 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
// only between html tags
// at the beginning and at the end only one space is left
// skipped in such tags: script, pre, textarea
// 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];
size_t name_len;
enum Type
{
opening,
closing,
simple,
special,
none
} type;
// is there a new line after this tag
bool new_line;
void Clear();
Item();
};
// only this method have direct access to the output string
// you can easily change the output from a std::string to something else
virtual void Put(const char * str, const char * 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);
bool IsTagSafe(const char * tag);
int CheckOrphan(const char * str, const char * end, const char * orphan);
bool CheckOrphanTable(const char * str, const char * end, const char ** table, size_t o1, size_t o2);
bool CheckOrphanLangPl(const char * str, const char * end);
bool CheckOrphanLangCz(const char * str, const char * end);
bool CheckOrphan(const char * str, const char * end);
bool IsWhite(int c);
void SkipWhite();
void SkipWhiteLines();
void SkipWhiteWithFirstNewLine();
bool IsClosingTagForLastItem();
virtual bool IsOpeningTagMark();
virtual bool IsOpeningCommentaryTagMark();
size_t OpeningCommentaryTagMarkSize();
virtual bool IsClosingTagMark();
virtual bool IsClosingXmlSimpleTagMark();
bool SkipCommentaryTagIfExists();
const char * SkipItemCheckXmlSimple();
void PopStack();
bool PushStack();
virtual bool IsValidCharForName(int c);
void CheckNewLine();
virtual void CheckExceptions();
void CheckStackPrintRest();
void AddForgottenTags();
void CheckClosingTags();
virtual void ReadNormalTextSkipWhite(const char * & start, const char * & last_non_white);
void ReadNormalText();
bool PrintRest();
void PrintItem(const char * start, const char * end);
void ReadItemName();
bool ReadItem();
virtual void Init();
virtual void Deinit();
void Read();
size_t PutNormalTextTrimFillBuffer(const char * & str, const char * & end);
size_t PutNormalTextFillBuffer(const char * & str, const char * & end);
virtual void PutNormalText(const char * str, const char * end);
virtual void PutNormalTextTrim(const char * str, const char * end);
void PutLastTagWithClosingTag();
virtual void PutOpeningTagMark();
virtual void PutClosingTagMark();
virtual void PutTagName(const char * name);
virtual void PutOpeningTag(const char * start, const char * end);
virtual void PutClosingTag(const char * 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;
Item empty;
Item * pstack; // stack pointer
size_t stack_len; // length of the stack
char * buffer; // buffer used when printing
std::string * out_string;
bool last_new_line;
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
};
#endif

View File

@@ -1,8 +1,8 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
@@ -101,12 +101,16 @@ void HttpSimpleParser::CheckSpecialChar()
int c2 = GetChar();
if( c1==-1 || c2==-1 )
{
last_c = -1;
}
else
{
c1 = ParseHalfHex(c1);
c2 = ParseHalfHex(c2);
c1 = ParseHalfHex(c1);
c2 = ParseHalfHex(c2);
last_c = (c1 << 4) + c2;
last_c = (c1 << 4) + c2;
}
}
else
if( last_c == '+' )

View File

@@ -1,14 +1,14 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilehttpsimpleparser
#define headerfilehttpsimpleparser
#ifndef headerfilecmslucorehttpsimpleparser
#define headerfilecmslucorehttpsimpleparser
#include <string>

View File

@@ -1,14 +1,14 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfileitem
#define headerfileitem
#ifndef headerfilecmslucoreitem
#define headerfilecmslucoreitem
#include <string>
@@ -18,49 +18,91 @@
struct Item
{
long id;
long parent_id;
long user_id;
long group_id;
std::string 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;
enum ContentType
{
ct_text = 0,
ct_formatted_text,
ct_html,
ct_bbcode,
ct_raw
};
ContentType content_type;
int content_type;
enum Type
{
dir = 0,
file = 1,
none = 1000
none = 1000 // !! pozbyc sie tego
};
Type type;
//item_type;
long parent_id;
long default_item;
// used by the database
long content_id;
// 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()
{
@@ -69,18 +111,26 @@ void Clear()
user_id = -1;
group_id = -1;
privileges = 0;
modification_user_id = -1;
guest_name.clear();
subject.clear();
content.clear();
url.clear();
content_type = 0;
content_type = ct_formatted_text;
type = none;
parent_id = -1;
default_item = -1;
content_id = -1;
auth = auth_none;
auth_path.clear();
SetDateToNow();
}

115
core/lastcontainer.cpp Executable file
View File

@@ -0,0 +1,115 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2009, Tomasz Sowa
* All rights reserved.
*
*/
#include "lastcontainer.h"
#include "log.h"
LastItem::LastItem()
{
user_id = 0;
ip = 0;
session_id = 0;
memset((char*)&start, 0, sizeof(start));
memset((char*)&end, 0, sizeof(end));
}
bool LastItem::IsLoggedOut()
{
if( end.tm_sec == 0 &&
end.tm_min == 0 &&
end.tm_hour == 0 &&
end.tm_mday == 0 &&
end.tm_mon == 0 &&
end.tm_year == 0 )
return false;
return true;
}
LastContainer::Iterator LastContainer::Begin()
{
return last_tab.begin();
}
LastContainer::Iterator LastContainer::End()
{
return last_tab.end();
}
LastContainer::Iterator LastContainer::FindNotLoggedOut(long user_id, long session_id)
{
LastTab::iterator i;
for(i=last_tab.begin() ; i!=last_tab.end() ; ++i)
{
if( i->user_id == user_id && i->session_id == session_id && !i->IsLoggedOut() )
return i;
}
return last_tab.end();
}
void LastContainer::UserLogin(long user_id, const std::string & name, unsigned int ip, long session_id)
{
LastTab::iterator i = FindNotLoggedOut(user_id, session_id);
if( i != last_tab.end() )
{
log << log1 << "LC: such a user and session_id exist, not added as a new one" << logend;
return;
}
if( last_tab.size() >= LAST_TABLE_SIZE )
last_tab.erase(last_tab.begin());
LastItem li;
li.user_id = user_id;
li.name = name;
li.ip = ip;
li.session_id = session_id;
time_t t = std::time(0);
li.start = *localtime(&t);
last_tab.insert(last_tab.end(), li);
log << log2 << "LC: added user: " << name << " into the last table" << logend;
}
void LastContainer::UserLogout(long user_id, long session_id)
{
LastTab::iterator i = FindNotLoggedOut(user_id, session_id);
if( i != last_tab.end() )
{
time_t t = std::time(0);
i->end = *localtime(&t);
}
else
{
log << log1 << "LC: there is no such a user to log out" << logend;
}
}

77
core/lastcontainer.h Executable file
View File

@@ -0,0 +1,77 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2009, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslucorelastcontainer
#define headerfilecmslucorelastcontainer
#include <string>
#include <list>
#include <cstring>
#include <ctime>
// how many items we store in the 'last' function
#define LAST_TABLE_SIZE 100
struct LastItem
{
long user_id;
// 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;
// ip address
unsigned int ip;
// session id (used when logging out)
long session_id;
// start logging and end logging
tm start;
tm end;
LastItem();
bool IsLoggedOut();
};
class LastContainer
{
public:
typedef std::list<LastItem> LastTab;
typedef LastTab::iterator Iterator;
public:
Iterator Begin();
Iterator End();
void UserLogin(long user_id, const std::string & name, unsigned int ip, long session_id);
void UserLogout(long user_id, long session_id);
private:
LastTab last_tab;
Iterator FindNotLoggedOut(long user_id, long session_id);
};
#endif

372
core/loadavg.cpp Executable file
View File

@@ -0,0 +1,372 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "loadavg.h"
#include "log.h"
LoadAvg::LoadAvg()
{
current1.Clear();
current5.Clear();
current15.Clear();
cache_load1 = 0.0;
cache_load5 = 0.0;
cache_load15 = 0.0;
cache_req_per_sec1 = 0.0;
cache_req_per_sec5 = 0.0;
cache_req_per_sec15 = 0.0;
was_stop_request = false;
CreateTable();
}
LoadAvg & LoadAvg::operator=(const LoadAvg & l)
{
current1 = l.current1;
current5 = l.current5;
current15 = l.current15;
cache_load1 = l.cache_load1;
cache_load5 = l.cache_load5;
cache_load15 = l.cache_load15;
cache_req_per_sec1 = l.cache_req_per_sec1;
cache_req_per_sec5 = l.cache_req_per_sec5;
cache_req_per_sec15 = l.cache_req_per_sec15;
was_stop_request = l.was_stop_request;
CreateTable();
return *this;
}
LoadAvg::LoadAvg(const LoadAvg & l)
{
operator=(l);
}
LoadAvg::~LoadAvg()
{
delete [] tab1;
delete [] tab5;
delete [] tab15;
}
void LoadAvg::CreateTable(size_t seconds, size_t granularity, Times* & tab, size_t & len)
{
len = (seconds / granularity) + 1; // rounding up (len mininum is 1)
tab = new Times[len];
for(size_t i=0 ; i<len ; ++i)
{
tab[i].Clear();
tab[i].dp = granularity; // at the beginning we assume the pause for all items
}
}
void LoadAvg::CreateTable()
{
CreateTable(60, WINIX_LOADAVG_GRANULARITY1, tab1, len1);
CreateTable(60 * 5, WINIX_LOADAVG_GRANULARITY5, tab5, len5);
CreateTable(60 * 15, WINIX_LOADAVG_GRANULARITY15, tab15, len15);
}
void LoadAvg::MoveTab(Times * tab, size_t len)
{
if( len > 1 )
{
for(size_t i=0 ; i<len-1 ; ++i)
tab[i] = tab[i+1];
}
tab[len-1].Clear();
}
void LoadAvg::UpdateTimer1()
{
MoveTab(tab1, len1);
tab1[len1-1] = current1;
current1.Clear();
cache_load1 = 0.0;
cache_req_per_sec1 = 0.0;
}
void LoadAvg::UpdateTimer5()
{
MoveTab(tab5, len5);
tab5[len5-1] = current5;
current5.Clear();
cache_load5 = 0.0;
cache_req_per_sec5 = 0.0;
}
void LoadAvg::UpdateTimer15()
{
MoveTab(tab15, len15);
tab15[len15-1] = current15;
current15.Clear();
cache_load15 = 0.0;
cache_req_per_sec15 = 0.0;
}
void LoadAvg::CheckTimers()
{
if( current1.dr + current1.dp > (double)WINIX_LOADAVG_GRANULARITY1 )
UpdateTimer1();
if( current5.dr + current5.dp > (double)WINIX_LOADAVG_GRANULARITY5 )
UpdateTimer5();
if( current15.dr + current15.dp > (double)WINIX_LOADAVG_GRANULARITY15 )
UpdateTimer15();
}
void LoadAvg::StartRequest()
{
clock_gettime(CLOCK_REALTIME, &start_req);
if( was_stop_request )
{
double dp = (start_req.tv_sec - stop_req.tv_sec);
dp += double(start_req.tv_nsec - stop_req.tv_nsec) / 1000000000.0; // make sure that tv_nsec has signed type
current1.dp += dp;
current5.dp += dp;
current15.dp += dp;
CheckTimers();
}
}
void LoadAvg::StopRequest()
{
clock_gettime(CLOCK_REALTIME, &stop_req);
double dr = (stop_req.tv_sec - start_req.tv_sec);
dr += double(stop_req.tv_nsec - start_req.tv_nsec) / 1000000000.0; // make sure that tv_nsec has signed type
current1.dr += dr;
current5.dr += dr;
current15.dr += dr;
current1.req += 1;
current5.req += 1;
current15.req += 1;
log << log2 << "LA: request took: " << dr << "s" << logend;
was_stop_request = true;
}
void LoadAvg::SumTab(Times * tab, size_t len, double expected, Times & t)
{
size_t i = len;
while( i-- > 0 && t.dr+t.dp < expected )
{
t.dr += tab[i].dr;
t.dp += tab[i].dp;
t.req += tab[i].req;
}
}
void LoadAvg::Calculate1()
{
Times t = current1;
SumTab(tab1, len1, 60.0, t);
if( t.dr+t.dp == 0.0 )
{
cache_load1 = 0.0;
cache_req_per_sec1 = 0.0;
}
else
{
cache_load1 = t.dr / (t.dr+t.dp);
cache_req_per_sec1 = t.req / (t.dr+t.dp);
}
}
void LoadAvg::Calculate5()
{
Times t = current5;
SumTab(tab5, len5, 60.0 * 5, t);
if( t.dr+t.dp == 0.0 )
{
cache_load5 = 0.0;
cache_req_per_sec5 = 0.0;
}
else
{
cache_load5 = t.dr / (t.dr+t.dp);
cache_req_per_sec5 = t.req / (t.dr+t.dp);
}
}
void LoadAvg::Calculate15()
{
Times t = current15;
SumTab(tab15, len15, 60.0 * 15, t);
if( t.dr+t.dp == 0.0 )
{
cache_load15 = 0.0;
cache_req_per_sec15 = 0.0;
}
else
{
cache_load15 = t.dr / (t.dr+t.dp);
cache_req_per_sec15 = t.req / (t.dr+t.dp);
}
}
double LoadAvg::LoadAvgNow()
{
double load = 0.0;
double dr = current1.dr;
double dp = current1.dp;
if( tab1[len1-1].dr + tab1[len1-1].dp < WINIX_LOADAVG_GRANULARITY1 * 2 )
{
dr += tab1[len1-1].dr;
dp += tab1[len1-1].dp;
}
if( dr + dp != 0.0 )
load = dr / (dr + dp);
return load;
}
double LoadAvg::LoadAvg1()
{
if( cache_load1 != 0.0 )
return cache_load1;
Calculate1();
return cache_load1;
}
double LoadAvg::LoadAvg5()
{
if( cache_load5 != 0.0 )
return cache_load5;
Calculate5();
return cache_load5;
}
double LoadAvg::LoadAvg15()
{
if( cache_load15 != 0.0 )
return cache_load15;
Calculate15();
return cache_load15;
}
double LoadAvg::ReqPerSecNow()
{
double req_per_sec = 0.0;
double dr = current1.dr;
double dp = current1.dp;
double req = current1.req;
if( tab1[len1-1].dr + tab1[len1-1].dp < WINIX_LOADAVG_GRANULARITY1 * 2 )
{
dr += tab1[len1-1].dr;
dp += tab1[len1-1].dp;
req += tab1[len1-1].req;
}
if( dr + dp != 0.0 )
req_per_sec = req / (dr + dp);
return req_per_sec;
}
double LoadAvg::ReqPerSec1()
{
if( cache_req_per_sec1 != 0.0 )
return cache_req_per_sec1;
Calculate1();
return cache_req_per_sec1;
}
double LoadAvg::ReqPerSec5()
{
if( cache_req_per_sec5 != 0.0 )
return cache_req_per_sec5;
Calculate5();
return cache_req_per_sec5;
}
double LoadAvg::ReqPerSec15()
{
if( cache_req_per_sec15 != 0.0 )
return cache_req_per_sec15;
Calculate15();
return cache_req_per_sec15;
}

114
core/loadavg.h Executable file
View File

@@ -0,0 +1,114 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslucoreloadavg
#define headerfilecmslucoreloadavg
#include <ctime>
// in seconds
#define WINIX_LOADAVG_GRANULARITY1 2
#define WINIX_LOADAVG_GRANULARITY5 15
#define WINIX_LOADAVG_GRANULARITY15 45
class LoadAvg
{
public:
LoadAvg();
~LoadAvg();
LoadAvg & operator=(const LoadAvg & l);
LoadAvg(const LoadAvg & l);
void StartRequest();
void StopRequest();
double LoadAvgNow(); // load average withing last WINIX_LOADAVG_GRANULARITY1 seconds
double LoadAvg1();
double LoadAvg5();
double LoadAvg15();
double ReqPerSecNow();
double ReqPerSec1();
double ReqPerSec5();
double ReqPerSec15();
private:
struct Times
{
double dr; // time for the request (in seconds)
double dp; // time for the pause between requestes (in seconds)
long req; // how many requests
void Clear()
{
dr = 0.0;
dp = 0.0;
req = 0;
}
Times & operator=(const Times & t)
{
dr = t.dr;
dp = t.dp;
req = t.req;
return *this;
}
};
void CheckTimers();
void UpdateTimer1();
void UpdateTimer5();
void UpdateTimer15();
Times current1;
Times current5;
Times current15;
void CreateTable(size_t seconds, size_t granulatiry, Times* & tab, size_t & len);
void CreateTable();
void MoveTab(Times * tab, size_t len);
void SumTab(Times * tab, size_t len, double expected, Times & t);
void Calculate1();
void Calculate5();
void Calculate15();
bool was_stop_request;
timespec start_req, stop_req;
Times * tab1;
size_t len1;
Times * tab5;
size_t len5;
Times * tab15;
size_t len15;
double cache_load1;
double cache_load5;
double cache_load15;
double cache_req_per_sec1;
double cache_req_per_sec5;
double cache_req_per_sec15;
};
#endif

234
core/locale.cpp Executable file
View File

@@ -0,0 +1,234 @@
/*
* 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::TableSingle::iterator i = loc_parser.table_single.begin();
for( ; i != loc_parser.table_single.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 && ReadFile(dir_def, lang, file) )
read = true;
if( dir && ReadFile(dir, lang, file) )
read = true;
if( !read )
log << log1 << "Locale: can't open locale's file: " << file << logend;
}
bool Locale::ReadFile(const char * dir, Lang lang, const char * file)
{
bool read = false;
file_name = dir;
file_name += '/';
file_name += file;
loc_parser.SplitSingle(true);
if( loc_parser.Parse(file_name) == ConfParser::ok )
{
read = true;
AddLocale(lang);
log << log3 << "Locale: read locale from: " << file_name << logend;
}
return read;
}
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::TableSingle::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::TableSingle::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();
}

71
core/locale.h Executable file
View File

@@ -0,0 +1,71 @@
/*
* 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.h"
#include <vector>
#include <string>
// !! locale nie powinny byc w templates?
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);
bool ReadFile(const char * dir, Lang lang, const char * file);
std::vector<ConfParser::TableSingle> loc_tab;
ConfParser loc_parser;
std::string file_name;
std::string empty;
Lang default_lang;
Lang current_lang;
};
#endif

View File

@@ -1,66 +1,115 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "log.h"
#include <ctime>
#include <string.h>
Log::Log()
{
log_level = 3;
current_level = 4; // nothing to log (call Init() first)
item = 0;
item_save = 1;
lines = 0;
}
void Log::Init(int log_l, const std::string & log_f, bool log_std)
void Log::Init(int log_l, const std::string & log_f, bool log_std, int log_request)
{
log_level = log_l;
log_file = log_f;
log_stdout = log_std;
item_save = log_request;
OpenFile();
}
void Log::OpenFile()
{
if( !log_file.empty() )
file.open( log_file.c_str(), std::ios_base::out | std::ios_base::app );
}
void Log::PutDate(Manipulators m)
{
time_t t = std::time(0);
std::tm * loct = std::localtime(&t);
char buffer[70];
sprintf(buffer, "%d.%02d.%02d %02d:%02d:%02d ", int(loct->tm_year + 1900),
int(loct->tm_mon + 1),
int(loct->tm_mday),
int(loct->tm_hour),
int(loct->tm_min),
int(loct->tm_sec));
(*this) << m << buffer;
}
Log & Log::operator<<(const char * s)
{
if( !s )
return *this;
buffer << s;
buffer << s;
return *this;
}
Log & Log::operator<<(const std::string & s)
{
buffer << s;
buffer << s;
return *this;
}
return *this;
Log & Log::operator<<(const std::string * s)
{
buffer << *s;
return *this;
}
Log & Log::operator<<(const void * s)
{
buffer << s;
return *this;
}
Log & Log::operator<<(int s)
{
buffer << s;
buffer << s;
return *this;
return *this;
}
Log & Log::operator<<(long s)
{
buffer << s;
buffer << s;
return *this;
return *this;
}
@@ -68,27 +117,57 @@ Log & Log::operator<<(long s)
Log & Log::operator<<(char s)
{
buffer << s;
buffer << s;
return *this;
return *this;
}
Log & Log::operator<<(size_t s)
{
buffer << s;
buffer << s;
return *this;
return *this;
}
Log & Log::operator<<(double s)
{
buffer << s;
return *this;
}
Log & Log::operator<<(Manipulators m)
{
switch(m)
{
case logend:
buffer << '\n';
lines += 1;
break;
case logsavenow:
SaveLog();
buffer.str( "" );
item = 0;
lines = 0;
break;
case logsave:
item += 1;
if( item >= item_save || lines > 3000 )
{
SaveLog();
buffer.str( "" );
item = 0;
lines = 0;
}
break;
case log1:
@@ -108,36 +187,45 @@ return *this;
}
void Log::SystemErr(int err)
{
(*this) << "errno: " << err;
const char * err_msg = strerror(err);
if( err_msg )
(*this) << " (" << err_msg << ")";
}
void Log::SaveLog()
{
int attempt = 2;
if( current_level > log_level )
return;
if( current_level > log_level )
return;
const std::string & source = buffer.str();
if( log_stdout )
std::cout << buffer.str() << std::endl;
if( source.empty() )
return;
if( log_stdout )
std::cout << source;
if( log_file.empty() )
if( log_file.empty() )
return;
if( !file )
{
file.close();
file.clear();
OpenFile();
if( !file )
return;
}
std::ofstream file;
do
{
file.open( log_file.c_str(), std::ios_base::out | std::ios_base::app );
// if( !file )
// sleep(1);
}
while( --attempt > 0 && !file );
if( !file )
return;
file << buffer.str() << std::endl;
file << source << std::endl;
}

View File

@@ -1,14 +1,14 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilelog
#define headerfilelog
#ifndef headerfilecmslucorelog
#define headerfilecmslucorelog
#include <sstream>
@@ -19,7 +19,7 @@
// !! 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 { logend, log1, log2, log3 };
enum Manipulators { logsave, logsavenow, logend, log1, log2, log3 };
@@ -27,29 +27,41 @@ 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);
void Init(int log_l, const std::string & log_f, bool log_std, int log_request);
void PutDate(Manipulators m);
Log & operator<<(const char * s);
Log & operator<<(const void * s);
Log & operator<<(const std::string * s);
Log & operator<<(const std::string & s);
Log & operator<<(int s);
Log & operator<<(long s);
Log & operator<<(char s);
Log & operator<<(size_t s);
Log & operator<<(double s);
Log & operator<<(Manipulators m);
void SystemErr(int err);
void SaveLog();
};
extern Log log;
extern Log nlog;

View File

@@ -1,118 +0,0 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* All rights reserved.
*
*/
#include <cstdlib>
#include <ctime>
#include <signal.h>
#include <iostream>
#include "requestcontroller.h"
#include "data.h"
#include "log.h"
#include "request.h"
#include "db.h"
#include "config.h"
// singletons
// first 'data' then 'log' then 'request'
Data data;
Log log;
Request request;
Db db;
Config config;
void signal_term(int)
{
log << log1 << "cmslu stopped" << logend;
exit(0);
}
void signal_hup(int)
{
log << log3 << "SIGHUP received" << logend;
data.signal_hup = true;
config.ReadConfig(false); /* errors not to stdout */
}
void print_syntax()
{
std::cout << "Syntax:" << std::endl;
std::cout << " cmslu.fcgi config_file" << std::endl;
}
int main(int argv, char ** argc)
{
RequestController req_controller;
std::srand(std::time(0));
if( argv != 2 )
{
print_syntax();
return 1;
}
data.config_file = argc[1];
if( !config.ReadConfig(true) ) /* errors to stdout */
return 2;
// closing descriptors only at the beginning
close(2);
if( !data.log_stdout )
{
close(1);
data.stdout_is_closed = true;
}
signal(SIGTERM, signal_term);
signal(SIGINT, signal_term);
signal(SIGHUP, signal_hup);
while( true )
{
log.Init(data.log_level, data.log_file, data.log_stdout);
db.Init(data.db_database, data.db_user, data.db_pass);
if( !req_controller.Init() )
return 1;
log << log2 << "checking for table consistency:" << logend;
// !! zrobic wyjatek dla root
//db.CheckAllUrlSubject();
log << log1 << "cmslu started" << logend;
req_controller.Loop();
if( data.signal_hup )
data.signal_hup = false;
}
return 0;
}

View File

@@ -1,13 +1,16 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include <sys/types.h>
#include <sys/stat.h>
#include "misc.h"
#include "log.h"
@@ -47,11 +50,33 @@ return false;
}
void CorrectUrl(Item & item)
// this function checks how many dots there are in the url
// if there are more than one (last) dot then the first dots will be changed into '_'
void CorrectUrlDots(std::string & url)
{
size_t i = url.size();
bool was_dot = false;
while( i-- > 0 )
{
if( url[i] == '.' )
{
if( was_dot )
// only one dot is allowed
url[i] = '_';
was_dot = true;
}
}
}
void CorrectUrlChars(std::string & url)
{
std::string::iterator i;
for(i = item.url.begin(); i!=item.url.end() ; ++i)
for(i=url.begin(); i != url.end() ; ++i)
{
if( !CorrectUrlChar(*i) )
{
@@ -63,49 +88,35 @@ std::string::iterator i;
*i = '_';
}
}
if( item.url.empty() )
item.url = "bez_nazwy"; // !! wrzucic do pliku konfiguracyjnego
else
if( item.url[0] >= '0' && item.url[0] <= '9' )
// url must begin with a letter
item.url.insert(item.url.begin(), '_');
}
void SetUrlFromSubject(Item & item)
void CorrectUrlOnlyAllowedChar(std::string & url)
{
item.url = item.subject;
CorrectUrl(item);
CorrectUrlDots(url);
CorrectUrlChars(url);
ToSmall(url);
Trim(url, '_');
/*
std::string::iterator i;
item.url.clear();
for(i = item.subject.begin(); i!=item.subject.end() ; ++i)
if( url.empty() || url == "." )
{
int c = ChangeLocalChar(*i);
if( (c >= 'a' && c <='z') ||
(c >= 'A' && c <='Z') ||
(c >= '0' && c <='9') ||
(c == '(' || c == ')' || c == '.' || c == ',' || c == '_' )
)
{
item.url += c;
}
else
item.url += '_';
// !! brakuje config->
//if( config->item_url_empty.empty() )
url = "unnamed";
//else
//{
// url = config->item_url_empty;
// CorrectUrlDots(url);
// CorrectUrlChars(url);
// ToSmall(url);
// we don't trim here and the string will not be empty
//}
}
if( item.url.empty() )
item.url = "bez_nazwy"; // !! wrzucic do pliku konfiguracyjnego
else
if( item.url[0] >= '0' && item.url[0] <= '9' )
if( url[0] >= '0' && url[0] <= '9' )
// url must begin with a letter
item.url.insert(item.url.begin(), '_');
*/
url.insert(url.begin(), '_');
}
@@ -156,21 +167,38 @@ return c;
}
bool HtmlTryChar(std::ostringstream & out, int c)
{
if( c == '<' )
{
out << "&lt;";
return true;
}
else
if( c == '>' )
{
out << "&gt;";
return true;
}
else
if( c == '&' )
{
out << "&amp;";
return true;
}
return false;
}
void HtmlEscape(std::ostringstream & out, const std::string & in)
{
std::string::const_iterator i;
for(i = in.begin() ; i != in.end() ; ++i)
{
if( *i == '<' )
out << "&lt;";
else
if( *i == '>' )
out << "&gt;";
else
if( *i == '&' )
out << "&amp;";
else
if( !HtmlTryChar(out, *i) )
out << *i;
}
}
@@ -186,5 +214,571 @@ return out.str();
}
void HtmlEscapeFormTxt(std::ostringstream & out, const std::string & in)
{
std::string::const_iterator i;
int was_enter = 0; // how many enteres there were before
if( in.empty() )
return;
out << "<p>";
// skipping first new line characters
for(i = in.begin() ; i != in.end() && (*i==13 || *i==10) ; ++i);
for( ; i != in.end() ; ++i )
{
if( *i == 13 ) // skipping stupid characters (\r\n\ in dos mode)
continue;
if( *i == 10 )
{
++was_enter;
}
else
{
if( was_enter == 1 )
out << "<br>\n";
else
if( was_enter > 1 )
out << "</p>\n<p>";
was_enter = 0;
}
if( !HtmlTryChar(out, *i) )
out << *i;
}
out << "</p>\n";
}
std::string HtmlEscapeFormTxt(const std::string & in)
{
std::ostringstream out;
HtmlEscapeFormTxt(out, in);
return out.str();
}
const char * DateToStr(int year, int month, int day)
{
static const char * month_letter[] = { "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X", "XI", "XII" };
static char buffer[100];
--month;
if( month < 0 )
month = 0;
if( month > 11 )
month = 11;
if( year == 0 )
sprintf(buffer, "%s %02d", month_letter[month], day);
else
sprintf(buffer, "%02d %s %02d", year, month_letter[month], day);
// warning: not thread safe (we do not use threads)
return buffer;
}
const char * DateToStr(int year, int month, int day, int hour, int min, int sec)
{
static const char * month_letter[] = { "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X", "XI", "XII" };
static char buffer[100];
--month;
if( month < 0 )
month = 0;
if( month > 11 )
month = 11;
if( year == 0 )
sprintf(buffer, "%s %02d %02d:%02d:%02d", month_letter[month], day, hour, min, sec);
else
sprintf(buffer, "%02d %s %02d %02d:%02d:%02d", year, month_letter[month], day, hour, min, sec);
// warning: not thread safe (we do not use threads)
return buffer;
}
const char * DateToStr(tm * ptm)
{
return DateToStr(ptm->tm_year + 1900, ptm->tm_mon+1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
}
const char * DateToStr(time_t t)
{
tm * ptm = std::localtime(&t);
return DateToStr(ptm);
}
const char * DateToStrWithoutHours(tm * ptm)
{
return DateToStr(ptm->tm_year + 1900, ptm->tm_mon+1, ptm->tm_mday);
}
const char * DateToStrWithoutHours(time_t t)
{
tm * ptm = std::localtime(&t);
return DateToStrWithoutHours(ptm);
}
// this format is used with cookies
const char * DateToStrCookie(int year, int month, int day, int hour, int min, int sec)
{
static const char * month_str[]={ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
static char buffer[100];
--month;
if( month < 0 )
month = 0;
if( month > 11 )
month = 11;
sprintf(buffer, "%02d-%s-%04d %02d:%02d:%02d", day, month_str[month], year, hour, min, sec);
return buffer;
}
const char * DateToStrCookie(tm * ptm)
{
return DateToStrCookie(ptm->tm_year + 1900, ptm->tm_mon+1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
}
const char * DateToStrCookie(time_t t)
{
tm * ptm = std::localtime(&t);
return DateToStrCookie(ptm);
}
const char * IpToStr(unsigned int ip_)
{
static char buffer[100];
union
{
unsigned int ip;
unsigned char c[4];
} ip;
ip.ip = ip_;
sprintf(buffer, "%u.%u.%u.%u", (int)ip.c[0], (int)ip.c[1], (int)ip.c[2], (int)ip.c[3]);
return buffer;
}
const char * ToStr(int value)
{
static char buffer[100];
sprintf(buffer, "%d", value);
return buffer;
}
bool IsWhite(int s)
{
if( s==' ' || s=='\t' || s==13 || s==160 )
return true;
return false;
}
void TrimWhite(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);
}
void Trim(std::string & s, char c)
{
std::string::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, std::string::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);
}
const char * SkipWhite(const char * s)
{
while( IsWhite(*s) )
++s;
return s;
}
int ToSmall(int c)
{
if( c>='A' && c<='Z' )
c = c - 'A' + 'a';
return c;
}
void ToSmall(std::string & s)
{
std::string::size_type i;
for(i=0 ; i<s.size() ; ++i)
s[i] = ToSmall(s[i]);
}
bool IsSubString(const char * short_str, const char * long_str)
{
while( *short_str && *long_str && *short_str == *long_str )
{
++short_str;
++long_str;
}
if( *short_str == 0 )
return true;
return false;
}
bool IsSubStringNoCase(const char * short_str, const char * 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;
}
bool EqualNoCase(const char * str1, const char * str2)
{
while( *str1 && *str2 && ToSmall(*str1) == ToSmall(*str2) )
{
++str1;
++str2;
}
if( *str1 == 0 && *str2 == 0 )
return true;
return false;
}
bool ValidateEmail(const std::string & email)
{
if( email.empty() )
return false;
bool correct = true;
size_t i;
char allowed_chars[] = "!#$%&'*+-/=?^_`{|}~.@";
int at = 0;
for(i=0 ; i<email.length() && correct ; ++i)
{
correct = false;
if( (email[i] >= 'A' && email[i]<='Z') ||
(email[i] >= 'a' && email[i]<='z') ||
(email[i] >= '0' && email[i]<='9') )
{
correct = true;
}
else
{
for(size_t a=0 ; a < sizeof(allowed_chars)-1 ; ++a)
{
if( email[i] == allowed_chars[a] )
{
correct = true;
break;
}
}
}
if( email[i] == '@' )
++at;
}
if( at != 1 )
return false;
return correct;
}
bool IsFile(const char * file)
{
struct stat sb;
return (stat(file, &sb) == 0);
}
bool IsFile(const std::string & file)
{
return IsFile(file.c_str());
}
bool CreateDir(const char * dir, int priv)
{
if( !IsFile(dir) )
{
if( mkdir(dir, priv) < 0 )
{
log << log1 << "Can't create a directory on fs: " << dir << logend;
return false;
}
}
return true;
}
bool CreateDir(const std::string & dir, int priv)
{
return CreateDir(dir.c_str(), priv);
}
// creating directories (can be more than one)
// 'dirs' can begin with a slash (will be skipped)
bool CreateDirs(const char * base_dir, const char * dirs, int priv)
{
static std::string temp;
const char * p = dirs;
temp = base_dir; // we start creating from 'base_dir'
if( temp.empty() )
return false;
if( temp[temp.size()-1] != '/' )
temp += '/';
while( true )
{
// skipping slashes
for( ; *p=='/' ; ++p );
if( *p == 0 )
break;
// taking the name
for( ; *p && *p!='/' ; ++p )
temp += *p;
if( !CreateDir(temp.c_str(), priv) )
return false;
temp += '/';
}
return true;
}
bool CreateDirs(const std::string & base_dir, const std::string & dirs, int priv)
{
return CreateDirs(base_dir.c_str(), dirs.c_str(), priv);
}
bool CopyFile(FILE * in, FILE * out)
{
char buf[1024];
size_t buflen = sizeof(buf)/sizeof(char);
size_t len;
do
{
len = fread(buf, 1, buflen, in);
if( len > 0 )
fwrite(buf, 1, len, out);
if( ferror(in) || ferror(out) )
return false;
}
while( !feof(in) );
return true;
}
bool CopyFile(const char * src, const char * dst)
{
FILE * in, * out;
in = fopen(src, "rb");
if( !in )
return false;
out = fopen(dst, "wb");
if( !out )
{
fclose(in);
return false;
}
bool res = CopyFile(in, out);
fclose(in);
fclose(out);
if( res && ferror(out) )
res = false;
if( !res )
remove(dst);
return res;
}
bool CopyFile(const std::string & src, const std::string & dst)
{
return CopyFile(src.c_str(), dst.c_str());
}
// if there is not an extension it returns a pointer to the last '\0' character
const char * GetFileExt(const char * name)
{
size_t i, ilast;
// looking for the end of the name
for(i=0 ; name[i] != 0 ; ++i);
if( i == 0 )
return name; // ops, the name is empty
// remember the end of the string
ilast = i;
// looking for the last dot
for(--i ; i>0 && name[i] != '.' ; --i);
if( name[i] != '.' )
return name + ilast; // ops, there is not a dot
// the extensions starts from i+1
// and can be empty (if the last character is a dot)
return name + i + 1;
}
Item::Auth SelectFileType(const char * file_name)
{
const char * ext = GetFileExt(file_name);
// as an image we're using only those types which can be rendered
// by a web browser
if( EqualNoCase(ext, "jpg") ||
EqualNoCase(ext, "jpeg") ||
EqualNoCase(ext, "jpe") ||
EqualNoCase(ext, "pic") ||
EqualNoCase(ext, "tga") ||
EqualNoCase(ext, "gif") ||
EqualNoCase(ext, "bmp") ||
EqualNoCase(ext, "png") )
return Item::auth_image;
if( EqualNoCase(ext, "pdf") ||
EqualNoCase(ext, "doc") ||
EqualNoCase(ext, "xls") ||
EqualNoCase(ext, "txt") ||
EqualNoCase(ext, "ods") ||
EqualNoCase(ext, "odt") )
return Item::auth_document;
return Item::auth_other;
}

View File

@@ -1,36 +1,76 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilemisc
#define headerfilemisc
#ifndef headerfilecmslucoremisc
#define headerfilecmslucoremisc
#include <string>
#include <sstream>
#include "log.h"
#include <ctime>
#include "item.h"
#include <cstdio>
#define MAJOR_VER 0
#define MINOR_VER 2
#define REVISION_VER 0
void ToString(std::string & s, int value);
void ToString(std::string & s, long value);
int ChangeLocalChar(unsigned char c);
bool CorrectUrlChar(char c);
void CorrectUrl(Item & item);
void SetUrlFromSubject(Item & item);
void CorrectUrlDots(std::string & url);
void CorrectUrlChars(std::string & url);
void CorrectUrlOnlyAllowedChar(std::string & url);
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);
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);
const char * DateToStrWithoutHours(tm * ptm);
const char * 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(time_t t);
const char * IpToStr(unsigned int ip_);
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);
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);
bool CopyFile(FILE * in, FILE * out);
bool CopyFile(const char * src, const char * dst);
bool CopyFile(const std::string & src, const std::string & dst);
const char * GetFileExt(const char * name);
Item::Auth SelectFileType(const char * file_name);
#endif

191
core/mount.cpp Executable file
View File

@@ -0,0 +1,191 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2009, Tomasz Sowa
* All rights reserved.
*
*/
#include "mount.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" },
{ par_html_template, "html_template" },
};
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;
}
void Mount::ClearParams()
{
size_t i;
for(i=0 ; i<param.size() ; ++i)
param[i].Clear();
}
bool Mount::IsPar(Mount::ParamCode code)
{
if( !param[code].defined )
return false;
return true;
}
bool Mount::IsArg(Mount::ParamCode code, const char * arg)
{
ParamArg::iterator i;
if( !param[code].defined )
return false;
for(i=param[code].arg.begin() ; i!=param[code].arg.end() ; ++i)
{
if( *i == arg )
return true;
}
return false;
}
bool Mount::IsArg(Mount::ParamCode code, const std::string & arg)
{
return IsArg(code, arg.c_str());
}
bool Mount::IsArg(Mount::ParamCode code, int arg)
{
ParamArg::iterator i;
if( !param[code].defined )
return false;
for(i=param[code].arg.begin() ; i!=param[code].arg.end() ; ++i)
{
if( atoi(i->c_str()) == arg )
return true;
}
return false;
}
const std::string * Mount::HtmlTemplate() const
{
if( !param[par_html_template].defined )
return 0;
if( param[par_html_template].arg.size() != 1 )
return 0;
return & param[par_html_template].arg[0];
}

111
core/mount.h Executable file
View File

@@ -0,0 +1,111 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2009, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslucoremount
#define headerfilecmslucoremount
#include <map>
#include <string>
#include <vector>
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_html_template,
par_none
};
typedef std::vector<std::string> ParamArg;
struct ParamRow
{
bool defined;
ParamArg arg;
ParamRow() { defined = false; }
void Clear() { defined = false; arg.clear(); }
};
typedef std::vector<ParamRow> Param;
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(Mount::ParamCode code);
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 a name to html template (can be null if not defined)
const std::string * HtmlTemplate() const;
};
#endif

374
core/mountparser.cpp Executable file
View File

@@ -0,0 +1,374 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "mountparser.h"
#include "log.h"
#include "misc.h"
void MountParser::SetDirs(Dirs * pdirs)
{
dirs = pdirs;
}
bool MountParser::IsWhite(int c)
{
if( c==' ' || c=='\t' || c==13 || c==160 )
return true;
return false;
}
void MountParser::SkipWhite()
{
while( IsWhite(*pinput) )
++pinput;
}
void MountParser::SkipLine()
{
while( *pinput && *pinput != 10 )
++pinput;
if( *pinput == 10 )
++pinput;
}
void MountParser::ReadWordQuote(std::string & res)
{
++pinput;
while( *pinput && *pinput!=10 && *pinput!='\"' )
{
if( pinput[0]=='\\' && pinput[1]=='\"' )
{
res += '\"';
pinput += 2;
}
else
if( pinput[0]=='\\' && pinput[1]=='\\' )
{
res += '\\';
pinput += 2;
}
else
{
res += *pinput;
pinput += 1;
}
}
if( *pinput == '"' )
++pinput;
}
// a white character is the separator
void MountParser::ReadWordWhite(std::string & res)
{
while( *pinput && *pinput!=10 && !IsWhite(*pinput) )
{
res += *pinput;
++pinput;
}
}
// the comma or the second bracket ')' are the separators
void MountParser::ReadWordComma(std::string & res)
{
while( *pinput && *pinput!=10 && *pinput!=',' && *pinput!=')' )
{
res += *pinput;
++pinput;
}
// trimming last white characters
// (white characters can be in the middle of the string)
TrimWhite(res);
}
void MountParser::ReadWord(std::string & res, bool comma_bracket_separator)
{
res.clear();
SkipWhite();
if( *pinput == '"' )
{
ReadWordQuote(res);
}
else
if( comma_bracket_separator )
{
ReadWordComma(res);
}
else
{
ReadWordWhite(res);
}
}
void MountParser::ReadParamArgsLoop(Mount::ParamArg & args)
{
SkipWhite();
while( *pinput && *pinput!=10 && *pinput!=')' )
{
ReadWord(temp_arg, true);
if( !temp_arg.empty() )
args.push_back(temp_arg);
if( *pinput == ',' )
++pinput;
}
}
void MountParser::ReadParamArgs(Mount::ParamArg & args)
{
SkipWhite();
args.clear();
if( *pinput == '(' )
{
++pinput;
ReadParamArgsLoop(args);
if( *pinput != ')' )
{
// there should be ')' at the end
// temporarily we do nothing
}
else
{
++pinput;
}
}
}
void MountParser::ReadParamName(std::string & res)
{
SkipWhite();
res.clear();
while( *pinput && *pinput!=10 && *pinput!=',' && *pinput!='(' && !IsWhite(*pinput) )
{
res += *pinput;
++pinput;
}
}
void MountParser::ReadParam(std::string & res, Mount::ParamArg & args)
{
ReadParamName(res);
if( res.empty() )
return;
ReadParamArgs(args);
SkipWhite();
if( *pinput == ',' )
++pinput;
}
void MountParser::ReadMountType()
{
ReadWord(temp);
if( temp.empty() )
{
// an empty line (some white characters only)
err = WINIX_ERR_EMPTY;
}
else
if( temp == "cms" )
{
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;
}
else
{
err = WINIX_ERR_MOUNT_UNKNOWN;
log << log1 << "MP: unknown mount type: " << temp << logend;
}
}
void MountParser::ReadMountPoint()
{
ReadWord(temp);
pdir = dirs->GetDir(temp);
if( pdir )
{
mount.dir_id = pdir->id;
log << log3 << "MP: mount point: " << temp << logend;
}
else
{
err = WINIX_ERR_NO_MOUNTPOINT;
log << log1 << "MP: there is no such a mount point: " << temp << logend;
}
}
void MountParser::ReadFs()
{
ReadWord(temp);
if( temp == "simplefs" )
{
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;
}
else
{
err = WINIX_ERR_UNKNOWN_FILESYSTEM;
log << log1 << "MP: unknown filesystem: " << temp << logend;
}
}
void MountParser::LogMountParams()
{
size_t i;
log << log3 << "MP: mount param: " << temp << "(";
for(i=0 ; i<param_args.size() ; ++i)
{
log << param_args[i];
if( i != param_args.size()-1 )
log << ",";
}
log << ")" << logend;
}
void MountParser::ReadMountParams()
{
mount.ClearParams();
for( ReadParam(temp, param_args) ; !temp.empty() ; ReadParam(temp, param_args) )
{
Mount::ParamCode p = Mount::ParseParam(temp.c_str());
if( p != Mount::par_none )
{
mount.param[p].defined = true;
mount.param[p].arg = param_args;
LogMountParams();
}
else
{
log << log1 << "MP: unknown mount param: " << temp << " (skipped)" << logend;
}
}
}
void MountParser::ReadRow(std::map<long, Mount> & output)
{
ReadMountType();
if( err == WINIX_ERR_EMPTY )
{
err = WINIX_ERR_OK;
SkipLine();
return;
}
if( err == WINIX_ERR_OK )
ReadMountPoint();
if( err == WINIX_ERR_OK )
ReadFs();
if( err == WINIX_ERR_OK )
ReadMountParams();
if( err == WINIX_ERR_OK )
{
std::pair<std::map<long, Mount>::iterator, bool> res = output.insert( std::make_pair(mount.dir_id, mount) );
if( !res.second )
log << log1 << "MP: this mount point exists (skipped)" << logend;
}
SkipLine();
}
Error MountParser::Parse(const std::string & input, std::map<long, Mount> & output)
{
pinput = input.c_str();
err = WINIX_ERR_OK;
output.clear();
while( *pinput && err == WINIX_ERR_OK )
ReadRow(output);
return err;
}

68
core/mountparser.h Executable file
View File

@@ -0,0 +1,68 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslucoremountparser
#define headerfilecmslucoremountparser
#include <map>
#include <string>
#include <vector>
#include <stdlib.h>
#include <limits.h>
#include "mount.h"
#include "item.h"
#include "error.h"
#include "dirs.h"
class MountParser
{
public:
Error Parse(const std::string & input, std::map<long, Mount> & output);
void SetDirs(Dirs * pdirs);
private:
Dirs * dirs;
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 ReadMountType();
void ReadMountPoint();
void ReadFs();
void LogMountParams();
void ReadMountParams();
void ReadRow(std::map<long, Mount> & output);
const char * pinput;
std::string temp;
std::string temp_arg;
Mount::ParamArg param_args;
Mount mount;
Item * pdir;
Error err;
};
#endif

174
core/mounts.cpp Executable file
View File

@@ -0,0 +1,174 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2009, Tomasz Sowa
* All rights reserved.
*
*/
#include "mounts.h"
#include "request.h"
#include "log.h"
#include "mountparser.h"
#include "db.h"
Mounts::Mounts()
{
pmount = 0;
}
void Mounts::SetDirs(Dirs * pdirs)
{
dirs = pdirs;
}
void Mounts::SetDb(Db * pdb)
{
db = pdb;
}
void Mounts::SetRequest(Request * prequest)
{
request = prequest;
}
// reading from 'mounts'
Error Mounts::ReadMounts(const std::string & mounts)
{
MountParser mp;
mp.SetDirs(dirs);
Error err = mp.Parse(mounts, mount_tab);
if( err != WINIX_ERR_OK )
{
log << log1 << "M: some problems with mountpoints (mountpoints table will be empty)" << logend;
mount_tab.clear();
}
CalcCurMount();
return err;
}
// reading from /etc/fstab
Error Mounts::ReadMounts()
{
static std::string file = "fstab";
Item * etc = dirs->GetEtcDir();
if( !etc )
{
log << log1 << "M: there is no /etc directory" << logend;
return WINIX_ERR_NO_ITEM;
}
Item fstab;
Error err = db->GetItem(etc->id, file, fstab);
if( err == WINIX_ERR_NO_ITEM )
{
log << log1 << "M: there is no /etc/fstab file" << logend;
return err;
}
if( err != WINIX_ERR_OK )
{
log << log1 << "M: cannot read /etc/fstab" << logend;
return err;
}
return ReadMounts(fstab.content);
}
void Mounts::MountCmsForRoot()
{
Mount mount;
mount.type = Mount::cms;
mount.fs = Mount::simplefs;
Item * proot = dirs->GetRootDir();
if( proot )
mount.dir_id = proot->id;
else
{
mount.dir_id = -1;
log << log1 << "M: there is no a root dir" << logend;
}
std::pair<MountTab::iterator, bool> res = mount_tab.insert( std::make_pair(mount.dir_id, mount) );
pmount = &(res.first->second);
}
void Mounts::CalcCurMount()
{
std::vector<Item*>::reverse_iterator i;
// when the program starts (when the dir_table is empty()
// we don't want to call MountCmsForRoot()
if( request->dir_table.empty() )
return;
for(i = request->dir_table.rbegin() ; i!=request->dir_table.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;
return;
}
}
// 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;
}
// can return null pointer
// and we don't assume cms as a default mount point if nothing is found
Mount * Mounts::CalcMount(long dir_id)
{
while( true )
{
Item * pdir = dirs->GetDir(dir_id);
if( !pdir )
return 0;
std::map<long, Mount>::iterator m = mount_tab.find( pdir->id );
if( m != mount_tab.end() )
return &(m->second);
dir_id = pdir->parent_id;
}
}
const Mounts::MountTab * Mounts::GetMountTab()
{
return &mount_tab;
}

63
core/mounts.h Executable file
View File

@@ -0,0 +1,63 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2009, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslucorecoremounts
#define headerfilecmslucorecoremounts
#include <map>
#include <string>
#include "mount.h"
#include "error.h"
#include "dirs.h"
#include "db.h"
#include "request.h"
class Mounts
{
public:
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);
Error ReadMounts();
void CalcCurMount();
Mount * CalcMount(long dir_id);
// current mount point
// will not be null after calling CalcCurMount() or ReadMounts([...])
Mount * pmount;
const MountTab * GetMountTab();
private:
Dirs * dirs;
Db * db;
Request * request;
MountTab mount_tab;
void MountCmsForRoot();
};
#endif

288
core/notify.cpp Executable file
View File

@@ -0,0 +1,288 @@
/*
* 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 "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;
void Notify::SetRequest(Request * prequest)
{
request = prequest;
}
void Notify::SetConfig(Config * pconfig)
{
config = pconfig;
}
void Notify::SetSystem(System * psystem)
{
system = psystem;
}
void Notify::SetTemplatesNotify(TemplatesNotify * ptemplates_notify)
{
templates_notify = ptemplates_notify;
}
/*
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 = config->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 = system->mounts.pmount->type;
n.doc_base_url = config->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=system->users.Begin() ; i != system->users.End() ; ++i)
{
sending = false;
if( system->mounts.pmount->type == Mount::thread )
{
if( (i->thread_notify & notify_code) != 0 )
sending = true;
}
else
if( system->mounts.pmount->type == Mount::cms )
{
if( (i->cms_notify & notify_code) != 0 )
sending = true;
}
if( sending )
{
n.email = i->email;
n.lang = Locale::StrToLang(config->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();
}

91
core/notify.h Executable file
View File

@@ -0,0 +1,91 @@
/*
* 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"
#include "request.h"
#include "config.h"
#include "system.h"
#include "users.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 SetRequest(Request * prequest);
void SetConfig(Config * pconfig);
void SetSystem(System * psystem);
void SetTemplatesNotify(TemplatesNotify * ptemplates_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:
Request * request;
Config * config;
System * system;
TemplatesNotify * templates_notify;
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;
};
#endif

322
core/plugin.cpp Executable file
View File

@@ -0,0 +1,322 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include <dlfcn.h>
#include "plugin.h"
#include "pluginmsg.h"
void Plugin::UnloadPlugins()
{
size_t i;
slots.clear();
for(i=0 ; i<plugins.size() ; ++i)
dlclose(plugins[i].handle);
plugins.clear();
}
Plugin::Plugin()
{
current_plugin = -1;
request = 0;
db = 0;
config = 0;
request = 0;
system = 0;
functions = 0;
templates = 0;
session_manager = 0;
}
Plugin::~Plugin()
{
UnloadPlugins();
}
void Plugin::SetDb(Db * pdb)
{
db = pdb;
}
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::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 && 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.session_manager = session_manager;
return res;
}
void Plugin::LoadPlugins(const std::vector<std::string> & plugins)
{
size_t i;
for(i=0 ; i<plugins.size() ; ++i)
LoadPlugin(plugins[i]);
}
void Plugin::LoadPlugin(const std::string & filename)
{
LoadPlugin(filename.c_str());
}
void * Plugin::LoadInitFun(const char * filename, Fun1 & fun_init)
{
void * p = dlopen(filename, RTLD_NOW | RTLD_LOCAL);
if( !p )
{
log << log1 << "Plugin: cannot load a plugin: \"" << filename << "\"" << logend;
log << log1 << "Plugin: dlerror: " << dlerror() << logend;
return 0;
}
fun_init = (Fun1)dlfunc(p, "Init");
if( !fun_init )
{
log << log1 << "Plugin: cannot load a plugin: " << filename
<< " (there is no Init() function)" << logend;
dlclose(p);
return 0;
}
log << log1 << "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;
if( !(plugin_handle = LoadInitFun(filename, fun_init)) )
return;
info.Clear();
old_current_plugin = current_plugin;
current_plugin = (int)plugins.size();
info.plugin_id = current_plugin;
fun_init(info);
PluginsItem item;
item.handle = plugin_handle;
item.plugin_name = reinterpret_cast<const char *>(info.p1);
plugins.push_back(item);
current_plugin = old_current_plugin;
}
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 )
{
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;
}
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);
int old_current_plugin = current_plugin;
for( ; i!=slots.end() && i->first==message ; ++i )
{
info.Clear();
info.p1 = p1_;
info.p2 = p2_;
info.l1 = l1_;
info.l2 = l2_;
Call(message, i);
}
current_plugin = old_current_plugin;
}
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();
}
void Plugin::Assign(int message, Fun1 fun1)
{
Slot s;
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;
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;
}

197
core/plugin.h Executable file
View File

@@ -0,0 +1,197 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmsluplugin
#define headerfilecmsluplugin
#include <vector>
#include <string>
#include <map>
#include "pluginmsg.h"
#include "log.h"
#include "plugindata.h"
#include "config.h"
#include "request.h"
#include "system.h"
#include "sessionmanager.h"
#include "functions/functions.h"
#include "templates/templates.h"
/*
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
{
// 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;
// objects from winix which are accessible from a plugin
Db * db;
Config * config;
Request * request;
System * system;
Functions * functions;
Templates * templates;
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?
// function return status
// default: false (if not set by the plugin)
bool ret;
void Clear()
{
// 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;
}
};
class Plugin
{
public:
// index of a plugin which is called by Call() method
// 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);
struct Slot
{
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 SetSessionManager(SessionManager * psession_manager);
void LoadPlugin(const char * filename);
void LoadPlugin(const std::string & filename);
void LoadPlugins(const std::vector<std::string> & plugins);
void UnloadPlugins();
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();
// 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;
SessionManager * session_manager;
struct PluginsItem
{
void * handle;
const char * 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;
PluginInfo info;
void * LoadInitFun(const char * filename, Fun1 & fun_init);
void Call(int message, Slots::iterator & slot);
bool SetPointers(PluginInfo & info);
};
extern Plugin plugin;
#endif

125
core/plugindata.cpp Executable file
View File

@@ -0,0 +1,125 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "plugindata.h"
#include "plugin.h"
#include "log.h"
void PluginData::Assign(size_t index, PluginDataBase * data)
{
if( index >= table.size() )
Resize(index+1);
table[index] = data;
}
void PluginData::Assign(PluginDataBase * data)
{
if( plugin.current_plugin == -1 )
{
log << log1 << "PD: Assign(PluginDataBase*) should be called only from plugins" << logend;
return;
}
Assign(plugin.current_plugin, data);
}
PluginDataBase * PluginData::Get(size_t index)
{
if( index >= table.size() )
Resize(index+1);
return table[index];
}
PluginDataBase * PluginData::Get()
{
if( plugin.current_plugin == -1 )
{
log << log1 << "PD: Get() should be called only from plugins" << logend;
return 0;
}
return Get(plugin.current_plugin);
}
void PluginData::DeleteAll()
{
if( table.empty() )
return;
plugin.Call(WINIX_SESSION_REMOVE);
for(size_t i=0 ; i<table.size() ; ++i)
table[i] = 0;
}
PluginData::PluginData()
{
}
PluginData::PluginData(const PluginData & p)
{
operator=(p);
}
PluginData & PluginData::operator=(const PluginData & p)
{
// we don't copy all pointers - only resize the table
// pointers will be set to zero
Resize(p.Size());
return *this;
}
PluginData::~PluginData()
{
DeleteAll();
}
size_t PluginData::Size() const
{
return table.size();
}
void PluginData::Resize(size_t new_size)
{
size_t old_size = table.size();
if( old_size == new_size )
return;
table.resize(new_size);
for(size_t i = old_size ; i<new_size ; ++i)
table[i] = 0;
}

56
core/plugindata.h Executable file
View File

@@ -0,0 +1,56 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslucoreplugindata
#define headerfilecmslucoreplugindata
#include <vector>
struct PluginDataBase
{
virtual ~PluginDataBase() {}
};
class PluginData
{
public:
void Assign(size_t index, PluginDataBase * data);
void Assign(PluginDataBase * data);
PluginDataBase * Get(size_t index);
PluginDataBase * Get();
void DeleteAll();
PluginData();
PluginData(const PluginData & p);
PluginData & operator=(const PluginData & p);
~PluginData();
size_t Size() const;
void Resize(size_t new_size);
private:
std::vector<PluginDataBase*> table;
};
#endif

50
core/pluginmsg.h Executable file
View File

@@ -0,0 +1,50 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#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 attach your own session data (based on PluginDataBase class)
// call request.session->plugin_data.Assign(pointer)
#define WINIX_SESSION_CREATED 3000
// here you should remove your session data
#define WINIX_SESSION_REMOVE 3001
// when a session is changed (you can save a pointer to your data here)
#define WINIX_SESSION_CHANGED 3002
// the winix is closing
#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
#endif

565
core/postmultiparser.cpp Executable file
View File

@@ -0,0 +1,565 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "postmultiparser.h"
#include "log.h"
PostMultiParser::PostMultiParser()
{
in_buffer = new unsigned char[WINIX_POSTMULTI_INPUT_BUFFER];
}
PostMultiParser::PostMultiParser(const PostMultiParser & p)
{
in_buffer = new unsigned char[WINIX_POSTMULTI_INPUT_BUFFER];
config = p.config;
}
PostMultiParser & PostMultiParser::operator=(const PostMultiParser & p)
{
in_buffer = new unsigned char[WINIX_POSTMULTI_INPUT_BUFFER];
config = p.config;
return *this;
}
PostMultiParser::~PostMultiParser()
{
delete [] in_buffer;
}
void PostMultiParser::SetConfig(Config * pconfig)
{
config = pconfig;
}
void PostMultiParser::ReadBoundary()
{
boundary.clear();
while( last != -1 && last != 10 && last != 13 )
{
boundary += last;
ReadChar();
}
if( last == 13 )
{
ReadChar();
line_end_dos = true;
}
if( last == 10 )
ReadChar();
}
bool PostMultiParser::IsWhite(int c)
{
if( c==' ' || c=='\t' || c==13 )
return true;
return false;
}
void PostMultiParser::SkipWhite()
{
while( IsWhite(last) )
ReadChar();
}
bool PostMultiParser::IsHeader()
{
SkipWhite();
if( last == 10 )
{
ReadChar();
return false;
}
return true;
}
void PostMultiParser::ReadHeaderName()
{
SkipWhite();
while( last!=-1 && last!=':' && last!='=' && !IsWhite(last) && last!=10 )
{
header_name += last;
ReadChar();
}
SkipWhite();
if( last != ':' && last != '=' )
{
err = WINIX_ERR_BROKEN_INPUT;
return;
}
ReadChar();
}
void PostMultiParser::ReadHeaderValue()
{
bool was_apost = false;
SkipWhite();
if( last == '"' )
{
was_apost = true;
ReadChar();
}
while( last!=-1 && last!=10 &&
((!was_apost && last!=';' && !IsWhite(last)) || (was_apost && last!='"')))
{
header_value += last;
ReadChar();
}
if( was_apost )
{
if( last != '"' )
{
err = WINIX_ERR_BROKEN_INPUT;
return;
}
ReadChar();
}
SkipWhite();
if( last != ';' && last != 10 )
{
err = WINIX_ERR_BROKEN_INPUT;
return;
}
ReadChar();
}
void PostMultiParser::ReadPartHeader()
{
header_name.clear();
header_value.clear();
ReadHeaderName();
if( err != WINIX_ERR_OK )
return;
ReadHeaderValue();
if( err != WINIX_ERR_OK )
return;
log << "PMP: " << header_name << ": " << header_value << logend;
if( header_name == "name" )
name = header_value;
if( header_name == "filename" )
filename = header_value;
}
bool PostMultiParser::HasBoundary()
{
if( content.size() < boundary.size() )
return false;
size_t c = content.size() - boundary.size();
size_t b = 0;
for( ; c<content.size() ; ++c, ++b)
{
if( content[c] != boundary[b] )
return false;
}
return true;
}
void PostMultiParser::LogFirst(const std::string & to_log, size_t len)
{
size_t i;
if( len > to_log.size() )
len = to_log.size();
log << log3 << "PMP: Content (";
if( len > 0 )
log << "len: " << to_log.size() << ", first " << len << " bytes";
else
log << "empty";
log << "): \"";
for(i=0 ; i<len ; ++i)
{
if( to_log[i] < 32 )
log << '.';
else
log << to_log[i];
}
log << "\"" << logend;
}
void PostMultiParser::ReadContentSkipBoundary(bool has_boundary)
{
if( has_boundary )
content.erase(content.size()-boundary.size());
// the last new line character doesn't belong to the content
if( !content.empty() && content[content.size()-1] == 10 )
{
content.erase(content.size()-1);
if( line_end_dos && !content.empty() && content[content.size()-1] == 13 )
content.erase(content.size()-1);
}
}
void PostMultiParser::ReadContentToFileLoop()
{
bool has_boundary = false;
while( last!=-1 && !(has_boundary=HasBoundary()) )
{
content += last;
ReadChar();
if( content.size() > WINIX_POSTMULTI_OUTPUT_BUFFER + boundary.size() + 2 ) // +2 for the new line character
{
tmp_file.write(content.c_str(), WINIX_POSTMULTI_OUTPUT_BUFFER);
content_len += WINIX_POSTMULTI_OUTPUT_BUFFER;
content.erase(0, WINIX_POSTMULTI_OUTPUT_BUFFER);
}
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 " << config->post_file_max << " (skipping)" << logend;
return;
}
}
ReadContentSkipBoundary(has_boundary);
// saving the rest
if( !content.empty() )
{
tmp_file.write(content.c_str(), content.size());
content_len += content.size();
content.clear();
}
}
void PostMultiParser::ReadContentToFile()
{
time_t t1, t2;
content.clear();
content.reserve(WINIX_POSTMULTI_OUTPUT_BUFFER + boundary.size());
content_len = 0;
t1 = time(0);
ReadContentToFileLoop();
tmp_file.close();
log << log2 << "PMP: content size: " << content_len << " bytes" << logend;
t2 = time(0);
if( t2 - t1 > 1 )
log << log2 << "PMP: content read in " << (t2-t1) << " sec" << logend;
}
void PostMultiParser::ReadContentLoop()
{
bool has_boundary = false;
while( last!=-1 && !(has_boundary=HasBoundary()) )
{
content += last;
content_len += 1;
ReadChar();
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 " << config->post_file_max << " (skipping)" << logend;
return;
}
}
ReadContentSkipBoundary(has_boundary);
}
void PostMultiParser::ReadContent()
{
content.clear();
content_len = 0;
ReadContentLoop();
log << log2 << "PMP: content size: " << content_len << " bytes" << logend;
LogFirst(content, 200);
}
void PostMultiParser::AddNormalPostVar()
{
if( post_table->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) );
bool added = res.second;
log << log2 << "PMP: POST var, name: \"" << name << "\"";
if( !added )
log << log2 << " (skipped)";
log << logend;
}
void PostMultiParser::AddFilePostVar()
{
if( post_file_table->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;
post_file_temp.tmp_filename = tmp_filename;
std::pair<PostFileTable::iterator, bool> res = post_file_table->insert( std::make_pair(name, post_file_temp) );
bool added = res.second;
log << log2 << "PMP: POST FILE var, name: \"" << name << "\"";
if( !added )
log << log2 << " (skipped)";
log << logend;
}
void PostMultiParser::AddPostVar()
{
if( name.empty() )
return;
if( filename.empty() )
{
AddNormalPostVar();
}
else
{
AddFilePostVar();
}
}
void PostMultiParser::CheckBoundaryEnd()
{
if( last == '-' )
{
ReadChar();
if( last != '-' )
{
err = WINIX_ERR_BROKEN_INPUT;
return;
}
// end of parsing
// the rest input (if exists) is ignored
last = -1;
}
// skipping a new line after the boundary
if( last == 13 )
ReadChar();
if( last == 10 )
ReadChar();
}
void PostMultiParser::CreateTmpFile()
{
char buf[100];
if( config->auth_tmp_dir.empty() )
{
log << log1 << "PMP: auth_tmp_dir is not set in the config" << logend;
err = WINIX_ERR_CANT_CREATE_FILE;
return;
}
sprintf(buf, "%s/winix_%u_%d_%u", config->auth_tmp_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;
if( !tmp_file )
{
log << log1 << "PMP: can't create a temporary file: " << tmp_filename << logend;
err = WINIX_ERR_CANT_CREATE_FILE;
return;
}
log << log3 << "PMP: using temporary file for the content: " << tmp_filename << logend;
}
void PostMultiParser::ReadPart()
{
name.clear();
filename.clear();
while( IsHeader() )
ReadPartHeader();
if( err != WINIX_ERR_OK )
return;
if( !filename.empty() )
CreateTmpFile();
if( err != WINIX_ERR_OK )
return;
if( !filename.empty() )
ReadContentToFile();
else
ReadContent();
if( err == WINIX_ERR_OK )
{
AddPostVar();
CheckBoundaryEnd();
}
if( err != WINIX_ERR_OK && !filename.empty() )
{
log << log1 << "PMP: deleting the tmp file: " << tmp_filename << logend;
unlink(tmp_filename.c_str());
}
}
void PostMultiParser::ReadChar()
{
if( last == -1 )
return;
if( in_buffer_ind >= in_buffer_len )
{
if( in_buffer_len < WINIX_POSTMULTI_INPUT_BUFFER )
{
last = -1;
return;
}
in_buffer_len = FCGX_GetStr((char*)in_buffer, WINIX_POSTMULTI_INPUT_BUFFER, in);
in_buffer_ind = 0;
}
if( in_buffer_len == 0 )
{
last = -1;
}
else
{
last = in_buffer[in_buffer_ind];
in_buffer_ind += 1;
}
}
Error PostMultiParser::Parse(FCGX_Stream * in_, PostTable & post_table_, PostFileTable & post_file_table_)
{
in = in_;
last = 0;
err = WINIX_ERR_OK;
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_;
tmp_filename_postfix = 1;
ReadChar();
ReadBoundary();
if( boundary.empty() )
return WINIX_ERR_NO_BOUNDARY;
while( last!=-1 && err == WINIX_ERR_OK )
ReadPart();
if( err != WINIX_ERR_OK )
{
post_table->clear();
post_file_table->clear();
if( err != WINIX_ERR_INPUT_TOO_LARGE && err != WINIX_ERR_CANT_CREATE_FILE )
log << log1 << "PMP: syntax error" << logend;
}
return err;
}

98
core/postmultiparser.h Executable file
View File

@@ -0,0 +1,98 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslucorepostmultiparser
#define headerfilecmslucorepostmultiparser
#include <string>
#include <fcgiapp.h>
#include <fstream>
#include "error.h"
#include "requesttypes.h"
#include "config.h"
// 2 MB
#define WINIX_POSTMULTI_INPUT_BUFFER 2097152
#define WINIX_POSTMULTI_OUTPUT_BUFFER 2097152
class PostMultiParser
{
public:
PostMultiParser();
PostMultiParser(const PostMultiParser &);
PostMultiParser & operator=(const PostMultiParser &);
~PostMultiParser();
void SetConfig(Config * pconfig);
Error Parse(FCGX_Stream * in_, PostTable & post_table_, PostFileTable & post_file_table_);
private:
Config * config;
FCGX_Stream * in;
unsigned char * in_buffer;
std::ofstream tmp_file;
std::string tmp_filename;
int tmp_filename_postfix;
size_t in_buffer_ind;
size_t in_buffer_len;
PostTable * post_table;
PostFileTable * post_file_table;
int last; // last read character
bool line_end_dos;
std::string boundary;
std::string content;
size_t content_len;
std::string header_name, header_value;
Error err;
std::string name, filename;
PostFile post_file_temp;
void LogFirst(const std::string & to_log, size_t len);
bool IsWhite(int c);
void SkipWhite();
void AddNormalPostVar();
void AddFilePostVar();
void AddPostVar();
void ReadBoundary();
bool IsHeader();
void ReadHeaderName();
void ReadHeaderValue();
void ReadPartHeader();
void CreateTmpFile();
bool HasBoundary();
void ReadContentSkipBoundary(bool has_boundary);
void ReadContentToFileLoop();
void ReadContentToFile();
void ReadContentLoop();
void ReadContent();
void CheckBoundaryEnd();
void ReadPart();
void ReadChar();
};
#endif

View File

@@ -1,14 +1,14 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilepostparser
#define headerfilepostparser
#ifndef headerfilecmslucorepostparser
#define headerfilecmslucorepostparser
#include <fcgiapp.h>
#include <string>
@@ -16,6 +16,8 @@
#include "requesttypes.h"
class PostParser : public HttpSimpleParser
{

169
core/rebus.cpp Executable file
View File

@@ -0,0 +1,169 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include <cstdlib>
#include <limits.h>
#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];
bool add = false;
if( a+b <= 15 )
{
sprintf(buffer, "%d+%d", a, b);
item.question = buffer;
item.answer = a+b;
add = true;
}
if( a-b >= 0 )
{
sprintf(buffer, "%d-%d", a, b);
item.question = buffer;
item.answer = a-b;
add = true;
}
return add;
}
void Rebus::Init()
{
int a, b;
Item item;
item.key = 0;
for(a=1 ; a<10 ; ++a)
{
for(b=1 ; b<10 ; ++b)
{
if( InitPair(a, b, item) )
{
table.push_back(item);
item.key += 1;
}
}
}
}
Rebus::Item * Rebus::Rand()
{
size_t len = table.size();
if( len == 0 )
// empty table, call Init() first
return 0;
size_t i = size_t( ((double)rand()*(double)len) / (double(RAND_MAX)+1.0) );
if( i >= table.size() )
{
log << log1 << "Rebus: Rand() index too big" << logend;
// oops, it should not be greater then table.size()
return &table[0];
}
return &table[0] + i;
}
bool Rebus::IsAnswerOk(Rebus::Item * item, const std::string & answer)
{
if( item == 0 )
return false;
char * end;
const char * a = answer.c_str();
a = SkipWhite(a);
int value = (int)strtol(a, &end, 10);
if( a == end )
// nothing has been read
return false;
log << log2 << "Rebus: your answer is: " << value << logend;
end = (char*)SkipWhite(end);
if( *end != 0 )
{
// something is at the end
return false;
}
bool result = (item->answer == value);
if( result )
log << log3 << "Rebus: the answer is correct" << logend;
return result;
}
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;
}
std::string * answer = request->PostVar("rebus");
if( answer && IsAnswerOk(request->session->rebus_item, *answer) )
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;
}

51
core/rebus.h Executable file
View File

@@ -0,0 +1,51 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslucorerebus
#define headerfilecmslucorerebus
#include <string>
#include <vector>
class Request;
class Rebus
{
public:
struct Item
{
int key;
std::string question;
int answer;
};
void SetRequest(Request * prequest);
void Init();
Item * Rand();
bool IsAnswerOk(Item * item, const std::string & answer);
bool CheckRebus();
private:
Request * request;
bool InitPair(int a, int b, Item & item);
std::vector<Item> table;
};
#endif

View File

@@ -1,13 +1,26 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include <ctime>
#include <sys/stat.h>
#include <unistd.h>
#include "request.h"
#include "getparser.h"
#include "postparser.h"
#include "cookieparser.h"
#include "log.h"
#include "plugin.h"
#include "misc.h"
#include "db.h"
#include "functions/functionbase.h"
@@ -18,6 +31,34 @@ Request::Request() : char_empty(0)
}
void Request::SetConfig(Config * pconfig)
{
config = pconfig;
}
void Request::Init()
{
compress.Init();
}
void Request::ClearPostFileTmp()
{
// deleting temporary files (if exists)
while( !post_file_table.empty() )
{
const std::string & tmp_filename = post_file_table.begin()->second.tmp_filename;
if( unlink(tmp_filename.c_str()) == 0 )
log << log3 << "Request: deleted tmp file: " << tmp_filename << logend;
post_file_table.erase(post_file_table.begin());
}
}
void Request::Clear()
{
// warning: don't clear: in, out, err, env
@@ -25,85 +66,92 @@ void Request::Clear()
// id is never 0
if( ++id == 0 )
++id;
get_table.clear();
post_table.clear();
post_file_table.clear();
cookie_table.clear();
method = none;
role = responder;
headers.str("");
page.str("");
debug.str("");
notify.str("");
env_request_method = &char_empty;
env_request_uri = &char_empty;
env_http_cookie = &char_empty;
env_remote_addr = &char_empty;
env_http_host = &char_empty;
env_http_user_agent = &char_empty;
env_http_accept_encoding = &char_empty;
env_fcgi_role = &char_empty;
env_content_type = &char_empty;
session = 0;
result = err404; // !! tutaj moze cos lepszego, cos w stylu 'not implemented'
// dir = -1;
// cur_dir_table.clear();
item_table.clear();
// dir_table2.clear();
item.Clear();
str.clear();
dir_table.clear();
is_item = false;
pfunction = 0;
param_table.clear();
status = Error::ok;
}
status = WINIX_ERR_OK;
is_thread = false;
thread.Clear();
thread_tab.clear();
is_ticket = false;
ticket.Clear();
ticket_tab.clear();
void Request::CopyFirstItem()
{
if( !request.item_table.empty() )
request.item = request.item_table[0];
else
{
request.item.Clear();
log << log1 << "Request::CopyFirstItem: item_table is empty" << logend;
request.result = err_internal;
}
notify_code = 0;
browser_msie = false;
redirect_to.clear();
x_sendfile.clear();
send_as_attachment = false;
plugin.Call(WINIX_REQUEST_CLEAR);
}
// value can be null
void Request::SetCookie(const char * name, const char * value)
void Request::SetCookie(const char * name, const char * value, tm * expires)
{
request.headers << "Set-Cookie: " << name << "=";
headers << "Set-Cookie: " << name << "=";
if( value && value[0]!=0 )
request.headers << value;
headers << value;
else
request.headers << "\"\"";
headers << "\"\"";
request.headers << "; path=/\r\n";
if( expires )
headers << "; expires=" << DateToStrCookie(expires) << " GMT";
headers << "; path=/; domain=." << config->base_server << "\r\n";
}
void Request::SetCookie(const char * name, long value)
void Request::SetCookie(const char * name, long value, tm * expires)
{
request.headers << "Set-Cookie: " << name << "=" << value << "; path=/\r\n";
headers << "Set-Cookie: " << name << "=" << value;
if( expires )
headers << "; expires=" << DateToStrCookie(expires) << " GMT";
headers << "; path=/; domain=." << config->base_server << "\r\n";
}
bool Request::IsPostVar(const char * var)
{
PostTable::iterator p;
@@ -118,36 +166,33 @@ return true;
std::string & Request::PostVar(const char * var)
std::string * Request::PostVar(const char * var)
{
PostTable::iterator p;
p = post_table.find(var);
PostTable::iterator p = post_table.find(var);
if( p == post_table.end() )
{
throw Error(Error::no_postvar);
}
return 0;
return p->second;
return &(p->second);
}
/*
bool Request::PostVar(const char * var, std::string & result)
{
PostTable::iterator p;
p = post_table.find(var);
PostTable::iterator p = post_table.find(var);
if( p == post_table.end() )
{
result.clear();
return false;
}
result = p->second;
return true;
}
*/
@@ -230,6 +275,33 @@ void Request::ReadEnvVariables()
env_remote_addr = SetEnvVar("REMOTE_ADDR");
env_http_host = SetEnvVar("HTTP_HOST");
env_http_user_agent = SetEnvVar("HTTP_USER_AGENT");
env_http_accept_encoding = SetEnvVar("HTTP_ACCEPT_ENCODING");
env_fcgi_role = SetEnvVar("FCGI_ROLE");
env_content_type = SetEnvVar("CONTENT_TYPE");
}
void Request::CheckIE()
{
char * msie = strstr(env_http_user_agent, "MSIE");
if( msie )
browser_msie = true;
else
browser_msie = false;
}
void Request::CheckKonqueror()
{
char * kon = strstr(env_http_user_agent, "Konqueror");
if( kon )
browser_konqueror = true;
else
browser_konqueror = false;
}
@@ -238,49 +310,71 @@ void Request::CheckMethod()
{
method = none;
if( env_request_method[0] == 'G' )
if( ToSmall(env_request_method[0]) == 'g' )
method = get;
else
if( env_request_method[0] == 'P' )
if( ToSmall(env_request_method[0]) == 'p' )
method = post;
// default we assume 'responder'
role = responder;
if( ToSmall(env_fcgi_role[0]) == 'a' )
role = authorizer;
}
bool Request::AllPostVarEmpty()
{
PostTable::iterator i;
for(i=post_table.begin() ; i!=post_table.end() ; ++i)
if( !i->second.empty() )
return false;
return true;
}
// !! czy te parsery powinny byc skladowymi Request?
void Request::ReadParameters()
{
// !!some parameters (get) we have always
// if( method == get )
{
GetParser get_parser(env_request_uri, get_table);
get_parser.Parse();
}
// !! wrzucic jako skladowa klasy
GetParser get_parser(env_request_uri, get_table);
get_parser.Parse();
if( method == post )
{
PostParser post_parser(in, post_table);
post_parser.Parse();
if( IsSubStringNoCase("multipart/form-data", env_content_type) )
{
log << log3 << "Request: post content type: multipart/form-data" << logend;
post_multi_parser.SetConfig(config);
post_multi_parser.Parse(in, post_table, post_file_table);
}
else
{
// !! wrzucic jako skladowa klasy
PostParser post_parser(in, post_table);
post_parser.Parse();
}
}
CookieParser cookie_parser(env_http_cookie, cookie_table);
cookie_parser.Parse();
accept_encoding_parser.Parse(env_http_accept_encoding);
}
void Request::StandardLog()
{
time_t t = std::time(0);
std::tm * loct = std::localtime(&t);
char buffer[70];
sprintf(buffer, "%d.%02d.%02d %02d:%02d:%02d ", int(loct->tm_year + 1900),
int(loct->tm_mon + 1),
int(loct->tm_mday),
int(loct->tm_hour),
int(loct->tm_min),
int(loct->tm_sec));
log << log1 << buffer << env_remote_addr << ' ' << env_request_method << ' ' << env_request_uri << ' ' << env_http_user_agent << logend;
log.PutDate(log1);
log << env_remote_addr << ' ' << env_request_method << ' ';
log << env_http_host << env_request_uri << ' ' << env_http_user_agent << logend;
}
@@ -289,58 +383,180 @@ void Request::StandardLog()
void Request::Read()
{
ReadEnvVariables();
StandardLog();
CheckMethod();
StandardLog();
ReadParameters();
CheckIE();
if( role == authorizer )
log << log3 << "Request: fast cgi role: authorizer" << logend;
CheckKonqueror();
}
void Request::SendAll()
void Request::SendSessionCookie()
{
if( result == redirect )
if( !session || session->id==0 )
return;
if( !session->puser || !session->remember_me )
{
SetCookie(config->http_session_id_name.c_str(), session->id);
return;
}
time_t t = time(0) + config->session_remember_max_idle;
tm * expires = localtime(&t);
if( !expires )
{
// oops, something wrong
SetCookie(config->http_session_id_name.c_str(), session->id);
return;
}
SetCookie(config->http_session_id_name.c_str(), session->id, expires);
}
void Request::SendHeaders(bool compressing, Header header)
{
if( send_as_attachment )
FCGX_PutS("Content-Disposition: attachment\r\n", out);
if( !redirect_to.empty() )
{
FCGX_PutS("Status: 301 Moved Permanently\r\n", out);
FCGX_FPrintF(out, "Location: %s\r\n", str.c_str());
log << log2 << "Redirect to: " << str << logend;
FCGX_FPrintF(out, "Location: %s\r\n", redirect_to.c_str());
log << log2 << "Redirect to: " << redirect_to << logend;
}
else
if( !x_sendfile.empty() )
{
FCGX_FPrintF(out, "X-LIGHTTPD-send-file: %s\r\n", x_sendfile.c_str());
FCGX_PutS("Status: 200 OK\r\n", out);
log << log2 << "Sending file: " << x_sendfile << logend;
}
else
{
FCGX_PutS("Status: 200 OK\r\n", out);
FCGX_PutS("Content-Type: Text/Html\r\n", out);
}
switch(header)
{
case h_404:
FCGX_PutS("Status: 404 Not Found\r\n", out);
FCGX_PutS("Content-Type: text/html\r\n", out);
log << log2 << "Request: response: 404 Not Found" << logend;
break;
case h_403:
FCGX_PutS("Status: 403 Forbidden\r\n", out);
FCGX_PutS("Content-Type: text/html\r\n", out);
log << log2 << "Request: response: 403 Forbidden" << logend;
break;
default:
FCGX_PutS("Status: 200 OK\r\n", out);
if( role != authorizer )
FCGX_PutS("Content-Type: text/html\r\n", out);
}
}
if( compressing )
FCGX_PutS("Content-Encoding: deflate\r\n", out);
FCGX_PutS(headers.str().c_str(), out);
FCGX_PutS("\r\n", out);
}
if( result == redirect )
// if there is a redirect we do not send a content
return;
FCGX_PutS(page.str().c_str(), out);
void Request::AddDebugInfo()
{
const std::string & d = debug.str();
if( !d.empty() )
{
FCGX_PutS("\n<!--\n", out);
FCGX_PutS(d.c_str(), out);
FCGX_PutS("\n-->\n", out);
page << "\n<!--\n";
page << d;
page << "\n-->\n";
}
}
// !! to powinno isc do kontrolera app
void Request::SendPage(bool compressing, const std::string & source_ref)
{
const std::string * source = &source_ref;
bool raw = is_item && item.content_type == Item::ct_raw && status == WINIX_ERR_OK &&
pfunction && (pfunction->fun.url == "cat" || pfunction->fun.url == "run");
if( config->html_filter && !raw )
{
html_filter.TrimWhite(true);
html_filter.BreakLines(60);
html_filter.InsertTabs(2);
html_filter.CheckOrphans(HTMLFilter::lang_pl, HTMLFilter::orphan_160space);
html_filter.Filter(*source, clean_html);
source = &clean_html;
}
if( compressing )
compress.CompressAndPut(source->c_str(), source->length(), out);
else
FCGX_PutS(source->c_str(), out);
}
void Request::SendAll()
{
const std::string & source = page.str();
Header header = h_200;
bool compressing = config->compression && role == responder && redirect_to.empty() && x_sendfile.empty() &&
!browser_msie && !browser_konqueror &&
accept_encoding_parser.AcceptDeflate() && source.size() >= 512;
if( status == WINIX_ERR_NO_ITEM || status == WINIX_ERR_NO_FUNCTION || status == WINIX_ERR_UNKNOWN_PARAM )
header = h_404;
if( status == WINIX_ERR_PERMISSION_DENIED || status == WINIX_ERR_CANT_CHANGE_USER || status == WINIX_ERR_CANT_CHANGE_GROUP )
header = h_403;
SendSessionCookie();
SendHeaders(compressing, header);
if( !redirect_to.empty() || !x_sendfile.empty() )
// if there is a redirect or a file to send then we do not send a content
return;
if( header == h_200 && role == authorizer && is_item && item.auth != Item::auth_none )
// if there is an item and the item has 'file' storage we do not send a content
return;
// adding debug info if exists
AddDebugInfo();
// sending content
SendPage(compressing, source);
}
bool Request::IsParam(const char * s)
bool Request::IsParam(const char * param_name)
{
std::vector<std::string*>::iterator i;
ParamTable::iterator i;
for(i=param_table.begin() ; i!=param_table.end() ; ++i)
{
if( **i == s )
// !! make sure that exists std::string::operator==(const char*)
// (optimization)
if( i->name == param_name )
return true;
}
@@ -348,134 +564,23 @@ return false;
}
bool Request::CanChangeUser(const Item & item, long new_user_id)
const std::string & Request::ParamValue(const char * param_name)
{
if( !session )
// session must be set
return false;
ParamTable::iterator i;
if( session->puser && session->puser->super_user )
// super user is allowed everything
return true;
if( item.user_id != new_user_id )
// only super user can change the owner of an item
return false;
return true;
}
bool Request::CanChangeGroup(const Item & item, long new_group_id)
{
if( !session )
// session must be set
return false;
if( session->puser && session->puser->super_user )
// super user is allowed everything
return true;
if( item.group_id != new_group_id )
for(i=param_table.begin() ; i!=param_table.end() ; ++i)
{
// user is allowed to change the group only if he is an owner of the item
// he can change only into a group in which he is a member of, or into a 'no_group'
if( !session->puser )
return false;
if( session->puser->id != item.user_id )
return false;
if( new_group_id == -1 )
return true;
if( !session->puser->IsMemberOf(new_group_id) )
return false;
// is logged, is the owner of the item, is the member of the new group
if( i->name == param_name )
{
return i->value;
}
}
return true;
}
bool Request::CanChangePrivileges(const Item & item, int new_priv)
{
if( !session )
// session must be set
return false;
if( session->puser && session->puser->super_user )
// super user is allowed everything
return true;
if( item.privileges != new_priv )
{
// the owner of an item is allowed to change the privileges
if( !session->puser )
return false;
if( session->puser->id != item.user_id )
return false;
}
return true;
return str_empty;
}
bool Request::HasAccess(const Item & item, int mask)
{
if( !session )
// session must be set
return false;
if( session->puser && session->puser->super_user )
// super user is allowed everything
return true;
if( session->puser && session->puser->id == item.user_id )
{
// the owner
return ((item.privileges >> 6) & mask) == mask;
}
if( session->puser && session->puser->IsMemberOf(item.group_id) )
{
// group
return ((item.privileges >> 3) & mask) == mask;
}
// others
return (item.privileges & mask) == mask;
}
bool Request::HasReadAccess(const Item & item)
{
return HasAccess(item, 4);
}
bool Request::HasWriteAccess(const Item & item)
{
return HasAccess(item, 2);
}
bool Request::HasReadWriteAccess(const Item & item)
{
return HasAccess(item, 6); // r+w
}
bool Request::HasReadExecAccess(const Item & item)
{
return HasAccess(item, 5); // r+x
}

View File

@@ -1,30 +1,35 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilerequest
#define headerfilerequest
#ifndef headerfilecmslucorerequest
#define headerfilecmslucorerequest
#include <fcgiapp.h>
#include <sstream>
#include <vector>
#include <ctime>
#include <iomanip>
#include "requesttypes.h"
#include "log.h"
#include "session.h"
#include "getparser.h"
#include "postparser.h"
#include "cookieparser.h"
#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"
class FunctionBase;
struct Request
@@ -32,7 +37,7 @@ 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;
@@ -41,44 +46,42 @@ struct Request
enum Method { get, post, none } method;
enum Role { responder, authorizer } role;
// headers, page and debug
std::ostringstream headers, page, debug;
// notify (for mailing)
std::ostringstream headers, page, debug, notify;
GetTable get_table;
PostTable post_table;
CookieTable cookie_table;
GetTable get_table;
PostTable post_table;
PostFileTable post_file_table;
CookieTable cookie_table;
// environment variables
// they are not null -- when the server doesn't have such a variable it will be pointing into 'char_empty' which is default '\0'
// they are not null -- when the server doesn't have such a variable
// it will be pointing into 'char_empty' which is default '\0'
const char * env_request_method;
const char * env_request_uri;
const char * env_http_cookie;
const char * env_remote_addr;
const char * env_http_host;
const char * env_http_user_agent;
const char * env_http_accept_encoding;
const char * env_fcgi_role;
const char * env_content_type;
// true if the browser is Microsoft Internet Explorer
bool browser_msie;
// true if the browser is Konqueror
bool browser_konqueror;
// current session
// is set after calling session_manager.SetSession()
Session * session;
// 'done_status' is set if 'done' is different than 'nothing'
Error done_status; // !! wywalic - jest przeciez w session
// what to do
enum Result { err_internal, err404, err_per_denied, show_dir, show_item, show_item_by_id, add_item, edit_item, del_item, del_item_confirm, confirm, redirect, logout } result; // zamienic na to_do
// !! nowe skladowe
// current directory
// !! zapewnic aby byl minimum jeden katalog (root)
// !! moze nazwac to poprostu dir?
std::vector<Item*> dir_table;
bool is_item;
@@ -87,33 +90,38 @@ struct Request
Item item;
// null if there is no a function
Function * pfunction;
FunctionBase * pfunction;
// !! moze nazwac to poprostu param?
std::vector<std::string*> param_table;
// parameters (name:value)
ParamTable param_table;
Error status;
// ------------------
// !! stare skladowe
// current directory e.g. /foo/bar
//std::vector<Item> cur_dir_table;
// id of the last directory (bar) or -1
//long dir;
// ------------------
// last notify
int notify_code;
// items in the current directory
// maybe without contents?
std::vector<Item> item_table;
// directories in the current directory
//std::vector<Item> dir_table2;
// current thread (if exists)
bool is_thread;
Thread thread;
std::vector<Thread> thread_tab;
// this string is used for many purposes such as redirecting
std::string str;
// current ticket (if exists)
bool is_ticket;
Ticket ticket;
std::vector<Ticket> ticket_tab;
// if not empty means an address for redirecting to
std::string redirect_to;
// send header X-LIGHTTPD-send-file with path to a file
std::string x_sendfile;
// send as attachment (causing header: content-disposition: attachment)
bool send_as_attachment;
// for debugging
void PrintGetTable();
@@ -121,55 +129,78 @@ struct Request
void PrintIn();
Request();
void ClearPostFileTmp();
void Clear();
void Init();
bool IsParam(const char * s);
bool IsParam(const char * param_name);
const std::string & ParamValue(const char * param_name); // returns empty string if there is no such a parameter
void SetCookie(const char * name, const char * value);
void SetCookie(const char * name, long value);
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); // with a throw
//bool PostVar(const char * var, std::string & result);
// item_table[0] -> item
// !! to tez nie bedzie potrzebne
void CopyFirstItem();
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 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);
void SetConfig(Config * pconfig);
private:
Config * config;
enum Header
{
h_200,
h_404,
h_403
};
bool CanUse(long user_id, const char * group_name);
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'
const char char_empty;
// used in ParamValue(const char * param_name) when there is no such a param
const std::string str_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;
};
extern Request request;

View File

@@ -1,178 +0,0 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* All rights reserved.
*
*/
#include "requestcontroller.h"
RequestController::RequestController()
{
}
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();
//
if( !content.Init() )
return false;
return true;
}
bool RequestController::BaseUrlRedirect()
{
if( request.env_request_uri[0] == 0 )
return false;
if( data.base_url_http_host == request.env_http_host )
return false;
request.result = Request::redirect;
request.str = data.base_url + (request.env_request_uri + 1); // +1 means skipping the first slash from env_request_uri
return true;
}
void RequestController::Loop()
{
while( FCGX_Accept(&request.in, &request.out, &request.err, &request.env) == 0 )
{
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.SetSession(); // set request.session as well
request.session->CheckTimers();
function_parser.Parse();
content.Make();
}
request.SendAll();
}
catch(const std::exception & e)
{
log << log1 << "uncaught std exception: " << e.what() << logend;
}
catch(const Error & e)
{
log << log1 << "uncaught exception: Error: " << e << logend;
}
catch(...)
{
log << log1 << "uncaught exception" << logend;
}
// !! this should be immediately after FCGX_Accept() but signals don't want to break FCGX_Accept
if( data.signal_hup )
{
FCGX_Finish();
return;
}
}
}

View File

@@ -1,51 +0,0 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilerequestcontroller
#define headerfilerequestcontroller
#include <unistd.h>
#include <sys/stat.h>
#include <iostream>
#include <sys/types.h>
#include <pwd.h>
#include <grp.h>
#include <errno.h>
#include "data.h"
#include "log.h"
#include "request.h"
#include "../content/content.h"
#include "sessionmanager.h"
#include "postparser.h"
#include "cookieparser.h"
class RequestController
{
Content content;
SessionManager session_manager;
bool BaseUrlRedirect();
FunctionParser function_parser;
public:
RequestController();
~RequestController();
bool Init();
void Close();
void Loop();
};
#endif

View File

@@ -1,26 +1,45 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilerequesttypes
#define headerfilerequesttypes
#ifndef headerfilecmslucorerequesttypes
#define headerfilecmslucorerequesttypes
#include <string>
#include <vector>
#include <map>
// some global types used by Request class
typedef std::vector<std::string> GetTable;
typedef std::map<std::string, std::string> PostTable;
typedef std::map<std::string, std::string> CookieTable;
#define WINIX_POSTTABLE_MAXSIZE 20
struct PostFile
{
std::string filename; // original file name
std::string tmp_filename; // file with content (in /tmp)
};
// parameters from get name:value
struct Param
{
std::string name;
std::string value;
};
// some global types used by Request class
typedef std::vector<std::string> GetTable;
typedef std::map<std::string, std::string> PostTable;
typedef std::map<std::string, PostFile> PostFileTable;
typedef std::map<std::string, std::string> CookieTable;
typedef std::vector<Param> ParamTable;
#endif

View File

@@ -1,8 +1,8 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
@@ -10,11 +10,21 @@
#include "session.h"
Session::Session()
{
Clear();
time = std::time(0);
tm_time = *std::localtime(&time);
last_time = time;
tm_last_time = tm_time;
// the first request can be a POST (it doesn't matter)
last_time_get = time;
}
@@ -23,10 +33,13 @@ void Session::Clear()
id = 0;
time = 0;
puser = 0;
done = Done::none;
done_status = Error::ok;
item.Clear();
done_timer = 0;
rebus_item = 0;
rebus_checked = false;
remember_me = false;
new_session = true;
spam_score = 0;
// dir_old.clear();
}
@@ -41,32 +54,3 @@ bool Session::operator<(const Session & s) const
return id < s.id;
}
bool Session::DecTimer(int & timer)
{
if( timer == 0 )
return false;
--timer;
if( timer == 0 )
return true; // we must clear our variables
return false;
}
void Session::CheckTimers()
{
if( DecTimer(done_timer) )
{
done = Done::none;
done_status = Error::ok;
}
}

View File

@@ -1,22 +1,21 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecoresession
#define headerfilecoresession
#ifndef headerfilecmslucoresession
#define headerfilecmslucoresession
#include <ctime>
#include "requesttypes.h"
#include "error.h"
#include "item.h"
#include "done.h"
#include "error.h"
#include "user.h"
#include "plugindata.h"
#include "rebus.h"
struct Session
@@ -24,40 +23,53 @@ struct Session
// 0 - means that there is no session
long id;
// when this session was created
int time;
// true if the session was created now
bool new_session;
// when this session was created
// (the same values)
time_t time;
tm tm_time;
// when this session was last used
// (the same values)
time_t last_time;
tm tm_last_time;
// when there was a last get request
// (used to calculate spam)
time_t last_time_get;
// 0 - means that nobody is logged
User * puser;
// what is done
Done done;
Error done_status;
int done_timer;
// if false the session will end when the user browser is shutdown
bool remember_me;
// used for many purposes, depending on 'done'
Item item;
// rebus - set by rebus_question(Info & i) from templates
Rebus::Item * rebus_item;
bool rebus_checked;
//std::string dir_old;
int spam_score;
PluginData plugin_data;
// -------------------
Session();
virtual void Clear();
void Clear();
bool operator==(const Session & s) const;
bool operator<(const Session & s) const;
bool DecTimer(int & timer);
void CheckTimers();
void DecTimer(int & timer);
};
#endif

161
core/sessioncontainer.cpp Executable file
View File

@@ -0,0 +1,161 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "sessioncontainer.h"
#include "log.h"
void SessionContainer::Clear()
{
table.clear();
index_id.clear();
index_time.clear();
}
void SessionContainer::SetLastContainer(LastContainer * plast_container)
{
last_container = plast_container;
}
SessionContainer::TableSize SessionContainer::Size()
{
return table.size();
}
SessionContainer::Iterator SessionContainer::Begin()
{
return table.begin();
}
SessionContainer::Iterator SessionContainer::End()
{
return table.end();
}
Session & SessionContainer::Back()
{
return table.back();
}
bool SessionContainer::PushBack(const Session & session)
{
if( index_id.find(session.id) != index_id.end() )
// that element already exists
return false;
Iterator last = table.insert(table.end(), session);
index_id.insert( std::make_pair(session.id, last) );
index_time.insert( std::make_pair(session.last_time, last) );
log << log3 << "SC: added session, id: " << session.id << logend;
return true;
}
SessionContainer::Iterator SessionContainer::FindById(long id)
{
IndexId::iterator i;
i = index_id.find(id);
if( i == index_id.end() )
return table.end();
return i->second;
}
void SessionContainer::DelFirstByTimeInterval(time_t interval, bool skip_remember_flag)
{
IndexTime::iterator i = index_time.begin();
IndexTime::iterator iold;
time_t limit = std::time(0) - interval;
while( i != index_time.end() && i->second->last_time < limit )
{
long id = i->second->id;
iold = i;
++i; // incrementing before deleting old one
if( skip_remember_flag && iold->second->puser && iold->second->remember_me )
// don't delete sessions which have 'remember_me' flag (and a user is logged)
continue;
if( iold->second->puser )
last_container->UserLogout(iold->second->puser->id, iold->second->id);
// we're logging session.id (call this before table.erase())
DelFromIdIndex(iold->second);
table.erase(iold->second);
index_time.erase(iold);
log << log3 << "SC: deleted index_time for session id: " << id << logend;
log << log3 << "SC: deleted session, id: " << id << logend;
}
}
void SessionContainer::DelFromIdIndex(SessionContainer::Iterator iter)
{
IndexId::iterator i;
for( i = index_id.begin() ; i!=index_id.end() ; ++i)
{
if( i->second == iter )
{
index_id.erase(i);
log << log3 << "SC: deleted index_id for session id: " << iter->id << logend;
break;
}
}
}
void SessionContainer::UpdateLastTime(SessionContainer::Iterator iter, time_t new_time)
{
IndexTime::iterator i = index_time.lower_bound(iter->last_time);
bool found = false;
for( ; i != index_time.end() ; ++i)
{
if( i->second == iter )
{
index_time.erase(i);
index_time.insert( std::make_pair(new_time, iter) );
iter->last_time = new_time;
iter->tm_last_time = *std::localtime(&new_time);
log << log3 << "SC: last time and the time index for session id: " << iter->id << " updated" << logend;
found = true;
break;
}
}
if( !found )
log << log1 << "SC: cannot update the time, time index not found for session id: " << iter->id << logend;
}

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