GithubHelp home page GithubHelp logo

dromara / ujcms Goto Github PK

View Code? Open in Web Editor NEW
45.0 3.0 19.0 88.54 MB

Java开源网站内容管理系统(java cms)。使用SpringBoot、MyBatis、Spring Security、Lucene、FreeMarker、TypeScript、Vue3、ElementPlus等技术开发。

Home Page: https://www.ujcms.com

License: Apache License 2.0

JavaScript 2.16% Java 89.40% HTML 8.20% CSS 0.08% SCSS 0.12% Dockerfile 0.04%
java cms mybatis vue3 element-plus

ujcms's Introduction

UJCMS

Java开源网站内容管理系统(java cms)、Java建站系统。使用SpringBoot、MyBatis、Spring Security、Lucene、FreeMarker、TypeScript、Vue3、ElementPlus等技术开发。使用Apache-2.0开源协议,可免费用于商业网站。

支持无头CMS,可使用模板(Freemarker)+标签或Vue(React)+API方式制作网站。支持自定义字段及字段可视化设计,自定义字段在前后端均可作为搜索条件。

技术上尽量选择主流、先进、简单的架构,方便用户进行二次开发。设计上强调“简单”、“灵活”,避免繁杂的设计和实现,降低系统维护成本和二次开发难度。功能使用上也要求“简单”,避免复杂的使用逻辑。

QQ交流群:626599871

微信交流群:加作者微信拉入群

UJCMS交流群

技术及功能亮点

自定义字段可查询:支持自定义字段,且所有的自定义字段都可查询,极大地增强了系统的灵活性。

自定义字段可视化设计:自定义字段使用拖拽式的可视化设计,所见即所得。

MyBatis参数化查询:数据通常会需要通过不同字段进行搜索,对每个表都写大量的查询,无疑是一项繁重的工作。MyBatis参数化查询功能通过前台传递查询参数,即可实现任意字段及关联表的查询功能(如:Q_title=abc,Q_user-username=test),无需后台编写代码,大幅减少后端的开发工作量。后台开发和前台标签(API)均可使用参数化查询,因此标签(API)几乎可以实现任意查询效果。

URL地址SEO优化:栏目和文章的动态地址可以通过系统的全局设置功能进行修改。默认的栏目和文章URL地址前缀为/channel/article,可以根据自己的需要修改,如改为/categories/archives。多站点的情况下,子站点URL地址可为目录形式(www.example.com/abc)或次级域名形式(abc.example.com)。

清理垃圾附件:系统使用时,可能会多传、误传图片等附件;在删除文章后,文章中的图片还保留在系统中,产生大量的未使用的垃圾图片和附件。系统中的附件管理可以查看所有未使用的图片和附件,并可对其进行删除。

附件、模板、索引文件独立部署:系统运行时产生的文件可以和程序分开,部署到独立的目录,方便系统备份、升级和管理。比如上传的图片和附件、前台的模板、索引文件,都可以部署到程序以外的目录。

模板文件和CSS、JS在同一目录:模板文件和CSS、JS分开的目录结构,会给模板制作和部署带来很大的不便性。而将模板文件和CSS、JS放在一起的设计,会方便很多。

主副表拆分:对查询量大的复杂表进行主副表拆分,把常用查询字段放到主表,不常用的字段放到副表,提升大数据量下的性能表现。

环境要求

  • JDK 11
  • MySQL 8.0 (5.7.22+)
  • Tomcat 9.0 (Servlet 3.1+)
  • Maven 3.6.3 (3.5.4)
  • 系统后台兼容的浏览器:Chrome、Firefox、Edge
  • 前台页面兼容的浏览器取决于模板,使用者可以完全控制模板,理论上可以支持任何浏览器。演示模板支持Chrome、Firefox、Edge

创建数据库

  1. 创建数据库。数据库名可为ujcms或其它任何名称。
  • MySQL,字符集选utf8mb4(不要选择utf8,该字符集可能导致某些特殊字符出现乱码)。
  • 达梦数据库,字符集选UTF-8(不要使用GB18030,该字符集可能导致某些特殊字符出现乱码)。
  • 人大金仓数据库,字符集选UTF8(不要使用GBK,该字符集可能导致某些特殊字符出现乱码)。
  1. 无需执行SQL文件,程序启动时会自动创建表及初始化数据。以后程序升级同样不需要执行SQL升级脚本,程序启动时会判断当前软件版本及数据库表结构版本,自动进行数据库表结构升级。

MySQL表名大小写问题

如果在Windows环境使用MySQL,且以后需要迁移到Linux环境的MySQL,建议将Windows环境的MySQL配置为表名大小写敏感模式。

因为Linux环境下MySQL的表名是大小写敏感的;而在Windows环境下MySQL表名大小写不敏感,且会自动把大写的表名改为小写的表名。从Windows向Linux迁移数据时,本为大写表名的成为了小写表名,导致程序出错。需要手动把小写表名改回大写表名,费时费力且容易出错。

UJCMS系统的表名都为小写,不管在Window还是Linux下都没有问题,但第三方的类库(如Liquibase、Flowable、Quartz等)创建的表则为大写表名。所以Windows环境下也把MySQL设置成表名大小写敏感,有利以后迁移数据。

可修改MySQL配置文件my.ini

[mysqld]
# Windows下表名也区分大小写,与Linux一致。
lower_case_table_names=2

此配置必须在MySQL初始化之前设置。一旦MySQL已经启动或初始化,再修改该配置,MySQL将无法再次启动。

启动程序

  1. 在IntelliJ IDEA中打开项目。点击File - Open,选择项目文件夹(有pom.xml的文件夹)。会开始从maven服务器下载第三方jar包(如spring等),需要一定时间,请耐心等待。
  2. 修改数据库连接。打开/src/main/resources/application.yaml文件,根据实际情况修改spring.datasource.urlspring.datasource.usernamespring.datasource.password的值。其中spring.datasource.url中的数据库名要和上一步创建的数据库名一致。
  3. 启动程序。可在左侧Project导航中找到/src/main/java/com/ujcms/cms/Application类,右键点击,选择Run 'Application'。也可直接点击右上角的绿色三角图标(Run 'Application')。
  4. 首次运行程序,会自动创建数据库表和初始化数据库,需要一些时间,请耐心等待,只要没有出现报错信息,说明程序还在启动中,不要急于关闭程序。直到出现类似com.ujcms.cms.Application: Started Application in xxx seconds信息,代表程序启动完成。如果程序首次启动,还在创建数据库表时,强行关闭了程序;再次启动程序可能会出现类似LockException: Could not acquire change log lockWaiting for changelog lock....的报错信息;此时只要将数据库databasechangeloglock表中数据清空(注意,不是databasechangelog表),也可删除数据库所有表甚至重建数据库,再次启动程序即可继续创建数据库表和初始化数据,正常启动。
  5. 前台地址:http://localhost:8080/,使用手机访问前台或者使用浏览器模拟手机访问前台,会自适应显示手机端的界面。如遇到前台页面没有样式的情况,则是因为没有部署在Tomcat的根目录。如前台首页地址类似为http://localhost:8080/abc,即代表部署在/abc目录下,没有部署在根目录。解决办法请参考下一章节内容。
  6. 后台地址:http://localhost:8080/cp/,用户名:admin,密码:password。后台前端基于开发,如要修改后台界面,请另外下载ujcms-cp项目。
  7. 默认访问地址是http://localhost:8080/,如需修改域名、端口等内容,可分别到后台配置 - 系统设置配置 - 站点设置中修改。

常见错误

如程序无法正常编译,通常是因为Maven没有正确下载jar依赖包。可以尝试在IntelliJ IDEA的Maven窗口点击刷新按钮Reload All Maven Projects按钮,尝试重新下载jar依赖包,或者点击菜单Build - Rebuild Project重新编译项目。

如首次使用IntelliJ IDEA,没有配置JDK,也会导致无法正常程序不能编译。可选中项目,点击File - Project Structure...,在Project Settings - Project处,配置Project SDK

如运行时出现flowable-eventregistry-db-changelog.xml::1::flowable: Specified key was too long; max key length is 767 bytes等错误信息,则 MySQL 5.7 需要设置innodb_large_prefix=ON;MySQL 5.6 需要设置innodb_large_prefix=1。从 mysql 5.7.7 开始,innodb_large_prefix的默认值就是ON,因此只要MySQL版本大于5.7.7即可避免这个问题。

部署

  • 使用maven进行打包mvn package -P war。会生成target/ujcms-***.war文件和target/ujcms-***目录。
  • 用目录方式部署的,可以将target/ujcms-***/目录下文件复制到tomcat的webapps/ROOT目录下(请先删除原tomcat/webapps目录下所有文件夹)。复制完成后有类似webapps/ROOT/uploads webapps/ROOT/templates webapps/ROOT/WEB-INF等文件夹。
  • 也可使用war包部署,将ujcms-***.war更名为ROOT.war(注意大小写),复制到tomcat的webapps目录下(请先删除原tomcat/webapps目录下所有文件夹)。复制完成后文件地址为webapps/ROOT.war文件。war部署要使用解压模式,tomcat默认就是使用解压模式,如修改过tomcat配置,请检查tomcat/conf/server.xml配置文件中<Host ... unpackWARs="true" ... >的配置项。
  • 需注意/WEB-INF/classes/application.yaml文件中的数据库地址、用户名、密码相关配置是否与部署环境的数据库一致。

jar部署

  • 使用maven进行打包mvn package -P jar
  • 将打包的target/ujcms-***.jar文件复制到部署目录。
  • 在部署目录(即ujcms-***.jar所在目录)新建文件夹static
  • src/main/webapp目录下所有文件复制到上一步新建的static目录下。复制完成后,会有类似static/WEB-INF static/templates等文件夹。
  • 在部署目录运行java -jar ujcms-***.jar命令,即可启动。

完整目录结构:

  • ujcms-***.jar
  • static/WEB-INF/...
  • static/templates/...
  • static/uploads/...
  • static/cp/...

关于部署路径

程序通常在部署在Tomcat根目录,首页访问地址类似http://www.mysite.com/ http://localhost/ http://localhost:8080/。在一些特殊的场合,如在Eclipse默认的Tomcat启动方式,可能将程序部署在某一个路径下,首页访问地址类似http://www.mysite.com/ujcms/ http://localhost/ujcms/ http://localhost:8080/ujcms/。此时访问网站前台会出现样式不能正常显示的情况,可以到后台配置 - 全局设置中设置上下文路径,类似为/ujcms,其中斜杠/不能省略,ujcms为部署目录的路径,如在开发环境,则通常为项目名。

开发环境要避免使用上下文路径,除非网站正式部署时也要部署到相应的路径下,否则在开发环境下上传的图片部署到正式环境时,不能正常显示。因为上传图片时,图片地址会带有上下文路径的信息(如:/ujcms/uploads/...)。

Eclipse默认的tomcat启动方式会将程序部署到特定目录再启动,并不是直接在项目所在目录启动tomcat,这时上传的图片(包括通过系统后台新增和修改的模板)也保存在特定的部署目录,并不会保存在程序所在的目录。当修改了Eclipse源代码或文件,会自动重新部署程序,之前上传的图片会被清空。如果发现在开发环境下上传的图片突然都找不到了,很可能就是这个原因。

综上所述,强烈建议使用之前启动程序中介绍的方式启动程序。

前台模板

网站前台模板位于/src/main/webapp/templates目录,使用Freemarker技术。通过修改模板文件,可以完全控制网站页面显示的内容。也可使用Vue(React)+API的方式制作网站。

后端技术

  • Spring Boot:提供了对Spring开箱即用的功能。简化了Spring配置,提供自动配置auto-configuration功能。
  • Spring MVC:MVC框架,使用方便,Bug较少。
  • Spring Security:安全组件。
  • MyBatis:持久化框架。
  • Lucene:全文检索组件。

后台前端技术

  • TypeScript: JavaScript的一个超集。
  • Vue3:JavaScript框架。
  • ElementPlus:Vue 3 UI 框架。
  • Vite: 下一代前端开发与构建工具。
  • Tailwind CSS: 功能类优先的 CSS 框架。
  • VueRouter: Vue 路由组件。
  • VueI18n: Vue 国际化组件。
  • Tinymce: 富文本编辑器。

网站前端技术

网站前端技术可以使用传统的HTML(Freemarker),通过UJCMS提供的Freemarker的自定义标签获取数据;也可以使用前后端分离的vue或react,通过调用API获取数据。

由于前后端分离的方式对搜索引擎不友好,对于需要通过搜索引擎推广的网站不建议采用。

演示站使用传统的HTML(Freemarker),使用到以下一些技术:

  • Freemarker
  • HTML、CSS、JS
  • Bootstrap
  • JQuery
  • Axios

目录结构

  • src
    • main
      • java
        • com/ujcms/cms
          • core
            • domain:实体类
            • generator:生成功能(包括静态页生成,全文索引生成)
            • listener:监听类(包括数据删除的监听)
            • lucene:全文检索功能
            • mapper:MyBatis Mapper Java 文件
            • security:安全相关功能
            • service:服务层功能
            • support:各种支持类
            • web
              • api:前台API接口
              • backendapi:后台API接口
              • directive:前台Freemarker自定义标签
              • frontend:前台页面Controller
              • support:Web支持类(包括web拦截器等)
            • ContextConfig.java:Context配置类
            • LuceneConfig.java:全文索引配置类
            • ShiroConfig.java:Shiro安全配置类
            • TaskExecutorConfig.java:任务执行器配置类
          • Application.java 启动类
        • com/ujcms/util:公共工具类
      • resources
        • com/ujcms/cms/core/mapper:MyBatis Mapper XML 配置文件。
        • db
          • changelog:数据库表结构更新日志文件。
          • data.mysql.sql:数据库初始化数据SQL脚本。
        • application.yaml:程序配置文件。包括数据库URL、数据库用户名、数据库密码等信息。
        • messages.properties:国际化资源文件。
      • webapp:
        • cp:后台前端页面。
        • templates:网站前台模板。
        • uploads:用户上传文件。
        • WEB-INF/lucene:全文检索索引文件。
  • .editorconfig:设置编辑器文件的格式,如缩进方式、最大行数等。
  • .gitignore:设置不需要提交到git管理的文件和目录。
  • CHANGELOG.md:版本更新日志。
  • LICENSE:许可协议。
  • gulpfile.js:前台构建文件。具有拷贝jquery、bootstrap等文件至前台模板目录/src/main/webapp/template/1/default/_files等功能。
  • package.json:前台模板依赖的js、css组件,如jquery、bootstrap等。
  • pom.xml:Maven配置文件。

ujcms's People

Contributors

ujcms avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ujcms's Issues

XSS attacks may occur on the UJCMS

Hello, I found that when ujcms V4.1.3 of your company added articles in the background, the redirection link was selected, and the url was not verified when the new window was opened without checking the check box. javascript pseudo-protocol is used to carry out cross-site attack. When the viewer clicks on the article, the cross-site attack is triggered. The user's browser control permissions and sensitive information can be obtained in this way.

Specific steps: When adding new articles, turn to the url and input javascript:alert(1). Click Save. When clicking the new articles in the foreground, js events can be triggered.
CVE-1
CVE-2

Suggestion: If you want to add a forward link, verify the location of the forward url in the system, for example, limit it to HTTP or HTTPS.

Ujcms v8.0.2 has a vulnerability that upload a pdf file with hidden Cross Site Scripting (XSS).

[Vulnerability description]

Ujcms v8.0.2 has a vulnerability that upload a pdf file with hidden Cross Site Scripting (XSS).

[Vulnerability Type]
CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')

[Vendor of Product]
https://gitee.com/ujcms/ujcms
https://github.com/ujcms/ujcms
https://www.ujcms.com/

[Affected Product Code Base]
v8.0.2

[Vulnerability proof]

Condition: tomcat deployment project

  1. we could upload this poc.
    image

  2. click view in edge.
    image

[Repair suggestion]

  1. We should filter the PDF file uploaded by the user to ensure that it does not contain malicious scripts and other content.

arbitrary file upload vulnerability in ujcms v6.0.2

Hello, I found that your ujcms v6.0.2 version has an arbitrary file upload vulnerability in the background.
In the background file -> upload file here, we can upload files, I know you have made restrictions on the suffix of the uploaded file name, for example, jsp files are not allowed to be uploaded. But we can bypass the check by capturing the packet and modifying the file name to "1.jsp." (adding a decimal point to the suffix).

  1. Try to upload 1.jsp file, but it is blocked
    image

  2. Use burpsuite to capture the package, modify the file name to "1.jsp." and then change the Content-Type to "image/png" to upload successfully
    image
    image

  3. Click Browse to download the file, and the suffix of the downloaded file is "jsp" instead of "jsp."
    image
    image

4.Suggestion: Check whether the suffix of the uploaded file name is normal, and prevent the suffix of the malformed symbol like "jsp." from bypassing the security check

Ujcms v6.0.2 has a sensitive file reading problem

[Vulnerability description]

Ujcms v6.0.2 has a sensitive file reading problem. When using Tomcat to deploy the project, the background zip package downloads the html directory, and modifying the dir parameter causes the source code and configuration files to be downloaded

[Vulnerability Type]
Sensitive file reading(Information Disclosure)

[Vendor of Product]
https://gitee.com/ujcms/ujcms
https://github.com/ujcms/ujcms
https://www.ujcms.com/

[Affected Product Code Base]
v6.0.2

[Vulnerability proof]

Condition: tomcat deployment project

The dir parameter is allowed to be set to "WEB-INF/", and the names parameter is allowed to be set to "classes", so that the source code and web configuration files can be downloaded directly.(There is no html directory by default, you can create it directly through the function)

image-20230606124209259

image-20230606125908489

image-20230606130027003

[Code Details]

com.ujcms.cms.core.web.backendapi.AbstractWebFileController#downloadZip
The code checks the two parameters "dir" and "names" separately

image-20230606130152382

com.ujcms.cms.core.web.backendapi.AbstractWebFileController#checkId(java.lang.String)
Check whether there is directory traversal, no restrictions on accessible directories

image-20230606130208683

com.ujcms.cms.core.web.backendapi.AbstractWebFileController#checkName(java.lang.String)Check the file name, when both meet
(1) The file name is empty
(2) The file name contains illegal characters
Accessible directories are not restricted

image-20230606130903428

Ujcms v8.0.2 has a vulnerability that attacker could spoofing servers with IP addresses.

[Vulnerability description]

Ujcms v8.0.2 has a vulnerability that is Reliance on IP Address for Authentication(CWE-291), attacker could spoofing servers with IP addresses and impact log record.

[Vulnerability Type]
CWE-291: Reliance on IP Address for Authentication

[Vendor of Product]
https://gitee.com/ujcms/ujcms
https://github.com/ujcms/ujcms
https://www.ujcms.com/

[Affected Product Code Base]
v8.0.2

[Vulnerability proof]

Condition: tomcat deployment project
the weak java file : src/main/java/com/ujcms/commons/web/Servlets.java

  1. The method to get a real client IP by X-Forwarded-For
    image
  2. If attacker add a X-Forwarded-For: 1.1.1.1 in header, the IP list will be 1.1.1.1, 127.0.0.1, now getRemoteAddr() will get the 127.0.0.1
    image

image
3. And then find the ip from right to left, the left ip is 1.1.1.1
image

The IP impersonation is complete

We can see the fake IP address in the log.
image
many Controllers use this weak method:
image

There is a remote code execution (RCE) vulnerability exists in ujcms v6.0.2

[Vulnerability description]
The Remote Code Execution (RCE) vulnerability exists in ujcms v6.0.2, when the project is partially configured on Linux using Tomcat, attackers can use path traversal and arbitrary file uploads to execute arbitrary code.

[Vulnerability Type]
Remote Code Execution (RCE)

[Vendor of Product]
https://gitee.com/ujcms/ujcms
https://github.com/ujcms/ujcms
https://www.ujcms.com/

[Affected Product Code Base]
v6.0.2

[Vulnerability proof]
The code restricts the access and execution of jsp and jspx files, but it exists in any path and any file upload, so you can upload a web.xml file and add a jsp resolvable suffix, such as abc

<servlet-mapping>
    <servlet-name>jsp</servlet-name>
    <url-pattern>*.abc</url-pattern>
</servlet-mapping>

Condition: It needs to be deployed with tomcat on Linux, and the configuration file cannot be overwritten on Windows, and File.renameTo is used

  1. Upload web.xml
    Download an initial configuration file web.xml of tomcat, and add the above configuration in the following location
    image
    Upload the web.xml file to the uploads directory first, and use the path id to indicate it when uploading, and the path cannot be traversed
    image
    Rename, the capture package can traverse the path at the file name, and overwrite the original web.xml
    image

  2. Upload the Trojan horse
    Upload a Trojan horse and execute the ping command. At this time, the uploaded suffix cannot be the custom analytical suffix above. You can upload any suffix and rename it later, otherwise the upload will not succeed
    image
    The upload suffix is ​​abc1
    image
    Renamed to ../../123.abc, the path traverses to the root directory
    image
    Visit 123.abc and successfully trigger rce
    image

[Code Details]

  1. Upload
    Track the rename interface, find that the parameters are being passed to doUpload, and verify the suffix at the upload
    com.ujcms.cms.core.web.backendapi.AbstractUploadController#doUpload
    image
    The suffix can be uploaded without any problem.

  2. Rename
    com.ujcms.cms.core.web.backendapi.AbstractWebFileController#rename is the same as upload, it has checkName to verify the file name, enter here to view the code
    image
    com.ujcms.cms.core.web.backendapi.AbstractWebFileController#checkName(java.lang.String) Check the file name, when both meet
    (1) The file name is empty
    (2) The file name contains illegal characters
    an exception is thrown, but the first condition is always false, and the conditions cannot be met at the same time, so this verification will always be bypassed, so it can be executed, and then any file can be renamed and uploaded.
    image
    So there is a problem with the judgment logic here, it should be || instead of &&, which leads to the failure of the security check in this place. Of course, this is also the reason why it can be used successfully.
    After passing the verification of this block, use File.renameTo in com.ujcms.util.file.LocalFileHandler#rename to rename the file.
    image
    renameTo cannot overwrite files in Windows, but can overwrite and create directories in Linux, so this vulnerability can only be exploited in Linux.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.