<%@ taglib uri="/WEB-INF/jspwiki.tld" prefix="wiki" %> <%@ page import="javax.servlet.http.*" %> <%@ page import="javax.servlet.*" %> <%@ page import="java.io.*" %> <%@ page import="java.util.*" %> <%@ page import="com.ecyrd.jspwiki.*" %> <%@ page import="com.ecyrd.jspwiki.providers.*" %> <%! String message = null; String propertyResult = null; public String sanitizePath( String s ) { s = TextUtil.replaceString(s, "\\", "\\\\" ); return s.trim(); } /** * Simply sanitizes any URL which contains backslashes (sometimes Windows users may have them) */ public String sanitizeURL( String s ) { s = TextUtil.replaceString(s, "\\", "/" ); return s.trim(); } public String setProperty( String propertyfile, String key, String value ) { int idx = 0; while( (idx < propertyfile.length()) && ((idx = propertyfile.indexOf(key,idx)) != -1) ) { int prevret = propertyfile.lastIndexOf("\n",idx); if( prevret != -1 ) { // Commented lines are skipped if( propertyfile.charAt(prevret+1) == '#' ) { idx += key.length(); continue; } } int eqsign = propertyfile.indexOf("=",idx); if( eqsign != -1 ) { int ret = propertyfile.indexOf("\n",eqsign); if( ret == -1 ) ret = propertyfile.length(); propertyfile = TextUtil.replaceString( propertyfile, eqsign+1, ret, value ); return propertyfile; } // idx += key.length(); } // // If it was not found, we'll add it here. // propertyfile += "\n"+key+" = "+value+"\n"; return propertyfile; } public void writeProperties( File propertyFile, String contents ) throws IOException { byte[] bytes = contents.getBytes("ISO-8859-1"); OutputStream out = null; try { out = new FileOutputStream( propertyFile ); FileUtil.copyContents( new ByteArrayInputStream( bytes ), out ); } finally { if( out != null ) out.close(); } } public File findPropertyFile( ServletContext context ) { String path = context.getRealPath("/"); File f = new File( path, WikiEngine.DEFAULT_PROPERTYFILE ); return f; } public String readProperties( ServletContext context ) throws IOException { File f = findPropertyFile( context ); FileReader in = null; String contents = null; try { in = new FileReader( f ); contents = FileUtil.readContents( in ); } finally { if( in != null ) in.close(); } return contents; } %> <% String propertyString = readProperties( getServletContext() ); Properties props = new Properties(); props.load( new ByteArrayInputStream(propertyString.getBytes("ISO-8859-1")) ); String appname = request.getParameter( "appname" ); String baseurl = request.getParameter( "baseurl" ); String dir = request.getParameter( "dir" ); String logdir = request.getParameter( "logdir" ); String workdir = request.getParameter( "workdir" ); String password1 = request.getParameter( "password1" ); String password2 = request.getParameter( "password2" ); String password = request.getParameter( "password" ); String oldpassword = props.getProperty( "jspwiki.auth.masterPassword", null ); if( request.getParameter("submit") != null ) { if( dir.length() == 0 ) { message = "You must define the location where the files are stored!"; } else if( appname.length() == 0 ) { message = "You must define application name"; } else if( workdir.length() == 0 ) { message = "You must define a work directory"; } else if( logdir.length() == 0 ) { message = "You must define a log directory"; } else if( password1 != null && !password1.equals(password2) ) { message = "Password missing or password mismatch"; } else if( oldpassword != null && !oldpassword.equals(password) ) { message = "The password you gave does not match with the master password"; } else { propertyString = setProperty( propertyString, WikiEngine.PROP_APPNAME, appname ); propertyString = setProperty( propertyString, WikiEngine.PROP_BASEURL, sanitizeURL(baseurl) ); propertyString = setProperty( propertyString, FileSystemProvider.PROP_PAGEDIR, sanitizePath(dir) ); propertyString = setProperty( propertyString, BasicAttachmentProvider.PROP_STORAGEDIR, sanitizePath(dir) ); propertyString = setProperty( propertyString, WikiEngine.PROP_WORKDIR, sanitizePath(workdir) ); propertyString = setProperty( propertyString, "log4j.appender.FileLog.File", sanitizePath( logdir ) ); if( password1 != null ) { propertyString = setProperty( propertyString, "jspwiki.auth.masterPassword", password1 ); oldpassword = password1; } // // Some default settings for the easy setup // propertyString = setProperty( propertyString, PageManager.PROP_PAGEPROVIDER, "VersioningFileProvider" ); propertyString = setProperty( propertyString, WikiEngine.PROP_ENCODING, "UTF-8" ); try { writeProperties( findPropertyFile(getServletContext()), propertyString ); message = "Your new properties have been saved. Please restart your container (unless this was your first install). Scroll down a bit to see your new jspwiki.properties."; } catch( IOException e ) { message = "Unable to write properties: "+e.getMessage()+ ". Please copy the file below as your jspwiki.properties"; } propertyResult = propertyString; } } %> <% File propertyFile = findPropertyFile( getServletContext() ); if( appname == null ) appname = props.getProperty( WikiEngine.PROP_APPNAME, "MyWiki" ); if( baseurl == null ) { baseurl = HttpUtils.getRequestURL(request).toString(); baseurl = baseurl.substring( 0, baseurl.lastIndexOf('/') )+"/"; baseurl = props.getProperty( WikiEngine.PROP_BASEURL, baseurl ); } if( dir == null ) dir = props.getProperty( FileSystemProvider.PROP_PAGEDIR, "Please configure me!" ); if( logdir == null ) logdir = props.getProperty( "log4j.appender.FileLog.File", "/tmp/" ); if( workdir == null ) workdir = props.getProperty( WikiEngine.PROP_WORKDIR, "/tmp/" ); if( password1 == null ) password1 = ""; if( password2 == null ) password2 = ""; // FIXME: encoding as well. response.addHeader("Pragma", "no-cache"); response.setHeader( "Expires", "-1" ); response.setHeader("Cache-Control", "no-cache" ); response.setContentType("text/html; charset=UTF-8"); %> JSPWiki configuration helper

JSPWiki configuration

Welcome! This little JSP page is here to help you do the first difficult stage of JSPWiki installation. If you're seeing this page, you have already installed JSPWiki correctly inside your container.

There are now some things that you should configure. When you press submit, the "jspwiki.properties" -file from the distribution will be modified, or if it can't be found, a new one will be created.

This setup system is really meant for people who just want to be up and running really quickly. If you want to integrate JSPWiki with an existing system, I would recommend that you go and edit the jspwiki.properties file directly. You can find a sample config file from yourwiki/WEB-INF/.

<%if(propertyFile!=null) {%>

(Read these properties from '<%=propertyFile.getAbsolutePath()%>')

<%}%> <%if( message != null ) { %>
<%=message%>
<%}%>

Mandatory options

Application Name:
What should your wiki be called? Try and make this a relatively short one.
Base URL:
Please tell me where your wiki is located.
File storage:
By default, I will use the VersioningFileProvider that will store files in a particular directory on your hard drive. If you specify a directory that does not exist, I'll create one for you. All attachments will also be put in the same directory.
Work directory:
This is the place where all caches and other runtime stuff is stored.

Other useful settings

Administrator password:
Repeat password:
<% if( oldpassword != null ) { %> If you want to change your current password, type it here. <% } else { %> Enter your new password here. It's not mandatory, but anyone can access this setup page, unless you set a password. HIGHLY RECOMMENDED <% } %>
<%--
URL format: Relative Absolute
Would you like to use relative URLs whenever possible (they are shorter)?
Encoding: UTF-8 ISO-8859-1
UTF-8 is the standard encoding in the internet these days, but ISO-8859-1 (aka Latin1) might be useful for legacy applications.
--%>
Log files:
JSPWiki uses Jakarta Log4j for logging. Please tell me where the log files should go to?
<% if( oldpassword != null ) { %>
Current administrator password:
You must give the current administrator password for the change to take place.
<% } %>
<%if(propertyResult != null) {%>

Here is your new jspwiki.properties

<%=propertyResult%>
    
<%}%>