📄 setup-admin-settings.jsp
字号:
<%--
- $RCSfile$
- $Revision: 1410 $
- $Date: 2005-05-26 23:00:40 -0700 (Thu, 26 May 2005) $
--%>
<%@ page import="org.jivesoftware.util.JiveGlobals,
org.jivesoftware.util.ParamUtils,
org.jivesoftware.util.StringUtils,
org.jivesoftware.wildfire.XMPPServer,
org.jivesoftware.wildfire.auth.AuthFactory,
org.jivesoftware.wildfire.ldap.LdapManager,
org.jivesoftware.wildfire.user.User" %>
<%@ page import="org.jivesoftware.wildfire.user.UserManager"%>
<%@ page import="org.xmpp.packet.JID"%>
<%@ page import="javax.servlet.http.HttpSession" %>
<%@ page import="java.net.URLEncoder" %>
<%@ page import="java.util.*" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>
<%
// Redirect if we've already run setup:
if (!XMPPServer.getInstance().isSetupMode()) {
response.sendRedirect("setup-completed.jsp");
return;
}
%>
<%! // Global vars, methods, etc
void setSetupFinished(HttpSession session) {
JiveGlobals.setXMLProperty("setup","true");
}
%>
<%
// Get parameters
String username = ParamUtils.getParameter(request, "username");
String password = ParamUtils.getParameter(request, "password");
String email = ParamUtils.getParameter(request, "email");
String newPassword = ParamUtils.getParameter(request, "newPassword");
String newPasswordConfirm = ParamUtils.getParameter(request, "newPasswordConfirm");
boolean doContinue = request.getParameter("continue") != null;
boolean doSkip = request.getParameter("doSkip") != null;
boolean doTest = request.getParameter("test") != null;
boolean ldap = "true".equals(request.getParameter("ldap"));
boolean addAdmin = request.getParameter("addAdministrator") != null;
boolean deleteAdmins = request.getParameter("deleteAdmins") != null;
boolean ldapFinished = request.getParameter("ldapFinished") != null;
// Handle a skip request
if (doSkip) {
// assume the admin account is setup, so we're done:
setSetupFinished(session);
// redirect
response.sendRedirect("setup-finished.jsp");
return;
}
// Error checks
Map<String, String> errors = new HashMap<String, String>();
if (doContinue) {
if (password == null) {
errors.put("password", "password");
}
if (email == null) {
errors.put("email", "email");
}
if (newPassword == null) {
errors.put("newPassword", "newPassword");
}
if (newPasswordConfirm == null) {
errors.put("newPasswordConfirm", "newPasswordConfirm");
}
if (newPassword != null && newPasswordConfirm != null
&& !newPassword.equals(newPasswordConfirm)) {
errors.put("match", "match");
}
// if no errors, continue:
if (errors.size() == 0) {
try {
User adminUser = UserManager.getInstance().getUser("admin");
adminUser.setPassword(newPassword);
if (email != null) {
adminUser.setEmail(email);
}
Date now = new Date();
adminUser.setCreationDate(now);
adminUser.setModificationDate(now);
// setup is finished, indicate so:
setSetupFinished(session);
// All good so redirect
response.sendRedirect("setup-finished.jsp");
return;
}
catch (Exception e) {
System.err.println("Could not find UserManager");
errors.put("general", "There was an unexpected error encountered when "
+ "setting the new admin information. Please check your error "
+ "logs and try to remedy the problem.");
}
}
}
if (ldapFinished) {
setSetupFinished(session);
// All good so redirect
response.sendRedirect("setup-finished.jsp");
return;
}
if (addAdmin) {
final String admin = request.getParameter("administrator");
if (admin != null) {
if (ldap) {
// Try to verify that the username exists in LDAP
Map<String, String> settings = (Map<String, String>) session.getAttribute("ldapSettings");
Map<String, String> userSettings = (Map<String, String>) session.getAttribute("ldapUserSettings");
if (settings != null) {
LdapManager manager = new LdapManager(settings);
manager.setUsernameField(userSettings.get("ldap.usernameField"));
manager.setSearchFilter(userSettings.get("ldap.searchFilter"));
try {
manager.findUserDN(JID.unescapeNode(admin));
}
catch (Exception e) {
e.printStackTrace();
errors.put("administrator", "");
}
}
}
if (errors.isEmpty()) {
String currentList = JiveGlobals.getXMLProperty("admin.authorizedUsernames");
final List users = new ArrayList(StringUtils.stringToCollection(currentList));
users.add(admin);
String userList = StringUtils.collectionToString(users);
JiveGlobals.setXMLProperty("admin.authorizedUsernames", userList);
}
} else {
errors.put("administrator", "");
}
}
if (deleteAdmins) {
String[] params = request.getParameterValues("remove");
String currentAdminList = JiveGlobals.getXMLProperty("admin.authorizedUsernames");
Collection<String> adminCollection = StringUtils.stringToCollection(currentAdminList);
List temporaryUserList = new ArrayList<String>(adminCollection);
final int no = params != null ? params.length : 0;
for (int i = 0; i < no; i++) {
temporaryUserList.remove(params[i]);
}
String newUserList = StringUtils.collectionToString(temporaryUserList);
if (temporaryUserList.size() == 0) {
JiveGlobals.setXMLProperty("admin.authorizedUsernames", "");
} else {
JiveGlobals.setXMLProperty("admin.authorizedUsernames", newUserList);
}
}
// This handles the case of reverting back to default settings from LDAP. Will
// add admin to the authorizedUsername list if the authorizedUsername list contains
// entries.
if (!ldap && !doTest) {
String currentAdminList = JiveGlobals.getXMLProperty("admin.authorizedUsernames");
List<String> adminCollection = new ArrayList<String>(StringUtils.stringToCollection(currentAdminList));
if ((!adminCollection.isEmpty() && !adminCollection.contains("admin")) ||
JiveGlobals.getXMLProperty("admin.authorizedJIDs") != null) {
adminCollection.add("admin");
JiveGlobals.setXMLProperty("admin.authorizedUsernames",
StringUtils.collectionToString(adminCollection));
}
}
%>
<html>
<head>
<title><fmt:message key="setup.admin.settings.account" /></title>
<meta name="currentStep" content="4"/>
</head>
<body>
<h1>
<fmt:message key="setup.admin.settings.account" />
</h1>
<% if(!ldap){ %>
<p>
<fmt:message key="setup.admin.settings.info" />
</p>
<% if (errors.size() > 0) { %>
<div class="error">
<% if (errors.get("general") != null) { %>
<%= errors.get("general") %>
<% } else if (errors.get("administrator") != null) { %>
<fmt:message key="setup.admin.settings.username-error" />
<% } else { %>
<fmt:message key="setup.admin.settings.error" />
<% } %>
</div>
<% } %>
<!-- BEGIN jive-contentBox -->
<div class="jive-contentBox">
<script language="JavaScript" type="text/javascript">
var clicked = false;
function checkClick() {
if (!clicked) {
clicked = true;
return true;
}
return false;
}
</script>
<form action="setup-admin-settings.jsp" name="acctform" method="post" onsubmit="return checkClick();">
<table cellpadding="3" cellspacing="2" border="0">
<%
// If the current password is "admin", don't show the text box for them to type
// the current password. This makes setup simpler for first-time users.
String currentPass = null;
try {
currentPass = AuthFactory.getPassword("admin");
}
catch (Exception e) {
// Ignore.
}
if ("admin".equals(currentPass)) {
%>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -