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
This commit is contained in:
Tomasz Sowa 2010-05-20 18:28:19 +00:00
parent 2ad666d221
commit 612f260938
22 changed files with 291 additions and 145 deletions

View File

@ -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

View File

@ -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

View File

@ -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;

View File

@ -92,6 +92,15 @@ class Content
void FunCKEditor();
void FunUname();
bool SubjectCheckAccess();
void EditDirSubject();
void EditFileSubject();
void PostFunSubject();
void FunSubject();
/*
rm
*/

81
content/subject.cpp Executable file
View File

@ -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();
}

18
content/uname.cpp Executable file
View File

@ -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()
{
}

View File

@ -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)
{

View File

@ -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> & user_table);

View File

@ -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

View File

@ -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");
}

View File

@ -23,8 +23,11 @@ class Functions
typedef std::map<std::string, Function> 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);
};

View File

@ -16,12 +16,7 @@
#include <ctime>
#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);

19
core/version.h Executable file
View File

@ -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

View File

@ -10,7 +10,8 @@
[if-one item_is]{mv_page} "[item_url]":[else]{mv_dir} "[dir_without_slash]"[end]
</p>
{suggested_url}:<br>
<p class="withnext">{suggested_url}</p>
<input class="edit" type="text" name="moveto" value="[dir][if-one item_is][item_url][end]">

17
html/fun_subject.html Executable file
View File

@ -0,0 +1,17 @@
<h1>{subject_header}</h1>
[include "error.html"]
<form id="additem" method="post" action="[doc_base_url][dir][if-one item_is][item_url]/[end]subject">
<fieldset>
<legend>{subject_form_legend}</legend>
<p class="withnext">{title}</p>
<input class="edit" type="text" name="subject" value="[if-one item_is][item_subject][else][dir_last_subject][end]">
<input class="submit" type="submit" value="{change}">
</fieldset>
</form>

View File

@ -0,0 +1,6 @@
<h1>{uname_header}</h1>
[include "error.html"]
<p>Winix [sys_ver_major].[sys_ver_minor].[sys_ver_revision]</p>

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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;
}

View File

@ -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");
}

View File

@ -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
};