moved winix directories to winixd subdirectory

git-svn-id: svn://ttmath.org/publicrep/winix/trunk@1027 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2016-03-17 08:24:59 +00:00
parent 7d0508961e
commit ed5adb3f23
222 changed files with 0 additions and 0 deletions

19
winixd/functions/Makefile Normal file
View File

@@ -0,0 +1,19 @@
include Makefile.o.dep
all: $(o)
%.o: %.cpp
$(CXX) -c $(CXXFLAGS) $(CXXWINIXINCLUDEFLAGS) $<
depend:
makedepend -Y. $(CXXWINIXINCLUDEFLAGS) -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
include Makefile.dep

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1 @@
o = account.o adduser.o cat.o chmod.o chown.o ckeditor.o cp.o default.o download.o emacs.o env.o functionbase.o functionparser.o functions.o imgcrop.o ipban.o last.o ln.o locale.o login.o logout.o ls.o man.o meta.o mkdir.o mount.o mv.o nicedit.o node.o passwd.o priv.o privchanger.o pw.o reload.o rm.o rmuser.o run.o sort.o specialdefault.o stat.o subject.o template.o timezone.o tinymce.o uname.o upload.o uptime.o vim.o who.o

View File

@@ -0,0 +1,167 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2013-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "account.h"
#include "core/log.h"
#include "core/misc.h"
#include "functions/functions.h"
namespace Winix
{
namespace Fun
{
Account::Account()
{
fun.url = L"account";
}
bool Account::ActivateAccount(User * puser, long code, bool use_ses_log)
{
std::wstring * user_code_str = puser->aenv.GetValue(L"activation_code");
if( user_code_str )
{
if( Tol(*user_code_str) == code )
{
if( db->ChangeUserStatus(puser->id, WINIX_ACCOUNT_READY) == WINIX_ERR_OK )
{
puser->aenv.Remove(L"activation_code");
db->ChangeUserAdminEnv(puser->id, puser->aenv);
puser->status = WINIX_ACCOUNT_READY;
log << log2 << "Account: account: " << puser->name << " activated" << logend;
if( use_ses_log )
slog << loginfo << T(L"account_activated") << logend;
return true;
}
else
{
log << log1 << "Account: account not activated -- database error" << logend;
}
}
else
{
// !! IMPROVE ME if too many errors from the same IP address
// add this ip to the banip list
log << log2 << "Account: incorrect activation code" << logend;
if( use_ses_log )
slog << logerror << T(L"incorrect_activation_code") << logend;
}
}
else
{
log << log1 << "Account: there is no activation_code value in an admin environment" << logend;
if( use_ses_log )
slog << loginfo << T(L"account_cannot_be_activated") << logend;
}
return false;
}
bool Account::ActivateAccount(const std::wstring & login, long code, bool use_ses_log)
{
bool result = false;
User * puser = system->users.GetUser(login);
if( puser )
{
if( puser->status == WINIX_ACCOUNT_NOT_ACTIVATED )
{
result = ActivateAccount(puser, code, use_ses_log);
}
else
{
log << log2 << "Account: this account is already activated" << logend;
if( use_ses_log )
slog << loginfo << T(L"account_already_activated") << logend;
}
}
else
{
log << log1 << "Account: there is no a user: " << login << logend;
}
return result;
}
void Account::ActivateAccount()
{
const std::wstring & login = cur->request->ParamValue(L"login");
long code = Tol(cur->request->ParamValue(L"code"));
if( !login.empty() )
{
ActivateAccount(login, code, true);
system->RedirectToLastItem();
}
}
void Account::MakePost()
{
}
void Account::MakeGet()
{
if( cur->request->IsParam(L"activate") )
ActivateAccount();
}
} // namespace
} // namespace Winix

View File

@@ -0,0 +1,71 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2013-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_winix_functions_account
#define headerfile_winix_functions_account
#include "functionbase.h"
namespace Winix
{
namespace Fun
{
class Account : public FunctionBase
{
public:
Account();
void MakeGet();
void MakePost();
bool ActivateAccount(const std::wstring & login, long code, bool use_ses_log = false);
private:
bool ActivateAccount(User * puser, long code, bool use_ses_log);
void ActivateAccount();
};
} // namespace
} // namespace Winix
#endif

View File

@@ -0,0 +1,295 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2008-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <cstdlib>
#include "adduser.h"
#include "core/slog.h"
#include "core/plugin.h"
#include "core/misc.h"
#include "functions/functions.h"
namespace Winix
{
namespace Fun
{
AddUser::AddUser()
{
fun.url = L"adduser";
need_ssl = true;
}
/*
checking whether a login consists of allowed characters
*/
bool AddUser::HasLoginCorrectChars(const std::wstring & login)
{
for(size_t i=0 ; i<login.size() ; ++i)
if( login[i] <= 32 || IsWhite(login[i]) )
return false;
return true;
}
bool AddUser::IsLoginCorrect(const std::wstring & login, bool use_ses_log)
{
if( login.empty() )
{
log << log2 << "AddUser: login can't be empty" << logend;
if( use_ses_log )
slog << logerror << T("adduser_err_login_empty") << logend;
return false;
}
if( login.size() > WINIX_ACCOUNT_MAX_LOGIN_SIZE )
{
log << log2 << "AddUser: login can't be longer than: " << WINIX_ACCOUNT_MAX_LOGIN_SIZE << " characters" << logend;
if( use_ses_log )
slog << logerror << T("adduser_err_login_too_big") << " " << WINIX_ACCOUNT_MAX_LOGIN_SIZE
<< " " << T("adduser_err_login_too_big2") << logend;
return false;
}
if( !HasLoginCorrectChars(login) )
{
log << log2 << "AddUser: incorrect login characters" << logend;
if( use_ses_log )
slog << logerror << T("adduser_err_login_incorrect_chars") << logend;
return false;
}
if( system->users.IsUser(login) )
{
log << log2 << "AddUser: such user already exists" << logend;
if( use_ses_log )
slog << logerror << T("adduser_err_user_exists") << logend;
return false;
}
return true;
}
bool AddUser::IsEmailCorrect(const std::wstring & email, bool use_ses_log)
{
if( email.size() > WINIX_ACCOUNT_MAX_EMAIL_SIZE )
{
log << log2 << "AddUser: email can't be longer than: " << WINIX_ACCOUNT_MAX_EMAIL_SIZE << " characters" << logend;
if( use_ses_log )
slog << logerror << T("adduser_err_email_too_big") << " " << WINIX_ACCOUNT_MAX_EMAIL_SIZE
<< " " << T("adduser_err_email_too_big2") << logend;
return false;
}
if( !ValidateEmail(email) )
{
log << log2 << "AddUser: email: " << email << " does not seem to be correct" << logend;
if( use_ses_log )
slog << logerror << T(L"adduser_err_email_incorrect") << logend;
return false;
}
return true;
}
// !! IMPROVE ME
// may it should be moved to passwd winix function
/*
adding a new account
this method doesn't check whether the login or password is correct
(consist of allowed characters)
input:
user - all fields from User struct without 'id'
pass - user's password
output:
result: true when the account has been successfully created
and user.id will be set
*/
bool AddUser::AddNewUser(User & user, const std::wstring & pass)
{
up.has_pass = true;
up.pass = pass;
system->crypt.PassHashCrypt(up);
if( db->AddUser(user, up) == WINIX_ERR_OK )
{
if( system->users.AddUser(user) )
{
log << log2 << "AddUser: added a new user: " << user.name << logend;
return true;
}
else
{
log << log1 << "AddUser: I can't add to system->users: " << user.name
<< " but the user was added to the db correctly" << logend;
}
}
else
{
log << log1 << "AddUser: I cannot add a user -- database error" << logend;
}
return false;
}
/*
adding a new account
this method doesn't check whether the login or password is correct
(consist of allowed characters)
input:
login - account login name
pass - password
email - email address
autoactivate - if true then the account will be created with WINIX_ACCOUNT_READY flag
(an email will not be sent)
if false then the flag depends on config->account_need_email_verification
try_login - if true then if there is no a user logged (in this session)
and if the account is ready (has WINIX_ACCOUNT_READY flag)
the the new user will be logged in
use_ses_log - when true the session logger will be used (info about sending an email)
*/
bool AddUser::AddNewUser(const std::wstring & login,
const std::wstring & pass,
const std::wstring & email,
bool autoactivate,
bool try_login,
bool use_ses_log)
{
user.Clear();
user.name = login;
user.email = email;
user.super_user = false;
user.notify = 0;
user.locale_id = config->locale_default_id;
user.time_zone_id = config->time_zone_default_id;
user.status = (config->account_need_email_verification)? WINIX_ACCOUNT_NOT_ACTIVATED : WINIX_ACCOUNT_READY;
long code = 0;
if( autoactivate )
user.status = WINIX_ACCOUNT_READY;
if( user.status == WINIX_ACCOUNT_NOT_ACTIVATED )
{
code = std::rand();
user.aenv.Add(L"activation_code", code);
}
if( AddNewUser(user, pass) )
{
if( try_login && !cur->session->puser && user.status == WINIX_ACCOUNT_READY )
{
system->users.LoginUser(user.id, false);
log << log2 << "AddUser: now logged as: " << user.name << logend;
plugin.Call(WINIX_USER_LOGGED);
}
if( user.status == WINIX_ACCOUNT_NOT_ACTIVATED )
{
system->notify.ActivateAccount(user.name, user.email, code);
if( use_ses_log )
slog << loginfo << T(L"account_email_sent") << logend;
}
return true;
}
return false;
}
void AddUser::MakePost()
{
const std::wstring & login = cur->request->PostVar(L"login");
const std::wstring & pass = cur->request->PostVar(L"password");
const std::wstring & conf_pass = cur->request->PostVar(L"passwordconfirm");
const std::wstring & email = cur->request->PostVar(L"email");
bool autoactivate = false;
if( !IsLoginCorrect(login, true) ||
!IsEmailCorrect(email, true) ||
!functions->fun_passwd.IsPasswordCorrect(pass, conf_pass, true) )
return;
if( cur->session->puser && cur->session->puser->super_user )
{
autoactivate = cur->request->IsPostVar(L"autoactivate");
if( autoactivate )
log << log2 << "AddUser: account activated by an admin" << logend;
}
if( AddNewUser(login, pass, email, autoactivate, true, true) )
system->RedirectToLastItem();
}
void AddUser::MakeGet()
{
}
} // namespace
} // namespace Winix

View File

@@ -0,0 +1,82 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2010-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_winix_functions_adduser
#define headerfile_winix_functions_adduser
#include "functionbase.h"
#include "core/user.h"
namespace Winix
{
namespace Fun
{
class AddUser : public FunctionBase
{
public:
AddUser();
void MakePost();
void MakeGet();
bool IsLoginCorrect(const std::wstring & login, bool use_ses_log = false);
bool IsEmailCorrect(const std::wstring & email, bool use_ses_log = false);
bool HasLoginCorrectChars(const std::wstring & login);
bool AddNewUser(User & user, const std::wstring & pass);
bool AddNewUser(const std::wstring & login,
const std::wstring & pass,
const std::wstring & email,
bool autoactivate,
bool try_login,
bool use_ses_log = false);
private:
UserPass up;
User user;
};
} // namespace
} // namespace Winix
#endif

74
winixd/functions/cat.cpp Normal file
View File

@@ -0,0 +1,74 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2008-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "cat.h"
namespace Winix
{
namespace Fun
{
Cat::Cat()
{
fun.url = L"cat";
}
void Cat::MakeGet()
{
if( !cur->request->is_item )
{
log << log1 << "Content: cat function requires an item" << logend;
cur->request->status = WINIX_ERR_NO_ITEM;
return;
}
if( !system->HasReadAccess(cur->request->item) )
{
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
return;
}
cur->request->send_as_attachment = cur->request->IsParam(L"attachment");
}
} // namespace
} // namespace Winix

62
winixd/functions/cat.h Normal file
View File

@@ -0,0 +1,62 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2010-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_winix_functions_cat
#define headerfile_winix_functions_cat
#include "functionbase.h"
namespace Winix
{
namespace Fun
{
class Cat : public FunctionBase
{
public:
Cat();
void MakeGet();
};
} // namespace Fun
} // namespace Winix
#endif

View File

@@ -0,0 +1,77 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2008-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "chmod.h"
namespace Winix
{
namespace Fun
{
Chmod::Chmod()
{
fun.url = L"chmod";
}
void Chmod::MakePost()
{
priv_changer.SetCur(cur);
priv_changer.SetSystem(system);
priv_changer.SetDb(db);
priv_changer.Change(false, true);
}
void Chmod::MakeGet()
{
priv_changer.SetCur(cur);
priv_changer.SetSystem(system);
priv_changer.SetDb(db);
priv_changer.CheckAccess();
}
} // namespace
} // namespace Winix

67
winixd/functions/chmod.h Normal file
View File

@@ -0,0 +1,67 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2010-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_winix_functions_chmod
#define headerfile_winix_functions_chmod
#include "functionbase.h"
#include "privchanger.h"
namespace Winix
{
namespace Fun
{
class Chmod : public FunctionBase
{
public:
Chmod();
void MakePost();
void MakeGet();
private:
PrivChanger priv_changer;
};
} // namespace
} // namespace Winix
#endif

View File

@@ -0,0 +1,77 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2008-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "chown.h"
namespace Winix
{
namespace Fun
{
Chown::Chown()
{
fun.url = L"chown";
}
void Chown::MakePost()
{
priv_changer.SetCur(cur);
priv_changer.SetSystem(system);
priv_changer.SetDb(db);
priv_changer.Change(true, false);
}
void Chown::MakeGet()
{
priv_changer.SetCur(cur);
priv_changer.SetSystem(system);
priv_changer.SetDb(db);
priv_changer.CheckAccess();
}
} // namespace
} // namespace Winix

67
winixd/functions/chown.h Normal file
View File

@@ -0,0 +1,67 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2010-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_winix_functions_chown
#define headerfile_winix_functions_chown
#include "functionbase.h"
#include "privchanger.h"
namespace Winix
{
namespace Fun
{
class Chown : public FunctionBase
{
public:
Chown();
void MakePost();
void MakeGet();
private:
PrivChanger priv_changer;
};
} // namespace
} // namespace Winix
#endif

View File

@@ -0,0 +1,85 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2008-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "ckeditor.h"
#include "functions.h"
namespace Winix
{
namespace Fun
{
Ckeditor::Ckeditor()
{
fun.url = L"ckeditor";
}
void Ckeditor::Init()
{
system->AddCommonFileToVar(L"winix/ckeditor_full.js", L"ckeditor_full.js");
system->AddCommonFileToVar(L"winix/ckeditor_winix.js", L"ckeditor_winix.js");
}
bool Ckeditor::HasAccess()
{
return functions->fun_emacs.HasAccess();
}
void Ckeditor::MakeGet()
{
cur->session->last_css.clear();
int parcss = system->mounts.MountParCss();
if( cur->mount->param[parcss].defined )
cur->session->last_css = cur->mount->param[parcss].arg;
}
void Ckeditor::MakePost()
{
functions->fun_emacs.MakePost();
}
} // namespace
} // namespace Winix

View File

@@ -0,0 +1,65 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2011-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_winix_functions_ckeditor
#define headerfile_winix_functions_ckeditor
#include "functionbase.h"
namespace Winix
{
namespace Fun
{
class Ckeditor : public FunctionBase
{
public:
Ckeditor();
void Init();
bool HasAccess();
void MakeGet();
void MakePost();
};
} // namespace
} // namespace Winix
#endif

429
winixd/functions/cp.cpp Normal file
View File

@@ -0,0 +1,429 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2008-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "cp.h"
#include "core/misc.h"
#include "functions.h"
#include "core/plugin.h"
namespace Winix
{
namespace Fun
{
Cp::Cp()
{
fun.url = L"cp";
}
bool Cp::HasAccess()
{
return CheckAccessFrom();
}
bool Cp::CheckAccessFrom()
{
if( cur->request->is_item )
{
if( !system->HasReadAccess(cur->request->item) || cur->request->item.type == Item::symlink )
{
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
return false;
}
}
else
if( !cur->request->IsParam(L"r") )
{
// directories need 'r' parameter
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
}
return true;
}
bool Cp::CheckAccessTo()
{
if( dir_tab.empty() ||
!system->HasReadExecAccessToPath(dir_tab) ||
!system->HasWriteAccess(*dir_tab.back()) )
{
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
return false;
}
return true;
}
bool Cp::ParseDir()
{
const std::wstring & new_dir = cur->request->PostVar(L"to");
int res = system->dirs.FollowLink(cur->request->dir_tab, new_dir, dir_tab, file);
if( res == 3 )
cur->request->status = WINIX_ERR_NO_ROOT_DIR;
else
if( res != 0 && res != 1 )
cur->request->status = WINIX_ERR_INCORRECT_DIR;
return res == 0 || res == 1;
}
bool Cp::CopyStaticFile(const std::wstring & from, const std::wstring & to)
{
if( from == to )
{
log << log3 << "Cp: the same path to a static file: " << to << logend;
return true;
}
if( Winix::CopyFile(from, to) )
{
log << log2 << "Cp: copied a static file from: " << from << ", to: " << to << logend;
return true;
}
else
{
log << log1 << "Cp: can't copy a file from: " << from << ", to: " << to << logend;
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
return false;
}
}
void Cp::CopyStaticFile(Item & item)
{
bool res1, res2, res3, res4, res5;
res1 = system->MakeFilePath(item, old_path, false);
res2 = !item.has_thumb || system->MakeFilePath(item, old_path_thumb, true);
res3 = system->CreateNewFile(item);
res4 = system->MakeFilePath(item, new_path, false, true, config->upload_dirs_chmod);
res5 = !item.has_thumb || system->MakeFilePath(item, new_path_thumb, true, true, config->upload_dirs_chmod);
if( !res1 || !res2 || !res3 || !res4 || !res5 )
{
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
return;
}
if( CopyStaticFile(old_path, new_path) )
{
cur->request->status = db->EditFileById(item, item.id);
if( item.has_thumb )
CopyStaticFile(old_path_thumb, new_path_thumb);
}
}
void Cp::SetNewAttributes(Item & item)
{
item.user_id = new_user;
item.group_id = new_group;
item.SetDateModifyToNow();
}
void Cp::CopyFile(Item & item, long dst_dir_id)
{
if( !preserve_attr )
SetNewAttributes(item);
item.parent_id = dst_dir_id;
cur->request->status = db->AddItem(item);
if( cur->request->status == WINIX_ERR_OK )
{
if( item.file_type != WINIX_ITEM_FILETYPE_NONE )
CopyStaticFile(item);
plugin.Call(WINIX_FILE_COPIED, &item);
}
}
void Cp::CopyFileOrSymlink(Item & item, long dst_dir_id)
{
if( !system->HasReadAccess(item) )
return; // !! w przyszlosci bedziemy dodawac komunikaty do specjalnej tablicy (narazie nie zaimplementowane)
if( item.type == Item::symlink && follow_symlinks )
{
if( system->dirs.CreateDirTab(item.parent_id, symlink_dir_tab) )
{
int res = system->FollowAllLinks(symlink_dir_tab, item.link_to, symlink_dir_tab, item);
if( res == 0 )
CopyDirTree(*symlink_dir_tab.back(), dst_dir_id);
else
if( res == 1 )
CopyFile(item, dst_dir_id);
}
}
else
{
CopyFile(item, dst_dir_id);
}
}
void Cp::Prepare()
{
iq.SetAll(true, false);
iq.WhereType(Item::dir, false);
new_user = -1;
new_group = dir_tab.back()->group_id;
if( cur->session->puser )
new_user = cur->session->puser->id;
loop_checker.clear();
}
void Cp::CopyFilesInDir(const Item & dir, long dst_dir_id)
{
iq.WhereParentId(dir.id);
db->GetItems(item_tab, iq);
for(size_t i=0 ; i<item_tab.size() ; ++i)
CopyFileOrSymlink(item_tab[i], dst_dir_id);
}
void Cp::CopyDirContentTree(const Item & dir, long dst_dir_id)
{
DirContainer::ParentIterator i = system->dirs.FindFirstChild(dir.id);
// go through all directories
for( ; i != system->dirs.ParentEnd() ; i = system->dirs.NextChild(i) )
CopyDirTree(*(i->second), dst_dir_id);
CopyFilesInDir(dir, dst_dir_id);
}
bool Cp::WasThisDir(const Item & dir)
{
for(size_t i=0 ; i<loop_checker.size() ; ++i)
if( loop_checker[i] == dir.id )
return true;
return false;
}
// we shouldn't change 'item' because we have references to our app.dirs objects
long Cp::CopyDirTree(const Item & dir, long dst_dir_id)
{
if( WasThisDir(dir) )
{
log << log1 << "Cp: a loop between directories found (created by a symlink), "
<< "dir_id: " << dir.id << ", dir_url: " << dir.url << logend;
return -1;
}
loop_checker.push_back(dir.id);
temp = dir;
temp.parent_id = dst_dir_id;
if( !file.empty() )
{
temp.url = file;
functions->PrepareUrl(temp);
file.clear();
}
if( !preserve_attr )
SetNewAttributes(temp);
if( remove_defaults )
{
temp.link_to.clear();
temp.link_redirect = 0;
}
cur->request->status = system->dirs.AddDirectory(temp);
loop_checker.push_back(temp.id);
// remember the new dir_id because temp can be changed
// this method is called in recurrences
long new_dir_id = temp.id;
if( system->HasReadExecAccess(dir) )
CopyDirContentTree(dir, temp.id);
return new_dir_id; // and return it
}
bool Cp::IsTheSameFile(const Item & item)
{
if( file.empty() )
{
if( item.parent_id == dir_tab.back()->id )
return true; // nothing to do
}
else
{
if( item.parent_id == dir_tab.back()->id && item.url == file )
return true; // nothing to do
}
return false;
}
// here 'item' can be changed in place
void Cp::PostCopyFile(Item & item, bool redirect)
{
if( IsTheSameFile(item) )
return;
if( !file.empty() )
{
item.url = file;
functions->PrepareUrl(item);
file.clear();
}
CopyFileOrSymlink(item, dir_tab.back()->id);
if( cur->request->status == WINIX_ERR_OK && redirect )
system->RedirectTo(item);
}
void Cp::PostCopyDirContent(const Item & dir, bool redirect)
{
if( !file.empty() )
{
cur->request->status = WINIX_ERR_INCORRECT_DIR;
return;
}
if( dir_tab.back()->id == dir.id )
return; // nothing to do
CopyDirContentTree(dir, dir_tab.back()->id);
if( cur->request->status == WINIX_ERR_OK && redirect )
system->RedirectTo(dir_tab.back()->id);
}
void Cp::PostCopyDir(const Item & dir, bool redirect)
{
long dir_id = dir_tab.back()->id;
if( file.empty() && dir_id == dir.id )
return; // nothing to do
long new_dir_id = CopyDirTree(dir, dir_id);
if( new_dir_id != -1 && cur->request->status == WINIX_ERR_OK && redirect )
system->RedirectTo(new_dir_id);
}
void Cp::Clear()
{
loop_checker.clear();
dir_tab.clear();
item_tab.clear();
symlink_dir_tab.clear();
}
void Cp::MakePost()
{
if( ParseDir() && CheckAccessTo() )
{
Prepare();
preserve_attr = cur->request->IsPostVar(L"preserveattr");
remove_defaults = cur->request->IsPostVar(L"removedefaults");
follow_symlinks = cur->request->IsPostVar(L"followsymlinks");
if( cur->request->is_item )
{
PostCopyFile(cur->request->item);
}
else
{
if( cur->request->IsPostVar(L"onlycontent") )
PostCopyDirContent(*cur->request->dir_tab.back());
else
PostCopyDir(*cur->request->dir_tab.back());
}
Clear();
}
}
} // namespace
} // namespace Winix

108
winixd/functions/cp.h Normal file
View File

@@ -0,0 +1,108 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2010-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_winix_functions_cp
#define headerfile_winix_functions_cp
#include "functionbase.h"
namespace Winix
{
namespace Fun
{
class Cp : public FunctionBase
{
public:
Cp();
bool HasAccess();
void MakePost();
private:
Item temp;
DbItemQuery iq;
bool remove_defaults;
bool preserve_attr;
bool follow_symlinks;
long new_user;
long new_group;
// destination dir (will not be empty)
std::vector<Item*> dir_tab, symlink_dir_tab;
// for testing loops in directories (between symlinks)
std::vector<long> loop_checker;
// destination file (if exists)
std::wstring file;
// for copying static files
std::wstring new_path, new_path_thumb;
std::wstring old_path, old_path_thumb;
std::vector<Item> item_tab;
bool WasThisDir(const Item & dir);
bool CheckAccessFrom();
bool CheckAccessTo();
bool ParseDir();
bool CopyStaticFile(const std::wstring & from, const std::wstring & to);
void CopyStaticFile(Item & item);
void SetNewAttributes(Item & item);
void CopyFile(Item & item, long dst_dir_id);
void CopyFileOrSymlink(Item & item, long dst_dir_id);
void Prepare();
void CopyFilesInDir(const Item & dir, long dst_dir_id);
void CopyDirContentTree(const Item & item, long dst_dir_id);
long CopyDirTree(const Item & item, long dst_dir_id);
bool IsTheSameFile(const Item & item);
void Clear();
void PostCopyFile(Item & item, bool redirect = true);
void PostCopyDirContent(const Item & dir, bool redirect = true);
void PostCopyDir(const Item & dir, bool redirect = true);
};
} // namespace
} // namespace Winix
#endif

View File

@@ -0,0 +1,83 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2008-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "default.h"
namespace Winix
{
namespace Fun
{
Default::Default()
{
fun.url = L"default";
}
bool Default::HasAccess()
{
return !cur->request->is_item && system->HasWriteAccess(*cur->request->dir_tab.back());
}
void Default::MakePost()
{
Item & dir = *cur->request->dir_tab.back();
dir.link_to = cur->request->PostVar(L"linkto");
dir.link_redirect = cur->request->IsPostVar(L"makeredirect") ? 1 : 0;
TrimWhite(dir.link_to);
// !! dodac sprawdzenie czy link_to jest pusty teraz
cur->request->status = db->EditLinkItem(dir.id, dir.link_to, dir.link_redirect);
if( cur->request->status == WINIX_ERR_OK )
{
log << log2 << "Default: changed link_to: " << dir.link_to << ", for dir_id: " << dir.id << logend;
system->RedirectToLastDir();
}
}
} // namespace
} // namespace Winix

View File

@@ -0,0 +1,63 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2010-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_winix_functions_default
#define headerfile_winix_functions_default
#include "functionbase.h"
namespace Winix
{
namespace Fun
{
class Default : public FunctionBase
{
public:
Default();
bool HasAccess();
void MakePost();
};
} // namespace
} // namespace Winix
#endif

View File

@@ -0,0 +1,86 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2008-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "download.h"
namespace Winix
{
namespace Fun
{
Download::Download()
{
fun.url = L"download";
}
void Download::MakeGet()
{
// !! moze wywalic to no_item i wszedzie w takich miejscach dac poprostu permission_denied?
if( !cur->request->is_item )
{
log << log1 << "Content: download function requires an item" << logend;
cur->request->status = WINIX_ERR_NO_ITEM;
return;
}
if( !system->HasReadAccess(cur->request->item) ||
cur->request->item.file_type == WINIX_ITEM_FILETYPE_NONE ||
cur->request->item.file_path.empty() )
{
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
return;
}
cur->request->send_as_attachment = cur->request->IsParam(L"attachment");
if( cur->request->item.has_thumb && cur->request->IsParam(L"thumb") )
system->MakeFilePath(cur->request->item, cur->request->x_sendfile, true);
else
system->MakeFilePath(cur->request->item, cur->request->x_sendfile);
}
} // namespace
} // namespace Winix

View File

@@ -0,0 +1,64 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2010-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_winix_functions_download
#define headerfile_winix_functions_download
#include "functionbase.h"
namespace Winix
{
namespace Fun
{
class Download : public FunctionBase
{
public:
Download();
void MakeGet();
private:
};
} // namespace
} // namespace Winix
#endif

188
winixd/functions/emacs.cpp Normal file
View File

@@ -0,0 +1,188 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2008-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "emacs.h"
#include "templates/templates.h"
#include "functions.h"
namespace Winix
{
namespace Fun
{
Emacs::Emacs()
{
fun.url = L"emacs";
}
bool Emacs::HasAccess(const Item & item)
{
if( cur->session->puser && cur->session->puser->super_user )
// super user can use emacs everywhere
return true;
if( !system->HasWriteAccess(item) )
return false;
if( !system->mounts.pmount->IsPar(system->mounts.MountParEmacsOn()) )
return true;
if( system->mounts.pmount->IsArg(system->mounts.MountParEmacsOn(), cur->request->dir_tab.size()) )
return true;
return false;
}
bool Emacs::HasAccess()
{
return HasAccess(*cur->request->last_item);
}
bool Emacs::PostEmacsCheckAbuse(bool adding)
{
if( !system->rebus.CheckRebus() )
{
cur->request->status = WINIX_ERR_INCORRECT_REBUS;
return false;
}
// !! is tested in createthread once
functions->CheckGetPostTimes();
if( cur->session->spam_score > 0 )
{
cur->request->status = WINIX_ERR_SPAM;
log << log1 << "Emacs: ignoring due to suspected spamming" << logend;
return false;
}
return true;
}
// !! zmienic nazwy
// albo w ogole te metody nie sa potrzebne teraz (byly zmiany)
void Emacs::PostFunEmacsModifyMountPoint(bool adding)
{
system->RedirectTo(cur->request->item);
}
int Emacs::NotifyCodeEdit()
{
// !! nie potrzebne
// if( system->mounts.pmount->type == system->mounts.MountTypeThread() )
// return WINIX_NOTIFY_CODE_THREAD_POST_CHANGED;
return WINIX_NOTIFY_CODE_EDIT;
}
int Emacs::NotifyCodeAdd()
{
// !! nie potrzebne
// if( system->mounts.pmount->type == system->mounts.MountTypeThread() )
// return WINIX_NOTIFY_CODE_THREAD_REPLAYED;
return WINIX_NOTIFY_CODE_ADD;
}
void Emacs::MakePost()
{
bool adding = !cur->request->is_item;
if( !adding )
old_url = cur->request->item.url;
functions->ReadItem(cur->request->item, Item::file);
if( adding )
functions->SetUser(cur->request->item); // set user before checking the rebus
if( !PostEmacsCheckAbuse(adding) )
return;
if( adding )
{
cur->request->is_item = true; // !! moze lepiej nie ustawiac is_item? (bo jak wystapi blad np dodania do bazy danych
// to formularz edycji zmieni sie z 'dodaj' na 'edytuj'
cur->request->item.privileges = system->NewFilePrivileges();
cur->request->status = system->AddFile(cur->request->item, NotifyCodeAdd());
}
else
{
cur->request->status = system->EditFile(cur->request->item, cur->request->item.url != old_url, NotifyCodeEdit());
}
if( cur->request->status == WINIX_ERR_OK )
{
PostFunEmacsModifyMountPoint(adding);
functions->CheckSpecialFile(cur->request->item);
}
else
{
log << log1 << "Emacs: error: " << cur->request->status << logend;
}
}
} // namespace
} // namespace Winix

72
winixd/functions/emacs.h Normal file
View File

@@ -0,0 +1,72 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2010-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_winix_functions_emacs
#define headerfile_winix_functions_emacs
#include "functionbase.h"
namespace Winix
{
namespace Fun
{
class Emacs : public FunctionBase
{
public:
Emacs();
bool HasAccess();
void MakePost();
private:
bool HasAccess(const Item & item); // !! takie funkcje to nie powinny byc skladowe modelu?
bool PostEmacsCheckAbuse(bool adding);
void PostFunEmacsModifyMountPoint(bool adding);
int NotifyCodeEdit();
int NotifyCodeAdd();
std::wstring old_url;
};
} // namespace
} // namespace Winix
#endif

220
winixd/functions/env.cpp Normal file
View File

@@ -0,0 +1,220 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2012-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "env.h"
#include "core/log.h"
namespace Winix
{
namespace Fun
{
Env::Env()
{
fun.url = L"env";
puser = 0;
req_id = 0;
}
bool Env::HasAccess()
{
if( !cur->session->puser )
return false;
if( cur->request->IsParam(L"a") )
{
// show/change admin environment variables for a user
if( !cur->session->puser->super_user )
return false;
}
if( !GetUser() )
return false;
return true;
}
bool Env::Parse(const std::wstring & env_str)
{
space.Clear();
conf_parser.SetSpace(space);
conf_parser.SplitSingle(true);
return (conf_parser.ParseString(env_str) == PT::SpaceParser::ok);
}
bool Env::EditAdminEnv(long user_id, const std::wstring & env_str, bool use_ses_log)
{
if( Parse(env_str) )
{
if( db->ChangeUserAdminEnv(user_id, space) == WINIX_ERR_OK )
{
User * puser = system->users.GetUser(user_id);
if( puser )
puser->aenv = space;
return true;
}
else
{
log << log1 << "Evn: a database problem with changing environment variables for user: "
<< cur->session->puser->name << ", id: " << cur->session->puser->id << logend;
}
}
else
{
log << log2 << "Env: Syntax error in line: " << conf_parser.line << logend;
if( use_ses_log )
slog << logerror << T("syntax_error_in_line") << ' ' << conf_parser.line << logend;
}
return false;
}
bool Env::EditEnv(long user_id, const std::wstring & env_str, bool use_ses_log)
{
if( Parse(env_str) )
{
if( db->ChangeUserEnv(user_id, space) == WINIX_ERR_OK )
{
User * puser = system->users.GetUser(user_id);
if( puser )
puser->env = space;
return true;
}
else
{
log << log1 << "Evn: a database problem with changing admin environment variables for user: "
<< cur->session->puser->name << ", id: " << cur->session->puser->id << logend;
}
}
else
{
log << log2 << "Env: Syntax error in line: " << conf_parser.line << logend;
if( use_ses_log )
slog << logerror << T("syntax_error_in_line") << ' ' << conf_parser.line << logend;
}
return false;
}
void Env::SaveEnv()
{
if( GetUser() )
{
const std::wstring & env_str = cur->request->PostVar(L"envvar");
long user_id = GetUser()->id;
bool status = false;
if( cur->request->IsParam(L"a") )
{
if( cur->session->puser->super_user )
status = EditAdminEnv(user_id, env_str, true);
}
else
{
status = EditEnv(user_id, env_str, true);
}
if( status )
system->RedirectToLastItem();
}
}
User * Env::GetUser()
{
if( cur->request->id != req_id )
{
req_id = cur->request->id;
puser = 0;
if( cur->session->puser )
{
if( cur->session->puser->super_user && cur->request->IsPostVar(L"userid") )
{
long id = Tol(cur->request->PostVar(L"userid"));
puser = system->users.GetUser(id);
}
else
{
puser = cur->session->puser;
}
}
}
return puser;
}
void Env::MakePost()
{
if( cur->session->puser )
{
if( cur->request->IsPostVar(L"changeuser") )
{
// show environments variables for the specified user
if( GetUser() )
log << log2 << "Env: changing user to: " << GetUser()->name << ", id: " << GetUser()->id << logend;
}
else
{
// save environment variables
SaveEnv();
}
}
}
} // namespace
} // namespace Winix

83
winixd/functions/env.h Normal file
View File

@@ -0,0 +1,83 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2012-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_winix_functions_env
#define headerfile_winix_functions_env
#include "functionbase.h"
#include "space/spaceparser.h"
namespace Winix
{
namespace Fun
{
class Env : public FunctionBase
{
public:
Env();
bool EditAdminEnv(long user_id, const std::wstring & env_str, bool use_ses_log = false);
bool EditEnv(long user_id, const std::wstring & env_str, bool use_ses_log = false);
bool HasAccess();
void MakePost();
// used mainly by templates
// can return a null pointer
User * GetUser();
private:
PT::SpaceParser conf_parser;
PT::Space space;
User * puser;
size_t req_id;
bool Parse(const std::wstring & env_str);
void SaveEnv();
};
} // namespace
} // namespace Winix
#endif

View File

@@ -0,0 +1,144 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2010-2016, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "functionbase.h"
#include "functions.h"
namespace Winix
{
FunctionBase::FunctionBase()
{
follow_symlinks = true;
template_index = size_t(-1);
need_ssl = false;
fun.user_id = -1;
fun.group_id = -1;
fun.privileges = 07555;
fun.parent_id = -1;
fun.id = -1;
fun.type = Item::file;
}
FunctionBase::~FunctionBase()
{
}
void FunctionBase::SetConfig(Config * pconfig)
{
config = pconfig;
}
void FunctionBase::SetCur(Cur * pcur)
{
cur = pcur;
}
void FunctionBase::SetDb(Db * pdb)
{
db = pdb;
}
void FunctionBase::SetSystem(System * psystem)
{
system = psystem;
}
void FunctionBase::SetFunctions(Functions * pfunctions)
{
functions = pfunctions;
}
void FunctionBase::SetTemplates(Templates * ptemplates)
{
templates = ptemplates;
}
void FunctionBase::SetSynchro(Synchro * psynchro)
{
synchro = psynchro;
}
void FunctionBase::SetSessionManager(SessionManager * pmanager)
{
session_manager = pmanager;
}
void FunctionBase::Init()
{
// this method is called only once at the beginning
// when winix starts
}
bool FunctionBase::HasAccess()
{
// true by default
return true;
}
void FunctionBase::MakePost()
{
// do nothing by default
}
void FunctionBase::MakeGet()
{
// do nothing by default
}
} // namespace Winix

View File

@@ -0,0 +1,112 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2010-2016, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_winix_functions_functionbase
#define headerfile_winix_functions_functionbase
#include <string>
#include <vector>
#include "core/item.h"
#include "db/db.h"
#include "core/request.h"
#include "core/config.h"
#include "core/system.h"
#include "core/synchro.h"
#include "notify/notify.h"
namespace Winix
{
class Functions;
class Templates;
class FunctionBase
{
public:
FunctionBase();
virtual ~FunctionBase();
// user, group, permissions, url (function name)
Item fun;
// auto follow sym links, default: true
bool follow_symlinks;
// html template index (for using with 'patterns' object)
size_t template_index;
// try to use SSL
// if in the config 'use_ssl' is true and 'use_ssl_only_for_logged_users' is true
// then ssl is used only for logged users but sometimes there is a need to use
// SSL even if noone is logged (for example for such functions like 'login' or 'adduser')
// default: false
// (this option is ignored if 'use_ssl' in the config is false)
bool need_ssl;
virtual void Init();
virtual bool HasAccess();
virtual void MakePost();
virtual void MakeGet();
void SetConfig(Config * pconfig);
void SetCur(Cur * pcur);
void SetDb(Db * pdb);
void SetSystem(System * psystem);
void SetFunctions(Functions * pfunctions);
void SetTemplates(Templates * ptemplates);
void SetSynchro(Synchro * psynchro);
void SetSessionManager(SessionManager * pmanager);
protected:
Config * config;
Cur * cur;
Db * db;
System * system;
Functions * functions;
Templates * templates;
Synchro * synchro;
SessionManager * session_manager;
};
} // namespace Winix
#endif

View File

@@ -0,0 +1,420 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2008-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "functionparser.h"
#include "core/log.h"
#include "core/item.h"
#include "core/error.h"
#include "functions.h"
#include "utf8/utf8.h"
namespace Winix
{
FunctionParser::FunctionParser()
{
}
bool FunctionParser::Parse(Cur * pcur, Db * pdb, Functions * pfunctions, System * psystem)
{
db = pdb;
cur = pcur;
system = psystem;
functions = pfunctions;
last_dir = 0;
path = cur->request->env_request_uri.c_str();
ParseDirsItemFunction();
ParseParams();
ParseAnchor();
return cur->request->status == WINIX_ERR_OK;
}
void FunctionParser::ParseDirsItemFunction()
{
if( !AddRootDir() )
return;
ReadName();
while( IsDir() )
{
AddDir();
ReadName();
}
if( name.empty() )
return;
if( CheckAddFunction() )
return;
if( CheckAddItem() )
{
ReadName();
if( !name.empty() )
{
CheckAddFunction();
if( !cur->request->function )
{
log << log3 << "FP: unknown function: " << name << logend;
cur->request->status = WINIX_ERR_NO_ITEM;
}
}
}
}
bool FunctionParser::AddRootDir()
{
last_dir = system->dirs.GetRootDir();
if( !last_dir )
{
log << log3 << "FP: there is not a root directory" << logend;
cur->request->status = WINIX_ERR_INTERNAL_ERROR;
return false;
}
AddDir();
return true;
}
bool FunctionParser::IsDir()
{
// directory names should not be empty
if( name.empty() || !last_dir )
return false;
last_dir = system->dirs.GetDir(name, last_dir->id);
return last_dir != 0;
}
bool FunctionParser::CheckAddItem()
{
// cur->request->dir_tab has at least one element
long parent_id = cur->request->dir_tab.back()->id;
Error status = db->GetItem(parent_id, name, cur->request->item);
if( status == WINIX_ERR_OK )
{
log << log3 << "FP: Item: id: " << cur->request->item.id << ", url: " << cur->request->item.url << logend;
cur->request->last_item = &cur->request->item;
cur->request->is_item = true;
return true;
}
if( status == WINIX_ERR_NO_ITEM )
{
log << log3 << "FP: No Item: url: " << name << logend;
cur->request->status = WINIX_ERR_NO_ITEM;
return false;
}
log << log1 << "FP: db error" << logend;
cur->request->status = WINIX_ERR_INTERNAL_ERROR;
return false;
}
bool FunctionParser::CheckAddFunction()
{
cur->request->function = functions->Find(name);
if( cur->request->function )
{
log << log3 << "FP: Function: " << cur->request->function->fun.url << logend;
return true;
}
return false;
}
void FunctionParser::AddDir()
{
cur->request->dir_tab.push_back( last_dir );
log << log3 << "FP: Directory: ";
if( last_dir->parent_id == -1 )
log << "(root)" << logend;
else
log << last_dir->url << logend;
cur->request->last_item = cur->request->dir_tab.back();
}
void FunctionParser::ParseParams()
{
SkipSlashes();
if( *path == '#' )
{
// there are not any parameters
return;
}
if( *path == '?' )
ParseOrdinaryParams();
else
ParseWinixParams();
}
void FunctionParser::ParseOrdinaryParams()
{
if( *path == '?' )
path += 1;
do
{
ReadOrdinaryParName();
if( name.empty() )
break;
ReadOrdinaryParValue();
if( *path == '&' )
path += 1;
AddParam();
}
while( true );
}
void FunctionParser::ParseWinixParams()
{
do
{
SkipSlashes();
ReadWinixParName();
if( name.empty() )
break;
ReadWinixParValue();
AddParam();
}
while( true );
}
void FunctionParser::AddParam()
{
param.name = name;
param.value = value;
cur->request->param_tab.push_back(param);
log << log3 << "FP: Param: name=" << param.name;
if( !param.value.empty() )
log << ", value=" << param.value;
log << logend;
}
void FunctionParser::ParseAnchor()
{
if( *path == 0 )
return;
if( *path != '#' )
{
cur->request->status = WINIX_ERR_INCORRECT_URI;
return;
}
path += 1;
name_ascii.clear();
while( *path )
name_ascii += GetChar();
PT::UTF8ToWide(name_ascii, cur->request->anchor);
if( !cur->request->anchor.empty() )
log << log3 << "FP: anchor: " << cur->request->anchor << logend;
}
void FunctionParser::SkipSlashes()
{
while( *path == '/' )
path += 1;
}
int FunctionParser::FromHex(int c)
{
if( c>='0' && c<='9' )
return c - '0';
else
if( c>='a' && c<='f' )
return c - 'a' + 10;
else
if( c>='A' && c<='F' )
return c - 'A' + 10;
else
cur->request->status = WINIX_ERR_INCORRECT_URI;
return 0;
}
int FunctionParser::GetChar()
{
int c;
if( *path == 0 )
return 0;
if( *path == '%' && *(path+1)!=0 && *(path+2)!=0 )
{
c = (FromHex(*(path+1)) << 4) + FromHex(*(path+2));
if( c == 0 )
cur->request->status = WINIX_ERR_INCORRECT_URI;
path += 3;
}
else
if( *path == '+' )
{
c = ' ';
path += 1;
}
else
{
c = *path;
path += 1;
}
return c;
}
void FunctionParser::ReadName()
{
SkipSlashes();
name_ascii.clear();
while( *path && *path!='/' && *path!='?' && *path!='#' )
name_ascii += GetChar();
PT::UTF8ToWide(name_ascii, name);
}
void FunctionParser::ReadOrdinaryParName()
{
name_ascii.clear();
while( *path && *path!='=' && *path!='&' && *path!='#' )
name_ascii += GetChar();
PT::UTF8ToWide(name_ascii, name);
}
void FunctionParser::ReadOrdinaryParValue()
{
value_ascii.clear();
if( *path=='=' )
path += 1;
while( *path && *path!='&' && *path!='#' )
value_ascii += GetChar();
PT::UTF8ToWide(value_ascii, value);
}
void FunctionParser::ReadWinixParName()
{
name_ascii.clear();
while( *path && *path!='/' && *path!=':' && *path!='#' )
name_ascii += GetChar();
PT::UTF8ToWide(name_ascii, name);
}
void FunctionParser::ReadWinixParValue()
{
value_ascii.clear();
if( *path == ':' )
path += 1;
while( *path && *path!='/' && *path!='#' )
value_ascii += GetChar();
PT::UTF8ToWide(value_ascii, value);
}
} // namespace Winix

View File

@@ -0,0 +1,101 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2008-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_winix_functions_functionparser
#define headerfile_winix_functions_functionparser
#include <string>
#include "db/db.h"
#include "core/cur.h"
#include "core/system.h"
namespace Winix
{
class Functions;
class FunctionParser
{
public:
FunctionParser();
bool Parse(Cur * pcur, Db * pdb, Functions * pfunctions, System * psystem);
private:
Db * db;
Cur * cur;
System * system;
Functions * functions;
const wchar_t * path;
std::wstring name, value;
std::string name_ascii, value_ascii;
Item * last_dir;
Param param;
void SkipSlashes();
void ParseDirsItemFunction();
void ParseParams();
void ParseAnchor();
bool IsDir();
bool CheckAddItem();
bool CheckAddFunction();
bool AddRootDir();
void AddDir();
void AddParam();
void ParseOrdinaryParams();
void ParseWinixParams();
int FromHex(int c);
int GetChar();
void ReadName();
void ReadOrdinaryParName();
void ReadOrdinaryParValue();
void ReadWinixParName();
void ReadWinixParValue();
};
} // namespace Winix
#endif

View File

@@ -0,0 +1,641 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2010-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "functions.h"
#include "core/log.h"
#include "core/misc.h"
#include "core/plugin.h"
#include "templates/templates.h"
namespace Winix
{
void Functions::SetConfig(Config * pconfig)
{
config = pconfig;
}
void Functions::SetCur(Cur * pcur)
{
cur = pcur;
}
void Functions::SetDb(Db * pdb)
{
db = pdb;
}
void Functions::SetSystem(System * psystem)
{
system = psystem;
}
void Functions::SetTemplates(Templates * ptemplates)
{
templates = ptemplates;
}
void Functions::SetSynchro(Synchro * psynchro)
{
synchro = psynchro;
}
void Functions::SetSessionManager(SessionManager * pmanager)
{
session_manager = pmanager;
}
size_t Functions::FunctionsSize()
{
return table.size();
}
Functions::Iterator Functions::Begin()
{
return table.begin();
}
Functions::Iterator Functions::End()
{
return table.end();
}
FunctionBase * Functions::Find(const std::wstring & function_name)
{
Table::iterator i = table.find(function_name);
if( i == table.end() )
return 0;
return i->second;
}
void Functions::PrepareUrl(Item & item)
{
TrimWhite(item.url);
if( item.url.empty() )
item.url = item.subject; // if the subject is empty then the url will be corrected by CorrectUrlOnlyAllowedChar()
CorrectUrlOnlyAllowedChar(item.url);
if( Find(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(), '_');
}
}
Error Functions::CheckSpecialFile(const Item & item)
{
static std::wstring fstab = L"fstab";
Item * etc = system->dirs.GetEtcDir();
if( !etc )
return WINIX_NOTHING_TO_DO;
if( item.parent_id != etc->id )
return WINIX_NOTHING_TO_DO;
if( item.url == fstab )
{
log << log3 << "Functions: reloading mount points" << logend;
system->mounts.ReadMounts(item.content);
templates->ReadNewIndexTemplates();
templates->ReadNewChangeTemplates();
return WINIX_ERR_OK;
}
return WINIX_NOTHING_TO_DO;
}
void Functions::SetObjects(FunctionBase * fun)
{
fun->SetConfig(config);
fun->SetCur(cur);
fun->SetDb(db);
fun->SetSystem(system);
fun->SetFunctions(this);
fun->SetTemplates(templates);
fun->SetSynchro(synchro);
fun->SetSessionManager(session_manager);
}
void Functions::Add(FunctionBase * fun)
{
if( fun->fun.url.empty() )
{
log << log1 << "Functions: skipping a function with an empty url" << logend;
return;
}
if( Find(fun->fun.url) )
{
log << log1 << "Functions: function " << fun->fun.url << " already exists (skipped)" << logend;
return;
}
SetObjects(fun);
table[fun->fun.url] = fun;
}
void Functions::Add(FunctionBase & fun)
{
Add(&fun);
}
void Functions::CreateFunctions()
{
Add(fun_account);
Add(fun_adduser);
Add(fun_cat);
Add(fun_chmod);
Add(fun_chown);
Add(fun_ckeditor);
Add(fun_cp);
Add(fun_default);
Add(fun_download);
Add(fun_emacs);
Add(fun_env);
Add(fun_imgcrop);
Add(fun_last);
Add(fun_locale);
Add(fun_login);
Add(fun_logout);
Add(fun_ln);
Add(fun_ls);
Add(fun_ipban);
Add(fun_man);
Add(fun_meta);
Add(fun_mkdir);
Add(fun_mount);
Add(fun_mv);
Add(fun_nicedit);
Add(fun_node);
Add(fun_passwd);
Add(fun_priv);
Add(fun_pw);
Add(fun_reload);
Add(fun_rm);
Add(fun_rmuser);
Add(fun_run);
Add(fun_sort);
Add(fun_special_default);
Add(fun_stat);
Add(fun_subject);
Add(fun_template);
Add(fun_time_zone);
Add(fun_tinymce);
Add(fun_uname);
Add(fun_upload);
Add(fun_uptime);
Add(fun_who);
Add(fun_vim);
plugin.Call((Session*)0, WINIX_CREATE_FUNCTIONS);
}
void Functions::InitFunctions()
{
Table::iterator i = table.begin();
for( ; i!=table.end() ; ++i)
i->second->Init();
}
void Functions::Init()
{
CreateFunctions();
InitFunctions();
}
void Functions::Parse()
{
function_parser.Parse(cur, db, this, system);
}
void Functions::SetDefaultFunctionForFile()
{
if( cur->request->item.file_type != WINIX_ITEM_FILETYPE_NONE )
cur->request->function = &fun_download;
else
if( system->HasReadExecAccess(cur->request->item) )
cur->request->function = &fun_run;
else
cur->request->function = &fun_cat;
log << log3 << "Functions: default function: " << cur->request->function->fun.url << logend;
}
void Functions::SetDefaultFunctionForDir()
{
// !! nie potrzebne
// if( system->mounts.pmount->type == system->mounts.MountTypeThread() )
// cur->request->function = &fun_thread;
// else
cur->request->function = &fun_ls;
log << log3 << "Functions: default function: " << cur->request->function->fun.url << logend;
}
void Functions::SetDefaultFunction()
{
cur->request->function = 0;
plugin.Call(WINIX_SELECT_DEFAULT_FUNCTION);
if( cur->request->function )
{
log << log3 << "Functions: default function: " << cur->request->function->fun.url
<< " (set by a plugin)" << logend;
return;
}
if( cur->request->is_item )
SetDefaultFunctionForFile();
else
SetDefaultFunctionForDir();
}
void Functions::CheckFunctionFollowDir(bool was_default_function)
{
// directory with 'default' flag
if( was_default_function )
{
if( cur->request->dir_tab.back()->link_redirect == 1 )
{
system->RedirectTo(cur->request->dir_tab.back()->link_to);
}
else
{
if( system->FollowAllLinks(cur->request->dir_tab.back()->link_to, true, true) )
SetDefaultFunction();
}
}
}
void Functions::CheckFunctionFollowSymlink(bool was_default_function)
{
if( cur->request->item.link_redirect == 1 )
{
if( was_default_function )
system->RedirectTo(cur->request->item.link_to);
else
system->RedirectWithFunctionAndParamsTo(cur->request->item.link_to);
}
else
if( system->FollowAllLinks(cur->request->item.link_to, true, true) )
{
if( was_default_function )
SetDefaultFunction();
if( cur->request->status == WINIX_ERR_OK && !cur->request->redirect_to.empty() && !was_default_function && cur->request->function )
{
// !! nie jestem pewny dodania tej nowej funkcji do redirecta... (sprawdzic to)
cur->request->redirect_to += '/';
cur->request->redirect_to += cur->request->function->fun.url;
system->AddParams(cur->request->param_tab, cur->request->redirect_to, false);
}
}
}
// making a proper redirection from a directory with 'default' flag
// or from a symlink (or just loading it if there is no redirection flag set)
void Functions::CheckFunctionAndSymlink()
{
bool was_default_function = false;
if( !cur->request->function || cur->request->function == &fun_special_default )
{
was_default_function = true;
SetDefaultFunction();
}
if( cur->request->status != WINIX_ERR_OK || !cur->request->redirect_to.empty() )
return;
if( !cur->request->is_item && !cur->request->dir_tab.back()->link_to.empty() )
CheckFunctionFollowDir(was_default_function);
else
if( cur->request->is_item && cur->request->item.type == Item::symlink && cur->request->function && cur->request->function->follow_symlinks )
CheckFunctionFollowSymlink(was_default_function);
}
void Functions::MakeFunction()
{
if( !cur->request->function )
{
cur->request->status = WINIX_ERR_NO_FUNCTION;
log << log1 << "Functions: no function (neither cat nor ls)" << logend;
return;
}
if( !system->DirsHaveReadExecPerm() ||
!system->HasReadExecAccess(cur->request->function->fun) ||
!cur->request->function->HasAccess() )
{
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
return;
}
if( cur->request->method == Request::get )
{
if( cur->request->redirect_to.empty() )
cur->request->function->MakeGet();
}
else
if( cur->request->method == Request::post )
{
// we don't use post with redirecting (the post variables would be lost)
if( cur->request->redirect_to.empty() )
cur->request->function->MakePost();
else
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
}
else
if( cur->request->method == Request::head )
{
// do nothing
}
else
log << log1 << "Functions: unknown request method (skipping)" << logend;
}
void Functions::CheckGetPostTimes(time_t difference)
{
time_t now = std::time(0);
if( cur->session->puser )
return;
if( cur->request->method != Request::post )
return;
if( now - cur->session->last_time_get >= (time_t)difference )
return;
if( cur->request->AllPostVarEmpty() )
return;
cur->session->spam_score += 1;
log << log1 << "Functions: spam +1: POST after GET sent too fast" << logend;
}
// !!uwaga zwracana warto<74><6F> zmieniona (true/false)
bool Functions::CheckAbuse()
{
if( !system->rebus.CheckRebus() )
{
cur->request->status = WINIX_ERR_INCORRECT_REBUS;
return true;
}
CheckGetPostTimes();
if( cur->session->spam_score > 0 )
{
cur->request->status = WINIX_ERR_SPAM;
log << log1 << "Functions: ignoring due to suspected spamming" << logend;
return true;
}
return false;
}
// returning true if the 'url' has to be changed
void Functions::ReadItemUrlSubject(Item & item, Item::Type item_type)
{
std::wstring * new_subject = cur->request->PostVarp(L"subject");
std::wstring * new_url = cur->request->PostVarp(L"url");
if( new_subject )
item.subject = *new_subject;
/*
if( item.subject.empty() )
{
item.subject = cur->request->dir_tab.back()->subject;
item.subject += L"_msg_";
Toa(db->Size(cur->request->dir_tab.back()->id, Item::file), item.subject, 10, false);
}
*/
if( new_url )
item.url = *new_url;
// if item.url is empty then it will be set from item.subject
PrepareUrl(item);
}
void Functions::ReadItemFilterHtml(Item & item)
{
html_filter.BreakWord(0);
html_filter.WrapLine(0);
html_filter.TrimWhite(false);
html_filter.InsertTabs(0);
html_filter.SafeMode(true);
html_filter.ClearOrphans();
// SetNoFilterTag doesn't have to be called (default empty tag)
html_filter.Filter(cur->request->PostVar(L"itemcontent"), item.content);
}
void Functions::ReadItemContent(Item & item, const std::wstring & content_type)
{
bool is_root = cur->session->puser && cur->session->puser->super_user;
bool filter_html = (content_type == L"2") && config->editors_html_safe_mode;
if( filter_html && is_root && config->editors_html_safe_mode_skip_root )
filter_html = false;
if( filter_html )
ReadItemFilterHtml(item);
else
cur->request->PostVar(L"itemcontent", item.content);
}
void Functions::ReadItemContentWithType(Item & item)
{
item.content_type = Item::ct_formatted_text; // default is formatted text
cur->request->PostVar(L"contenttype", temp);
ReadItemContent(item, temp);
// ct_text and ct_formatted_text can use everyone
if( temp == L"0" )
item.content_type = Item::ct_text;
else
if( temp == L"1" )
item.content_type = Item::ct_formatted_text;
// those below need special privileges
if( !cur->session->puser )
return;
long user_id = cur->session->puser->id;
if( temp == L"2" )
{
if( system->CanUseHtml(user_id) )
item.content_type = Item::ct_html;
}
else
if( temp == L"3" )
{
if( system->CanUseBBCode(user_id) )
item.content_type = Item::ct_bbcode;
}
else
if( temp == L"4" )
{
if( system->CanUseRaw(user_id) )
item.content_type = Item::ct_raw;
}
}
// item_type - the type of an item you are expecting to read
// returns true if the url has to be changed
// at the moment this is only checked for Item::file - for Item::dir it returns always true
// !! zmienic nazwe na ReadUrlSubjectContent
void Functions::ReadItem(Item & item, Item::Type item_type)
{
if( item_type == Item::none )
return;
item.type = item_type;
item.parent_id = cur->request->dir_tab.back()->id; // !! moze to dac jako parametr?
ReadItemUrlSubject(item, item_type);
if( item_type == Item::file )
ReadItemContentWithType(item);
}
void Functions::SetUser(Item & item)
{
if( cur->session && cur->session->puser )
{
item.user_id = cur->session->puser->id;
item.guest_name.clear();
}
else
{
item.user_id = -1;
cur->request->PostVar(L"guestname", item.guest_name);
}
item.group_id = cur->request->dir_tab.back()->group_id;
}
} // namespace Winix

View File

@@ -0,0 +1,229 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2010-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_winix_functions_functions
#define headerfile_winix_functions_functions
#include <string>
#include "functionbase.h"
#include "functionparser.h"
#include "account.h"
#include "adduser.h"
#include "cat.h"
#include "chmod.h"
#include "chown.h"
#include "ckeditor.h"
#include "cp.h"
#include "default.h"
#include "download.h"
#include "emacs.h"
#include "env.h"
#include "imgcrop.h"
#include "last.h"
#include "locale.h"
#include "login.h"
#include "logout.h"
#include "ln.h"
#include "ls.h"
#include "ipban.h"
#include "man.h"
#include "meta.h"
#include "mkdir.h"
#include "mount.h"
#include "mv.h"
#include "nicedit.h"
#include "node.h"
#include "passwd.h"
#include "priv.h"
#include "pw.h"
#include "reload.h"
#include "rm.h"
#include "rmuser.h"
#include "run.h"
#include "sort.h"
#include "specialdefault.h"
#include "stat.h"
#include "subject.h"
#include "template.h"
#include "timezone.h"
#include "tinymce.h"
#include "uname.h"
#include "upload.h"
#include "uptime.h"
#include "who.h"
#include "vim.h"
#include "core/htmlfilter.h"
namespace Winix
{
class Templates;
class Functions
{
public:
Fun::Account fun_account;
Fun::AddUser fun_adduser;
Fun::Cat fun_cat;
Fun::Chmod fun_chmod;
Fun::Chown fun_chown;
Fun::Ckeditor fun_ckeditor;
Fun::Cp fun_cp;
Fun::Default fun_default;
Fun::Download fun_download;
Fun::Emacs fun_emacs;
Fun::Env fun_env;
Fun::ImgCrop fun_imgcrop;
Fun::Last fun_last;
Fun::Locale fun_locale;
Fun::Login fun_login;
Fun::Logout fun_logout;
Fun::Ln fun_ln;
Fun::Ls fun_ls;
Fun::IPBanFun fun_ipban;
Fun::Man fun_man;
Fun::Meta fun_meta;
Fun::Mkdir fun_mkdir;
Fun::Mount fun_mount;
Fun::Mv fun_mv;
Fun::Nicedit fun_nicedit;
Fun::Node fun_node;
Fun::Passwd fun_passwd;
Fun::Priv fun_priv;
Fun::Pw fun_pw;
Fun::Reload fun_reload;
Fun::Rm fun_rm;
Fun::RmUser fun_rmuser;
Fun::Run fun_run;
Fun::Sort fun_sort;
Fun::SpecialDefault fun_special_default;
Fun::Stat fun_stat;
Fun::Subject fun_subject;
Fun::Template fun_template;
Fun::TimeZone fun_time_zone;
Fun::Tinymce fun_tinymce;
Fun::Uname fun_uname;
Fun::Upload fun_upload;
Fun::Uptime fun_uptime;
Fun::Who fun_who;
Fun::Vim fun_vim;
typedef std::map<std::wstring, FunctionBase*> Table;
typedef Table::iterator Iterator;
void Init();
void Parse();
size_t FunctionsSize();
Iterator Begin();
Iterator End();
void CheckFunctionAndSymlink();
void MakeFunction();
void SetConfig(Config * pconfig);
void SetCur(Cur * pcur);
void SetDb(Db * pdb);
void SetSystem(System * psystem);
void SetTemplates(Templates * ptemplates);
void SetSynchro(Synchro * psynchro);
void SetSessionManager(SessionManager * pmanager);
FunctionBase * Find(const std::wstring & function_name);
Error CheckSpecialFile(const Item & item);
void PrepareUrl(Item & item);
void SetDefaultFunction();
void CheckGetPostTimes(time_t difference = 10);
bool CheckAbuse();
// !! dac lepsze nazwy
void ReadItemFilterHtml(Item & item);
void ReadItemContent(Item & item, const std::wstring & content_type);
void ReadItemContentWithType(Item & item);
// if item.url is not empty and there is not a post variable "url"
// then the item.url will not be changed
// (the same is for item.subject and "subject" post variable)
void ReadItem(Item & item, Item::Type item_type);
void SetUser(Item & item);
void Add(FunctionBase * fun);
void Add(FunctionBase & fun);
private:
Config * config;
Cur * cur;
Db * db;
System * system;
Synchro * synchro;
Templates * templates;
SessionManager * session_manager;
std::wstring temp;
HTMLFilter html_filter;
std::wstring link_to_temp;
void CreateFunctions();
void InitFunctions();
void SetObjects(FunctionBase * fun);
void SetDefaultFunctionForFile();
void SetDefaultFunctionForDir();
void ReadItemUrlSubject(Item & item, Item::Type item_type);
Table table;
FunctionParser function_parser;
void CheckFunctionFollowDir(bool was_default_function);
void CheckFunctionFollowSymlink(bool was_default_function);
};
} // namespace Winix
#endif

View File

@@ -0,0 +1,138 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2013-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "imgcrop.h"
#include "functions.h"
namespace Winix
{
namespace Fun
{
ImgCrop::ImgCrop()
{
fun.url = L"imgcrop";
}
bool ImgCrop::HasAccess()
{
if( cur->request->is_item )
return system->HasWriteAccess(cur->request->item);
return true;
}
void ImgCrop::GetDirContent()
{
iq.sel_type = Item::file;
iq.sel_content = false;
iq.WhereParentId(cur->request->dir_tab.back()->id);
iq.WhereFileType(WINIX_ITEM_FILETYPE_IMAGE);
db->GetItems(cur->request->item_tab, iq);
system->CheckWriteAccessToItems(cur->request->item_tab);
}
void ImgCrop::MakePost()
{
int xoffset = int(Tod(cur->request->PostVar(L"cropxtop")) + 0.5);
int yoffset = int(Tod(cur->request->PostVar(L"cropytop")) + 0.5);
int width = int(Tod(cur->request->PostVar(L"cropwidth")) + 0.5);
int height = int(Tod(cur->request->PostVar(L"cropheight")) + 0.5);
SetMinMax(xoffset, 0, 30000);
SetMinMax(yoffset, 0, 30000);
SetMinMax(width, 1, 30000);
SetMinMax(height, 1, 30000);
Item & item = cur->request->item;
if( cur->request->is_item && item.type == Item::file && item.file_type == WINIX_ITEM_FILETYPE_IMAGE )
{
if( system->HasWriteAccess(item) )
{
// !! IMPROVE ME add info about modification (Item::modify_time)
if( cur->request->IsParam(L"thumb") )
{
Image::Scale scale = system->image.GetThumbScale(item.parent_id);
system->image.CropThumb(item.id, xoffset, yoffset, width, height, scale.quality);
}
else
if( cur->request->IsParam(L"newthumb") )
{
Image::Scale scale = system->image.GetThumbScale(item.parent_id);
system->image.CropNewThumb(item.id, xoffset, yoffset, width, height, scale.cx, scale.cy,
scale.aspect_mode, scale.quality);
}
else
{
Image::Scale scale = system->image.GetImageScale(item.parent_id);
system->image.Crop(item.id, xoffset, yoffset, width, height, scale.quality);
}
// !! IMPROVE ME redirect me somewhere else
system->RedirectToLastItem();
}
else
{
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
}
}
}
void ImgCrop::MakeGet()
{
if( !cur->request->is_item )
GetDirContent();
}
} // namespace
} // namespace Winix

View File

@@ -0,0 +1,71 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2013-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_winix_functions_imgcrop
#define headerfile_winix_functions_imgcrop
#include "functionbase.h"
namespace Winix
{
namespace Fun
{
class ImgCrop : public FunctionBase
{
public:
ImgCrop();
bool HasAccess();
void MakeGet();
void MakePost();
private:
DbItemQuery iq;
void GetDirContent();
};
} // namespace
} // namespace Winix
#endif

110
winixd/functions/ipban.cpp Normal file
View File

@@ -0,0 +1,110 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2012-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "ipban.h"
#include "functions.h"
#include "core/sessionmanager.h"
namespace Winix
{
namespace Fun
{
IPBanFun::IPBanFun()
{
fun.url = L"ipban";
}
bool IPBanFun::HasAccess()
{
return cur->session->puser && cur->session->puser->super_user;
}
void IPBanFun::MakePost()
{
}
void IPBanFun::MakeGet()
{
char tmp_ip_str[100];
size_t tmp_ip_len = sizeof(tmp_ip_str) / sizeof(char);
if( cur->request->IsParam(L"removeip") )
{
if( cur->request->ParamValue(L"removeip") == L"all" )
{
session_manager->ClearIPBanList();
cur->session->ip_ban = 0;
}
else
{
int cur_ip = 0;
if( cur->session->ip_ban )
cur_ip = cur->session->ip_ban->ip;
if( WideToUTF8(cur->request->ParamValue(L"removeip"), tmp_ip_str, tmp_ip_len) )
{
int ip = (int)inet_addr(tmp_ip_str);
session_manager->RemoveIPBan(ip);
if( cur->session->ip_ban && cur_ip == ip )
cur->session->ip_ban = 0;
}
}
system->RedirectToLastFunction();
}
}
} // namespace
} // namespace Winix

68
winixd/functions/ipban.h Normal file
View File

@@ -0,0 +1,68 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2012-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_winix_functions_ipban
#define headerfile_winix_functions_ipban
#include "functionbase.h"
namespace Winix
{
namespace Fun
{
// IPBanFun in order to not confused with IPBan from core winix
class IPBanFun : public FunctionBase
{
public:
IPBanFun();
bool HasAccess();
void MakePost();
void MakeGet();
private:
};
} // namespace
} // namespace Winix
#endif

62
winixd/functions/last.cpp Normal file
View File

@@ -0,0 +1,62 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2008-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "last.h"
namespace Winix
{
namespace Fun
{
Last::Last()
{
fun.url = L"last";
}
bool Last::HasAccess()
{
return cur->session->puser != 0;
}
} // namespace
} // namespace Winix

65
winixd/functions/last.h Normal file
View File

@@ -0,0 +1,65 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2010-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_winix_functions_last
#define headerfile_winix_functions_last
#include "functionbase.h"
namespace Winix
{
namespace Fun
{
class Last : public FunctionBase
{
public:
Last();
bool HasAccess();
private:
};
} // namespace
} // namespace Winix
#endif

175
winixd/functions/ln.cpp Normal file
View File

@@ -0,0 +1,175 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2010-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "ln.h"
#include "core/misc.h"
#include "functions/functions.h"
namespace Winix
{
namespace Fun
{
Ln::Ln()
{
fun.url = L"ln";
}
bool Ln::HasAccess()
{
return system->HasWriteAccess(*cur->request->dir_tab.back());
}
bool Ln::CreateSymbolicLink(long parent_id, const wchar_t * link_to, const wchar_t * url, bool link_redirect)
{
item.Clear(); // setting the date to now
item.type = Item::symlink;
item.parent_id = parent_id;
item.url = url;
item.link_to = link_to;
item.link_redirect = static_cast<int>(link_redirect);
item.privileges = system->NewFilePrivileges();
functions->SetUser(item);
functions->PrepareUrl(item);
return db->AddItem(item) == WINIX_ERR_OK;
}
bool Ln::CreateSymbolicLink(long parent_id, const std::wstring & link_to, const std::wstring & url, bool link_redirect)
{
return CreateSymbolicLink(parent_id, link_to.c_str(), url.c_str(), link_redirect);
}
void Ln::CreateSymbolicLink(const std::wstring & link_to)
{
long parent_id = cur->request->dir_tab.back()->id;
const std::wstring & url = cur->request->PostVar(L"url");
bool link_redirect = cur->request->IsPostVar(L"makeredirect") ? 1 : 0;
if( CreateSymbolicLink(parent_id, link_to, url, link_redirect) )
log << log3 << "Ln: created a symbolic link to: " << link_to << logend;
else
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
}
/*
!! IMPROVE ME
we need a better public interface
instead of std::vector<Item*> may std::wstring for path?
dirs - directory from we start looking for a destination file
link_to - destination file (name or path - relative or not)
url - suggested url name of the link
*/
bool Ln::CreateHardLink(const std::vector<Item*> & dirs, const std::wstring & link_to, const std::wstring & url)
{
if( dirs.empty() )
return false;
int res = system->FollowAllLinks(dirs, link_to, dir_tab, item, false, false);
if( res == 0 )
{
log << log2 << "Ln: " << link_to << " is a directory (can't create a hard link)" << logend;
return false;
}
else
if( res == 1 )
{
item.type = Item::file;
item.parent_id = dirs.back()->id;
item.url = url;
functions->PrepareUrl(item);
return db->AddHardLink(item) == WINIX_ERR_OK;
}
return false;
}
void Ln::CreateHardLink(const std::wstring & link_to)
{
const std::vector<Item*> & dirs = cur->request->dir_tab;
const std::wstring & url = cur->request->PostVar(L"url");
if( CreateHardLink(dirs, link_to, url) )
log << log3 << "Ln: created a hard link to: " << link_to << logend;
else
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
}
// we do not use notifications for links
void Ln::MakePost()
{
link_to = cur->request->PostVar(L"linkto");
TrimWhite(link_to);
if( link_to.empty() )
return;
int type = Toi(cur->request->PostVar(L"linktype"));
if( type == 0 )
CreateHardLink(link_to);
else
CreateSymbolicLink(link_to);
if( cur->request->status == WINIX_ERR_OK )
system->RedirectTo(item);
}
} // namespace
} // namespace Winix

77
winixd/functions/ln.h Normal file
View File

@@ -0,0 +1,77 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2010-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_winix_functions_ln
#define headerfile_winix_functions_ln
#include "functionbase.h"
namespace Winix
{
namespace Fun
{
class Ln : public FunctionBase
{
public:
Ln();
bool HasAccess();
void MakePost();
bool CreateSymbolicLink(long parent_id, const wchar_t * link_to, const wchar_t * url, bool link_redirect = true);
bool CreateSymbolicLink(long parent_id, const std::wstring & link_to, const std::wstring & url, bool link_redirect = true);
bool CreateHardLink(const std::vector<Item*> & dirs, const std::wstring & link_to, const std::wstring & url);
private:
Item item;
std::wstring link_to;
std::vector<Item*> dir_tab;
void CreateSymbolicLink(const std::wstring & link_to);
void CreateHardLink(const std::wstring & link_to);
};
} // namespace
} // namespace Winix
#endif

View File

@@ -0,0 +1,91 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2012-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "locale.h"
#include "templates/templates.h"
namespace Winix
{
namespace Fun
{
Locale::Locale()
{
fun.url = L"locale";
}
bool Locale::HasAccess()
{
return cur->session->puser != 0;
}
void Locale::MakePost()
{
if( cur->session->puser )
{
size_t locale_id = size_t(Toi(cur->request->PostVar(L"localeid")));
if( TemplatesFunctions::locale.HasLanguage(locale_id) )
{
cur->session->puser->locale_id = locale_id;
db->ChangeUserLocale(cur->session->puser->id, locale_id);
TemplatesFunctions::locale.SetCurLang(locale_id);
}
else
{
log << log1 << "Locale: incorrect locale id: " << locale_id << logend;
}
}
}
void Locale::MakeGet()
{
}
} // namespace
} // namespace Winix

67
winixd/functions/locale.h Normal file
View File

@@ -0,0 +1,67 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2012-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_winix_functions_locale
#define headerfile_winix_functions_locale
#include "functionbase.h"
namespace Winix
{
namespace Fun
{
class Locale : public FunctionBase
{
public:
Locale();
bool HasAccess();
void MakePost();
void MakeGet();
private:
};
} // namespace
} // namespace Winix
#endif

317
winixd/functions/login.cpp Normal file
View File

@@ -0,0 +1,317 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2008-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "core/sessionmanager.h"
#include "login.h"
#include "utf8/utf8.h"
namespace Winix
{
namespace Fun
{
Login::Login()
{
fun.url = L"login";
need_ssl = true;
}
void Login::ClearTmpStruct()
{
system->crypt.ClearString(pass_decrypted);
system->crypt.ClearString(pass_hashed);
system->crypt.ClearString(up.pass);
system->crypt.ClearString(up.pass_encrypted);
system->crypt.ClearString(up2.pass);
system->crypt.ClearString(up2.pass_encrypted);
}
bool Login::CheckPasswords(const std::wstring & password)
{
if( !up.pass_encrypted.empty() )
{
if( system->crypt.RSA(false, config->pass_rsa_private_key, up.pass_encrypted, pass_decrypted) )
{
PT::UTF8ToWide(pass_decrypted, up.pass);
}
else
{
log << log1 << "Login: I cannot decrypt a stored password, login failure" << logend;
return false;
}
}
pass_hashed = password;
up2.pass_type = up.pass_type;
up2.pass = password;
if( up.pass_hash_salted )
salt = config->pass_hash_salt;
else
salt.clear();
if( !system->crypt.PassHash(salt, up2) )
{
log << log1 << "Login: I cannot hash a password, login failure" << logend;
return false;
}
bool result = (up.pass == up2.pass);
if( !result )
log << log2 << "Login: incorrect login/password" << logend;
return result;
}
/*
this method is checking whether there is a person with that login and password
in the database
return true if it has found one and sets it user_id
*/
bool Login::CheckUserPass(const std::wstring & login, const std::wstring & password, long & user_id)
{
bool result;
if( db->GetUserPass(login, user_id, up) )
{
if( up.has_pass )
{
result = CheckPasswords(password);
}
else
{
log << log2 << "Login: this account has not a password set yet" << logend;
result = false;
}
}
else
{
log << log2 << "Login: there is no a user name: " << login << logend;
result = false;
}
ClearTmpStruct();
return result;
}
void Login::CheckBan()
{
IPBan * ip_ban = cur->session->ip_ban;
if( !ip_ban )
{
ip_ban = &session_manager->AddIPToBanList(cur->request->ip, cur->request->start_time);
cur->session->ip_ban = ip_ban;
}
if( ip_ban->incorrect_login_events < config->incorrect_login_cannot_login_treshold )
{
ip_ban->incorrect_login_events += 1;
}
else
{
log << log2 << "Login: too many incorrect login attempts from this IP" << logend;
if( config->incorrect_login_cannot_login_mode == 0 )
{
time_t expires = cur->request->start_time + (time_t)config->incorrect_login_cannot_login_delay;
if( ip_ban->expires < expires )
ip_ban->expires = expires;
PT::Date date(ip_ban->expires);
log << log2 << "Login: logging from this IP address has been blocked until to: " << date << " UTC" << logend;
}
else
{
session_manager->IncrementBanLevel(ip_ban);
}
}
}
bool Login::ShouldUseCaptchaForCurrentIP()
{
if( cur->session->ip_ban )
return ShouldUseCaptchaFor(*cur->session->ip_ban);
return false;
}
bool Login::ShouldUseCaptchaFor(const IPBan & ipban)
{
if( ipban.expires != 0 && cur->request->start_time >= ipban.expires )
return false; // the 'ip block' has expired (but incorrect_login_events has the old value)
return ipban.incorrect_login_events >= config->incorrect_login_captcha_treshold;
}
bool Login::CannotLoginFromCurrentIP()
{
if( cur->session->ip_ban )
return CannotLoginFrom(*cur->session->ip_ban);
return false;
}
bool Login::CannotLoginFrom(const IPBan & ipban)
{
if( ipban.IsIPBanned() )
return true;
/*
* if incorrect_login_cannot_login_mode is equal to one then we only
* block logging (there is no a ban actually -- neither the active flag is enabled
* nor any ban_level is set)
*/
if( ipban.expires != 0 &&
cur->request->start_time < ipban.expires &&
ipban.incorrect_login_events >= config->incorrect_login_cannot_login_treshold )
return true;
return false;
}
bool Login::CheckAbuse()
{
time_t diff = (time_t)config->incorrect_login_min_time_between_get_post;
if( cur->session->last_time_get + diff > cur->request->start_time )
{
log << log2 << "Login: the minimum time between GET and POST have not passed" << logend;
return false;
}
if( ShouldUseCaptchaForCurrentIP() )
{
if( !system->rebus.CheckRebus() )
{
return false;
}
}
return true;
}
// if you are logging not from a webbrowser but from an application
// then probably you need check_abuse to be false
bool Login::LoginUser(const std::wstring & login, const std::wstring & password, bool remember_me,
bool use_ses_log, bool check_abuse)
{
long user_id;
if( cur->session->id == 0 )
{
log << log2 << "Login: can't login in a temporary session (skipped)" << logend;
return false;
}
if( CannotLoginFromCurrentIP() )
{
log << log2 << "Login: you cannot login from this IP address" << logend;
return false;
}
if( login.empty() )
{
log << log3 << "Login: login is empty (skipping)" << logend;
return false;
}
if( check_abuse && !CheckAbuse() )
{
CheckBan();
return false;
}
if( CheckUserPass(login, password, user_id) )
{
if( system->users.LoginUser(user_id, remember_me, use_ses_log) )
{
if( cur->session->ip_ban )
cur->session->ip_ban->incorrect_login_events = 0;
return true;
}
}
else
{
CheckBan();
}
return false;
}
void Login::MakePost()
{
const std::wstring & login = cur->request->PostVar(L"login");
const std::wstring & pass = cur->request->PostVar(L"password");
const std::wstring & remem = cur->request->PostVar(L"rememberme");
if( LoginUser(login, pass, !remem.empty(), true, true) )
system->RedirectToLastItem();
}
void Login::MakeGet()
{
}
} // namespace
} // namespace Winix

88
winixd/functions/login.h Normal file
View File

@@ -0,0 +1,88 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2010-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_winix_functions_login
#define headerfile_winix_functions_login
#include "functionbase.h"
#include "core/user.h"
namespace Winix
{
namespace Fun
{
class Login : public FunctionBase
{
public:
Login();
void MakePost();
void MakeGet();
bool ShouldUseCaptchaForCurrentIP();
bool ShouldUseCaptchaFor(const IPBan & ipban);
bool CannotLoginFromCurrentIP();
bool CannotLoginFrom(const IPBan & ipban);
bool CheckUserPass(const std::wstring & login, const std::wstring & password, long & user_id);
bool LoginUser(const std::wstring & login, const std::wstring & password, bool remember_me,
bool use_ses_log = false, bool check_abuse = false);
private:
void ClearTmpStruct();
bool CheckPasswords(const std::wstring & password);
void CheckBan();
bool CheckAbuse();
UserPass up, up2;
std::string pass_decrypted;
std::wstring pass_hashed;
std::wstring salt;
};
} // namespace
} // namespace Winix
#endif

View File

@@ -0,0 +1,68 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2008-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "logout.h"
namespace Winix
{
namespace Fun
{
Logout::Logout()
{
fun.url = L"logout";
}
void Logout::MakeGet()
{
if( cur->session->puser )
{
system->users.LogoutCurrentUser();
system->RedirectToLastItem();
}
}
} // namespace
} // namespace Winix

64
winixd/functions/logout.h Normal file
View File

@@ -0,0 +1,64 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2010-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_winix_functions_logout
#define headerfile_winix_functions_logout
#include "functionbase.h"
namespace Winix
{
namespace Fun
{
class Logout : public FunctionBase
{
public:
Logout();
void MakeGet();
private:
};
} // namespace
} // namespace Winix
#endif

85
winixd/functions/ls.cpp Normal file
View File

@@ -0,0 +1,85 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2008-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "ls.h"
namespace Winix
{
namespace Fun
{
Ls::Ls()
{
fun.url = L"ls";
}
void Ls::MakeGet()
{
if( !cur->request->is_item )
{
DbItemQuery iq;
iq.sel_content = false;
iq.WhereParentId(cur->request->dir_tab.back()->id);
iq.WhereType(Item::dir, false);
if( cur->request->IsParam(L"ckeditor_browse") )
{
iq.WhereFileType(WINIX_ITEM_FILETYPE_IMAGE);
db->GetItems(cur->request->item_tab, iq);
}
else
{
db->GetItems(cur->request->item_tab, iq);
}
}
}
} // namespace
} // namespace Winix

66
winixd/functions/ls.h Normal file
View File

@@ -0,0 +1,66 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2010-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_winix_functions_ls
#define headerfile_winix_functions_ls
#include "functionbase.h"
namespace Winix
{
namespace Fun
{
class Ls : public FunctionBase
{
public:
Ls();
void MakeGet();
private:
};
} // namespace
} // namespace Winix
#endif

59
winixd/functions/man.cpp Normal file
View File

@@ -0,0 +1,59 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2012-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "man.h"
#include "functions.h"
namespace Winix
{
namespace Fun
{
Man::Man()
{
fun.url = L"man";
}
} // namespace
} // namespace Winix

61
winixd/functions/man.h Normal file
View File

@@ -0,0 +1,61 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2012-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_winix_functions_man
#define headerfile_winix_functions_man
#include "functionbase.h"
namespace Winix
{
namespace Fun
{
class Man : public FunctionBase
{
public:
Man();
};
} // namespace
} // namespace Winix
#endif

178
winixd/functions/meta.cpp Normal file
View File

@@ -0,0 +1,178 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2011-2015, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "meta.h"
#include "core/log.h"
namespace Winix
{
namespace Fun
{
Meta::Meta()
{
fun.url = L"meta";
// !! CHECKME what about follow symlinks?
}
bool Meta::HasAccess()
{
if( cur->request->IsParam(L"a") )
return cur->session->puser && cur->session->puser->super_user;
else
return system->HasWriteAccess(*cur->request->last_item);
}
bool Meta::Parse(const std::wstring & meta_str)
{
space.Clear();
conf_parser.SetSpace(space);
conf_parser.SplitSingle(true);
return (conf_parser.ParseString(meta_str) == PT::SpaceParser::ok);
}
bool Meta::EditAdminMeta(long item_id, const std::wstring & meta_str, bool use_ses_log)
{
if( Parse(meta_str) )
{
if( db->EditAdminMetaById(space, item_id) == WINIX_ERR_OK )
{
return true;
}
else
{
log << log1 << "Meta: a database problem with changing admin meta information for item id: "
<< item_id << logend;
}
}
else
{
log << log2 << "Meta: Syntax error in line: " << conf_parser.line << logend;
if( use_ses_log )
slog << logerror << T("syntax_error_in_line") << ' ' << conf_parser.line << logend;
}
return false;
}
bool Meta::EditMeta(long item_id, const std::wstring & meta_str, bool use_ses_log)
{
if( Parse(meta_str) )
{
if( db->EditMetaById(space, item_id) == WINIX_ERR_OK )
{
return true;
}
else
{
log << log1 << "Meta: a database problem with changing meta information for item id: "
<< item_id << logend;
}
}
else
{
log << log2 << "Meta: Syntax error in line: " << conf_parser.line << logend;
if( use_ses_log )
slog << logerror << T("syntax_error_in_line") << ' ' << conf_parser.line << logend;
}
return false;
}
void Meta::ChangeAdminMeta()
{
if( cur->session->puser && cur->session->puser->super_user )
{
const std::wstring & meta_str = cur->request->PostVar(L"itemmeta");
if( EditAdminMeta(cur->request->last_item->id, meta_str, true) )
{
if( cur->request->last_item->type == Item::dir )
cur->request->last_item->ameta = space;
system->RedirectToLastItem();
}
}
}
void Meta::ChangeMeta()
{
if( system->HasWriteAccess(*cur->request->last_item) )
{
const std::wstring & meta_str = cur->request->PostVar(L"itemmeta");
if( EditMeta(cur->request->last_item->id, meta_str, true) )
{
if( cur->request->last_item->type == Item::dir )
cur->request->last_item->meta = space;
system->RedirectToLastItem();
}
}
}
void Meta::MakePost()
{
if( cur->request->IsParam(L"a") )
ChangeAdminMeta();
else
ChangeMeta();
}
} // namespace
} // namespace Winix

77
winixd/functions/meta.h Normal file
View File

@@ -0,0 +1,77 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2011-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_winix_functions_meta
#define headerfile_winix_functions_meta
#include "functionbase.h"
#include "space/spaceparser.h"
namespace Winix
{
namespace Fun
{
class Meta : public FunctionBase
{
public:
Meta();
bool HasAccess();
void MakePost();
bool EditAdminMeta(long item_id, const std::wstring & meta_str, bool use_ses_log = false);
bool EditMeta(long item_id, const std::wstring & meta_str, bool use_ses_log = false);
private:
PT::SpaceParser conf_parser;
PT::Space space;
bool Parse(const std::wstring & meta_str);
void ChangeAdminMeta();
void ChangeMeta();
};
} // namespace
} // namespace Winix
#endif

129
winixd/functions/mkdir.cpp Normal file
View File

@@ -0,0 +1,129 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2008-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "mkdir.h"
#include "functions.h"
#include "core/plugin.h"
namespace Winix
{
namespace Fun
{
Mkdir::Mkdir()
{
fun.url = L"mkdir";
}
bool Mkdir::HasAccess(const Item & item)
{
// you can create a directory only in a directory
if( item.type != Item::dir )
return false;
if( cur->session->puser && cur->session->puser->super_user )
// super user can use mkdir everywhere
return true;
if( !system->HasWriteAccess(item) )
return false;
if( !system->mounts.pmount->IsPar(system->mounts.MountParMkdirOn()) )
return true;
if( system->mounts.pmount->IsArg(system->mounts.MountParMkdirOn(), cur->request->dir_tab.size()) )
return true;
return false;
}
bool Mkdir::HasAccess()
{
if( cur->request->is_item || !HasAccess(*cur->request->dir_tab.back()) )
return false;
return true;
}
void Mkdir::PostFunMkdir(bool add_to_dir_tab, int privileges)
{
functions->ReadItem(cur->request->item, Item::dir);
functions->SetUser(cur->request->item);
cur->request->item.privileges = privileges;
Item * pdir;
cur->request->status = system->dirs.AddDirectory(cur->request->item, add_to_dir_tab, &pdir);
if( cur->request->status == WINIX_ERR_OK )
{
if( pdir )
plugin.Call(WINIX_DIR_ADDED, pdir);
system->RedirectTo(cur->request->item);
}
else
{
log << log1 << "Content: PostFunMkdir: Error: " << cur->request->status << logend;
}
}
void Mkdir::MakePost()
{
PostFunMkdir(false, system->NewDirPrivileges());
}
} // namespace
} // namespace Winix

68
winixd/functions/mkdir.h Normal file
View File

@@ -0,0 +1,68 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2010-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_winix_functions_mkdir
#define headerfile_winix_functions_mkdir
#include "functionbase.h"
namespace Winix
{
namespace Fun
{
class Mkdir : public FunctionBase
{
public:
Mkdir();
bool HasAccess();
void MakePost();
private:
bool HasAccess(const Item & item); // !! moze to powinien byc skladnik modelu?
bool FunMkdirCheckAccess();
void PostFunMkdir(bool add_to_dir_tab, int privileges);
};
} // namespace
} // namespace Winix
#endif

View File

@@ -0,0 +1,74 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2011-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "mount.h"
#include "functions.h"
namespace Winix
{
namespace Fun
{
Mount::Mount()
{
fun.url = L"mount";
}
bool Mount::HasAccess()
{
if( cur->session->puser && cur->session->puser->super_user )
return true;
return false;
}
void Mount::MakeGet()
{
}
} // namespace
} // namespace Winix

63
winixd/functions/mount.h Normal file
View File

@@ -0,0 +1,63 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2011-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_winix_functions_mount
#define headerfile_winix_functions_mount
#include "functionbase.h"
namespace Winix
{
namespace Fun
{
class Mount : public FunctionBase
{
public:
Mount();
bool HasAccess();
void MakeGet();
};
} // namespace
} // namespace Winix
#endif

718
winixd/functions/mv.cpp Normal file
View File

@@ -0,0 +1,718 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2008-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <errno.h>
#include "mv.h"
#include "functions.h"
#include "core/plugin.h"
namespace Winix
{
namespace Fun
{
Mv::Mv()
{
fun.url = L"mv";
follow_symlinks = false;
Prepare();
}
// !! CHECK ME
// check if everywhere correct messages are sent (prepare_to, modified item/dir)
bool Mv::HasAccess()
{
if( cur->request->is_item )
{
if( !system->CanRemoveRenameChild(*cur->request->dir_tab.back(), cur->request->item.user_id) )
return false;
}
else
{
bool only_content = (cur->request->IsParam(L"c") || cur->request->IsPostVar(L"c"));
if( !CheckAccessFromToDir(*cur->request->dir_tab.back(), only_content) )
return false;
}
return true;
}
bool Mv::CheckAccessFromToDir(const Item & dir, bool only_content)
{
if( dir.parent_id == -1 )
{
if( !only_content )
{
// the root directory cannot be moved anywhere
return false;
}
}
else
if( only_content )
{
// sticky bit for a specified child will be checked later
if( !system->HasWriteAccess(dir) )
return false;
}
else
{
Item * last_but_one_dir = system->dirs.GetDir(dir.parent_id);
if( !last_but_one_dir )
// ops, there is no a parent dir
return false;
if( !system->CanRemoveRenameChild(*last_but_one_dir, dir.user_id) )
return false;
}
return true;
}
// !! IMPROVE ME: may a better name?
void Mv::Prepare()
{
content_dir_iq.SetAll(false, false);
content_dir_iq.sel_parent_id = true;
content_dir_iq.sel_type = true;
content_dir_iq.sel_url = true;
content_dir_iq.sel_file = true;
content_dir_iq.sel_user_id = true;
content_dir_iq.sel_group_id = true;
content_dir_iq.sel_privileges = true;
content_dir_iq.sel_meta = true;
files_iq.SetAll(false, false);
files_iq.sel_parent_id = true;
files_iq.sel_type = true;
files_iq.sel_url = true;
files_iq.sel_file = true;
files_iq.sel_user_id = true;
files_iq.sel_group_id = true;
files_iq.sel_privileges = true;
files_iq.sel_meta = true;
files_iq.WhereType(Item::dir, false);
}
void Mv::Clear()
{
out_dir_tab.clear();
out_item.Clear();
out_filename.clear();
files_item_tab.clear();
item_tab.clear();
}
bool Mv::ParseDirCheckLastName()
{
if( out_has_file )
{
log << log1 << "Mv: incorrent path" << logend;
slog << logerror << T("mv_incorrect_path") << logend;
return false;
}
else
{
Item * dir = system->dirs.GetDir(out_filename, out_dir_tab.back()->id);
if( dir )
{
out_dir_tab.push_back(dir);
out_filename.clear();
}
else
{
if( db->GetItem(out_dir_tab.back()->id, out_filename, out_item) == WINIX_ERR_OK )
{
out_has_file = true;
out_filename.clear();
}
}
}
return true;
}
bool Mv::ParseDir(const std::wstring & dst_path, bool check_access)
{
if( dst_path.empty() )
return false;
// first we should remove the last name from the dst_path
// (it may not exist in current file system and FollowAllLinks will fail)
size_t last_slash = dst_path.find_last_of('/');
out_path = dst_path;
out_filename.clear();
if( last_slash != std::wstring::npos && last_slash + 1 < dst_path.size() )
{
out_path.erase(last_slash + 1); // leaving the slash at the end
out_filename = dst_path.c_str() + last_slash + 1;
}
int res = system->FollowAllLinks(cur->request->dir_tab, out_path, out_dir_tab, out_item, false, false, check_access);
if( res != 0 && res != 1 )
{
slog << logerror << T("mv_incorrect_dst_path") << logend;
return false;
}
out_has_file = (res == 1);
if( !out_filename.empty() )
return ParseDirCheckLastName();
return true;
}
bool Mv::CanRemoveRenameChild(const Item & child)
{
Item * parent_dir = system->dirs.GetDir(child.parent_id);
if( !parent_dir || !system->CanRemoveRenameChild(*parent_dir, child.user_id) )
{
log << log1 << "Mv: permission denied to: " << child.url << logend;
slog << logerror << T("mv_permission_denied_to") << ": " << child.url << logend;
return false;
}
return true;
}
bool Mv::MoveStaticFile(const std::wstring & from, const std::wstring & to)
{
if( from == to )
{
log << log3 << "Mv: the same path to a static file: " << to << " (skipped)" << logend;
return true;
}
if( RenameFile(from, to) )
{
log << log2 << "Mv: moved static file from: " << from << ", to: " << to << logend;
return true;
}
else
{
log << log1 << "Mv: cannot move a static file from: " << from << ", to: " << to << logend;
slog << logerror << T("internal_error") << logend;
return false;
}
}
void Mv::MoveStaticFile(Item & item)
{
bool res1, res2, res3, res4, res5;
res1 = system->MakeFilePath(item, old_static_path, false);
res2 = !item.has_thumb || system->MakeFilePath(item, old_static_thumb_path, true);
res3 = system->CreateNewFile(item);
res4 = system->MakeFilePath(item, new_static_path, false, true, config->upload_dirs_chmod);
res5 = !item.has_thumb || system->MakeFilePath(item, new_static_thumb_path, true, true, config->upload_dirs_chmod);
if( !res1 || !res2 || !res3 || !res4 || !res5 )
{
log << log1 << "Mv: cannot create a static path" << logend;
slog << logerror << T("internal_error") << logend;
return;
}
if( MoveStaticFile(old_static_path, new_static_path) )
{
if( db->EditFileById(item, item.id) != WINIX_ERR_OK )
{
log << log1 << "Mv: cannot move static file (database problem)" << logend;
slog << logerror << T("internal_error") << logend;
return;
}
if( item.has_thumb )
MoveStaticFile(old_static_thumb_path, new_static_thumb_path);
}
}
void Mv::MoveFilesPrepareTreeGo(const Item & src_dir)
{
DirContainer::ParentIterator i = system->dirs.FindFirstChild(src_dir.id);
// go through all directories
for( ; i != system->dirs.ParentEnd() ; i = system->dirs.NextChild(i) )
MoveFilesPrepareTreeGo(*(i->second));
files_iq.WhereParentId(src_dir.id);
db->GetItems(files_item_tab, files_iq);
for(size_t i=0 ; i<files_item_tab.size() ; ++i)
plugin.Call(WINIX_FILE_PREPARE_TO_MOVE, &files_item_tab[i]);
}
void Mv::MoveFilesPrepareTree(const Item & src_dir)
{
// we only calling plugins here
// so if there is no WINIX_FILE_PREPARE_TO_MOVE message
// we can immediately return and the database will not be bothered
if( plugin.HasMessage(WINIX_FILE_PREPARE_TO_MOVE) )
{
MoveFilesPrepareTreeGo(src_dir);
}
}
void Mv::MoveFilesTree(const Item & dir)
{
DirContainer::ParentIterator i = system->dirs.FindFirstChild(dir.id);
// go through all directories
for( ; i != system->dirs.ParentEnd() ; i = system->dirs.NextChild(i) )
MoveFilesTree(*(i->second));
files_iq.WhereParentId(dir.id);
db->GetItems(files_item_tab, files_iq);
for(size_t i=0 ; i<files_item_tab.size() ; ++i)
{
if( files_item_tab[i].file_type != WINIX_ITEM_FILETYPE_NONE )
{
plugin.Call(WINIX_FILE_PREPARE_TO_MOVE, &files_item_tab[i]);
MoveStaticFile(files_item_tab[i]);
plugin.Call(WINIX_FILE_MOVED, &files_item_tab[i]);
}
}
}
// private
// uses: out_dir_tab, out_filename
bool Mv::MoveDir(Item & src_dir, std::vector<Item*> & dst_dir_tab, const std::wstring & dst_name)
{
long dst_dir_id = dst_dir_tab.back()->id;
old_url = src_dir.url;
if( dst_dir_id == src_dir.id || system->dirs.HasParent(dst_dir_id, src_dir.id) )
{
log << log1 << "Mv: cannot move directory to inside it" << logend;
slog << logerror << T("mv_cannot_move_to_inside");
return false;
}
MoveFilesPrepareTree(src_dir);
if( !system->dirs.ChangeParent(src_dir.id, dst_dir_id) )
return false;
src_dir.parent_id = dst_dir_id;
old_url = src_dir.url;
if( !dst_name.empty() )
{
src_dir.url = dst_name;
functions->PrepareUrl(src_dir);
}
Error status = db->EditParentUrlById(src_dir, src_dir.id);
if( status == WINIX_ERR_OK )
{
log << log3 << "Mv: directory: " << old_url << " was moved to: ";
system->dirs.LogDir(dst_dir_tab);
log << src_dir.url << logend;
MoveFilesTree(src_dir);
return true;
}
return false;
}
// public
bool Mv::MoveDir(Item & src_dir, long dst_dir_id, const std::wstring & new_url, bool check_access)
{
bool res = MoveDir2(src_dir, dst_dir_id, new_url, check_access);
Clear();
return res;
}
// private
bool Mv::MoveDir2(Item & src_dir, long dst_dir_id, const std::wstring & new_url, bool check_access)
{
if( src_dir.type != Item::dir )
{
log << "Mv: a directory required" << logend;
return false;
}
if( src_dir.parent_id == -1 )
{
log << log1 << "Mv: the root directory cannot be moved anywhere" << logend;
slog << logerror << T("mv_cant_move_root_dir") << logend;
return false;
}
if( check_access && !CanRemoveRenameChild(src_dir) )
return false;
if( src_dir.id == dst_dir_id )
{
if( new_url.empty() || src_dir.url == new_url )
return true; // the same directory -- there is nothing to do
}
if( !system->dirs.CreateDirTab(dst_dir_id, out_dir_tab) )
{
log << log1 << "Mv: incorrect directory" << logend;
slog << logerror << T("mv_incorrect_dir") << logend;
return false;
}
return MoveDir(src_dir, out_dir_tab, new_url);
}
// public
bool Mv::MoveDir(Item & src_dir, const std::wstring & dst_path, bool check_access)
{
bool res = MoveDir2(src_dir, dst_path, check_access);
Clear();
return res;
}
// private
bool Mv::MoveDir2(Item & src_dir, const std::wstring & dst_path, bool check_access)
{
if( src_dir.type != Item::dir )
{
log << "Mv: a directory required" << logend;
return false;
}
if( src_dir.parent_id == -1 )
{
log << log1 << "Mv: the root directory cannot be moved anywhere" << logend;
slog << logerror << T("mv_cant_move_root_dir") << logend;
return false;
}
if( check_access && !CanRemoveRenameChild(src_dir) )
return false;
if( !ParseDir(dst_path, check_access) )
return false;
if( out_has_file )
{
log << log1 << "Mv: directory can be moved only to a directory" << logend;
slog << logerror << T("mv_dir_can_be_moved_to_dir") << logend;
return false;
}
if( src_dir.id == out_dir_tab.back()->id )
{
if( out_filename.empty() || src_dir.url == out_filename )
return true; // the same directory -- there is nothing to do
}
return MoveDir(src_dir, out_dir_tab, out_filename);
}
// private
bool Mv::MoveFileOrSymlink(Item & src_file, std::vector<Item*> & dst_dir_tab, const std::wstring & new_url)
{
plugin.Call(WINIX_FILE_PREPARE_TO_MOVE, &src_file);
old_url = src_file.url;
if( !new_url.empty() )
{
src_file.url = new_url;
functions->PrepareUrl(src_file);
}
src_file.parent_id = dst_dir_tab.back()->id;
Error status = db->EditParentUrlById(src_file, src_file.id);
if( status == WINIX_ERR_OK )
{
if( src_file.type == Item::file )
log << log3 << "Mv: file: ";
else
log << log3 << "Mv: symlink: ";
log << old_url << " was moved to: ";
system->dirs.LogDir(dst_dir_tab);
log << src_file.url << logend;
if( src_file.file_type != WINIX_ITEM_FILETYPE_NONE )
MoveStaticFile(src_file);
plugin.Call(WINIX_FILE_MOVED, &src_file);
return true;
}
return false;
}
// public
bool Mv::MoveFileOrSymlink(Item & src_file, long dst_dir_id, const std::wstring & new_url, bool check_access)
{
bool res = MoveFileOrSymlink2(src_file, dst_dir_id, new_url, check_access);
Clear();
return res;
}
// private
bool Mv::MoveFileOrSymlink2(Item & src_file, long dst_dir_id, const std::wstring & new_url, bool check_access)
{
if( src_file.type == Item::dir )
{
log << "Mv: a file/symlink required" << logend;
return false;
}
if( check_access && !CanRemoveRenameChild(src_file) )
return false;
if( src_file.parent_id == dst_dir_id )
{
if( new_url.empty() || src_file.url == new_url )
return true; // the same file -- there is nothing to do
}
if( !system->dirs.CreateDirTab(dst_dir_id, out_dir_tab) )
return false;
return MoveFileOrSymlink(src_file, out_dir_tab, new_url);
}
// public
bool Mv::MoveFileOrSymlink(Item & src_file, const std::wstring & dst_path, bool check_access)
{
bool res = MoveFileOrSymlink2(src_file, dst_path, check_access);
Clear();
return res;
}
// private
bool Mv::MoveFileOrSymlink2(Item & src_file, const std::wstring & dst_path, bool check_access)
{
if( src_file.type == Item::dir )
{
log << "Mv: a file/symlink required" << logend;
return false;
}
if( check_access && !CanRemoveRenameChild(src_file) )
return false;
if( !ParseDir(dst_path, check_access) )
return false;
if( src_file.parent_id == out_dir_tab.back()->id )
{
// actually out_filename is here empty
// because ParseDir() have been read it to out_item
if( out_filename.empty() || src_file.url == out_filename )
return true; // the same file -- there is nothing to do
}
return MoveFileOrSymlink(src_file, out_dir_tab, out_filename);
}
// private
void Mv::MoveAllFilesFromDir(Item & src_dir, std::vector<Item*> & dst_dir_tab, bool check_access)
{
content_dir_iq.WhereParentId(src_dir.id);
db->GetItems(item_tab, content_dir_iq);
out_filename.clear();
for(size_t i=0 ; i<item_tab.size() ; ++i)
{
if( check_access && !system->CanRemoveRenameChild(src_dir, item_tab[i].user_id) )
{
log << log1 << "Mv: permission denied to: " << src_dir.url << logend;
slog << logerror << T("mv_permission_denied_to") << ": " << src_dir.url << logend;
}
else
{
if( item_tab[i].type == Item::dir )
MoveDir(item_tab[i], dst_dir_tab, out_filename);
else
MoveFileOrSymlink(item_tab[i], dst_dir_tab, out_filename);
}
}
}
// public
void Mv::MoveDirContent(Item & src_dir, long dst_dir_id, bool check_access)
{
MoveDirContent2(src_dir, dst_dir_id, check_access);
Clear();
}
// private
void Mv::MoveDirContent2(Item & src_dir, long dst_dir_id, bool check_access)
{
if( src_dir.type != Item::dir )
{
log << "Mv: a directory required" << logend;
return;
}
if( src_dir.parent_id == -1 )
{
log << log1 << "Mv: the root directory cannot be moved anywhere" << logend;
slog << logerror << T("mv_cant_move_root_dir") << logend;
return;
}
if( !system->dirs.CreateDirTab(dst_dir_id, out_dir_tab) )
{
log << log1 << "Mv: incorrect directory" << logend;
slog << logerror << T("mv_incorrect_dir") << logend;
return;
}
MoveAllFilesFromDir(src_dir, out_dir_tab, check_access);
}
// public
void Mv::MoveDirContent(Item & src_dir, const std::wstring & dst_dir, bool check_access)
{
MoveDirContent2(src_dir, dst_dir, check_access);
Clear();
}
// private
void Mv::MoveDirContent2(Item & src_dir, const std::wstring & dst_dir, bool check_access)
{
if( !ParseDir(dst_dir, check_access) )
return;
if( out_has_file || !out_filename.empty() )
{
log << log1 << "Mv: directory content can be moved only to a directory" << logend;
slog << logerror << T("mv_dir_content_can_be_moved_to_dir") << logend;
return;
}
MoveDirContent2(src_dir, out_dir_tab.back()->id, check_access);
}
void Mv::MakePost()
{
const std::wstring & dst_path = cur->request->PostVar(L"dst_path");
bool ok = true;
if( cur->request->is_item )
{
ok = MoveFileOrSymlink(cur->request->item, dst_path, true);
}
else
{
if( cur->request->IsParam(L"c") || cur->request->IsPostVar(L"c") )
MoveDirContent(*cur->request->dir_tab.back(), dst_path, true);
else
ok = MoveDir(*cur->request->dir_tab.back(), dst_path, true);
}
if( ok )
system->RedirectToLastItem();
}
} // namespace
} // namespace Winix

134
winixd/functions/mv.h Normal file
View File

@@ -0,0 +1,134 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2010-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_winix_functions_mv
#define headerfile_winix_functions_mv
#include "functionbase.h"
namespace Winix
{
namespace Fun
{
class Mv : public FunctionBase
{
public:
Mv();
bool HasAccess();
void MakePost();
// moving a directory
// new_url can be empty (in such a case the old one is preserved)
// src_dir will be accordingly updated
bool MoveDir(Item & src_dir, long dst_dir_id, const std::wstring & new_url, bool check_access = true);
bool MoveDir(Item & src_dir, const std::wstring & dst_path, bool check_access = true);
// moving only the content of src_dir
// dst_path should point to an existing directory
// src_dir will be accordingly updated
void MoveDirContent(Item & src_dir, long dst_dir_id, bool check_access = true);
void MoveDirContent(Item & src_dir, const std::wstring & dst_dir, bool check_access = true);
// moving a file
// new_url can be empty (the old one is used then)
// src_file will be accordingly updated
bool MoveFileOrSymlink(Item & src_file, long dst_dir_id, const std::wstring & new_url, bool check_access = true);
bool MoveFileOrSymlink(Item & src_file, const std::wstring & dst_path, bool check_access = true);
private:
// directories parsed by ParseDir()
std::vector<Item*> out_dir_tab; // destination directories
Item out_item; // destination file/symlink (if out_has_file is true)
bool out_has_file; // if true then out_item is set
std::wstring out_filename; // the last part in an input path (not an existing directory, file or symlink)
// can be empty
// temporaries
std::wstring out_path;
std::wstring old_url;
std::wstring old_static_path;
std::wstring old_static_thumb_path;
std::wstring new_static_path;
std::wstring new_static_thumb_path;
// for files/symlinks in a directory
std::vector<Item> files_item_tab;
DbItemQuery files_iq;
// for moving content of a directory (all dirs/files/symlinks)
DbItemQuery content_dir_iq;
std::vector<Item> item_tab;
bool CheckAccessFromToDir(const Item & dir, bool only_content);
bool CanRemoveRenameChild(const Item & child);
void Prepare();
bool ParseDirCheckLastName();
bool ParseDir(const std::wstring & dst_path, bool check_access);
bool MoveStaticFile(const std::wstring & from, const std::wstring & to);
void MoveStaticFile(Item & item);
void MoveFilesPrepareTreeGo(const Item & src_dir);
void MoveFilesPrepareTree(const Item & src_dir);
void MoveFilesTree(const Item & dir);
bool MoveDir(Item & src_dir, std::vector<Item*> & dst_dir_tab, const std::wstring & dst_name);
bool MoveFileOrSymlink(Item & src_file, std::vector<Item*> & dst_dir_tab, const std::wstring & new_url);
void Clear();
bool MoveDir2(Item & src_dir, long dst_dir_id, const std::wstring & new_url, bool check_access);
bool MoveDir2(Item & src_dir, const std::wstring & dst_path, bool check_access);
bool MoveFileOrSymlink2(Item & src_file, long dst_dir_id, const std::wstring & new_url, bool check_access);
bool MoveFileOrSymlink2(Item & src_file, const std::wstring & dst_path, bool check_access);
void MoveDirContent2(Item & src_dir, long dst_dir_id, bool check_access);
void MoveAllFilesFromDir(Item & src_dir, std::vector<Item*> & dst_dir_tab, bool check_access);
void MoveDirContent2(Item & src_dir, const std::wstring & dst_dir, bool check_access);
};
} // namespace
} // namespace Winix
#endif

View File

@@ -0,0 +1,70 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2011-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "nicedit.h"
#include "functions.h"
namespace Winix
{
namespace Fun
{
Nicedit::Nicedit()
{
fun.url = L"nicedit";
}
bool Nicedit::HasAccess()
{
return functions->fun_emacs.HasAccess();
}
void Nicedit::MakePost()
{
functions->fun_emacs.MakePost();
}
} // namespace
} // namespace Winix

View File

@@ -0,0 +1,63 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2011-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_winix_functions_nicedit
#define headerfile_winix_functions_nicedit
#include "functionbase.h"
namespace Winix
{
namespace Fun
{
class Nicedit : public FunctionBase
{
public:
Nicedit();
bool HasAccess();
void MakePost();
};
} // namespace
} // namespace Winix
#endif

70
winixd/functions/node.cpp Normal file
View File

@@ -0,0 +1,70 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2008-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "node.h"
namespace Winix
{
namespace Fun
{
Node::Node()
{
fun.url = L"node";
}
void Node::MakeGet()
{
if( cur->request->param_tab.empty() )
{
//cur->request->status = Error
//!!zglosic 404
return;
}
long id = Tol(cur->request->param_tab[0].name);
system->RedirectTo(id);
}
} // namespace
} // namespace Winix

65
winixd/functions/node.h Normal file
View File

@@ -0,0 +1,65 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2010-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_winix_functions_node
#define headerfile_winix_functions_node
#include "functionbase.h"
namespace Winix
{
namespace Fun
{
class Node : public FunctionBase
{
public:
Node();
void MakeGet();
private:
};
} // namespace
} // namespace Winix
#endif

334
winixd/functions/passwd.cpp Normal file
View File

@@ -0,0 +1,334 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2011-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "passwd.h"
#include "core/slog.h"
#include "functions/functions.h"
namespace Winix
{
namespace Fun
{
Passwd::Passwd()
{
fun.url = L"passwd";
}
bool Passwd::HasAccess()
{
// a not logged user can use this function to reset his password
return true;
}
bool Passwd::IsPasswordCorrect(const std::wstring & pass, const std::wstring & conf_pass, bool use_ses_log)
{
if( pass != conf_pass )
{
log << log2 << "Passwd: passwords are different" << logend;
if( use_ses_log )
slog << logerror << T("adduser_err_passwords_different") << logend;
return false;
}
if( pass.size() < config->pass_min_size )
{
log << log2 << "Passwd: password is too small" << logend;
if( use_ses_log )
slog << logerror << T("adduser_err_password_too_small") << " "
<< config->pass_min_size << " " << T("adduser_err_password_too_small2") << logend;
return false;
}
if( pass.size() > WINIX_ACCOUNT_MAX_PASSWORD_SIZE )
{
log << log2 << "Passwd: password can't be longer than: " << WINIX_ACCOUNT_MAX_PASSWORD_SIZE << " characters" << logend;
if( use_ses_log )
slog << logerror << T("adduser_err_password_too_big") << " " << WINIX_ACCOUNT_MAX_PASSWORD_SIZE
<< " " << T("adduser_err_password_too_big2") << logend;
return false;
}
return true;
}
bool Passwd::ChangePassword(long user_id, const std::wstring & new_password)
{
bool result = false;
User * puser = system->users.GetUser(user_id);
if( puser )
{
up.has_pass = true;
up.pass = new_password;
system->crypt.PassHashCrypt(up);
result = (db->ChangeUserPass(user_id, up) == WINIX_ERR_OK);
if( result )
log << log2 << "Passwd: password for user " << puser->name << " has been changed" << logend;
else
log << log1 << "Passwd: I cannot change password -- database problem" << logend;
}
else
{
log << log1 << "Passwd: there is no a user with id: " << user_id << logend;
}
return result;
}
void Passwd::ChangePassword(User * puser)
{
long user_id;
const std::wstring & pass_cur = cur->request->PostVar(L"passwordcur");
const std::wstring & pass_new = cur->request->PostVar(L"passwordnew");
const std::wstring & pass_conf = cur->request->PostVar(L"passwordconfirm");
if( !cur->session->puser->super_user && !functions->fun_login.CheckUserPass(puser->name, pass_cur, user_id) )
{
log << log3 << "Passwd: incorrect current password" << logend;
slog << logerror << T("passwd_err_bad_current_password") << logend;
return;
}
if( !IsPasswordCorrect(pass_new, pass_conf, true) )
return;
if( ChangePassword(puser->id, pass_new) )
{
slog << loginfo << T("passwd_password_changed") << logend;
system->RedirectToLastItem();
}
}
bool Passwd::SetNewPassword(User * puser, bool use_ses_log)
{
bool result = false;
const std::wstring & pass = cur->request->PostVar(L"passwordnew");
const std::wstring & pass_conf = cur->request->PostVar(L"passwordconfirm");
if( IsPasswordCorrect(pass, pass_conf, use_ses_log) )
{
if( ChangePassword(puser->id, pass) )
{
result = true;
if( use_ses_log )
slog << loginfo << T("pw_password_changed") << logend;
}
else
{
if( use_ses_log )
slog << logerror << T("service_unavailable") << logend;
}
}
return result;
}
bool Passwd::ResetPassword(User * puser, long code, bool use_ses_log, bool only_check_access)
{
std::wstring * user_code_str = puser->aenv.GetValue(L"password_change_code");
if( user_code_str )
{
if( Tol(*user_code_str) == code )
{
if( only_check_access )
return true;
else
return SetNewPassword(puser, use_ses_log);
}
else
{
log << log2 << "Passwd: incorrect change password code" << logend;
if( use_ses_log )
slog << logerror << T(L"incorrect_change_password_code") << logend;
}
}
else
{
log << log1 << "Passwd: there is no change password code in admin environment" << logend;
if( use_ses_log )
slog << loginfo << T(L"password_cannot_be_changed") << logend;
}
return false;
}
bool Passwd::ResetPassword(const std::wstring & login, long code, bool use_ses_log, bool only_check_access)
{
bool result = false;
User * puser = system->users.GetUser(login);
if( puser )
{
long t = static_cast<long>(cur->request->start_time);
if( puser->aenv.Long(L"password_change_time") + config->reset_password_code_expiration_time > t )
{
result = ResetPassword(puser, code, use_ses_log, only_check_access);
}
else
{
log << log2 << "Passwd: the code has expired" << logend;
if( use_ses_log )
slog << logerror << T(L"code_expired") << logend;
}
}
else
{
log << log1 << "Passwd: there is no a user: " << login << logend;
}
return result;
}
void Passwd::ResetPassword()
{
const std::wstring & login = cur->request->PostVar(L"login");
long code = Tol(cur->request->PostVar(L"code"));
if( ResetPassword(login, code, true, false) )
system->RedirectToLastItem();
}
void Passwd::ShowResetPasswordForm()
{
const std::wstring & login = cur->request->ParamValue(L"login");
long code = Tol(cur->request->ParamValue(L"code"));
if( !login.empty() )
{
if( !ResetPassword(login, code, true, true) )
system->RedirectToLastItem();
}
else
{
system->RedirectToLastItem();
}
}
/*
if you are a root (super_user) you can change a password for everyone
(the html form has a select option)
but if you are not a root you can change only your password
and you should provide your current password as well
*/
void Passwd::MakePost()
{
const std::wstring * plogin;
// CHECK ME
// may it is better to check first for 'resetpassword'
// now if a user is logged then 'resetpassword' has no effect
// actually 'resetpassword' would be used for other user
if( cur->session->puser )
{
if( cur->session->puser->super_user )
plogin = &cur->request->PostVar(L"login");
else
plogin = &cur->session->puser->name;
User * puser = system->users.GetUser(*plogin);
if( puser )
ChangePassword(puser);
else
log << log1 << "Passwd: there is no such a user: " << *plogin << logend;
}
else
if( cur->request->IsParam(L"resetpassword") )
{
ResetPassword();
}
}
void Passwd::MakeGet()
{
if( cur->request->IsParam(L"resetpassword") )
ShowResetPasswordForm();
else
if( !cur->session->puser )
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
}
} // namespace
} // namespace Winix

81
winixd/functions/passwd.h Normal file
View File

@@ -0,0 +1,81 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2011-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_winix_functions_passwd
#define headerfile_winix_functions_passwd
#include "functionbase.h"
#include "core/user.h"
namespace Winix
{
namespace Fun
{
class Passwd : public FunctionBase
{
public:
Passwd();
bool HasAccess();
void MakeGet();
void MakePost();
bool IsPasswordCorrect(const std::wstring & pass, const std::wstring & conf_pass, bool use_ses_log = false);
bool ChangePassword(long user_id, const std::wstring & new_password);
bool ResetPassword(const std::wstring & login, long code, bool use_ses_log = false, bool only_check_access = false);
private:
UserPass up;
void ChangePassword(User * puser);
bool ResetPassword(User * puser, long code, bool use_ses_log);
bool SetNewPassword(User * puser, bool use_ses_log);
bool ResetPassword(User * puser, long code, bool use_ses_log, bool only_check_access);
void ResetPassword();
void ShowResetPasswordForm();
};
} // namespace
} // namespace Winix
#endif

78
winixd/functions/priv.cpp Normal file
View File

@@ -0,0 +1,78 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2008-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "priv.h"
namespace Winix
{
namespace Fun
{
Priv::Priv()
{
fun.url = L"priv";
}
void Priv::MakePost()
{
priv_changer.SetCur(cur);
priv_changer.SetSystem(system);
priv_changer.SetDb(db);
priv_changer.Change(true, true);
}
void Priv::MakeGet()
{
priv_changer.SetCur(cur);
priv_changer.SetSystem(system);
priv_changer.SetDb(db);
priv_changer.CheckAccess();
}
} // namespace
} // namespace Winix

68
winixd/functions/priv.h Normal file
View File

@@ -0,0 +1,68 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2010-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_winix_functions_priv
#define headerfile_winix_functions_priv
#include "functionbase.h"
#include "privchanger.h"
namespace Winix
{
namespace Fun
{
class Priv : public FunctionBase
{
public:
Priv();
void MakePost();
void MakeGet();
private:
PrivChanger priv_changer;
};
} // namespace
} // namespace Winix
#endif

View File

@@ -0,0 +1,335 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2010-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "privchanger.h"
namespace Winix
{
void PrivChanger::SetCur(Cur * pcur)
{
cur = pcur;
}
void PrivChanger::SetSystem(System * psystem)
{
system = psystem;
}
void PrivChanger::SetDb(Db * pdb)
{
db = pdb;
}
bool PrivChanger::CheckAccess()
{
// we do not check permissions here
// permissions depends on the user, group, and privileges
// but we cannot use parameter 'r' on files
// and only logged users can change permissions
if( !cur->session->puser || (cur->request->is_item && cur->request->IsParam(L"r")) )
{
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
return false;
}
return true;
}
bool PrivChanger::ChangeOwner(Item & item, long user_id, long group_id)
{
if( user_id!=item.user_id || group_id!=item.group_id )
{
if( !system->CanChangeUser(item, user_id) )
{
log << log3 << "Priv: can't change the user" << logend;
return false;
}
if( !system->CanChangeGroup(item, group_id) )
{
log << log3 << "Priv: can't change the group" << logend;
return false;
}
}
item.user_id = user_id;
item.group_id = group_id;
return true;
}
bool PrivChanger::ChangePrivileges(Item & item, int privileges)
{
if( privileges != item.privileges )
{
if( !system->CanChangePrivileges(item, privileges) )
{
log << log3 << "Priv: can't change privileges" << logend;
return false;
}
}
item.privileges = privileges;
return true;
}
void PrivChanger::ChangePriv(Item & item, long user_id, long group_id, int privileges)
{
if( change_owner )
{
if( !ChangeOwner(item, user_id, group_id) )
return;
}
if( change_priv )
{
if( !ChangePrivileges(item, privileges) )
return;
}
cur->request->status = db->EditPrivById(item, item.id);
}
void PrivChanger::PrivLogStart(const wchar_t * what, long user, long group, int priv)
{
log << log2 << what;
if( change_owner )
{
User * puser = system->users.GetUser(user);
Group * pgroup = system->groups.GetGroup(group);
log << "new user: ";
if( puser )
log << puser->name;
else
log << "id: " << user;
log << ", new group: ";
if( pgroup )
log << pgroup->name;
else
log << "id: " << group;
if( change_priv )
log << ", ";
}
if( change_priv )
{
char buf[30];
sprintf(buf, "0%o", priv);
log << "privileges: " << buf;
}
log << logend;
}
void PrivChanger::PrivLog(const wchar_t * what, long id, const std::wstring & url)
{
Item * root = 0;
if( id != -1 )
root = system->dirs.GetRootDir();
log << log3 << "Priv: " << what;
if( root && root->id == id )
log << "(root)";
else
log << url;
log << logend;
}
void PrivChanger::PrivFilesInDir(long parent_id)
{
DbItemQuery iq;
iq.SetAll(false, false);
iq.sel_user_id = iq.sel_group_id = iq.sel_guest_name = iq.sel_privileges = iq.sel_url = true;
iq.WhereParentId(parent_id);
iq.WhereType(Item::dir, false);
db->GetItems(cur->request->item_tab, iq);
std::vector<Item>::iterator i = cur->request->item_tab.begin();
for( ; i != cur->request->item_tab.end() ; ++i)
{
PrivLog(L"changed file: ", -1, i->url);
ChangePriv(*i, user_id_file, group_id_file, priv_file);
}
}
// recurrence
void PrivChanger::PrivDir(long parent_id)
{
PrivFilesInDir(parent_id);
DirContainer::ParentIterator i = system->dirs.FindFirstChild(parent_id);
for( ; i != system->dirs.ParentEnd() ; i = system->dirs.NextChild(i) )
{
PrivLog(L"changed dir: ", -1, i->second->url);
ChangePriv(*(i->second), user_id_dir, group_id_dir, priv_dir);
if( subdirectories )
PrivDir(i->second->id);
}
}
void PrivChanger::ReadPriv(const wchar_t * user_in, const wchar_t * group_in, const wchar_t * priv_in,
long & user_id, long & group_id, int & priv)
{
const std::wstring & user_str = cur->request->PostVar(user_in);
const std::wstring & group_str = cur->request->PostVar(group_in);
const std::wstring & priv_str = cur->request->PostVar(priv_in);
if( change_owner )
{
user_id = system->users.GetUserId( user_str );
group_id = system->groups.GetGroupId( group_str );
}
if( change_priv )
priv = wcstol(priv_str.c_str(), 0, 8);
}
void PrivChanger::PrivDir()
{
ReadPriv(L"userfile", L"groupfile", L"privilegesfile", user_id_file, group_id_file, priv_file);
ReadPriv(L"userdir", L"groupdir", L"privilegesdir", user_id_dir, group_id_dir, priv_dir);
PrivLogStart(L"Priv: changes for files: ", user_id_file, group_id_file, priv_file);
PrivLogStart(L"Priv: changes for dirs: ", user_id_dir, group_id_dir, priv_dir);
if( cur->request->IsPostVar(L"changecurrentdir") )
{
Item & last_dir = *cur->request->dir_tab.back();
PrivLog(L"changed dir: ", last_dir.id, last_dir.url);
ChangePriv(*cur->request->dir_tab.back(), user_id_dir, group_id_dir, priv_dir);
}
subdirectories = cur->request->IsPostVar(L"changesubdirs");
// go through all directories
PrivDir(cur->request->dir_tab.back()->id);
system->RedirectToLastDir();
}
// changing only one item (either a dir or file)
void PrivChanger::PrivOneItem()
{
ReadPriv(L"user", L"group", L"privileges", user_id_file, group_id_file, priv_file);
PrivLogStart(L"Priv: changes: ", user_id_file, group_id_file, priv_file);
if( cur->request->is_item )
{
ChangePriv(cur->request->item, user_id_file, group_id_file, priv_file);
system->RedirectTo(cur->request->item);
}
else
{
ChangePriv(*cur->request->dir_tab.back(), user_id_file, group_id_file, priv_file);
system->RedirectToLastDir();
}
}
/*
!! IMPROVE ME
we can add a counter to measure how many there are access denieds for files/directories
and when changing only one file/directory we can show access denied message
*/
void PrivChanger::Change(bool change_owner_, bool change_priv_)
{
if( !CheckAccess() )
return;
change_owner = change_owner_;
change_priv = change_priv_;
if( cur->request->IsParam(L"r") )
{
PrivDir();
}
else
{
PrivOneItem();
}
system->dirs.CheckRootDir();
}
} // namespace Winix

View File

@@ -0,0 +1,85 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2010-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_winix_functions_privchanger
#define headerfile_winix_functions_privchanger
#include "core/request.h"
#include "core/system.h"
#include "db/db.h"
namespace Winix
{
class PrivChanger
{
public:
bool CheckAccess();
void Change(bool change_owner_, bool change_priv_);
void SetCur(Cur * pcur);
void SetSystem(System * psystem);
void SetDb(Db * pdb);
private:
Cur * cur;
System * system;
Db * db;
long user_id_file, group_id_file, user_id_dir, group_id_dir;
int priv_file, priv_dir;
bool subdirectories;
bool change_owner, change_priv;
bool ChangeOwner(Item & item, long user_id, long group_id);
bool ChangePrivileges(Item & item, int privileges);
void ChangePriv(Item & item, long user_id, long group_id, int privileges);
void PrivLogStart(const wchar_t * what, long user, long group, int priv);
void PrivLog(const wchar_t * what, long id, const std::wstring & url);
void PrivFilesInDir(long parent_id);
void PrivDir(long parent_id);
void ReadPriv(const wchar_t * user_in, const wchar_t * group_in, const wchar_t * priv_in,
long & user_id, long & group_id, int & priv);
void PrivDir();
void PrivOneItem();
};
} // namespace Winix
#endif

81
winixd/functions/pw.cpp Normal file
View File

@@ -0,0 +1,81 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2012-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "pw.h"
#include "core/log.h"
#include "core/misc.h"
namespace Winix
{
namespace Fun
{
Pw::Pw()
{
fun.url = L"pw";
fun.privileges = 07000;
}
bool Pw::HasAccess()
{
return true;
}
/* this function will be used for: adding a new user, adding a new group, deleting an existing user etc. */
void Pw::MakePost()
{
}
void Pw::MakeGet()
{
}
} // namespace
} // namespace Winix

69
winixd/functions/pw.h Normal file
View File

@@ -0,0 +1,69 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2012-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_winix_functions_pw
#define headerfile_winix_functions_pw
#include "functionbase.h"
namespace Winix
{
namespace Fun
{
class Pw : public FunctionBase
{
public:
Pw();
bool HasAccess();
void MakePost();
void MakeGet();
private:
};
} // namespace
} // namespace Winix
#endif

View File

@@ -0,0 +1,94 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2008-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "reload.h"
#include "templates/templates.h"
namespace Winix
{
namespace Fun
{
Reload::Reload()
{
fun.url = L"reload";
fun.privileges = 07000;
}
bool Reload::HasAccess()
{
return cur->session->puser && cur->session->puser->super_user;
}
void Reload::FunReloadTemplates()
{
log << log1 << "Content: reloading html templates" << logend;
templates->ReadTemplates();
// reload notify after templates (notify uses locales from templates)
system->notify.ReadTemplates();
}
void Reload::MakeGet()
{
// !! temporarily only an admin has access
if( !cur->session->puser || !cur->session->puser->super_user )
{
log << log1 << "Content: Only an admin has access to reload function" << logend;
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
return;
}
if( cur->request->IsParam(L"templates") )
FunReloadTemplates();
}
} // namespace
} // namespace Winix

67
winixd/functions/reload.h Normal file
View File

@@ -0,0 +1,67 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2010-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_winix_functions_reload
#define headerfile_winix_functions_reload
#include "functionbase.h"
namespace Winix
{
namespace Fun
{
class Reload : public FunctionBase
{
public:
Reload();
bool HasAccess();
void MakeGet();
private:
void FunReloadTemplates();
};
} // namespace
} // namespace Winix
#endif

550
winixd/functions/rm.cpp Normal file
View File

@@ -0,0 +1,550 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2008-2015, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <cstdio>
#include "rm.h"
#include "core/plugin.h"
#include "core/misc.h"
#include "templates/templates.h"
namespace Winix
{
namespace Fun
{
Rm::Rm()
{
fun.url = L"rm";
follow_symlinks = false;
}
bool Rm::HasAccessToDir(const Item & dir, bool only_content)
{
if( dir.parent_id == -1 )
{
// this is a root directory
// we can only remove the content of the root directory
// sticky bit for a specified child will be checked later
if( !only_content || !system->HasWriteAccess(dir) )
return false;
}
else
if( only_content )
{
// sticky bit for a specified child will be checked later
if( !system->HasWriteAccess(dir) )
return false;
}
else
{
Item * last_but_one_dir = system->dirs.GetDir(dir.parent_id);
if( !last_but_one_dir )
// ops, there is no a parent dir
return false;
if( !system->CanRemoveRenameChild(*last_but_one_dir, dir.user_id) )
return false;
}
return true;
}
/*
here we are making a little test -- this method returns false if
we are sure that the permissions is not allowed (consequently the html form
will not be displayed)
the correct checking for permissions is done later in MakePost() method
parameter 'c' to rm function means removing only the content of a directory
this parameter can be sent either by a get or a post variable
*/
bool Rm::HasAccess()
{
bool res = false;
if( cur->request->is_item )
{
res = system->CanRemoveRenameChild(*cur->request->dir_tab.back(), cur->request->item.user_id);
}
else
{
if( cur->request->IsParam(L"r") )
{
bool only_content = (cur->request->IsParam(L"c") || cur->request->IsPostVar(L"c"));
res = HasAccessToDir(*cur->request->dir_tab.back(), only_content);
}
else
{
log << log3 << "Rm: directories can be removed only with 'r' parameter" << logend;
slog << logerror << T("rm_use_r_option") << logend;
}
}
if( !res && cur->request->IsParam(L"jquery_upload") )
CreateJSON(res);
return res;
}
void Rm::Prepare()
{
// selecting files and symlinks (without directories)
content_dir_iq.SetAll(false, false);
content_dir_iq.sel_parent_id = true;
content_dir_iq.sel_type = true;
content_dir_iq.sel_url = true;
content_dir_iq.sel_file = true;
content_dir_iq.sel_user_id = true;
content_dir_iq.sel_group_id = true;
content_dir_iq.sel_privileges = true;
content_dir_iq.sel_meta = true;
content_dir_iq.WhereType(Item::dir, false);
}
void Rm::RemoveStaticFile(const std::wstring & path)
{
if( Winix::RemoveFile(path) )
{
log << log2 << "Rm: static file removed: " << path << logend;
}
else
{
log << log1 << "Rm: I can't remove a static file: " << path << logend;
slog << logerror << T("rm_cannot_remove_static_file") << ": " << path << logend;
}
}
void Rm::RemoveStaticFile(const Item & item)
{
if( system->MakeFilePath(item, path, false) )
{
RemoveStaticFile(path);
if( item.has_thumb && system->MakeFilePath(item, path, true) )
RemoveStaticFile(path);
}
else
{
log << log1 << "Rm: I cannot create a path to a static file, url: "
<< item.url << ", id: " << item.id << logend;
slog << logerror << T("rm_cannot_create_static_path") << ": " << item.url << logend;
}
}
/*
!! IMPROVE ME:
plugin.Call(WINIX_FILE_REMOVED, &item) is getting its parameter as non-const
in the future we can add a pointer cp1, cp2 (in plugins) but pointing to a const object
and this bool Rm::RemoveFile(Item & item) can became bool Rm::RemoveFile(const Item & item)
*/
bool Rm::RemoveFile(Item & item)
{
plugin.Call(WINIX_FILE_PREPARE_TO_REMOVE, &item);
if( db->DelItem(item) == WINIX_ERR_OK )
{
if( item.type == Item::file )
log << log2 << "Rm: deleted file: ";
else
log << log2 << "Rm: deleted symlink: ";
log << item.url << logend;
TemplatesFunctions::pattern_cacher.DeletePattern(item);
if( item.file_type != WINIX_ITEM_FILETYPE_NONE )
RemoveStaticFile(item);
plugin.Call(WINIX_FILE_REMOVED, &item);
return true;
}
return false;
}
/*
we do not modify item
it is non-const because we use plugin.Call() later with a pointer to this structure
(and we want to avoid casting)
*/
bool Rm::RemoveFileOrSymlink(Item & item, bool check_access)
{
if( item.type == Item::dir )
return false;
if( check_access )
{
Item * dir = system->dirs.GetDir(item.parent_id);
// if there is not 'dir' directory then we can simply remove 'item'
if( dir )
{
if( !system->CanRemoveRenameChild(*dir, item.user_id) )
{
log << log1 << "Rm: permission denied to remove: " << item.url << ", id: " << item.id << logend;
slog << logerror << T("rm_permission_denied_to") << ": " << item.url << logend;
return false;
}
}
}
return RemoveFile(item);
}
bool Rm::RemoveFileOrSymlink(long item_id, bool check_access)
{
bool result = false;
// selecting files, symlinks and directories
rm_by_id_iq.SetAll(false, false);
rm_by_id_iq.sel_parent_id = true;
rm_by_id_iq.sel_type = true;
rm_by_id_iq.sel_url = true;
rm_by_id_iq.sel_file = true;
rm_by_id_iq.sel_user_id = true;
rm_by_id_iq.sel_group_id = true;
rm_by_id_iq.sel_privileges = true;
rm_by_id_iq.sel_meta = true;
rm_by_id_iq.WhereId(item_id);
if( db->GetItem(rm_by_id_item, rm_by_id_iq) == WINIX_ERR_OK )
{
if( rm_by_id_item.type == Item::file || rm_by_id_item.type == Item::symlink )
{
result = RemoveFileOrSymlink(rm_by_id_item, check_access);
}
else
{
log << log2 << "Rm: I cannot remove file or symlink, item_id: " << item_id
<< " is a directory" << logend;
}
}
return result;
}
// for other uses (plugins etc)
bool Rm::RemoveItemById(long item_id, bool check_access)
{
bool result = false;
// selecting files, symlinks and directories
rm_by_id_iq.SetAll(false, false);
rm_by_id_iq.sel_parent_id = true;
rm_by_id_iq.sel_type = true;
rm_by_id_iq.sel_url = true;
rm_by_id_iq.sel_file = true;
rm_by_id_iq.sel_user_id = true;
rm_by_id_iq.sel_group_id = true;
rm_by_id_iq.sel_privileges = true;
rm_by_id_iq.sel_meta = true;
rm_by_id_iq.WhereId(item_id);
if( db->GetItem(rm_by_id_item, rm_by_id_iq) == WINIX_ERR_OK )
{
if( rm_by_id_item.type == Item::dir )
{
RemoveDirTree(rm_by_id_item, true, check_access);
result = true; // RemoveDirTree doesn't return a status
}
else
{
result = RemoveFileOrSymlink(rm_by_id_item, check_access);
}
}
return result;
}
bool Rm::RemoveItemByPath(const std::wstring & path, bool check_access)
{
bool result = false;
int res = system->FollowAllLinks(path, rm_path_dir_tab, rm_path_item);
if( res == 0 )
{
Item * dir = system->dirs.GetDir(rm_path_dir_tab.back()->id);
if( dir )
{
RemoveDirTree(*dir, true, check_access);
result = false;
}
}
else
if( res == 1 )
{
result = RemoveFileOrSymlink(rm_path_item, check_access);
}
return result;
}
bool Rm::RemoveDirFiles(long dir_id, bool check_access)
{
content_dir_iq.WhereParentId(dir_id);
db->GetItems(content_item_tab, content_dir_iq);
size_t removed = 0;
for(size_t i=0 ; i<content_item_tab.size() ; ++i)
if( RemoveFileOrSymlink(content_item_tab[i], check_access) )
removed += 1;
return removed == content_item_tab.size();
}
/*
parent_dir can be null (when current_dir is the root directory)
*/
void Rm::RemoveCurrentDir(Item * parent_dir, Item * current_dir, bool check_access)
{
if( check_access )
{
if( !parent_dir || !system->CanRemoveRenameChild(*parent_dir, current_dir->user_id) )
{
log << log1 << "Rm: permission denied to directory: " << current_dir->url << logend;
slog << logerror << T("rm_permission_denied_to") << ": " << current_dir->url << logend;
return;
}
}
plugin.Call(WINIX_DIR_PREPARE_TO_REMOVE, current_dir);
if( db->DelDirById(current_dir->id) == WINIX_ERR_OK )
{
long dir_id = current_dir->id;
old_url = current_dir->url;
system->dirs.DelDir(dir_id);
// don't use current_dir pointer anymore
log << log2 << "Rm: directory removed: " << old_url << logend;
plugin.Call(WINIX_DIR_REMOVED, dir_id);
}
else
{
log << log1 << "Rm: I cannot remove a directory: " << current_dir->url << " (database error)" << logend;
}
}
/*
parent_dir can be null (when current_dir is pointing to the root directory)
current_dir is pointing to the directory which should be deleted
(contents of this directory is removed but the directory is deleted only if remove_this_dir is true)
*/
void Rm::RemoveDirTree(Item * parent_dir, Item * current_dir, bool remove_this_dir, bool check_access)
{
if( check_access && !system->HasReadExecAccess(*current_dir) )
{
log << log1 << "Rm: permission denied to directory: " << current_dir->url << logend;
slog << logerror << T("rm_permission_denied_to") << ": " << current_dir->url << logend;
return;
}
DirContainer::ParentIterator pnext, p = system->dirs.FindFirstChild(current_dir->id);
for( ; p != system->dirs.ParentEnd() ; p = pnext )
{
Item * child_dir = &(*p->second);
// this iterator p will be invalidated by the below RemoveDirTree() call
// (the next iterator we must calculate beforehand)
pnext = system->dirs.NextChild(p);
RemoveDirTree(current_dir, child_dir, true, check_access);
}
bool all_file_removed = RemoveDirFiles(current_dir->id, check_access);
if( remove_this_dir )
{
if( all_file_removed )
{
RemoveCurrentDir(parent_dir, current_dir, check_access);
// don't use current_dir pointer anymore
}
else
{
log << log1 << "Rm: " << current_dir->url << " directory not empty" << logend;
slog << logerror << current_dir->url << T("rm_directory_not_empty") << logend;
}
}
}
void Rm::RemoveDirTree(Item & dir, bool remove_this_dir, bool check_access)
{
Item * parent = system->dirs.GetDir(dir.parent_id);
RemoveDirTree(parent, &dir, remove_this_dir, check_access);
}
void Rm::RemoveDirContent()
{
if( !cur->request->IsParam(L"r") )
{
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
log << log3 << "Rm: directory content can be removed only with 'r' parameter" << logend;
slog << logerror << T("rm_content_use_r_option") << logend;
return;
}
RemoveDirTree(*cur->request->dir_tab.back(), false, true);
}
void Rm::RemoveDir()
{
if( !cur->request->IsParam(L"r") )
{
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
log << log3 << "Rm: a directory can be removed only with 'r' parameter" << logend;
slog << logerror << T("rm_use_r_option") << logend;
return;
}
if( cur->request->dir_tab.size() <= 1 )
{
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
log << log1 << "Rm: the root directory cannot be removed" << logend;
slog << logerror << T("rm_cannot_remove_root_dir") << logend;
return;
}
RemoveDirTree(*cur->request->dir_tab.back(), true, true);
cur->request->dir_tab.erase(--cur->request->dir_tab.end());
}
void Rm::Clear()
{
content_item_tab.clear();
}
/*
* !! IMPROVE ME what about a Content-Type header for javascript?
*/
void Rm::CreateJSON(bool status)
{
using TemplatesFunctions::R;
PT::WTextStream buf;
JSONescape(buf, cur->request->item.url);
auto & out = cur->request->out_main_stream;
out << R("{\"files\": [{\"") << R(buf) << R("\": ");
if( status )
out << R("true");
else
out << R("false");
out << R("}]}");
cur->request->page_generated = true;
cur->request->out_main_stream_use_html_filter = false;
}
void Rm::MakePost()
{
Prepare();
if( cur->request->is_item )
{
RemoveFileOrSymlink(cur->request->item, true);
}
else
{
if( cur->request->IsParam(L"c") || cur->request->IsPostVar(L"c") )
RemoveDirContent();
else
RemoveDir();
}
Clear();
if( cur->request->IsParam(L"jquery_upload") )
CreateJSON(true);
else
if( cur->request->status == WINIX_ERR_OK )
system->RedirectToLastDir();
}
} // namespace
} // namespace Winix

112
winixd/functions/rm.h Normal file
View File

@@ -0,0 +1,112 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2010-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_winix_functions_rm
#define headerfile_winix_functions_rm
#include "functionbase.h"
namespace Winix
{
namespace Fun
{
class Rm : public FunctionBase
{
public:
Rm();
bool HasAccess();
void MakePost();
// removing the whole directory structure
// if remove_this_dir is false then only content of dir is removed
void RemoveDirTree(Item & dir, bool remove_this_dir, bool check_access = true);
// removing either a file or a symlink
bool RemoveFileOrSymlink(long item_id, bool check_access = true);
bool RemoveFileOrSymlink(Item & item, bool check_access = true);
// removing either a directory or a symlink or a file
// if item_id is a directory then the whole subdirectories are removed too
bool RemoveItemById(long item_id, bool check_access = true);
// removing either a directory or a symlink or a file
// if path is a directory then the whole subdirectories are removed too
// path must begin with a slash (or can be empty then the root directory is removed)
bool RemoveItemByPath(const std::wstring & path, bool check_access = true);
private:
// for deleting content in a directory (files and symlinks)
DbItemQuery content_dir_iq;
std::vector<Item> content_item_tab;
std::wstring path;
// for logging
std::wstring old_url;
// for removing an item by id
DbItemQuery rm_by_id_iq;
Item rm_by_id_item;
std::vector<Item*> rm_path_dir_tab;
Item rm_path_item;
bool HasAccessToDir(const Item & dir, bool only_content);
void Prepare();
void Clear();
bool RemoveFile(Item & item);
bool RemoveDirFiles(long dir_id, bool check_access);
void RemoveCurrentDir(Item * parent_dir, Item * current_dir, bool check_access);
void RemoveDirTree(Item * parent_dir, Item * current_dir, bool remove_this_dir, bool check_access);
void RemoveStaticFile(const std::wstring & path);
void RemoveStaticFile(const Item & item);
void RemoveDirContent();
void RemoveDir();
void CreateJSON(bool status);
};
} // namespace
} // namespace Winix
#endif

114
winixd/functions/rmuser.cpp Normal file
View File

@@ -0,0 +1,114 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2012-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "rmuser.h"
#include "core/log.h"
#include "core/misc.h"
#include "core/plugin.h"
#include "functions/functions.h"
namespace Winix
{
namespace Fun
{
RmUser::RmUser()
{
fun.url = L"rmuser";
}
bool RmUser::HasAccess()
{
return cur->session->puser && cur->session->puser->super_user;
}
bool RmUser::RemoveUser(long user_id)
{
User * puser = system->users.GetUser(user_id);
bool result = false;
if( puser )
{
name = puser->name;
if( system->users.Remove(user_id) )
{
result = true;
log << log2 << "RmUser: user id: " << user_id << " name: " << name << " was removed" << logend;
if( db->RemoveUser(user_id) != WINIX_ERR_OK )
log << log1 << "RmUser: I cannot remove a user id: " << user_id << " from database" << logend;
}
}
return result;
}
void RmUser::MakePost()
{
if( cur->session->puser )
{
long user_id;
if( cur->session->puser->super_user )
user_id = Tol(cur->request->PostVar(L"userid"));
else
user_id = cur->session->puser->id;
RemoveUser(user_id);
}
system->RedirectToLastItem();
}
void RmUser::MakeGet()
{
}
} // namespace
} // namespace Winix

71
winixd/functions/rmuser.h Normal file
View File

@@ -0,0 +1,71 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2012-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_winix_functions_rmuser
#define headerfile_winix_functions_rmuser
#include "functionbase.h"
namespace Winix
{
namespace Fun
{
class RmUser : public FunctionBase
{
public:
RmUser();
bool HasAccess();
void MakeGet();
void MakePost();
bool RemoveUser(long user_id);
private:
std::wstring name;
};
} // namespace
} // namespace Winix
#endif

79
winixd/functions/run.cpp Normal file
View File

@@ -0,0 +1,79 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2008-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "run.h"
namespace Winix
{
namespace Fun
{
Run::Run()
{
fun.url = L"run";
}
void Run::MakePost()
{
MakeGet();
}
void Run::MakeGet()
{
if( !cur->request->is_item )
{
log << log1 << "Content: Run function requires an item" << logend;
cur->request->status = WINIX_ERR_NO_ITEM;
return;
}
if( !system->HasReadExecAccess(cur->request->item) )
{
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
return;
}
}
} // namespace
} // namespace Winix

66
winixd/functions/run.h Normal file
View File

@@ -0,0 +1,66 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2010-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_winix_functions_run
#define headerfile_winix_functions_run
#include "functionbase.h"
namespace Winix
{
namespace Fun
{
class Run : public FunctionBase
{
public:
Run();
private:
void MakePost();
void MakeGet();
};
} // namespace
} // namespace Winix
#endif

209
winixd/functions/sort.cpp Normal file
View File

@@ -0,0 +1,209 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2011-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "sort.h"
#include "core/plugin.h"
namespace Winix
{
namespace Fun
{
Sort::Sort()
{
fun.url = L"sort";
}
bool Sort::HasAccess()
{
if( cur->request->is_item )
return system->HasWriteAccess(cur->request->item);
// for directories we always return true
// (permissions are checked later)
return true;
}
void Sort::GetDirContent()
{
iq.sel_content = false;
iq.WhereParentId(cur->request->dir_tab.back()->id);
db->GetItems(cur->request->item_tab, iq);
system->CheckWriteAccessToItems(cur->request->item_tab);
}
bool Sort::SortHelper::operator()(size_t t1, size_t t2)
{
return psort->cur->request->item_tab[t1].id < psort->cur->request->item_tab[t2].id;
}
bool Sort::SortFun2(const SortPair & s1, const SortPair & s2)
{
return s1.id < s2.id;
}
void Sort::CreateItemTab()
{
size_t len = cur->request->item_tab.size();
item_tab.resize(len);
for(size_t i=0 ; i<len ; ++i)
item_tab[i] = i;
std::sort(item_tab.begin() , item_tab.end(), SortHelper(this));
}
void Sort::CreateItemTab2()
{
PostTab::iterator i2 = cur->request->post_tab.begin();
SortPair sp;
item_tab2.clear();
item_tab2.reserve(cur->request->post_tab.size());
// post_tab is sorted in lexicographical order but we should sort it by numbers
for( ; i2 != cur->request->post_tab.end() ; ++i2 )
{
if( IsSubStringNoCase(L"sort", i2->first.c_str()) )
{
sp.id = Tol(i2->first.c_str() + 4);
sp.sort_index = Toi(i2->second);
item_tab2.push_back(sp);
}
}
std::sort(item_tab2.begin(), item_tab2.end(), SortFun2);
}
void Sort::UpdateSortIndex(Item & item, int sort_index)
{
item.sort_index = sort_index;
if( db->EditSortIndexItemById(item.id, sort_index) == WINIX_ERR_OK )
{
log << log2
<< "Sort: updated sort index, item_id=" << item.id
<< ", url=" << item.url
<< ", sort_index=" << sort_index << logend;
}
}
void Sort::UpdateSortIndexes()
{
size_t i1 = 0;
size_t i2 = 0;
while( i1 < item_tab.size() && i2 < item_tab2.size() )
{
long id1 = cur->request->item_tab[item_tab[i1]].id;
long id2 = item_tab2[i2].id;
if( id1 == id2 )
{
int sort_index = item_tab2[i2].sort_index;
Item & item = cur->request->item_tab[item_tab[i1]];
if( system->HasWriteAccess(item) )
UpdateSortIndex(item, sort_index);
++i1;
++i2;
}
else
if( id1 < id2 )
{
++i1;
}
else
{
++i2;
}
}
}
void Sort::MakePost()
{
if( cur->request->is_item )
{
int sort_index = Toi(cur->request->PostVar(L"sortindex"));
UpdateSortIndex(cur->request->item, sort_index);
}
else
{
GetDirContent();
CreateItemTab();
CreateItemTab2();
UpdateSortIndexes();
}
plugin.Call(WINIX_DIR_CONTENT_SORTED, cur->request->dir_tab.back());
system->RedirectToLastItem();
}
void Sort::MakeGet()
{
if( !cur->request->is_item )
GetDirContent();
}
} // namespace
} // namespace Winix

95
winixd/functions/sort.h Normal file
View File

@@ -0,0 +1,95 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2011-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_winix_functions_sort
#define headerfile_winix_functions_sort
#include "functionbase.h"
namespace Winix
{
namespace Fun
{
class Sort : public FunctionBase
{
public:
Sort();
bool HasAccess();
void MakeGet();
void MakePost();
private:
DbItemQuery iq;
std::vector<size_t> item_tab; // indexes to cur->request->item_tab
struct SortPair
{
long id;
int sort_index;
};
std::vector<SortPair> item_tab2; // from post table
// for sorting item_tab
struct SortHelper
{
Sort * psort;
SortHelper(Sort * s) : psort(s) {}
bool operator()(size_t t1, size_t t2);
};
// for sorting item_tab2
static bool SortFun2(const SortPair & s1, const SortPair & s2);
void GetDirContent();
void CreateItemTab();
void CreateItemTab2();
void UpdateSortIndex(Item & item, int sort_index);
void UpdateSortIndexes();
};
} // namespace
} // namespace Winix
#endif

View File

@@ -0,0 +1,58 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2010-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "specialdefault.h"
namespace Winix
{
namespace Fun
{
SpecialDefault::SpecialDefault()
{
fun.url = L"-";
}
} // namespace
} // namespace Winix

View File

@@ -0,0 +1,60 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2010-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_winix_functions_specialdefault
#define headerfile_winix_functions_specialdefault
#include "functionbase.h"
namespace Winix
{
namespace Fun
{
class SpecialDefault : public FunctionBase
{
public:
SpecialDefault();
};
} // namespace
} // namespace Winix
#endif

56
winixd/functions/stat.cpp Normal file
View File

@@ -0,0 +1,56 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2008-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "stat.h"
namespace Winix
{
namespace Fun
{
Stat::Stat()
{
fun.url = L"stat";
}
} // namespace
} // namespace Winix

63
winixd/functions/stat.h Normal file
View File

@@ -0,0 +1,63 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2010-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_winix_functions_stat
#define headerfile_winix_functions_stat
#include "functionbase.h"
namespace Winix
{
namespace Fun
{
class Stat : public FunctionBase
{
public:
Stat();
private:
};
} // namespace
} // namespace Winix
#endif

View File

@@ -0,0 +1,128 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2008-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "subject.h"
#include "core/plugin.h"
namespace Winix
{
namespace Fun
{
Subject::Subject()
{
fun.url = L"subject";
}
bool Subject::SubjectCheckAccess()
{
// super user can always
if( cur->session->puser && cur->session->puser->super_user )
return true;
bool access;
if( cur->request->is_item )
access = system->HasWriteAccess(cur->request->item);
else
access = system->HasWriteAccess(*cur->request->dir_tab.back());
if( !access )
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
return access;
}
void Subject::EditDirSubject()
{
Item & dir = *cur->request->dir_tab.back();
cur->request->PostVar(L"subject", dir.subject);
db->EditSubjectById(dir, dir.id);
// !! IMPROVE ME
// we need something like WINIX_DIR_CHANGED message
//plugin.Call(WINIX______CHANGED, cur->request->dir_tab.back());
system->RedirectToLastDir();
}
void Subject::EditFileSubject()
{
cur->request->PostVar(L"subject", cur->request->item.subject);
db->EditSubjectById(cur->request->item, cur->request->item.id);
plugin.Call(WINIX_FILE_CHANGED, &cur->request->item);
system->RedirectTo(cur->request->item);
}
void Subject::MakePost()
{
if( !SubjectCheckAccess() )
return;
if( cur->request->is_item )
EditFileSubject();
else
EditDirSubject();
}
void Subject::MakeGet()
{
SubjectCheckAccess();
}
} // namespace
} // namespace Winix

View File

@@ -0,0 +1,69 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2010-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_winix_functions_subject
#define headerfile_winix_functions_subject
#include "functionbase.h"
namespace Winix
{
namespace Fun
{
class Subject : public FunctionBase
{
public:
Subject();
void MakePost();
void MakeGet();
private:
bool SubjectCheckAccess();
void EditDirSubject();
void EditFileSubject();
};
} // namespace
} // namespace Winix
#endif

View File

@@ -0,0 +1,139 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2010-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "template.h"
#include "core/misc.h"
namespace Winix
{
namespace Fun
{
Template::Template()
{
fun.url = L"template";
}
bool Template::HasAccess()
{
if( config->template_only_root_use_template_fun )
{
// only root is allowed to change the template
return (cur->session->puser && cur->session->puser->super_user);
}
if( cur->request->is_item )
return system->HasWriteAccess(cur->request->item);
else
return system->HasWriteAccess(*cur->request->dir_tab.back());
}
void Template::PutLog(Item & item)
{
log << log3 << "Template: changed template for item.id: " << item.id << ", new template: ";
if( item.html_template.empty() )
log << "(taking from mount point)";
else
log << item.html_template;
log << logend;
}
void Template::CreateTemplateFileName(const std::wstring & index_str)
{
int index = Toi(index_str);
if( index < 0 )
{
html_template.clear();
}
else
if( index == 0 )
{
html_template = config->templates_index;
}
else
{
index -= 1;
Mount::ParamRow & par = system->mounts.pmount->param[system->mounts.MountParHtmlTemplate()];
if( !par.defined || (size_t)index >= par.arg.size() )
html_template.clear();
else
html_template = par.arg[index];
}
}
void Template::ChangeTemplate(Item & item)
{
if( html_template != item.html_template )
{
cur->request->status = db->EditTemplateItemById(item.id, html_template);
if( cur->request->status == WINIX_ERR_OK )
{
item.html_template = html_template;
PutLog(item);
}
}
}
void Template::MakePost()
{
CreateTemplateFileName(cur->request->PostVar(L"template"));
ChangeTemplate(*cur->request->last_item);
system->RedirectToLastItem();
}
} // namespace
} // namespace Winix

View File

@@ -0,0 +1,69 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2010-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_winix_functions_template
#define headerfile_winix_functions_template
#include "functionbase.h"
namespace Winix
{
namespace Fun
{
class Template : public FunctionBase
{
public:
Template();
bool HasAccess();
void MakePost();
private:
std::wstring html_template;
void CreateTemplateFileName(const std::wstring & index_str);
void ChangeTemplate(Item & item);
void PutLog(Item & item);
};
} // namespace
} // namespace Winix
#endif

View File

@@ -0,0 +1,88 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2012-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "timezone.h"
namespace Winix
{
namespace Fun
{
TimeZone::TimeZone()
{
fun.url = L"timezone";
}
bool TimeZone::HasAccess()
{
return cur->session->puser != 0;
}
void TimeZone::MakePost()
{
if( cur->session->puser )
{
size_t tz_id = size_t(Toi(cur->request->PostVar(L"timezoneid")));
if( system->time_zones.HasZone(tz_id) )
{
cur->session->puser->time_zone_id = tz_id;
db->ChangeUserTimeZone(cur->session->puser->id, tz_id);
}
else
{
log << log1 << "TimeZone: incorrect time zone id: " << tz_id << logend;
}
}
}
void TimeZone::MakeGet()
{
}
} // namespace
} // namespace Winix

View File

@@ -0,0 +1,68 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2012-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_winix_functions_timezone
#define headerfile_winix_functions_timezone
#include "functionbase.h"
namespace Winix
{
namespace Fun
{
class TimeZone : public FunctionBase
{
public:
TimeZone();
bool HasAccess();
void MakePost();
void MakeGet();
private:
};
} // namespace
} // namespace Winix
#endif

View File

@@ -0,0 +1,86 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2008-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "tinymce.h"
#include "functions.h"
namespace Winix
{
namespace Fun
{
Tinymce::Tinymce()
{
fun.url = L"tinymce";
}
void Tinymce::Init()
{
system->AddCommonFileToVar(L"winix/tinymce.js", L"tinymce.js");
}
bool Tinymce::HasAccess()
{
return functions->fun_emacs.HasAccess();
}
void Tinymce::MakeGet()
{
cur->session->last_css.clear();
int parcss = system->mounts.MountParCss();
if( cur->mount->param[parcss].defined )
cur->session->last_css = cur->mount->param[parcss].arg;
}
void Tinymce::MakePost()
{
functions->fun_emacs.MakePost();
}
} // namespace
} // namespace Winix

View File

@@ -0,0 +1,65 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2010-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_winix_functions_tinymce
#define headerfile_winix_functions_tinymce
#include "functionbase.h"
namespace Winix
{
namespace Fun
{
class Tinymce : public FunctionBase
{
public:
Tinymce();
void Init();
bool HasAccess();
void MakeGet();
void MakePost();
};
} // namespace
} // namespace Winix
#endif

View File

@@ -0,0 +1,59 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2008-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "uname.h"
namespace Winix
{
namespace Fun
{
Uname::Uname()
{
fun.url = L"uname";
}
} // namespace
} // namespace Winix

63
winixd/functions/uname.h Normal file
View File

@@ -0,0 +1,63 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2010-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_winix_functions_uname
#define headerfile_winix_functions_uname
#include "functionbase.h"
namespace Winix
{
namespace Fun
{
class Uname : public FunctionBase
{
public:
Uname();
private:
};
} // namespace
} // namespace Winix
#endif

362
winixd/functions/upload.cpp Normal file
View File

@@ -0,0 +1,362 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2008-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <cstdio>
#include <errno.h>
#include "upload.h"
#include "core/misc.h"
#include "core/plugin.h"
#include "functions/functions.h"
#include "templates/templates.h"
#include "utf8/utf8.h"
namespace Winix
{
namespace Fun
{
Upload::Upload()
{
fun.url = L"upload";
}
void Upload::Init()
{
json_serializer.TreatAsTable(L"files");
json_serializer.TreatAsNumeric(L"size");
}
bool Upload::HasAccess(const Item & item)
{
// you can use 'upload' only in a directory
if( item.type != Item::dir )
return false;
if( config->upload_dir.empty() )
{
log << log1 << "Request: can't use upload function, upload_dir must be set in the config file" << logend;
return false;
}
if( cur->session->puser && cur->session->puser->super_user )
// super user can use upload everywhere
return true;
if( !system->HasWriteAccess(item) )
return false;
return true;
}
bool Upload::HasAccess()
{
if( cur->request->is_item || !HasAccess(*cur->request->dir_tab.back()) )
return false;
return true;
}
bool Upload::UploadSaveStaticFile(const Item & item, const std::wstring & tmp_filename)
{
if( !system->MakeFilePath(item, path, false, true, config->upload_dirs_chmod, config->upload_group_int) )
{
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
return false;
}
if( RenameFile(tmp_filename, path) )
{
if( !SetPriv(path, config->upload_files_chmod, config->upload_group_int) )
{
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
return false;
}
log << log2 << "Upload: uploaded a new file: " << path << logend;
return true;
}
else
{
log << log1 << "Upload: can't move the tmp file from: " << tmp_filename << ", to: " << path << logend;
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
return false;
}
}
void Upload::ResizeImage(Item & item)
{
Image::Scale scale = system->image.GetImageScale(item.parent_id);
system->image.Resize(item.id, scale.cx, scale.cy, scale.aspect_mode, scale.quality);
}
void Upload::CreateThumb(Item & item)
{
Image::Scale scale = system->image.GetThumbScale(item.parent_id);
system->image.CreateThumb(item.id, scale.cx, scale.cy, scale.aspect_mode, scale.quality);
}
void Upload::UploadFile(Item & item, const std::wstring & tmp_filename)
{
// we should add the file beforehand to get the proper item.id
cur->request->status = system->AddFile(item, 0, false);
if( cur->request->status == WINIX_ERR_OK )
{
if( system->CreateNewFile(item) )
{
if( UploadSaveStaticFile(item, tmp_filename) )
{
cur->request->status = db->EditFileById(item, item.id);
plugin.Call(WINIX_FILE_ADDED, &item);
if( item.file_type == WINIX_ITEM_FILETYPE_IMAGE )
{
if( config->image_resize )
ResizeImage(item);
if( config->create_thumb )
CreateThumb(item);
}
if( is_jquery_upload )
cur->request->item_tab.push_back(item);
}
else
{
db->DelItem(item);
}
}
}
}
bool Upload::FunUploadCheckAbuse()
{
if( !system->rebus.CheckRebus() )
{
cur->request->status = WINIX_ERR_INCORRECT_REBUS;
return false;
}
functions->CheckGetPostTimes(4);
if( cur->session->spam_score > 0 )
{
cur->request->status = WINIX_ERR_SPAM;
log << log1 << "Content: ignoring due to suspected spamming" << logend;
return false;
}
return true;
}
void Upload::UploadMulti()
{
cur->request->item.Clear(); // clearing and setting date
cur->request->item.parent_id = cur->request->dir_tab.back()->id;
cur->request->item.type = Item::file;
cur->request->item.privileges = system->NewFilePrivileges();
functions->SetUser(cur->request->item);
PostFileTab::iterator i = cur->request->post_file_tab.begin();
for( ; i != cur->request->post_file_tab.end() ; ++i)
{
const wchar_t * file_name = i->second.filename.c_str();
cur->request->item.subject = file_name;
cur->request->item.url = file_name;
cur->request->item.file_type = SelectFileType(file_name);
cur->request->item.file_size = i->second.file_size;
functions->PrepareUrl(cur->request->item);
UploadFile(cur->request->item, i->second.tmp_filename);
i->second.tmp_filename.clear();
}
if( is_jquery_upload )
CreateAnswer();
else
system->RedirectToLastDir();
}
void Upload::UploadSingle()
{
const std::wstring & new_subject = cur->request->PostVar(L"subject");
const std::wstring & new_url = cur->request->PostVar(L"url");
bool has_subject = !new_subject.empty();
bool has_url = !new_url.empty();
functions->ReadItem(cur->request->item, Item::file); // ReadItem() changes the url if it is empty
functions->SetUser(cur->request->item);
cur->request->item.privileges = system->NewFilePrivileges();
PostFile & post_file = cur->request->post_file_tab.begin()->second;
const wchar_t * file_name = post_file.filename.c_str();
cur->request->item.file_type = SelectFileType(file_name);
cur->request->item.file_size = post_file.file_size;
if( !has_subject )
cur->request->item.subject = file_name;
if( !has_url )
{
cur->request->item.url = file_name;
functions->PrepareUrl(cur->request->item);
}
UploadFile(cur->request->item, post_file.tmp_filename);
post_file.tmp_filename.clear();
if( is_jquery_upload )
CreateAnswer();
else
if( cur->request->status == WINIX_ERR_OK )
system->RedirectTo(cur->request->item, L"/cat");
}
void Upload::MakePost()
{
cur->request->item_tab.clear();
is_jquery_upload = cur->request->IsParam(L"jquery_upload");
if( cur->request->post_file_tab.empty() )
{
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
return;
}
if( !FunUploadCheckAbuse() )
return;
if( cur->request->post_file_tab.size() > 1 )
UploadMulti();
else
UploadSingle();
}
void Upload::CreateAnswer()
{
Request & req = *cur->request;
PT::Space & files = req.info.AddSpace(L"files"); // 'files' will be serialized to an array
for(size_t i=0 ; i<req.item_tab.size() ; ++i)
{
PT::Space & file = files.AddSpace(L"");
file.Add(L"name", req.item_tab[i].url);
file.Add(L"size", req.item_tab[i].file_size);
std::wstring & link = file.Add(L"url", L"");
system->CreateItemLink(req.item_tab[i], link);
std::wstring & del_url = file.Add(L"deleteUrl", link);
del_url += L"/rm/jquery_upload";
file.Add(L"deleteType", L"POST");
if( req.item_tab[i].file_type == WINIX_ITEM_FILETYPE_IMAGE )
{
std::wstring & thumb = file.Add(L"thumbnailUrl", link);
if( req.item_tab[i].has_thumb )
thumb += L"/-/thumb";
}
/*
* if there was an error add "error" item e.g.
* "error": "Filetype not allowed"
*/
}
cur->request->return_json = true;
cur->request->return_info_only = true;
cur->request->info_serializer = &json_serializer;
//cur->request->out_headers.Add(L"Content-Type", L"text/html");
}
void Upload::MakeGet()
{
if( cur->request->IsParam(L"jquery_upload") )
{
query.Clear();
query.WhereParentId(cur->request->dir_tab.back()->id);
query.WhereType(Item::file);
query.WhereFileType(WINIX_ITEM_FILETYPE_NONE, false);
db->GetItems(cur->request->item_tab, query);
CreateAnswer();
}
}
} // namespace
} // namespace Winix

87
winixd/functions/upload.h Normal file
View File

@@ -0,0 +1,87 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2010-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_winix_functions_upload
#define headerfile_winix_functions_upload
#include "functionbase.h"
#include "space/spacetojson.h"
namespace Winix
{
namespace Fun
{
class Upload : public FunctionBase
{
public:
Upload();
bool HasAccess();
void MakePost();
void MakeGet();
void UploadFile(Item & item, const std::wstring & tmp_filename);
private:
std::wstring path;
DbItemQuery query;
bool is_jquery_upload;
// this object is used in App at the end of a request
// for serializing Request::info to JSON
// this will make a problem if in the future we'll use multithread requests
PT::SpaceToJSON json_serializer;
void Init();
bool HasAccess(const Item & item);
bool UploadSaveStaticFile(const Item & item, const std::wstring & tmp_filename);
bool FunUploadCheckAbuse();
void UploadMulti();
void UploadSingle();
void ResizeImage(Item & item);
void CreateThumb(Item & item);
void CreateAnswer();
};
} // namespace
} // namespace Winix
#endif

View File

@@ -0,0 +1,57 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2008-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "uptime.h"
namespace Winix
{
namespace Fun
{
Uptime::Uptime()
{
fun.url = L"uptime";
}
} // namespace
} // namespace Winix

63
winixd/functions/uptime.h Normal file
View File

@@ -0,0 +1,63 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2010-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_winix_functions_uptime
#define headerfile_winix_functions_uptime
#include "functionbase.h"
namespace Winix
{
namespace Fun
{
class Uptime : public FunctionBase
{
public:
Uptime();
private:
};
} // namespace
} // namespace Winix
#endif

81
winixd/functions/vim.cpp Normal file
View File

@@ -0,0 +1,81 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2010-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "vim.h"
#include "functions.h"
namespace Winix
{
namespace Fun
{
Vim::Vim()
{
fun.url = L"vim";
}
void Vim::Init()
{
// WYMeditor doesn't work on different domains by default,
// solution: http://forum.wymeditor.org/forum/viewtopic.php?f=2&t=731&p=2507#p2504
// we add one file to winix: /var/wymiframe.html
system->AddCommonFileToVar(L"winix/wymiframe.html", L"wymiframe.html");
}
bool Vim::HasAccess()
{
return functions->fun_emacs.HasAccess();
}
void Vim::MakePost()
{
functions->fun_emacs.MakePost();
}
} // namespace
} // namespace Winix

64
winixd/functions/vim.h Normal file
View File

@@ -0,0 +1,64 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2010-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_winix_functions_vim
#define headerfile_winix_functions_vim
#include "functionbase.h"
namespace Winix
{
namespace Fun
{
class Vim : public FunctionBase
{
public:
Vim();
void Init();
bool HasAccess();
void MakePost();
};
} // namespace
} // namespace Winix
#endif

63
winixd/functions/who.cpp Normal file
View File

@@ -0,0 +1,63 @@
/*
* This file is a part of Winix
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2008-2014, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "who.h"
namespace Winix
{
namespace Fun
{
Who::Who()
{
fun.url = L"who";
}
bool Who::HasAccess()
{
return cur->session->puser != 0;
}
} // namespace
} // namespace Winix

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