Working with encryption!

pull/11/head
Isaac Grynsztein 7 years ago
parent 162425b702
commit 917235189a

@ -12,7 +12,8 @@
"favicon.ico",
"backend/audio",
"backend/video",
"backend"
"backend",
{ "glob": "default.json", "input": "./", "output": "../backend/config/", "allowOutsideOutDir": true }
],
"index": "index.html",
"main": "main.ts",

@ -3,26 +3,29 @@ var fs = require('fs');
var path = require('path');
var youtubedl = require('youtube-dl');
var config = require('config');
const https = require('https');
var https = require('https');
var express = require("express");
var bodyParser = require("body-parser");
var pem = require('https-pem');
var app = express();
var appAnchor = express();
var hostURL = config.get("YoutubeDL-Material.Host.frontend-url");
var hostPort = config.get("YoutubeDL-Material.Host.backend-port");
var usingEncryption = config.get("YoutubeDL-Material.Encryption.use-encryption");
var basePath = config.get("YoutubeDL-Material.Downloader.path-base");
var audioPath = config.get("YoutubeDL-Material.Downloader.path-audio");
var videoPath = config.get("YoutubeDL-Material.Downloader.path-video");
var frontendUrl = config.get("YoutubeDLMaterial.Host.frontendurl");
var backendUrl = config.get("YoutubeDLMaterial.Host.backendurl")
var backendPort = 17442;
var usingEncryption = config.get("YoutubeDLMaterial.Encryption.use-encryption");
var basePath = config.get("YoutubeDLMaterial.Downloader.path-base");
var audioPath = config.get("YoutubeDLMaterial.Downloader.path-audio");
var videoPath = config.get("YoutubeDLMaterial.Downloader.path-video");
if (usingEncryption)
{
var certFilePath = path.resolve(config.get("YoutubeDL-Material.Encryption.cert-file-path"));
var keyFilePath = path.resolve(config.get("YoutubeDL-Material.Encryption.key-file-path"));
var certFilePath = path.resolve(config.get("YoutubeDLMaterial.Encryption.cert-file-path"));
var keyFilePath = path.resolve(config.get("YoutubeDLMaterial.Encryption.key-file-path"));
var certKeyFile = fs.readFileSync(keyFilePath);
var certFile = fs.readFileSync(certFilePath);
var certKeyFile = fs.readFileSync(certFilePath);
var certFile = fs.readFileSync(keyFilePath);
var options = {
key: certKeyFile,
cert: certFile
@ -34,37 +37,24 @@ if (usingEncryption)
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
appAnchor.use(bodyParser.urlencoded({ extended: false }));
appAnchor.use(bodyParser.json());
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", hostURL);
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
appAnchor.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", hostURL);
res.header("Access-Control-Allow-Origin", frontendUrl);
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
appAnchor.get('/url', function(req, res) {
res.send(JSON.stringify(("localhost" + ":" + hostPort + "/")));
res.end("yes");
});
appAnchor.get('/using-encryption', function(req, res) {
app.get('/using-encryption', function(req, res) {
res.send(usingEncryption);
res.end("yes");
});
app.post('/tomp3', function(req, res) {
var url = req.body.url;
var date = Date.now();
var path = audioPath;
var audiopath = Date.now();
youtubedl.exec(url, ['--no-check-certificate','-o', path + audiopath + ".mp3", '-x', '--audio-format', 'mp3'], {}, function(err, output) {
youtubedl.exec(url, ['-o', path + audiopath + ".mp3", '-x', '--audio-format', 'mp3'], {}, function(err, output) {
if (err) {
audiopath = "-1";
throw err;
@ -81,7 +71,7 @@ app.post('/tomp4', function(req, res) {
var date = Date.now();
var path = videoPath;
var videopath = Date.now();
youtubedl.exec(url, ['--no-check-certificate', '-o', path + videopath + ".mp4", '-f', 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4'], {}, function(err, output) {
youtubedl.exec(url, ['-o', path + videopath + ".mp4", '-f', 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4'], {}, function(err, output) {
if (err) {
videopath = "-1";
throw err;
@ -188,19 +178,17 @@ app.get('/audio/:id', function(req , res){
});
appAnchor.listen(17442,function(){
console.log("Anchor set on 17442");
});
if (usingEncryption)
{
https.createServer(options, app).listen(hostPort, function() {
console.log('HTTPS: Started on PORT ' + hostPort);
https.createServer(options, app).listen(backendPort, function() {
console.log('HTTPS: Anchor set on 17442');
});
}
else
{
app.listen(hostPort,function(){
console.log("HTTP: Started on PORT " + hostPort);
app.listen(backendPort,function(){
console.log("HTTP: Started on PORT " + backendPort);
});
}

@ -2,6 +2,7 @@
"YoutubeDL-Material": {
"Host": {
"frontend-url": "http://localhost:4200",
"backend-url": "youtubedl.grynsztein.com",
"backend-port": "8088"
},
"Encryption": {

@ -1,13 +1,14 @@
{
"YoutubeDL-Material": {
"YoutubeDLMaterial": {
"Host": {
"frontend-url": "http://localhost:4200",
"backend-port": "8088"
"frontendurl": "http://localhost:4200",
"backendurl": "https://youtubedl.grynsztein.com/"
},
"Encryption": {
"use-encryption": false,
"cert-file-path": "fullchain.pem",
"key-file-path": "privkey.pem"
"cert-file-path": "cert.pem",
"key-file-path": "privkey.pem",
"chain-file-path": "chain.pem"
},
"Downloader": {
"path-base": "http://localhost:8088/",

@ -23,20 +23,39 @@ export class AppComponent {
constructor(private postsService: PostsService) {
this.audioOnly = true;
// starts handshake
this.doHandshake();
this.postsService.loadNavItems().subscribe(result => {
var backendUrl = result.YoutubeDLMaterial.Host.backendurl;
this.postsService.path = backendUrl;
this.postsService.startPath = backendUrl;
this.postsService.startPathSSL = backendUrl;
});
}
urlForm = new FormControl('', [Validators.required]);
doHandshake() {
this.postsService.startHandshake().subscribe(url => {
this.postsService.path = "http://" + url;
doHandshake(url: string) {
this.postsService.startHandshake(url).subscribe(theurl => {
this.postsService.path = theurl;
this.postsService.handShakeComplete = true;
console.log("Handshake complete!");
},
error => {
console.log("Initial handshake failed on http.");
this.doHandshakeSSL(url);
});
}
doHandshakeSSL(url: string) {
this.postsService.startHandshakeSSL(url).subscribe(theurl => {
this.postsService.path = theurl;
this.postsService.handShakeComplete = true;
console.log("Handshake complete!");
},
error => {
console.log("Initial handshake failed, make sure port 17442 is open!");
console.log("Initial handshake failed on https too! Make sure port 17442 is open.");
this.postsService.handShakeComplete = false;
});
}
@ -119,3 +138,4 @@ export class AppComponent {
return re.test(str);
}
}

@ -3,8 +3,6 @@ import { NgModule } from '@angular/core';
import {MatNativeDateModule, MatRadioModule, MatInputModule, MatButtonModule, MatSidenavModule, MatIconModule, MatListModule,
MatSnackBarModule, MatCardModule, MatSelectModule, MatToolbarModule, MatCheckboxModule,
MatProgressBarModule } from '@angular/material';
import { NgConfigureModule, ConfigureOptions } from 'ng4-configure/ng4-configure';
import { MyOptions } from './configuration_options.component';
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
import { AppComponent } from './app.component';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';

@ -1,7 +0,0 @@
import { ConfigureOptions } from 'ng4-configure/ng4-configure';
export class MyOptions extends ConfigureOptions {
ConfigurationURL: string = 'assets/config.json';
AppVersion: string = '0.0.0';
BustCache: boolean = false
}

@ -12,15 +12,22 @@ export class PostsService {
audioFolder: string = "";
videoFolder: string = "";
startPath: string = "http://localhost:17442/";
startPathSSL: string = "https://localhost:17442/"
handShakeComplete: boolean = false;
constructor(private http: Http){
console.log('PostsService Initialized...');
}
startHandshake(): Observable<string>
startHandshake(url: string): Observable<string>
{
return this.http.get(this.startPath + "url")
return this.http.get(url + "geturl")
.map(res => res.json());
}
startHandshakeSSL(url: string): Observable<string>
{
return this.http.get(url + "geturl")
.map(res => res.json());
}
@ -57,6 +64,14 @@ export class PostsService {
return this.http.post(this.path + "mp4fileexists",{name: name})
.map(res => res.json());
}
loadNavItems() {
return this.http.get("../../backend/config/default.json")
.map(res => res.json());
//This is optional, you can remove the last line
// if you don't want to log loaded json in
// console.
}
}

Loading…
Cancel
Save