Project: * Clean-up (Eclipse cruft, unused files, etc...) * Git-specific changes * Maven POMs clean-up and changes for the build system * Version set to 1.0.0-0 in the development branches * Maven plug-ins updated to latest versions * Very partial dev. documentation added

This commit is contained in:
Emmanuel BENOîT 2011-12-09 08:07:33 +01:00
parent c74e30d5ba
commit 0665a760de
1439 changed files with 1020 additions and 1649 deletions

View file

@ -0,0 +1,172 @@
package com.deepclone.lw.web.admin;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import com.deepclone.lw.cmd.admin.AdminResponse;
import com.deepclone.lw.cmd.admin.adata.Privileges;
import com.deepclone.lw.cmd.admin.bans.BanType;
import com.deepclone.lw.cmd.admin.bans.BansSummaryResponse;
import com.deepclone.lw.cmd.admin.bans.ListBansResponse;
import com.deepclone.lw.cmd.admin.bans.RejectBanResponse;
import com.deepclone.lw.cmd.admin.bans.RequestBanResponse;
import com.deepclone.lw.session.SessionException;
import com.deepclone.lw.web.beans.intercept.SessionRequirement;
import com.deepclone.lw.web.beans.session.SessionMaintenanceException;
import com.deepclone.lw.web.beans.session.SessionServerException;
import com.deepclone.lw.web.beans.view.PageControllerBase;
import com.deepclone.lw.web.csess.AdminSession;
@Controller
@SessionRequirement( value = true , subType = "main" , redirectTo = "admin-session" )
public class BanhammerPages
extends PageControllerBase
{
@RequestMapping( "/bans" )
public String bansSummary( HttpServletRequest request , Model model )
throws SessionException , SessionServerException , SessionMaintenanceException
{
BansSummaryResponse response = this.getSession( AdminSession.class , request ).getBansSummary( );
if ( !response.isPrivilegeOk( ) ) {
return this.redirect( "main" );
}
return this.render( model , "internal" , "en" , "bansSummary" , response );
}
@RequestMapping( "/bans-{type}" )
public String listBans( HttpServletRequest request , Model model , @PathVariable( "type" ) String sType )
throws SessionException , SessionServerException , SessionMaintenanceException
{
BanType type;
try {
type = BanType.valueOf( sType.toUpperCase( ) );
} catch ( IllegalArgumentException e ) {
return this.redirect( "bans" );
}
ListBansResponse response = this.getSession( AdminSession.class , request ).getBans( type );
if ( !response.isPrivilegeOk( ) ) {
return this.redirect( "main" );
}
return this.render( model , "internal" , "en" , "bans" , response );
}
@RequestMapping( "/request-ban" )
public String requestBan( HttpServletRequest request , Model model )
throws SessionException , SessionServerException , SessionMaintenanceException
{
AdminResponse response = this.getSession( AdminSession.class , request ).noOp( Privileges.BANH );
if ( !response.isPrivilegeOk( ) ) {
return this.redirect( "main" );
}
return this.render( model , "internal" , "en" , "banRequest" , response );
}
@RequestMapping( value = "/request-ban.action" , method = RequestMethod.POST )
public String requestBan( HttpServletRequest request , Model model , @RequestParam( "eName" ) String eName ,
@RequestParam( "eMail" ) String eMail , @RequestParam( "reason" ) String reason )
throws SessionException , SessionServerException , SessionMaintenanceException
{
boolean empire = "".equals( eMail );
String user = empire ? eName : eMail;
RequestBanResponse response = this.getSession( AdminSession.class , request ).requestBan( user , empire ,
reason );
if ( !response.isPrivilegeOk( ) ) {
return this.redirect( "main" );
} else if ( response.getError( ) == null ) {
return this.redirect( "bans" );
}
return this.render( model , "internal" , "en" , "banRequest" , response );
}
@RequestMapping( value = "reject-ban-{id}" )
public String rejectBan( HttpServletRequest request , Model model , @PathVariable( "id" ) String sId )
throws SessionException , SessionServerException , SessionMaintenanceException
{
int id;
try {
id = Integer.parseInt( sId );
} catch ( NumberFormatException e ) {
return this.redirect( "bans-pending" );
}
AdminResponse response = this.getSession( AdminSession.class , request ).noOp( Privileges.BANH );
if ( !response.isPrivilegeOk( ) ) {
return this.redirect( "main" );
}
return this.renderMap( model , "internal" , "en" , "banReject" , "admin" , response.getAdmin( ) , "id" , id );
}
@RequestMapping( value = "reject-ban-{id}.action" , method = RequestMethod.POST )
public String rejectBan( HttpServletRequest request , Model model , @PathVariable( "id" ) String sId ,
@RequestParam( "reason" ) String reason )
throws SessionException , SessionServerException , SessionMaintenanceException
{
int id;
try {
id = Integer.parseInt( sId );
} catch ( NumberFormatException e ) {
return this.redirect( "bans-pending" );
}
RejectBanResponse response = this.getSession( AdminSession.class , request ).rejectBan( id , reason );
if ( !response.isPrivilegeOk( ) ) {
return this.redirect( "main" );
} else if ( !response.isError( ) ) {
return this.redirect( "bans-pending" );
}
return this.render( model , "internal" , "en" , "banReject" , response );
}
@RequestMapping( "confirm-ban-{id}.action" )
public String confirmBan( HttpServletRequest request , Model model , @PathVariable( "id" ) String sId )
throws SessionException , SessionServerException , SessionMaintenanceException
{
int id;
try {
id = Integer.parseInt( sId );
} catch ( NumberFormatException e ) {
return this.redirect( "bans-pending" );
}
this.getSession( AdminSession.class , request ).confirmBan( id );
return this.redirect( "bans-pending" );
}
@RequestMapping( "lift-ban-{id}.action" )
public String liftBan( HttpServletRequest request , Model model , @PathVariable( "id" ) String sId )
throws SessionException , SessionServerException , SessionMaintenanceException
{
int id;
try {
id = Integer.parseInt( sId );
} catch ( NumberFormatException e ) {
return this.redirect( "bans-validated" );
}
this.getSession( AdminSession.class , request ).liftBan( id );
return this.redirect( "bans-validated" );
}
}

View file

@ -0,0 +1,373 @@
package com.deepclone.lw.web.admin;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import com.deepclone.lw.cmd.admin.adata.Administrator;
import com.deepclone.lw.cmd.admin.adata.Privileges;
import com.deepclone.lw.cmd.admin.bt.*;
import com.deepclone.lw.cmd.bt.data.BugEvent;
import com.deepclone.lw.cmd.bt.data.BugStatus;
import com.deepclone.lw.session.SessionException;
import com.deepclone.lw.web.beans.intercept.SessionRequirement;
import com.deepclone.lw.web.beans.msgs.MessageFormatter;
import com.deepclone.lw.web.beans.session.SessionMaintenanceException;
import com.deepclone.lw.web.beans.session.SessionServerException;
import com.deepclone.lw.web.beans.view.BugTrackerBase;
import com.deepclone.lw.web.csess.AdminSession;
@Controller
@SessionRequirement( value = true , subType = "main" , redirectTo = "admin-session" )
public class BugTrackerPages
extends BugTrackerBase
{
private static final int perPage = 20;
private MessageFormatter formatter;
@Autowired( required = true )
public void setFormatter( MessageFormatter formatter )
{
this.formatter = formatter;
}
@RequestMapping( "/btracker" )
public String getSummary( HttpServletRequest request , Model model )
throws SessionException , SessionServerException , SessionMaintenanceException
{
BugsSummaryResponse summary = this.getSession( AdminSession.class , request ).getBugsSummary( );
if ( !summary.isPrivilegeOk( ) ) {
return this.redirect( "main" );
}
return this.render( model , "internal" , "en" , "bugsSummary" , summary );
}
@RequestMapping( "/bugs" )
public String listBugs( HttpServletRequest request , Model model ,
@RequestParam( value = "status" , required = false ) String sStatus ,
@RequestParam( value = "own" , required = false ) String sOwn ,
@RequestParam( value = "first" , required = false ) String sFirst )
throws SessionException , SessionServerException , SessionMaintenanceException
{
BugQuery query = this.getBugQuery( sStatus , sOwn , sFirst );
AdminSession aSession = this.getSession( AdminSession.class , request );
ListBugsResponse response = aSession.listBugs( query.status , query.ownOnly , query.first , perPage );
return this.render( model , "internal" , "en" , "bugsList" , response );
}
@RequestMapping( "/report-bug" )
public String showReportForm( HttpServletRequest request , Model model ,
@RequestParam( value = "status" , required = false ) String sStatus ,
@RequestParam( value = "own" , required = false ) String sOwn ,
@RequestParam( value = "first" , required = false ) String sFirst )
throws SessionException , SessionServerException , SessionMaintenanceException
{
BugQuery query = this.getBugQuery( sStatus , sOwn , sFirst );
AdminSession aSession = this.getSession( AdminSession.class , request );
Administrator admin = aSession.noOp( Privileges.BUGT ).getAdmin( );
return this.renderMap( model , "internal" , "en" , "bugsReport" , "admin" , admin , "query" , query );
}
@RequestMapping( value = "/report-bug.action" , method = RequestMethod.POST )
public String postReport( HttpServletRequest request , Model model ,
@RequestParam( value = "status" , required = false ) String sStatus ,
@RequestParam( value = "own" , required = false ) String sOwn ,
@RequestParam( value = "first" , required = false ) String sFirst , @RequestParam( "title" ) String title ,
@RequestParam( "description" ) String description ,
@RequestParam( value = "public" , required = false , defaultValue = "0" ) String publicReport )
throws SessionException , SessionServerException , SessionMaintenanceException
{
BugQuery query = this.getBugQuery( sStatus , sOwn , sFirst );
AdminSession aSession = this.getSession( AdminSession.class , request );
ReportBugResponse response = aSession.reportBug( title , description , "1".equals( publicReport ) );
if ( response.getTitle( ) == null ) {
// Successful post
String rTo = "bug-" + response.getBugId( ) + this.makeGetParams( query );
return this.redirect( rTo );
}
response = new ReportBugResponse( response , query );
return this.render( model , "internal" , "en" , "bugsReport" , response );
}
@RequestMapping( value = "/bug-{id}" )
public String viewBug( HttpServletRequest request , Model model ,
@RequestParam( value = "status" , required = false ) String sStatus ,
@RequestParam( value = "own" , required = false ) String sOwn ,
@RequestParam( value = "first" , required = false ) String sFirst , @PathVariable( "id" ) String sId )
throws SessionException , SessionServerException , SessionMaintenanceException
{
BugQuery query = this.getBugQuery( sStatus , sOwn , sFirst );
long bugId;
try {
bugId = Long.parseLong( sId );
} catch ( NumberFormatException e ) {
return this.redirect( "bugs" + this.makeGetParams( query ) );
}
ViewBugResponse response = this.getSession( AdminSession.class , request ).getBugReport( bugId );
if ( !response.isPrivilegeOk( ) ) {
return this.redirect( "main" );
} else if ( response.getReport( ) == null ) {
return this.redirect( "bugs" + this.makeGetParams( query ) );
}
response = new ViewBugResponse( response , query );
return this.displayReport( model , response );
}
@RequestMapping( value = "/bug-{id}-comment.action" , method = RequestMethod.POST )
public String commentBug( HttpServletRequest request , Model model ,
@RequestParam( value = "status" , required = false ) String sStatus ,
@RequestParam( value = "own" , required = false ) String sOwn ,
@RequestParam( value = "first" , required = false ) String sFirst , @PathVariable( "id" ) String sId ,
@RequestParam( "comment" ) String comment , @RequestParam( "visibility" ) String visibility )
throws SessionException , SessionServerException , SessionMaintenanceException
{
BugQuery query = this.getBugQuery( sStatus , sOwn , sFirst );
long bugId;
try {
bugId = Long.parseLong( sId );
} catch ( NumberFormatException e ) {
return this.redirect( "bugtrack" + this.makeGetParams( query ) );
}
PostCommentResponse response = this.getSession( AdminSession.class , request ).postBugComment( bugId , comment ,
"1".equals( visibility ) );
if ( response.isPosted( ) ) {
String rTo = "bug-" + bugId + this.makeGetParams( query );
return this.redirect( rTo );
} else if ( response.getReport( ) == null ) {
return this.redirect( "bugtrack" + this.makeGetParams( query ) );
}
response = new PostCommentResponse( response , query );
return this.displayReport( model , response );
}
private String displayReport( Model model , ViewBugResponse response )
{
for ( BugEvent event : response.getEvents( ) ) {
if ( event.getTitle( ) != null ) {
event.setTitle( this.formatter.cleanMessage( event.getTitle( ) ) );
}
if ( event.getContents( ) != null ) {
event.setContents( this.formatter.formatMessage( event.getContents( ) , false ) );
}
}
return this.render( model , "internal" , "en" , "bugsView" , response );
}
@RequestMapping( value = "/bug-{id}-comment-moderation.action" , method = RequestMethod.POST )
public String moderateComment( HttpServletRequest request , Model model ,
@RequestParam( value = "status" , required = false ) String sStatus ,
@RequestParam( value = "own" , required = false ) String sOwn ,
@RequestParam( value = "first" , required = false ) String sFirst , @PathVariable( "id" ) String sId ,
@RequestParam( "comment" ) String sComment , @RequestParam( "cAction" ) String validate )
throws SessionException , SessionServerException , SessionMaintenanceException
{
BugQuery query = this.getBugQuery( sStatus , sOwn , sFirst );
long bugId;
try {
bugId = Long.parseLong( sId );
} catch ( NumberFormatException e ) {
return this.redirect( "bugtrack" + this.makeGetParams( query ) );
}
long commentId;
try {
commentId = Long.parseLong( sComment );
} catch ( NumberFormatException e ) {
return this.redirect( "bug-" + bugId + this.makeGetParams( query ) );
}
this.getSession( AdminSession.class , request ).moderateBugComment( commentId , "1".equals( validate ) );
return this.redirect( "bug-" + bugId + this.makeGetParams( query ) );
}
@RequestMapping( value = "/bug-{id}-validation.action" , method = RequestMethod.POST )
public String moderateReport( HttpServletRequest request , Model model ,
@RequestParam( value = "status" , required = false ) String sStatus ,
@RequestParam( value = "own" , required = false ) String sOwn ,
@RequestParam( value = "first" , required = false ) String sFirst , @PathVariable( "id" ) String sId ,
@RequestParam( "nStatus" ) String sNewStatus , @RequestParam( "visibility" ) String visibility ,
@RequestParam( "credits" ) String sCredits , @RequestParam( "snapshot" ) String keepSnapshot )
throws SessionException , SessionServerException , SessionMaintenanceException
{
BugQuery query = this.getBugQuery( sStatus , sOwn , sFirst );
long bugId;
try {
bugId = Long.parseLong( sId );
} catch ( NumberFormatException e ) {
return this.redirect( "bugtrack" + this.makeGetParams( query ) );
}
BugStatus newStatus;
try {
newStatus = BugStatus.valueOf( sNewStatus );
} catch ( IllegalArgumentException e ) {
newStatus = BugStatus.PENDING;
}
boolean visible = "1".equals( visibility );
boolean snapshot = "1".equals( keepSnapshot );
int grantCredits;
try {
grantCredits = Integer.parseInt( sCredits );
} catch ( NumberFormatException e ) {
grantCredits = -1;
}
if ( grantCredits < 0 || grantCredits > 3 || newStatus == BugStatus.PENDING ) {
return this.redirect( "bug-" + bugId + this.makeGetParams( query ) );
}
this.getSession( AdminSession.class , request ).validateReport( bugId , newStatus , visible , grantCredits ,
snapshot );
return this.redirect( "bug-" + bugId + this.makeGetParams( query ) );
}
@RequestMapping( value = "/bug-{id}-status.action" , method = RequestMethod.POST )
public String setReportStatus( HttpServletRequest request , Model model ,
@RequestParam( value = "status" , required = false ) String sStatus ,
@RequestParam( value = "own" , required = false ) String sOwn ,
@RequestParam( value = "first" , required = false ) String sFirst , @PathVariable( "id" ) String sId ,
@RequestParam( "nStatus" ) String sNewStatus )
throws SessionException , SessionServerException , SessionMaintenanceException
{
BugQuery query = this.getBugQuery( sStatus , sOwn , sFirst );
long bugId;
try {
bugId = Long.parseLong( sId );
} catch ( NumberFormatException e ) {
return this.redirect( "bugtrack" + this.makeGetParams( query ) );
}
BugStatus newStatus;
try {
newStatus = BugStatus.valueOf( sNewStatus );
} catch ( IllegalArgumentException e ) {
newStatus = BugStatus.PENDING;
}
if ( newStatus != BugStatus.PENDING ) {
this.getSession( AdminSession.class , request ).setReportStatus( bugId , newStatus );
}
return this.redirect( "bug-" + bugId + this.makeGetParams( query ) );
}
@RequestMapping( value = "/bug-{id}-visibility.action" , method = RequestMethod.POST )
public String toggleReportVisibility( HttpServletRequest request , Model model ,
@RequestParam( value = "status" , required = false ) String sStatus ,
@RequestParam( value = "own" , required = false ) String sOwn ,
@RequestParam( value = "first" , required = false ) String sFirst , @PathVariable( "id" ) String sId )
throws SessionException , SessionServerException , SessionMaintenanceException
{
BugQuery query = this.getBugQuery( sStatus , sOwn , sFirst );
long bugId;
try {
bugId = Long.parseLong( sId );
} catch ( NumberFormatException e ) {
return this.redirect( "bugtrack" + this.makeGetParams( query ) );
}
this.getSession( AdminSession.class , request ).toggleReportVisibility( bugId );
return this.redirect( "bug-" + bugId + this.makeGetParams( query ) );
}
@RequestMapping( value = "/bug-{id}-merge.action" , method = RequestMethod.POST )
public String mergeReports( HttpServletRequest request , Model model ,
@RequestParam( value = "status" , required = false ) String sStatus ,
@RequestParam( value = "own" , required = false ) String sOwn ,
@RequestParam( value = "first" , required = false ) String sFirst , @PathVariable( "id" ) String sId ,
@RequestParam( "mergeId" ) String sMerge )
throws SessionException , SessionServerException , SessionMaintenanceException
{
BugQuery query = this.getBugQuery( sStatus , sOwn , sFirst );
long bugId;
try {
bugId = Long.parseLong( sId );
} catch ( NumberFormatException e ) {
return this.redirect( "bugtrack" + this.makeGetParams( query ) );
}
long mergeId;
try {
mergeId = Long.parseLong( sMerge );
} catch ( NumberFormatException e ) {
return this.redirect( "bug-" + bugId + this.makeGetParams( query ) );
}
MergeReportsResponse response = this.getSession( AdminSession.class , request ).mergeReports( bugId , mergeId );
if ( !response.isPrivilegeOk( ) ) {
return this.redirect( "main" );
} else if ( response.getReport( ) == null ) {
if ( response.getMergeError( ) == null ) {
return this.redirect( "bug-" + mergeId + this.makeGetParams( query ) );
} else {
return this.redirect( "bugtrack" + this.makeGetParams( query ) );
}
}
response = new MergeReportsResponse( response , query );
return this.displayReport( model , response );
}
@RequestMapping( "/bug-{id}-xmlsnapshot" )
public ResponseEntity< String > downloadSnapshot( HttpServletRequest request , @PathVariable( "id" ) String sId )
throws SessionException , SessionServerException , SessionMaintenanceException
{
long bugId;
try {
bugId = Long.parseLong( sId );
} catch ( NumberFormatException e ) {
return new ResponseEntity< String >( "GTFO" , HttpStatus.NOT_FOUND );
}
GetSnapshotResponse response = this.getSession( AdminSession.class , request ).getSnapshot( bugId );
if ( !response.isPrivilegeOk( ) ) {
return new ResponseEntity< String >( "GTFO" , HttpStatus.FORBIDDEN );
} else if ( response.getSnapshot( ) == null ) {
return new ResponseEntity< String >( "GTFO" , HttpStatus.NOT_FOUND );
}
HttpHeaders rHeaders = new HttpHeaders( );
rHeaders.setContentType( MediaType.APPLICATION_OCTET_STREAM );
return new ResponseEntity< String >( response.getSnapshot( ) , rHeaders , HttpStatus.OK );
}
}

View file

@ -0,0 +1,64 @@
package com.deepclone.lw.web.admin;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import com.deepclone.lw.cmd.admin.constants.GetConstantsResponse;
import com.deepclone.lw.cmd.admin.constants.SetConstantResponse;
import com.deepclone.lw.session.SessionException;
import com.deepclone.lw.web.beans.intercept.SessionRequirement;
import com.deepclone.lw.web.beans.session.SessionMaintenanceException;
import com.deepclone.lw.web.beans.session.SessionServerException;
import com.deepclone.lw.web.beans.view.PageControllerBase;
import com.deepclone.lw.web.csess.AdminSession;
@Controller
@SessionRequirement( value = true , subType = "main" , redirectTo = "admin-session" )
public class ConstantsPages
extends PageControllerBase
{
@RequestMapping( "/constants" )
public String getConstants( HttpServletRequest request , Model model )
throws SessionException , SessionServerException , SessionMaintenanceException
{
AdminSession session = this.getSession( AdminSession.class , request );
GetConstantsResponse response = session.getConstants( );
if ( !response.isPrivilegeOk( ) ) {
return this.redirect( "main" );
}
return this.render( model , "internal" , "en" , "constants" , response );
}
@RequestMapping( value = "/set-constant.action" , method = RequestMethod.POST )
public String setConstant( HttpServletRequest request , Model model , @RequestParam( "name" ) String name ,
@RequestParam( "value" ) String sValue )
throws SessionException , SessionServerException , SessionMaintenanceException
{
double value;
try {
value = Double.parseDouble( sValue );
} catch ( NumberFormatException e ) {
return this.redirect( "constants" );
}
AdminSession session = this.getSession( AdminSession.class , request );
SetConstantResponse response = session.setConstant( name , value );
if ( !response.isPrivilegeOk( ) ) {
return this.redirect( "main" );
} else if ( !response.isError( ) ) {
return this.redirect( "constants" );
}
return this.render( model , "internal" , "en" , "constants" , response );
}
}

View file

@ -0,0 +1,44 @@
package com.deepclone.lw.web.admin;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;
import com.deepclone.lw.session.SessionCommandException;
import com.deepclone.lw.session.SessionIdentifierException;
import com.deepclone.lw.web.beans.session.SessionServerException;
public class ErrorHandlerBean
implements HandlerExceptionResolver
{
@Override
public ModelAndView resolveException( HttpServletRequest request , HttpServletResponse response , Object handler ,
Exception ex )
{
if ( ex instanceof SessionServerException ) {
return this.offline( request );
} else if ( ex instanceof SessionIdentifierException || ex instanceof SessionCommandException ) {
return new ModelAndView( "redirect:admin-session" );
}
// Other exceptions are not handled
return null;
}
private ModelAndView offline( HttpServletRequest request )
{
ModelAndView mav = new ModelAndView( "ROOT" );
mav.addObject( "container" , "external" );
mav.addObject( "language" , "en" );
mav.addObject( "type" , "offline" );
return mav;
}
}

View file

@ -0,0 +1,131 @@
package com.deepclone.lw.web.admin;
import javax.servlet.http.HttpServletRequest;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import com.deepclone.lw.cmd.admin.i18n.ChangeLanguageResponse;
import com.deepclone.lw.cmd.admin.i18n.GetLanguageResponse;
import com.deepclone.lw.cmd.admin.i18n.I18NString;
import com.deepclone.lw.cmd.admin.i18n.SetStringResponse;
import com.deepclone.lw.cmd.admin.i18n.ViewLanguagesResponse;
import com.deepclone.lw.session.SessionException;
import com.deepclone.lw.web.admin.i18ne.LanguageExport;
import com.deepclone.lw.web.admin.i18ne.StringExport;
import com.deepclone.lw.web.beans.intercept.SessionRequirement;
import com.deepclone.lw.web.beans.session.SessionMaintenanceException;
import com.deepclone.lw.web.beans.session.SessionServerException;
import com.deepclone.lw.web.beans.view.PageControllerBase;
import com.deepclone.lw.web.csess.AdminSession;
import com.thoughtworks.xstream.XStream;
@Controller
@SessionRequirement( value = true , subType = "main" , redirectTo = "admin-session" )
public class I18NPages
extends PageControllerBase
{
@RequestMapping( "/i18n" )
public String listLanguages( HttpServletRequest request , Model model )
throws SessionException , SessionServerException , SessionMaintenanceException
{
ViewLanguagesResponse response = this.getSession( AdminSession.class , request ).listLanguages( );
if ( !response.isPrivilegeOk( ) ) {
return this.redirect( "main" );
}
return this.render( model , "internal" , "en" , "languages" , response );
}
@RequestMapping( "/i18n-{language}" )
public String viewLanguage( HttpServletRequest request , Model model , @PathVariable( "language" ) String language )
throws SessionException , SessionServerException , SessionMaintenanceException
{
GetLanguageResponse response = this.getSession( AdminSession.class , request ).getLanguage( language );
if ( !response.isPrivilegeOk( ) ) {
return this.redirect( "main" );
} else if ( response.getLanguage( ) == null ) {
return this.redirect( "i18n" );
}
return this.render( model , "internal" , "en" , "language" , response );
}
@RequestMapping( "/i18n-export-{language}" )
public ResponseEntity< String > exportLanguage( HttpServletRequest request ,
@PathVariable( "language" ) String language )
throws SessionException , SessionServerException , SessionMaintenanceException
{
HttpHeaders rHeaders = new HttpHeaders( );
GetLanguageResponse response = this.getSession( AdminSession.class , request ).getLanguage( language );
if ( !response.isPrivilegeOk( ) ) {
return new ResponseEntity< String >( "GTFO" , HttpStatus.FORBIDDEN );
} else if ( response.getLanguage( ) == null ) {
return new ResponseEntity< String >( "GTFO" , HttpStatus.NOT_FOUND );
}
LanguageExport lExport = new LanguageExport( );
lExport.id = response.getLanguage( ).getId( );
lExport.name = response.getLanguage( ).getName( );
for ( I18NString str : response.getStrings( ) ) {
StringExport sExport = new StringExport( );
sExport.id = str.getId( );
sExport.value = str.getText( );
lExport.strings.add( sExport );
}
XStream xStream = new XStream( );
xStream.autodetectAnnotations( true );
rHeaders.setContentType( MediaType.APPLICATION_OCTET_STREAM );
return new ResponseEntity< String >( xStream.toXML( lExport ) , rHeaders , HttpStatus.OK );
}
@RequestMapping( value = "/i18n-{language}-edit.action" , method = RequestMethod.POST )
public String changeLanguage( HttpServletRequest request , Model model ,
@PathVariable( "language" ) String language , @RequestParam( "name" ) String name )
throws SessionException , SessionServerException , SessionMaintenanceException
{
ChangeLanguageResponse response;
response = this.getSession( AdminSession.class , request ).setLanguageName( language , name );
if ( !response.isPrivilegeOk( ) ) {
return this.redirect( "main" );
} else if ( response.getLanguage( ) == null ) {
return this.redirect( "i18n" );
} else if ( !response.isNameError( ) ) {
return this.redirect( "i18n-" + response.getLanguage( ).getId( ) );
}
return this.render( model , "internal" , "en" , "language" , response );
}
@RequestMapping( value = "/i18n-{language}-set-string.action" , method = RequestMethod.POST )
public String setString( HttpServletRequest request , Model model , @PathVariable( "language" ) String language ,
@RequestParam( "string" ) String string , @RequestParam( "value" ) String value )
throws SessionException , SessionServerException , SessionMaintenanceException
{
SetStringResponse response;
response = this.getSession( AdminSession.class , request ).setTranslation( language , string , value );
if ( !response.isPrivilegeOk( ) ) {
return this.redirect( "main" );
} else if ( response.getLanguage( ) == null ) {
return this.redirect( "i18n" );
} else if ( response.getEdited( ) == null ) {
return this.redirect( "i18n-" + response.getLanguage( ).getId( ) );
}
return this.render( model , "internal" , "en" , "language" , response );
}
}

View file

@ -0,0 +1,144 @@
package com.deepclone.lw.web.admin;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.deepclone.lw.cmd.admin.logs.GetEntryResponse;
import com.deepclone.lw.cmd.admin.logs.LogLevel;
import com.deepclone.lw.cmd.admin.logs.LogType;
import com.deepclone.lw.cmd.admin.logs.ViewLogResponse;
import com.deepclone.lw.session.SessionException;
import com.deepclone.lw.web.beans.intercept.SessionRequirement;
import com.deepclone.lw.web.beans.session.SessionMaintenanceException;
import com.deepclone.lw.web.beans.session.SessionServerException;
import com.deepclone.lw.web.beans.view.PageControllerBase;
import com.deepclone.lw.web.csess.AdminSession;
@Controller
@SessionRequirement( value = true , subType = "main" , redirectTo = "admin-session" )
public class LogPages
extends PageControllerBase
{
private final int pageSize = 30;
@RequestMapping( value = "/logs" , method = RequestMethod.GET )
public String viewLogs( HttpServletRequest request , Model model )
throws SessionException , SessionServerException , SessionMaintenanceException
{
int first = this.getFirstIndex( request );
LogType logType = this.getLogType( request );
LogLevel logLevel = this.getLogLevel( request );
String component = request.getParameter( "component" );
if ( component == null ) {
component = "";
} else {
component = component.trim( ).toLowerCase( );
}
boolean excOnly = "1".equals( request.getParameter( "excOnly" ) );
AdminSession aSession = this.getSession( AdminSession.class , request );
ViewLogResponse response = aSession.viewLog( logType , first , pageSize , logLevel , component , excOnly );
if ( !response.isPrivilegeOk( ) ) {
return this.redirect( "main" );
}
Map< String , Object > params = new HashMap< String , Object >( );
params.put( "type" , logType );
params.put( "level" , logLevel );
params.put( "component" , component );
params.put( "excOnly" , (Boolean) excOnly );
params.put( "first" , first );
Map< String , Object > data = new HashMap< String , Object >( );
data.put( "admin" , response.getAdmin( ) );
data.put( "entries" , response.getEntries( ) );
data.put( "count" , response.getCount( ) );
data.put( "params" , params );
return this.render( model , "internal" , "en" , "logs" , data );
}
private int getFirstIndex( HttpServletRequest request )
{
String sIndex = request.getParameter( "first" );
if ( sIndex == null ) {
return 0;
}
int f;
try {
f = Integer.parseInt( sIndex );
} catch ( NumberFormatException e ) {
return 0;
}
return ( f > 0 ) ? f : 0;
}
private LogType getLogType( HttpServletRequest request )
{
LogType logType;
String sLogType = request.getParameter( "logType" );
if ( sLogType == null ) {
logType = LogType.SYSTEM;
} else {
try {
logType = LogType.valueOf( sLogType );
} catch ( IllegalArgumentException e ) {
logType = LogType.SYSTEM;
}
}
return logType;
}
private LogLevel getLogLevel( HttpServletRequest request )
{
LogLevel logLevel;
String sLogLevel = request.getParameter( "logLevel" );
if ( sLogLevel == null ) {
logLevel = LogLevel.INFO;
} else {
try {
logLevel = LogLevel.valueOf( sLogLevel );
} catch ( IllegalArgumentException e ) {
logLevel = LogLevel.INFO;
}
}
return logLevel;
}
@RequestMapping( "/view-log-entry-{id}" )
public String viewLogEntry( HttpServletRequest request , Model model , @PathVariable( "id" ) String sId )
throws SessionException , SessionServerException , SessionMaintenanceException
{
long id;
try {
id = Long.parseLong( sId );
} catch ( NumberFormatException e ) {
return this.redirect( "logs" );
}
GetEntryResponse response = this.getSession( AdminSession.class , request ).getLogEntry( id );
if ( !response.isPrivilegeOk( ) ) {
return this.redirect( "main" );
} else if ( response.getEntry( ) == null ) {
return this.redirect( "logs" );
}
return this.render( model , "internal" , "en" , "logEntry" , response );
}
}

View file

@ -0,0 +1,53 @@
package com.deepclone.lw.web.admin;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import com.deepclone.lw.session.SessionException;
import com.deepclone.lw.web.beans.intercept.SessionRequirement;
import com.deepclone.lw.web.beans.session.SessionMaintenanceException;
import com.deepclone.lw.web.beans.session.SessionServerException;
import com.deepclone.lw.web.beans.view.PageControllerBase;
import com.deepclone.lw.web.csess.AdminSession;
@Controller
@SessionRequirement( value = false , redirectTo = "admin-session" )
public class LoginPage
extends PageControllerBase
{
@RequestMapping( value = "/" )
public String root( HttpServletRequest request , Model model )
{
return this.redirect( "login" );
}
@RequestMapping( value = "/login" )
public String login( HttpServletRequest request , Model model )
{
return this.renderMap( model , "external" , "en" , "login" , "failed" , (Boolean) false );
}
@RequestMapping( value = "/login.action" , method = RequestMethod.POST )
public String login( HttpServletRequest request , Model model , @RequestParam( "mail" ) String mail ,
@RequestParam( "password" ) String password )
throws SessionException , SessionServerException , SessionMaintenanceException
{
AdminSession aSession = this.initSession( AdminSession.class , request );
boolean authenticated = aSession.authenticate( mail , password );
if ( !authenticated ) {
this.clearSession( request );
return this.renderMap( model , "external" , "en" , "login" , "failed" , (Boolean) true );
}
return this.redirect( "admin-session" );
}
}

View file

@ -0,0 +1,89 @@
package com.deepclone.lw.web.admin;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import com.deepclone.lw.cmd.admin.mntm.*;
import com.deepclone.lw.session.SessionException;
import com.deepclone.lw.web.beans.intercept.SessionRequirement;
import com.deepclone.lw.web.beans.session.SessionMaintenanceException;
import com.deepclone.lw.web.beans.session.SessionServerException;
import com.deepclone.lw.web.beans.view.PageControllerBase;
import com.deepclone.lw.web.csess.AdminSession;
@Controller
@SessionRequirement( value = true , subType = "main" , redirectTo = "admin-session" )
public class MaintenancePages
extends PageControllerBase
{
@RequestMapping( "/maintenance" )
public String getMaintenanceStatus( HttpServletRequest request , Model model )
throws SessionException , SessionServerException , SessionMaintenanceException
{
MaintenanceStatusResponse response = this.getSession( AdminSession.class , request ).getMaintenanceStatus( );
if ( !response.isPrivilegeOk( ) ) {
return this.redirect( "main" );
}
return this.render( model , "internal" , "en" , "maintenance" , response );
}
@RequestMapping( value = "/maintenance-start.action" , method = RequestMethod.POST )
public String enableMaintenance( HttpServletRequest request , Model model ,
@RequestParam( "reason" ) String reason , @RequestParam( "duration" ) String sDuration )
throws SessionException , SessionServerException , SessionMaintenanceException
{
int duration;
try {
duration = Integer.parseInt( sDuration );
} catch ( NumberFormatException e ) {
duration = -1;
}
AdminSession aSession = this.getSession( AdminSession.class , request );
MaintenanceChangeResponse response = aSession.enableMaintenance( reason , duration );
if ( !response.isPrivilegeOk( ) ) {
return this.redirect( "main" );
} else if ( response.getNewReason( ) == null ) {
return this.redirect( "maintenance" );
}
return this.render( model , "internal" , "en" , "maintenance" , response );
}
@RequestMapping( value = "/maintenance-extend.action" , method = RequestMethod.POST )
public String extendMaintenance( HttpServletRequest request , Model model ,
@RequestParam( "duration" ) String sDuration )
throws SessionException , SessionServerException , SessionMaintenanceException
{
int duration;
try {
duration = Integer.parseInt( sDuration );
} catch ( NumberFormatException e ) {
duration = -1;
}
this.getSession( AdminSession.class , request ).extendMaintenance( duration );
return this.redirect( "maintenance" );
}
@RequestMapping( value = "/maintenance-end.action" , method = RequestMethod.POST )
public String endMaintenance( HttpServletRequest request , Model model )
throws SessionException , SessionServerException , SessionMaintenanceException
{
this.getSession( AdminSession.class , request ).endMaintenance( );
return this.redirect( "maintenance" );
}
}

View file

@ -0,0 +1,73 @@
package com.deepclone.lw.web.admin;
import java.util.LinkedList;
import java.util.List;
import com.deepclone.lw.cmd.admin.AdminResponse;
import com.deepclone.lw.cmd.admin.adata.Administrator;
import com.deepclone.lw.cmd.msgdata.MessageListEntry;
public class MessageBoxView
extends AdminResponse
{
private static final long serialVersionUID = 1L;
private final boolean inbox;
private int pages;
private int cPage;
private final List< MessageListEntry > messages = new LinkedList< MessageListEntry >( );
public MessageBoxView( Administrator admin , boolean inbox )
{
super( admin );
this.inbox = inbox;
}
public int getPages( )
{
return pages;
}
public void setPages( int pages )
{
this.pages = pages;
}
public int getcPage( )
{
return cPage;
}
public void setcPage( int cPage )
{
this.cPage = cPage;
}
public boolean isInbox( )
{
return inbox;
}
public List< MessageListEntry > getMessages( )
{
return messages;
}
public void addMessage( MessageListEntry entry )
{
this.messages.add( entry );
}
}

View file

@ -0,0 +1,453 @@
package com.deepclone.lw.web.admin;
import java.util.LinkedList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import com.deepclone.lw.cmd.admin.msg.*;
import com.deepclone.lw.cmd.msgdata.*;
import com.deepclone.lw.session.SessionException;
import com.deepclone.lw.web.beans.intercept.SessionRequirement;
import com.deepclone.lw.web.beans.msgs.MessageFormatter;
import com.deepclone.lw.web.beans.session.SessionMaintenanceException;
import com.deepclone.lw.web.beans.session.SessionServerException;
import com.deepclone.lw.web.beans.view.PageControllerBase;
import com.deepclone.lw.web.csess.AdminSession;
@Controller
@SessionRequirement( value = true , subType = "main" , redirectTo = "admin-session" )
public class MessagesPages
extends PageControllerBase
{
private final static int perPage = 30;
private MessageFormatter formatter;
@Autowired( required = true )
public void setFormatter( MessageFormatter formatter )
{
this.formatter = formatter;
}
@RequestMapping( "/messages" )
public String viewInbox( HttpServletRequest request , Model model )
throws SessionException , SessionServerException , SessionMaintenanceException
{
MessageBoxView view = this.viewMessageBox( true , this.getSession( AdminSession.class , request ) , 0 );
return this.render( model , "internal" , "en" , "messageBox" , view );
}
@RequestMapping( "/inbox-{page}" )
public String viewInbox( HttpServletRequest request , Model model , @PathVariable( "page" ) String sPage )
throws SessionException , SessionServerException , SessionMaintenanceException
{
int page;
try {
page = Integer.parseInt( sPage );
} catch ( NumberFormatException e ) {
page = 0;
}
MessageBoxView view = this.viewMessageBox( true , this.getSession( AdminSession.class , request ) , page );
return this.render( model , "internal" , "en" , "messageBox" , view );
}
@RequestMapping( "/inbox-from-{id}" )
public String viewInboxFrom( HttpServletRequest request , Model model , @PathVariable( "id" ) String sId )
throws SessionException , SessionServerException , SessionMaintenanceException
{
long id;
try {
id = Integer.parseInt( sId );
} catch ( NumberFormatException e ) {
id = 0;
}
MessageBoxView view = this.viewMessageBoxFrom( true , this.getSession( AdminSession.class , request ) , id );
return this.render( model , "internal" , "en" , "messageBox" , view );
}
@RequestMapping( "/outbox" )
public String viewOutbox( HttpServletRequest request , Model model )
throws SessionException , SessionServerException , SessionMaintenanceException
{
MessageBoxView view = this.viewMessageBox( false , this.getSession( AdminSession.class , request ) , 0 );
return this.render( model , "internal" , "en" , "messageBox" , view );
}
@RequestMapping( "/outbox-{page}" )
public String viewOutbox( HttpServletRequest request , Model model , @PathVariable( "page" ) String sPage )
throws SessionException , SessionServerException , SessionMaintenanceException
{
int page;
try {
page = Integer.parseInt( sPage );
} catch ( NumberFormatException e ) {
page = 0;
}
MessageBoxView view = this.viewMessageBox( false , this.getSession( AdminSession.class , request ) , page );
return this.render( model , "internal" , "en" , "messageBox" , view );
}
@RequestMapping( "/outbox-from-{id}" )
public String viewOutboxFrom( HttpServletRequest request , Model model , @PathVariable( "id" ) String sId )
throws SessionException , SessionServerException , SessionMaintenanceException
{
long id;
try {
id = Integer.parseInt( sId );
} catch ( NumberFormatException e ) {
id = 0;
}
MessageBoxView view = this.viewMessageBoxFrom( false , this.getSession( AdminSession.class , request ) , id );
return this.render( model , "internal" , "en" , "messageBox" , view );
}
private MessageBoxView viewMessageBox( boolean inbox , AdminSession aSession , int page )
throws SessionException , SessionServerException , SessionMaintenanceException
{
GetMessagesResponse mResponse = aSession.getMessages( inbox );
MessageBoxView view = new MessageBoxView( mResponse.getAdmin( ) , inbox );
List< MessageListEntry > messages = mResponse.getMessages( );
// Handle paging
messages = this.setPage( view , messages , page );
this.prepareMessages( view , messages );
return view;
}
private MessageBoxView viewMessageBoxFrom( boolean inbox , AdminSession pSession , long fromId )
throws SessionException , SessionServerException , SessionMaintenanceException
{
GetMessagesResponse mResponse = pSession.getMessages( inbox );
MessageBoxView view = new MessageBoxView( mResponse.getAdmin( ) , inbox );
List< MessageListEntry > messages = mResponse.getMessages( );
int page = 0;
int nSeen = -1;
for ( MessageListEntry e : messages ) {
nSeen++;
if ( e.getId( ) != fromId ) {
continue;
}
page = ( nSeen - nSeen % MessagesPages.perPage ) / MessagesPages.perPage;
break;
}
// Handle paging
messages = this.setPage( view , messages , page );
this.prepareMessages( view , messages );
return view;
}
private void prepareMessages( MessageBoxView view , List< MessageListEntry > messages )
{
for ( MessageListEntry message : messages ) {
message.setTitle( this.formatter.cleanMessage( message.getTitle( ) ) );
view.addMessage( message );
}
}
private List< MessageListEntry > setPage( MessageBoxView view , List< MessageListEntry > messages , int page )
{
int nMessages = messages.size( );
int mod = nMessages % MessagesPages.perPage;
int nPages = ( nMessages - mod ) / MessagesPages.perPage + ( mod > 0 ? 1 : 0 );
if ( page < 0 ) {
page = 0;
} else if ( page >= nPages ) {
page = nPages - 1;
}
if ( !messages.isEmpty( ) ) {
messages = messages.subList( page * MessagesPages.perPage , Math.min( ( page + 1 ) * MessagesPages.perPage ,
nMessages ) );
}
view.setPages( nPages );
view.setcPage( page );
return messages;
}
@RequestMapping( "/inbox-message-{id}" )
public String viewInboxMessage( HttpServletRequest request , Model model , @PathVariable( "id" ) String sId )
throws SessionException , SessionServerException , SessionMaintenanceException
{
return this.viewMessage( request , model , sId , true );
}
@RequestMapping( "/outbox-message-{id}" )
public String viewOutboxMessage( HttpServletRequest request , Model model , @PathVariable( "id" ) String sId )
throws SessionException , SessionServerException , SessionMaintenanceException
{
return this.viewMessage( request , model , sId , false );
}
private String viewMessage( HttpServletRequest request , Model model , String sId , boolean inbox )
throws SessionException , SessionServerException , SessionMaintenanceException
{
long id;
try {
id = Long.parseLong( sId );
} catch ( NumberFormatException e ) {
return this.redirect( inbox ? "messages" : "outbox" );
}
AdminSession aSession = this.getSession( AdminSession.class , request );
ReadMessageResponse response = aSession.readMessage( inbox , id );
Message message = response.getMessage( );
if ( message == null ) {
return this.redirect( inbox ? "messages" : "outbox" );
}
boolean internal = ( message.getType( ) == MessageType.INTERNAL );
message.setTitle( this.formatter.cleanMessage( message.getTitle( ) ) );
message.setContents( this.formatter.formatMessage( message.getContents( ) , internal ) );
return this.render( model , "internal" , "en" , "message" , response );
}
@RequestMapping( value = "/messages.action" , method = RequestMethod.POST )
public String mbAction( HttpServletRequest request , Model model , @RequestParam( "inbox" ) String sInbox ,
@RequestParam( "page" ) String sPage , @RequestParam( "target" ) String sTarget ,
@RequestParam( "action" ) String action ,
@RequestParam( value = "selection" , required = false ) String[] sSelection )
throws SessionException , SessionServerException , SessionMaintenanceException
{
boolean inbox = "1".equals( sInbox );
if ( !inbox ) {
action = "d";
}
boolean useSelected = "0".equals( sTarget );
long selection[];
if ( useSelected ) {
List< Long > rSel = new LinkedList< Long >( );
if ( sSelection != null ) {
for ( String sItem : sSelection ) {
Long value;
try {
value = Long.parseLong( sItem );
} catch ( NumberFormatException e ) {
continue;
}
rSel.add( value );
}
selection = new long[ rSel.size( ) ];
int i = 0;
for ( Long value : rSel ) {
selection[ i++ ] = value;
}
} else {
selection = new long[ 0 ];
}
} else {
selection = null;
}
AdminSession aSession = this.getSession( AdminSession.class , request );
if ( selection == null || selection.length > 0 ) {
if ( "d".equals( action ) ) {
aSession.deleteMessages( inbox , selection );
} else if ( "r".equals( action ) ) {
aSession.markRead( selection );
} else if ( "u".equals( action ) ) {
aSession.markUnread( selection );
}
}
int page;
try {
page = Integer.parseInt( sPage );
} catch ( NumberFormatException e ) {
page = 0;
}
return this.redirect( ( inbox ? "inbox" : "outbox" ) + "-" + page );
}
@RequestMapping( value = "/message.action" , method = RequestMethod.POST )
public String msgAction( HttpServletRequest request , Model model , @RequestParam( "inbox" ) String sInbox ,
@RequestParam( "id" ) String sId , @RequestParam( "next" ) String sNext ,
@RequestParam( value = "delete" , required = false ) String delete ,
@RequestParam( value = "reply" , required = false ) String reply )
throws SessionException , SessionServerException , SessionMaintenanceException
{
boolean inbox = "1".equals( sInbox );
long id;
try {
id = Long.parseLong( sId );
} catch ( NumberFormatException e ) {
return this.redirect( inbox ? "messages" : "outbox" );
}
AdminSession aSession = this.getSession( AdminSession.class , request );
if ( delete != null ) {
aSession.deleteMessages( inbox , new long[] {
id
} );
try {
id = Long.parseLong( sNext );
} catch ( NumberFormatException e ) {
return this.redirect( inbox ? "messages" : "outbox" );
}
return this.redirect( ( inbox ? "inbox" : "outbox" ) + "-message-" + id );
} else if ( reply != null ) {
ComposeMessageResponse response;
response = aSession.replyTo( inbox , id );
return this.showWriter( model , response );
}
return this.redirect( inbox ? "messages" : "outbox" );
}
@RequestMapping( "/compose-message" )
public String composeNew( HttpServletRequest request , Model model )
throws SessionException , SessionServerException , SessionMaintenanceException
{
AdminSession aSession = this.getSession( AdminSession.class , request );
return this.render( model , "internal" , "en" , "messageWriter" , aSession.initNewMessage( ) );
}
@RequestMapping( "/msg-empire-{id}" )
public String messageEmpire( HttpServletRequest request , Model model , @PathVariable( "id" ) String sId )
throws SessionException , SessionServerException , SessionMaintenanceException
{
return this.newMessageTo( request , model , MessageType.EMPIRE , sId );
}
@RequestMapping( "/msg-admin-{id}" )
public String messageAdmin( HttpServletRequest request , Model model , @PathVariable( "id" ) String sId )
throws SessionException , SessionServerException , SessionMaintenanceException
{
return this.newMessageTo( request , model , MessageType.ADMINISTRATOR , sId );
}
@RequestMapping( value = "/send-message.action" , method = RequestMethod.POST )
public String sendMessage( HttpServletRequest request , Model model , @RequestParam( "toType" ) String sToType ,
@RequestParam( "toName" ) String toName , @RequestParam( "title" ) String title ,
@RequestParam( "contents" ) String contents ,
@RequestParam( value = "rtInbox" , required = false ) String sRtInbox ,
@RequestParam( value = "rtId" , required = false ) String sRtId ,
@RequestParam( value = "cancel" , required = false ) String sCancel )
throws SessionException , SessionServerException , SessionMaintenanceException
{
// Handle cancellation
if ( sCancel != null ) {
return this.cancelSendRedirect( sRtInbox , sRtId );
}
// Get message type
MessageType type;
try {
type = MessageType.valueOf( sToType );
} catch ( IllegalArgumentException e ) {
type = MessageType.INTERNAL;
}
if ( type == MessageType.INTERNAL ) {
type = MessageType.EMPIRE;
}
AdminSession aSession = this.getSession( AdminSession.class , request );
ComposeMessageResponse response;
if ( sRtInbox == null || sRtId == null ) {
response = aSession.sendMessage( type , toName , title , contents );
} else {
boolean inbox = "1".equals( sRtInbox );
long rtId;
try {
rtId = Long.parseLong( sRtId );
} catch ( NumberFormatException e ) {
return this.redirect( inbox ? "messages" : "outbox" );
}
response = aSession.sendReply( inbox , rtId , type , toName , title , contents );
}
if ( !response.isError( ) ) {
return this.cancelSendRedirect( sRtInbox , sRtId );
}
return this.showWriter( model , response );
}
private String newMessageTo( HttpServletRequest request , Model model , MessageType type , String sId )
throws SessionException , SessionServerException , SessionMaintenanceException
{
int id;
try {
id = Integer.parseInt( sId );
} catch ( NumberFormatException e ) {
return this.redirect( "compose-message" );
}
ComposeMessageResponse response;
response = this.getSession( AdminSession.class , request ).messageTo( type , id );
return this.showWriter( model , response );
}
private String showWriter( Model model , ComposeMessageResponse response )
{
if ( response.getReplyTo( ) != null ) {
Message message = response.getReplyTo( );
message.setTitle( this.formatter.cleanMessage( message.getTitle( ) ) );
message.setContents( this.formatter.formatMessage( message.getContents( ) , false ) );
}
return this.render( model , "internal" , "en" , "messageWriter" , response );
}
private String cancelSendRedirect( String sRtInbox , String sRtId )
{
if ( sRtInbox == null || sRtId == null ) {
return this.redirect( "messages" );
}
boolean inbox = "1".equals( sRtInbox );
long rtId;
try {
rtId = Long.parseLong( sRtId );
} catch ( NumberFormatException e ) {
return this.redirect( inbox ? "messages" : "outbox" );
}
return this.redirect( ( inbox ? "inbox" : "outbox" ) + "-message-" + rtId );
}
}

View file

@ -0,0 +1,107 @@
package com.deepclone.lw.web.admin;
import java.util.LinkedList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import com.deepclone.lw.cmd.admin.naming.*;
import com.deepclone.lw.session.SessionException;
import com.deepclone.lw.web.beans.intercept.SessionRequirement;
import com.deepclone.lw.web.beans.session.SessionMaintenanceException;
import com.deepclone.lw.web.beans.session.SessionServerException;
import com.deepclone.lw.web.beans.view.PageControllerBase;
import com.deepclone.lw.web.csess.AdminSession;
@Controller
@SessionRequirement( value = true , subType = "main" , redirectTo = "admin-session" )
public class NamesPages
extends PageControllerBase
{
@RequestMapping( "/names" )
public String listNameTypes( HttpServletRequest request , Model model )
throws SessionException , SessionServerException , SessionMaintenanceException
{
NamesSummaryResponse response = this.getSession( AdminSession.class , request ).getNameSummary( );
if ( !response.isPrivilegeOk( ) ) {
return this.redirect( "main" );
}
return this.render( model , "internal" , "en" , "namesSummary" , response );
}
@RequestMapping( "/names-{type}" )
public String listNames( HttpServletRequest request , Model model , @PathVariable( "type" ) String sType )
throws SessionException , SessionServerException , SessionMaintenanceException
{
NameType type;
try {
type = NameType.valueOf( sType.toUpperCase( ).replace( "-" , "_" ) );
} catch ( IllegalArgumentException e ) {
return this.redirect( "names" );
}
GetNamesResponse response = this.getSession( AdminSession.class , request ).getNames( type );
if ( !response.isPrivilegeOk( ) ) {
return this.redirect( "main" );
}
return this.render( model , "internal" , "en" , "names" , response );
}
@RequestMapping( value = "/names-{type}.action" , method = RequestMethod.POST )
public String namesAction( HttpServletRequest request , Model model , @PathVariable( "type" ) String sType ,
@RequestParam( "action" ) String sAction , @RequestParam( value = "ids" , required = false ) String[] sIds )
throws SessionException , SessionServerException , SessionMaintenanceException
{
// Parse type
NameType type;
try {
type = NameType.valueOf( sType.toUpperCase( ).replace( "-" , "_" ) );
} catch ( IllegalArgumentException e ) {
return this.redirect( "names" );
}
// Parse action
NameAction action;
try {
action = NameAction.valueOf( sAction );
} catch ( IllegalArgumentException e ) {
return this.redirect( "names-" + type.toString( ).toLowerCase( ).replace( "_" , "-" ) );
}
// Parse identifiers
List< Integer > lIds = new LinkedList< Integer >( );
if ( sIds != null ) {
for ( String s : sIds ) {
try {
lIds.add( Integer.parseInt( s ) );
} catch ( NumberFormatException e ) {
// EMPTY
}
}
}
if ( lIds.isEmpty( ) ) {
return this.redirect( "names-" + type.toString( ).toLowerCase( ).replace( "_" , "-" ) );
}
int[] ids = new int[ lIds.size( ) ];
int i = 0;
for ( Integer v : lIds ) {
ids[ i++ ] = v.intValue( );
}
this.getSession( AdminSession.class , request ).namesAction( type , action , ids );
return this.redirect( "names-" + type.toString( ).toLowerCase( ).replace( "_" , "-" ) );
}
}

View file

@ -0,0 +1,51 @@
package com.deepclone.lw.web.admin;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import com.deepclone.lw.cmd.admin.SetPasswordResponse;
import com.deepclone.lw.cmd.admin.SetPasswordResponse.PasswordChangeStatus;
import com.deepclone.lw.session.SessionException;
import com.deepclone.lw.web.beans.intercept.SessionRequirement;
import com.deepclone.lw.web.beans.session.SessionMaintenanceException;
import com.deepclone.lw.web.beans.session.SessionServerException;
import com.deepclone.lw.web.beans.view.PageControllerBase;
import com.deepclone.lw.web.csess.AdminSession;
@Controller
@SessionRequirement( value = true , redirectTo = "login" )
public class PasswordPages
extends PageControllerBase
{
@RequestMapping( "/change-password" )
public String changePassword( HttpServletRequest request , Model model )
throws SessionException , SessionServerException , SessionMaintenanceException
{
AdminSession aSession = this.getSession( AdminSession.class , request );
return this.render( model , "internal" , "en" , "changePassword" , aSession.noOp( ) );
}
@RequestMapping( value = "/change-password.action" , method = RequestMethod.POST )
public String changePassword( HttpServletRequest request , Model model , @RequestParam( "current" ) String current ,
@RequestParam( "password" ) String pass1 , @RequestParam( "passwordConfirm" ) String pass2 )
throws SessionException , SessionServerException , SessionMaintenanceException
{
AdminSession aSession = this.getSession( AdminSession.class , request );
SetPasswordResponse response = aSession.changePassword( current , pass1 , pass2 );
if ( !response.isAuthError( ) && response.getPasswordError( ) == PasswordChangeStatus.OK ) {
return this.redirect( "admin-session" );
}
return this.render( model , "internal" , "en" , "changePassword" , response );
}
}

View file

@ -0,0 +1,48 @@
package com.deepclone.lw.web.admin;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import com.deepclone.lw.cmd.admin.prefs.PrefDefaultsResponse;
import com.deepclone.lw.session.SessionException;
import com.deepclone.lw.web.beans.intercept.SessionRequirement;
import com.deepclone.lw.web.beans.session.SessionMaintenanceException;
import com.deepclone.lw.web.beans.session.SessionServerException;
import com.deepclone.lw.web.beans.view.PageControllerBase;
import com.deepclone.lw.web.csess.AdminSession;
@Controller
@SessionRequirement( value = true , subType = "main" , redirectTo = "admin-session" )
public class PreferencesPages
extends PageControllerBase
{
@RequestMapping( "/prefs" )
public String listPrefDefaults( HttpServletRequest request , Model model )
throws SessionException , SessionServerException , SessionMaintenanceException
{
PrefDefaultsResponse response = this.getSession( AdminSession.class , request ).getPrefDefaults( );
if ( !response.isPrivilegeOk( ) ) {
return this.redirect( "main" );
}
return this.render( model , "internal" , "en" , "preferences" , response );
}
@RequestMapping( value = "/prefs.action" , method = RequestMethod.POST )
public String setPrefDefault( HttpServletRequest request , Model model , @RequestParam( "pref" ) String pref ,
@RequestParam( "value" ) String value )
throws SessionException , SessionServerException , SessionMaintenanceException
{
this.getSession( AdminSession.class , request ).setPrefDefault( pref , value );
return this.redirect( "prefs" );
}
}

View file

@ -0,0 +1,54 @@
package com.deepclone.lw.web.admin;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import com.deepclone.lw.session.SessionException;
import com.deepclone.lw.web.beans.intercept.SessionRequirement;
import com.deepclone.lw.web.beans.session.ClientSessionReference;
import com.deepclone.lw.web.beans.session.SessionMaintenanceException;
import com.deepclone.lw.web.beans.session.SessionServerException;
import com.deepclone.lw.web.beans.view.PageControllerBase;
import com.deepclone.lw.web.csess.AdminSession;
@Controller
@SessionRequirement( value = true , redirectTo = "login" )
public class SessionPages
extends PageControllerBase
{
@RequestMapping( "/admin-session" )
public String login( HttpServletRequest request , Model model )
{
ClientSessionReference cReference = (ClientSessionReference) request.getSession( ).getAttribute( "sReference" );
String type = cReference.getReference( ).extra;
if ( "pass".equals( type ) ) {
return this.redirect( "change-password" );
}
return this.redirect( "main" );
}
@RequestMapping( "/main" )
public String main( HttpServletRequest request , Model model )
throws SessionException , SessionServerException , SessionMaintenanceException
{
AdminSession session = this.getSession( AdminSession.class , request );
return this.render( model , "internal" , "en" , "main" , session.getOverview( ) );
}
@RequestMapping( value = "/logout.action" )
public String validation( HttpServletRequest request , Model model )
throws SessionServerException , SessionException
{
this.getSession( AdminSession.class , request ).terminate( );
return this.redirect( "login" );
}
}

View file

@ -0,0 +1,89 @@
package com.deepclone.lw.web.admin;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import com.deepclone.lw.cmd.admin.AdminResponse;
import com.deepclone.lw.cmd.admin.adata.Privileges;
import com.deepclone.lw.session.SessionException;
import com.deepclone.lw.web.beans.intercept.SessionRequirement;
import com.deepclone.lw.web.beans.msgs.MessageFormatter;
import com.deepclone.lw.web.beans.session.SessionMaintenanceException;
import com.deepclone.lw.web.beans.session.SessionServerException;
import com.deepclone.lw.web.beans.view.PageControllerBase;
import com.deepclone.lw.web.csess.AdminSession;
@Controller
@SessionRequirement( value = true , redirectTo = "admin-session" , subType = "main" )
public class SpamPages
extends PageControllerBase
{
private MessageFormatter formatter;
@Autowired( required = true )
public void setFormatter( MessageFormatter formatter )
{
this.formatter = formatter;
}
@RequestMapping( "/send-spam" )
public String sendSpam( HttpServletRequest request , Model model )
throws SessionException , SessionServerException , SessionMaintenanceException
{
AdminResponse response = this.getSession( AdminSession.class , request ).noOp( Privileges.SPAM );
if ( !response.isPrivilegeOk( ) ) {
return this.redirect( "main" );
}
return this.render( model , "internal" , "en" , "spam" , response );
}
@RequestMapping( value = "/send-spam.action" , method = RequestMethod.POST )
public String sendSpam( HttpServletRequest request , Model model , @RequestParam( "title" ) String title ,
@RequestParam( "body" ) String body , @RequestParam( value = "preview" , required = false ) String preview )
throws SessionException , SessionServerException , SessionMaintenanceException
{
boolean tError , bError;
title = title.trim( );
body = body.trim( );
tError = ( title.length( ) < 5 || title.length( ) > 64 );
bError = ( body.length( ) < 10 );
AdminResponse response;
if ( ( tError || bError || preview != null ) ) {
response = this.getSession( AdminSession.class , request ).noOp( Privileges.SPAM );
if ( !response.isPrivilegeOk( ) ) {
return this.redirect( "main" );
}
} else {
this.getSession( AdminSession.class , request ).sendSpam( title , body );
return this.redirect( "send-spam" );
}
Map< String , Object > data = new HashMap< String , Object >( );
data.put( "admin" , response.getAdmin( ) );
data.put( "title" , title );
data.put( "body" , body );
data.put( "preview" , this.formatter.formatMessage( body , false ) );
data.put( "titleError" , (Boolean) tError );
data.put( "bodyError" , (Boolean) bError );
return this.render( model , "internal" , "en" , "spam" , data );
}
}

View file

@ -0,0 +1,186 @@
package com.deepclone.lw.web.admin;
import java.util.LinkedList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import com.deepclone.lw.cmd.admin.AdminResponse;
import com.deepclone.lw.cmd.admin.adata.Privileges;
import com.deepclone.lw.cmd.admin.su.AddAdministratorResponse;
import com.deepclone.lw.cmd.admin.su.ListAdministratorsResponse;
import com.deepclone.lw.cmd.admin.su.ViewAdministratorResponse;
import com.deepclone.lw.session.SessionException;
import com.deepclone.lw.web.beans.intercept.SessionRequirement;
import com.deepclone.lw.web.beans.session.SessionMaintenanceException;
import com.deepclone.lw.web.beans.session.SessionServerException;
import com.deepclone.lw.web.beans.view.PageControllerBase;
import com.deepclone.lw.web.csess.AdminSession;
@Controller
@SessionRequirement( value = true , subType = "main" , redirectTo = "admin-session" )
public class SuperUserPages
extends PageControllerBase
{
@RequestMapping( "/admins" )
public String listAdministrators( HttpServletRequest request , Model model )
throws SessionException , SessionServerException , SessionMaintenanceException
{
ListAdministratorsResponse response = this.getSession( AdminSession.class , request ).listAdmins( );
if ( !response.isPrivilegeOk( ) ) {
return this.redirect( "main" );
}
return this.render( model , "internal" , "en" , "admins" , response );
}
@RequestMapping( "/add-admin" )
public String addAdministrator( HttpServletRequest request , Model model )
throws SessionException , SessionServerException , SessionMaintenanceException
{
AdminResponse response = this.getSession( AdminSession.class , request ).noOp( Privileges.SUPER );
if ( !response.isPrivilegeOk( ) ) {
return this.redirect( "main" );
}
return this.render( model , "internal" , "en" , "addAdmin" , response );
}
@RequestMapping( value = "/add-admin.action" , method = RequestMethod.POST )
public String addAdministrator( HttpServletRequest request , Model model ,
@RequestParam( "address" ) String address , @RequestParam( "name" ) String name ,
@RequestParam( value = "privileges" , required = false ) String[] sPrivs )
throws SessionException , SessionServerException , SessionMaintenanceException
{
List< Privileges > privs = this.getPrivileges( sPrivs );
AddAdministratorResponse response;
response = this.getSession( AdminSession.class , request ).addAdmin( address , name , privs );
if ( !response.isPrivilegeOk( ) ) {
return this.redirect( "main" );
} else if ( !response.isError( ) ) {
return this.redirect( "admins" );
}
return this.render( model , "internal" , "en" , "addAdmin" , response );
}
@RequestMapping( "/admin-{id}" )
public String viewAdministrator( HttpServletRequest request , Model model , @PathVariable( "id" ) String sId )
throws SessionException , SessionServerException , SessionMaintenanceException
{
int id;
try {
id = Integer.parseInt( sId );
} catch ( NumberFormatException e ) {
return this.redirect( "admins" );
}
ViewAdministratorResponse response = this.getSession( AdminSession.class , request ).viewAdministrator( id );
if ( !response.isPrivilegeOk( ) ) {
return this.redirect( "main" );
} else if ( response.getView( ) == null ) {
return this.redirect( "admins" );
}
return this.render( model , "internal" , "en" , "viewAdmin" , response );
}
@RequestMapping( "/reset-admin-{id}.action" )
public String resetAdministrator( HttpServletRequest request , Model model , @PathVariable( "id" ) String sId )
throws SessionException , SessionServerException , SessionMaintenanceException
{
int id;
try {
id = Integer.parseInt( sId );
} catch ( NumberFormatException e ) {
return this.redirect( "admins" );
}
ViewAdministratorResponse response = this.getSession( AdminSession.class , request ).viewAdministrator( id );
if ( !response.isPrivilegeOk( ) ) {
return this.redirect( "main" );
} else if ( response.getView( ) == null || response.getView( ).getPrivileges( ).isEmpty( ) ) {
return this.redirect( "admins" );
}
return this.render( model , "internal" , "en" , "resetAdmin" , response );
}
@RequestMapping( value = "/do-reset-admin-{id}.action" , method = RequestMethod.POST )
public String confirmResetAdministrator( HttpServletRequest request , Model model ,
@PathVariable( "id" ) String sId , @RequestParam( value = "cancel" , required = false ) String sCancel )
throws SessionException , SessionServerException , SessionMaintenanceException
{
int id;
try {
id = Integer.parseInt( sId );
} catch ( NumberFormatException e ) {
return this.redirect( "admins" );
}
if ( sCancel != null ) {
return this.redirect( "admin-" + id );
}
ViewAdministratorResponse response = this.getSession( AdminSession.class , request ).resetAdministrator( id );
if ( !response.isPrivilegeOk( ) ) {
return this.redirect( "main" );
} else if ( response.getView( ) == null ) {
return this.redirect( "admins" );
}
return this.redirect( "admin-" + id );
}
@RequestMapping( value = "/admin-privileges-{id}.action" , method = RequestMethod.POST )
public String setPrivileges( HttpServletRequest request , Model model , @PathVariable( "id" ) String sId ,
@RequestParam( value = "privileges" , required = false ) String[] sPrivs )
throws SessionException , SessionServerException , SessionMaintenanceException
{
int id;
try {
id = Integer.parseInt( sId );
} catch ( NumberFormatException e ) {
return this.redirect( "admins" );
}
List< Privileges > privs = this.getPrivileges( sPrivs );
ViewAdministratorResponse response;
response = this.getSession( AdminSession.class , request ).setAdminPrivileges( id , privs );
if ( !response.isPrivilegeOk( ) ) {
return this.redirect( "main" );
} else if ( response.getView( ) == null ) {
return this.redirect( "admins" );
}
return this.redirect( "admin-" + id );
}
private List< Privileges > getPrivileges( String[] sPrivs )
{
List< Privileges > privs = new LinkedList< Privileges >( );
if ( sPrivs != null ) {
for ( String sPriv : sPrivs ) {
try {
privs.add( Privileges.valueOf( sPriv ) );
} catch ( IllegalArgumentException e ) {
// EMPTY
}
}
}
return privs;
}
}

View file

@ -0,0 +1,101 @@
package com.deepclone.lw.web.admin;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import com.deepclone.lw.cmd.admin.tick.TickerStatusResponse;
import com.deepclone.lw.session.SessionException;
import com.deepclone.lw.web.beans.intercept.SessionRequirement;
import com.deepclone.lw.web.beans.session.SessionMaintenanceException;
import com.deepclone.lw.web.beans.session.SessionServerException;
import com.deepclone.lw.web.beans.view.PageControllerBase;
import com.deepclone.lw.web.csess.AdminSession;
@Controller
@SessionRequirement( value = true , subType = "main" , redirectTo = "admin-session" )
public class TickerPages
extends PageControllerBase
{
@RequestMapping( "/ticker" )
public String viewStatus( HttpServletRequest request , Model model )
throws SessionException , SessionServerException , SessionMaintenanceException
{
TickerStatusResponse response = this.getSession( AdminSession.class , request ).getTickerStatus( );
if ( !response.isPrivilegeOk( ) ) {
return this.redirect( "main" );
}
return this.render( model , "internal" , "en" , "ticker" , response );
}
@RequestMapping( "/toggle-ticker.action" )
public String toggleTicker( HttpServletRequest request , Model model )
throws SessionException , SessionServerException , SessionMaintenanceException
{
this.getSession( AdminSession.class , request ).toggleTicker( );
return this.redirect( "ticker" );
}
@RequestMapping( "/start-ticker-task-{id}.action" )
public String startTask( HttpServletRequest request , Model model , @PathVariable( "id" ) String sId )
throws SessionException , SessionServerException , SessionMaintenanceException
{
return this.setTickerTaskStatus( request , sId , true );
}
@RequestMapping( "/stop-ticker-task-{id}.action" )
public String stopTask( HttpServletRequest request , Model model , @PathVariable( "id" ) String sId )
throws SessionException , SessionServerException , SessionMaintenanceException
{
return this.setTickerTaskStatus( request , sId , false );
}
private String setTickerTaskStatus( HttpServletRequest request , String sId , boolean run )
throws SessionException , SessionServerException , SessionMaintenanceException
{
int id;
try {
id = Integer.parseInt( sId );
} catch ( NumberFormatException e ) {
return this.redirect( "ticker" );
}
this.getSession( AdminSession.class , request ).setTickerTaskStatus( id , run );
return this.redirect( "ticker" );
}
@RequestMapping( value = "/set-ticker-task-{id}.action" , method = RequestMethod.POST )
public String setTaskDelay( HttpServletRequest request , Model model , @PathVariable( "id" ) String sId ,
@RequestParam( "delay" ) String sDelay , @RequestParam( "multiplier" ) String sMultiplier )
throws SessionException , SessionServerException , SessionMaintenanceException
{
int id;
long delay , multiplier;
try {
id = Integer.parseInt( sId );
delay = Long.parseLong( sDelay );
multiplier = Long.parseLong( sMultiplier );
} catch ( NumberFormatException e ) {
return this.redirect( "ticker" );
}
delay *= multiplier;
if ( delay <= 0 ) {
return this.redirect( "ticker" );
}
this.getSession( AdminSession.class , request ).setTickerTaskStatus( id , delay );
return this.redirect( "ticker" );
}
}

View file

@ -0,0 +1,144 @@
package com.deepclone.lw.web.admin;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import com.deepclone.lw.cmd.admin.users.AccountStatus;
import com.deepclone.lw.cmd.admin.users.ListAccountsResponse;
import com.deepclone.lw.cmd.admin.users.ListSessionsResponse;
import com.deepclone.lw.cmd.admin.users.ViewAccountResponse;
import com.deepclone.lw.session.SessionException;
import com.deepclone.lw.web.beans.intercept.SessionRequirement;
import com.deepclone.lw.web.beans.session.SessionMaintenanceException;
import com.deepclone.lw.web.beans.session.SessionServerException;
import com.deepclone.lw.web.beans.view.PageControllerBase;
import com.deepclone.lw.web.csess.AdminSession;
@Controller
@SessionRequirement( value = true , subType = "main" , redirectTo = "admin-session" )
public class UsersPages
extends PageControllerBase
{
@RequestMapping( "/users" )
public String listUsers( HttpServletRequest request , Model model ,
@RequestParam( value = "online" , required = false ) String sOnline )
throws SessionException , SessionServerException , SessionMaintenanceException
{
AdminSession aSession = this.getSession( AdminSession.class , request );
ListAccountsResponse list;
if ( "1".equals( sOnline ) ) {
list = aSession.listOnlineUsers( );
} else {
list = aSession.listUsers( );
}
if ( !list.isPrivilegeOk( ) ) {
return this.redirect( "main" );
}
return this.render( model , "internal" , "en" , "users" , list );
}
@RequestMapping( "/users-by-status" )
public String listUsers( HttpServletRequest request , Model model , @RequestParam( "status" ) String sStatus ,
@RequestParam( value = "online" , required = false ) String sOnline )
throws SessionException , SessionServerException , SessionMaintenanceException
{
AccountStatus status;
try {
status = AccountStatus.valueOf( sStatus );
} catch ( IllegalArgumentException e ) {
return this.redirect( "users" + ( "1".equals( sOnline ) ? "?online=1" : "" ) );
}
AdminSession aSession = this.getSession( AdminSession.class , request );
ListAccountsResponse list;
if ( "1".equals( sOnline ) ) {
list = aSession.listOnlineUsers( status );
} else {
list = aSession.listUsers( status );
}
if ( !list.isPrivilegeOk( ) ) {
return this.redirect( "main" );
}
return this.render( model , "internal" , "en" , "users" , list );
}
@RequestMapping( "/user-{id}" )
public String viewUser( HttpServletRequest request , Model model , @PathVariable( "id" ) String sId )
throws SessionException , SessionServerException , SessionMaintenanceException
{
int id;
try {
id = Integer.parseInt( sId );
} catch ( NumberFormatException e ) {
return this.redirect( "users" );
}
ViewAccountResponse response = this.getSession( AdminSession.class , request ).viewUser( id );
if ( !response.isPrivilegeOk( ) ) {
return this.redirect( "main" );
} else if ( response.getAccount( ) == null ) {
return this.redirect( "users" );
}
return this.render( model , "internal" , "en" , "user" , response );
}
@RequestMapping( "/user-{id}-sessions" )
public String viewUserSessions( HttpServletRequest request , Model model , @PathVariable( "id" ) String sId )
throws SessionException , SessionServerException , SessionMaintenanceException
{
int id;
try {
id = Integer.parseInt( sId );
} catch ( NumberFormatException e ) {
return this.redirect( "users" );
}
ListSessionsResponse response = this.getSession( AdminSession.class , request ).viewUserSessions( id );
if ( !response.isPrivilegeOk( ) ) {
return this.redirect( "main" );
} else if ( response.getAccount( ) == null ) {
return this.redirect( "users" );
}
return this.render( model , "internal" , "en" , "userSessions" , response );
}
@RequestMapping( value = "/user-{id}.action" , method = RequestMethod.POST )
public String grantCredits( HttpServletRequest request , Model model , @PathVariable( "id" ) String sId ,
@RequestParam( "credits" ) String sCredits )
throws SessionException , SessionServerException , SessionMaintenanceException
{
int id;
try {
id = Integer.parseInt( sId );
} catch ( NumberFormatException e ) {
return this.redirect( "users" );
}
int credits;
try {
credits = Integer.parseInt( sCredits );
} catch ( NumberFormatException e ) {
credits = 0;
}
if ( credits > 0 ) {
this.getSession( AdminSession.class , request ).giveCredits( id , credits );
}
return this.redirect( "user-" + id );
}
}

View file

@ -0,0 +1,28 @@
package com.deepclone.lw.web.admin.i18ne;
import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
import com.thoughtworks.xstream.annotations.XStreamImplicit;
@SuppressWarnings( "serial" )
@XStreamAlias( "language" )
public class LanguageExport
implements Serializable
{
@XStreamAsAttribute
public String id;
@XStreamAsAttribute
public String name;
@XStreamImplicit
public List< StringExport > strings = new LinkedList< StringExport >( );
}

View file

@ -0,0 +1,21 @@
package com.deepclone.lw.web.admin.i18ne;
import java.io.Serializable;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
@SuppressWarnings( "serial" )
@XStreamAlias( "inline-string" )
public class StringExport
implements Serializable
{
@XStreamAsAttribute
public String id;
public String value;
}

View file

@ -0,0 +1,5 @@
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
log4j.rootLogger=warn, stdout