/var/www/html/site/functions.php
function SenseGetInstance() {
if(getenv('SENSE_INSTANCE')) {
$instance = getenv('SENSE_INSTANCE');
} elseif(!isset($_SERVER['HTTP_HOST'])) {
throw new Exception('HTTP_HOST is not available and SENSE_INSTANCE is undefined');
} else {
$host = $_SERVER['HTTP_HOST'];
if(!preg_match('|[a-z]+|i', $host)) {
// Then it's probably just an ELB health check
exit("OK");
}
list($instance,) = explode('.', $host);
}
return $instance;
}
function SenseGetPdo($config): PDO
{
return new PDO("mysql:dbname=".$config->dbName.";host=".$config->dbHost.";port=".$config->dbPort.";charset=utf8", $config->dbUser, $config->dbPass);
}
// This function is called right before $wire is created and after ProcessWireBootConfig()
function SensePostBootConfig($config) {
// Setup Whoops only for HTTP requests
if(isset($_SERVER['HTTP_HOST'])) {
if(getenv('SENSE_MODE') === 'dev') {
// Enabled for dev
senseSetupWhoops($config);
} elseif(strpos($_SERVER['REQUEST_URI'],'/processwire') === 0) {
// Always use Whoops for admin
senseSetupWhoops($config);
}
}
// PW's session init during tests causes errors, allow disabling
if(getenv('SENSE_DISABLE_PW_SESSIONS') === '1') {
$config->sessionAllow = false;
}
/var/www/html/site/functions.php
function SenseGetInstance() {
if(getenv('SENSE_INSTANCE')) {
$instance = getenv('SENSE_INSTANCE');
} elseif(!isset($_SERVER['HTTP_HOST'])) {
throw new Exception('HTTP_HOST is not available and SENSE_INSTANCE is undefined');
} else {
$host = $_SERVER['HTTP_HOST'];
if(!preg_match('|[a-z]+|i', $host)) {
// Then it's probably just an ELB health check
exit("OK");
}
list($instance,) = explode('.', $host);
}
return $instance;
}
function SenseGetPdo($config): PDO
{
return new PDO("mysql:dbname=".$config->dbName.";host=".$config->dbHost.";port=".$config->dbPort.";charset=utf8", $config->dbUser, $config->dbPass);
}
// This function is called right before $wire is created and after ProcessWireBootConfig()
function SensePostBootConfig($config) {
// Setup Whoops only for HTTP requests
if(isset($_SERVER['HTTP_HOST'])) {
if(getenv('SENSE_MODE') === 'dev') {
// Enabled for dev
senseSetupWhoops($config);
} elseif(strpos($_SERVER['REQUEST_URI'],'/processwire') === 0) {
// Always use Whoops for admin
senseSetupWhoops($config);
}
}
// PW's session init during tests causes errors, allow disabling
if(getenv('SENSE_DISABLE_PW_SESSIONS') === '1') {
$config->sessionAllow = false;
}
/var/www/html/site/functions.php
if(!file_exists($config->paths->$key)) {
@mkdir($config->paths->$key);
}
}
// Added to support local dev envs
$config->paths->sessions = $config->paths->assets . "sessions/";
if(!file_exists($config->paths->sessions)) {
@mkdir($config->paths->sessions);
}
if(ini_get('session.save_handler') == 'files') {
ini_set('session.save_path', $config->paths->sessions);
}
// TODO: Solve this some other way, at some point. This is currently done like this because
// we needed a cloud-compatible way of preparing these. These are not sensitive information
// so we could safely cache these using tedivm/stash for an example
// Setup our own PDO to the database - PW has not yet setup it's own database connection
$pdo = SenseGetPdo($config);
// PW defaults
$templateIDs = [3];
$parentIDs = [29];
// Fetch the entities directly from sensesettings
// NOTE: During setup, this table does not exist. This is silently handled by
// a try/catch block in SensePdoGetValue
$query = "SELECT value FROM sensesettings WHERE keyname='ui.login.entities' AND user='global'";
$entities = SenseMultiSplit(SensePdoGetValue($pdo, $query, null, false));
foreach($entities as $entity) {
$query = "SELECT id FROM templates WHERE name=?";
$templateIDs[] = SensePdoGetValue($pdo, $query, $entity);
// Needed so we can find out the parent holding the entities
$query = "SELECT id FROM templates WHERE name=?";
$containerID = SensePdoGetValue($pdo, $query, $entity . '_container');
$query = "SELECT id FROM pages WHERE templates_id=?";
$parentIDs[] = SensePdoGetValue($pdo, $query, $containerID);
/var/www/html/site/config.php
$config->senseCoreRoot . 'Other/',
$config->senseCoreRoot . 'Process/',
$config->senseCoreRoot . 'Service/',
$config->senseCoreRoot . 'Service/DeliveryEngine/Submodules/',
$config->senseCoreRoot . 'Service/ExportEngine/Submodules/',
$config->senseCoreRoot . 'Service/FetchEngine/Submodules/',
$config->senseCoreRoot . 'Service/TransformationEngine/Submodules/',
];
// Since we make a POST from tunnistus.avoine.fi, without this, the browser
// doesn't send the session cookie and you cannot login. This happens only
// with the js-forms + SSO -combo, so hopefully we can remove this some day.
//
// We also need to condition this because browsers require secure
if(getenv("SENSE_MODE") !== 'dev') {
$config->sessionCookieSameSite = 'None';
}
// $config->httpHosts = [];
SensePostBootConfig($config);
/var/www/vendor/processwire/processwire/wire/core/ProcessWire.php
$cfg['styles'] = new FilenameArray();
$cfg['scripts'] = new FilenameArray();
$config = new Config();
$config->setTrackChanges(false);
$config->data($cfg, true);
// Include system config defaults
/** @noinspection PhpIncludeInspection */
require("$rootPath/$wireDir/config.php");
// Include site-specific config settings
$configFile = $sitePath . "config.php";
$configFileDev = $sitePath . "config-dev.php";
if(is_file($configFileDev)) {
/** @noinspection PhpIncludeInspection */
@require($configFileDev);
} else if(is_file($configFile)) {
/** @noinspection PhpIncludeInspection */
@require($configFile);
}
if($httpHost) {
$config->httpHost = $httpHost;
if(!in_array($httpHost, $config->httpHosts)) $config->httpHosts[] = $httpHost;
}
if($scheme) $config->https = ($scheme === 'https');
return $config;
}
}
/var/www/html/index.php
* @version 3.0
*
* Index Versions
* ==============
* 300 Moved much of this file to a ProcessWire::buildConfig() method.
* 252 Extract all fuel to local API vars when in external or cli mode.
* 251 Add $config->debugIf option.
* 250 PW 2.5 support.
*
*/
if(!defined("PROCESSWIRE")) define("PROCESSWIRE", 300); // index version
$rootPath = __DIR__;
if(DIRECTORY_SEPARATOR != '/') $rootPath = str_replace(DIRECTORY_SEPARATOR, '/', $rootPath);
# $composerAutoloader = $rootPath . '/vendor/autoload.php'; // composer autoloader
# if(file_exists($composerAutoloader)) require_once($composerAutoloader);
# if(!class_exists("ProcessWire\\ProcessWire", false)) require_once("$rootPath/wire/core/ProcessWire.php");
require $rootPath . '/../vendor/autoload.php';
$config = ProcessWire::buildConfig($rootPath);
if(!$config->dbName) {
// If ProcessWire is not installed, go to the installer
if(is_file("./install.php") && strtolower($_SERVER['REQUEST_URI']) == strtolower($config->urls->root)) {
require("./install.php");
exit(0);
} else {
header("HTTP/1.1 404 Page Not Found");
echo "404 page not found (no site configuration or install.php available)";
exit(0);
}
}
$process = null;
$wire = null;
try {
// Bootstrap ProcessWire's core and make the API available with $wire
// NOTE: Currently loading our own bootstrap wrapper
require_once __DIR__ . '/AvoineProcessWire.php';