Compare commits

..

6 Commits

13 changed files with 50 additions and 45 deletions

View File

@@ -1 +1 @@
v2.0.3
v2.0.4

View File

@@ -58,21 +58,18 @@ spec:
readOnly: true
# Health checks
startupProbe:
httpGet:
path: /login
tcpSocket:
port: 8080
initialDelaySeconds: 10
periodSeconds: 5
failureThreshold: 30
readinessProbe:
httpGet:
path: /login
tcpSocket:
port: 8080
initialDelaySeconds: 5
periodSeconds: 10
livenessProbe:
httpGet:
path: /login
tcpSocket:
port: 8080
initialDelaySeconds: 10
periodSeconds: 60

View File

@@ -127,15 +127,24 @@ fi
if [ "$current_branch" != "main" ]; then
git checkout main
git merge --no-ff -m "Merged branch '$current_branch' into main while building $VERSION" "$current_branch"
git push origin main
elif [ "$current_branch" = "main" ]; then
log "🔄 Вы находитесь на ветке main. Слияние с release..."
git add .
git commit -m "Исправления в ветке $current_branch"
git push origin main
fi
# переключиться на ветку release и слить с веткой main
git checkout release
git merge --no-ff -m "Merged main into release while building $VERSION" main
if git show-ref --quiet refs/heads/release; then
log " Branch 'release' exists. Proceeding with merge."
git checkout release
git merge --no-ff -m "Merged main into release while building $VERSION" main
else
log "❌ Branch 'release' does not exist. Please create the branch before proceeding."
git checkout -b release
git merge --no-ff -m "Merged main into release while building $VERSION" main
fi
# если тег $VERSION существует, удалить его и принудительно запушить
tag_exists=$(git tag -l "$VERSION")

View File

@@ -1 +1 @@
v2.0.3
v2.0.4

View File

@@ -5,7 +5,7 @@ metadata:
namespace: lcg
data:
# Основные настройки
LCG_VERSION: "v2.0.3"
LCG_VERSION: "v2.0.4"
LCG_BASE_PATH: "/lcg"
LCG_SERVER_HOST: "0.0.0.0"
LCG_SERVER_PORT: "8080"

View File

@@ -5,7 +5,7 @@ metadata:
namespace: lcg
labels:
app: lcg
version: v2.0.3
version: v2.0.4
spec:
replicas: 1
selector:
@@ -15,11 +15,11 @@ spec:
metadata:
labels:
app: lcg
version: v2.0.3
version: v2.0.4
spec:
containers:
- name: lcg
image: kuznetcovay/lcg:v2.0.3
image: kuznetcovay/lcg:v2.0.4
imagePullPolicy: Always
ports:
- containerPort: 8080
@@ -58,21 +58,18 @@ spec:
readOnly: true
# Health checks
startupProbe:
httpGet:
path: /login
tcpSocket:
port: 8080
initialDelaySeconds: 10
periodSeconds: 5
failureThreshold: 30
readinessProbe:
httpGet:
path: /login
tcpSocket:
port: 8080
initialDelaySeconds: 5
periodSeconds: 10
livenessProbe:
httpGet:
path: /login
tcpSocket:
port: 8080
initialDelaySeconds: 10
periodSeconds: 60

View File

@@ -5,7 +5,7 @@ metadata:
namespace: lcg
labels:
app: lcg
version: v2.0.3
version: v2.0.4
spec:
entryPoints:
- websecure

View File

@@ -15,11 +15,11 @@ resources:
# Common labels
commonLabels:
app: lcg
version: v2.0.3
version: v2.0.4
managed-by: kustomize
# Images
images:
- name: lcg
newName: kuznetcovay/lcg
newTag: v2.0.3
newTag: v2.0.4

View File

@@ -5,7 +5,7 @@ metadata:
namespace: lcg
labels:
app: lcg
version: v2.0.3
version: v2.0.4
spec:
type: ClusterIP
ports:
@@ -15,4 +15,4 @@ spec:
name: http
selector:
app: lcg
version: v2.0.3
version: v2.0.4

View File

@@ -14,7 +14,7 @@ import (
func handleLoginPage(w http.ResponseWriter, r *http.Request) {
// Если пользователь уже авторизован, перенаправляем на главную
if isAuthenticated(r) {
http.Redirect(w, r, "/", http.StatusSeeOther)
http.Redirect(w, r, makePath("/"), http.StatusSeeOther)
return
}
@@ -41,6 +41,7 @@ func handleLoginPage(w http.ResponseWriter, r *http.Request) {
Message: "",
Error: "",
CSRFToken: csrfToken,
BasePath: getBasePath(),
}
if err := RenderLoginPage(w, data); err != nil {
@@ -73,6 +74,7 @@ type LoginPageData struct {
Message string
Error string
CSRFToken string
BasePath string
}
// RenderLoginPage рендерит страницу входа

View File

@@ -2,6 +2,7 @@ package serve
import (
"net/http"
"strings"
"github.com/direct-dev-ru/linux-command-gpt/config"
)
@@ -15,8 +16,8 @@ func AuthMiddleware(next http.HandlerFunc) http.HandlerFunc {
return
}
// Исключаем страницу входа и API логина из проверки
if r.URL.Path == "/login" || r.URL.Path == "/api/login" || r.URL.Path == "/api/validate-token" {
// Исключаем страницу входа и API логина из проверки (с учетом BasePath)
if r.URL.Path == makePath("/login") || r.URL.Path == makePath("/api/login") || r.URL.Path == makePath("/api/validate-token") {
next(w, r)
return
}
@@ -31,8 +32,8 @@ func AuthMiddleware(next http.HandlerFunc) http.HandlerFunc {
return
}
// Для веб-запросов перенаправляем на страницу входа
http.Redirect(w, r, "/login", http.StatusSeeOther)
// Для веб-запросов перенаправляем на страницу входа (с учетом BasePath)
http.Redirect(w, r, makePath("/login"), http.StatusSeeOther)
return
}
@@ -50,8 +51,8 @@ func CSRFMiddleware(next http.HandlerFunc) http.HandlerFunc {
return
}
// Исключаем некоторые API endpoints
if r.URL.Path == "/api/login" || r.URL.Path == "/api/logout" {
// Исключаем некоторые API endpoints (с учетом BasePath)
if r.URL.Path == makePath("/api/login") || r.URL.Path == makePath("/api/logout") {
next(w, r)
return
}
@@ -103,7 +104,8 @@ func CSRFMiddleware(next http.HandlerFunc) http.HandlerFunc {
// isAPIRequest проверяет, является ли запрос API запросом
func isAPIRequest(r *http.Request) bool {
path := r.URL.Path
return len(path) >= 4 && path[:4] == "/api"
apiPrefix := makePath("/api")
return strings.HasPrefix(path, apiPrefix)
}
// RequireAuth обертка для requireAuth из auth.go

View File

@@ -285,7 +285,7 @@ const LoginPageTemplate = `
try {
const csrfToken = document.getElementById('csrf_token').value;
const response = await fetch('/api/login', {
const response = await fetch('{{.BasePath}}/api/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
@@ -302,7 +302,7 @@ const LoginPageTemplate = `
if (data.success) {
// Успешная авторизация, перенаправляем на главную страницу
window.location.href = '/';
window.location.href = '{{.BasePath}}/';
} else {
// Ошибка авторизации
showMessage(data.error || 'Ошибка авторизации', 'error');

View File

@@ -1,6 +1,7 @@
package ssl
import (
"slices"
"crypto/rand"
"crypto/rsa"
"crypto/tls"
@@ -139,26 +140,23 @@ func LoadOrGenerateCert(host string) (*tls.Certificate, error) {
// IsSecureHost проверяет, является ли хост безопасным для HTTP
func IsSecureHost(host string) bool {
secureHosts := []string{"localhost", "127.0.0.1", "::1"}
for _, secureHost := range secureHosts {
if host == secureHost {
return true
}
}
return false
return slices.Contains(secureHosts, host)
}
// ShouldUseHTTPS определяет, нужно ли использовать HTTPS
func ShouldUseHTTPS(host string) bool {
// Если хост не localhost/127.0.0.1, принуждаем к HTTPS
if !IsSecureHost(host) {
return true
}
// Если явно разрешен HTTP, используем HTTP
if config.AppConfig.Server.AllowHTTP {
return false
}
// Если хост не localhost/127.0.0.1, принуждаем к HTTPS
if !IsSecureHost(host) {
return true
}
// По умолчанию для localhost используем HTTP
return false
}