From 612f260938b8226dd051c907535a7a1470081412 Mon Sep 17 00:00:00 2001
From: Tomasz Sowa
Date: Thu, 20 May 2010 18:28:19 +0000
Subject: [PATCH] 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
---
content/Makefile.dep | 21 +++++
content/Makefile.o.dep | 2 +-
content/content.cpp | 10 ++-
content/content.h | 9 +++
content/subject.cpp | 81 +++++++++++++++++++
content/uname.cpp | 18 +++++
core/db.cpp | 27 +++++++
core/db.h | 5 +-
core/function.h | 3 +-
core/functions.cpp | 169 +++++++++++-----------------------------
core/functions.h | 7 +-
core/misc.h | 7 +-
core/version.h | 19 +++++
html/fun_mv.html | 3 +-
html/fun_subject.html | 17 ++++
html/fun_uname.html | 6 ++
locale/en | 8 ++
locale/pl | 7 ++
templates/Makefile.dep | 2 +-
templates/sys.cpp | 8 +-
templates/templates.cpp | 6 +-
templates/templates.h | 1 +
22 files changed, 291 insertions(+), 145 deletions(-)
create mode 100755 content/subject.cpp
create mode 100755 content/uname.cpp
create mode 100755 core/version.h
create mode 100755 html/fun_subject.html
diff --git a/content/Makefile.dep b/content/Makefile.dep
index c6496f8..d91a6eb 100755
--- a/content/Makefile.dep
+++ b/content/Makefile.dep
@@ -337,6 +337,19 @@ run.o: ../core/rebus.h ../core/plugindata.h ../core/function.h
run.o: ../core/compress.h ../core/acceptencodingparser.h
run.o: ../core/acceptbaseparser.h ../core/htmlfilter.h
run.o: ../core/postmultiparser.h ../core/error.h
+subject.o: content.h ../core/item.h ../templates/templates.h
+subject.o: ../templates/patterncacher.h ../templates/misc.h
+subject.o: ../templates/localefilter.h ../core/locale.h
+subject.o: ../confparser/confparser.h ../templates/ckeditorgetparser.h
+subject.o: ../core/httpsimpleparser.h ../core/log.h ../core/thread.h
+subject.o: ../core/ticket.h ../core/db.h ../core/item.h ../core/user.h
+subject.o: ../core/group.h ../core/thread.h ../core/error.h ../core/log.h
+subject.o: ../core/dircontainer.h ../core/ugcontainer.h ../core/ticket.h
+subject.o: ../core/request.h ../core/requesttypes.h ../core/session.h
+subject.o: ../core/rebus.h ../core/plugindata.h ../core/function.h
+subject.o: ../core/compress.h ../core/acceptencodingparser.h
+subject.o: ../core/acceptbaseparser.h ../core/htmlfilter.h
+subject.o: ../core/postmultiparser.h
thread.o: content.h ../core/item.h ../templates/templates.h
thread.o: ../templates/patterncacher.h ../templates/misc.h
thread.o: ../templates/localefilter.h ../core/locale.h
@@ -369,6 +382,14 @@ ticket.o: ../core/postmultiparser.h ../core/data.h ../core/dirs.h
ticket.o: ../core/users.h ../core/groups.h ../core/functions.h
ticket.o: ../core/lastcontainer.h ../core/mounts.h ../core/mount.h
ticket.o: ../core/loadavg.h ../core/mount.h
+uname.o: content.h ../core/item.h ../templates/templates.h
+uname.o: ../templates/patterncacher.h ../templates/misc.h
+uname.o: ../templates/localefilter.h ../core/locale.h
+uname.o: ../confparser/confparser.h ../templates/ckeditorgetparser.h
+uname.o: ../core/httpsimpleparser.h ../core/log.h ../core/thread.h
+uname.o: ../core/ticket.h ../core/db.h ../core/item.h ../core/user.h
+uname.o: ../core/group.h ../core/thread.h ../core/error.h ../core/log.h
+uname.o: ../core/dircontainer.h ../core/ugcontainer.h ../core/ticket.h
upload.o: content.h ../core/item.h ../templates/templates.h
upload.o: ../templates/patterncacher.h ../templates/misc.h
upload.o: ../templates/localefilter.h ../core/locale.h
diff --git a/content/Makefile.o.dep b/content/Makefile.o.dep
index eff91b6..e418960 100755
--- a/content/Makefile.o.dep
+++ b/content/Makefile.o.dep
@@ -1 +1 @@
-o = adduser.o cat.o content.o createthread.o createticket.o default.o download.o editticket.o emacs.o last.o login.o logout.o ls.o misc_item.o misc_specialfile.o mkdir.o mv.o node.o priv.o reload.o rm.o run.o thread.o ticket.o upload.o who.o
+o = adduser.o cat.o content.o createthread.o createticket.o default.o download.o editticket.o emacs.o last.o login.o logout.o ls.o misc_item.o misc_specialfile.o mkdir.o mv.o node.o priv.o reload.o rm.o run.o subject.o thread.o ticket.o uname.o upload.o who.o
diff --git a/content/content.cpp b/content/content.cpp
index 4d85955..cdbf79b 100755
--- a/content/content.cpp
+++ b/content/content.cpp
@@ -214,10 +214,9 @@ void Content::MakeStandardFunction()
else
if( request.pfunction->code == FUN_MV )
FunMv();
-/* else
+ else
if( request.pfunction->code == FUN_UNAME )
FunUname();
-*/
else
if( request.pfunction->code == FUN_CHMOD )
FunPriv();
@@ -230,6 +229,9 @@ void Content::MakeStandardFunction()
else
if( request.pfunction->code == FUN_ADDUSER )
FunAddUser();
+ else
+ if( request.pfunction->code == FUN_SUBJECT )
+ FunSubject();
else
request.status = WINIX_ERR_PERMISSION_DENIED;
@@ -313,6 +315,10 @@ void Content::MakePost()
PostFunMv();
break;
+ case FUN_SUBJECT:
+ PostFunSubject();
+ break;
+
default:
log << log1 << "Content: unknown post function" << logend;
break;
diff --git a/content/content.h b/content/content.h
index f910134..a65002d 100755
--- a/content/content.h
+++ b/content/content.h
@@ -92,6 +92,15 @@ class Content
void FunCKEditor();
+ void FunUname();
+
+ bool SubjectCheckAccess();
+ void EditDirSubject();
+ void EditFileSubject();
+ void PostFunSubject();
+ void FunSubject();
+
+
/*
rm
*/
diff --git a/content/subject.cpp b/content/subject.cpp
new file mode 100755
index 0000000..e6c118f
--- /dev/null
+++ b/content/subject.cpp
@@ -0,0 +1,81 @@
+/*
+ * This file is a part of Winix
+ * and is not publicly distributed
+ *
+ * Copyright (c) 2008-2010, Tomasz Sowa
+ * All rights reserved.
+ *
+ */
+
+#include "content.h"
+#include "../core/request.h"
+#include "../core/db.h"
+#include "../core/log.h"
+
+
+
+bool Content::SubjectCheckAccess()
+{
+ // super user can always
+ if( request.session->puser && request.session->puser->super_user )
+ return true;
+
+ bool access;
+
+ if( request.is_item )
+ access = request.HasWriteAccess(request.item);
+ else
+ access = request.HasWriteAccess(*request.dir_table.back());
+
+ if( !access )
+ request.status = WINIX_ERR_PERMISSION_DENIED;
+
+return access;
+}
+
+
+
+void Content::EditDirSubject()
+{
+ Item & dir = *request.dir_table.back();
+
+ request.PostVar("subject", dir.subject);
+ db.EditSubjectById(dir, dir.id);
+
+ RedirectToLastDir();
+}
+
+
+
+void Content::EditFileSubject()
+{
+ request.PostVar("subject", request.item.subject);
+ db.EditSubjectById(request.item, request.item.id);
+
+ RedirectTo(request.item);
+}
+
+
+
+
+void Content::PostFunSubject()
+{
+ if( !SubjectCheckAccess() )
+ return;
+
+ if( request.is_item )
+ EditFileSubject();
+ else
+ EditDirSubject();
+}
+
+
+
+void Content::FunSubject()
+{
+ SubjectCheckAccess();
+}
+
+
+
+
diff --git a/content/uname.cpp b/content/uname.cpp
new file mode 100755
index 0000000..884b8ec
--- /dev/null
+++ b/content/uname.cpp
@@ -0,0 +1,18 @@
+/*
+ * This file is a part of Winix
+ * and is not publicly distributed
+ *
+ * Copyright (c) 2008-2010, Tomasz Sowa
+ * All rights reserved.
+ *
+ */
+
+#include "content.h"
+
+
+
+void Content::FunUname()
+{
+}
+
+
diff --git a/core/db.cpp b/core/db.cpp
index a77910c..b6489a8 100755
--- a/core/db.cpp
+++ b/core/db.cpp
@@ -1259,6 +1259,33 @@ return result;
+Error Db::EditSubjectById(Item & item, long id)
+{
+ PGresult * r = 0;
+ Error result = WINIX_ERR_OK;
+
+ try
+ {
+ AssertConnection();
+ std::ostringstream query;
+ query << "update core.item set (subject) = (";
+ query << '\'' << Escape(item.subject) << "') ";
+ query << " where id='" << id << "';";
+
+ r = AssertQuery(query.str());
+ AssertResultStatus(r, PGRES_COMMAND_OK);
+ }
+ catch(const Error & e)
+ {
+ result = e;
+ }
+
+ ClearResult(r);
+
+return result;
+}
+
+
bool Db::DelItemDelItem(const Item & item)
{
diff --git a/core/db.h b/core/db.h
index c70b581..e0615ab 100755
--- a/core/db.h
+++ b/core/db.h
@@ -138,7 +138,10 @@ public:
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_table);
diff --git a/core/function.h b/core/function.h
index 533e67c..a48b667 100755
--- a/core/function.h
+++ b/core/function.h
@@ -37,12 +37,13 @@
#define FUN_TICKET 20
#define FUN_UPTIME 21
#define FUN_MV 23
-//#define FUN_UNAME 24
+#define FUN_UNAME 24
#define FUN_CHMOD 25
#define FUN_CHOWN 26
#define FUN_CKEDITOR 27
#define FUN_DOWNLOAD 28
#define FUN_ADDUSER 29
+#define FUN_SUBJECT 30
diff --git a/core/functions.cpp b/core/functions.cpp
index c706591..7e5795a 100755
--- a/core/functions.cpp
+++ b/core/functions.cpp
@@ -22,139 +22,62 @@ void Functions::Clear()
+void Functions::AddFun(int code, const char * url)
+{
+ fun.code = code;
+ fun.item.url = url;
+ table.insert( std::make_pair(fun.item.url, fun) );
+}
+
+
+
+// in the future we will read these functions from the database
void Functions::ReadFunctions()
{
Clear();
- Function f;
-
- f.item.user_id = -1;
- f.item.group_id = -1;
- f.item.privileges = 0755;
- 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 = FUN_LS;
- f.item.url = "ls";
- table.insert( std::make_pair(f.item.url, f) );
-
- f.code = FUN_CAT;
- f.item.url = "cat";
- table.insert( std::make_pair(f.item.url, f) );
-
- f.code = FUN_NODE;
- f.item.url = "node";
- table.insert( std::make_pair(f.item.url, f) );
-
- f.code = FUN_EMACS;
- f.item.url = "emacs";
- table.insert( std::make_pair(f.item.url, f) );
-
- f.code = FUN_MKDIR;
- f.item.url = "mkdir";
- table.insert( std::make_pair(f.item.url, f) );
-
- f.code = FUN_DEFAULT;
- f.item.url = "default";
- table.insert( std::make_pair(f.item.url, f) );
-
- f.code = FUN_PRIV;
- f.item.url = "priv";
- table.insert( std::make_pair(f.item.url, f) );
-
- f.code = FUN_RM;
- f.item.url = "rm";
- table.insert( std::make_pair(f.item.url, f) );
-
- f.code = FUN_LOGOUT;
- f.item.url = "logout";
- table.insert( std::make_pair(f.item.url, f) );
-
- f.code = FUN_LOGIN;
- f.item.url = "login";
- table.insert( std::make_pair(f.item.url, f) );
-
- f.code = FUN_RUN;
- f.item.url = "run";
- table.insert( std::make_pair(f.item.url, f) );
-
- f.code = FUN_WHO;
- f.item.url = "who";
- table.insert( std::make_pair(f.item.url, f) );
-
- f.code = FUN_LAST;
- f.item.url = "last";
- table.insert( std::make_pair(f.item.url, f) );
-
- f.code = FUN_CREATETHREAD;
- f.item.url = "createthread";
- table.insert( std::make_pair(f.item.url, f) );
-
- f.code = FUN_THREAD;
- f.item.url = "thread";
- table.insert( std::make_pair(f.item.url, f) );
-
- f.code = FUN_UPLOAD;
- f.item.url = "upload";
- table.insert( std::make_pair(f.item.url, f) );
-
- f.code = FUN_CREATETICKET;
- f.item.url = "createticket";
- table.insert( std::make_pair(f.item.url, f) );
-
- f.code = FUN_EDITTICKET;
- f.item.url = "editticket";
- table.insert( std::make_pair(f.item.url, f) );
-
- f.code = FUN_TICKET;
- f.item.url = "ticket";
- table.insert( std::make_pair(f.item.url, f) );
-
- f.code = FUN_UPTIME;
- f.item.url = "uptime";
- table.insert( std::make_pair(f.item.url, f) );
-
- f.code = FUN_MV;
- f.item.url = "mv";
- table.insert( std::make_pair(f.item.url, f) );
-
- /*
- f.code = FUN_UNAME;
- f.item.url = "uname";
- table.insert( std::make_pair(f.item.url, f) );
- */
-
- f.code = FUN_CHMOD;
- f.item.url = "chmod";
- table.insert( std::make_pair(f.item.url, f) );
-
- f.code = FUN_CHOWN;
- f.item.url = "chown";
- table.insert( std::make_pair(f.item.url, f) );
+ fun.item.user_id = -1;
+ fun.item.group_id = -1;
+ fun.item.privileges = 0755;
+ fun.item.parent_id = -1; // !! temporarily doesn't matter
+ fun.item.id = -1;
+ fun.item.type = Item::file;
- f.code = FUN_CKEDITOR;
- f.item.url = "ckeditor";
- table.insert( std::make_pair(f.item.url, f) );
+ AddFun(FUN_LS, "ls");
+ AddFun(FUN_CAT, "cat");
+ AddFun(FUN_NODE, "node");
+ AddFun(FUN_EMACS, "emacs");
+ AddFun(FUN_MKDIR, "mkdir");
+ AddFun(FUN_DEFAULT, "default");
+ AddFun(FUN_PRIV, "priv");
+ AddFun(FUN_RM, "rm");
+ AddFun(FUN_LOGOUT, "logout");
+ AddFun(FUN_LOGIN, "login");
+ AddFun(FUN_RUN, "run");
+ AddFun(FUN_WHO, "who");
+ AddFun(FUN_LAST, "last");
+ AddFun(FUN_CREATETHREAD, "createthread");
+ AddFun(FUN_THREAD, "thread");
+ AddFun(FUN_UPLOAD, "upload");
+ AddFun(FUN_CREATETICKET, "createticket");
+ AddFun(FUN_EDITTICKET, "editticket");
+ AddFun(FUN_TICKET, "ticket");
+ AddFun(FUN_UPTIME, "uptime");
+ AddFun(FUN_MV, "mv");
+ AddFun(FUN_UNAME, "uname");
+ AddFun(FUN_CHMOD, "chmod");
+ AddFun(FUN_CHOWN, "chown");
+ AddFun(FUN_CKEDITOR, "ckeditor");
+ AddFun(FUN_DOWNLOAD, "download");
+ AddFun(FUN_ADDUSER, "adduser");
+ AddFun(FUN_SUBJECT, "subject");
- f.code = FUN_DOWNLOAD;
- f.item.url = "download";
- table.insert( std::make_pair(f.item.url, f) );
-
- f.code = FUN_ADDUSER;
- f.item.url = "adduser";
- table.insert( std::make_pair(f.item.url, f) );
// functions which need more privileges
+ fun.item.privileges = 0700;
- f.code = FUN_RELOAD;
- f.item.url = "reload";
- f.item.privileges = 0700;
- table.insert( std::make_pair(f.item.url, f) );
-
-
+ AddFun(FUN_RELOAD, "reload");
}
diff --git a/core/functions.h b/core/functions.h
index 7a06e25..de2ee2c 100755
--- a/core/functions.h
+++ b/core/functions.h
@@ -23,8 +23,11 @@ class Functions
typedef std::map Table;
Table table;
-public:
+Function fun;
+ void AddFun(int code, const char * url);
+
+public:
void Clear();
@@ -33,8 +36,6 @@ public:
Function * GetFunction(const std::string & name);
Function * GetFunction(int code);
-
-
};
diff --git a/core/misc.h b/core/misc.h
index c029c55..16fa443 100755
--- a/core/misc.h
+++ b/core/misc.h
@@ -16,12 +16,7 @@
#include
#include "item.h"
-// !! wrzucic do pliku version.h i dodac przedrostek typu WINIX_
-// albo dac nazwy typu WINIX_VER_MAJOR
-#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);
diff --git a/core/version.h b/core/version.h
new file mode 100755
index 0000000..acea5d7
--- /dev/null
+++ b/core/version.h
@@ -0,0 +1,19 @@
+/*
+ * This file is a part of Winix
+ * and is not publicly distributed
+ *
+ * Copyright (c) 2008-2010, Tomasz Sowa
+ * All rights reserved.
+ *
+ */
+
+#ifndef headerfilecmslucoreversion
+#define headerfilecmslucoreversion
+
+
+#define WINIX_VER_MAJOR 0
+#define WINIX_VER_MINOR 3
+#define WINIX_VER_REVISION 0
+
+
+#endif
diff --git a/html/fun_mv.html b/html/fun_mv.html
index e9a8b38..544bbed 100755
--- a/html/fun_mv.html
+++ b/html/fun_mv.html
@@ -10,7 +10,8 @@
[if-one item_is]{mv_page} "[item_url]":[else]{mv_dir} "[dir_without_slash]"[end]
- {suggested_url}:
+
+ {suggested_url}
diff --git a/html/fun_subject.html b/html/fun_subject.html
new file mode 100755
index 0000000..79b0ba6
--- /dev/null
+++ b/html/fun_subject.html
@@ -0,0 +1,17 @@
+{subject_header}
+
+[include "error.html"]
+
+
+
+
+
diff --git a/html/fun_uname.html b/html/fun_uname.html
index e69de29..736d1a2 100755
--- a/html/fun_uname.html
+++ b/html/fun_uname.html
@@ -0,0 +1,6 @@
+{uname_header}
+
+[include "error.html"]
+
+
+Winix [sys_ver_major].[sys_ver_minor].[sys_ver_revision]
diff --git a/locale/en b/locale/en
index 94f0236..104b060 100755
--- a/locale/en
+++ b/locale/en
@@ -195,6 +195,14 @@ mv_dir = Move directory
mv_only_content = Move only content of the directory
+subject_header = Edit subject
+subject_form_legend = Edit subject form
+
+
+uname_header = Uname
+
+
+
# notifications
notify_new = News
notify_change = Changes
diff --git a/locale/pl b/locale/pl
index 5bebb06..1b3156f 100755
--- a/locale/pl
+++ b/locale/pl
@@ -196,6 +196,13 @@ mv_dir = Przenie
mv_only_content = Przenieś tylko zawartość katalogu
+subject_header = Zmień tytuł
+subject_form_legend = Formularz zmiany tytułu
+
+uname_header = Nazwa systemu
+
+
+
# notifications
notify_new = Coś nowego
notify_change = Zmiany
diff --git a/templates/Makefile.dep b/templates/Makefile.dep
index 03aad2d..1420c2f 100755
--- a/templates/Makefile.dep
+++ b/templates/Makefile.dep
@@ -127,7 +127,7 @@ sys.o: ../core/loadavg.h ../core/request.h ../core/requesttypes.h
sys.o: ../core/session.h ../core/plugindata.h ../core/thread.h
sys.o: ../core/compress.h ../core/acceptencodingparser.h
sys.o: ../core/acceptbaseparser.h ../core/htmlfilter.h
-sys.o: ../core/postmultiparser.h ../core/ticket.h ../core/misc.h
+sys.o: ../core/postmultiparser.h ../core/ticket.h ../core/version.h
templates.o: templates.h patterncacher.h ../core/item.h misc.h localefilter.h
templates.o: ../core/locale.h ../confparser/confparser.h ckeditorgetparser.h
templates.o: ../core/httpsimpleparser.h ../core/log.h ../core/data.h
diff --git a/templates/sys.cpp b/templates/sys.cpp
index d442f31..2549027 100755
--- a/templates/sys.cpp
+++ b/templates/sys.cpp
@@ -10,7 +10,7 @@
#include "templates.h"
#include "../core/data.h"
#include "../core/request.h"
-#include "../core/misc.h"
+#include "../core/version.h"
@@ -21,20 +21,20 @@ namespace TemplatesFunctions
void sys_ver_major(Info & i)
{
- i.out << MAJOR_VER;
+ i.out << WINIX_VER_MAJOR;
}
void sys_ver_minor(Info & i)
{
- i.out << MINOR_VER;
+ i.out << WINIX_VER_MINOR;
}
void sys_ver_revision(Info & i)
{
- i.out << REVISION_VER;
+ i.out << WINIX_VER_REVISION;
}
diff --git a/templates/templates.cpp b/templates/templates.cpp
index 5952466..50667ba 100755
--- a/templates/templates.cpp
+++ b/templates/templates.cpp
@@ -65,8 +65,9 @@ Ezc::Pattern * p = 0;
{FUN_UPTIME, pat_fun_uptime},
{FUN_LOGIN, pat_fun_login},
{FUN_MV, pat_fun_mv},
-/* {FUN_UNAME, pat_fun_uname},*/
+ {FUN_UNAME, pat_fun_uname},
{FUN_CKEDITOR, pat_fun_ckeditor},
+ {FUN_SUBJECT, pat_fun_subject},
{FUN_ADDUSER, pat_fun_adduser}
};
@@ -515,9 +516,10 @@ using namespace TemplatesFunctions;
ReadFile(pat_fun_uptime, "fun_uptime.html");
ReadFile(pat_fun_login, "fun_login.html");
ReadFile(pat_fun_mv, "fun_mv.html");
- /*ReadFile(pat_fun_uname, "fun_uname.html");*/
+ ReadFile(pat_fun_uname, "fun_uname.html");
ReadFile(pat_fun_ckeditor, "fun_ckeditor.html");
ReadFile(pat_fun_adduser, "fun_adduser.html");
+ ReadFile(pat_fun_subject, "fun_subject.html");
}
diff --git a/templates/templates.h b/templates/templates.h
index b5b4805..fe66c1d 100755
--- a/templates/templates.h
+++ b/templates/templates.h
@@ -52,6 +52,7 @@ namespace TemplatesFunctions
pat_item_info,
pat_item_tab_info,
pat_dir_last_info,
+ pat_fun_subject,
pat_last // should be last
};