root Apostolos
6 years ago
22 changed files with 11835 additions and 0 deletions
@ -0,0 +1,3 @@ |
|||||
|
|
||||
|
1. Install composer |
||||
|
2. run composer update |
@ -0,0 +1,51 @@ |
|||||
|
{ |
||||
|
"name": "php-http/socket-client", |
||||
|
"description": "Socket client for PHP-HTTP", |
||||
|
"license": "MIT", |
||||
|
"authors": [ |
||||
|
{ |
||||
|
"name": "Joel Wurtz", |
||||
|
"email": "jwurtz@jolicode.com" |
||||
|
} |
||||
|
], |
||||
|
"require": { |
||||
|
"slim/slim": "^3.12", |
||||
|
"slim/php-view": "^2.2", |
||||
|
"monolog/monolog": "^1.24", |
||||
|
"chadicus/slim-oauth2-middleware": "^3.3", |
||||
|
"bshaffer/oauth2-server-php": "^1.11", |
||||
|
"tuupola/cors-middleware": "^0.9.4", |
||||
|
"php-http/guzzle6-adapter": "^2.0", |
||||
|
"symfony/yaml": "^4.3", |
||||
|
"nahid/jsonq": "^5.2", |
||||
|
"respect/validation": "^1.1", |
||||
|
"andrewdyer/slim3-validator": "^0.1.1", |
||||
|
"mongodb/mongodb": "^1.4", |
||||
|
"chadicus/slim-oauth2-routes": "^3.1", |
||||
|
"friendsofphp/php-cs-fixer": "^2.15", |
||||
|
"guzzlehttp/guzzle": "~6.0", |
||||
|
"php-http/httplug": "^2.0", |
||||
|
"php-http/message": "^1.7", |
||||
|
"php-http/client-common": "^2.0", |
||||
|
"php-http/httplug-bundle": "^1.16", |
||||
|
"php-http/curl-client": "^2.0", |
||||
|
"php-http/mock-client": "^1.3", |
||||
|
"php": "^7.1", |
||||
|
"nyholm/psr7": "^1.0", |
||||
|
"psr/http-client": "^1.0", |
||||
|
"symfony/options-resolver": "^2.6 || ^3.0 || ^4.0" |
||||
|
}, |
||||
|
"require-dev": { |
||||
|
"concurrent-php/async-api": "dev-master", |
||||
|
"friendsofphp/php-cs-fixer": "^2.2", |
||||
|
"php-http/client-integration-tests": "dev-master", |
||||
|
"php-http/message": "^1.0", |
||||
|
"php-http/client-common": "^2.0" |
||||
|
}, |
||||
|
"provide": { |
||||
|
"php-http/client-implementation": "1.0" |
||||
|
}, |
||||
|
"minimum-stability": "dev", |
||||
|
"prefer-stable": true |
||||
|
} |
||||
|
|
File diff suppressed because it is too large
@ -0,0 +1,44 @@ |
|||||
|
{ |
||||
|
"name": "slim/slim-skeleton", |
||||
|
"description": "A Slim Framework skeleton application for rapid development", |
||||
|
"keywords": ["microframework", "rest", "router", "psr7"], |
||||
|
"homepage": "http://github.com/slimphp/Slim-Skeleton", |
||||
|
"license": "MIT", |
||||
|
"authors": [ |
||||
|
{ |
||||
|
"name": "Josh Lockhart", |
||||
|
"email": "info@joshlockhart.com", |
||||
|
"homepage": "http://www.joshlockhart.com/" |
||||
|
} |
||||
|
], |
||||
|
"require": { |
||||
|
"php": ">=5.5.0", |
||||
|
"slim/slim": "^3.1", |
||||
|
"slim/php-view": "^2.0", |
||||
|
"monolog/monolog": "^1.17", |
||||
|
"chadicus/slim-oauth2-middleware": "^3.3", |
||||
|
"bshaffer/oauth2-server-php": "^1.10", |
||||
|
"tuupola/cors-middleware": "^0.9.0", |
||||
|
"php-http/guzzle6-adapter": "^1.1", |
||||
|
"symfony/yaml": "^4.2", |
||||
|
"nahid/jsonq": "^5.2", |
||||
|
"respect/validation": "^1.1", |
||||
|
"andrewdyer/slim3-validator": "^0.1.1", |
||||
|
"mongodb/mongodb": "^1.4" |
||||
|
}, |
||||
|
"require-dev": { |
||||
|
"phpunit/phpunit": ">=4.8 < 6.0" |
||||
|
}, |
||||
|
"autoload-dev": { |
||||
|
"psr-4": { |
||||
|
"Tests\\": "tests/" |
||||
|
} |
||||
|
}, |
||||
|
"config": { |
||||
|
"process-timeout" : 0 |
||||
|
}, |
||||
|
"scripts": { |
||||
|
"start": "php -S localhost:8080 -t public", |
||||
|
"test": "phpunit" |
||||
|
} |
||||
|
} |
File diff suppressed because it is too large
@ -0,0 +1,18 @@ |
|||||
|
#!/bin/sh |
||||
|
|
||||
|
EXPECTED_SIGNATURE="$(wget -q -O - https://composer.github.io/installer.sig)" |
||||
|
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 |
||||
|
>&2 echo 'ERROR: Invalid installer signature' |
||||
|
rm composer-setup.php |
||||
|
exit 1 |
||||
|
fi |
||||
|
|
||||
|
php composer-setup.php |
||||
|
RESULT=$? |
||||
|
rm composer-setup.php |
||||
|
cp composer.phar /usr/local/bin/composer |
||||
|
exit $RESULT |
@ -0,0 +1,22 @@ |
|||||
|
<IfModule mod_rewrite.c> |
||||
|
RewriteEngine On |
||||
|
|
||||
|
# Some hosts may require you to use the `RewriteBase` directive. |
||||
|
# Determine the RewriteBase automatically and set it as environment variable. |
||||
|
# If you are using Apache aliases to do mass virtual hosting or installed the |
||||
|
# project in a subdirectory, the base path will be prepended to allow proper |
||||
|
# resolution of the index.php file and to redirect to the correct URI. It will |
||||
|
# work in environments without path prefix as well, providing a safe, one-size |
||||
|
# fits all solution. But as you do not need it in this case, you can comment |
||||
|
# the following 2 lines to eliminate the overhead. |
||||
|
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$ |
||||
|
RewriteRule ^(.*) - [E=BASE:%1] |
||||
|
|
||||
|
# If the above doesn't work you might need to set the `RewriteBase` directive manually, it should be the |
||||
|
# absolute physical path to the directory that contains this htaccess file. |
||||
|
# RewriteBase / |
||||
|
|
||||
|
RewriteCond %{REQUEST_FILENAME} !-f |
||||
|
RewriteCond %{REQUEST_FILENAME} !-d |
||||
|
RewriteRule ^ index.php [QSA,L] |
||||
|
</IfModule> |
@ -0,0 +1,32 @@ |
|||||
|
<?php |
||||
|
if (PHP_SAPI == 'cli-server') { |
||||
|
// To help the built-in PHP dev server, check if the request was actually for |
||||
|
// something which should probably be served as a static file |
||||
|
$url = parse_url($_SERVER['REQUEST_URI']); |
||||
|
$file = __DIR__ . $url['path']; |
||||
|
if (is_file($file)) { |
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
ini_set("error_log",__DIR__ . '/../logs/app.log'); |
||||
|
require __DIR__ . '/../vendor/autoload.php'; |
||||
|
require __DIR__ . '/../vendor/bshaffer/oauth2-server-php/src/OAuth2/Autoloader.php'; |
||||
|
OAuth2\Autoloader::register(); |
||||
|
session_start(); |
||||
|
|
||||
|
// Instantiate the app |
||||
|
$settings = require __DIR__ . '/../src/settings.php'; |
||||
|
$app = new \Slim\App($settings); |
||||
|
|
||||
|
// Set up dependencies |
||||
|
require __DIR__ . '/../src/dependencies.php'; |
||||
|
|
||||
|
// Register middleware |
||||
|
require __DIR__ . '/../src/middleware.php'; |
||||
|
|
||||
|
// Register routes |
||||
|
require __DIR__ . '/../src/routes.php'; |
||||
|
|
||||
|
// Run app |
||||
|
$app->run(); |
@ -0,0 +1,58 @@ |
|||||
|
<?php |
||||
|
// DIC configuration |
||||
|
|
||||
|
$container = $app->getContainer(); |
||||
|
|
||||
|
// view renderer |
||||
|
$container['renderer'] = function ($c) { |
||||
|
$settings = $c->get('settings')['renderer']; |
||||
|
return new Slim\Views\PhpRenderer($settings['template_path']); |
||||
|
}; |
||||
|
|
||||
|
// monolog |
||||
|
$container['logger'] = function ($c) { |
||||
|
$settings = $c->get('settings')['logger']; |
||||
|
$logger = new Monolog\Logger($settings['name']); |
||||
|
$logger->pushProcessor(new Monolog\Processor\UidProcessor()); |
||||
|
$logger->pushHandler(new Monolog\Handler\StreamHandler($settings['path'], $settings['level'])); |
||||
|
return $logger; |
||||
|
}; |
||||
|
$container['db'] = function ($c) { |
||||
|
$db = $c['settings']['db']; |
||||
|
$pdo = new PDO('mysql:host=' . $db['host'] . ';dbname=' . $db['dbname'], |
||||
|
$db['user'], $db['pass']); |
||||
|
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
||||
|
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); |
||||
|
return $pdo; |
||||
|
}; |
||||
|
$container['mongo'] = function ($c) { |
||||
|
$db = $c['settings']['mongo']; |
||||
|
$host=$db['host']; |
||||
|
$user=$db['user']; |
||||
|
$pass=$db['pass']; |
||||
|
$pwd=rawurlencode($db['pass']); |
||||
|
$dbname=$db['dbname']; |
||||
|
//$mongo = new MongoDB\Client("mongodb://$user:$pwd@$host"); |
||||
|
$mongo = new MongoDB\Client("mongodb://$user:$pass@$host"); |
||||
|
|
||||
|
return $mongo; |
||||
|
}; |
||||
|
$container['httpClient'] = function($c) { |
||||
|
$master='http://127.0.0.1:8080'; |
||||
|
$config = [ |
||||
|
'timeout' => 60, |
||||
|
'base_uri' => $master |
||||
|
]; |
||||
|
|
||||
|
$guzzle = new \GuzzleHttp\Client($config); |
||||
|
|
||||
|
return $guzzle; |
||||
|
}; |
||||
|
$container['y2j'] = function($c) { |
||||
|
$y2j = new \Symfony\Component\Yaml\Parser(); |
||||
|
return $y2j; |
||||
|
}; |
||||
|
$container['validationService'] = function () { |
||||
|
return new \Anddye\Validation\Validator(); |
||||
|
}; |
||||
|
|
@ -0,0 +1,32 @@ |
|||||
|
<?php |
||||
|
// Application middleware |
||||
|
|
||||
|
// e.g: $app->add(new \Slim\Csrf\Guard); |
||||
|
|
||||
|
// This is the middleware |
||||
|
// It will add the Access-Control-Allow-Methods header to every request |
||||
|
$app->add(new \Tuupola\Middleware\CorsMiddleware([ |
||||
|
"origin" => ["*"], |
||||
|
"methods" => ["GET", "POST", "PUT", "PATCH", "DELETE"], |
||||
|
"headers.allow" => ["Access-Control-Allow-Origin", "Authorization", "Content-Type","Accept"], |
||||
|
"headers.expose" => [], |
||||
|
"credentials" => false, |
||||
|
"cache" => 0, |
||||
|
"error" => function ($request, $response, $arguments) { |
||||
|
$data["status"] = "error"; |
||||
|
$data["message"] = $arguments["message"]; |
||||
|
return $response |
||||
|
->withHeader("Content-Type", "application/json") |
||||
|
->write(json_encode($data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT)); |
||||
|
}, |
||||
|
])); |
||||
|
/* |
||||
|
$app->add(new Tuupola\Middleware\CorsMiddleware([ |
||||
|
"origin" => ["*"], |
||||
|
"methods" => ["GET", "POST", "PUT", "PATCH", "DELETE"], |
||||
|
"headers.allow" => [], |
||||
|
"headers.expose" => [], |
||||
|
"credentials" => false, |
||||
|
"cache" => 0, |
||||
|
])); |
||||
|
*/ |
@ -0,0 +1,45 @@ |
|||||
|
<?php |
||||
|
|
||||
|
use \Slim\Middleware\HttpBasicAuthentication\PdoAuthenticator; |
||||
|
use Chadicus\Slim\OAuth2\Http\RequestBridge; |
||||
|
use Chadicus\Slim\OAuth2\Http\ResponseBridge; |
||||
|
use Chadicus\Slim\OAuth2\Middleware; |
||||
|
use Tuupola\Middleware\CorsMiddleware; |
||||
|
use Symfony\Component\Yaml\Yaml; |
||||
|
use Symfony\Component\Yaml\Exception\ParseException; |
||||
|
use MongoDB\Client; |
||||
|
|
||||
|
$container = $app->getContainer(); |
||||
|
$Lclient = $container['httpClient']; |
||||
|
$y2j = $container['y2j']; |
||||
|
$MongoClient = $container['mongo']; |
||||
|
$pdo = $container['db']; |
||||
|
|
||||
|
|
||||
|
|
||||
|
$storage = new OAuth2\Storage\Pdo($pdo); |
||||
|
// create the oauth2 server |
||||
|
$server = new OAuth2\Server( |
||||
|
$storage, |
||||
|
[ |
||||
|
'access_lifetime' => 3600, |
||||
|
], |
||||
|
[ |
||||
|
new OAuth2\GrantType\ClientCredentials($storage), |
||||
|
new OAuth2\GrantType\AuthorizationCode($storage), |
||||
|
] |
||||
|
); |
||||
|
|
||||
|
|
||||
|
// create the authorization middlware |
||||
|
$authMiddleware = new Middleware\Authorization($server, $app->getContainer()); |
||||
|
|
||||
|
// Routes |
||||
|
//get |
||||
|
require_once ("routes/get/helloworld.php"); |
||||
|
//post |
||||
|
require_once ("routes/post/token.php"); |
||||
|
require_once ("routes/post/helloworld.php"); |
||||
|
// Catch-all route to serve a 404 Not Found page if none of the routes match |
||||
|
// NOTE: make sure this route is defined last |
||||
|
|
@ -0,0 +1,76 @@ |
|||||
|
<?php |
||||
|
use Slim\Http\Request; |
||||
|
use Slim\Http\Response; |
||||
|
|
||||
|
use GuzzleHttp\Client as LClient; |
||||
|
use Http\Adapter\Guzzle6\Client as LAdapter; |
||||
|
use Psr\Http\Message\ResponseInterface as LResponseInterface; |
||||
|
use GuzzleHttp\Exception\RequestException as LRequestException; |
||||
|
use GuzzleHttp\Psr7\Request as LRequest; |
||||
|
use Http\Client\Exception; |
||||
|
use Nahid\JsonQ\Jsonq; |
||||
|
use Anddye\Validation\Validator; |
||||
|
use Respect\Validation\Exceptions\ValidationException; |
||||
|
use Respect\Validation\Validator as v; |
||||
|
use MongoDB\Client; |
||||
|
|
||||
|
$postCallbackhelloworld = function ($request, $response, $id) use ($app, $server, $MongoClient) { |
||||
|
|
||||
|
// ****************** get user info ********** |
||||
|
$token = $server->getAccessTokenData(OAuth2\Request::createFromGlobals()); |
||||
|
$USER=(string)$token['client_id']; |
||||
|
// ****************** get user info ********** |
||||
|
|
||||
|
// ****************** Get data ********** |
||||
|
$allGetVars = $request->getQueryParams(); |
||||
|
$jsonget=trim($allGetVars["getvars"]); |
||||
|
$jsonget1=json_decode($jsonget,true); |
||||
|
$start=$jsonget1['start']; |
||||
|
$end=$jsonget1['end']; |
||||
|
// ****************** Get data ********** |
||||
|
|
||||
|
// ********************* VALIDATION ********************* |
||||
|
// see post helloword |
||||
|
// ********************* VALIDATION ********************* |
||||
|
|
||||
|
// ****************** make obj for validate data ********** |
||||
|
try { |
||||
|
// ****************** mongo ********** |
||||
|
// example pagination |
||||
|
$mongo = $MongoClient; |
||||
|
$mplaybook = $mongo->lab_db->tasks; |
||||
|
$regex=new MongoDB\BSON\Regex('^' . preg_quote("$USER") . '$'); |
||||
|
$mstart=new MongoDB\BSON\Regex('^' . preg_quote("$start") . '$'); |
||||
|
$mto=new MongoDB\BSON\Regex('^' . preg_quote("$end") . '$'); |
||||
|
$query = array( |
||||
|
'user' => $regex, |
||||
|
'datefrom' => array('$gt' => $start, '$lte' => $end), |
||||
|
'dateto' => array('$gt' => $start, '$lte' => $end), |
||||
|
|
||||
|
); |
||||
|
$match = array( '$match'=>$query); |
||||
|
$findPlaybks = $mplaybook->aggregate(array($match)); |
||||
|
$c=0; |
||||
|
foreach($findPlaybks as $playbook) |
||||
|
{ |
||||
|
$rrr[$c]['_id']=$jsonget['_id']; |
||||
|
$datefrom = $jsonget['datefrom'].' '.$jsonget['timefrom']; |
||||
|
$dateto = $jsonget['dateto'].' '.$jsonget['timeto']; |
||||
|
$rrr[$c]['start']=$datefrom; |
||||
|
$rrr[$c]['end']=$dateto; |
||||
|
$c++; |
||||
|
} |
||||
|
// ****************** mongo ********** |
||||
|
|
||||
|
// ****************** return data ********** |
||||
|
$rr["data"]= $rrr; |
||||
|
$rr["query"]=$query; |
||||
|
$rr["start"]=$start; |
||||
|
$rr["error"][]="ok"; |
||||
|
} catch(ValidationException $exception) { |
||||
|
$rr["error"][]=$exception->getMainMessage(); |
||||
|
} |
||||
|
$response->getBody()->write(json_encode($rr)); |
||||
|
return $response; |
||||
|
}; |
||||
|
$app->get('/helloworld', $postCallbackhelloworld)->add($authMiddleware->withRequiredScope(['superuser', 'owner'])); |
@ -0,0 +1,156 @@ |
|||||
|
<?php |
||||
|
use Slim\Http\Request; |
||||
|
use Slim\Http\Response; |
||||
|
|
||||
|
use GuzzleHttp\Client as LClient; |
||||
|
use Http\Adapter\Guzzle6\Client as LAdapter; |
||||
|
use Psr\Http\Message\ResponseInterface as LResponseInterface; |
||||
|
use GuzzleHttp\Exception\RequestException as LRequestException; |
||||
|
use GuzzleHttp\Psr7\Request as LRequest; |
||||
|
use Http\Client\Exception; |
||||
|
use Nahid\JsonQ\Jsonq; |
||||
|
use Anddye\Validation\Validator; |
||||
|
use Respect\Validation\Exceptions\ValidationException; |
||||
|
use Respect\Validation\Validator as v; |
||||
|
use Respect\Validation\Rules; |
||||
|
use MongoDB\Client; |
||||
|
use Symfony\Component\Yaml\Yaml; |
||||
|
use Symfony\Component\Yaml\Exception\ParseException; |
||||
|
|
||||
|
|
||||
|
$postCallbackHelloworld = function ($request, $response, $id) use ($app, $server, $MongoClient) { |
||||
|
|
||||
|
// ******************** Custom local functions helper ***************************** |
||||
|
|
||||
|
/** |
||||
|
* Creating date collection between two dates |
||||
|
* date_range("2014-01-01", "2014-01-20", "+1 day", "m/d/Y"); |
||||
|
*/ |
||||
|
function date_range($first, $last, $step = '+1 day', $output_format = 'Y/m/d' ) { |
||||
|
$dates = array(); |
||||
|
$current = strtotime($first); |
||||
|
$last = strtotime($last); |
||||
|
while( $current <= $last ) { |
||||
|
$dates[] = date($output_format, $current); |
||||
|
$current = strtotime($step, $current); |
||||
|
} |
||||
|
return $dates; |
||||
|
} |
||||
|
// ******************** Custom function ***************************** |
||||
|
|
||||
|
// ****************** get user info ********** |
||||
|
$token = $server->getAccessTokenData(OAuth2\Request::createFromGlobals()); |
||||
|
$USER=$token['client_id']; |
||||
|
// ****************** get user info ********** |
||||
|
|
||||
|
// ****************** Get data ********** |
||||
|
//$json = $request->getBody(); |
||||
|
$jsonpost = $request->getBody()->getContents(); |
||||
|
$j = json_decode($jsonpost, true); // parse the JSON into an assoc. array |
||||
|
// ****************** Get data ********** |
||||
|
|
||||
|
|
||||
|
// ****************** VALIDATION ********** |
||||
|
$validation_error=true; |
||||
|
try { |
||||
|
// ****************** 1. validate custom ********** |
||||
|
/* |
||||
|
$jname = $j['name']; |
||||
|
|
||||
|
// ******** yamlname valid ***************************** |
||||
|
$r['name'] = new Rules\AllOf( |
||||
|
new Rules\Regex('/^[A-Za-z0-9\-\_]+$/') |
||||
|
); |
||||
|
$r['name']->check($name); |
||||
|
// ******** yamlname valid end |
||||
|
*/ |
||||
|
// ****************** 2. validate ********** |
||||
|
/* |
||||
|
$r = new stdClass; |
||||
|
$r->labid = $lab; |
||||
|
//$r->inventoryid = $labInventoryValue; |
||||
|
// ****************** make obj for validate data ********** |
||||
|
//$rv = v::attribute('labid', v::notEmpty()->alnum()->length(15,32)->noWhitespace()) |
||||
|
// ->attribute('inventoryid',v::notEmpty()->alnum()->length(15,32)->noWhitespace()); |
||||
|
$rv = v::attribute('labid', v::notEmpty()->alnum()->length(15,32)->noWhitespace()); |
||||
|
$rv->check($r); |
||||
|
|
||||
|
*/ |
||||
|
} catch(ValidationException $exception) { |
||||
|
$validation_error=false; |
||||
|
$rr["error"][]=$exception->getMainMessage(); |
||||
|
} |
||||
|
// ****************** VALIDATION ********** |
||||
|
/* |
||||
|
// ****************** MAIN ********** |
||||
|
if($validation_error){ |
||||
|
// --------------- create obj with data ----------- |
||||
|
try { |
||||
|
$user=$USER; |
||||
|
// ****************** mongo ********** |
||||
|
$mongo = $MongoClient; |
||||
|
$mplaybook = $mongo->log->log; |
||||
|
$datetmp=(new \DateTime())->format('Y-m-d H:i:s'); |
||||
|
$inputdate = strtotime($datetmp); |
||||
|
$date = new \MongoDB\BSON\UTCDateTime($inputdate * 1000); |
||||
|
$insertPlaybks1 = $mplaybook1->insertOne([ |
||||
|
'user' => $USER, |
||||
|
'date' => $date |
||||
|
]); |
||||
|
// ****************** mongo ********** |
||||
|
|
||||
|
$rr["action"]='ok'; |
||||
|
$rr["error"][]="ok"; |
||||
|
} catch(ValidationException $exception) { |
||||
|
$rr["action"]='no'; |
||||
|
$rr["error"][]=$exception->getMainMessage(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
$datetmp=(new \DateTime())->format('Y-m-d H:i:s'); |
||||
|
$inputdate = strtotime($datetmp); |
||||
|
$date = new \MongoDB\BSON\UTCDateTime($inputdate * 1000); |
||||
|
$insertPlaybks1 = $mplaybook->insertOne([ |
||||
|
'user' => 'user', |
||||
|
'date' => $date |
||||
|
]); |
||||
|
*/ |
||||
|
try { |
||||
|
|
||||
|
$m=$MongoClient->log->log; |
||||
|
$datetmp=(new \DateTime())->format('Y-m-d H:i:s'); |
||||
|
$inputdate = strtotime($datetmp); |
||||
|
$date = new \MongoDB\BSON\UTCDateTime($inputdate * 1000); |
||||
|
$insert = $m->insertOne([ |
||||
|
'user' => 'user', |
||||
|
'date' => $date |
||||
|
]); |
||||
|
$q = $m->find([ |
||||
|
'user' => 'user' |
||||
|
]); |
||||
|
//var_dump($q); |
||||
|
$c=0; |
||||
|
foreach ($q as $doc) { |
||||
|
$rr['q'][$c]=$doc; // testing comment in production |
||||
|
$c++; |
||||
|
//var_dump($doc); |
||||
|
} |
||||
|
|
||||
|
} catch (MongoDB\Driver\Exception\AuthenticationException $e) { |
||||
|
|
||||
|
echo "Exception:", $e->getMessage(), "\n"; |
||||
|
} catch (MongoDB\Driver\Exception\ConnectionException $e) { |
||||
|
|
||||
|
echo "Exception:", $e->getMessage(), "\n"; |
||||
|
} catch (MongoDB\Driver\Exception\ConnectionTimeoutException $e) { |
||||
|
|
||||
|
echo "Exception:", $e->getMessage(), "\n"; |
||||
|
} |
||||
|
|
||||
|
// ****************** MAIN ********** |
||||
|
$rr['user']=$USER; |
||||
|
$rr['json']=$json; // testing comment in production |
||||
|
$response->getBody()->write(json_encode($rr)); |
||||
|
return $response; |
||||
|
}; |
||||
|
$app->post('/helloworld', $postCallbackHelloworld)->add($authMiddleware->withRequiredScope(['superuser', 'owner'])); |
@ -0,0 +1,7 @@ |
|||||
|
<?php |
||||
|
use Slim\Http\Request; |
||||
|
use Slim\Http\Response; |
||||
|
|
||||
|
$app->post('/token', function (Request $request, Response $response, array $args) use ($app, $server ) { |
||||
|
$server->handleTokenRequest(OAuth2\Request::createFromGlobals())->send(); |
||||
|
}); |
@ -0,0 +1,39 @@ |
|||||
|
<?php |
||||
|
return [ |
||||
|
'settings' => [ |
||||
|
'displayErrorDetails' => true, // set to false in production |
||||
|
'determineRouteBeforeAppMiddleware' => true, |
||||
|
'addContentLengthHeader' => false, // Allow the web server to send the content-length header |
||||
|
|
||||
|
// Renderer settings |
||||
|
'renderer' => [ |
||||
|
'template_path' => __DIR__ . '/../templates/', |
||||
|
], |
||||
|
|
||||
|
// Monolog settings |
||||
|
'logger' => [ |
||||
|
'name' => 'slim-app', |
||||
|
'path' => isset($_ENV['docker']) ? 'php://stdout' : __DIR__ . '/../logs/app.log', |
||||
|
'level' => \Monolog\Logger::DEBUG, |
||||
|
], |
||||
|
// mysql |
||||
|
'db' => [ |
||||
|
'host' => 'mongo_mysql:3306', |
||||
|
'user' => 'dbuser', |
||||
|
'pass' => 'psssssssssssssssss', |
||||
|
'dbname' => 'dbname', |
||||
|
], |
||||
|
// mongo |
||||
|
'mongo' => [ |
||||
|
'host' => 'mongo_node1:27017,mongo_node2:27017,mongo_node3:27017/?replicaSet=replica01', |
||||
|
'user' => 'user', |
||||
|
'pass' => 'psssssssssssssssssss', |
||||
|
'dbname' => 'dbname', |
||||
|
], |
||||
|
// guzzle httpClient settings |
||||
|
'httpClient' => [ |
||||
|
'timeout' => 60, |
||||
|
'base_uri' => 'http://127.0.0.1:8080' |
||||
|
], |
||||
|
], |
||||
|
]; |
@ -0,0 +1,6 @@ |
|||||
|
curl -k -X POST -d "client_id=user&client_secret=pssssssssssssssss&grant_type=client_credentials" https://apiexec1.swarm:8081/token > test.token |
||||
|
token=$(cat test.token | cut -d':' -f2 | cut -d',' -f1 | cut -d'"' -f2) |
||||
|
echo $token |
||||
|
curl -k -X POST https://apiexec1.swarm:8081/helloworld \ |
||||
|
-H "Authorization: Bearer $token" \ |
||||
|
-H "Accept: application/json" |
@ -0,0 +1,46 @@ |
|||||
|
ServerName localhost |
||||
|
<IfModule ssl_module> |
||||
|
SSLRandomSeed startup builtin |
||||
|
SSLRandomSeed connect builtin |
||||
|
</IfModule> |
||||
|
<VirtualHost *:443> |
||||
|
|
||||
|
ServerName apiexec1.swarm |
||||
|
ServerAlias apiexec2.swarm |
||||
|
ServerAlias apiexec3.swarm |
||||
|
|
||||
|
DocumentRoot /var/www/api/public |
||||
|
ErrorLog ${APACHE_LOG_DIR}/error.log |
||||
|
CustomLog ${APACHE_LOG_DIR}/access.log combined |
||||
|
|
||||
|
SSLEngine on |
||||
|
SSLCertificateFile /usr/local/apache2/conf/domain.crt |
||||
|
SSLCertificateKeyFile /usr/local/apache2/conf/domain.key |
||||
|
|
||||
|
SSLCompression off |
||||
|
#SSLProtocol all -SSLv2 -SSLv3 -TLSv1 |
||||
|
SSLProtocol ALL -SSLv2 -SSLv3 |
||||
|
#SSLCipherSuite EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH |
||||
|
SSLCipherSuite ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:RSA+AESGCM:RSA+AES:!aNULL:!MD5:!DSS |
||||
|
SSLHonorCipherOrder on |
||||
|
|
||||
|
<FilesMatch "\.(cgi|shtml|phtml|php)$"> |
||||
|
SSLOptions +StdEnvVars |
||||
|
</FilesMatch> |
||||
|
<Directory /usr/lib/cgi-bin> |
||||
|
SSLOptions +StdEnvVars |
||||
|
</Directory> |
||||
|
|
||||
|
<Directory /var/www/api/public> |
||||
|
AllowOverride All |
||||
|
# changed from None to FileInfo |
||||
|
Order allow,deny |
||||
|
allow from all |
||||
|
</Directory> |
||||
|
|
||||
|
</VirtualHost> |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
@ -0,0 +1 @@ |
|||||
|
GRANT ALL PRIVILEGES ON *.* TO 'user'@'host' IDENTIFIED BY 'psssssssssssssssssssssss' WITH GRANT OPTION; |
File diff suppressed because it is too large
@ -0,0 +1,192 @@ |
|||||
|
# MariaDB database server configuration file. |
||||
|
# |
||||
|
# You can copy this file to one of: |
||||
|
# - "/etc/mysql/my.cnf" to set global options, |
||||
|
# - "~/.my.cnf" to set user-specific options. |
||||
|
# |
||||
|
# One can use all long options that the program supports. |
||||
|
# Run program with --help to get a list of available options and with |
||||
|
# --print-defaults to see which it would actually understand and use. |
||||
|
# |
||||
|
# For explanations see |
||||
|
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html |
||||
|
|
||||
|
# This will be passed to all mysql clients |
||||
|
# It has been reported that passwords should be enclosed with ticks/quotes |
||||
|
# escpecially if they contain "#" chars... |
||||
|
# Remember to edit /etc/mysql/debian.cnf when changing the socket location. |
||||
|
[client] |
||||
|
port = 3306 |
||||
|
socket = /var/run/mysqld/mysqld.sock |
||||
|
|
||||
|
# Here is entries for some specific programs |
||||
|
# The following values assume you have at least 32M ram |
||||
|
|
||||
|
# This was formally known as [safe_mysqld]. Both versions are currently parsed. |
||||
|
[mysqld_safe] |
||||
|
socket = /var/run/mysqld/mysqld.sock |
||||
|
nice = 0 |
||||
|
|
||||
|
[mysqld] |
||||
|
# |
||||
|
# * Basic Settings |
||||
|
# |
||||
|
#user = mysql |
||||
|
pid-file = /var/run/mysqld/mysqld.pid |
||||
|
socket = /var/run/mysqld/mysqld.sock |
||||
|
port = 3306 |
||||
|
basedir = /usr |
||||
|
datadir = /var/lib/mysql |
||||
|
tmpdir = /tmp |
||||
|
lc_messages_dir = /usr/share/mysql |
||||
|
lc_messages = en_US |
||||
|
skip-external-locking |
||||
|
skip-networking=0 |
||||
|
skip-bind-address |
||||
|
# |
||||
|
# Instead of skip-networking the default is now to listen only on |
||||
|
# localhost which is more compatible and is not less secure. |
||||
|
#bind-address = 127.0.0.1 |
||||
|
# |
||||
|
# * Fine Tuning |
||||
|
# |
||||
|
max_connections = 100 |
||||
|
connect_timeout = 5 |
||||
|
wait_timeout = 600 |
||||
|
max_allowed_packet = 16M |
||||
|
thread_cache_size = 128 |
||||
|
sort_buffer_size = 4M |
||||
|
bulk_insert_buffer_size = 16M |
||||
|
tmp_table_size = 32M |
||||
|
max_heap_table_size = 32M |
||||
|
# |
||||
|
# * MyISAM |
||||
|
# |
||||
|
# This replaces the startup script and checks MyISAM tables if needed |
||||
|
# the first time they are touched. On error, make copy and try a repair. |
||||
|
myisam_recover_options = BACKUP |
||||
|
key_buffer_size = 128M |
||||
|
#open-files-limit = 2000 |
||||
|
table_open_cache = 400 |
||||
|
myisam_sort_buffer_size = 512M |
||||
|
concurrent_insert = 2 |
||||
|
read_buffer_size = 2M |
||||
|
read_rnd_buffer_size = 1M |
||||
|
# |
||||
|
# * Query Cache Configuration |
||||
|
# |
||||
|
# Cache only tiny result sets, so we can fit more in the query cache. |
||||
|
query_cache_limit = 128K |
||||
|
query_cache_size = 64M |
||||
|
# for more write intensive setups, set to DEMAND or OFF |
||||
|
#query_cache_type = DEMAND |
||||
|
# |
||||
|
# * Logging and Replication |
||||
|
# |
||||
|
# Both location gets rotated by the cronjob. |
||||
|
# Be aware that this log type is a performance killer. |
||||
|
# As of 5.1 you can enable the log at runtime! |
||||
|
#general_log_file = /var/log/mysql/mysql.log |
||||
|
#general_log = 1 |
||||
|
# |
||||
|
# Error logging goes to syslog due to /etc/mysql/conf.d/mysqld_safe_syslog.cnf. |
||||
|
# |
||||
|
# we do want to know about network errors and such |
||||
|
#log_warnings = 2 |
||||
|
# |
||||
|
# Enable the slow query log to see queries with especially long duration |
||||
|
#slow_query_log[={0|1}] |
||||
|
slow_query_log_file = /var/log/mysql/mariadb-slow.log |
||||
|
long_query_time = 10 |
||||
|
#log_slow_rate_limit = 1000 |
||||
|
#log_slow_verbosity = query_plan |
||||
|
|
||||
|
#log-queries-not-using-indexes |
||||
|
#log_slow_admin_statements |
||||
|
# |
||||
|
# The following can be used as easy to replay backup logs or for replication. |
||||
|
# note: if you are setting up a replication slave, see README.Debian about |
||||
|
# other settings you may need to change. |
||||
|
#server-id = 1 |
||||
|
#report_host = master1 |
||||
|
#auto_increment_increment = 2 |
||||
|
#auto_increment_offset = 1 |
||||
|
#log_bin = /var/log/mysql/mariadb-bin |
||||
|
#log_bin_index = /var/log/mysql/mariadb-bin.index |
||||
|
# not fab for performance, but safer |
||||
|
#sync_binlog = 1 |
||||
|
expire_logs_days = 10 |
||||
|
max_binlog_size = 100M |
||||
|
# slaves |
||||
|
#relay_log = /var/log/mysql/relay-bin |
||||
|
#relay_log_index = /var/log/mysql/relay-bin.index |
||||
|
#relay_log_info_file = /var/log/mysql/relay-bin.info |
||||
|
#log_slave_updates |
||||
|
#read_only |
||||
|
# |
||||
|
# If applications support it, this stricter sql_mode prevents some |
||||
|
# mistakes like inserting invalid dates etc. |
||||
|
#sql_mode = NO_ENGINE_SUBSTITUTION,TRADITIONAL |
||||
|
# |
||||
|
# * InnoDB |
||||
|
# |
||||
|
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/. |
||||
|
# Read the manual for more InnoDB related options. There are many! |
||||
|
default_storage_engine = InnoDB |
||||
|
# you can't just change log file size, requires special procedure |
||||
|
#innodb_log_file_size = 50M |
||||
|
innodb_buffer_pool_size = 256M |
||||
|
innodb_log_buffer_size = 8M |
||||
|
innodb_file_per_table = 1 |
||||
|
innodb_open_files = 400 |
||||
|
innodb_io_capacity = 400 |
||||
|
innodb_flush_method = O_DIRECT |
||||
|
# |
||||
|
# * Security Features |
||||
|
# |
||||
|
# Read the manual, too, if you want chroot! |
||||
|
# chroot = /var/lib/mysql/ |
||||
|
# |
||||
|
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca". |
||||
|
# |
||||
|
# ssl-ca=/etc/mysql/cacert.pem |
||||
|
# ssl-cert=/etc/mysql/server-cert.pem |
||||
|
# ssl-key=/etc/mysql/server-key.pem |
||||
|
|
||||
|
# |
||||
|
# * Galera-related settings |
||||
|
# |
||||
|
[galera] |
||||
|
# Mandatory settings |
||||
|
#wsrep_on=ON |
||||
|
#wsrep_provider= |
||||
|
#wsrep_cluster_address= |
||||
|
#binlog_format=row |
||||
|
#default_storage_engine=InnoDB |
||||
|
#innodb_autoinc_lock_mode=2 |
||||
|
# |
||||
|
# Allow server to accept connections on all interfaces. |
||||
|
# |
||||
|
#bind-address=0.0.0.0 |
||||
|
# |
||||
|
# Optional setting |
||||
|
#wsrep_slave_threads=1 |
||||
|
#innodb_flush_log_at_trx_commit=0 |
||||
|
|
||||
|
[mysqldump] |
||||
|
quick |
||||
|
quote-names |
||||
|
max_allowed_packet = 16M |
||||
|
|
||||
|
[mysql] |
||||
|
#no-auto-rehash # faster start of mysql but no tab completion |
||||
|
|
||||
|
[isamchk] |
||||
|
key_buffer = 16M |
||||
|
|
||||
|
# |
||||
|
# * IMPORTANT: Additional settings that can override those from this file! |
||||
|
# The files must end with '.cnf', otherwise they'll be ignored. |
||||
|
# |
||||
|
!include /etc/mysql/mariadb.cnf |
||||
|
!includedir /etc/mysql/conf.d/ |
@ -0,0 +1,15 @@ |
|||||
|
# have to change the VirtualHost statement in |
||||
|
# /etc/apache2/sites-enabled/000-default.conf |
||||
|
|
||||
|
Listen 443 |
||||
|
|
||||
|
<IfModule ssl_module> |
||||
|
Listen 443 |
||||
|
</IfModule> |
||||
|
|
||||
|
<IfModule mod_gnutls.c> |
||||
|
Listen 443 |
||||
|
</IfModule> |
||||
|
|
||||
|
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet |
||||
|
|
Loading…
Reference in new issue