mirror of
https://github.com/HeyPuter/puter
synced 2024-11-14 22:06:00 +00:00
feat: start directory index frame
This commit is contained in:
parent
581964b655
commit
fb1e2f21fb
@ -27,10 +27,13 @@ const { LLRead } = require("../../filesystem/ll_operations/ll_read");
|
||||
const { Actor, UserActorType, SiteActorType } = require("../../services/auth/Actor");
|
||||
const APIError = require("../../api/APIError");
|
||||
|
||||
const AT_DIRECTORY_NAMESPACE = '4aa6dc52-34c1-4b8a-b63c-a62b27f727cf';
|
||||
|
||||
class PuterSiteMiddleware extends AdvancedBase {
|
||||
static MODULES = {
|
||||
path: require('path'),
|
||||
mime: require('mime-types'),
|
||||
uuidv5: require('uuid').v5,
|
||||
}
|
||||
install (app) {
|
||||
app.use(this.run.bind(this));
|
||||
@ -66,9 +69,39 @@ class PuterSiteMiddleware extends AdvancedBase {
|
||||
|
||||
const context = Context.get();
|
||||
const services = context.get('services');
|
||||
|
||||
const get_username_site = (async () => {
|
||||
if ( ! subdomain.endsWith('.at') ) return;
|
||||
const parts = subdomain.split('.');
|
||||
if ( parts.length !== 2 ) return;
|
||||
const username = parts[0];
|
||||
if ( ! username.match(config.username_regex) ) {
|
||||
return;
|
||||
}
|
||||
const svc_fs = services.get('filesystem');
|
||||
const index_node = await svc_fs.node(new NodePathSelector(
|
||||
`/${username}/Public/index.html`
|
||||
));
|
||||
const node = await svc_fs.node(new NodePathSelector(
|
||||
`/${username}/Public`
|
||||
));
|
||||
if ( ! await index_node.exists() ) return;
|
||||
|
||||
return {
|
||||
name: username + '.at',
|
||||
uuid: this.modules.uuidv5(username, AT_DIRECTORY_NAMESPACE),
|
||||
root_dir_id: await node.get('mysql-id'),
|
||||
};
|
||||
})
|
||||
|
||||
const site =
|
||||
await get_username_site() ||
|
||||
await (async () => {
|
||||
const svc_puterSite = services.get('puter-site');
|
||||
const site = await svc_puterSite.get_subdomain(subdomain);
|
||||
return site;
|
||||
})();
|
||||
|
||||
const svc_puterSite = services.get('puter-site');
|
||||
const site = await svc_puterSite.get_subdomain(subdomain);
|
||||
if ( site === null ) {
|
||||
return res.status(404).send('Subdomain not found');
|
||||
}
|
||||
|
@ -75,6 +75,8 @@ class PuterHomepageService extends BaseService {
|
||||
app_name_regex: config.app_name_regex,
|
||||
app_name_max_length: config.app_name_max_length,
|
||||
app_title_max_length: config.app_title_max_length,
|
||||
hosting_domain: config.static_hosting_domain +
|
||||
(config.pub_port !== 80 && config.pub_port !== 443 ? ':' + config.pub_port : ''),
|
||||
subdomain_regex: config.subdomain_regex,
|
||||
subdomain_max_length: config.subdomain_max_length,
|
||||
domain: config.domain,
|
||||
|
@ -314,7 +314,11 @@ class WebServerService extends BaseService {
|
||||
// Validate host header against allowed domains to prevent host header injection
|
||||
// https://www.owasp.org/index.php/Host_Header_Injection
|
||||
app.use((req, res, next)=>{
|
||||
const allowedDomains = [config.domain.toLowerCase(), config.static_hosting_domain.toLowerCase()];
|
||||
const allowedDomains = [
|
||||
config.domain.toLowerCase(),
|
||||
config.static_hosting_domain.toLowerCase(),
|
||||
'at.' + config.static_hosting_domain.toLowerCase(),
|
||||
];
|
||||
|
||||
// Retrieve the Host header and ensure it's in a valid format
|
||||
const hostHeader = req.headers.host;
|
||||
|
Loading…
Reference in New Issue
Block a user