added: function cp (only for files)
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@605 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
@@ -49,6 +49,21 @@ content.o: ../core/dirs.h ../core/users.h ../core/groups.h
|
||||
content.o: ../core/functions.h ../core/lastcontainer.h ../core/mounts.h
|
||||
content.o: ../core/mount.h ../core/loadavg.h ../core/misc.h ../core/plugin.h
|
||||
content.o: ../core/request.h ../core/data.h ../core/pluginmsg.h
|
||||
cp.o: content.h ../core/item.h ../templates/templates.h
|
||||
cp.o: ../templates/patterncacher.h ../templates/misc.h
|
||||
cp.o: ../templates/localefilter.h ../core/locale.h ../confparser/confparser.h
|
||||
cp.o: ../templates/ckeditorgetparser.h ../core/httpsimpleparser.h
|
||||
cp.o: ../core/log.h ../core/thread.h ../core/ticket.h ../core/db.h
|
||||
cp.o: ../core/item.h ../core/user.h ../core/group.h ../core/thread.h
|
||||
cp.o: ../core/error.h ../core/log.h ../core/dircontainer.h
|
||||
cp.o: ../core/ugcontainer.h ../core/ticket.h ../core/request.h
|
||||
cp.o: ../core/requesttypes.h ../core/session.h ../core/rebus.h
|
||||
cp.o: ../core/plugindata.h ../core/function.h ../core/compress.h
|
||||
cp.o: ../core/acceptencodingparser.h ../core/acceptbaseparser.h
|
||||
cp.o: ../core/htmlfilter.h ../core/postmultiparser.h ../core/data.h
|
||||
cp.o: ../core/dirs.h ../core/users.h ../core/groups.h ../core/functions.h
|
||||
cp.o: ../core/lastcontainer.h ../core/mounts.h ../core/mount.h
|
||||
cp.o: ../core/loadavg.h
|
||||
createthread.o: content.h ../core/item.h ../templates/templates.h
|
||||
createthread.o: ../templates/patterncacher.h ../templates/misc.h
|
||||
createthread.o: ../templates/localefilter.h ../core/locale.h
|
||||
|
||||
@@ -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 subject.o thread.o ticket.o uname.o upload.o who.o
|
||||
o = adduser.o cat.o content.o cp.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
|
||||
|
||||
@@ -112,6 +112,61 @@ void Content::SetDefaultFunction()
|
||||
}
|
||||
|
||||
|
||||
void Content::FunNothing()
|
||||
{
|
||||
/* do nothing */
|
||||
}
|
||||
|
||||
|
||||
void Content::CallFunction()
|
||||
{
|
||||
static FunItem tab[] = {
|
||||
{FUN_LOGOUT, &Content::FunLogout},
|
||||
{FUN_CAT, &Content::FunCat},
|
||||
{FUN_LS, &Content::FunLs},
|
||||
{FUN_EMACS, &Content::FunEmacs},
|
||||
{FUN_MKDIR, &Content::FunMkdir},
|
||||
{FUN_DEFAULT, &Content::FunDefault},
|
||||
{FUN_PRIV, &Content::FunPriv},
|
||||
{FUN_RM, &Content::FunRm},
|
||||
{FUN_RUN, &Content::FunRun},
|
||||
{FUN_NODE, &Content::FunNode},
|
||||
{FUN_WHO, &Content::FunWho},
|
||||
{FUN_LAST, &Content::FunLast},
|
||||
{FUN_THREAD, &Content::FunThread},
|
||||
{FUN_RELOAD, &Content::FunReload},
|
||||
{FUN_UPLOAD, &Content::FunUpload},
|
||||
{FUN_TICKET, &Content::FunTicket},
|
||||
{FUN_CKEDITOR, &Content::FunEmacs},
|
||||
{FUN_LOGIN, &Content::FunLogin},
|
||||
{FUN_MV, &Content::FunMv},
|
||||
{FUN_UNAME, &Content::FunUname},
|
||||
{FUN_CHMOD, &Content::FunPriv},
|
||||
{FUN_CHOWN, &Content::FunPriv},
|
||||
{FUN_DOWNLOAD, &Content::FunDownload},
|
||||
{FUN_ADDUSER, &Content::FunAddUser},
|
||||
{FUN_SUBJECT, &Content::FunSubject},
|
||||
{FUN_CP, &Content::FunCp},
|
||||
{FUN_UPTIME, &Content::FunNothing},
|
||||
{FUN_EDITTICKET,&Content::FunEditTicket},
|
||||
{FUN_CREATETHREAD, &Content::FunCreateThread},
|
||||
{FUN_CREATETICKET, &Content::FunCreateTicket}
|
||||
};
|
||||
|
||||
size_t len = sizeof(tab) / sizeof(FunItem);
|
||||
size_t i;
|
||||
|
||||
for(i=0 ; i<len ; ++i)
|
||||
{
|
||||
if( tab[i].code == request.pfunction->code )
|
||||
{
|
||||
(this->*tab[i].fun)();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
request.status = WINIX_ERR_PERMISSION_DENIED;
|
||||
}
|
||||
|
||||
|
||||
void Content::MakeStandardFunction()
|
||||
@@ -145,102 +200,51 @@ void Content::MakeStandardFunction()
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if( request.pfunction->code == FUN_LOGOUT )
|
||||
FunLogout();
|
||||
else
|
||||
if( request.pfunction->code == FUN_CAT )
|
||||
FunCat();
|
||||
else
|
||||
if( request.pfunction->code == FUN_LS )
|
||||
FunLs();
|
||||
else
|
||||
if( request.pfunction->code == FUN_EMACS )
|
||||
FunEmacs();
|
||||
else
|
||||
if( request.pfunction->code == FUN_MKDIR )
|
||||
FunMkdir();
|
||||
else
|
||||
if( request.pfunction->code == FUN_DEFAULT )
|
||||
FunDefault();
|
||||
else
|
||||
if( request.pfunction->code == FUN_PRIV )
|
||||
FunPriv();
|
||||
else
|
||||
if( request.pfunction->code == FUN_RM )
|
||||
FunRm();
|
||||
else
|
||||
if( request.pfunction->code == FUN_RUN )
|
||||
FunRun();
|
||||
else
|
||||
if( request.pfunction->code == FUN_NODE )
|
||||
FunNode();
|
||||
else
|
||||
if( request.pfunction->code == FUN_WHO )
|
||||
FunWho();
|
||||
else
|
||||
if( request.pfunction->code == FUN_LAST )
|
||||
FunLast();
|
||||
else
|
||||
if( request.pfunction->code == FUN_THREAD )
|
||||
FunThread();
|
||||
else
|
||||
if( request.pfunction->code == FUN_RELOAD )
|
||||
FunReload();
|
||||
else
|
||||
if( request.pfunction->code == FUN_CREATETHREAD )
|
||||
FunCreateThread();
|
||||
else
|
||||
if( request.pfunction->code == FUN_UPLOAD )
|
||||
FunUpload();
|
||||
else
|
||||
if( request.pfunction->code == FUN_CREATETICKET )
|
||||
FunCreateTicket();
|
||||
else
|
||||
if( request.pfunction->code == FUN_EDITTICKET )
|
||||
FunEditTicket();
|
||||
else
|
||||
if( request.pfunction->code == FUN_TICKET )
|
||||
FunTicket();
|
||||
else
|
||||
if( request.pfunction->code == FUN_CKEDITOR )
|
||||
FunEmacs();
|
||||
else
|
||||
if( request.pfunction->code == FUN_LOGIN )
|
||||
FunLogin();
|
||||
else
|
||||
if( request.pfunction->code == FUN_UPTIME )
|
||||
{ /* do nothing */ }
|
||||
else
|
||||
if( request.pfunction->code == FUN_MV )
|
||||
FunMv();
|
||||
else
|
||||
if( request.pfunction->code == FUN_UNAME )
|
||||
FunUname();
|
||||
else
|
||||
if( request.pfunction->code == FUN_CHMOD )
|
||||
FunPriv();
|
||||
else
|
||||
if( request.pfunction->code == FUN_CHOWN )
|
||||
FunPriv();
|
||||
else
|
||||
if( request.pfunction->code == FUN_DOWNLOAD )
|
||||
FunDownload();
|
||||
else
|
||||
if( request.pfunction->code == FUN_ADDUSER )
|
||||
FunAddUser();
|
||||
else
|
||||
if( request.pfunction->code == FUN_SUBJECT )
|
||||
FunSubject();
|
||||
else
|
||||
request.status = WINIX_ERR_PERMISSION_DENIED;
|
||||
|
||||
|
||||
CallFunction();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Content::CallPostFunction()
|
||||
{
|
||||
static FunItem tab[] = {
|
||||
{FUN_RUN, &Content::PostFunRun},
|
||||
{FUN_EMACS, &Content::PostFunEmacs},
|
||||
{FUN_MKDIR, &Content::PostFunMkdir},
|
||||
{FUN_DEFAULT, &Content::PostFunDefault},
|
||||
{FUN_PRIV, &Content::PostFunPriv},
|
||||
{FUN_CHMOD, &Content::PostFunPriv},
|
||||
{FUN_CHOWN, &Content::PostFunPriv},
|
||||
{FUN_LOGIN, &Content::PostFunLogin},
|
||||
{FUN_UPLOAD, &Content::PostFunUpload},
|
||||
{FUN_EDITTICKET,&Content::PostFunEditTicket},
|
||||
{FUN_CKEDITOR, &Content::PostFunEmacs},
|
||||
{FUN_ADDUSER, &Content::PostFunAddUser},
|
||||
{FUN_MV, &Content::PostFunMv},
|
||||
{FUN_SUBJECT, &Content::PostFunSubject},
|
||||
{FUN_CP, &Content::PostFunCp},
|
||||
{FUN_CREATETHREAD, &Content::PostFunCreateThread},
|
||||
{FUN_CREATETICKET, &Content::PostFunCreateTicket}
|
||||
};
|
||||
|
||||
size_t len = sizeof(tab) / sizeof(FunItem);
|
||||
size_t i;
|
||||
|
||||
for(i=0 ; i<len ; ++i)
|
||||
{
|
||||
if( tab[i].code == request.pfunction->code )
|
||||
{
|
||||
(this->*tab[i].fun)();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
log << log1 << "Content: unknown post function" << logend;
|
||||
request.status = WINIX_ERR_PERMISSION_DENIED;
|
||||
}
|
||||
|
||||
|
||||
void Content::MakePost()
|
||||
{
|
||||
if( request.role == Request::authorizer )
|
||||
@@ -259,70 +263,7 @@ void Content::MakePost()
|
||||
return;
|
||||
}
|
||||
|
||||
switch( request.pfunction->code )
|
||||
{
|
||||
case FUN_RUN:
|
||||
PostFunRun();
|
||||
break;
|
||||
|
||||
case FUN_EMACS:
|
||||
PostFunEmacs();
|
||||
break;
|
||||
|
||||
case FUN_MKDIR:
|
||||
PostFunMkdir();
|
||||
break;
|
||||
|
||||
case FUN_DEFAULT:
|
||||
PostFunDefault();
|
||||
break;
|
||||
|
||||
case FUN_PRIV:
|
||||
case FUN_CHMOD:
|
||||
case FUN_CHOWN:
|
||||
PostFunPriv();
|
||||
break;
|
||||
|
||||
case FUN_LOGIN:
|
||||
PostFunLogin();
|
||||
break;
|
||||
|
||||
case FUN_CREATETHREAD:
|
||||
PostFunCreateThread();
|
||||
break;
|
||||
|
||||
case FUN_UPLOAD:
|
||||
PostFunUpload();
|
||||
break;
|
||||
|
||||
case FUN_CREATETICKET:
|
||||
PostFunCreateTicket();
|
||||
break;
|
||||
|
||||
case FUN_EDITTICKET:
|
||||
PostFunEditTicket();
|
||||
break;
|
||||
|
||||
case FUN_CKEDITOR:
|
||||
PostFunEmacs();
|
||||
break;
|
||||
|
||||
case FUN_ADDUSER:
|
||||
PostFunAddUser();
|
||||
break;
|
||||
|
||||
case FUN_MV:
|
||||
PostFunMv();
|
||||
break;
|
||||
|
||||
case FUN_SUBJECT:
|
||||
PostFunSubject();
|
||||
break;
|
||||
|
||||
default:
|
||||
log << log1 << "Content: unknown post function" << logend;
|
||||
break;
|
||||
}
|
||||
CallPostFunction();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -66,6 +66,15 @@ class Content
|
||||
Db::ItemQuery mv_auth_iq;
|
||||
|
||||
|
||||
/*
|
||||
cp
|
||||
*/
|
||||
bool CpCheckAccessFrom();
|
||||
void CpAuth(Item & item);
|
||||
void CpItem(Item & item, bool redirect = true);
|
||||
void PostFunCp();
|
||||
void FunCp();
|
||||
|
||||
|
||||
|
||||
void SetDefaultFunctionForFile();
|
||||
@@ -73,13 +82,33 @@ class Content
|
||||
void SetDefaultFunction();
|
||||
bool DirsHaveReadExecPerm();
|
||||
|
||||
|
||||
/*
|
||||
calling functions (standard, post)
|
||||
*/
|
||||
typedef void (Content::*Fun)();
|
||||
|
||||
struct FunItem
|
||||
{
|
||||
int code;
|
||||
Fun fun;
|
||||
};
|
||||
|
||||
void FunNothing();
|
||||
void CallFunction();
|
||||
void MakeStandardFunction();
|
||||
|
||||
void CallPostFunction();
|
||||
void MakePost();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void SetUser(Item & item);
|
||||
bool CheckRebus();
|
||||
|
||||
|
||||
void MakePost();
|
||||
|
||||
void FunCat();
|
||||
void FunLogout();
|
||||
@@ -145,14 +174,16 @@ class Content
|
||||
|
||||
void ReadItemContentWithType(Item & item);
|
||||
bool FunEmacsCheckAccess();
|
||||
void PostFunEmacsAdd();
|
||||
void PostFunEmacsAdd(Item & item);
|
||||
void PostFunEmacsEdit(bool with_url);
|
||||
bool PostEmacsCheckAbuse(bool adding);
|
||||
void PostFunEmacsModifyMountPoint(bool adding);
|
||||
void PostFunEmacs();
|
||||
|
||||
bool FunMkdirCheckAccess();
|
||||
void PostFunMkdir(bool add_to_dir_table = false, int privileges = 0755 );
|
||||
void PostFunMkdir(bool add_to_dir_table, int privileges);
|
||||
void PostFunMkdir();
|
||||
|
||||
void Mkdir(Item & item, bool add_to_dir_table);
|
||||
long PostFunDefaultParsePath();
|
||||
void PostFunDefault();
|
||||
|
||||
105
content/cp.cpp
Executable file
105
content/cp.cpp
Executable file
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008-2010, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include "content.h"
|
||||
#include "../core/request.h"
|
||||
#include "../core/data.h"
|
||||
#include "../core/misc.h"
|
||||
|
||||
|
||||
bool Content::CpCheckAccessFrom()
|
||||
{
|
||||
if( request.is_item )
|
||||
{
|
||||
if( !request.HasReadAccess(request.item) )
|
||||
{
|
||||
request.status = WINIX_ERR_PERMISSION_DENIED;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// dirs are checked in function parser
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void Content::CpAuth(Item & item)
|
||||
{
|
||||
if( !request.MakePath(item, mv_new_path, true) )
|
||||
{
|
||||
request.status = WINIX_ERR_PERMISSION_DENIED;
|
||||
return;
|
||||
}
|
||||
|
||||
if( CopyFile(item.auth_path, mv_new_path) )
|
||||
{
|
||||
log << log1 << "Content: copied static file from: " << item.auth_path << ", to: " << mv_new_path << logend;
|
||||
item.auth_path = mv_new_path;
|
||||
request.status = db.EditAuthById(item, item.id);
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log1 << "Content: can't copy a file from: " << item.auth_path << ", to: " << mv_new_path << logend;
|
||||
request.status = WINIX_ERR_PERMISSION_DENIED;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Content::CpItem(Item & item, bool redirect)
|
||||
{
|
||||
if( MoveIsTheSameFile(item) )
|
||||
return;
|
||||
|
||||
if( !mv_file.empty() )
|
||||
{
|
||||
item.url = mv_file;
|
||||
PrepareUrl(item);
|
||||
}
|
||||
|
||||
item.parent_id = mv_dir_id;
|
||||
PostFunEmacsAdd(item);
|
||||
|
||||
if( request.status == WINIX_ERR_OK )
|
||||
{
|
||||
if( item.auth != Item::auth_none )
|
||||
CpAuth(item);
|
||||
|
||||
if( redirect )
|
||||
RedirectTo(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Content::PostFunCp()
|
||||
{
|
||||
if( CpCheckAccessFrom() &&
|
||||
MoveParseDir(mv_dir_id, mv_dir, mv_file) &&
|
||||
MoveCheckAccessTo(mv_dir_id) )
|
||||
{
|
||||
if( request.is_item )
|
||||
{
|
||||
CpItem(request.item);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* not implemented yet */
|
||||
request.status = WINIX_ERR_PERMISSION_DENIED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Content::FunCp()
|
||||
{
|
||||
CpCheckAccessFrom();
|
||||
}
|
||||
@@ -111,7 +111,7 @@ void Content::PostFunCreateThread()
|
||||
request.item.type = Item::file;
|
||||
request.item.privileges = 0644; // !! tymczasowo
|
||||
request.item.parent_id = request.dir_table.back()->id;
|
||||
PostFunEmacsAdd();
|
||||
PostFunEmacsAdd(request.item);
|
||||
|
||||
if( request.status == WINIX_ERR_OK )
|
||||
AddThread();
|
||||
|
||||
@@ -199,7 +199,7 @@ void Content::PostFunCreateTicket()
|
||||
request.item.type = Item::file;
|
||||
request.item.privileges = 0644; // !! tymczasowo
|
||||
request.item.parent_id = request.dir_table.back()->id;
|
||||
PostFunEmacsAdd();
|
||||
PostFunEmacsAdd(request.item);
|
||||
|
||||
if( request.status == WINIX_ERR_OK )
|
||||
AddTicket();
|
||||
|
||||
@@ -39,9 +39,9 @@ return true;
|
||||
}
|
||||
|
||||
|
||||
void Content::PostFunEmacsAdd()
|
||||
void Content::PostFunEmacsAdd(Item & item)
|
||||
{
|
||||
request.status = db.AddItem(request.item);
|
||||
request.status = db.AddItem(item);
|
||||
|
||||
if( request.status == WINIX_ERR_OK )
|
||||
{
|
||||
@@ -129,7 +129,7 @@ void Content::PostFunEmacs()
|
||||
{
|
||||
request.is_item = true;
|
||||
request.item.privileges = 0644; // !! tymczasowo, bedzie uzyte umask
|
||||
PostFunEmacsAdd();
|
||||
PostFunEmacsAdd(request.item);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -67,6 +67,10 @@ void Content::PostFunMkdir(bool add_to_dir_table, int privileges)
|
||||
}
|
||||
|
||||
|
||||
void Content::PostFunMkdir()
|
||||
{
|
||||
PostFunMkdir(false, 0755);
|
||||
}
|
||||
|
||||
|
||||
void Content::FunMkdir()
|
||||
|
||||
@@ -49,6 +49,7 @@ return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Content::MoveCheckAccessFrom()
|
||||
{
|
||||
if( request.is_item )
|
||||
@@ -125,7 +126,7 @@ return true;
|
||||
|
||||
bool Content::MoveParseDir(long & dir_id, std::string & dir, std::string & file)
|
||||
{
|
||||
std::string * move_to = request.PostVar("moveto");
|
||||
std::string * move_to = request.PostVar("to");
|
||||
|
||||
if( !move_to )
|
||||
{
|
||||
|
||||
@@ -112,7 +112,7 @@ void Content::UploadMulti()
|
||||
request.item.auth = SelectFileType(file_name);
|
||||
|
||||
PrepareUrl(request.item);
|
||||
PostFunEmacsAdd(); // always adding a new item
|
||||
PostFunEmacsAdd(request.item); // always adding a new item
|
||||
|
||||
if( !UploadCreatePath() )
|
||||
return;
|
||||
@@ -150,7 +150,7 @@ void Content::UploadSingle()
|
||||
PrepareUrl(request.item);
|
||||
}
|
||||
|
||||
PostFunEmacsAdd(); // always adding a new item
|
||||
PostFunEmacsAdd(request.item); // always adding a new item
|
||||
|
||||
// url can be changed by PostFunEmacsAdd()
|
||||
if( !UploadCreatePath() )
|
||||
|
||||
Reference in New Issue
Block a user