mirror of
				https://github.com/mail-in-a-box/mailinabox.git
				synced 2025-10-25 18:00:54 +00:00 
			
		
		
		
	add instructions for static web hosting into the control panel
This commit is contained in:
		
							parent
							
								
									bf9b770255
								
							
						
					
					
						commit
						6ab29c3244
					
				| @ -74,6 +74,7 @@ def index(): | |||||||
| 	no_admins_exist = (len([user for user in get_mail_users(env, as_json=True) if "admin" in user['privileges']]) == 0) | 	no_admins_exist = (len([user for user in get_mail_users(env, as_json=True) if "admin" in user['privileges']]) == 0) | ||||||
| 	return render_template('index.html', | 	return render_template('index.html', | ||||||
| 		hostname=env['PRIMARY_HOSTNAME'], | 		hostname=env['PRIMARY_HOSTNAME'], | ||||||
|  | 		storage_root=env['STORAGE_ROOT'], | ||||||
| 		no_admins_exist=no_admins_exist, | 		no_admins_exist=no_admins_exist, | ||||||
| 	) | 	) | ||||||
| 
 | 
 | ||||||
| @ -227,6 +228,12 @@ def dns_get_dump(): | |||||||
| 
 | 
 | ||||||
| # WEB | # WEB | ||||||
| 
 | 
 | ||||||
|  | @app.route('/web/domains') | ||||||
|  | @authorized_personnel_only | ||||||
|  | def web_get_domains(): | ||||||
|  | 	from web_update import get_web_domains_info | ||||||
|  | 	return json_response(get_web_domains_info(env)) | ||||||
|  | 
 | ||||||
| @app.route('/web/update', methods=['POST']) | @app.route('/web/update', methods=['POST']) | ||||||
| @authorized_personnel_only | @authorized_personnel_only | ||||||
| def web_update(): | def web_update(): | ||||||
|  | |||||||
| @ -60,6 +60,10 @@ | |||||||
|             table.table { |             table.table { | ||||||
|               margin: 1.5em 0; |               margin: 1.5em 0; | ||||||
|             } |             } | ||||||
|  | 
 | ||||||
|  | 	    ol li { | ||||||
|  | 	       margin-bottom: 1em; | ||||||
|  | 	    } | ||||||
|         </style> |         </style> | ||||||
|         <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css"> |         <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css"> | ||||||
|         <style> |         <style> | ||||||
| @ -101,6 +105,7 @@ | |||||||
|               </ul> |               </ul> | ||||||
|             </li> |             </li> | ||||||
|             <li><a href="#sync_guide" onclick="return show_panel(this);">Contacts/Calendar</a></li> |             <li><a href="#sync_guide" onclick="return show_panel(this);">Contacts/Calendar</a></li> | ||||||
|  |             <li><a href="#web" onclick="return show_panel(this);">Web</a></li> | ||||||
|           </ul> |           </ul> | ||||||
|           <ul class="nav navbar-nav navbar-right"> |           <ul class="nav navbar-nav navbar-right"> | ||||||
|             <li><a href="#" onclick="do_logout(); return false;" style="color: white">Log out?</a></li> |             <li><a href="#" onclick="do_logout(); return false;" style="color: white">Log out?</a></li> | ||||||
| @ -146,6 +151,10 @@ | |||||||
|       {% include "sync-guide.html" %} |       {% include "sync-guide.html" %} | ||||||
|       </div> |       </div> | ||||||
| 
 | 
 | ||||||
|  |       <div id="panel_web" class="container panel"> | ||||||
|  |       {% include "web.html" %} | ||||||
|  |       </div> | ||||||
|  | 
 | ||||||
|       <hr> |       <hr> | ||||||
| 
 | 
 | ||||||
|       <footer> |       <footer> | ||||||
|  | |||||||
							
								
								
									
										100
									
								
								management/templates/web.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										100
									
								
								management/templates/web.html
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,100 @@ | |||||||
|  | <style> | ||||||
|  | </style> | ||||||
|  | 
 | ||||||
|  | <h2>Static Web Hosting</h2> | ||||||
|  | 
 | ||||||
|  | <p>This machine is serving a simple, static website at <a href="https://{{hostname}}">https://{{hostname}}</a> and at all domain names that you set up an email user or alias for.</p> | ||||||
|  | 
 | ||||||
|  | <h3>Uploading web files</h3> | ||||||
|  | 
 | ||||||
|  | <p>You can replace this website with your own HTML or other static files:</p> | ||||||
|  | 
 | ||||||
|  | <ol> | ||||||
|  | <li>Ensure that the domains and SSL certificates are configured properly on the <a href="#system_status" onclick="return show_panel(this);">Status Checks</a> page.</li> | ||||||
|  | 
 | ||||||
|  | <li>Install an SSH file transfer program such as <a href="https://filezilla-project.org/">FileZilla</a> or <a href="http://linuxcommand.org/man_pages/scp1.html">scp</a>.</li> | ||||||
|  | 
 | ||||||
|  | <li>Log in with the file transfer program. The server is <strong>{{hostname}}</strong>, the protocol is SSH or SFTP, and use the <strong>SSH login credentials</strong> that you used when you originally created this machine at your cloud host provider. This is <strong>not</strong> what you use to log in either for email or this control panel. Your SSH credentials probably involves a private key file.</li> | ||||||
|  | 
 | ||||||
|  | <li>Replace the files in <tt>{{storage_root}}/www/default</tt>, or the directory indicated in the table below, with any HTML pages or other static files. They will appear directly and immediately on the web.</li> | ||||||
|  | 
 | ||||||
|  | <table id="web_domains_existing" class="table" style="margin-bottom: 2em; width: auto;"> | ||||||
|  |         <thead> | ||||||
|  |                 <tr> | ||||||
|  |                         <th>Site</th> | ||||||
|  |                         <th>Directory for Files</th> | ||||||
|  |                 </tr> | ||||||
|  |         </thead> | ||||||
|  |         <tbody> | ||||||
|  |         </tbody> | ||||||
|  | </table> | ||||||
|  | 
 | ||||||
|  | <li>If you want to have this box host a static website on a domain that is not listed in the table, create a dummy <a href="#users" onclick="return show_panel(this);">mail user</a> or <a href="#aliases" onclick="return show_panel(this);">alias</a> on the domain first.</li> | ||||||
|  | 
 | ||||||
|  | </ol> | ||||||
|  | 
 | ||||||
|  | <h3>Different sites for different domains</h3> | ||||||
|  | 
 | ||||||
|  | <p>Create one of the directories shown in the table below to create a space for different files for one of the websites.</p> | ||||||
|  | 
 | ||||||
|  | <p>After you create one of these directories, click <button id="web_update" class="btn btn-primary" onclick="do_web_update()">Web Update</button> to restart the box’s web server so that it sees the new website file location.</p> | ||||||
|  | 
 | ||||||
|  | <table id="web_domains_custom" class="table" style="margin-bottom: 2em; width: auto;"> | ||||||
|  |         <thead> | ||||||
|  |                 <tr> | ||||||
|  |                         <th>Site</th> | ||||||
|  |                         <th>Create Directory</th> | ||||||
|  |                 </tr> | ||||||
|  |         </thead> | ||||||
|  |         <tbody> | ||||||
|  |         </tbody> | ||||||
|  | </table> | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | <script> | ||||||
|  | function show_web() { | ||||||
|  |  api( | ||||||
|  |     "/web/domains", | ||||||
|  |     "GET", | ||||||
|  |     { | ||||||
|  |     }, | ||||||
|  |     function(domains) { | ||||||
|  | 	var tb = $('#web_domains_existing tbody'); | ||||||
|  | 	tb.text(''); | ||||||
|  | 	for (var i = 0; i < domains.length; i++) { | ||||||
|  | 		var row = $("<tr><td class='domain'><a href=''></a></td><td class='directory'/></tr>"); | ||||||
|  | 		tb.append(row); | ||||||
|  | 		row.find('.domain a').text('https://' + domains[i].domain); | ||||||
|  | 		row.find('.domain a').attr('href', 'https://' + domains[i].domain); | ||||||
|  | 		row.find('.directory').text(domains[i].root); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	tb = $('#web_domains_custom tbody'); | ||||||
|  | 	tb.text(''); | ||||||
|  | 	for (var i = 0; i < domains.length; i++) { | ||||||
|  | 		if (domains[i].root != domains[i].custom_root) { | ||||||
|  | 			var row = $("<tr><td class='domain'><a href=''></a></td><td class='directory'/></tr>"); | ||||||
|  | 			tb.append(row); | ||||||
|  | 			row.find('.domain a').text('https://' + domains[i].domain); | ||||||
|  | 			row.find('.domain a').attr('href', 'https://' + domains[i].domain); | ||||||
|  | 			row.find('.directory').text(domains[i].custom_root); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  |     }); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | function do_web_update() { | ||||||
|  |  api( | ||||||
|  |     "/web/update", | ||||||
|  |     "POST", | ||||||
|  |     { | ||||||
|  |     }, | ||||||
|  |     function(data) { | ||||||
|  |       if (data == "") | ||||||
|  |         data = "Nothing changed."; | ||||||
|  |       else | ||||||
|  |         data = $("<pre/>").text(data); | ||||||
|  |       show_modal_error("Web Update", data, function() { show_web() }); | ||||||
|  |     }); | ||||||
|  | } | ||||||
|  | </script> | ||||||
| @ -113,11 +113,11 @@ def make_domain_config(domain, template, template_for_primaryhost, env): | |||||||
| 
 | 
 | ||||||
| 	return nginx_conf | 	return nginx_conf | ||||||
| 
 | 
 | ||||||
| def get_web_root(domain, env): | def get_web_root(domain, env, test_exists=True): | ||||||
| 	# Try STORAGE_ROOT/web/domain_name if it exists, but fall back to STORAGE_ROOT/web/default. | 	# Try STORAGE_ROOT/web/domain_name if it exists, but fall back to STORAGE_ROOT/web/default. | ||||||
| 	for test_domain in (domain, 'default'): | 	for test_domain in (domain, 'default'): | ||||||
| 		root = os.path.join(env["STORAGE_ROOT"], "www", safe_domain_name(test_domain)) | 		root = os.path.join(env["STORAGE_ROOT"], "www", safe_domain_name(test_domain)) | ||||||
| 		if os.path.exists(root): break | 		if os.path.exists(root) or not test_exists: break | ||||||
| 	return root | 	return root | ||||||
| 
 | 
 | ||||||
| def get_domain_ssl_files(domain, env): | def get_domain_ssl_files(domain, env): | ||||||
| @ -193,3 +193,12 @@ def ensure_ssl_certificate_exists(domain, ssl_key, ssl_certificate, csr_path, en | |||||||
| 		"-signkey", ssl_key, | 		"-signkey", ssl_key, | ||||||
| 		"-out", ssl_certificate]) | 		"-out", ssl_certificate]) | ||||||
| 
 | 
 | ||||||
|  | def get_web_domains_info(env): | ||||||
|  | 	return [ | ||||||
|  | 		{ | ||||||
|  | 			"domain": domain, | ||||||
|  | 			"root": get_web_root(domain, env), | ||||||
|  | 			"custom_root": get_web_root(domain, env, test_exists=False), | ||||||
|  | 		} | ||||||
|  | 		for domain in get_web_domains(env) | ||||||
|  | 	] | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user