This commit is contained in:
2026-04-20 20:32:59 +03:00
parent fc96a95335
commit b7875bb623
2 changed files with 54 additions and 20 deletions

View File

@@ -42,6 +42,36 @@ server {
proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Proto $scheme;
} }
location /phpmyadmin/ {
allow 80.68.9.83;
allow 185.51.125.202;
# Локальные сети
allow 192.168.0.0/16; # 192.168.0.0 - 192.168.255.255
allow 10.0.0.0/8; # 10.0.0.0 - 10.255.255.255
allow 172.16.0.0/12; # 172.16.0.0 - 172.31.255.255
allow fd00::/8; # IPv6 ULA (аналог приватных IPv4)
allow fe80::/10; # IPv6 link-local
# Localhost
allow 127.0.0.0/8; # 127.0.0.0 - 127.255.255.255
allow ::1; # IPv6 localhost
# Docker сети (если используете)
allow 172.17.0.0/16;
allow 172.18.0.0/16;
deny all;
proxy_pass http://127.0.0.1:7102/;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
listen 443 ssl; listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/iiko-app.dev.xserver.su/fullchain.pem; ssl_certificate /etc/letsencrypt/live/iiko-app.dev.xserver.su/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/iiko-app.dev.xserver.su/privkey.pem; ssl_certificate_key /etc/letsencrypt/live/iiko-app.dev.xserver.su/privkey.pem;

View File

@@ -7,6 +7,9 @@ import io.vertx.sqlclient.Pool;
import io.vertx.sqlclient.Row; import io.vertx.sqlclient.Row;
import io.vertx.sqlclient.templates.SqlTemplate; import io.vertx.sqlclient.templates.SqlTemplate;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@@ -18,6 +21,23 @@ public class RestaurantService {
this.pool = pool; this.pool = pool;
} }
// Хеширование пароля SHA-1
private String hashPassword(String password) {
try {
MessageDigest md = MessageDigest.getInstance("SHA-1");
byte[] hash = md.digest(password.getBytes(StandardCharsets.UTF_8));
StringBuilder hexString = new StringBuilder();
for (byte b : hash) {
String hex = Integer.toHexString(0xff & b);
if (hex.length() == 1) hexString.append('0');
hexString.append(hex);
}
return hexString.toString();
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException("SHA-1 algorithm not found", e);
}
}
public Future<Void> initDatabase() { public Future<Void> initDatabase() {
String createTable = """ String createTable = """
CREATE TABLE IF NOT EXISTS restaurants ( CREATE TABLE IF NOT EXISTS restaurants (
@@ -31,7 +51,6 @@ public class RestaurantService {
updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) )
"""; """;
return pool.query(createTable).execute().mapEmpty(); return pool.query(createTable).execute().mapEmpty();
} }
@@ -42,10 +61,11 @@ public class RestaurantService {
} }
public Future<Void> createRestaurant(String name, String login, String password, String host, boolean https) { public Future<Void> createRestaurant(String name, String login, String password, String host, boolean https) {
String hashedPassword = hashPassword(password);
Map<String, Object> params = Map.of( Map<String, Object> params = Map.of(
"name", name, "name", name,
"login", login, "login", login,
"password", password, "password", hashedPassword,
"host", host, "host", host,
"https", https "https", https
); );
@@ -55,23 +75,6 @@ public class RestaurantService {
.mapEmpty(); .mapEmpty();
} }
public Future<JsonObject> findByName(String name) {
return SqlTemplate.forQuery(pool,
"SELECT id, name, login, password, created, updated, host FROM restaurants WHERE name = #{name}")
.mapTo(row -> new JsonObject()
.put("id", row.getInteger("id"))
.put("name", row.getString("name"))
.put("login", row.getString("login"))
.put("password", row.getString("password"))
.put("created", row.getLocalDateTime("created") != null ?
row.getLocalDateTime("created").toString() : null)
.put("updated", row.getLocalDateTime("updated") != null ?
row.getLocalDateTime("updated").toString() : null)
.put("host", row.getString("host")))
.execute(Collections.singletonMap("name", name))
.map(rows -> rows.iterator().hasNext() ? rows.iterator().next() : null);
}
public Future<JsonArray> getAllRestaurants() { public Future<JsonArray> getAllRestaurants() {
return pool.query("SELECT id, name, login, created, updated, https, host FROM restaurants ORDER BY id") return pool.query("SELECT id, name, login, created, updated, https, host FROM restaurants ORDER BY id")
.execute() .execute()
@@ -118,7 +121,8 @@ public class RestaurantService {
params.put("https", https); params.put("https", https);
String sql; String sql;
if (password != null && !password.isEmpty()) { if (password != null && !password.isEmpty()) {
params.put("password", password); String hashedPassword = hashPassword(password);
params.put("password", hashedPassword);
sql = "UPDATE restaurants SET name = #{name}, login = #{login}, password = #{password}, host = #{host}, https = #{https} WHERE id = #{id}"; sql = "UPDATE restaurants SET name = #{name}, login = #{login}, password = #{password}, host = #{host}, https = #{https} WHERE id = #{id}";
} else { } else {
sql = "UPDATE restaurants SET name = #{name}, login = #{login}, host = #{host}, https = #{https} WHERE id = #{id}"; sql = "UPDATE restaurants SET name = #{name}, login = #{login}, host = #{host}, https = #{https} WHERE id = #{id}";