Permalink
Browse files

publish

  • Loading branch information...
klkvsk committed Apr 1, 2018
0 parents commit 973fd954cb44a5eb95098563f9681199c0e92895
Showing 720 changed files with 62,691 additions and 0 deletions.
@@ -0,0 +1,24 @@
# docker swarm mode requires registry
REGISTRY_PATH=localhost
# production mode (0=dev, 1=prod)
PROD=0
# misc use
SALT=some_random_string
# for getting some debug on prod
SAVE_DEBUG_KEY=fo0o0o0o0
## uncomment to enable torgate
#TORGATE_HOSTNAME=yourhost.onion
#TORGATE_PRIVATE_KEY=key in single line
#TORGATE_ENDPOINT=ip.of.front.end:80
POSTGRES_USER=postgres
POSTGRES_DB=nully
POSTGRES_PASSWORD=passw0rd
# sentry.io error catching
#SENTRY_BACKEND=https://...:...@sentry.io/123456
#SENTRY_FRONTEND=https://...@sentry.io/123456
@@ -0,0 +1,5 @@
.idea
.env
npm-debug.log
node_modules
frontend/dist
@@ -0,0 +1,4 @@
vendor
composer.lock
composer.phar
@@ -0,0 +1,20 @@
FROM ubuntu:16.04
RUN apt-get update && apt-get install -y wget git php-fpm php-memcache php-pgsql php-redis php-gd php-mbstring php-dom php-imagick php-curl php-apcu
RUN mkdir -p /var/www/logs
WORKDIR /src
ADD ./composer.json composer.json
ADD ./config/get-composer.sh config/get-composer.sh
RUN sh config/get-composer.sh
RUN php composer.phar install --no-autoloader
COPY . ./
RUN php composer.phar install --optimize-autoloader --apcu-autoloader
RUN mkdir /images
RUN chmod 777 /images
CMD [ "php-fpm7.0", "-O", "-F", "--fpm-config", "/src/config/php-fpm.conf" ]
@@ -0,0 +1,18 @@
{
"name": "0chan/backend",
"authors": [
{
"name": "anonymous",
"email": "root@null.dev"
}
],
"require": {
"onphp/onphp": "dev-master",
"dapphp/securimage": "^3.6",
"guzzlehttp/guzzle": "^6.2",
"sentry/sentry": "^1.6"
},
"autoload": {
"classmap": ["src/classes", "src/controllers"]
}
}
@@ -0,0 +1,93 @@
<?php
// system settings
error_reporting(E_ALL | E_STRICT);
setlocale(LC_CTYPE, "ru_RU.UTF8");
setlocale(LC_TIME, "ru_RU.UTF8");
date_default_timezone_set('Europe/Moscow');
define('PRODUCTION', getenv('PROD') == '1');
define('SALT', getenv('SALT'));
if (empty(SALT)) {
die('you really should define some random SALT');
}
// paths
define('PATH_BASE', dirname(__FILE__).DIRECTORY_SEPARATOR);
define('PATH_SOURCE', PATH_BASE.'src'.DIRECTORY_SEPARATOR);
if (PRODUCTION) {
define('PATH_WEB', 'https://0chan.hk/');
$saveDebug = false;
if (isset($_SERVER['HTTP_X_DEBUG']) && getenv('SAVE_DEBUG_KEY')
&& ($_SERVER['HTTP_X_DEBUG'] === getenv('SAVE_DEBUG_KEY'))
) {
$saveDebug = true;
}
define('SAVE_DEBUG', $saveDebug);
define('APCU_ENABLED', true);
} else {
// define('PATH_WEB', 'http://192.168.99.100/');
define('PATH_WEB', '//localhost/');
define('SAVE_DEBUG', true);
define('APCU_ENABLED', false);
}
// shared classes
define('PATH_CLASSES', PATH_SOURCE.'classes'.DIRECTORY_SEPARATOR);
define('PATH_CONTROLLERS', PATH_SOURCE.'controllers'.DIRECTORY_SEPARATOR);
define('PATH_TEMPLATES', PATH_SOURCE.'templates'.DIRECTORY_SEPARATOR);
define('PATH_SCRIPTS', PATH_BASE.'console'.DIRECTORY_SEPARATOR.'scripts'.DIRECTORY_SEPARATOR);
define('PATH_TESTS', PATH_BASE.'console'.DIRECTORY_SEPARATOR.'tests'.DIRECTORY_SEPARATOR);
define('PATH_LOGS', '/var/www/logs/');
if (!file_exists(PATH_LOGS)) {
mkdir(PATH_LOGS, 0777, true);
}
// onPHP init
//require PATH_BASE . '../onphp-framework/global.inc.php.tpl';
require PATH_BASE . 'vendor/autoload.php';
require PATH_BASE . 'vendor/onphp/onphp/global.inc.php.tpl';
define('PATH_STORAGE', realpath(PATH_BASE . '../storage') . DIRECTORY_SEPARATOR);
register_shutdown_function( "fatal_handler" );
function fatal_handler() {
$error = error_get_last();
if ($error !== NULL) {
$errno = $error["type"];
$errfile = $error["file"];
$errline = $error["line"];
$errstr = $error["message"];
throw new ErrorException($errstr, $errno, 1, $errfile, $errline);
}
}
// everything else
define('DEFAULT_ENCODING', 'UTF-8');
mb_internal_encoding(DEFAULT_ENCODING);
mb_regex_encoding(DEFAULT_ENCODING);
$dbLink = DB::spawn(
PgSqlX::class,
getenv('POSTGRES_USER'),
getenv('POSTGRES_PASSWORD'),
'db', // hostname
getenv('POSTGRES_DB')
);
$dbLink->setEncoding(DEFAULT_ENCODING);
DBPool::me()->setDefault($dbLink);
DBPool::me()->addLink('main', $dbLink);
// magic_quotes_gpc must be off
define('__LOCAL_DEBUG__', !PRODUCTION);
Cache::setPeer(
// PeclMemcached::create('cache')
RedisCachePeer::create('cache')
);
Cache::setDefaultWorker(CommonDaoWorker::class);
@@ -0,0 +1,17 @@
#!/bin/sh
EXPECTED_SIGNATURE=$(wget https://composer.github.io/installer.sig -O - -q)
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
ACTUAL_SIGNATURE=$(php -r "echo hash_file('SHA384', 'composer-setup.php');")
if [ "$EXPECTED_SIGNATURE" = "$ACTUAL_SIGNATURE" ]
then
php composer-setup.php --quiet
RESULT=$?
rm composer-setup.php
exit $RESULT
else
>&2 echo 'ERROR: Invalid installer signature'
rm composer-setup.php
exit 1
fi
@@ -0,0 +1,17 @@
[global]
pid = /var/run/php7.0-fpm.pid
error_log = /var/log/php7.0-fpm.log
[www]
user = www-data
group = www-data
listen = 9000
clear_env = no
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
php_value[memory_limit] = 128M
php_value[post_max_size] = 15M
php_value[upload_max_filesize] = 10M
@@ -0,0 +1,18 @@
<?php
require dirname(__FILE__) . '/../config.inc.php';
$crontab = [
// script => run every X minutes
'cleanUnpublished' => 1,
'cleanStorageTrash' => 1,
'cleanBoards' => 1,
'countRatings' => 60,
'updateBoardStats' => 1,
];
$minutesNow = floor(time() / 60);
foreach ($crontab as $command => $everyMinutes) {
if ($minutesNow % $everyMinutes === 0) {
passthru('php run.php ' . $command);
}
}
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
cd /src/meta
sh createdb.sh
cd /src/console/
while [ true ]
do
php daemon.php
sleep 60
done
@@ -0,0 +1,16 @@
<?php
require dirname(__FILE__) . '/../config.inc.php';
if ($argc > 1) {
$scriptName = $argv[1];
} else {
die('Usage: php run.php <scriptName>' . PHP_EOL);
}
if ($argc > 2) {
$scriptArgs = array_slice($argv, 2);
} else {
$scriptArgs = [];
}
ConsoleScriptRunner::me()->execScript($scriptName, $scriptArgs);
@@ -0,0 +1,72 @@
<?php
class Script_BuildApiDoc extends ConsoleScript {
public function run() {
// TODO: выдирать инфу из phpdoc-комментов
// TODO: генерить в какой-нибудь markdown-файл
// инклюдим все классы контроллеров
$controllerFileNames =
new RecursiveIteratorIterator(
new RecursiveDirectoryIterator(PATH_CONTROLLERS, RecursiveDirectoryIterator::SKIP_DOTS)
);
foreach ($controllerFileNames as $controllerFileName) {
include_once $controllerFileName;
}
foreach (get_declared_classes() as $className) {
if (is_subclass_of($className, ApiBaseController::class)) {
$this->log($className);
preg_match('/^Api(.+)Controller$/', $className, $matches);
$apiMethodName = lcfirst($matches[1]);
$rc = new ReflectionClass($className);
foreach ($rc->getMethods() as $rm) {
if (preg_match('/^(.+)Action$/', $rm->getName(), $matches)) {
$apiActionName = $matches[1];
$apiParametersInfo = [];
foreach ($rm->getParameters() as $rp) {
$parameter = ' ' . $rp->getName();
if ($rp->getClass()) {
$parameter .= ':' . $rp->getClass()->getName();
}
if ($rp->isDefaultValueAvailable()) {
if ($rp->isDefaultValueConstant()) {
$parameter .= ' (default: ' . $rp->getDefaultValueConstantName() . ')';
} else {
$parameter .= ' (default: ' . var_export($rp->getDefaultValue(), true). ')';
}
}
$apiParametersInfo []= $parameter;
}
$apiEndPoint = ' /' . $apiMethodName . '/';
if ($apiActionName != 'default') {
$apiEndPoint .= $apiActionName . '/';
}
if ($apiParametersInfo) {
$apiEndPoint .= ' (';
} else {
$apiEndPoint .= ' ()';
}
$this->log($apiEndPoint);
foreach ($apiParametersInfo as $apiParameterInfo) {
$this->log($apiParameterInfo);
}
if ($apiParametersInfo) {
$this->log(' )');
}
}
}
$this->log('');
}
}
}
}
Oops, something went wrong.

0 comments on commit 973fd95

Please sign in to comment.