Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Mar 15, 2024
1 parent 462dce2 commit a591198
Show file tree
Hide file tree
Showing 11 changed files with 218 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
RewriteEngine On
RewriteRule ^(.*)$ public/$1
3 changes: 3 additions & 0 deletions app/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<FilesMatch "\.(php|php3|php4|php5|phtml|inc)$">
Require all denied
</FilesMatch>
9 changes: 9 additions & 0 deletions app/_config/mimevalidator.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
Name: app-mimeuploadvalidator
After: '#mimeuploadvalidator'
Only:
moduleexists: 'silverstripe/mimevalidator'
---
SilverStripe\Core\Injector\Injector:
SilverStripe\Assets\Upload_Validator:
class: SilverStripe\MimeValidator\MimeUploadValidator
16 changes: 16 additions & 0 deletions app/_config/mysite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
Name: myproject
---
SilverStripe\Core\Manifest\ModuleManifest:
project: app

# UTF8MB4 has limited support in older MySQL versions.
# Remove this configuration if you experience issues.
---
Name: myproject-database
---
SilverStripe\ORM\Connect\MySQLDatabase:
connection_charset: utf8mb4
connection_collation: utf8mb4_unicode_ci
charset: utf8mb4
collation: utf8mb4_unicode_ci
13 changes: 13 additions & 0 deletions app/src/Page.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace {

use SilverStripe\CMS\Model\SiteTree;

class Page extends SiteTree
{
private static $db = [];

private static $has_one = [];
}
}
37 changes: 37 additions & 0 deletions app/src/PageController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace {

use SilverStripe\CMS\Controllers\ContentController;

/**
* @template T of Page
* @extends ContentController<T>
*/
class PageController extends ContentController
{
/**
* An array of actions that can be accessed via a request. Each array element should be an action name, and the
* permissions or conditions required to allow the user to access it.
*
* <code>
* [
* 'action', // anyone can access this action
* 'action' => true, // same as above
* 'action' => 'ADMIN', // you must have ADMIN permissions to access this action
* 'action' => '->checkAction' // you can only access this action if $this->checkAction() returns true
* ];
* </code>
*
* @var array
*/
private static $allowed_actions = [];

protected function init()
{
parent::init();
// You can include any CSS or JS required by your project here.
// See: https://docs.silverstripe.org/en/developer_guides/templates/requirements/
}
}
}
23 changes: 20 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"silverstripe-themes/simple": "3.x-dev",
"silverstripe/login-forms": "5.x-dev",
"dnadesign/silverstripe-elemental": "dev-pulls/5/inline-validation as 5.x-dev",
"silverstripe/frameworktest": "1.x-dev",
"silverstripe/recipe-testing": "^3",
"mikey179/vfsstream": "^1.6.10",
"silverstripe/admin": "dev-pulls/2/bypass-entwine as 2.x-dev"
"silverstripe/admin": "dev-pulls/2/bypass-entwine as 2.x-dev",
"silverstripe/frameworktest": "dev-pulls/1/elemental as 1.x-dev"
},
"require-dev": {
"phpunit/phpunit": "^9.6"
Expand All @@ -27,6 +27,19 @@
"public-files": [
"assets/*",
"favicon.ico"
],
"project-files-installed": [
".htaccess",
"app/.htaccess",
"app/_config/mimevalidator.yml",
"app/_config/mysite.yml",
"app/src/Page.php",
"app/src/PageController.php"
],
"public-files-installed": [
".htaccess",
"index.php",
"web.config"
]
},
"config": {
Expand All @@ -50,6 +63,10 @@
"x1": {
"type": "vcs",
"url": "[email protected]:creative-commoners/silverstripe-admin"
},
"x3": {
"type": "vcs",
"url": "[email protected]:creative-commoners/silverstripe-frameworktest"
}
},
"conflict": {
Expand All @@ -59,4 +76,4 @@
"symfony/service-contracts": "3.2.1",
"symfony/translation-contracts": "3.2.1"
}
}
}
29 changes: 16 additions & 13 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions public/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
### SILVERSTRIPE START ###

# Deny access to templates (but allow from localhost)
<Files *.ss>
Require ip 127.0.0.1
</Files>

# Deny access to IIS configuration
<Files web.config>
Require all denied
</Files>

# Deny access to YAML configuration files which might include sensitive information
<Files ~ "\.ya?ml$">
Require all denied
</Files>

# Route errors to static pages automatically generated by SilverStripe
ErrorDocument 404 /assets/error-404.html
ErrorDocument 500 /assets/error-500.html

<IfModule mod_rewrite.c>

# Turn off index.php handling requests to the homepage fixes issue in apache >=2.4
<IfModule mod_dir.c>
DirectoryIndex disabled
DirectorySlash On
</IfModule>

SetEnv HTTP_MOD_REWRITE On
RewriteEngine On

# Enable HTTP Basic authentication workaround for PHP running in CGI mode
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

# Deny access to potentially sensitive files and folders
RewriteRule ^vendor(/|$) - [F,L,NC]
RewriteRule ^\.env - [F,L,NC]
RewriteRule silverstripe-cache(/|$) - [F,L,NC]
RewriteRule composer\.(json|lock) - [F,L,NC]
RewriteRule (error|silverstripe|debug)\.log - [F,L,NC]

# Process through SilverStripe if no file with the requested name exists.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php
</IfModule>
### SILVERSTRIPE END ###
25 changes: 25 additions & 0 deletions public/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

use SilverStripe\Control\HTTPApplication;
use SilverStripe\Control\HTTPRequestBuilder;
use SilverStripe\Core\CoreKernel;

// Find autoload.php
if (file_exists(__DIR__ . '/../vendor/autoload.php')) {
require __DIR__ . '/../vendor/autoload.php';
} elseif (file_exists(__DIR__ . '/vendor/autoload.php')) {
require __DIR__ . '/vendor/autoload.php';
} else {
header('HTTP/1.1 500 Internal Server Error');
echo "autoload.php not found";
exit(1);
}

// Build request and detect flush
$request = HTTPRequestBuilder::createFromEnvironment();

// Default application
$kernel = new CoreKernel(BASE_PATH);
$app = new HTTPApplication($kernel);
$response = $app->handle($request);
$response->output();
30 changes: 30 additions & 0 deletions public/web.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!-- Routing configuration for Microsoft IIS web server -->
<configuration>
<system.webServer>
<security>
<requestFiltering>
<hiddenSegments>
<add segment=".env" />
<add segment="silverstripe-cache" />
<add segment="composer.json" />
<add segment="composer.lock" />
</hiddenSegments>
<fileExtensions allowUnlisted="true" >
<add fileExtension=".ss" allowed="false"/>
<add fileExtension=".yml" allowed="false"/>
</fileExtensions>
</requestFiltering>
</security>
<rewrite>
<rules>
<rule name="SilverStripe Clean URLs" stopProcessing="true">
<match url="^(.*)$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

0 comments on commit a591198

Please sign in to comment.