-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Check extensions of uploaded files to deny webshell uploading - Forbid admin to delete/relegate himself - Improve error pages - Disable Struts devmode
- Loading branch information
1 parent
c5b1755
commit 43b901e
Showing
6 changed files
with
90 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,80 @@ | ||
package bookstore.action; | ||
|
||
import java.io.File; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.apache.commons.io.FilenameUtils; | ||
|
||
import bookstore.model.result.FailureMessage; | ||
import bookstore.model.result.SuccessMessage; | ||
import bookstore.service.AppService; | ||
|
||
public class UploadImageAction extends BaseAction { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
private File file; | ||
private String filename; | ||
|
||
private final static String uploadPath = "img/upload/"; | ||
|
||
private Object retJson; | ||
|
||
private AppService appService; | ||
|
||
// Getters and setters | ||
|
||
public void setImage(File file) { | ||
this.file = file; | ||
this.file = file; | ||
} | ||
|
||
public void setImageFileName(String filename) { | ||
this.filename = filename; | ||
} | ||
} | ||
|
||
public Object getRetJson() { | ||
return retJson; | ||
} | ||
|
||
public void setRetJson(Object retJson) { | ||
this.retJson = retJson; | ||
} | ||
|
||
public AppService getAppService() { | ||
return appService; | ||
} | ||
|
||
public void setAppService(AppService appService) { | ||
this.appService = appService; | ||
} | ||
|
||
// Actions | ||
|
||
public String execute() { | ||
|
||
if (session().getAttribute("user") == null) { | ||
retJson = new FailureMessage("请先登录"); | ||
return LOGIN; | ||
} | ||
|
||
|
||
List<String> allowedExtensions = Arrays.asList(".jpg", ".jpeg", ".png", ".bmp", ".gif"); | ||
if (allowedExtensions.indexOf(FilenameUtils.getExtension(filename)) == -1) { | ||
retJson = new FailureMessage("上传失败!仅支持 JPG、PNG、BMP、GIF 图片格式!"); | ||
return ERROR; | ||
} | ||
|
||
String newFilename = appService.uploadImage(FilenameUtils.concat(application().getRealPath("/"), uploadPath), | ||
file, filename); | ||
|
||
if (newFilename.isEmpty()) { | ||
retJson = new FailureMessage("上传失败!请检查文件大小和格式。"); | ||
return ERROR; | ||
} | ||
|
||
retJson = new SuccessMessage(newFilename); | ||
return SUCCESS; | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.