Commit 148bd95e authored by Julian Bigge's avatar Julian Bigge

Merge branch 'develop' into 'master'

Version 0.3.2

See merge request !10
parents 5b82d2f6 cf3027a8
Pipeline #36945 passed with stage
in 4 minutes and 33 seconds
# This file is a template, and might need editing before it works on your project.
# This fiis a template, and might need editing before it works on your project.
# Official docker image.
image: centos:7.6.1810
variables:
GIT_SUBMODULE_STRATEGY: recursive
services:
- docker:dind
before_script:
.setup_centos: &setup
before_script:
- yum -y install epel-release # for newer cmake
- yum -y install gcc-c++ cmake3 make mariadb-devel boost-devel boost-program-options libcurl-devel rpm-build rpmdevtools
stages:
- build
- rpm
variables:
GIT_SUBMODULE_STRATEGY: recursive
build:
build_binary:
stage: build
<<: *setup
script:
- mkdir build && cd build
- cmake3 ..
- make
rpm:
build_rpm:
only:
- tags
stage: rpm
stage: build
<<: *setup
script:
- mkdir build && cd build
- cmake3 ..
......@@ -38,4 +33,23 @@ rpm:
paths:
- build/sccuot-$CI_COMMIT_TAG*.rpm
sast:
image: docker:stable
variables:
DOCKER_DRIVER: overlay2
allow_failure: true
services:
- docker:stable-dind
script:
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
- docker run
--env SAST_CONFIDENCE_LEVEL="${SAST_CONFIDENCE_LEVEL:-3}"
--volume "$PWD:/code"
--volume /var/run/docker.sock:/var/run/docker.sock
"registry.gitlab.com/gitlab-org/security-products/sast:$SP_VERSION" /app/bin/run /code
only:
- develop
artifacts:
reports:
sast: gl-sast-report.json
......@@ -4,11 +4,11 @@ project (sccuot)
set (sccuot_LIB_VERSION_MAJOR 0)
set (sccuot_LIB_VERSION_MINOR 3)
set (sccuot_LIB_VERSION_PATCH 1)
set (sccuot_LIB_VERSION_PATCH 2)
set (sccuot_VERSION_MAJOR 0)
set (sccuot_VERSION_MINOR 3)
set (sccuot_VERSION_PATCH 1)
set (sccuot_VERSION_PATCH 2)
include(GNUInstallDirs)
find_package (Boost COMPONENTS program_options REQUIRED)
......@@ -77,7 +77,7 @@ if (STATIC_LIB)
target_link_libraries (sccuot_client sccuot_static)
install (TARGETS sccuot_static ARCHIVE DESTINATION lib)
else ()
add_library (sccuot SHARED ${LIBSCCUOT_SOURCES})
add_library (sccuot SHARED ${LIBSCCUOT_SOURCES} include/libsccuot/db/tables/oc_mounts.hpp include/libsccuot/db/tables/oc_appconfig.hpp)
target_link_libraries (sccuot ${Boost_LIBRARIES})
target_link_libraries (sccuot_client sccuot)
install (TARGETS sccuot LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
......
......@@ -141,7 +141,7 @@ which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
such as by intimate rows communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
......
......@@ -6,23 +6,29 @@
#include <libsccuot/db/query_base.hpp>
#include "detail/dataframe_row.hpp"
namespace sccuot {
template <typename T>
class Dataframe {
public:
using data_type = std::vector<std::vector<T>>;
using iterator = typename data_type::iterator;
using const_iterator = typename data_type::const_iterator;
using reverse_iterator = typename data_type::reverse_iterator;
using const_reverse_iterator = typename data_type::const_reverse_iterator;
using data_type = detail::Row<T>;
using collection_type = std::vector<data_type>;
using iterator = typename collection_type::iterator;
using const_iterator = typename collection_type::const_iterator;
using reverse_iterator = typename collection_type::reverse_iterator;
using const_reverse_iterator = typename collection_type::const_reverse_iterator;
Dataframe() = default;
Dataframe(const Dataframe&) = default;
Dataframe& operator=(const Dataframe&) = default;
Dataframe(data_type&& data);
explicit Dataframe(collection_type&& data);
const data_type& data() const;
data_type& data();
const collection_type& rows() const;
collection_type& rows();
std::size_t size() const;
std::size_t size_x() const;
......@@ -37,11 +43,14 @@ namespace sccuot {
std::pair<std::size_t, std::size_t> dims() const;
std::vector<T>& operator[](std::size_t pos);
const std::vector<T>& operator[](std::size_t pos) const;
data_type& operator[](std::size_t pos);
const data_type& operator[](std::size_t pos) const;
data_type& operator[](const std::string& row);
const data_type& operator[](const std::string& row) const;
void add_row(const std::vector<T>& row);
void add_row(std::vector<T>&& row);
void add_row(const std::vector<T>& row, const std::string& label = {});
void add_row(std::vector<T>&& row, const std::string& label = {});
void sort_x();
void sort_y();
......@@ -61,8 +70,7 @@ namespace sccuot {
const_reverse_iterator crend() const;
private:
data_type _data;
std::size_t _size;
collection_type _data;
};
} /* namespace sccuot */
......@@ -7,16 +7,28 @@ namespace sccuot {
class Query_base;
struct Config {
std::string hostname;
std::string user;
std::string passwd;
std::string db;
};
class Connection {
public:
friend class Storage;
using connection_type = sqlpp::mysql::connection;
Connection(const std::string& hostname, const std::string& user,
const std::string& passwd, const std::string& db);
Connection(const Config& config);
Connection& operator<<(Query_base& query);
private:
connection_type& connection();
std::unique_ptr<connection_type> _connection;
};
} /* namespace db */
......
......@@ -9,147 +9,6 @@
namespace sccuot {
namespace db {
enum class Queries {
count_active_users,
count_ext_shares,
count_file_type,
count_files,
count_links,
count_shared_dirs,
count_shared_files,
count_shares,
count_users,
quota_users,
used_space,
used_space_users,
_END
};
template<Queries Q>
struct Query_type;
template<>
struct Query_type<Queries::count_active_users> {
using type = impl::Count_active_users;
};
template<>
struct Query_type<Queries::count_ext_shares> {
using type = impl::Count_ext_shares;
};
template<>
struct Query_type<Queries::count_file_type> {
using type = impl::Count_file_type;
};
template<>
struct Query_type<Queries::count_files> {
using type = impl::Count_files;
};
template<>
struct Query_type<Queries::count_links> {
using type = impl::Count_links;
};
template<>
struct Query_type<Queries::count_shared_dirs> {
using type = impl::Count_shared_dirs;
};
template<>
struct Query_type<Queries::count_shared_files> {
using type = impl::Count_shared_files;
};
template<>
struct Query_type<Queries::count_shares> {
using type = impl::Count_shares;
};
template<>
struct Query_type<Queries::count_users> {
using type = impl::Count_shares;
};
template<>
struct Query_type<Queries::quota_users> {
using type = impl::Quota_users;
};
template<>
struct Query_type<Queries::used_space> {
using type = impl::Used_space;
};
template<>
struct Query_type<Queries::used_space_users> {
using type = impl::Used_space_users;
};
Queries str_to_query_type(const std::string& name) {
if (name == "used_space") {
return Queries::used_space;
} else if (name == "used_space_user") {
return Queries::used_space_users;
} else if (name == "count_files") {
return Queries::count_files;
} else if (name.find("count_file_type") != std::string::npos) {
return Queries::count_file_type;
} else if (name == "count_users") {
return Queries::count_users;
} else if (name == "count_shares") {
return Queries::count_shares;
} else if (name == "count_ext_shares") {
return Queries::count_ext_shares;
} else if (name == "count_links") {
return Queries::count_links;
} else if (name == "count_shared_files") {
return Queries::count_shared_files;
} else if (name == "count_shared_dirs") {
return Queries::count_shared_dirs;
} else if (name == "quota_users") {
return Queries::quota_users;
} else if (name.find("count_active_users") != std::string::npos) {
return Queries::count_active_users;
} else {
throw std::invalid_argument {"Unknown template name: " + name};
}
}
std::unique_ptr<Query<float>> query(Queries q, typename Query_base::arglist&& args = {})
{
switch (q) {
case Queries::count_active_users:
return std::unique_ptr<Query<float>> {new Query_type<Queries::count_active_users>::type {std::move(args)}};
case Queries::count_ext_shares:
return std::unique_ptr<Query<float>> {new Query_type<Queries::count_ext_shares>::type {}};
case Queries::count_file_type:
return std::unique_ptr<Query<float>> {new Query_type<Queries::count_file_type>::type {std::move(args)}};
case Queries::count_files:
return std::unique_ptr<Query<float>> {new Query_type<Queries::count_files>::type {}};
case Queries::count_links:
return std::unique_ptr<Query<float>> {new Query_type<Queries::count_links>::type {}};
case Queries::count_shared_dirs:
return std::unique_ptr<Query<float>> {new Query_type<Queries::count_shared_dirs>::type {}};
case Queries::count_shared_files:
return std::unique_ptr<Query<float>> {new Query_type<Queries::count_shared_files>::type {}};
case Queries::count_shares:
return std::unique_ptr<Query<float>> {new Query_type<Queries::count_shares>::type {}};
case Queries::count_users:
return std::unique_ptr<Query<float>> {new Query_type<Queries::count_users>::type {}};
case Queries::quota_users:
return std::unique_ptr<Query<float>> {new Query_type<Queries::quota_users>::type {}};
case Queries::used_space:
return std::unique_ptr<Query<float>> {new Query_type<Queries::used_space>::type {}};
case Queries::used_space_users:
return std::unique_ptr<Query<float>> {new Query_type<Queries::used_space_users>::type {}};
default:
throw std::invalid_argument {"No such query"};
}
}
Dataframe<float> execute(Connection& connection, Queries q, typename Query_base::arglist&& args = {})
{
......
......@@ -7,6 +7,7 @@
#include <sqlpp11/parameter.h>
#include <sqlpp11/verbatim.h>
#include "../queries.hpp"
#include "../tables/tables.hpp"
namespace sccuot {
......@@ -15,6 +16,8 @@ namespace sccuot {
class Count_active_users : public Query<float> {
public:
static constexpr bool is_convertible = false;
static constexpr Queries query_type = Queries::count_active_users;
using base = Query<float>;
using value_type = float;
using typename base::arglist;
......@@ -24,10 +27,15 @@ namespace sccuot {
{
}
Queries type() const override
{
return query_type;
};
protected:
void execute(Connection::connection_type& connection) override
{
static constexpr auto t = tables::Oc_accounts{};
static constexpr auto t = tables::oc_accounts::oc_accounts{};
_result.reset(new Dataframe<float> {});
for (const auto& arg : _args) {
......@@ -38,8 +46,10 @@ namespace sccuot {
sqlpp::verbatim<sqlpp::boolean>("DATE_SUB(CURDATE(), INTERVAL " + opts.at(arg)
+ " DAY) <= from_unixtime(last_login)")
));
_result->add_row({static_cast<float>(result.front().count)});
_result->add_row({static_cast<float>(result.front().count)}, arg);
}
base::execute(connection);
}
private:
const std::map<std::string, std::string> opts = {
......
......@@ -4,6 +4,7 @@
#include <sqlpp11/mysql/mysql.h>
#include <libsccuot/db/query.hpp>
#include "../queries.hpp"
#include "../tables/tables.hpp"
namespace sccuot {
......@@ -12,18 +13,28 @@ namespace sccuot {
class Count_ext_shares : public Query<float> {
public:
static constexpr bool is_convertible = false;
static constexpr Queries query_type = Queries::count_ext_shares;
using base = Query<float>;
using value_type = float;
Count_ext_shares() = default;
Queries type() const override
{
return query_type;
}
protected:
void execute(Connection::connection_type& connection) override
{
static constexpr auto t = tables::Oc_share_external {};
static constexpr auto t = tables::oc_share_external::oc_share_external {};
_result.reset(new Dataframe<value_type> {});
for (const auto& row : connection.run(sqlpp::select(sqlpp::count(t.id)).from(t).unconditionally())) {
_result->add_row({static_cast<float>(row.count)});
}
base::execute(connection);
}
};
......
......@@ -3,12 +3,17 @@
#include <memory>
#include <libsccuot/db/query.hpp>
#include "../queries.hpp"
#include "../tables/tables.hpp"
namespace sccuot {
namespace db {
namespace impl {
class Count_file_type : public Query<float> {
public:
static constexpr bool is_convertible = false;
static constexpr Queries query_type = Queries::count_file_type;
using base = Query<float>;
using value_type = float;
using typename base::arglist;
......@@ -17,10 +22,16 @@ namespace sccuot {
: base(std::move(args))
{
}
Queries type() const override
{
return query_type;
}
protected:
void execute(Connection::connection_type& connection) override
{
static constexpr auto t = tables::Oc_filecache{};
static constexpr auto t = tables::oc_filecache::oc_filecache{};
_result.reset(new Dataframe<float> {});
auto prep_stmt = connection.prepare(
......@@ -32,9 +43,10 @@ namespace sccuot {
for (const auto& arg : _args) {
prep_stmt.params.name = std::string {"%"} + arg;
auto result = connection.run(prep_stmt);
_result->add_row({static_cast<float>(result.front().count)});
_result->add_row({static_cast<float>(result.front().count)}, arg);
}
base::execute(connection);
}
};
......
......@@ -2,6 +2,7 @@
#include <libsccuot/db/query.hpp>
#include "../queries.hpp"
#include "../tables/tables.hpp"
namespace sccuot {
......@@ -10,17 +11,28 @@ namespace sccuot {
class Count_files : public Query<float> {
public:
static constexpr bool is_convertible = false;
static constexpr Queries query_type = Queries::count_files;
using base = Query<float>;
using value_type = float;
Count_files() = default;
Queries type() const override
{
return query_type;
}
protected:
void execute(Connection::connection_type& connection) override
{
static constexpr auto t = tables::Oc_filecache{};
static constexpr auto t = tables::oc_filecache::oc_filecache{};
_result.reset(new Dataframe<value_type>{});
for (const auto& row : connection.run(sqlpp::select(sqlpp::count(t.fileid)).from(t).unconditionally())) {
_result->add_row({static_cast<float>(row.count)});
}
base::execute(connection);
}
};
......
......@@ -2,6 +2,7 @@
#include <libsccuot/db/query.hpp>
#include "../queries.hpp"
#include "../tables/tables.hpp"
namespace sccuot {
......@@ -10,17 +11,28 @@ namespace sccuot {
class Count_links : public Query<float> {
public:
static constexpr bool is_convertible = false;
static constexpr Queries query_type = Queries::count_links;
using base = Query<float>;
using value_type = float;
Count_links() = default;
Queries type() const override
{
return query_type;
}
protected:
void execute(Connection::connection_type& connection) override
{
static constexpr auto t = tables::Oc_share{};
static constexpr auto t = tables::oc_share::oc_share{};
_result.reset(new Dataframe<value_type> {});
for (const auto& row : connection.run(sqlpp::select(sqlpp::count(t.id)).from(t).where(t.share_with.is_null()))) {
_result->add_row({static_cast<float>(row.count)});
}
base::execute(connection);
}
};
......
......@@ -2,6 +2,7 @@
#include <libsccuot/db/query.hpp>
#include "../queries.hpp"
#include "../tables/tables.hpp"
namespace sccuot {
......@@ -10,18 +11,28 @@ namespace sccuot {
class Count_shared_dirs : public Query<float> {
public:
static constexpr bool is_convertible = false;
static constexpr Queries query_type = Queries::count_shared_dirs;
using base = Query<float>;
using value_type = float;
Count_shared_dirs() = default;
Queries type() const override
{
return query_type;
}
protected:
void execute(Connection::connection_type& connection) override
{
static constexpr auto t = tables::Oc_share{};
static constexpr auto t = tables::oc_share::oc_share{};
_result.reset(new Dataframe<value_type> {});
for (const auto& row : connection.run(sqlpp::select(sqlpp::count(t.id)).from(t).where(t.item_type.like("folder")))) {
_result->add_row({static_cast<float>(row.count)});
}
base::execute(connection);
}
};
......
......@@ -2,6 +2,7 @@
#include <libsccuot/db/query.hpp>
#include "../queries.hpp"
#include "../tables/tables.hpp"
namespace sccuot {
......@@ -10,17 +11,29 @@ namespace sccuot {
class Count_shared_files : public Query<float> {
public:
static constexpr bool is_convertible = false;
static constexpr Queries query_type = Queries::count_shared_files;
using base = Query<float>;
using value_type = float;
Count_shared_files() = default;
Queries type() const override
{
return query_type;
}
protected:
void execute(Connection::connection_type& connection) override
{
static constexpr auto t = tables::Oc_share{};
static constexpr auto t = tables::oc_share::oc_share{};
_result.reset(new Dataframe<value_type> {});
for (const auto& row : connection.run(sqlpp::select(sqlpp::count(t.id)).from(t).where(t.item_type.like("file")))) {