Skip to content

Commit

Permalink
Upgrading from wt3 to wt4
Browse files Browse the repository at this point in the history
  • Loading branch information
epoupon committed Sep 21, 2018
1 parent 14b5eec commit 4e253ea
Show file tree
Hide file tree
Showing 32 changed files with 387 additions and 461 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Expand Up @@ -14,8 +14,8 @@ before_install:
- popd
- git clone https://github.com/emweb/wt.git wt
- pushd wt;
- git checkout 3.3.4
- cmake -DWT_CPP_11_MODE=-std=c++11 -DCMAKE_INSTALL_PREFIX=/usr && sudo make install
- git checkout 4.0.4
- cmake -DCMAKE_INSTALL_PREFIX=/usr && sudo make install
- popd
script: autoreconf -vfi && ./configure && make
env:
Expand Down
17 changes: 0 additions & 17 deletions Makefile.am
Expand Up @@ -22,20 +22,3 @@ dist_fileshelter_approot_DATA = \
dist_sysconf_DATA = \
$(top_srcdir)/conf/fileshelter.conf

install-data-hook:
cd $(DESTDIR)$(fileshelter_docrootdir); \
rm -f resources; \
if ! [ -z "$(WT_RESOURCES_DIR)" ]; then \
$(LN_S) "$(WT_RESOURCES_DIR)" resources; \
else \
for wt_dir in "/usr/local/share/Wt/resources" "/usr/share/Wt/resources"; do \
if [ -d $$wt_dir ]; then \
$(LN_S) $$wt_dir resources; \
break; \
fi \
done \
fi

uninstall-local:
rm -f $(DESTDIR)$(fileshelter_docrootdir)/resources

27 changes: 3 additions & 24 deletions README.md
Expand Up @@ -28,29 +28,14 @@ A [docker image](https://github.com/paulgalow/fileshelter-docker) is available,
Once the expiry date or the download limit is reached, the download is no longer available and the file is deleted.

## Installation
### From packages
Check the [release](https://github.com/epoupon/fileshelter/releases) page to get the latest package for your distribution.

### From Source
#### Debian/Ubuntu dependencies
```sh
apt-get install build-essential autoconf automake libboost-dev libwtdbosqlite-dev libwthttp-dev libwtdbo-dev libwt-dev libconfig++-dev libzip-dev
```
#### CentOS 7 dependencies
You need to install [wt](https://www.webtoolkit.eu/wt/doc/reference/html/InstallationUnix.html) from source:
```sh
yum groupinstall 'Development Tools'
yum install boost-devel
git clone https://github.com/emweb/wt.git wt
cd wt; mkdir build
cmake ../ -DWT_CPP_11_MODE=-std=c++11 -DCMAKE_INSTALL_PREFIX=/usr
make install
```
Once this is done, you can install fileshelter's extra dependencies:
```sh
yum install libconfig-devel
apt-get install build-essential autoconf automake libboost-dev libconfig++-dev libzip-dev
```

You also need wt4, that is not packaged yet on Debian. See [installation instructions](https://www.webtoolkit.eu/wt/doc/reference/html/InstallationUnix.html).

#### Build
```sh
git clone https://github.com/epoupon/fileshelter.git fileshelter
Expand All @@ -62,11 +47,6 @@ cd build
```
configure will complain if a mandatory library is missing.

FileShelter tries to create a link to the Wt's resources directory. By default, "/usr/local/share/Wt/resources" and "/usr/share/Wt/resources" are searched, but you can provide a custom location by using the WT_RESOURCES_DIR variable:
```sh
../configure --prefix=/usr --sysconfdir=/etc WT_RESOURCES_DIR=/path/to/Wt/resources
```

```sh
make
```
Expand All @@ -77,7 +57,6 @@ make install
This last command requires root privileges.



## Configuration
FileShelter uses a configuration file, installed in '/etc/fileshelter.conf'.
It is recommended to edit this file and change the relevant settings (working directory, maximum file size, maximum validity duration, listen port, etc.)
Expand Down
8 changes: 4 additions & 4 deletions approot/templates.xml
Expand Up @@ -109,7 +109,7 @@
</details>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
${create-btn}
${create-btn class="btn-primary"}
</div>
</div>
</div>
Expand All @@ -134,7 +134,7 @@
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-5">
${unlock-btn}
${unlock-btn class="btn-primary"}
</div>
</div>
</div>
Expand Down Expand Up @@ -223,7 +223,7 @@
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-5">
${download-btn}
${download-btn class="btn btn-primary"}
</div>
</div>
</div>
Expand Down Expand Up @@ -284,7 +284,7 @@
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-5">
${delete-btn}
${delete-btn class="btn-danger"}
</div>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions conf/fileshelter.conf
Expand Up @@ -51,6 +51,7 @@ deploy-path = "/"
# Path to the resources used by the web interface
docroot = "/usr/share/fileshelter/docroot/;/resources,/css,/images,/favicon.ico";
approot = "/usr/share/fileshelter/approot";
wt-resources = "/usr/share/Wt/resources";

# Bcrypt count parameter used to hash passwords
bcrypt-count = 12;
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile.am
Expand Up @@ -37,6 +37,6 @@ fileshelter_SOURCES = \


# BOOST_NO_CXX11_SCOPED_ENUMS prevents a link error with outdated boost filesystem lib
fileshelter_CXXFLAGS=-std=c++11 -Wall -I$(srcdir)/ui -DBOOST_NO_CXX11_SCOPED_ENUMS $(libzip_CFLAGS)
fileshelter_CXXFLAGS=-std=c++14 -Wall -I$(srcdir)/ui -DBOOST_NO_CXX11_SCOPED_ENUMS $(libzip_CFLAGS)
fileshelter_LDADD=$(libzip_LIBS)

26 changes: 11 additions & 15 deletions src/database/DbCleaner.cpp
Expand Up @@ -17,11 +17,13 @@
* along with fileshelter. If not, see <http://www.gnu.org/licenses/>.
*/

#include <boost/asio/placeholders.hpp>
#include "DbCleaner.hpp"

#include <Wt/WLocalDateTime.h>

#include "utils/Logger.hpp"

#include "Share.hpp"
#include "DbCleaner.hpp"

namespace Database {

Expand All @@ -43,21 +45,16 @@ void
Cleaner::start(void)
{
// Schedule an immediate cleanup
schedule(boost::posix_time::seconds(0));
schedule(std::chrono::seconds(0));

_ioService.start();
}

void
Cleaner::schedule(boost::posix_time::time_duration duration)
Cleaner::schedule(std::chrono::seconds seconds)
{
auto now = boost::posix_time::second_clock::universal_time();
auto nextScanTime = now + duration;

_scheduleTimer.expires_at(nextScanTime);
_scheduleTimer.async_wait( boost::bind( &Cleaner::process, this, boost::asio::placeholders::error));

FS_LOG(DB, INFO) << "Scheduled next scan at UTC " << nextScanTime;
_scheduleTimer.expires_from_now(seconds);
_scheduleTimer.async_wait(std::bind(&Cleaner::process, this, std::placeholders::_1));
}

void
Expand All @@ -74,7 +71,7 @@ Cleaner::process(boost::system::error_code err)
if (err)
return;

auto now = boost::posix_time::second_clock::universal_time();
auto now = Wt::WLocalDateTime::currentServerDateTime().toUTC();

FS_LOG(DB, INFO) << "Cleaning expired shares...";
Wt::Dbo::Transaction transaction(_db.getSession());
Expand All @@ -85,8 +82,7 @@ Cleaner::process(boost::system::error_code err)
{
// In order not to delete a share that is being downloaded,
// really remove the share at least a day after it has expired
if (share->hasExpired()
&& now > share->getExpiryTime() + boost::posix_time::hours(24))
if (share->hasExpired() && now > share->getExpiryTime().addDays(1))
{
FS_LOG(DB, INFO) << "[" << share->getDownloadUUID() << "] Deleting expired share";

Expand All @@ -97,7 +93,7 @@ Cleaner::process(boost::system::error_code err)

FS_LOG(DB, INFO) << "Cleaning expired shares: complete!";

schedule(boost::posix_time::hours(6));
schedule(std::chrono::hours(6));
}


Expand Down
10 changes: 6 additions & 4 deletions src/database/DbCleaner.hpp
Expand Up @@ -19,9 +19,11 @@

#pragma once

#include <Wt/WIOService>
#include <chrono>

#include <boost/asio/deadline_timer.hpp>
#include <boost/asio/system_timer.hpp>

#include <Wt/WIOService.h>

#include "DbHandler.hpp"

Expand All @@ -37,11 +39,11 @@ class Cleaner

private:

void schedule(boost::posix_time::time_duration duration);
void schedule(std::chrono::seconds duration);
void process(boost::system::error_code ec);

Wt::WIOService _ioService;
boost::asio::deadline_timer _scheduleTimer;
boost::asio::system_timer _scheduleTimer;
Database::Handler _db;
};

Expand Down
17 changes: 8 additions & 9 deletions src/database/DbHandler.cpp
Expand Up @@ -17,12 +17,12 @@
* along with fileshelter. If not, see <http://www.gnu.org/licenses/>.
*/

#include <Wt/Dbo/FixedSqlConnectionPool>
#include <Wt/Dbo/backend/Sqlite3>
#include "DbHandler.hpp"

#include "utils/Logger.hpp"
#include <Wt/Dbo/FixedSqlConnectionPool.h>
#include <Wt/Dbo/backend/Sqlite3.h>

#include "DbHandler.hpp"
#include "utils/Logger.hpp"

#include "Share.hpp"

Expand Down Expand Up @@ -56,15 +56,14 @@ Handler::Handler(Wt::Dbo::SqlConnectionPool& connectionPool)
}
}

Wt::Dbo::SqlConnectionPool*
std::unique_ptr<Wt::Dbo::SqlConnectionPool>
Handler::createConnectionPool(boost::filesystem::path p)
{
FS_LOG(DB, INFO) << "Creating connection pool on file " << p;
FS_LOG(DB, INFO) << "Creating connection pool on file " << p.string();

Wt::Dbo::backend::Sqlite3 *connection = new Wt::Dbo::backend::Sqlite3(p.string());
auto connection = std::make_unique<Wt::Dbo::backend::Sqlite3>(p.string());

// connection->setProperty("show-queries", "true");
return new Wt::Dbo::FixedSqlConnectionPool(connection, 1);
return std::make_unique<Wt::Dbo::FixedSqlConnectionPool>(std::move(connection), 1);
}

} // namespace Database
Expand Down
6 changes: 3 additions & 3 deletions src/database/DbHandler.hpp
Expand Up @@ -21,8 +21,8 @@

#include <boost/filesystem.hpp>

#include <Wt/Dbo/Dbo>
#include <Wt/Dbo/SqlConnectionPool>
#include <Wt/Dbo/Dbo.h>
#include <Wt/Dbo/SqlConnectionPool.h>

namespace Database {

Expand All @@ -34,7 +34,7 @@ class Handler

Wt::Dbo::Session& getSession() { return _session; }

static Wt::Dbo::SqlConnectionPool* createConnectionPool(boost::filesystem::path db);
static std::unique_ptr<Wt::Dbo::SqlConnectionPool> createConnectionPool(boost::filesystem::path db);

private:

Expand Down

0 comments on commit 4e253ea

Please sign in to comment.