initial code comit

This commit is contained in:
2018-11-22 21:02:44 +03:00
parent dda0488d4b
commit 801bbd37b7
117 changed files with 7612 additions and 0 deletions

11
system/apps/apps.json Normal file
View File

@@ -0,0 +1,11 @@
{
"Plex" : "plex",
"Transmission" : "transmission",
"Resilio sync" : "rslsync",
"NextCloud" : "nextcloud",
"OwnCloud" : "owncloud",
"Files downloader" : "cai_downloader",
"OpenFire" : "openfire",
"phpMyAdmin" : "phpmyadmin",
"phpPgAdmin" : "phppgadmin"
}

View File

@@ -0,0 +1,16 @@
{
"app_name" : "app_cai_downloader",
"caption" : "Files downloader",
"version" : "1.0.20170705",
"author" : "Alexander I. Chebykin",
"http_uri" : "system/apps/cai_downloader/",
"use_http" : true,
"https_uri" : "system/apps/cai_downloader/",
"use_https" : true,
"frame_support" : true,
"require_php" : true,
"require" : [
{"data" : "php"},
{"data" : "curl"}
]
}

View File

@@ -0,0 +1,32 @@
.full_width {width: 100%}
.hidden {opacity: 0;}
.td_label {width: 100px;}
.del_rec {
position: absolute;
right: 15px;
cursor: pointer;
}
#in_submit {margin: 10px auto;}
#div_download,
#div_log,
.div_log_rec {transition: all 0.5s ease-out 0.1s;}
.div_log_rec span {margin-right: 20px;}
fieldset {
border-width: 1px;
border-color: #ddd;
}
hr {
margin: 5px 0;
padding: 0;
border: 0;
height: 1px;
background-image: -webkit-linear-gradient(left,rgba(0,0,0,0),rgba(0,0,0,0.25),rgba(0,0,0,0));
background-image: -moz-linear-gradient(left,rgba(0,0,0,0),rgba(0,0,0,0.25),rgba(0,0,0,0));
background-image: -ms-linear-gradient(left,rgba(0,0,0,0),rgba(0,0,0,0.25),rgba(0,0,0,0));
background-image: -o-linear-gradient(left,rgba(0,0,0,0),rgba(0,0,0,0.25),rgba(0,0,0,0));
background: linear-gradient(left,rgba(0,0,0,0),rgba(0,0,0,0.25),rgba(0,0,0, 0));
}

View File

@@ -0,0 +1,69 @@
<?php
/**
* CAI CP v.1
*
* @module : Download application
* @author : Alexander I. Chebykin <alex.chebykin@gmail.com>
* @copyright : Copyright (c) 2016-2017 Alexander I. Chebykin
* @version : 1.0
* @build date : 2017-07-17
* @license : MIT
* @link : https://github.com/CAI79/CAI-CP
******************************************************************/
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
require_once('../../../settings.php');
/* Places to store files by type */
$ParentDir = array('.gif' => 'images/_animations/',
'.jpg' => 'images/', '.jpeg' => 'images/', '.png' => 'images/',
'.tif' => 'images/', '.tiff' => 'images/',
'.avi' => 'video/', '.flv' => 'video/', '.mkv' => 'video/',
'.mp4' => 'video/', '.mpeg' => 'video/', '.mpg' => 'video/',
'.exe' => 'soft/', '.msi' => 'soft/',
'.7z' => 'archives/', '.iso' => 'archives/', '.rar' => 'archives/',
'.tar' => 'archives/', '.zip' => 'archives/');
/* Filter parameters */
$Dir = str_replace(array('.', '/', '~', '\\', ' ', '%'),
'_',
filter_input(INPUT_POST, 'dir', FILTER_SANITIZE_STRING)
);
$Overwrite = (int)filter_input(INPUT_POST, 'overwrite', FILTER_SANITIZE_NUMBER_INT);
$URI = filter_input(INPUT_POST, 'uri', FILTER_SANITIZE_URL);
$SubstrPos = 0;
$PDir = '';
foreach ($ParentDir as $Key => $Val) {
if (mb_stripos($URI, $Key) !== false){
$SPos = mb_stripos($URI, $Key);
if ($SubstrPos == 0) {
$SubstrPos = $SPos;
$PDir = $Val;
} else {
if ($SubstrPos < $Pos && $Pos > 0) {
$SubstrPos = $Pos;
$PDir = $Val;
}
}
}
}
if ($Overwrite !== 1 && file_exists(str_replace('\ ', ' ', FILE_DOWNLOAD_DIR) . $PDir . $Dir . '/')) {
$i = 1;
while (file_exists(str_replace('\ ', ' ', FILE_DOWNLOAD_DIR) . $PDir . $Dir . '/' . $i)) {
$i++;
}
$Dir .= '/' . $i;
}
echo exec(sprintf('bash -c "%s > /dev/null 2>&1 &"',
sprintf("./scripts/app.sh %s %s",
FILE_DOWNLOAD_DIR . $PDir . $Dir,
$URI)
)
);
echo '[langDownloadStarted]';

View File

@@ -0,0 +1,3 @@
#! /bin/bash
mkdir -p "$1" && cd "$1" && curl -L -S -O $2 >> download.log 2>&1 &
# mkdir -p "$1" && cd "$1" && curl -L -O $2 > /dev/null 2>&1 &

Binary file not shown.

After

Width:  |  Height:  |  Size: 332 KiB

View File

@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html>
<head>
<title>Files downloader app for CAI CP</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/downloader.css" type="text/css" />
</head>
<body>
<div id="div_download" class="hidden">
<form id="frm_submit" method="post" action="exec/">
<table class="full_width">
<tr><td class="td_label"><label id="lbl_uri" for="uri">[langURI]: </label></td><td><input class="full_width" name="uri" id="uri" type="url" placeholder="http://domain.local/image[1-10].jpg" autofocus required></td></tr>
<tr><td class="td_label"><label id="lbl_dir" for="dir">[langDir]: </label></td><td><input class="full_width" name="dir" id="dir" type="text"></td></tr>
</table>
<input id="lang" name="lang" type="hidden" value="en">
<input name="overwrite" id="overwrite" type="checkbox" value="1"><label id="lbl_overwrite" for="overwrite"> [langOverwrite]</label><br>
<input id="in_submit" type="submit" value="[langGo]">
</form>
</div>
<div id="div_log" class="hidden">
<fieldset id="fs_log">
<legend id="lgn_log">Log</legend>
<div id="div_log_recs"></div>
</fieldset>
</div>
<script src="js/downloader.js"></script>
</body>
</html>

View File

@@ -0,0 +1,206 @@
// MIT License:
//
// Copyright (c) 2016-2017, Alexander I. Chebykin
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
/**
* CAI CP v.1
*
* @module : Downloader app
* @author : Alexander I. Chebykin <alex.chebykin@gmail.com>
* @copyright : Copyright (c) 2016-2017 Alexander I. Chebykin
* @version : 1.0
* @build date : 2017-06-05
* @license : MIT
* @link : https://github.com/CAI79/CAI-CP
******************************************************************/
(function () {
'use strict';
/**
* Return GET parameter from parent page
*
* @param {string} key Key name
*
* returns {string}
*/
function $_PARENT_GET(key) {
// var s = window.location.search;
var s = (window.location !== window.parent.location)
? document.referrer
: document.location.href;
s = s.match(new RegExp(key + '=([^&=]+)'));
return s ? s[1] : false;
}
/**
* Return GET parameter
*
* @param {string} key Key name
*
* returns {string}
*/
function $_GET(key) {
// var s = window.location.search;
var s = document.referrer;
s = s.match(new RegExp(key + '=([^&=]+)'));
return s ? s[1] : false;
}
/**
* Download system constructor
*
* @returns {undefined}
*/
function DownloadSystem() {
this.locales = 'en ru';
this.lang = {};
}
/**
* Download system initialization
*
* @param {string} lang Language code. Ex: en, ru etc.
*
* @returns {undefined}
*/
DownloadSystem.prototype.init = function (lang) {
var dl_instance = this,
json_file = 'locale/',
request = new XMLHttpRequest();
if (this.check_locale(lang)) {
json_file += lang + '.json';
} else {
json_file += 'en.json';
}
if (document.getElementById('lang') !== null) {
document.getElementById('lang').value = lang;
}
if ($_GET('overwrite') && (document.getElementById('overwrite') !== null)) {
document.getElementById('overwrite').checked = true;
}
request.open('GET', json_file);
request.send();
request.onreadystatechange = function () {
if (this.readyState === 4) {
if (this.status === 200) {
dl_instance.lang = JSON.parse(this.responseText);
document.getElementById('lbl_uri').textContent = dl_instance.lang.uri + ': ';
document.getElementById('lbl_dir').textContent = dl_instance.lang.dir + ': ';
document.getElementById('lbl_overwrite').textContent = dl_instance.lang.overwrite;
document.getElementById('lgn_log').textContent = dl_instance.lang.log;
document.getElementById('in_submit').value = dl_instance.lang.go;
document.getElementById('div_download').classList.toggle('hidden');
document.getElementById('div_log').classList.toggle('hidden');
}
}
};
};
/**
* Check locale support
*
* @param {string} locale Locale code to check. Ex: en, ru etc.
*
* @returns {Boolean}
*/
DownloadSystem.prototype.check_locale = function (locale) {
return this.locales.indexOf(locale.toLowerCase()) !== -1;
};
document.addEventListener('DOMContentLoaded', function () {
/**
* Initialize download object
*/
var download = new DownloadSystem();
if ($_GET('lang')) {
download.init($_GET('lang'));
} else if ($_PARENT_GET('lang')) {
download.init($_PARENT_GET('lang'));
} else {
download.init('en');
}
document.getElementById('frm_submit').onsubmit = function () {
var xhr = new XMLHttpRequest(),
msg,
cur_date = new Date();
xhr.onload = function () {
var log_rec = document.createElement('div'),
log_span = document.createElement('span'),
img_del = document.createElement('img'),
hr = document.createElement('hr');
log_rec.classList.add('div_log_rec');
log_rec.classList.add('hidden');
img_del.classList.add('del_rec');
img_del.src = '../../../gfx/buttons/delete.png';
img_del.title = download.lang.del_log_rec;
img_del.addEventListener('click', function () {
this.parentNode.parentNode.removeChild(this.parentNode);
});
log_rec.appendChild(log_span);
log_rec.appendChild(img_del);
log_rec.appendChild(hr);
// document.getElementById('div_log_recs').appendChild(log_rec);
document.getElementById('div_log_recs').insertBefore(log_rec,
document.getElementById('div_log_recs').childNodes[0]);
if (xhr.responseText === '[langDownloadStarted]') {
msg = download.lang.download_started;
} else {
msg = xhr.responseText;
}
log_span.appendChild(document.createTextNode(
cur_date.toLocaleString() + ': ' +
document.getElementById('dir').value + ' (' +
document.getElementById('uri').value + '): ' +
msg
)
);
log_rec.classList.toggle('hidden');
};
xhr.open(this.method, this.action, true);
xhr.send(new FormData(this));
return false;
};
});
}());

View File

@@ -0,0 +1,9 @@
{
"uri" : "URI",
"dir" : "Directory",
"overwrite" : "Overwrite",
"go" : "Go!",
"log" : "Log",
"del_log_rec" : "Delete log record",
"download_started" : "Download started"
}

View File

@@ -0,0 +1,9 @@
{
"uri" : "URI",
"dir" : "Директория",
"overwrite" : "Перезаписать",
"go" : "Поехали!",
"log" : "Журнал",
"del_log_rec" : "Удалить запись журнала",
"download_started" : "Загрузка начата"
}

View File

@@ -0,0 +1,4 @@
Settings
========
Set $DataDir variable value to download dir in exec/index.php file.
Grant write access for this directory to web server.

View File

@@ -0,0 +1,4 @@
Настройка
=========
В файле exec/index.php задайте каталог для загрузки файлов в переменной $DataDir.
Права на каталог должны позволять запись веб-серверу.

16
system/apps/index.php Normal file
View File

@@ -0,0 +1,16 @@
<?php
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
require_once('../settings.php');
$action = filter_input(INPUT_GET, 'do', FILTER_SANITIZE_STRING);
if ($action === 'get_apps') {
$apps = new \CAI\CAICP\Applications(CP_ROOT_REL);
echo $apps->get_avail_json();
} elseif ($action === 'get_enabled_apps') {
$apps = new \CAI\CAICP\Applications(CP_ROOT_REL);
echo $apps->get_enabled_json();
}

View File

@@ -0,0 +1,12 @@
{
"app_name" : "app_nextcloud",
"caption" : "NextCloud",
"http_uri" : "",
"use_http" : false,
"https_uri" : "https://[server_name]/",
"use_https" : true,
"frame_support" : false,
"require" : [
{"data" : "php"}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@@ -0,0 +1,12 @@
{
"app_name" : "app_openfire",
"caption" : "OpenFire",
"http_uri" : "http://[server_name]:9090/",
"use_http" : true,
"https_uri" : "https://[server_name]:9091/",
"use_https" : true,
"frame_support" : false,
"require" : [
{"data" : "openfire"}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

View File

@@ -0,0 +1,12 @@
{
"app_name" : "app_owncloud",
"caption" : "OwnCloud",
"http_uri" : "http://[server_name]/owncloud/",
"use_http" : true,
"https_uri" : "https://[server_name]/owncloud/",
"use_https" : true,
"frame_support" : true,
"require" : [
{"data" : "php"}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@@ -0,0 +1,12 @@
{
"app_name" : "app_phpmyadmin",
"caption" : "phpMyAdmin",
"http_uri" : "",
"use_http" : true,
"https_uri" : "https://[server_name]/phpMyAdmin/",
"use_https" : true,
"frame_support" : false,
"require" : [
{"data" : "php"}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 178 KiB

View File

@@ -0,0 +1,12 @@
{
"app_name" : "app_phppgadmin",
"caption" : "phpPgAdmin",
"http_uri" : "",
"use_http" : true,
"https_uri" : "https://[server_name]/phpPgAdmin/",
"use_https" : true,
"frame_support" : true,
"require" : [
{"data" : "php"}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

12
system/apps/plex/app.json Normal file
View File

@@ -0,0 +1,12 @@
{
"app_name" : "app_plex",
"caption" : "Plex",
"http_uri" : "http://[server_name]:32400/web/index.html",
"use_http" : false,
"https_uri" : "https://[server_name]:32400/web/index.html",
"use_https" : true,
"frame_support" : false,
"require" : [
{"data" : "plexmediaserver"}
]
}

BIN
system/apps/plex/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

View File

@@ -0,0 +1,12 @@
{
"app_name" : "app_rslsync",
"caption" : "Resilio sync",
"http_uri" : "http://[server_name]:8888/",
"use_http" : true,
"https_uri" : "",
"use_https" : true,
"frame_support" : false,
"require" : [
{"data" : "rslsync"}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.6 KiB

View File

@@ -0,0 +1,12 @@
{
"app_name" : "app_transmission",
"caption" : "Transmission",
"http_uri" : "http://[server_name]:9091/",
"use_http" : true,
"https_uri" : "",
"use_https" : false,
"frame_support" : true,
"require" : [
{"data" : "transmission"}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB