2017-08-15 13:54:22 +02:00
global . window = undefined
function getUrls ( env ) {
if ( env . staticUrl ) {
return env . staticUrl + " ws" + env . staticUrl . substring ( 4 )
} else {
return ""
}
}
/ * *
* Renders the initial HTML page to bootstrap Tutanota for different environments
* /
2019-09-13 13:49:11 +02:00
export async function renderHtml ( scripts , env ) {
global . window = ( await import ( "mithril/test-utils/browserMock.js" ) ) . default ( global )
2019-08-16 16:25:01 +02:00
global . requestAnimationFrame = setTimeout
2019-09-13 13:49:11 +02:00
const m = ( await import ( 'mithril' ) ) . default
const render = ( await import ( 'mithril-node-render' ) ) . default
2019-08-16 16:25:01 +02:00
return render (
2018-07-18 16:07:25 +02:00
m ( "html" , [
m ( "head" , [
m ( "meta[charset=utf-8]" ) ,
2018-09-25 16:59:26 +02:00
csp ( m , env ) ,
2018-07-18 16:07:25 +02:00
m ( "meta[name=apple-mobile-web-app-capable][content=yes]" ) ,
m ( "meta[name=mobile-web-app-capable][content=yes]" ) ,
m ( "meta[name=referrer][content=no-referrer]" ) ,
2018-10-24 10:46:52 +02:00
m ( "meta[name=viewport][content=width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover]" ) ,
2019-09-13 13:49:11 +02:00
scripts . map ( ( scriptImport ) => renderScriptImport ( m , scriptImport ) ) ,
2018-07-18 16:07:25 +02:00
m . trust ( "<!-- TutanotaTags -->" ) , // everything from here to </head> is replaced at runtime for custom domains with defined metaTags
2019-04-04 09:40:02 +02:00
m ( "title" , "Mail. Done. Right. Tutanota Login & Sign up for an Ad-free Mailbox" ) , // keep in sync with Env.
m ( "meta[name=description][content=Mail. Done. Right. Make a fresh start in 2019 and get a free mail account that does not abuse your emails for advertising. Tutanota is fast, easy, secure and free of ads.]" ) ,
2019-07-02 16:57:16 +02:00
m ( "link[rel=shortcut icon][type=image/x-icon][href=images/logo-favicon-152.png]" ) ,
2018-07-18 16:07:25 +02:00
m ( "meta[name=application-name][content=Tutanota]" ) ,
2019-07-02 16:57:16 +02:00
m ( "link[rel=apple-touch-icon][sizes=152x152][href=images/logo-favicon-152.png]" ) ,
2018-07-18 16:07:25 +02:00
m ( "link[rel=icon][sizes=192x192][href=/images/logo-favicon-192.png]" ) ,
2017-08-15 13:54:22 +02:00
2018-07-18 16:07:25 +02:00
// twitter
m ( "meta[name=twitter:card][content=summary]" ) ,
m ( "meta[name=twitter:site][content=@TutanotaTeam]" ) ,
m ( "meta[name=twitter:domain][content=tutanota.com]" ) ,
m ( "meta[name=twitter:image][content=https://tutanota.com/images/share_image.png]" ) ,
2017-08-15 13:54:22 +02:00
2018-07-18 16:07:25 +02:00
// facebook
m ( "meta[stream=og:site_name][content=Tutanota]" ) ,
m ( "meta[stream=og:title][content=Secure Emails Become a Breeze]" ) ,
m ( "meta[stream=og:description][content=Get your encrypted mailbox for free and show the Internet spies that you won't make it easy for them! Why? Because you simply can.]" ) ,
m ( "meta[stream=og:locale][content=en_US]" ) ,
m ( "meta[stream=og:url][content=https://tutanota.com/]" ) ,
m ( "meta[stream=og:image][content=https://tutanota.com/images/share_image.png]" ) ,
m ( "meta[stream=article:publisher][content=https://www.facebook.com/tutanota]" ) ,
2017-08-15 13:54:22 +02:00
2018-07-18 16:07:25 +02:00
// google +
m ( "meta[itemprop=name][content=Secure Emails Become a Breeze.]" ) ,
m ( "meta[itemprop=description][content=Get your encrypted mailbox for free and show the Internet spies that you won't make it easy for them! Why? Because you simply can.]" ) ,
m ( "meta[itemprop=image][content=https://tutanota.com/images/share_image.png]" ) ,
2017-08-15 13:54:22 +02:00
2018-07-18 16:07:25 +02:00
m ( "meta[name=apple-itunes-app][content=app-id=id922429609, affiliate-data=10lSfb]" ) ,
] ) ,
m ( "body" , m ( "noscript" ,
2020-12-16 17:51:59 +01:00
"This site requires javascript to be enabled. Please activate it in the settings of your browser." ) )
2018-07-18 16:07:25 +02:00
] )
2019-08-16 16:25:01 +02:00
) . then ( ( html ) => {
delete global . window
return '<!DOCTYPE html>\n' + html
} )
2017-08-15 13:54:22 +02:00
}
2018-09-25 16:59:26 +02:00
const csp = ( m , env ) => {
2019-09-13 13:49:11 +02:00
if ( env . dist ) {
if ( env . mode === "App" || env . mode === "Desktop" ) {
// differences in comparison to web csp:
// * Content Security Policies delivered via a <meta> element may not contain the frame-ancestors directive.
return m ( "meta[http-equiv=Content-Security-Policy][content=default-src 'none'; script-src 'self'; child-src 'self'; font-src 'self'; img-src http: blob: data: *; "
+ ` style-src 'unsafe-inline'; base-uri 'none'; connect-src 'self' ${ getUrls ( env ) } https://tutanota.com;] ` )
} else {
return null
}
2018-07-18 16:07:25 +02:00
} else {
2019-09-13 13:49:11 +02:00
m ( "meta[http-equiv=Content-Security-Policy][content="
+ "default-src * 'unsafe-inline' 'unsafe-eval';"
+ " script-src * 'unsafe-inline' 'unsafe-eval';"
+ ` connect-src 'self' 'unsafe-inline' ${ getUrls ( env ) } ws://localhost:9001; `
+ " img-src * data: blob: 'unsafe-inline';"
+ " media-src * data: blob: 'unsafe-inline';"
+ " frame-src *;"
+ " style-src * 'unsafe-inline';"
+ "]" )
2018-07-18 16:07:25 +02:00
}
}
2019-09-13 13:49:11 +02:00
function renderScriptImport ( m , scriptImport ) {
const { src , type } = scriptImport
const typeString = type ? ` [type= ${ type } ] ` : ""
return m ( ` script[src= ${ src } ] ${ typeString } [defer] ` )
}