view src/nabble/view/web/catalog/ExportConfirmation.java @ 19:18cf4872fd7f

remove anonymous posting
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 29 May 2020 22:58:25 -0600
parents 7ecd1a4ef557
children
line wrap: on
line source


package nabble.view.web.catalog;

import fschmidt.util.servlet.AuthorizingServlet;
import nabble.model.ModelHome;
import nabble.model.Node;
import nabble.model.User;
import nabble.model.export.Export;
import nabble.view.lib.Jtp;
import nabble.view.lib.Shared;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;


public class ExportConfirmation extends HttpServlet implements AuthorizingServlet {
	private static final Logger logger = LoggerFactory.getLogger(ExportConfirmation.class);

	public String getAuthorizationKey(HttpServletRequest request) throws ServletException {
		return Jtp.getReadAuthorizationKey( Jtp.getSiteNotNull(request).getNode(Jtp.getLong(request,"node")) );
	}

	public boolean authorize(String key,HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
		return Jtp.authorizeForRead(key,request,response);
	}

	protected void service(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException
	{
		PrintWriter out = response.getWriter();
		String nodeId = request.getParameter("node");
		Node node = Jtp.getSiteNotNull(request).getNode(Long.valueOf(nodeId));
		if (node == null) {
			response.sendError(HttpServletResponse.SC_NOT_FOUND);
			return;
		}

		User user = Jtp.getUser(request);
		boolean allowed = Jtp.canBeRemovedBy(node,user);
		if (!allowed) {
			Jtp.login("Only administrators can proceed in this area.", request, response);
			return;
		}

		String url = request.getParameter("url");
		if (url == null || !Export.isValidExportServer(url)) {
			logger.error("Invalid export URL: ["+url+"] referer="+request.getHeader("referer")+" user="+Jtp.getUser(request)+" user-agent="+request.getHeader("user-agent"));
			return;
		}

		String action = request.getParameter("action");
		if ("export".equals(action) && "POST".equals(request.getMethod())) {
			logger.info("Starting export of node ID=" + node.getId() + " to [" + url + ']');
			node.export(url, user.getEmail());
			response.sendRedirect(url);
			return;
		}
		
		out.print( "\n<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<html>\n	<head>\n		" );
 Shared.title(request, response, "Parent Options / Export Confirmation"); 
		out.print( "\n	</head>\n	<body>\n		" );
 Shared.minHeader(request,response, node); 
		out.print( "\n		" );
 Shared.editHeader(node.getSubjectHtml(), "Parent Options", out); 
		out.print( "\n\n		<h2 style=\"margin-bottom:.6em\">Export Confirmation</h2>\n		You have requested the following URL to be the new parent of <em>\"" );
		out.print( (node.getSubjectHtml()) );
		out.print( "\"</em>:\n		<div class=\"highlight rounded\" style=\"padding:.5em;margin: .5em 0 1em;font-weight:bold\">\n			" );
		out.print( (url) );
		out.print( "\n		</div>\n		This new parent is not related to <em>" );
		out.print( (node.getSubjectHtml()) );
		out.print( "</em>,\n		so Nabble must migrate the contents of your " );
		out.print( (Jtp.viewName(node).toLowerCase()) );
		out.print( " to that new location.\n		You should understand that:\n		<ul>\n			<li style=\"padding-bottom:1em\">\n				<strong>This change may not happen immediately</strong>.\n				<div>\n					The system will have to move post by post to the new location and this may\n					take hours (or even days) to finish depending on the size of the moved elements.\n					You will be notified by email when the process is complete.\n				</div>\n			</li>\n			<li style=\"padding-bottom:1em\">\n				<strong>All links to the moved elements will change (including links to posts and replies).</strong>\n				<div>\n					<span class=\"important\" style=\"font-weight:bold\">Previous links will NOT work anymore.</span>\n					Users should update their links if they want to visit those pages again in the future.\n				</div>\n			</li>\n			<li style=\"padding-bottom:1em\">\n				<strong>Some user accounts may not be moved.</strong>\n				<div>\n					The system will move posts and all associated user accounts to the new destination.\n					Non-related users accounts will not be moved. \n				</div>\n			</li>\n			<li>\n				<strong>Customizations will not be moved.</strong>\n				<div>\n					Custom NAML code and other changes (e.g., font size, CSS and other settings from the <i>Change Appearance</i> page) will not be moved.\n				</div>\n			</li>\n		</ul>\n		<div style=\"margin-top:1.5em\">\n		Do you really want to start the export process for <em>" );
		out.print( (node.getSubjectHtml()) );
		out.print( "</em>?\n		</div>\n		\n		<form method=\"post\" action=\"/catalog/ExportConfirmation.jtp\" accept-charset=\"UTF-8\">\n			<input type=\"hidden\" name=\"action\" value=\"export\" />\n			<input type=\"hidden\" name=\"node\" value=\"" );
		out.print( (node.getId()) );
		out.print( "\" />\n			<input type=\"hidden\" name=\"url\" value=\"" );
		out.print( (url) );
		out.print( "\" />\n\n			<div style=\"margin-top:1.4em\">\n				<input type=\"submit\" name=\"save\" value=\"Yes, Export it\" /> or <a href=\"" );
		out.print( (Jtp.path(node)) );
		out.print( "\">Cancel</a>\n			</div>\n		</form>\n\n		" );
 Shared.footer(request, response); 
		out.print( "\n		" );
 Shared.analytics(request,response); 
		out.print( "\n	</body>\n</html>\n" );

	}
}