|
25 | 25 | import javax.servlet.ServletConfig; |
26 | 26 | import javax.servlet.ServletException; |
27 | 27 | import javax.servlet.annotation.WebServlet; |
| 28 | +import java.io.File; |
28 | 29 | import java.sql.Connection; |
29 | 30 | import java.sql.PreparedStatement; |
30 | 31 | import java.sql.ResultSet; |
31 | 32 | import java.sql.Statement; |
32 | 33 | import java.util.Scanner; |
33 | 34 |
|
| 35 | +import org.apache.commons.io.FileUtils; |
34 | 36 | import org.apache.commons.lang.RandomStringUtils; |
35 | 37 | import org.apache.commons.lang3.StringUtils; |
36 | 38 | import org.slf4j.Logger; |
@@ -123,11 +125,20 @@ public void init(ServletConfig config) throws ServletException { |
123 | 125 | statement.executeUpdate("create table if not exists session_log (id BIGINT PRIMARY KEY AUTO_INCREMENT, session_tm timestamp default CURRENT_TIMESTAMP, first_nm varchar, last_nm varchar, username varchar not null, ip_address varchar)"); |
124 | 126 | statement.executeUpdate("create table if not exists terminal_log (session_id BIGINT, instance_id INTEGER, output varchar not null, log_tm timestamp default CURRENT_TIMESTAMP, display_nm varchar not null, user varchar not null, host varchar not null, port INTEGER not null, foreign key (session_id) references session_log(id) on delete cascade)"); |
125 | 127 |
|
126 | | - //insert default admin user |
| 128 | + //if exists readfile to set default password |
127 | 129 | String salt = EncryptionUtil.generateSalt(); |
| 130 | + String defaultPassword = EncryptionUtil.hash("changeme" + salt); |
| 131 | + File file = new File("/opt/keybox/instance_id"); |
| 132 | + if (file.exists()) { |
| 133 | + String str = FileUtils.readFileToString(file, "UTF-8"); |
| 134 | + if(StringUtils.isNotEmpty(str)) { |
| 135 | + defaultPassword = EncryptionUtil.hash(str.trim() + salt); |
| 136 | + } |
| 137 | + } |
| 138 | + //insert default admin user |
128 | 139 | PreparedStatement pStmt = connection.prepareStatement("insert into users (username, password, user_type, salt) values(?,?,?,?)"); |
129 | 140 | pStmt.setString(1, "admin"); |
130 | | - pStmt.setString(2, EncryptionUtil.hash("changeme" + salt)); |
| 141 | + pStmt.setString(2, defaultPassword); |
131 | 142 | pStmt.setString(3, Auth.MANAGER); |
132 | 143 | pStmt.setString(4, salt); |
133 | 144 | pStmt.execute(); |
|
0 commit comments