Compare commits
22 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
7ef2432796 | ||
|
2055cf574c | ||
|
772c9d607c | ||
|
0e520fe937 | ||
|
bded0b69b2 | ||
|
a181ad89d0 | ||
|
b0f4250c60 | ||
|
a88d8b0c55 | ||
|
927f5489c6 | ||
|
e482c3706c | ||
|
b6863ac2e7 | ||
|
97289fec3f | ||
|
af1a093fe4 | ||
|
be277cd1e1 | ||
|
94cc5f40d8 | ||
|
b66026c7e0 | ||
|
e603b7319b | ||
|
cba08636c6 | ||
|
46f32badc6 | ||
|
fc0ae6fb40 | ||
|
b0d1f1f176 | ||
|
b2a673f887 |
4
.gitignore
vendored
4
.gitignore
vendored
@ -11,6 +11,7 @@
|
|||||||
*.sln.docstates
|
*.sln.docstates
|
||||||
|
|
||||||
# Tubio files
|
# Tubio files
|
||||||
|
/Tubio/Tubio
|
||||||
config.json
|
config.json
|
||||||
log.txt
|
log.txt
|
||||||
log.json
|
log.json
|
||||||
@ -28,6 +29,7 @@ ffprobe.exe
|
|||||||
mono_crash.*
|
mono_crash.*
|
||||||
|
|
||||||
# Build results
|
# Build results
|
||||||
|
build/
|
||||||
[Dd]ebug/
|
[Dd]ebug/
|
||||||
[Dd]ebugPublic/
|
[Dd]ebugPublic/
|
||||||
[Rr]elease/
|
[Rr]elease/
|
||||||
@ -371,4 +373,4 @@ MigrationBackup/
|
|||||||
.ionide/
|
.ionide/
|
||||||
|
|
||||||
# Fody - auto-generated XML schema
|
# Fody - auto-generated XML schema
|
||||||
FodyWeavers.xsd
|
FodyWeavers.xsd
|
||||||
|
278
README.md
278
README.md
@ -1,139 +1,139 @@
|
|||||||

|

|
||||||
|
|
||||||
# Tubio
|
# Tubio
|
||||||
The free, open source video downloader!
|
The free, open source video downloader!
|
||||||
|
|
||||||
No longer do you have to rely on shady websites, shoving tons of ads in your face to fulfil your downloady needs. No longer will you be held back by artificially crippled download speeds, login-/paywalls or even watermarks.
|
No longer do you have to rely on shady websites, shoving tons of ads in your face to fulfil your downloady needs. No longer will you be held back by artificially crippled download speeds, login-/paywalls or even watermarks.
|
||||||
|
|
||||||
## But what is Tubio?
|
## But what is Tubio?
|
||||||
Tubio in of itself is not a downloader, but a GUI for the widely known, open-source, public-domain cli [youtube-dl](http://youtube-dl.org/). <sup>Thanks for this awesome tool! You guys are heroes!</sup>
|
Tubio in of itself is not a downloader, but a GUI for the widely known, open-source, public-domain cli [yt-dlp](https://github.com/yt-dlp/yt-dlp/). <sup>Thanks for this awesome tool! You guys are heroes! (Obviously, same goes for youtube-dl, which yt-dlp is based on)</sup>
|
||||||
The goal of Tubio is to make this awesome software more accessible. Not everyone knows how to use the command line!
|
The goal of Tubio is to make this awesome software more accessible. Not everyone knows how to use the command line!
|
||||||
|
|
||||||
## But, how does it work?
|
## But, how does it work?
|
||||||
It\`s quite easy! Make sure the Tubio service is running in the background, navigate to http://localhost, paste in your video/music url and chances are that it will work!
|
It\`s quite easy! Make sure the Tubio service is running in the background, navigate to http://localhost, paste in your video/music url and chances are that it will work!
|
||||||
|
|
||||||
This is because the set of supported websites is **extremely** large! See here: [supportedsites.md](https://github.com/blackjack4494/yt-dlc/blob/master/docs/supportedsites.md)
|
This is because the set of supported websites is **extremely** large! See here: [supportedsites.md](https://github.com/blackjack4494/yt-dlc/blob/master/docs/supportedsites.md)
|
||||||
|
|
||||||
When your download finished, just click "download" and have fun!
|
When your download finished, just click "download" and have fun!
|
||||||
|
|
||||||
## No, i mean on a more technical level
|
## No, i mean on a more technical level
|
||||||
The backend is a C++ webserver, powered by [casenta/mongoose](https://github.com/cesanta/mongoose).<sup>Thanks, you guys are awesome!</sup>
|
The backend is a C++ webserver, powered by [casenta/mongoose](https://github.com/cesanta/mongoose).<sup>Thanks, you guys are awesome!</sup>
|
||||||
The connection is **not** encrypted, but that\`s okay because it is intended for localhost only. Mongoose does support ssl, so you can always add it, if you fancy it.
|
The connection is **not** encrypted, but that\`s okay because it is intended for localhost only. Mongoose does support ssl, so you can always add it, if you fancy it.
|
||||||
|
|
||||||
The frontend is a nuxt.js web application.
|
The frontend is a nuxt.js web application.
|
||||||
|
|
||||||
## But how does it look?
|
## But how does it look?
|
||||||
Have a sneak peak!
|
Have a sneak peak!
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||

|

|
||||||
|
|
||||||

|

|
||||||
|
|
||||||

|

|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## NEW! Get the Chrome Companion Extension!
|
## There's also a Chrome Extension
|
||||||

|

|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
|
||||||
## How can i configure it?
|
## How can i configure it?
|
||||||
See this json file (config.json).
|
See this json file (config.json).
|
||||||
Most of these values are configurable in the web-interface, but not all, such as the port.
|
Most of these values are configurable in the web-interface, but not all, such as the port.
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"access": {
|
"access": {
|
||||||
"enable_whitelist": true,
|
"enable_whitelist": true,
|
||||||
"only_allow_localhost": false,
|
"only_allow_localhost": false,
|
||||||
"whitelist": [
|
"whitelist": [
|
||||||
"127.0.0.1",
|
"127.0.0.1",
|
||||||
"192.168.1.12",
|
"192.168.1.12",
|
||||||
"192.168.1.14",
|
"192.168.1.14",
|
||||||
"192.168.1.10"
|
"192.168.1.10"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"downloader": {
|
"downloader": {
|
||||||
"cachedir": "dlcache",
|
"cachedir": "dlcache",
|
||||||
"max_dlrate_per_thread": "100M",
|
"max_dlrate_per_thread": "100M",
|
||||||
"num_threads": 10
|
"num_threads": 10
|
||||||
},
|
},
|
||||||
"general": {
|
"general": {
|
||||||
"show_console": true
|
"show_console": true
|
||||||
},
|
},
|
||||||
"httpServer": {
|
"httpServer": {
|
||||||
"polling_rate": 100,
|
"polling_rate": 100,
|
||||||
"port": "80",
|
"port": "80",
|
||||||
"rootdir": "./frontend"
|
"rootdir": "./frontend"
|
||||||
},
|
},
|
||||||
"logging": {
|
"logging": {
|
||||||
"autosave_interval": 20,
|
"autosave_interval": 20,
|
||||||
"logfile_json": "log.json",
|
"logfile_json": "log.json",
|
||||||
"logfile_text": "log.txt"
|
"logfile_text": "log.txt"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Can i use Tubio on multiple devices?
|
## Can i use Tubio on multiple devices?
|
||||||
Tubio is a webserver, after all. It is intended to be used for localhost only (since no encryption), but no one is preventing you from unticking `localhost only` under /settings.
|
Tubio hosts a webserver, after all. It is intended to be used for localhost only (since no encryption), but no one is preventing you from unticking `localhost only` under `/settings`. Then you could connect to it via your local IPv4 address (such as `192.168.1.12`) or even over the global WAN! However, regarding WAN, i would **strongly** advise against such a careless setup.
|
||||||
|
|
||||||
Then you could connect to it via your local IPv4 address (such as `192.168.1.12`) or even over the global WAN! However, regarding WAN, i would **strongly** advise against such a careless setup.
|
It wouldn't be that complicated to enable TLS. You'd have to install and link `libcryptopp`, obtain a certificate + key, and pass them to the mongoose webserver. But that would break that whole *"compiles without any dependencies thing"*. See [the mongoose docs TLS page](https://mongoose.ws/tutorials/tls/) for instructions. If you implement this cleanly, like with a special make target, a merge request would be greatly appreciated.
|
||||||
|
|
||||||
!!! IMPORTANT
|
!!! IMPORTANT
|
||||||
Tubio does NOT manage sessions or accounts! Everyone using your Tubio instance will see **all your downloads** and vica versa.
|
Tubio does NOT manage sessions or accounts! Everyone using your Tubio instance will see **all your downloads** and vica versa.
|
||||||
|
|
||||||
If you opt for unleashing Tubio on your LAN, i would **strongly** recommend enabling the whitelist! You can do this either in the `config.json` or in /settings. Either way, it is a json-array of strings which represent IPv4 addresses.
|
If you opt for unleashing Tubio on your LAN, i would **strongly** recommend enabling the whitelist! You can do this either in the `config.json` or in /settings. Either way, it is a json-array of strings which represent IPv4 addresses.
|
||||||
|
|
||||||
## Setup (Windows)
|
## Setup (Linux)
|
||||||
#### Install youtube-dl.exe:
|
1) Clone this repository and build it with cmake
|
||||||
1) Download the latest Tubio build from [here](https://github.com/Leonetienne/Tubio/releases).
|
2) Create some folder on your system. This will be the installation folder.
|
||||||
2) Create some folder on your pc. This will be the installation folder.
|
3) In this folder, dump the contents of /Tubio/.
|
||||||
3) Dump in the contents of the Tubio build you just downloaded.
|
4) Install python3 and then yt-dlp via `pip install yt-dlp`.
|
||||||
4) Launch vcredist_x86.exe and install it. This will install Microsoft Visual C++ 2010 Redistributable Package (x86) which is needed for dependencies.
|
5) Launch the tubio executable
|
||||||
5) Launch VC_redist.x64.exe and install it. This will install Microsoft Visual C++ 2015/17/19 Redistributable Package (x64) which is needed to run Tubio.exe
|
6) Enjoy <3
|
||||||
6) Launch Tubio.exe
|
|
||||||
7) Navigate to `http://localhost/settings` and click "Update ytdl", as the version Tubio shipped with might be out of date.
|
## Frequently Asked Questions
|
||||||
8) <Optional>: Set up `Tubio.exe` to launch with windows to have it\`s service always at hand.
|
### My downloads hang at 99% or 100%
|
||||||
9) Enjoy <3
|
This happens as there almost always is some post-processing to do after downloading. Like, audio-extracting and/or video recoding. If you're downloading
|
||||||
|
a video this may take a while, as it may be converting webm to mp4.
|
||||||
## Frequently Asked Questions
|
|
||||||
### My downloads hang at 99% or 100%
|
### My downloads fail!
|
||||||
This happens as there often is some post-processing to do after downloading.
|
First thing to do: Verify that are using the latest version of yt-dlp. The team behind its upstream, youtube-dl, are quite fast adjusting the downloading backend to changes in popular platforms, such as youtube. If your downloads still fail,
|
||||||
|
verify that yt-dlp is in fact capable of downloading the url you supplied by executing `yt-dlp $url`, replacing `$url` with your url. If this works, you can extract the tubio id of the url you just queued in `/settings`, and then open `<your-tubio-host>/downloadlog/<tubio-id>` to see the output stdout and stderr of the yt-dlp call. Then work from the error messages you see in there.
|
||||||
### My downloads fail!
|
|
||||||
First thing to do: Navigate to /settings and click "Update ytdl". This will update your local instance of [youtube-dl](http://youtube-dl.org/). Check the logs to see if it worked. If not, restart Tubio and try again.
|
If it\`s still not working, you\`re out of luck. :(
|
||||||
|
You may want to check youtube-dl compatible sites.
|
||||||
If it\`s still not working, you are most likely trying to download a video from a playlist with a weird url. Try a different one (The one from the share button, the one from right-clicking the video or the one from the url-bar in your browser).
|
|
||||||
|
### I locked myself out by enabling localhost only on another device!
|
||||||
If it\`s still not working, you\`re out of luck. :(
|
This can only be undone from localhost. Open Tubio via, and this is important, either `localhost` or `127.0.0.1` and untick it again. If you can only ssh into the host, you can edit the `config.json` itself and restart Tubio.
|
||||||
|
|
||||||
### I locked myself out by enabling localhost only on another device!
|
### Does it work on Windows?
|
||||||
This can only be undone from the host. Open Tubio via, and this is important, either `localhost` or `127.0.0.1` and untick it again. If you can only ssh into the host, you can edit the `config.json` itself and restart Tubio.
|
Sure it does. You just have to compile it yourself using cmake, and put yt-dlp.exe, ffmpeg.exe, ffplay.exe and ffprobe.exe
|
||||||
|
in Tubios working directory (installation directory). You could then just launch it at startup.
|
||||||
### Does it work on linux?
|
|
||||||
Well, technically, yes. You would have to install youtube-dl and the ffmpeg suite yourself, and compile Tubio yourself though. I have not tried it yet, but it should work.
|
### Can I use it on my phone?
|
||||||
|
You bet! That's what I'm mainly using it for :) Read [this](#user-content-can-i-use-tubio-on-multiple-devices).
|
||||||
### Can i use it on my phone?
|
|
||||||
Sure. Read [this](#user-content-can-i-use-tubio-on-multiple-devices).
|
### Can I use this to host my own downloader website?
|
||||||
|
On your own risk! Tubio is NOT designed for this! Also do note that tubio does NOT manage sessions or accounts! Everyone accessing this instance can see everyones downloads and access the admin panel! Tubio is really designed for one user!
|
||||||
### Can i use this to host my own downloader website?
|
|
||||||
On your own risk! Tubio is NOT designed for this! Also do note that tubio does NOT manage sessions or accounts! Everyone accessing this instance can see everyones downloads and access the admin panel! Tubio is really designed for one user!
|
### XY is not working, you have to fix it now!
|
||||||
|
I do not. Tubio is a tool I originally made for myself only. I just thought it\`s nice and worth sharing. I will address issues when I have time. Feel free to submit issues and I will have a look when I get to it. :)
|
||||||
### XY is not working, you have to fix it now!
|
|
||||||
I do not. Tubio is a tool i originally made for myself only. I just thought it\`s nice and worth sharing. I will address issues when i have time. Feel free to submit issues and i will have a look when i get to it. :)
|
### XY is not polished enough!
|
||||||
|
This is an alpha-version. What did you expect? :D
|
||||||
### XY is not polished enough!
|
|
||||||
This is an alpha-version. What did you expect? :D
|
### Can you please add support for website XY?
|
||||||
|
Please address the awesome team at youtube-dl, as they make the downloading-backend: [github.com/ytdl-org/youtube-dl/issues](https://github.com/ytdl-org/youtube-dl/issues).
|
||||||
### Can you please add support for website XY?
|
The downloader uses ([yt-dlp](https://github.com/yt-dlp/yt-dlp/)), which is based on youtube-dl.
|
||||||
Please address the awesome team at youtube-dl, as they made the downloading-end: [github.com/ytdl-org/youtube-dl/issues](https://github.com/ytdl-org/youtube-dl/issues)
|
|
||||||
|
## Important notice!
|
||||||
## Important notice!
|
I do NOT endorse illegal downloads in any way, shape, or form. Tubio is a tool to download media from legal sources! Use Tubio at your own discretion! Neither do i provide ANY warranty in ANY way, shape, or form!
|
||||||
I do NOT endorse illegal downloads in any way, shape, or form. Tubio is a tool to download media from legal sources! Use Tubio at your own discretion! Neither do i provide ANY warranty in ANY way, shape, or form!
|
|
||||||
|
## License
|
||||||
## License
|
Tubio is distributed under the GNU General Public License v3.0.
|
||||||
Tubio is distributed under the GNU General Public License v3.0.
|
Please read the [license file](https://gitea.leonetienne.de/leonetienne/Tubio/src/branch/master/LICENSE).
|
||||||
Please read the [license file](https://github.com/Leonetienne/Tubio/blob/master/license.txt).
|
|
||||||
|
31
Tubio.sln
31
Tubio.sln
@ -1,31 +0,0 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
|
||||||
# Visual Studio Version 16
|
|
||||||
VisualStudioVersion = 16.0.30413.136
|
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
|
||||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Tubio", "Tubio\Tubio.vcxproj", "{8AE799C5-CB17-4714-A362-D8B9817A723E}"
|
|
||||||
EndProject
|
|
||||||
Global
|
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
|
||||||
Debug|x64 = Debug|x64
|
|
||||||
Debug|x86 = Debug|x86
|
|
||||||
Release|x64 = Release|x64
|
|
||||||
Release|x86 = Release|x86
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
|
||||||
{8AE799C5-CB17-4714-A362-D8B9817A723E}.Debug|x64.ActiveCfg = Debug|x64
|
|
||||||
{8AE799C5-CB17-4714-A362-D8B9817A723E}.Debug|x64.Build.0 = Debug|x64
|
|
||||||
{8AE799C5-CB17-4714-A362-D8B9817A723E}.Debug|x86.ActiveCfg = Debug|Win32
|
|
||||||
{8AE799C5-CB17-4714-A362-D8B9817A723E}.Debug|x86.Build.0 = Debug|Win32
|
|
||||||
{8AE799C5-CB17-4714-A362-D8B9817A723E}.Release|x64.ActiveCfg = Release|x64
|
|
||||||
{8AE799C5-CB17-4714-A362-D8B9817A723E}.Release|x64.Build.0 = Release|x64
|
|
||||||
{8AE799C5-CB17-4714-A362-D8B9817A723E}.Release|x86.ActiveCfg = Release|Win32
|
|
||||||
{8AE799C5-CB17-4714-A362-D8B9817A723E}.Release|x86.Build.0 = Release|Win32
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
|
||||||
HideSolutionNode = FALSE
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
|
||||||
SolutionGuid = {11C6C438-21D5-40CC-9CDC-FBA3AE6634F3}
|
|
||||||
EndGlobalSection
|
|
||||||
EndGlobal
|
|
53
Tubio/CMakeLists.txt
Executable file
53
Tubio/CMakeLists.txt
Executable file
@ -0,0 +1,53 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.16)
|
||||||
|
project(Tubio)
|
||||||
|
|
||||||
|
# Set C++ standard
|
||||||
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
|
||||||
|
# Add external-directories dir to include dir list
|
||||||
|
include_directories(./external_dependencies/)
|
||||||
|
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
|
||||||
|
|
||||||
|
# Add absolutely kawaii sources to Tubio <3
|
||||||
|
add_executable(Tubio
|
||||||
|
main.cpp
|
||||||
|
ConsoleManager.cpp
|
||||||
|
ConsoleManager.h
|
||||||
|
DownloadManager.cpp
|
||||||
|
DownloadManager.h
|
||||||
|
FileSystem.cpp
|
||||||
|
FileSystem.h
|
||||||
|
Framework.cpp
|
||||||
|
Framework.h
|
||||||
|
HttpServer.cpp
|
||||||
|
HttpServer.h
|
||||||
|
Idler.cpp
|
||||||
|
Idler.h
|
||||||
|
LogHistory.cpp
|
||||||
|
LogHistory.h
|
||||||
|
LogTypes.h
|
||||||
|
Logger.cpp
|
||||||
|
Logger.h
|
||||||
|
RestQueryHandler.cpp
|
||||||
|
RestQueryHandler.h
|
||||||
|
RestResponseTemplates.cpp
|
||||||
|
RestResponseTemplates.h
|
||||||
|
TimeUnits.h
|
||||||
|
Updater.cpp
|
||||||
|
Updater.h
|
||||||
|
Version.h
|
||||||
|
XGConfig.cpp
|
||||||
|
XGConfig.h
|
||||||
|
XGControl.cpp
|
||||||
|
XGControl.h
|
||||||
|
external_dependencies/casenta/mongoose/mongoose.c
|
||||||
|
external_dependencies/casenta/mongoose/mongoose.h
|
||||||
|
external_dependencies/leonetienne/JasonPP/JasonPP.cpp
|
||||||
|
external_dependencies/leonetienne/JasonPP/JasonPP.hpp
|
||||||
|
external_dependencies/leonetienne/stringtools/StringTools.cpp
|
||||||
|
external_dependencies/leonetienne/stringtools/StringTools.h
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(Tubio pthread)
|
||||||
|
|
@ -162,7 +162,7 @@ void DownloadManager::DownloadNext()
|
|||||||
std::string ytdl_call_video_base =
|
std::string ytdl_call_video_base =
|
||||||
"yt-dlp --newline --no-call-home --no-playlist --no-part --no-warnings --socket-timeout 5 --limit-rate $$DL_RATE"
|
"yt-dlp --newline --no-call-home --no-playlist --no-part --no-warnings --socket-timeout 5 --limit-rate $$DL_RATE"
|
||||||
" --no-mtime --no-cache-dir -f \"$$QUALITY\" --recode-video mp4 --prefer-ffmpeg"
|
" --no-mtime --no-cache-dir -f \"$$QUALITY\" --recode-video mp4 --prefer-ffmpeg"
|
||||||
" -o \"$$DL_FILE\" \"$$DL_URL\" > \"$$DL_PROG_BUF_FILE\"";
|
" -o \"$$DL_FILE\" \"$$DL_URL\" > \"$$DL_PROG_BUF_FILE\" 2>&1";
|
||||||
|
|
||||||
// Fill template
|
// Fill template
|
||||||
ytdl_call_video_base = Internal::StringHelpers::Replace(ytdl_call_video_base, "$$QUALITY", DownloadQualityToStringParams(entry->quality));
|
ytdl_call_video_base = Internal::StringHelpers::Replace(ytdl_call_video_base, "$$QUALITY", DownloadQualityToStringParams(entry->quality));
|
||||||
@ -180,7 +180,7 @@ void DownloadManager::DownloadNext()
|
|||||||
std::string ytdl_call_audio_base =
|
std::string ytdl_call_audio_base =
|
||||||
"yt-dlp --newline --no-call-home --no-playlist --no-part --no-warnings --socket-timeout 5 --limit-rate $$DL_RATE"
|
"yt-dlp --newline --no-call-home --no-playlist --no-part --no-warnings --socket-timeout 5 --limit-rate $$DL_RATE"
|
||||||
" --no-mtime --no-cache-dir -f worstvideo+bestaudio --audio-format mp3 --audio-quality 0 --extract-audio -o \"$$DL_FILE\""
|
" --no-mtime --no-cache-dir -f worstvideo+bestaudio --audio-format mp3 --audio-quality 0 --extract-audio -o \"$$DL_FILE\""
|
||||||
" \"$$DL_URL\" > \"$$DL_PROG_BUF_FILE\"";
|
" \"$$DL_URL\" > \"$$DL_PROG_BUF_FILE\" 2>&1";
|
||||||
|
|
||||||
|
|
||||||
// Fill template
|
// Fill template
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#include "Filesystem.h"
|
#include "FileSystem.h"
|
||||||
#ifdef _WIN
|
#ifdef _WIN
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,264 +1,307 @@
|
|||||||
#include "HttpServer.h"
|
#include "HttpServer.h"
|
||||||
|
#include "external_dependencies/leonetienne/stringtools/StringTools.h"
|
||||||
using namespace Logging;
|
|
||||||
using namespace Rest;
|
using namespace Logging;
|
||||||
using namespace JasonPP;
|
using namespace Rest;
|
||||||
|
using namespace JasonPP;
|
||||||
HttpServer::HttpServer()
|
|
||||||
{
|
HttpServer::HttpServer()
|
||||||
pMgr = new mg_mgr();
|
{
|
||||||
pNc = nullptr;
|
pMgr = new mg_mgr();
|
||||||
log = new Logger("HttpServer");
|
pNc = nullptr;
|
||||||
|
log = new Logger("HttpServer");
|
||||||
return;
|
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
HttpServer::~HttpServer()
|
|
||||||
{
|
HttpServer::~HttpServer()
|
||||||
delete pMgr;
|
{
|
||||||
delete log;
|
delete pMgr;
|
||||||
|
delete log;
|
||||||
log = nullptr;
|
|
||||||
pMgr = nullptr;
|
log = nullptr;
|
||||||
|
pMgr = nullptr;
|
||||||
return;
|
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
void HttpServer::PostInit()
|
|
||||||
{
|
void HttpServer::PostInit()
|
||||||
isBootedSuccessfully = InitWebServer();
|
{
|
||||||
|
isBootedSuccessfully = InitWebServer();
|
||||||
return;
|
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
bool HttpServer::InitWebServer()
|
|
||||||
{
|
bool HttpServer::InitWebServer()
|
||||||
mg_mgr_init(pMgr, NULL);
|
{
|
||||||
|
mg_mgr_init(pMgr, NULL);
|
||||||
log->cout << "Starting http-server on port " << XGConfig::httpServer.port << "...";
|
|
||||||
log->Flush();
|
log->cout << "Starting http-server on port " << XGConfig::httpServer.port << "...";
|
||||||
|
log->Flush();
|
||||||
pNc = mg_bind(pMgr, XGConfig::httpServer.port.c_str(), this->EventHandler);
|
|
||||||
|
pNc = mg_bind(pMgr, XGConfig::httpServer.port.c_str(), this->EventHandler);
|
||||||
if (pNc == NULL)
|
|
||||||
{
|
if (pNc == NULL)
|
||||||
log->cout << log->Err() << "Failed to boot the http-server! - Unable to bind listener! (port: " << XGConfig::httpServer.port << ")";
|
{
|
||||||
log->Flush();
|
log->cout << log->Err() << "Failed to boot the http-server! - Unable to bind listener! (port: " << XGConfig::httpServer.port << ")";
|
||||||
return false;
|
log->Flush();
|
||||||
}
|
return false;
|
||||||
|
}
|
||||||
mg_set_protocol_http_websocket(pNc);
|
|
||||||
frontend_serve_opts.document_root = XGConfig::httpServer.rootdir.c_str();
|
mg_set_protocol_http_websocket(pNc);
|
||||||
frontend_serve_opts.enable_directory_listing = "no";
|
frontend_serve_opts.document_root = XGConfig::httpServer.rootdir.c_str();
|
||||||
|
frontend_serve_opts.enable_directory_listing = "no";
|
||||||
log->cout << "Started http-server successfully!";
|
|
||||||
log->Flush();
|
log->cout << "Started http-server successfully!";
|
||||||
isBootedSuccessfully = true;
|
log->Flush();
|
||||||
|
isBootedSuccessfully = true;
|
||||||
return true;
|
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
void HttpServer::Update()
|
|
||||||
{
|
void HttpServer::Update()
|
||||||
mg_mgr_poll(pMgr, XGConfig::httpServer.polling_rate);
|
{
|
||||||
|
mg_mgr_poll(pMgr, XGConfig::httpServer.polling_rate);
|
||||||
return;
|
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
void HttpServer::ServeStringToConnection(struct mg_connection* c, std::string str, int httpStatusCode)
|
|
||||||
{
|
void HttpServer::ServeStringToConnection(struct mg_connection* c, std::string str, int httpStatusCode)
|
||||||
mg_send_head(c, httpStatusCode, str.length(), "content-type: application/json\nAccess-Control-Allow-Origin: *");
|
{
|
||||||
mg_printf(c, "%s", str.c_str());
|
mg_send_head(c, httpStatusCode, str.length(), "content-type: application/json\nAccess-Control-Allow-Origin: *");
|
||||||
|
mg_printf(c, "%s", str.c_str());
|
||||||
return;
|
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
void HttpServer::EventHandler(mg_connection* pNc, int ev, void* p)
|
|
||||||
{
|
void HttpServer::EventHandler(mg_connection* pNc, int ev, void* p)
|
||||||
switch (ev)
|
{
|
||||||
{
|
switch (ev)
|
||||||
case MG_EV_HTTP_REQUEST:
|
{
|
||||||
// Reset standby timer
|
case MG_EV_HTTP_REQUEST:
|
||||||
XGControl::last_query_time = time(0);
|
// Reset standby timer
|
||||||
|
XGControl::last_query_time = time(0);
|
||||||
http_message* hpm = (http_message*)p;
|
|
||||||
std::string requestedUri = FixUnterminatedString(hpm->uri.p, hpm->uri.len);
|
http_message* hpm = (http_message*)p;
|
||||||
|
std::string requestedUri = FixUnterminatedString(hpm->uri.p, hpm->uri.len);
|
||||||
// Get clients ip address
|
|
||||||
std::string peer_addr;
|
// Get clients ip address
|
||||||
{
|
std::string peer_addr;
|
||||||
char buf[32];
|
{
|
||||||
mg_sock_addr_to_str(&pNc->sa, buf, sizeof(buf), MG_SOCK_STRINGIFY_IP);
|
char buf[32];
|
||||||
peer_addr = buf;
|
mg_sock_addr_to_str(&pNc->sa, buf, sizeof(buf), MG_SOCK_STRINGIFY_IP);
|
||||||
}
|
peer_addr = buf;
|
||||||
|
}
|
||||||
std::string denialReason;
|
|
||||||
if (IsConnectionAllowed(peer_addr, denialReason))
|
std::string denialReason;
|
||||||
{
|
if (IsConnectionAllowed(peer_addr, denialReason))
|
||||||
try
|
{
|
||||||
{
|
try
|
||||||
if (requestedUri == "/api")
|
{
|
||||||
{
|
if (requestedUri == "/api")
|
||||||
ProcessAPIRequest(pNc, ev, p, peer_addr);
|
{
|
||||||
}
|
ProcessAPIRequest(pNc, ev, p, peer_addr);
|
||||||
else if (requestedUri.substr(0, 9) == "/download")
|
}
|
||||||
{
|
else if (requestedUri.substr(0, 12) == "/downloadlog")
|
||||||
ServeDownloadeableResource(pNc, ev, p, requestedUri);
|
{
|
||||||
}
|
ServeDownloadLog(pNc, ev, p, requestedUri);
|
||||||
else
|
}
|
||||||
{
|
else if (requestedUri.substr(0, 9) == "/download")
|
||||||
// Just serve the files requested
|
{
|
||||||
mg_serve_http(pNc, (struct http_message*)p, frontend_serve_opts);
|
ServeDownloadeableResource(pNc, ev, p, requestedUri);
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
catch (std::exception& e)
|
{
|
||||||
{
|
// Just serve the files requested
|
||||||
Json j;
|
mg_serve_http(pNc, (struct http_message*)p, frontend_serve_opts);
|
||||||
j.CloneFrom(RestResponseTemplates::GetByCode(HTTP_STATUS_CODE::INTERNAL_SERVER_ERROR, e.what()));
|
}
|
||||||
ServeStringToConnection(pNc, j.Render(), (int)HTTP_STATUS_CODE::INTERNAL_SERVER_ERROR);
|
}
|
||||||
}
|
catch (std::exception& e)
|
||||||
catch (...)
|
{
|
||||||
{
|
Json j;
|
||||||
Json j;
|
j.CloneFrom(RestResponseTemplates::GetByCode(HTTP_STATUS_CODE::INTERNAL_SERVER_ERROR, e.what()));
|
||||||
j.CloneFrom(RestResponseTemplates::GetByCode(HTTP_STATUS_CODE::INTERNAL_SERVER_ERROR, "Das not good"));
|
ServeStringToConnection(pNc, j.Render(), (int)HTTP_STATUS_CODE::INTERNAL_SERVER_ERROR);
|
||||||
ServeStringToConnection(pNc, j.Render(), (int)HTTP_STATUS_CODE::INTERNAL_SERVER_ERROR);
|
}
|
||||||
}
|
catch (...)
|
||||||
|
{
|
||||||
break;
|
Json j;
|
||||||
}
|
j.CloneFrom(RestResponseTemplates::GetByCode(HTTP_STATUS_CODE::INTERNAL_SERVER_ERROR, "Das not good"));
|
||||||
else // Client is not allowed, serve error json
|
ServeStringToConnection(pNc, j.Render(), (int)HTTP_STATUS_CODE::INTERNAL_SERVER_ERROR);
|
||||||
{
|
}
|
||||||
Json j;
|
|
||||||
j.CloneFrom(RestResponseTemplates::GetByCode(HTTP_STATUS_CODE::UNAUTHORIZED, denialReason));
|
break;
|
||||||
ServeStringToConnection(pNc, j.Render(), (int)HTTP_STATUS_CODE::UNAUTHORIZED);
|
}
|
||||||
}
|
else // Client is not allowed, serve error json
|
||||||
}
|
{
|
||||||
|
Json j;
|
||||||
return;
|
j.CloneFrom(RestResponseTemplates::GetByCode(HTTP_STATUS_CODE::UNAUTHORIZED, denialReason));
|
||||||
}
|
ServeStringToConnection(pNc, j.Render(), (int)HTTP_STATUS_CODE::UNAUTHORIZED);
|
||||||
|
}
|
||||||
void HttpServer::ProcessAPIRequest(mg_connection* pNc, int ev, void* p, std::string peerAddress)
|
}
|
||||||
{
|
|
||||||
// Get struct with http message informations
|
return;
|
||||||
http_message* hpm = (http_message*)p;
|
}
|
||||||
|
|
||||||
// Get the transmitted message body
|
std::string HttpServer::SanitizeString(std::string in) {
|
||||||
std::string requestBodyRaw = FixUnterminatedString(hpm->body.p, hpm->body.len);
|
in = StringTools::Replace(in, '`', "\\\\`");
|
||||||
|
in = StringTools::Replace(in, '|', "\\\\|");
|
||||||
// Check for the body being valid json
|
in = StringTools::Replace(in, '$', "\\\\$");
|
||||||
if (IsJsonValid(requestBodyRaw))
|
in = StringTools::Replace(in, "&&", "\\\\&\\\\&");
|
||||||
{
|
in = StringTools::Replace(in, ";", "\\\\;");
|
||||||
Json requestBody;
|
|
||||||
requestBody.Parse(requestBodyRaw);
|
return in;
|
||||||
|
}
|
||||||
|
|
||||||
|
void HttpServer::ProcessAPIRequest(mg_connection* pNc, int ev, void* p, std::string peerAddress)
|
||||||
JsonBlock responseBody;
|
{
|
||||||
HTTP_STATUS_CODE returnCode;
|
// Get struct with http message informations
|
||||||
RestQueryHandler::ProcessQuery(peerAddress, requestBody, responseBody, returnCode);
|
http_message* hpm = (http_message*)p;
|
||||||
|
|
||||||
Json response(responseBody);
|
// Get the transmitted message body
|
||||||
ServeStringToConnection(pNc, response.Render(), (int)returnCode);
|
std::string requestBodyRaw = FixUnterminatedString(hpm->body.p, hpm->body.len);
|
||||||
}
|
|
||||||
else // return error message for invalid json
|
// Sanitize it
|
||||||
{
|
requestBodyRaw = SanitizeString(requestBodyRaw);
|
||||||
Json errorJson;
|
|
||||||
errorJson.CloneFrom(RestResponseTemplates::GetByCode(HTTP_STATUS_CODE::BAD_REQUEST, "Received json is fucked"));
|
// Check for the body being valid json
|
||||||
ServeStringToConnection(pNc, errorJson.Render(), (int)HTTP_STATUS_CODE::BAD_REQUEST);
|
if (IsJsonValid(requestBodyRaw))
|
||||||
}
|
{
|
||||||
|
Json requestBody;
|
||||||
return;
|
requestBody.Parse(requestBodyRaw);
|
||||||
}
|
|
||||||
|
|
||||||
void HttpServer::ServeDownloadeableResource(mg_connection* pNc, int ev, void* p, std::string uri)
|
|
||||||
{
|
JsonBlock responseBody;
|
||||||
std::string fileId = uri.substr(10, uri.length() - 10);
|
HTTP_STATUS_CODE returnCode;
|
||||||
|
RestQueryHandler::ProcessQuery(peerAddress, requestBody, responseBody, returnCode);
|
||||||
if (Downloader::DownloadManager::DoesTubioIDExist(fileId))
|
|
||||||
{
|
Json response(responseBody);
|
||||||
Downloader::DownloadEntry& entry = Downloader::DownloadManager::GetDownloadEntryByTubioID(fileId);
|
ServeStringToConnection(pNc, response.Render(), (int)returnCode);
|
||||||
|
}
|
||||||
if (entry.status == Downloader::DOWNLOAD_STATUS::FINISHED)
|
else // return error message for invalid json
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
Json errorJson;
|
||||||
std::string downloadedFilename = entry.title + (entry.mode == Downloader::DOWNLOAD_MODE::AUDIO ? ".mp3" : ".mp4");
|
errorJson.CloneFrom(RestResponseTemplates::GetByCode(HTTP_STATUS_CODE::BAD_REQUEST, "Received json is fucked"));
|
||||||
|
ServeStringToConnection(pNc, errorJson.Render(), (int)HTTP_STATUS_CODE::BAD_REQUEST);
|
||||||
ss << "Access-Control-Allow-Origin: *\nContent-Disposition: attachment; filename=\"" << downloadedFilename << "\"\nPragma: public\nCache-Control: must-revalidate, post-check=0, pre-check=0";
|
}
|
||||||
mg_http_serve_file(pNc, (http_message*)p, entry.downloaded_filename.c_str(), mg_mk_str("application/octet-stream"), mg_mk_str(ss.str().c_str()));
|
|
||||||
}
|
return;
|
||||||
else
|
}
|
||||||
{
|
|
||||||
Json j;
|
void HttpServer::ServeDownloadeableResource(mg_connection* pNc, int ev, void* p, std::string uri)
|
||||||
j.CloneFrom(RestResponseTemplates::GetByCode(HTTP_STATUS_CODE::BAD_REQUEST, "File download not ready!"));
|
{
|
||||||
ServeStringToConnection(pNc, j.Render(), (int)HTTP_STATUS_CODE::BAD_REQUEST);
|
std::string fileId = uri.substr(10, uri.length() - 10);
|
||||||
}
|
|
||||||
}
|
if (Downloader::DownloadManager::DoesTubioIDExist(fileId))
|
||||||
else
|
{
|
||||||
{
|
Downloader::DownloadEntry& entry = Downloader::DownloadManager::GetDownloadEntryByTubioID(fileId);
|
||||||
Json j;
|
|
||||||
j.CloneFrom(RestResponseTemplates::GetByCode(HTTP_STATUS_CODE::BAD_REQUEST, "Invalid tubio id!"));
|
if (entry.status == Downloader::DOWNLOAD_STATUS::FINISHED)
|
||||||
ServeStringToConnection(pNc, j.Render(), (int)HTTP_STATUS_CODE::BAD_REQUEST);
|
{
|
||||||
}
|
std::stringstream ss;
|
||||||
|
std::string downloadedFilename = entry.title + (entry.mode == Downloader::DOWNLOAD_MODE::AUDIO ? ".mp3" : ".mp4");
|
||||||
return;
|
|
||||||
}
|
ss << "Access-Control-Allow-Origin: *\nContent-Disposition: attachment; filename=\"" << downloadedFilename << "\"\nPragma: public\nCache-Control: must-revalidate, post-check=0, pre-check=0";
|
||||||
|
mg_http_serve_file(pNc, (http_message*)p, entry.downloaded_filename.c_str(), mg_mk_str("application/octet-stream"), mg_mk_str(ss.str().c_str()));
|
||||||
bool HttpServer::IsConnectionAllowed(std::string peer_address, std::string& denialReason)
|
}
|
||||||
{
|
else
|
||||||
// Localhost is always allowed!
|
{
|
||||||
if (peer_address == "127.0.0.1") return true;
|
Json j;
|
||||||
|
j.CloneFrom(RestResponseTemplates::GetByCode(HTTP_STATUS_CODE::BAD_REQUEST, "File download not ready!"));
|
||||||
// Peer is not localhost, but only localhost is allowed!
|
ServeStringToConnection(pNc, j.Render(), (int)HTTP_STATUS_CODE::BAD_REQUEST);
|
||||||
else if (XGConfig::access.only_allow_localhost)
|
}
|
||||||
{
|
}
|
||||||
denialReason = "Only localhost allowed!";
|
else
|
||||||
return false;
|
{
|
||||||
}
|
Json j;
|
||||||
|
j.CloneFrom(RestResponseTemplates::GetByCode(HTTP_STATUS_CODE::BAD_REQUEST, "Invalid tubio id!"));
|
||||||
// Let's check if the whitelist is active
|
ServeStringToConnection(pNc, j.Render(), (int)HTTP_STATUS_CODE::BAD_REQUEST);
|
||||||
else if (XGConfig::access.enable_whitelist)
|
}
|
||||||
{
|
|
||||||
// It is. Let's check if our peer is whitelisted
|
return;
|
||||||
for (std::size_t i = 0; i < XGConfig::access.whitelist.size(); i++)
|
}
|
||||||
{
|
|
||||||
// Whitelist is enabled, and peer is whitelisted
|
void HttpServer::ServeDownloadLog(mg_connection* pNc, int ev, void* p, std::string uri)
|
||||||
if (XGConfig::access.whitelist[i] == peer_address) return true;
|
{
|
||||||
}
|
std::string fileId = uri.substr(13, uri.length() - 13);
|
||||||
|
|
||||||
// Whitelist is enabled, but peer is NOT whitelisted
|
if (Downloader::DownloadManager::DoesTubioIDExist(fileId))
|
||||||
denialReason = std::string("Not whitelisted! Ask your tubio administrator to whitelist '") + peer_address + "' in order to gain access.";
|
{
|
||||||
return false;
|
Downloader::DownloadEntry& entry = Downloader::DownloadManager::GetDownloadEntryByTubioID(fileId);
|
||||||
}
|
|
||||||
else // Whitelist is NOT enabled and only_allow_localhost is FALSE!
|
std::stringstream ss;
|
||||||
{
|
std::string logFilename = std::string("./dlcache/dlprogbuf/") + fileId + ".buf";
|
||||||
return true;
|
|
||||||
}
|
ss << "Access-Control-Allow-Origin: *\nContent-Type: text/plain; Cache-Control: must-revalidate, post-check=0, pre-check=0";
|
||||||
|
mg_http_serve_file(pNc, (http_message*)p, logFilename.c_str(), mg_mk_str("text/plain"), mg_mk_str(ss.str().c_str()));
|
||||||
// Should never come to this point
|
}
|
||||||
denialReason = "Access denied";
|
else
|
||||||
return false;
|
{
|
||||||
}
|
Json j;
|
||||||
|
std::stringstream ss;
|
||||||
void HttpServer::OnExit()
|
j.CloneFrom(RestResponseTemplates::GetByCode(HTTP_STATUS_CODE::BAD_REQUEST, "Invalid tubio id!"));
|
||||||
{
|
ServeStringToConnection(pNc, j.Render(), (int)HTTP_STATUS_CODE::BAD_REQUEST);
|
||||||
log->cout << "Shutting down http-server...";
|
}
|
||||||
log->Flush();
|
|
||||||
|
return;
|
||||||
mg_mgr_free(pMgr);
|
}
|
||||||
|
|
||||||
return;
|
bool HttpServer::IsConnectionAllowed(std::string peer_address, std::string& denialReason)
|
||||||
}
|
{
|
||||||
|
// Localhost is always allowed!
|
||||||
|
if (peer_address == "127.0.0.1") return true;
|
||||||
std::string HttpServer::FixUnterminatedString(const char* cstr, const std::size_t len)
|
|
||||||
{
|
// Peer is not localhost, but only localhost is allowed!
|
||||||
std::stringstream ss;
|
else if (XGConfig::access.only_allow_localhost)
|
||||||
for (std::size_t i = 0; i < len; i++)
|
{
|
||||||
{
|
denialReason = "Only localhost allowed!";
|
||||||
ss << *(cstr + i);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ss.str();
|
// Let's check if the whitelist is active
|
||||||
}
|
else if (XGConfig::access.enable_whitelist)
|
||||||
|
{
|
||||||
mg_serve_http_opts HttpServer::frontend_serve_opts;
|
// It is. Let's check if our peer is whitelisted
|
||||||
|
for (std::size_t i = 0; i < XGConfig::access.whitelist.size(); i++)
|
||||||
|
{
|
||||||
|
// Whitelist is enabled, and peer is whitelisted
|
||||||
|
if (XGConfig::access.whitelist[i] == peer_address) return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Whitelist is enabled, but peer is NOT whitelisted
|
||||||
|
denialReason = std::string("Not whitelisted! Ask your tubio administrator to whitelist '") + peer_address + "' in order to gain access.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else // Whitelist is NOT enabled and only_allow_localhost is FALSE!
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Should never come to this point
|
||||||
|
denialReason = "Access denied";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void HttpServer::OnExit()
|
||||||
|
{
|
||||||
|
log->cout << "Shutting down http-server...";
|
||||||
|
log->Flush();
|
||||||
|
|
||||||
|
mg_mgr_free(pMgr);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::string HttpServer::FixUnterminatedString(const char* cstr, const std::size_t len)
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
for (std::size_t i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
ss << *(cstr + i);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
mg_serve_http_opts HttpServer::frontend_serve_opts;
|
||||||
|
@ -24,6 +24,7 @@ namespace Rest
|
|||||||
bool InitWebServer();
|
bool InitWebServer();
|
||||||
static void ProcessAPIRequest(struct mg_connection* pNc, int ev, void* p, std::string peerAddress);
|
static void ProcessAPIRequest(struct mg_connection* pNc, int ev, void* p, std::string peerAddress);
|
||||||
static void ServeDownloadeableResource(struct mg_connection* pNc, int ev, void* p, std::string uri);
|
static void ServeDownloadeableResource(struct mg_connection* pNc, int ev, void* p, std::string uri);
|
||||||
|
static void ServeDownloadLog(struct mg_connection* pNc, int ev, void* p, std::string uri);
|
||||||
|
|
||||||
static void EventHandler(struct mg_connection* pNc, int ev, void* p);
|
static void EventHandler(struct mg_connection* pNc, int ev, void* p);
|
||||||
static void ServeStringToConnection(struct mg_connection* c, std::string str, int httpStatusCode = 200);
|
static void ServeStringToConnection(struct mg_connection* c, std::string str, int httpStatusCode = 200);
|
||||||
@ -31,6 +32,8 @@ namespace Rest
|
|||||||
|
|
||||||
static bool IsConnectionAllowed(std::string peer_address, std::string& denialReason);
|
static bool IsConnectionAllowed(std::string peer_address, std::string& denialReason);
|
||||||
|
|
||||||
|
//! Will remove all `, | and && from a string to prevent remote code execution
|
||||||
|
static std::string SanitizeString(std::string in);
|
||||||
|
|
||||||
struct mg_mgr* pMgr;
|
struct mg_mgr* pMgr;
|
||||||
struct mg_connection* pNc;
|
struct mg_connection* pNc;
|
||||||
|
@ -115,11 +115,11 @@ bool RestQueryHandler::QueueDownload(const JsonBlock& request, JsonBlock& respon
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
log->cout << "Queued video \"" << videoUrl << "\"...";
|
|
||||||
log->Flush();
|
|
||||||
|
|
||||||
std::string tubId = DownloadManager::QueueDownload(videoUrl, mode, quality);
|
std::string tubId = DownloadManager::QueueDownload(videoUrl, mode, quality);
|
||||||
|
|
||||||
|
log->cout << "Queued video \"" << videoUrl << "\" with id \"" << tubId << "\"...";
|
||||||
|
log->Flush();
|
||||||
|
|
||||||
responseCode = HTTP_STATUS_CODE::OK;
|
responseCode = HTTP_STATUS_CODE::OK;
|
||||||
responseBody.CloneFrom(RestResponseTemplates::GetByCode(HTTP_STATUS_CODE::OK));
|
responseBody.CloneFrom(RestResponseTemplates::GetByCode(HTTP_STATUS_CODE::OK));
|
||||||
responseBody.Set("message") = "Download queued!";
|
responseBody.Set("message") = "Download queued!";
|
||||||
|
@ -1,195 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
||||||
<ItemGroup Label="ProjectConfigurations">
|
|
||||||
<ProjectConfiguration Include="Debug|Win32">
|
|
||||||
<Configuration>Debug</Configuration>
|
|
||||||
<Platform>Win32</Platform>
|
|
||||||
</ProjectConfiguration>
|
|
||||||
<ProjectConfiguration Include="Release|Win32">
|
|
||||||
<Configuration>Release</Configuration>
|
|
||||||
<Platform>Win32</Platform>
|
|
||||||
</ProjectConfiguration>
|
|
||||||
<ProjectConfiguration Include="Debug|x64">
|
|
||||||
<Configuration>Debug</Configuration>
|
|
||||||
<Platform>x64</Platform>
|
|
||||||
</ProjectConfiguration>
|
|
||||||
<ProjectConfiguration Include="Release|x64">
|
|
||||||
<Configuration>Release</Configuration>
|
|
||||||
<Platform>x64</Platform>
|
|
||||||
</ProjectConfiguration>
|
|
||||||
</ItemGroup>
|
|
||||||
<PropertyGroup Label="Globals">
|
|
||||||
<VCProjectVersion>16.0</VCProjectVersion>
|
|
||||||
<Keyword>Win32Proj</Keyword>
|
|
||||||
<ProjectGuid>{8ae799c5-cb17-4714-a362-d8b9817a723e}</ProjectGuid>
|
|
||||||
<RootNamespace>Tubio</RootNamespace>
|
|
||||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
|
||||||
</PropertyGroup>
|
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
|
||||||
<PlatformToolset>v142</PlatformToolset>
|
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
|
||||||
<PlatformToolset>v142</PlatformToolset>
|
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
|
||||||
<PlatformToolset>v142</PlatformToolset>
|
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
|
||||||
<PlatformToolset>v142</PlatformToolset>
|
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
|
||||||
</PropertyGroup>
|
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
|
||||||
<ImportGroup Label="ExtensionSettings">
|
|
||||||
</ImportGroup>
|
|
||||||
<ImportGroup Label="Shared">
|
|
||||||
</ImportGroup>
|
|
||||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
|
||||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
|
||||||
</ImportGroup>
|
|
||||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
|
||||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
|
||||||
</ImportGroup>
|
|
||||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
|
||||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
|
||||||
</ImportGroup>
|
|
||||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
|
||||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
|
||||||
</ImportGroup>
|
|
||||||
<PropertyGroup Label="UserMacros" />
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
|
||||||
<LinkIncremental>true</LinkIncremental>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
|
||||||
<LinkIncremental>false</LinkIncremental>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
|
||||||
<LinkIncremental>true</LinkIncremental>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
|
||||||
<LinkIncremental>false</LinkIncremental>
|
|
||||||
</PropertyGroup>
|
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
|
||||||
<ClCompile>
|
|
||||||
<WarningLevel>Level3</WarningLevel>
|
|
||||||
<SDLCheck>true</SDLCheck>
|
|
||||||
<PreprocessorDefinitions>_WIN;JASONPP_RENDER_SORTED;_WIN32;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
||||||
<ConformanceMode>true</ConformanceMode>
|
|
||||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
|
||||||
</ClCompile>
|
|
||||||
<Link>
|
|
||||||
<SubSystem>Console</SubSystem>
|
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
|
||||||
<AdditionalDependencies>urlmon.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
|
||||||
</Link>
|
|
||||||
</ItemDefinitionGroup>
|
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
|
||||||
<ClCompile>
|
|
||||||
<WarningLevel>Level3</WarningLevel>
|
|
||||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
|
||||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
|
||||||
<SDLCheck>true</SDLCheck>
|
|
||||||
<PreprocessorDefinitions>_WIN;JASONPP_RENDER_SORTED;_WIN32;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
||||||
<ConformanceMode>true</ConformanceMode>
|
|
||||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
|
||||||
</ClCompile>
|
|
||||||
<Link>
|
|
||||||
<SubSystem>Console</SubSystem>
|
|
||||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
|
||||||
<OptimizeReferences>true</OptimizeReferences>
|
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
|
||||||
<AdditionalDependencies>urlmon.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
|
||||||
</Link>
|
|
||||||
</ItemDefinitionGroup>
|
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
|
||||||
<ClCompile>
|
|
||||||
<WarningLevel>Level3</WarningLevel>
|
|
||||||
<SDLCheck>true</SDLCheck>
|
|
||||||
<PreprocessorDefinitions>_WIN;JASONPP_RENDER_SORTED;_WIN64;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
||||||
<ConformanceMode>true</ConformanceMode>
|
|
||||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
|
||||||
</ClCompile>
|
|
||||||
<Link>
|
|
||||||
<SubSystem>Console</SubSystem>
|
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
|
||||||
<AdditionalDependencies>urlmon.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
|
||||||
</Link>
|
|
||||||
</ItemDefinitionGroup>
|
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
|
||||||
<ClCompile>
|
|
||||||
<WarningLevel>Level3</WarningLevel>
|
|
||||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
|
||||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
|
||||||
<SDLCheck>true</SDLCheck>
|
|
||||||
<PreprocessorDefinitions>_WIN;JASONPP_RENDER_SORTED;_WIN64;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
||||||
<ConformanceMode>true</ConformanceMode>
|
|
||||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
|
||||||
</ClCompile>
|
|
||||||
<Link>
|
|
||||||
<SubSystem>Console</SubSystem>
|
|
||||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
|
||||||
<OptimizeReferences>true</OptimizeReferences>
|
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
|
||||||
<AdditionalDependencies>urlmon.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
|
||||||
</Link>
|
|
||||||
</ItemDefinitionGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<ClCompile Include="ConsoleManager.cpp" />
|
|
||||||
<ClCompile Include="DownloadManager.cpp" />
|
|
||||||
<ClCompile Include="external_dependencies\casenta\mongoose\mongoose.c">
|
|
||||||
<WarningLevel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">TurnOffAllWarnings</WarningLevel>
|
|
||||||
<WarningLevel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">TurnOffAllWarnings</WarningLevel>
|
|
||||||
<WarningLevel Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">TurnOffAllWarnings</WarningLevel>
|
|
||||||
<WarningLevel Condition="'$(Configuration)|$(Platform)'=='Release|x64'">TurnOffAllWarnings</WarningLevel>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="external_dependencies\leonetienne\JasonPP\JasonPP.cpp" />
|
|
||||||
<ClCompile Include="FileSystem.cpp" />
|
|
||||||
<ClCompile Include="Framework.cpp" />
|
|
||||||
<ClCompile Include="Idler.cpp" />
|
|
||||||
<ClCompile Include="Logger.cpp" />
|
|
||||||
<ClCompile Include="LogHistory.cpp" />
|
|
||||||
<ClCompile Include="main.cpp" />
|
|
||||||
<ClCompile Include="RestQueryHandler.cpp" />
|
|
||||||
<ClCompile Include="RestResponseTemplates.cpp" />
|
|
||||||
<ClCompile Include="HttpServer.cpp" />
|
|
||||||
<ClCompile Include="Updater.cpp" />
|
|
||||||
<ClCompile Include="XGConfig.cpp" />
|
|
||||||
<ClCompile Include="XGControl.cpp" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<ClInclude Include="ConsoleManager.h" />
|
|
||||||
<ClInclude Include="DownloadManager.h" />
|
|
||||||
<ClInclude Include="external_dependencies\casenta\mongoose\mongoose.h" />
|
|
||||||
<ClInclude Include="external_dependencies\leonetienne\JasonPP\JasonPP.hpp" />
|
|
||||||
<ClInclude Include="FileSystem.h" />
|
|
||||||
<ClInclude Include="Framework.h" />
|
|
||||||
<ClInclude Include="Idler.h" />
|
|
||||||
<ClInclude Include="Logger.h" />
|
|
||||||
<ClInclude Include="LogHistory.h" />
|
|
||||||
<ClInclude Include="LogTypes.h" />
|
|
||||||
<ClInclude Include="RestQueryHandler.h" />
|
|
||||||
<ClInclude Include="RestResponseTemplates.h" />
|
|
||||||
<ClInclude Include="HttpServer.h" />
|
|
||||||
<ClInclude Include="TimeUnits.h" />
|
|
||||||
<ClInclude Include="Updater.h" />
|
|
||||||
<ClInclude Include="Version.h" />
|
|
||||||
<ClInclude Include="XGConfig.h" />
|
|
||||||
<ClInclude Include="XGControl.h" />
|
|
||||||
</ItemGroup>
|
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
|
||||||
<ImportGroup Label="ExtensionTargets">
|
|
||||||
</ImportGroup>
|
|
||||||
</Project>
|
|
@ -1,126 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
||||||
<ItemGroup>
|
|
||||||
<Filter Include="Quelldateien">
|
|
||||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
|
||||||
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
|
||||||
</Filter>
|
|
||||||
<Filter Include="Headerdateien">
|
|
||||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
|
||||||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
|
||||||
</Filter>
|
|
||||||
<Filter Include="Ressourcendateien">
|
|
||||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
|
||||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
|
||||||
</Filter>
|
|
||||||
<Filter Include="_external_dependencies">
|
|
||||||
<UniqueIdentifier>{714ac1f3-3586-412c-9b83-bf00f08d58ab}</UniqueIdentifier>
|
|
||||||
</Filter>
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<ClCompile Include="main.cpp">
|
|
||||||
<Filter>Quelldateien</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Logger.cpp">
|
|
||||||
<Filter>Quelldateien</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="LogHistory.cpp">
|
|
||||||
<Filter>Quelldateien</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Framework.cpp">
|
|
||||||
<Filter>Quelldateien</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="RestResponseTemplates.cpp">
|
|
||||||
<Filter>Quelldateien</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="RestQueryHandler.cpp">
|
|
||||||
<Filter>Quelldateien</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="XGControl.cpp">
|
|
||||||
<Filter>Quelldateien</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="XGConfig.cpp">
|
|
||||||
<Filter>Quelldateien</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="FileSystem.cpp">
|
|
||||||
<Filter>Quelldateien</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="HttpServer.cpp">
|
|
||||||
<Filter>Quelldateien</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="DownloadManager.cpp">
|
|
||||||
<Filter>Quelldateien</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="ConsoleManager.cpp">
|
|
||||||
<Filter>Quelldateien</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="external_dependencies\casenta\mongoose\mongoose.c">
|
|
||||||
<Filter>_external_dependencies</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="external_dependencies\leonetienne\JasonPP\JasonPP.cpp">
|
|
||||||
<Filter>_external_dependencies</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Updater.cpp">
|
|
||||||
<Filter>Quelldateien</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Idler.cpp">
|
|
||||||
<Filter>Quelldateien</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<ClInclude Include="Logger.h">
|
|
||||||
<Filter>Headerdateien</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="LogHistory.h">
|
|
||||||
<Filter>Headerdateien</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="LogTypes.h">
|
|
||||||
<Filter>Headerdateien</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="Framework.h">
|
|
||||||
<Filter>Headerdateien</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="RestResponseTemplates.h">
|
|
||||||
<Filter>Headerdateien</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="RestQueryHandler.h">
|
|
||||||
<Filter>Headerdateien</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="XGControl.h">
|
|
||||||
<Filter>Headerdateien</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="XGConfig.h">
|
|
||||||
<Filter>Headerdateien</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="FileSystem.h">
|
|
||||||
<Filter>Headerdateien</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="HttpServer.h">
|
|
||||||
<Filter>Headerdateien</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="DownloadManager.h">
|
|
||||||
<Filter>Headerdateien</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="ConsoleManager.h">
|
|
||||||
<Filter>Headerdateien</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="external_dependencies\casenta\mongoose\mongoose.h">
|
|
||||||
<Filter>_external_dependencies</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="external_dependencies\leonetienne\JasonPP\JasonPP.hpp">
|
|
||||||
<Filter>_external_dependencies</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="Updater.h">
|
|
||||||
<Filter>Headerdateien</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="Idler.h">
|
|
||||||
<Filter>Headerdateien</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="TimeUnits.h">
|
|
||||||
<Filter>Headerdateien</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="Version.h">
|
|
||||||
<Filter>Headerdateien</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
</ItemGroup>
|
|
||||||
</Project>
|
|
@ -1,2 +1,2 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#define TUBIO_SERVER_VERSION (0.6)
|
#define TUBIO_SERVER_VERSION (0.66)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "Filesystem.h"
|
#include "FileSystem.h"
|
||||||
#include "external_dependencies/leonetienne/JasonPP/JasonPP.hpp"
|
#include "external_dependencies/leonetienne/JasonPP/JasonPP.hpp"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
|
|
||||||
|
@ -0,0 +1,155 @@
|
|||||||
|
#include "StringTools.h"
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
std::string StringTools::Replace(const std::string& str, const char find, const std::string& subst) {
|
||||||
|
std::stringstream ss;
|
||||||
|
|
||||||
|
for (std::size_t i = 0; i < str.length(); i++)
|
||||||
|
{
|
||||||
|
if (str[i] != find)
|
||||||
|
ss << str[i];
|
||||||
|
else
|
||||||
|
ss << subst;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string StringTools::Replace(const std::string& str, const std::string& find, const std::string& subst) {
|
||||||
|
if (find.length() == 0)
|
||||||
|
return str;
|
||||||
|
|
||||||
|
std::stringstream ss;
|
||||||
|
|
||||||
|
std::size_t posFound = 0;
|
||||||
|
std::size_t lastFound = 0;
|
||||||
|
|
||||||
|
while (posFound != std::string::npos)
|
||||||
|
{
|
||||||
|
lastFound = posFound;
|
||||||
|
posFound = str.find(find, posFound);
|
||||||
|
|
||||||
|
if (posFound != std::string::npos)
|
||||||
|
{
|
||||||
|
ss << str.substr(lastFound, posFound - lastFound) << subst;
|
||||||
|
posFound += find.length();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ss << str.substr(lastFound, (str.length()) - lastFound);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string StringTools::Replace(const std::string& str, const char find, const char subst) {
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << subst;
|
||||||
|
|
||||||
|
return Replace(str, find, ss.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string StringTools::Replace(const std::string& str, const std::string& find, const char subst) {
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << subst;
|
||||||
|
|
||||||
|
return Replace(str, find, ss.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string StringTools::Lower(const std::string& str) {
|
||||||
|
std::stringstream ss;
|
||||||
|
|
||||||
|
for (std::size_t i = 0; i < str.size(); i++)
|
||||||
|
{
|
||||||
|
const char c = str[i];
|
||||||
|
|
||||||
|
// Quick-accept: regular letters
|
||||||
|
if ((c >= 'A') && (c <= 'Z'))
|
||||||
|
ss << (char)(c | 32);
|
||||||
|
|
||||||
|
// Else: keep the character as is
|
||||||
|
else ss << c;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string StringTools::Upper(const std::string& str) {
|
||||||
|
std::stringstream ss;
|
||||||
|
|
||||||
|
for (std::size_t i = 0; i < str.size(); i++)
|
||||||
|
{
|
||||||
|
const char c = str[i];
|
||||||
|
|
||||||
|
// Quick-accept: regular letters
|
||||||
|
if ((c >= 'a') && (c <= 'z'))
|
||||||
|
ss << (char)(c & ~32);
|
||||||
|
|
||||||
|
// Else: keep the character as is
|
||||||
|
else ss << c;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> StringTools::Split(const std::string& str, const std::string& seperator) {
|
||||||
|
std::vector<std::string> toRet;
|
||||||
|
// Quick-accept: str length is 0
|
||||||
|
if (str.length() == 0)
|
||||||
|
toRet.push_back("");
|
||||||
|
|
||||||
|
// Quick-accept: seperator length is 0
|
||||||
|
else if (seperator.length() == 0) {
|
||||||
|
for (const char c : str)
|
||||||
|
toRet.push_back(std::string(&c, (&c) + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
std::size_t idx = 0;
|
||||||
|
while (idx != std::string::npos) {
|
||||||
|
std::size_t lastIdx = idx;
|
||||||
|
idx = str.find(seperator, idx);
|
||||||
|
|
||||||
|
// Grab our substring until the next finding of sep
|
||||||
|
if (idx != std::string::npos) {
|
||||||
|
toRet.push_back(str.substr(
|
||||||
|
lastIdx,
|
||||||
|
idx - lastIdx
|
||||||
|
));
|
||||||
|
|
||||||
|
idx += seperator.length();
|
||||||
|
}
|
||||||
|
// No more seperator found. Grab the rest until the end of the string
|
||||||
|
else {
|
||||||
|
toRet.push_back(str.substr(
|
||||||
|
lastIdx
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return toRet;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string StringTools::PadLeft(const std::string& str, const char pad, const std::size_t len) {
|
||||||
|
std::stringstream ss;
|
||||||
|
|
||||||
|
for (std::size_t i = str.length(); i < len; i++)
|
||||||
|
ss << pad;
|
||||||
|
|
||||||
|
ss << str;
|
||||||
|
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string StringTools::PadRight(const std::string& str, const char pad, const std::size_t len) {
|
||||||
|
std::stringstream ss;
|
||||||
|
|
||||||
|
ss << str;
|
||||||
|
|
||||||
|
for (std::size_t i = str.length(); i < len; i++)
|
||||||
|
ss << pad;
|
||||||
|
|
||||||
|
return ss.str();
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
#ifndef STRINGTOOLS_STRINGTOOLS_H
|
||||||
|
#define STRINGTOOLS_STRINGTOOLS_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
/* Handy utensils to manipulate strings */
|
||||||
|
class StringTools
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//! Will replace every occurence of `find` in `str` by `subst`.
|
||||||
|
static std::string Replace(const std::string& str, const char find, const std::string& subst);
|
||||||
|
|
||||||
|
//! Will replace every occurence of `find` in `str` by `subst`.
|
||||||
|
static std::string Replace(const std::string& str, const std::string& find, const std::string& subst);
|
||||||
|
|
||||||
|
//! Will replace every occurence of `find` in `str` by `subst`.
|
||||||
|
static std::string Replace(const std::string& str, const char find, const char subst);
|
||||||
|
|
||||||
|
//! Will replace every occurence of `find` in `str` by `subst`.
|
||||||
|
static std::string Replace(const std::string& str, const std::string& find, const char subst);
|
||||||
|
|
||||||
|
//! Will make a string all-lowercase.
|
||||||
|
static std::string Lower(const std::string& str);
|
||||||
|
|
||||||
|
//! Will make a string all-uppercase.
|
||||||
|
static std::string Upper(const std::string& str);
|
||||||
|
|
||||||
|
//! Will split a string by a string seperator
|
||||||
|
static std::vector<std::string> Split(const std::string& str, const std::string& seperator);
|
||||||
|
|
||||||
|
//! Will pad a string to the left to length l
|
||||||
|
static std::string PadLeft(const std::string& str, const char pad, const std::size_t len);
|
||||||
|
|
||||||
|
//! Will pad a string to the right to length l
|
||||||
|
static std::string PadRight(const std::string& str, const char pad, const std::size_t len);
|
||||||
|
|
||||||
|
private:
|
||||||
|
// No instanciation! >:(
|
||||||
|
StringTools();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //STRINGTOOLS_STRINGTOOLS_H
|
@ -1,7 +1,45 @@
|
|||||||
#include "Framework.h"
|
#include "Framework.h"
|
||||||
|
|
||||||
|
#ifndef _WIN
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
void Deamonize() {
|
||||||
|
// Fork me, kernel-san :o
|
||||||
|
pid_t fork_res = fork();
|
||||||
|
|
||||||
|
// Error handling...
|
||||||
|
if (fork_res < 0) {
|
||||||
|
std::cerr << "Aww shit! Deamonizing failed! Couldn't get forked..." << std::endl;
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close launcher process...
|
||||||
|
if (fork_res > 0) {
|
||||||
|
std::cout << "Successfully spawned tubio daemon... Exiting launcher gracefully..." << std::endl;
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// And set the daemon process free
|
||||||
|
if (setsid() < 0) {
|
||||||
|
std::cerr << "Aww shit! Deamonizing failed! Couldn't create new session..." << std::endl;
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
#ifndef _WIN
|
||||||
|
// Deamonize();
|
||||||
|
#endif
|
||||||
|
|
||||||
Framework framework;
|
Framework framework;
|
||||||
framework.Run();
|
framework.Run();
|
||||||
|
|
||||||
|
BIN
Tubio/yt-dlp.exe
BIN
Tubio/yt-dlp.exe
Binary file not shown.
@ -1,5 +1,9 @@
|
|||||||
# Chrome Extension for Tubio
|
# Chrome Extension for Tubio
|
||||||
|
Authors note:
|
||||||
|
Since I am no longer using chromium, this is no longer maintained.
|
||||||
|
|
||||||
Adds a context-menu and a popup to download videos instantly.
|
Adds a context-menu and a popup to download videos instantly.
|
||||||
It does not open Tubio for you. It just downloads the videos. But you can click a button in the extensions popup that takes you to Tubio.
|
It does not open Tubio for you. It just downloads the videos. But you can click a button in the extensions popup that takes you to Tubio.
|
||||||
|
|
||||||
For now this is not on the chrome store, but you can easily install unlisted extensions from source as shown [here](https://developer.chrome.com/docs/extensions/mv2/faq/#:~:text=Click%20the%20Chrome%20menu%20icon,a%20packaged%20extension%2C%20and%20more.).
|
For now this is not on the chrome store, but you can easily install unlisted extensions from source as shown [here](https://developer.chrome.com/docs/extensions/mv2/faq/#:~:text=Click%20the%20Chrome%20menu%20icon,a%20packaged%20extension%2C%20and%20more.).
|
||||||
|
|
||||||
|
23
goodies/dockerfiles/Dockerfile
Normal file
23
goodies/dockerfiles/Dockerfile
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
FROM debian
|
||||||
|
MAINTAINER Leon Etienne
|
||||||
|
|
||||||
|
RUN apt-get update
|
||||||
|
|
||||||
|
RUN apt-get install -y \
|
||||||
|
python3 \
|
||||||
|
python3-pip
|
||||||
|
|
||||||
|
RUN pip install \
|
||||||
|
yt-dlp
|
||||||
|
|
||||||
|
RUN apt-get install -y \
|
||||||
|
ffmpeg
|
||||||
|
|
||||||
|
COPY ./entrypoint.sh /app/entrypoint.sh
|
||||||
|
RUN chmod +x /app/entrypoint.sh
|
||||||
|
|
||||||
|
WORKDIR /app/
|
||||||
|
|
||||||
|
ENTRYPOINT ["/app/entrypoint.sh"]
|
||||||
|
CMD ["./Tubio"]
|
||||||
|
|
4
goodies/dockerfiles/README.md
Normal file
4
goodies/dockerfiles/README.md
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# Dockerfiles
|
||||||
|
Here are basic dockerfiles to get an image running.
|
||||||
|
They are expected (all three) to be lying within the same directory as the Tubio executable.
|
||||||
|
|
18
goodies/dockerfiles/docker-compose.yml
Normal file
18
goodies/dockerfiles/docker-compose.yml
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
version: '3'
|
||||||
|
|
||||||
|
services:
|
||||||
|
main:
|
||||||
|
build: .
|
||||||
|
restart: always
|
||||||
|
container_name: tubio
|
||||||
|
volumes:
|
||||||
|
- .:/app
|
||||||
|
- /etc/timezone:/etc/timezone:ro
|
||||||
|
- /etc/localtime:/etc/localtime:ro
|
||||||
|
|
||||||
|
ports:
|
||||||
|
- 80:80
|
||||||
|
|
||||||
|
environment:
|
||||||
|
- TZ=Europe/Berlin
|
||||||
|
|
5
goodies/dockerfiles/entrypoint.sh
Normal file
5
goodies/dockerfiles/entrypoint.sh
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
cd instance
|
||||||
|
exec $@
|
||||||
|
|
@ -1,31 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
g++ \
|
|
||||||
\
|
|
||||||
-std=c++17 \
|
|
||||||
\
|
|
||||||
-D __linux__ \
|
|
||||||
-D JASONPP_RENDER_SORTED \
|
|
||||||
\
|
|
||||||
../Tubio/main.cpp \
|
|
||||||
../Tubio/ConsoleManager.cpp \
|
|
||||||
../Tubio/DownloadManager.cpp \
|
|
||||||
../Tubio/FileSystem.cpp \
|
|
||||||
../Tubio/Framework.cpp \
|
|
||||||
../Tubio/HttpServer.cpp \
|
|
||||||
../Tubio/Logger.cpp \
|
|
||||||
../Tubio/LogHistory.cpp \
|
|
||||||
../Tubio/RestQueryHandler.cpp \
|
|
||||||
../Tubio/RestResponseTemplates.cpp \
|
|
||||||
../Tubio/XGConfig.cpp \
|
|
||||||
../Tubio/XGControl.cpp \
|
|
||||||
../Tubio/Updater.cpp \
|
|
||||||
../Tubio/Idler.cpp \
|
|
||||||
\
|
|
||||||
\
|
|
||||||
../Tubio/external_dependencies/casenta/mongoose/mongoose.c \
|
|
||||||
../Tubio/external_dependencies/leonetienne/JasonPP/JasonPP.cpp \
|
|
||||||
\
|
|
||||||
-lpthread \
|
|
||||||
\
|
|
||||||
-Wall \
|
|
||||||
-o ./tubio.out
|
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user