Исправил баг с загрузкой конфигурации AP сети в Settings. Добавил возможность изменять из в админ панели. Применил их к AP сети. Изменил функциональность endpoint'ов и удалил лишние. Обновил README
This commit is contained in:
@@ -20,78 +20,83 @@ Password: admin
|
||||
|
||||

|
||||
|
||||
## API управления (Управляющие Endpoint'ы)
|
||||
## API
|
||||
|
||||
Все эндпоинты управления требуют **HTTP Basic Auth** авторизации. В случае неуспешной авторизации сервер возвращает статус `401 Unauthorized`.
|
||||
Все перечисленные endpoint'ы требуют **HTTP Basic Auth**. При неуспешной авторизации сервер возвращает `401 Unauthorized`. Для запросов с JSON передавайте данные в теле запроса.
|
||||
|
||||
При отправке настроек, некорректный JSON или отсутствие обязательных полей вызовет ответ со статусом `400 Bad Request`.
|
||||
|
||||
---
|
||||
Некорректный JSON, неверный формат IP-адреса или отсутствие обязательных полей приводит к ответу `400 Bad Request`.
|
||||
|
||||
### Обновление настроек точки доступа (AP)
|
||||
* **URL:** `/settings/ap_update`
|
||||
* **Метод:** `POST` (передается в теле запроса `plain`)
|
||||
* **Тело запроса (JSON):**
|
||||
```json
|
||||
{
|
||||
"ssid": "Имя_сети_AP",
|
||||
"pass": "Пароль_сети_AP"
|
||||
}
|
||||
```
|
||||
* **Ответ:** `200 OK` (после успешного сохранения устройство перезагружается).
|
||||
- **URL:** `/settings/ap_update`
|
||||
- **Метод:** `POST`
|
||||
- **Поля JSON:** `ssid` и `pass` должны передаваться вместе; оба поля можно не указывать. Также можно передать `ip`, `gateway` и `mask` независимо друг от друга.
|
||||
|
||||
### Обновление настроек подключения к роутеру (STA)
|
||||
* **URL:** `/settings/sta_update`
|
||||
* **Метод:** `POST`
|
||||
* **Тело запроса (JSON):**
|
||||
```json
|
||||
{
|
||||
"ssid": "Имя_вашего_WIFI",
|
||||
"pass": "Пароль_от_WIFI"
|
||||
}
|
||||
```
|
||||
* **Ответ:** `200 OK` (после успешного сохранения устройство перезагружается).
|
||||
```json
|
||||
{
|
||||
"ssid": "Имя_сети_AP",
|
||||
"pass": "Пароль_сети_AP",
|
||||
"ip": "192.168.4.1",
|
||||
"gateway": "192.168.4.1",
|
||||
"mask": "255.255.255.0"
|
||||
}
|
||||
```
|
||||
|
||||
Ответ: `200 OK`; после сохранения устройство перезагружается.
|
||||
|
||||
### Обновление настроек подключения к внешней сети (STA)
|
||||
- **URL:** `/settings/sta_update`
|
||||
- **Метод:** `POST`
|
||||
- **Обязательные поля JSON:** `is_conn_out` (boolean), `ssid` и `pass` (строки).
|
||||
|
||||
```json
|
||||
{
|
||||
"is_conn_out": true,
|
||||
"ssid": "Имя_вашего_WIFI",
|
||||
"pass": "Пароль_от_WIFI"
|
||||
}
|
||||
```
|
||||
|
||||
Ответ: `200 OK`. Если `is_conn_out` равен `true`, устройство перезагружается. При `true` поле `ssid` не может быть пустым.
|
||||
|
||||
### Изменение пароля администратора
|
||||
* **URL:** `/settings/admin_update`
|
||||
* **Метод:** `POST`
|
||||
* **Тело запроса (JSON):**
|
||||
```json
|
||||
{
|
||||
"new_pass": "Новый_пароль_админа"
|
||||
}
|
||||
```
|
||||
* **Ответ:** `200 OK`.
|
||||
- **URL:** `/settings/admin_update`
|
||||
- **Метод:** `POST`
|
||||
- **Обязательное поле JSON:** `new_pass`.
|
||||
|
||||
### Получение статуса внешнего подключения (Conn Out)
|
||||
* **URL:** `/settings/is_conn_out`
|
||||
* **Метод:** `GET`
|
||||
* **Ответ:** `200 OK` c JSON-контентом `application/json`:
|
||||
```json
|
||||
{
|
||||
"is_conn_out": true
|
||||
}
|
||||
```
|
||||
```json
|
||||
{
|
||||
"new_pass": "Новый_пароль_админа"
|
||||
}
|
||||
```
|
||||
|
||||
### Установка статуса внешнего подключения (Conn Out)
|
||||
* **URL:** `/settings/set_conn_out`
|
||||
* **Метод:** `POST`
|
||||
* **Тело запроса (JSON):**
|
||||
```json
|
||||
{
|
||||
"is_conn_out": true
|
||||
}
|
||||
```
|
||||
* **Ответ:** `200 OK` (после успешного изменения устройство перезагружается).
|
||||
Ответ: `200 OK`.
|
||||
|
||||
### Получение текущих настроек
|
||||
Возвращает настройки сети без паролей.
|
||||
- **URL:** `/settings/current_settings`
|
||||
- **Метод:** `GET`
|
||||
- **Ответ:** `200 OK`, `application/json`.
|
||||
|
||||
```json
|
||||
{
|
||||
"ip": "192.168.4.1",
|
||||
"gateway": "192.168.4.1",
|
||||
"mask": "255.255.255.0",
|
||||
"sta_ssid": "Имя_вашего_WIFI",
|
||||
"ap_ssid": "Имя_сети_AP",
|
||||
"is_conn_out": true
|
||||
}
|
||||
```
|
||||
|
||||
### Получение списка подключенных клиентов
|
||||
Возвращает сетевые параметры устройств, подключенных в данный момент к точке доступа коммутатора (SoftAP).
|
||||
* **URL:** `/user_list`
|
||||
* **Метод:** `GET`
|
||||
* **Ответ:** `200 OK` с JSON-контентом `application/json`:
|
||||
```json
|
||||
{
|
||||
"user_ip": ["192.168.4.2", "192.168.4.3"],
|
||||
"user_mac": ["a1:b2:c3:d4:e5:f6", "7a:8b:9c:0d:1e:2f"]
|
||||
}
|
||||
```
|
||||
Возвращает IP- и MAC-адреса устройств, подключенных к точке доступа (SoftAP).
|
||||
- **URL:** `/user_list`
|
||||
- **Метод:** `GET`
|
||||
- **Ответ:** `200 OK`, `application/json`.
|
||||
|
||||
```json
|
||||
{
|
||||
"user_ip": ["192.168.4.2", "192.168.4.3"],
|
||||
"user_mac": ["a1:b2:c3:d4:e5:f6", "7a:8b:9c:0d:1e:2f"]
|
||||
}
|
||||
```
|
||||
|
||||
+209
-8
@@ -1,9 +1,93 @@
|
||||
/* Специфичное ограничение ширины для карточек настроек */
|
||||
.main-content {
|
||||
max-width: 700px;
|
||||
/* ==========================================================================
|
||||
ИМПОРТ ИЛИ СЛИЯНИЕ С БАЗОВЫМИ СТИЛЯМИ (base.css)
|
||||
========================================================================== */
|
||||
body {
|
||||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||
background-color: #121212;
|
||||
color: #ffffff;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
h1 {
|
||||
color: #ff6600;
|
||||
margin: 0 0 30px 0;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 2px;
|
||||
border-bottom: 2px solid #ff6600;
|
||||
padding-bottom: 10px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
/* ШАПКА (TOP BAR) */
|
||||
.top-bar {
|
||||
width: 100%;
|
||||
background-color: #1a1a1a;
|
||||
border-bottom: 2px solid #ff6600;
|
||||
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.top-bar-container {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 0 20px;
|
||||
height: 60px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.logo {
|
||||
font-size: 20px;
|
||||
font-weight: bold;
|
||||
color: #ffffff;
|
||||
text-decoration: none;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 1px;
|
||||
}
|
||||
|
||||
.logo span {
|
||||
color: #ff6600;
|
||||
}
|
||||
|
||||
.nav-links {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.nav-link {
|
||||
color: #e0e0e0;
|
||||
text-decoration: none;
|
||||
font-size: 15px;
|
||||
transition: color 0.2s ease;
|
||||
}
|
||||
|
||||
.nav-link:hover,
|
||||
.nav-link.active {
|
||||
color: #ff6600;
|
||||
}
|
||||
|
||||
.nav-link.active {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
/* ==========================================================================
|
||||
СПЕЦИФИЧНЫЕ СТИЛИ СТРАНИЦЫ НАСТРОЕК
|
||||
========================================================================== */
|
||||
.main-content {
|
||||
width: 100%;
|
||||
max-width: 740px; /* 700px + padding */
|
||||
padding: 40px 20px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
/* Ссылка назад к списку */
|
||||
.back-link {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
@@ -19,20 +103,20 @@
|
||||
color: #ff6600;
|
||||
}
|
||||
|
||||
/* Сетка для блоков настроек */
|
||||
.settings-grid {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 30px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
/* Карточка настроек */
|
||||
.settings-card {
|
||||
background-color: #1a1a1a;
|
||||
border-radius: 8px;
|
||||
padding: 30px;
|
||||
box-shadow: 0 4px 15px rgba(255, 102, 0, 0.05);
|
||||
border: 1px solid #2a2a2a;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.card-title {
|
||||
@@ -43,6 +127,10 @@
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
border-bottom: none;
|
||||
padding-bottom: 0;
|
||||
text-transform: none;
|
||||
letter-spacing: normal;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
@@ -52,6 +140,17 @@
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
/* Строчный контейнер для трех полей (IP, Gateway, Mask) */
|
||||
.form-row-three {
|
||||
display: flex;
|
||||
gap: 15px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.form-row-three .form-group {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
label {
|
||||
color: #a0a0a0;
|
||||
font-size: 14px;
|
||||
@@ -79,6 +178,18 @@ input[type="password"]:focus {
|
||||
box-shadow: 0 0 8px rgba(255, 102, 0, 0.2);
|
||||
}
|
||||
|
||||
/* Чекбоксы */
|
||||
.checkbox-group {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
margin-bottom: 25px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.checkbox-group input[type="checkbox"] {
|
||||
position: absolute;
|
||||
opacity: 0;
|
||||
@@ -96,6 +207,7 @@ input[type="password"]:focus {
|
||||
display: inline-block;
|
||||
position: relative;
|
||||
transition: all 0.2s ease;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.checkbox-group:hover input[type="checkbox"] ~ .checkmark {
|
||||
@@ -131,7 +243,7 @@ input[type="password"]:focus {
|
||||
letter-spacing: 0.5px;
|
||||
}
|
||||
|
||||
/* Кнопка отправки формы */
|
||||
/* Кнопка отправки */
|
||||
.submit-btn {
|
||||
background-color: #ff6600;
|
||||
color: #000000;
|
||||
@@ -153,12 +265,95 @@ input[type="password"]:focus {
|
||||
box-shadow: 0 4px 12px rgba(255, 102, 0, 0.3);
|
||||
}
|
||||
|
||||
/* Адаптивность для карточек и инпутов */
|
||||
/* Текстовый блок "Текущие настройки" */
|
||||
.info-card {
|
||||
border-left: 4px solid #ff6600;
|
||||
}
|
||||
|
||||
.info-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 14px;
|
||||
}
|
||||
|
||||
.info-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding-bottom: 10px;
|
||||
border-bottom: 1px solid #222222;
|
||||
}
|
||||
|
||||
.info-item:last-child {
|
||||
border-bottom: none;
|
||||
padding-bottom: 0;
|
||||
}
|
||||
|
||||
.info-label {
|
||||
color: #a0a0a0;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.info-value {
|
||||
color: #ffffff;
|
||||
font-weight: 600;
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
/* Цвета статусов */
|
||||
.status-connected {
|
||||
color: #00cc66;
|
||||
background-color: rgba(0, 204, 102, 0.1);
|
||||
padding: 4px 8px;
|
||||
border-radius: 4px;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.status-disconnected {
|
||||
color: #ff3333;
|
||||
background-color: rgba(255, 51, 51, 0.1);
|
||||
padding: 4px 8px;
|
||||
border-radius: 4px;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
/* ==========================================================================
|
||||
АДАПТИВНОСТЬ
|
||||
========================================================================== */
|
||||
@media (max-width: 768px) {
|
||||
.top-bar-container {
|
||||
height: auto;
|
||||
padding: 12px 16px;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.nav-links {
|
||||
width: 100%;
|
||||
justify-content: space-between;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.main-content {
|
||||
padding: 24px 14px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 24px;
|
||||
letter-spacing: 1px;
|
||||
}
|
||||
|
||||
.settings-card {
|
||||
padding: 20px 16px;
|
||||
}
|
||||
|
||||
.form-row-three {
|
||||
flex-direction: column;
|
||||
gap: 0;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
@@ -171,4 +366,10 @@ input[type="password"]:focus {
|
||||
padding: 12px 10px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.info-item {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 6px;
|
||||
}
|
||||
}
|
||||
|
||||
+104
-98
@@ -4,131 +4,137 @@
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Панель управления — Настройки сети</title>
|
||||
|
||||
<link rel="stylesheet" href="/base.css">
|
||||
<link rel="stylesheet" href="/settings.css">
|
||||
<link rel="stylesheet" href="settings.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<!-- ВЕРХНЯЯ ПАНЕЛЬ (TOP BAR) -->
|
||||
<!-- Шапка (Top Bar) -->
|
||||
<header class="top-bar">
|
||||
<div class="top-bar-container">
|
||||
<a href="#" class="logo">Admin<span>Panel</span></a>
|
||||
|
||||
<a href="#" class="logo">Admin <span>Panel</span></a>
|
||||
<nav class="nav-links">
|
||||
<a href="/" class="nav-link">Главная</a>
|
||||
<a href="/" class="nav-link">Пользователи</a>
|
||||
<a href="#" class="nav-link active">Настройки</a>
|
||||
<a href="/#" class="nav-link">Главная</a>
|
||||
<a href="/#" class="nav-link">Пользователи</a>
|
||||
<a href="/settings#" class="nav-link active">Настройки</a>
|
||||
</nav>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<!-- Основной контент страницы -->
|
||||
<main class="main-content">
|
||||
|
||||
<a href="/" class="back-link">
|
||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<line x1="19" y1="12" x2="5" y2="12"></line>
|
||||
<polyline points="12 19 5 12 12 5"></polyline>
|
||||
</svg>
|
||||
<a href="/#" class="back-link">
|
||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="19" y1="12" x2="5" y2="12"></line><polyline points="12 19 5 12 12 5"></polyline></svg>
|
||||
Назад к списку пользователей
|
||||
</a>
|
||||
|
||||
<h1>Настройки</h1>
|
||||
|
||||
<div class="settings-grid">
|
||||
|
||||
<!-- БЛОК 1: НАСТРОЙКИ СЕТИ (WI-FI) -->
|
||||
<div class="settings-card">
|
||||
<div class="card-title">
|
||||
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#ff6600" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M5 12.55a11 11 0 0 1 14.08 0"></path>
|
||||
<path d="M1.42 9a16 16 0 0 1 21.16 0"></path>
|
||||
<path d="M8.53 16.11a6 6 0 0 1 6.94 0"></path>
|
||||
<line x1="12" y1="20" x2="12.01" y2="20" stroke-width="3"></line>
|
||||
</svg>
|
||||
Параметры AP сети
|
||||
|
||||
<!-- ТЕКСТОВЫЙ БЛОК: ТЕКУЩИЕ НАСТРОЙКИ (БЕЗ ПАРОЛЕЙ) -->
|
||||
<section class="settings-card info-card">
|
||||
<h2 class="card-title">
|
||||
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="16" x2="12" y2="12"></line><line x1="12" y1="8" x2="12.01" y2="8"></line></svg>
|
||||
Текущие настройки сети
|
||||
</h2>
|
||||
<div class="info-group">
|
||||
<div class="info-item">
|
||||
<span class="info-label">Режим точки доступа (AP SSID):</span>
|
||||
<span class="info-value" id="current-ap-ssid">—</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">Подключение к внешней сети (STA SSID):</span>
|
||||
<span class="info-value" id="current-sta-ssid">—</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">IP-адрес:</span>
|
||||
<span class="info-value" id="current-ip">—</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">Шлюз (Gateway):</span>
|
||||
<span class="info-value" id="current-gateway">—</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">Маска подсети (Mask):</span>
|
||||
<span class="info-value" id="current-mask">—</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">Внешняя:</span>
|
||||
<span class="info-value status-connected" id="connection-status">Подключено</span>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Параметры AP сети -->
|
||||
<section class="settings-card">
|
||||
<h2 class="card-title">Параметры AP сети</h2>
|
||||
<div class="form-group">
|
||||
<label for="ap-ssid">Имя сети (SSID)</label>
|
||||
<input type="text" id="ap-ssid" placeholder="Введите имя AP сети">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="ap-password">Пароль от Wi-Fi</label>
|
||||
<input type="password" id="ap-password" placeholder="••••••••">
|
||||
</div>
|
||||
|
||||
<div class="form-row-three">
|
||||
<div class="form-group">
|
||||
<label for="sta-ip">IP адрес</label>
|
||||
<input type="text" id="ap-ip" placeholder="192.168.4.1">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="sta-gateway">Шлюз (Gateway)</label>
|
||||
<input type="text" id="ap-gateway" placeholder="192.168.4.1">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="sta-mask">Маска (Mask)</label>
|
||||
<input type="text" id="ap-mask" placeholder="255.255.255.0">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<form action="#" method="POST">
|
||||
<!-- Имя сети (SSID) -->
|
||||
<div class="form-group">
|
||||
<label for="ap-ssid">Имя сети (SSID)</label>
|
||||
<input type="text" id="ap-ssid" name="ap_ssid" required placeholder="Например: Home_Network">
|
||||
</div>
|
||||
<button type="button" class="submit-btn" id="ap_update">Обновить настройки сети</button>
|
||||
</section>
|
||||
|
||||
<!-- Пароль сети -->
|
||||
<div class="form-group">
|
||||
<label for="ap-password">Пароль от Wi-Fi</label>
|
||||
<input type="password" id="ap-password" name="ap_password" required placeholder="Минимум 8 символов">
|
||||
</div>
|
||||
|
||||
<button id="ap_update" type="button" class="submit-btn">Обновить настройки сети</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="settings-card">
|
||||
<div class="card-title">
|
||||
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#ff6600" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M5 12.55a11 11 0 0 1 14.08 0"></path>
|
||||
<path d="M1.42 9a16 16 0 0 1 21.16 0"></path>
|
||||
<path d="M8.53 16.11a6 6 0 0 1 6.94 0"></path>
|
||||
<line x1="12" y1="20" x2="12.01" y2="20" stroke-width="3"></line>
|
||||
</svg>
|
||||
Параметры STA сети
|
||||
<!-- Параметры STA сети -->
|
||||
<section class="settings-card">
|
||||
<h2 class="card-title">Параметры STA сети</h2>
|
||||
<div class="form-group">
|
||||
<label for="sta-ssid">Имя сети (SSID)</label>
|
||||
<input type="text" id="sta-ssid" placeholder="Введите имя внешней сети">
|
||||
</div>
|
||||
|
||||
<form action="#" method="POST">
|
||||
<!-- Имя сети (SSID) -->
|
||||
<div class="form-group">
|
||||
<label for="sta-ssid">Имя сети (SSID)</label>
|
||||
<input type="text" id="sta-ssid" name="sta_ssid" required placeholder="Например: Home_Network">
|
||||
</div>
|
||||
|
||||
<!-- Пароль сети -->
|
||||
<div class="form-group">
|
||||
<label for="sta-password">Пароль от сети</label>
|
||||
<input type="password" id="sta-password" name="sta_password" required placeholder="Минимум 8 символов">
|
||||
</div>
|
||||
|
||||
<button id="sta_update" type="button" class="submit-btn">Обновить настройки сети</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- КАСТОМНЫЙ CHECKBUTTON: CONNECTION_OUT -->
|
||||
<label class="form-group checkbox-group">
|
||||
<input type="checkbox" id="connection-out" name="connection_out">
|
||||
<span class="checkmark"></span>
|
||||
<span class="checkbox-label">Подключение к внешней сети</span>
|
||||
</label>
|
||||
|
||||
<!-- БЛОК 2: БЕЗОПАСНОСТЬ (АДМИН) -->
|
||||
<div class="settings-card">
|
||||
<div class="card-title">
|
||||
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#ff6600" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<rect x="3" y="11" width="18" height="11" rx="2" ry="2"></rect>
|
||||
<path d="M7 11V7a5 5 0 0 1 10 0v4"></path>
|
||||
</svg>
|
||||
Безопасность (Смена пароля администратора)
|
||||
<div class="form-group">
|
||||
<label for="sta-password">Пароль от сети</label>
|
||||
<input type="password" id="sta-password" placeholder="••••••••">
|
||||
</div>
|
||||
|
||||
<!-- Подключение к внешней сети (Checkbox) -->
|
||||
<label class="checkbox-group">
|
||||
<input type="checkbox" id="connection-out">
|
||||
<span class="checkmark"></span>
|
||||
<span class="checkbox-label">Подключение к внешней сети</span>
|
||||
</label>
|
||||
|
||||
<form action="#" method="POST">
|
||||
<div class="form-group">
|
||||
<label for="new-password">Новый пароль</label>
|
||||
<input type="password" id="new-password" name="new_password" required placeholder="Минимум 8 знаков">
|
||||
</div>
|
||||
<button type="button" class="submit-btn" id="sta_update">Обновить настройки сети</button>
|
||||
</section>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="confirm-password">Подтвердите новый пароль</label>
|
||||
<input type="password" id="confirm-password" name="confirm_password" required placeholder="••••••••">
|
||||
</div>
|
||||
|
||||
<button id="admin_update" type="button" class="submit-btn">Сохранить изменения</button>
|
||||
</form>
|
||||
</div>
|
||||
<!-- Безопасность (Смена пароля администратора) -->
|
||||
<section class="settings-card">
|
||||
<h2 class="card-title">Безопасность (Смена пароля администратора)</h2>
|
||||
<div class="form-group">
|
||||
<label for="new-password">Новый пароль</label>
|
||||
<input type="password" id="new-password" placeholder="Новый пароль">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="confirm-password">Подтвердите новый пароль</label>
|
||||
<input type="password" id="confirm-password" placeholder="Подтвердите новый пароль">
|
||||
</div>
|
||||
<button type="button" class="submit-btn" id="admin_update">Сохранить изменения</button>
|
||||
</section>
|
||||
|
||||
</div>
|
||||
</main>
|
||||
|
||||
</body>
|
||||
<script src="settings.js"></script>
|
||||
</html>
|
||||
<script src="/settings.js"></script>
|
||||
</html>
|
||||
|
||||
+71
-39
@@ -1,30 +1,53 @@
|
||||
async function ap_update()
|
||||
{
|
||||
const ssid = document.querySelector('#ap-ssid');
|
||||
const pass = document.querySelector('#ap-password');
|
||||
const ssid = document.getElementById('ap-ssid');
|
||||
const pass = document.getElementById('ap-password');
|
||||
const ip = document.getElementById('ap-ip');
|
||||
const gateway = document.getElementById('ap-gateway');
|
||||
const mask = document.getElementById('ap-mask');
|
||||
|
||||
const response = await fetch("/settings/ap_update", {
|
||||
let body = {};
|
||||
|
||||
if (ssid.value != "")
|
||||
{
|
||||
body.ssid = ssid.value;
|
||||
if (pass.value === "")
|
||||
body.pass = "";
|
||||
else
|
||||
body.pass = pass.value;
|
||||
}
|
||||
if (ip.value != "")
|
||||
body.ip = ip.value;
|
||||
if (gateway.value != "")
|
||||
body.gateway = gateway.value;
|
||||
if (mask.value != "")
|
||||
body.mask = mask.value;
|
||||
|
||||
const res = await fetch("/settings/ap_update",{
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Content-Type': 'application/json;charset=utf-8'
|
||||
'Content-Type': 'application/json;charset=utf-8'
|
||||
},
|
||||
body: JSON.stringify({ssid: ssid.value, pass: pass.value})
|
||||
body: JSON.stringify(body)
|
||||
});
|
||||
|
||||
if (!response.ok)
|
||||
alert("Fail set AP settings");
|
||||
if (res.ok)
|
||||
init();
|
||||
else
|
||||
alert("Неудплось обновить параметры AP сети");
|
||||
}
|
||||
async function sta_update()
|
||||
{
|
||||
const ssid = document.querySelector('#sta-ssid');
|
||||
const pass = document.querySelector('#sta-password');
|
||||
const ssid = document.getElementById('sta-ssid');
|
||||
const pass = document.getElementById('sta-password');
|
||||
const checkbox = document.getElementById('connection-out');
|
||||
|
||||
const response = await fetch("/settings/sta_update", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Content-Type': 'application/json;charset=utf-8'
|
||||
},
|
||||
body: JSON.stringify({ssid: ssid.value, pass: pass.value})
|
||||
body: JSON.stringify({ssid: ssid.value, pass: pass.value, is_conn_out: checkbox.checked})
|
||||
});
|
||||
|
||||
if (!response.ok)
|
||||
@@ -53,40 +76,52 @@ async function admin_update()
|
||||
alert("Ошибка! Пароль не обновился");
|
||||
}
|
||||
|
||||
async function set_conn_out()
|
||||
{
|
||||
const checkbox = document.getElementById('connection-out');
|
||||
function updateConnectionStatus(isConnected/*, networkName = ''*/) {
|
||||
const statusElem = document.getElementById('connection-status');
|
||||
|
||||
const response = await fetch("/settings/set_conn_out", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Content-Type': 'application/json;charset=utf-8'
|
||||
},
|
||||
body: JSON.stringify({is_conn_out: checkbox.checked})
|
||||
});
|
||||
|
||||
if (!response.ok)
|
||||
alert("Fail set CONN_TO_OUT settings");
|
||||
if (isConnected) {
|
||||
statusElem.textContent = 'Подключено';
|
||||
statusElem.className = 'info-value status-connected';
|
||||
} else {
|
||||
statusElem.textContent = 'Отключено';
|
||||
statusElem.className = 'info-value status-disconnected';
|
||||
|
||||
ssidElem.textContent = '—';
|
||||
}
|
||||
}
|
||||
|
||||
async function init()
|
||||
{
|
||||
try {
|
||||
const res = await fetch("/settings/is_conn_out", {
|
||||
method: "GET"
|
||||
});
|
||||
const res = await fetch("/settings/current_settings");
|
||||
if (res.ok)
|
||||
{
|
||||
const json = await res.json();
|
||||
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
|
||||
const conn_out = document.getElementById('connection-out');
|
||||
const current_sta = document.getElementById('current-sta-ssid');
|
||||
current_sta.textContent = json["sta_ssid"];
|
||||
|
||||
conn_out.checked = data.is_conn_out;
|
||||
} else {
|
||||
console.warn("Сервер вернул ошибку:", res.status);
|
||||
const current_ap = document.getElementById('current-ap-ssid');
|
||||
current_ap.textContent = json["ap_ssid"];
|
||||
|
||||
const current_ip = document.getElementById('current-ip');
|
||||
current_ip.textContent = json["ip"];
|
||||
|
||||
const current_gateway = document.getElementById('current-gateway');
|
||||
current_gateway.textContent = json["gateway"];
|
||||
|
||||
const current_mask = document.getElementById('current-mask');
|
||||
current_mask.textContent = json["mask"];
|
||||
|
||||
updateConnectionStatus(json["is_conn_out"]);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Ошибка при выполнении запроса:", error);
|
||||
else
|
||||
{
|
||||
alert("Неудалось получть текущие настройки");
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.log("Ошибка во время запроса настроек: ", error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,7 +135,4 @@ button = document.querySelector('#sta_update');
|
||||
button.addEventListener('click', sta_update);
|
||||
|
||||
button = document.querySelector('#admin_update');
|
||||
button.addEventListener('click', admin_update);
|
||||
|
||||
const checkbox = document.getElementById('connection-out');
|
||||
checkbox.addEventListener('change', set_conn_out);
|
||||
button.addEventListener('click', admin_update);
|
||||
@@ -12,7 +12,6 @@
|
||||
platform = espressif8266
|
||||
board = esp12e
|
||||
framework = arduino
|
||||
upload_port = COM6
|
||||
monitor_speed = 115200
|
||||
board_build.filesystem = littlefs
|
||||
lib_deps =
|
||||
|
||||
+11
-3
@@ -48,9 +48,17 @@ void Settings::init()
|
||||
DELAY = atoi(settings.readStringUntil('\n').c_str());
|
||||
CNT_RETRY = atoi(settings.readStringUntil('\n').c_str());
|
||||
|
||||
IP.fromString(settings.readStringUntil('\n'));
|
||||
GATEWAY.fromString(settings.readStringUntil('\n'));
|
||||
MASK.fromString(settings.readStringUntil('\n'));
|
||||
String str_ip = settings.readStringUntil('\n');
|
||||
str_ip.trim();
|
||||
IP.fromString(str_ip);
|
||||
|
||||
String str_gateway = settings.readStringUntil('\n');
|
||||
str_gateway.trim();
|
||||
GATEWAY.fromString(str_gateway);
|
||||
|
||||
String str_mask = settings.readStringUntil('\n');
|
||||
str_mask.trim();
|
||||
MASK.fromString(str_mask);
|
||||
|
||||
String str_conn_out = settings.readStringUntil('\n');
|
||||
str_conn_out.trim();
|
||||
|
||||
+114
-70
@@ -152,22 +152,83 @@ void WebServer::ap_update()
|
||||
web_server.send(400);
|
||||
return;
|
||||
}
|
||||
if (json["ssid"].isNull() || json["pass"].isNull())
|
||||
if (json["ssid"].isNull() != json["pass"].isNull())
|
||||
{
|
||||
web_server.send(400);
|
||||
return;
|
||||
}
|
||||
|
||||
String ssid = json["ssid"];
|
||||
if (ssid.isEmpty())
|
||||
if (json["ip"].isNull() == false)
|
||||
{
|
||||
web_server.send(400);
|
||||
return;
|
||||
String str = json["ip"];
|
||||
IPAddress ip;
|
||||
if(ip.fromString(str) == false)
|
||||
{
|
||||
web_server.send(400);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (json["gateway"].isNull() == false)
|
||||
{
|
||||
String str = json["gateway"];
|
||||
IPAddress gateway;
|
||||
if(gateway.fromString(str) == false)
|
||||
{
|
||||
web_server.send(400);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (json["mask"].isNull() == false)
|
||||
{
|
||||
String str = json["mask"];
|
||||
IPAddress mask;
|
||||
if(mask.fromString(str) == false)
|
||||
{
|
||||
web_server.send(400);
|
||||
return;
|
||||
}
|
||||
}
|
||||
settings_.setAPSSID(ssid);
|
||||
|
||||
String pass = json["pass"];
|
||||
settings_.setAPPASS(pass);
|
||||
if (json["ssid"].isNull() == false)
|
||||
{
|
||||
settings_.setAPSSID(json["ssid"]);
|
||||
settings_.setAPPASS(json["pass"]);
|
||||
}
|
||||
if (json["ip"].isNull() == false)
|
||||
{
|
||||
String str = json["ip"];
|
||||
IPAddress ip;
|
||||
if(ip.fromString(str))
|
||||
settings_.setSelfIP(ip);
|
||||
else
|
||||
{
|
||||
web_server.send(400);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (json["gateway"].isNull() == false)
|
||||
{
|
||||
String str = json["gateway"];
|
||||
IPAddress gateway;
|
||||
if(gateway.fromString(str))
|
||||
settings_.setGateway(gateway);
|
||||
else
|
||||
{
|
||||
web_server.send(400);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (json["mask"].isNull() == false)
|
||||
{
|
||||
String str = json["mask"];
|
||||
IPAddress mask;
|
||||
if(mask.fromString(str))
|
||||
settings_.setMask(mask);
|
||||
else
|
||||
{
|
||||
web_server.send(400);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
web_server.send(200);
|
||||
@@ -189,26 +250,31 @@ void WebServer::sta_update()
|
||||
web_server.send(400);
|
||||
return;
|
||||
}
|
||||
if (json["ssid"].isNull() || json["pass"].isNull())
|
||||
|
||||
if (json["is_conn_out"].isNull() || json["ssid"].isNull() || json["pass"].isNull())
|
||||
{
|
||||
web_server.send(400);
|
||||
return;
|
||||
}
|
||||
|
||||
String ssid = json["ssid"];
|
||||
if (ssid.isEmpty() && json["is_conn_out"] == true)
|
||||
{
|
||||
web_server.send(400);
|
||||
return;
|
||||
}
|
||||
|
||||
String ssid = json["ssid"];
|
||||
if (ssid.isEmpty())
|
||||
{
|
||||
web_server.send(400);
|
||||
return;
|
||||
}
|
||||
settings_.setModemSSID(ssid);
|
||||
|
||||
String pass = json["pass"];
|
||||
settings_.setConnToOut(json["is_conn_out"]);
|
||||
settings_.setModemSSID(ssid);
|
||||
settings_.setModemPASS(pass);
|
||||
|
||||
web_server.send(200);
|
||||
delay(100);
|
||||
ESP.restart();
|
||||
if (json["is_conn_out"] == true)
|
||||
{
|
||||
delay(100);
|
||||
ESP.restart();
|
||||
}
|
||||
}
|
||||
void WebServer::admin_update()
|
||||
{
|
||||
@@ -234,48 +300,6 @@ void WebServer::admin_update()
|
||||
settings_.setAdminPass(json["new_pass"]);
|
||||
web_server.send(200);
|
||||
}
|
||||
void WebServer::is_conn_out()
|
||||
{
|
||||
if (!web_server.authenticate(settings_.getAdminLogin().c_str(), settings_.getAdminPass().c_str()))
|
||||
{
|
||||
web_server.send(401);
|
||||
return;
|
||||
}
|
||||
|
||||
bool is_conn_out = settings_.getConnToOut();
|
||||
JsonDocument json;
|
||||
json["is_conn_out"] = is_conn_out;
|
||||
String serialize;
|
||||
serializeJson(json, serialize);
|
||||
web_server.send(200, "application/json", serialize);
|
||||
}
|
||||
|
||||
void WebServer::set_conn_out()
|
||||
{
|
||||
if (!web_server.authenticate(settings_.getAdminLogin().c_str(), settings_.getAdminPass().c_str()))
|
||||
{
|
||||
web_server.send(401);
|
||||
return;
|
||||
}
|
||||
|
||||
JsonDocument json;
|
||||
DeserializationError err = deserializeJson(json, web_server.arg("plain"));
|
||||
if (err)
|
||||
{
|
||||
web_server.send(400);
|
||||
return;
|
||||
}
|
||||
if (json["is_conn_out"].isNull())
|
||||
{
|
||||
web_server.send(400);
|
||||
return;
|
||||
}
|
||||
|
||||
settings_.setConnToOut(json["is_conn_out"]);
|
||||
web_server.send(200);
|
||||
delay(100);
|
||||
ESP.restart();
|
||||
}
|
||||
|
||||
void WebServer::get_user_list()
|
||||
{
|
||||
@@ -313,6 +337,30 @@ void WebServer::get_user_list()
|
||||
web_server.send(200, "application/json", serialized);
|
||||
}
|
||||
|
||||
void WebServer::get_cuurent_settings()
|
||||
{
|
||||
if (!web_server.authenticate(settings_.getAdminLogin().c_str(), settings_.getAdminPass().c_str()))
|
||||
{
|
||||
web_server.send(401);
|
||||
return;
|
||||
}
|
||||
|
||||
JsonDocument json;
|
||||
|
||||
json["ip"] = settings_.getSelfIP().toString();
|
||||
json["gateway"] = settings_.getGateway().toString();
|
||||
json["mask"] = settings_.getMask().toString();
|
||||
|
||||
json["sta_ssid"] = settings_.getModemSSID();
|
||||
json["ap_ssid"] = settings_.getAPSSID();
|
||||
|
||||
json["is_conn_out"] = settings_.getConnToOut();
|
||||
|
||||
String body;
|
||||
serializeJson(json, body);
|
||||
web_server.send(200, "application/json", body);
|
||||
}
|
||||
|
||||
WebServer::WebServer(Settings& settings, int port):
|
||||
web_server(port),
|
||||
settings_(settings)
|
||||
@@ -351,19 +399,15 @@ settings_(settings)
|
||||
web_server.on("/settings/admin_update", [this](){
|
||||
admin_update();
|
||||
});
|
||||
|
||||
web_server.on("/settings/is_conn_out", [this](){
|
||||
is_conn_out();
|
||||
});
|
||||
|
||||
web_server.on("/settings/set_conn_out", [this](){
|
||||
set_conn_out();
|
||||
});
|
||||
|
||||
web_server.on("/user_list", [this](){
|
||||
get_user_list();
|
||||
});
|
||||
|
||||
web_server.on("/settings/current_settings", [this](){
|
||||
get_cuurent_settings();
|
||||
});
|
||||
|
||||
web_server.begin();
|
||||
}
|
||||
|
||||
|
||||
+3
-5
@@ -25,13 +25,11 @@ class WebServer
|
||||
// Смена пароля администратора
|
||||
void admin_update();
|
||||
|
||||
// Возвращает флаг IS_CONN_TO_OUT из настроек
|
||||
void is_conn_out();
|
||||
// Установить значение IS_CONN_TO_OUT в настройках
|
||||
void set_conn_out();
|
||||
|
||||
// Получить список пользователей
|
||||
void get_user_list();
|
||||
|
||||
// Возвращает текущие настройки без паролей
|
||||
void get_cuurent_settings();
|
||||
|
||||
public:
|
||||
WebServer(Settings& settings, int port = 80);
|
||||
|
||||
+34
-4
@@ -79,7 +79,10 @@ void setup() {
|
||||
Serial.println();
|
||||
|
||||
if (!LittleFS.begin()) {
|
||||
Serial.println("An Error has occurred while mounting LittleFS");
|
||||
Serial.println("[-] Неудалось инициализировать LittleFS");
|
||||
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -91,14 +94,41 @@ void setup() {
|
||||
else
|
||||
WiFi.mode(WIFI_AP);
|
||||
|
||||
if (WiFi.softAPConfig(settings.getSelfIP(), settings.getGateway(), settings.getMask()))
|
||||
{
|
||||
Serial.println("[+] Конфигурация AP сети: ");
|
||||
Serial.print("\tIP:\t\t");
|
||||
Serial.println(settings.getSelfIP().toString().c_str());
|
||||
Serial.print("\tGATEWAY:\t");
|
||||
Serial.println(settings.getGateway().toString().c_str());
|
||||
Serial.print("\tMASK:\t\t");
|
||||
Serial.println(settings.getMask().toString().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
WiFi.mode(WIFI_OFF);
|
||||
Serial.println("[-] Неудалось применить конфигурацию к AP сети");
|
||||
Serial.print("\tIP:\t\t");
|
||||
Serial.println(settings.getSelfIP().toString().c_str());
|
||||
Serial.print("\tGATEWAY:\t");
|
||||
Serial.println(settings.getGateway().toString().c_str());
|
||||
Serial.print("\tMASK:\t\t");
|
||||
Serial.println(settings.getMask().toString().c_str());
|
||||
|
||||
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
return;
|
||||
}
|
||||
|
||||
if (WiFi.softAP(settings.getAPSSID(), settings.getAPPASS()))
|
||||
{
|
||||
Serial.println("[+] AP mode started");
|
||||
Serial.print("\tSSID: ");
|
||||
Serial.print("\tSSID:\t");
|
||||
Serial.println(settings.getAPSSID());
|
||||
Serial.print("\tPASS: ");
|
||||
Serial.print("\tPASS:\t");
|
||||
Serial.println(settings.getAPPASS());
|
||||
Serial.print("\tAP IP: ");
|
||||
Serial.print("\tAP IP:\t");
|
||||
Serial.println(WiFi.softAPIP());
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user