mirror of
https://github.com/Direct-Dev-Ru/go-lcg.git
synced 2025-11-16 17:49:55 +00:00
Compare commits
30 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a20fb846f0 | |||
| 99b1a74034 | |||
| 90cfc6fb0c | |||
| 89d15bfdc9 | |||
| 114146f4d2 | |||
| 5c672ecc39 | |||
| b4b902cb4c | |||
| 164f32dbaf | |||
| 7933abe62d | |||
| 1545fe2508 | |||
| d213de7a95 | |||
| deb80f2b37 | |||
| 81b01d74ae | |||
| 3c95eb85db | |||
| 1fbdd237a3 | |||
| 5b78e775c1 | |||
| 2d82b91090 | |||
| 9044b02d27 | |||
| 5d3829d1fe | |||
| e7c11879a1 | |||
| edadedcf80 | |||
| 6444c35bbb | |||
| 5ff6d4e072 | |||
| 6ec41355d3 | |||
| ffc2d6ba0a | |||
| 7a0d0746d4 | |||
| dab94df7d2 | |||
| 0da366cad5 | |||
| 281f7f877a | |||
| 3be2880dd2 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -18,3 +18,5 @@ shell-code/jwt.admin.token
|
|||||||
run.sh
|
run.sh
|
||||||
lcg_history.json
|
lcg_history.json
|
||||||
deploy/0.create_sealed_secrets.sh
|
deploy/0.create_sealed_secrets.sh
|
||||||
|
deploy/0.create_git_secrets.sh
|
||||||
|
deploy/0.create_app_secrets.sh
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
v2.0.2
|
v2.0.11
|
||||||
|
|||||||
@@ -68,6 +68,15 @@ type ValidationConfig struct {
|
|||||||
MaxExplanationLength int
|
MaxExplanationLength int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetEnvBool(key string, defaultValue bool) bool {
|
||||||
|
if value, exists := os.LookupEnv(key); exists {
|
||||||
|
if boolValue, err := strconv.ParseBool(value); err == nil {
|
||||||
|
return boolValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return defaultValue
|
||||||
|
}
|
||||||
|
|
||||||
func getEnv(key, defaultValue string) string {
|
func getEnv(key, defaultValue string) string {
|
||||||
if value, exists := os.LookupEnv(key); exists {
|
if value, exists := os.LookupEnv(key); exists {
|
||||||
return value
|
return value
|
||||||
|
|||||||
@@ -16,7 +16,8 @@ data:
|
|||||||
LCG_CONFIG_FOLDER: "/app/data/config"
|
LCG_CONFIG_FOLDER: "/app/data/config"
|
||||||
LCG_NO_HISTORY: "false"
|
LCG_NO_HISTORY: "false"
|
||||||
LCG_ALLOW_EXECUTION: "false"
|
LCG_ALLOW_EXECUTION: "false"
|
||||||
LCG_DEBUG: "false"
|
LCG_DEBUG: "true"
|
||||||
|
LCG_PROVIDER: "proxy"
|
||||||
|
|
||||||
# Настройки аутентификации
|
# Настройки аутентификации
|
||||||
LCG_SERVER_REQUIRE_AUTH: "true"
|
LCG_SERVER_REQUIRE_AUTH: "true"
|
||||||
@@ -41,6 +42,4 @@ data:
|
|||||||
|
|
||||||
# Настройки таймаутов
|
# Настройки таймаутов
|
||||||
LCG_TIMEOUT: "300"
|
LCG_TIMEOUT: "300"
|
||||||
|
|
||||||
# Настройки отладки
|
|
||||||
LCG_DEBUG: "false"
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
apiVersion: source.toolkit.fluxcd.io/v1
|
|
||||||
kind: GitRepository
|
|
||||||
metadata:
|
|
||||||
name: linux-command-gpt
|
|
||||||
namespace: flux-system
|
|
||||||
spec:
|
|
||||||
interval: 3m
|
|
||||||
url: https://direct-dev.ru/gitea/GiteaAdmin/go-lcg.git
|
|
||||||
ref:
|
|
||||||
branch: release
|
|
||||||
secretRef:
|
|
||||||
name: gitea-token
|
|
||||||
77
deploy/2.lcg-flux.yaml
Normal file
77
deploy/2.lcg-flux.yaml
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
apiVersion: source.toolkit.fluxcd.io/v1
|
||||||
|
kind: GitRepository
|
||||||
|
metadata:
|
||||||
|
name: go-lcg
|
||||||
|
namespace: flux-system
|
||||||
|
spec:
|
||||||
|
interval: 3m
|
||||||
|
url: https://github.com/Direct-Dev-Ru/go-lcg.git
|
||||||
|
ref:
|
||||||
|
branch: release
|
||||||
|
secretRef:
|
||||||
|
name: git-secrets
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# apiVersion: source.toolkit.fluxcd.io/v1
|
||||||
|
# kind: GitRepository
|
||||||
|
# metadata:
|
||||||
|
# name: linux-command-gpt
|
||||||
|
# namespace: flux-system
|
||||||
|
# spec:
|
||||||
|
# interval: 3m
|
||||||
|
# url: https://direct-dev.ru/gitea/GiteaAdmin/go-lcg.git
|
||||||
|
# ref:
|
||||||
|
# branch: release
|
||||||
|
# secretRef:
|
||||||
|
# name: gitea-token
|
||||||
|
|
||||||
|
|
||||||
|
---
|
||||||
|
apiVersion: kustomize.toolkit.fluxcd.io/v1
|
||||||
|
kind: Kustomization
|
||||||
|
metadata:
|
||||||
|
name: lcg
|
||||||
|
namespace: flux-system
|
||||||
|
spec:
|
||||||
|
healthChecks:
|
||||||
|
- kind: Deployment
|
||||||
|
name: lcg
|
||||||
|
namespace: lcg
|
||||||
|
interval: 3m15s
|
||||||
|
path: ./kustomize
|
||||||
|
prune: true
|
||||||
|
sourceRef:
|
||||||
|
kind: GitRepository
|
||||||
|
name: go-lcg
|
||||||
|
targetNamespace: lcg
|
||||||
|
timeout: 2m0s
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
apiVersion: image.toolkit.fluxcd.io/v1beta2
|
||||||
|
kind: ImageRepository
|
||||||
|
metadata:
|
||||||
|
name: lcg
|
||||||
|
namespace: flux-system
|
||||||
|
spec:
|
||||||
|
image: kuznetcovay/lcg
|
||||||
|
interval: 3m
|
||||||
|
secretRef:
|
||||||
|
name: regcred
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
apiVersion: image.toolkit.fluxcd.io/v1beta2
|
||||||
|
kind: ImagePolicy
|
||||||
|
metadata:
|
||||||
|
name: lcg
|
||||||
|
namespace: flux-system
|
||||||
|
spec:
|
||||||
|
imageRepositoryRef:
|
||||||
|
name: lcg
|
||||||
|
policy:
|
||||||
|
semver:
|
||||||
|
range: '>=1.0.0'
|
||||||
|
|
||||||
|
---
|
||||||
@@ -14,8 +14,7 @@ spec:
|
|||||||
template:
|
template:
|
||||||
metadata:
|
metadata:
|
||||||
labels:
|
labels:
|
||||||
app: lcg
|
app: lcg
|
||||||
version: ${VERSION}
|
|
||||||
spec:
|
spec:
|
||||||
containers:
|
containers:
|
||||||
- name: lcg
|
- name: lcg
|
||||||
@@ -28,7 +27,7 @@ spec:
|
|||||||
- configMapRef:
|
- configMapRef:
|
||||||
name: lcg-config
|
name: lcg-config
|
||||||
- secretRef:
|
- secretRef:
|
||||||
name: lcg-secret
|
name: lcg-secrets
|
||||||
env:
|
env:
|
||||||
# Pod information
|
# Pod information
|
||||||
- name: POD_NAME
|
- name: POD_NAME
|
||||||
@@ -58,21 +57,18 @@ spec:
|
|||||||
readOnly: true
|
readOnly: true
|
||||||
# Health checks
|
# Health checks
|
||||||
startupProbe:
|
startupProbe:
|
||||||
httpGet:
|
tcpSocket:
|
||||||
path: /login
|
|
||||||
port: 8080
|
port: 8080
|
||||||
initialDelaySeconds: 10
|
initialDelaySeconds: 10
|
||||||
periodSeconds: 5
|
periodSeconds: 5
|
||||||
failureThreshold: 30
|
failureThreshold: 30
|
||||||
readinessProbe:
|
readinessProbe:
|
||||||
httpGet:
|
tcpSocket:
|
||||||
path: /login
|
|
||||||
port: 8080
|
port: 8080
|
||||||
initialDelaySeconds: 5
|
initialDelaySeconds: 5
|
||||||
periodSeconds: 10
|
periodSeconds: 10
|
||||||
livenessProbe:
|
livenessProbe:
|
||||||
httpGet:
|
tcpSocket:
|
||||||
path: /login
|
|
||||||
port: 8080
|
port: 8080
|
||||||
initialDelaySeconds: 10
|
initialDelaySeconds: 10
|
||||||
periodSeconds: 60
|
periodSeconds: 60
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
---
|
|
||||||
apiVersion: kustomize.toolkit.fluxcd.io/v1
|
|
||||||
kind: Kustomization
|
|
||||||
metadata:
|
|
||||||
name: lcg
|
|
||||||
namespace: flux-system
|
|
||||||
spec:
|
|
||||||
healthChecks:
|
|
||||||
- kind: Deployment
|
|
||||||
name: lcg
|
|
||||||
namespace: lcg
|
|
||||||
interval: 3m15s
|
|
||||||
path: ./kustomize
|
|
||||||
prune: true
|
|
||||||
sourceRef:
|
|
||||||
kind: GitRepository
|
|
||||||
name: linux-command-gpt
|
|
||||||
targetNamespace: lcg
|
|
||||||
timeout: 2m0s
|
|
||||||
@@ -50,9 +50,7 @@ log "🚀 Полная сборка LCG (бинарные файлы + Docker о
|
|||||||
|
|
||||||
# Этап 1: Сборка бинарных файлов
|
# Этап 1: Сборка бинарных файлов
|
||||||
log "📦 Этап 1: Сборка бинарных файлов с goreleaser..."
|
log "📦 Этап 1: Сборка бинарных файлов с goreleaser..."
|
||||||
./deploy/4.build-binaries.sh "$VERSION"
|
if ! ./deploy/4.build-binaries.sh "$VERSION"; then
|
||||||
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
error "Ошибка при сборке бинарных файлов"
|
error "Ошибка при сборке бинарных файлов"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@@ -61,9 +59,7 @@ success "✅ Бинарные файлы собраны успешно"
|
|||||||
|
|
||||||
# Этап 2: Сборка Docker образа
|
# Этап 2: Сборка Docker образа
|
||||||
log "🐳 Этап 2: Сборка Docker образа..."
|
log "🐳 Этап 2: Сборка Docker образа..."
|
||||||
./deploy/5.build-docker.sh "$REPOSITORY" "$VERSION" "$PLATFORMS"
|
if ! ./deploy/5.build-docker.sh "$REPOSITORY" "$VERSION" "$PLATFORMS"; then
|
||||||
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
error "Ошибка при сборке Docker образа"
|
error "Ошибка при сборке Docker образа"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@@ -78,14 +74,14 @@ export VERSION=$VERSION
|
|||||||
export PLATFORMS=$PLATFORMS
|
export PLATFORMS=$PLATFORMS
|
||||||
export KUBECONFIG="${HOME}/.kube/config_hlab" && kubectx default
|
export KUBECONFIG="${HOME}/.kube/config_hlab" && kubectx default
|
||||||
|
|
||||||
if ! envsubst < deploy/1.configmap.yaml > kustomize/configmap.yaml; then
|
if ! envsubst < deploy/1.configmap.tmpl.yaml > kustomize/configmap.yaml; then
|
||||||
error "Ошибка при генерации deploy/1.configmap.yaml"
|
error "Ошибка при генерации deploy/1.configmap.yaml"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
success "✅ kustomize/configmap.yaml сгенерирован успешно"
|
success "✅ kustomize/configmap.yaml сгенерирован успешно"
|
||||||
|
|
||||||
if ! envsubst < deploy/deployment.tmpl.yaml > kustomize/deployment.yaml; then
|
if ! envsubst < deploy/3.deployment.tmpl.yaml > kustomize/deployment.yaml; then
|
||||||
error "Ошибка при генерации kustomize/deployment.yaml"
|
error "Ошибка при генерации kustomize/deployment.yaml"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@@ -131,11 +127,24 @@ fi
|
|||||||
if [ "$current_branch" != "main" ]; then
|
if [ "$current_branch" != "main" ]; then
|
||||||
git checkout main
|
git checkout main
|
||||||
git merge --no-ff -m "Merged branch '$current_branch' into main while building $VERSION" "$current_branch"
|
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
|
fi
|
||||||
|
|
||||||
# переключиться на ветку release и слить с веткой main
|
# переключиться на ветку release и слить с веткой main
|
||||||
git checkout -b release
|
if git show-ref --quiet refs/heads/release; then
|
||||||
git merge --no-ff -m "Merged main into release while building $VERSION" main
|
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 существует, удалить его и принудительно запушить
|
# если тег $VERSION существует, удалить его и принудительно запушить
|
||||||
tag_exists=$(git tag -l "$VERSION")
|
tag_exists=$(git tag -l "$VERSION")
|
||||||
@@ -189,14 +198,7 @@ log "🔍 Проверка образа:"
|
|||||||
echo " docker run --rm $REPOSITORY:$VERSION /app/lcg --version"
|
echo " docker run --rm $REPOSITORY:$VERSION /app/lcg --version"
|
||||||
echo ""
|
echo ""
|
||||||
log "📝 Команды для использования:"
|
log "📝 Команды для использования:"
|
||||||
echo " kubectl apply -k kustomize"
|
|
||||||
echo " kubectl get pods"
|
echo " kubectl get pods"
|
||||||
echo " kubectl get services"
|
echo " kubectl get services"
|
||||||
echo " kubectl get ingress"
|
echo " kubectl get ingress"
|
||||||
echo " kubectl get hpa"
|
|
||||||
echo " kubectl get servicemonitor"
|
|
||||||
echo " kubectl get pods"
|
|
||||||
echo " kubectl get services"
|
|
||||||
echo " kubectl get ingress"
|
|
||||||
echo " kubectl get hpa"
|
|
||||||
echo " kubectl get servicemonitor"
|
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
v2.0.2
|
v2.0.11
|
||||||
|
|||||||
@@ -4,8 +4,7 @@ metadata:
|
|||||||
name: lcg-route
|
name: lcg-route
|
||||||
namespace: lcg
|
namespace: lcg
|
||||||
labels:
|
labels:
|
||||||
app: lcg
|
app: lcg
|
||||||
version: ${VERSION}
|
|
||||||
spec:
|
spec:
|
||||||
entryPoints:
|
entryPoints:
|
||||||
- websecure
|
- websecure
|
||||||
|
|||||||
@@ -13,13 +13,13 @@ resources:
|
|||||||
- ingress-route.yaml
|
- ingress-route.yaml
|
||||||
|
|
||||||
# Common labels
|
# Common labels
|
||||||
commonLabels:
|
# commonLabels:
|
||||||
app: lcg
|
# app: lcg
|
||||||
version: ${VERSION}
|
# version: ${VERSION}
|
||||||
managed-by: kustomize
|
# managed-by: kustomize
|
||||||
|
|
||||||
# Images
|
# Images
|
||||||
images:
|
# images:
|
||||||
- name: lcg
|
# - name: lcg
|
||||||
newName: ${REPOSITORY}
|
# newName: ${REPOSITORY}
|
||||||
newTag: ${VERSION}
|
# newTag: ${VERSION}
|
||||||
|
|||||||
@@ -4,8 +4,7 @@ metadata:
|
|||||||
name: lcg
|
name: lcg
|
||||||
namespace: lcg
|
namespace: lcg
|
||||||
labels:
|
labels:
|
||||||
app: lcg
|
app: lcg
|
||||||
version: ${VERSION}
|
|
||||||
spec:
|
spec:
|
||||||
type: ClusterIP
|
type: ClusterIP
|
||||||
ports:
|
ports:
|
||||||
@@ -14,5 +13,4 @@ spec:
|
|||||||
protocol: TCP
|
protocol: TCP
|
||||||
name: http
|
name: http
|
||||||
selector:
|
selector:
|
||||||
app: lcg
|
app: lcg
|
||||||
version: ${VERSION}
|
|
||||||
|
|||||||
16
git-sealed-cfg.yaml
Normal file
16
git-sealed-cfg.yaml
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
apiVersion: bitnami.com/v1alpha1
|
||||||
|
kind: SealedSecret
|
||||||
|
metadata:
|
||||||
|
creationTimestamp: null
|
||||||
|
name: git-secrets
|
||||||
|
namespace: flux-system
|
||||||
|
spec:
|
||||||
|
encryptedData:
|
||||||
|
password: AgB8/7lk3onjQG9R2OzX02rv9Lwh3tkOkvV/DjySSGZDHnYtdOw6ttOZXSeQqibAfKIOqtbKvpGAmK0x0/1tQXfB1zg2unFh1p5oEa0sgYBNd0eeNV5nRXDpgl8gv3lWKLaLvLCmhxloYze1B6Js8UrPDGeH3lvxRk9A5oja87HEBnx/VIGm5h4crvb5fUn+7wibr+oQNP+LBRLiko4eqR8PZAA0qgWUvoJnAF6NIsGPEtNi6WjErtwwvYIsZbCIChjPHQll+FQYwSH7M9jXVEBPejiR92+XIR8RMMo6hsWWxkEvvZs5prNREirAOSErOHBRTMEYkI5JIAb6uaRBKZ2nP0G4YQAkx3N7DIZPD7MVQF3u5jIpqaRwP4S+v703/19uPID1D8RuXt99QUv4d7Bfs8PlwkV5/SOgx2ZPVn1viuieZZ9M9hdk5uXYqOqgLOjU4aQSVpVV5pdR7ifn2fcbcTsG6fE3srrjUt8c2t+bV1IBUw8CIzyA1lebxj31s2XRpY+6JsfihSneKm/RkR4ySkyLjF+BeAO7CuXeCdziSFsoCzRDGQqaf/3YKCv1HFbLUsAfHvbCOYuZH7X9UAw51OVqqhEpdD21Ms0W29NGRVUFz80/eglLpK5OmvlXr1kME2P9Wo8TEkLIK1Fjo10f6WzHsUU9eI1cfy6/JgyoaFn4Sjga9SaRgdMkv2neztyFLx6cRbdGui+5qh5Zewqaawvp72j7ZhosXVi0uBnKSoBkN6CLEzlw
|
||||||
|
username: AgB1HiFs7wfaiAaCrwGNr6zWfd8IoNMZUvJrKeaLbKqEJ2oAr3Db406mjq1gz/O0lhvOJqnmBR/Iel4PMVfixMBtmA8j2anytEkj7ZuruFF3OHOzEkN6OeYfJa9ddkJmUs+Zq62TxQdcaJufQnVfuSdScGvE+Exc8ruFWE0xM1cDgFsRp75d0lo6UmhxaJlBRewQexyH6izOmtecAZDX6WVyBopIGx2cPgNfyxp/4sU5CI5sGCjeqcq+5INRELk9kofbDIUnQuHxrH3nbzABNnK76sU6DhqS3jBmT5Pv9azB2AWaaYZ8z1di/fdYia3wKoQAbef36wKyQ+/ZLApnuaVkj9F96tcjqlV4T3SGp4179k99M8zf/7g1GwsljYRPEcRmc00L2FrC5m3S+oK8wIk6fLVT5KYJBlEP6ja3eTrgGDttosuNa4BcpzqLC2Ov6x1b6RKLRVPN9/+1eC9gMBxBqKnvsdjZn4kQb8yUYgjyRHMZl8kHehLnRDhIoE1O7xCQAMkrdeNyE1kAXsij2jgTDR7a72J86nnE0NPAyct4mCpn2x+2aFUVeyZ8u2e0nDLjxPIAs/ceN51ybz5f2cXH0JrEk3Yy0ZXTtHOF6NbZNcxrCrZGODYYIbtTpjI0MjYd+nxJt5TI3UN0pnrdR7FxHai+76Gw+fGWhXKQk+NgmSXsjyiQkBfoU7LCcnv8iFI5T3IpxtmlckZvcn/b
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
creationTimestamp: null
|
||||||
|
name: git-secrets
|
||||||
|
namespace: flux-system
|
||||||
|
---
|
||||||
@@ -124,6 +124,11 @@ func (p *ProxyAPIProvider) Chat(messages []Chat) (string, error) {
|
|||||||
req.Header.Set("Authorization", "Bearer "+p.JWTToken)
|
req.Header.Set("Authorization", "Bearer "+p.JWTToken)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if config.AppConfig.MainFlags.Debug {
|
||||||
|
fmt.Println("Chat URL: ", p.BaseURL+config.AppConfig.Server.ProxyUrl)
|
||||||
|
fmt.Println("ProxyChatRequest: ", req)
|
||||||
|
}
|
||||||
|
|
||||||
resp, err := p.HTTPClient.Do(req)
|
resp, err := p.HTTPClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("ошибка выполнения запроса: %w", err)
|
return "", fmt.Errorf("ошибка выполнения запроса: %w", err)
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ metadata:
|
|||||||
namespace: lcg
|
namespace: lcg
|
||||||
data:
|
data:
|
||||||
# Основные настройки
|
# Основные настройки
|
||||||
LCG_VERSION: "v2.0.2"
|
LCG_VERSION: "v2.0.11"
|
||||||
LCG_BASE_PATH: "/lcg"
|
LCG_BASE_PATH: "/lcg"
|
||||||
LCG_SERVER_HOST: "0.0.0.0"
|
LCG_SERVER_HOST: "0.0.0.0"
|
||||||
LCG_SERVER_PORT: "8080"
|
LCG_SERVER_PORT: "8080"
|
||||||
@@ -16,7 +16,8 @@ data:
|
|||||||
LCG_CONFIG_FOLDER: "/app/data/config"
|
LCG_CONFIG_FOLDER: "/app/data/config"
|
||||||
LCG_NO_HISTORY: "false"
|
LCG_NO_HISTORY: "false"
|
||||||
LCG_ALLOW_EXECUTION: "false"
|
LCG_ALLOW_EXECUTION: "false"
|
||||||
LCG_DEBUG: "false"
|
LCG_DEBUG: "true"
|
||||||
|
LCG_PROVIDER: "proxy"
|
||||||
|
|
||||||
# Настройки аутентификации
|
# Настройки аутентификации
|
||||||
LCG_SERVER_REQUIRE_AUTH: "true"
|
LCG_SERVER_REQUIRE_AUTH: "true"
|
||||||
@@ -41,6 +42,4 @@ data:
|
|||||||
|
|
||||||
# Настройки таймаутов
|
# Настройки таймаутов
|
||||||
LCG_TIMEOUT: "300"
|
LCG_TIMEOUT: "300"
|
||||||
|
|
||||||
# Настройки отладки
|
|
||||||
LCG_DEBUG: "false"
|
|
||||||
@@ -5,7 +5,7 @@ metadata:
|
|||||||
namespace: lcg
|
namespace: lcg
|
||||||
labels:
|
labels:
|
||||||
app: lcg
|
app: lcg
|
||||||
version: v2.0.2
|
version: v2.0.11
|
||||||
spec:
|
spec:
|
||||||
replicas: 1
|
replicas: 1
|
||||||
selector:
|
selector:
|
||||||
@@ -14,12 +14,11 @@ spec:
|
|||||||
template:
|
template:
|
||||||
metadata:
|
metadata:
|
||||||
labels:
|
labels:
|
||||||
app: lcg
|
app: lcg
|
||||||
version: v2.0.2
|
|
||||||
spec:
|
spec:
|
||||||
containers:
|
containers:
|
||||||
- name: lcg
|
- name: lcg
|
||||||
image: kuznetcovay/lcg:v2.0.2
|
image: kuznetcovay/lcg:v2.0.11
|
||||||
imagePullPolicy: Always
|
imagePullPolicy: Always
|
||||||
ports:
|
ports:
|
||||||
- containerPort: 8080
|
- containerPort: 8080
|
||||||
@@ -28,7 +27,7 @@ spec:
|
|||||||
- configMapRef:
|
- configMapRef:
|
||||||
name: lcg-config
|
name: lcg-config
|
||||||
- secretRef:
|
- secretRef:
|
||||||
name: lcg-secret
|
name: lcg-secrets
|
||||||
env:
|
env:
|
||||||
# Pod information
|
# Pod information
|
||||||
- name: POD_NAME
|
- name: POD_NAME
|
||||||
@@ -58,21 +57,18 @@ spec:
|
|||||||
readOnly: true
|
readOnly: true
|
||||||
# Health checks
|
# Health checks
|
||||||
startupProbe:
|
startupProbe:
|
||||||
httpGet:
|
tcpSocket:
|
||||||
path: /login
|
|
||||||
port: 8080
|
port: 8080
|
||||||
initialDelaySeconds: 10
|
initialDelaySeconds: 10
|
||||||
periodSeconds: 5
|
periodSeconds: 5
|
||||||
failureThreshold: 30
|
failureThreshold: 30
|
||||||
readinessProbe:
|
readinessProbe:
|
||||||
httpGet:
|
tcpSocket:
|
||||||
path: /login
|
|
||||||
port: 8080
|
port: 8080
|
||||||
initialDelaySeconds: 5
|
initialDelaySeconds: 5
|
||||||
periodSeconds: 10
|
periodSeconds: 10
|
||||||
livenessProbe:
|
livenessProbe:
|
||||||
httpGet:
|
tcpSocket:
|
||||||
path: /login
|
|
||||||
port: 8080
|
port: 8080
|
||||||
initialDelaySeconds: 10
|
initialDelaySeconds: 10
|
||||||
periodSeconds: 60
|
periodSeconds: 60
|
||||||
|
|||||||
@@ -4,8 +4,7 @@ metadata:
|
|||||||
name: lcg-route
|
name: lcg-route
|
||||||
namespace: lcg
|
namespace: lcg
|
||||||
labels:
|
labels:
|
||||||
app: lcg
|
app: lcg
|
||||||
version: v2.0.2
|
|
||||||
spec:
|
spec:
|
||||||
entryPoints:
|
entryPoints:
|
||||||
- websecure
|
- websecure
|
||||||
|
|||||||
@@ -13,13 +13,13 @@ resources:
|
|||||||
- ingress-route.yaml
|
- ingress-route.yaml
|
||||||
|
|
||||||
# Common labels
|
# Common labels
|
||||||
commonLabels:
|
# commonLabels:
|
||||||
app: lcg
|
# app: lcg
|
||||||
version: v2.0.2
|
# version: v2.0.11
|
||||||
managed-by: kustomize
|
# managed-by: kustomize
|
||||||
|
|
||||||
# Images
|
# Images
|
||||||
images:
|
# images:
|
||||||
- name: lcg
|
# - name: lcg
|
||||||
newName: kuznetcovay/lcg
|
# newName: kuznetcovay/lcg
|
||||||
newTag: v2.0.2
|
# newTag: v2.0.11
|
||||||
|
|||||||
@@ -4,8 +4,7 @@ metadata:
|
|||||||
name: lcg
|
name: lcg
|
||||||
namespace: lcg
|
namespace: lcg
|
||||||
labels:
|
labels:
|
||||||
app: lcg
|
app: lcg
|
||||||
version: v2.0.2
|
|
||||||
spec:
|
spec:
|
||||||
type: ClusterIP
|
type: ClusterIP
|
||||||
ports:
|
ports:
|
||||||
@@ -14,5 +13,4 @@ spec:
|
|||||||
protocol: TCP
|
protocol: TCP
|
||||||
name: http
|
name: http
|
||||||
selector:
|
selector:
|
||||||
app: lcg
|
app: lcg
|
||||||
version: v2.0.2
|
|
||||||
|
|||||||
16
main.go
16
main.go
@@ -156,6 +156,12 @@ lcg [опции] <описание команды>
|
|||||||
Debug: c.Bool("debug"),
|
Debug: c.Bool("debug"),
|
||||||
}
|
}
|
||||||
disableHistory = config.AppConfig.MainFlags.NoHistory || config.AppConfig.IsNoHistoryEnabled()
|
disableHistory = config.AppConfig.MainFlags.NoHistory || config.AppConfig.IsNoHistoryEnabled()
|
||||||
|
|
||||||
|
config.AppConfig.MainFlags.Debug = config.AppConfig.MainFlags.Debug || config.GetEnvBool("LCG_DEBUG", false)
|
||||||
|
|
||||||
|
fmt.Println("Debug:", config.AppConfig.MainFlags.Debug)
|
||||||
|
fmt.Println("LCG_DEBUG:", config.GetEnvBool("LCG_DEBUG", false))
|
||||||
|
|
||||||
args := c.Args().Slice()
|
args := c.Args().Slice()
|
||||||
|
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
@@ -175,7 +181,7 @@ lcg [опции] <описание команды>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if CompileConditions.NoServe {
|
if CompileConditions.NoServe {
|
||||||
if len(args) > 1 && args[0] == "serve" {
|
if len(args) > 1 && args[0] == "serve" {
|
||||||
printColored("❌ Error: serve command is disabled in this build\n", colorRed)
|
printColored("❌ Error: serve command is disabled in this build\n", colorRed)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
@@ -566,11 +572,9 @@ func getCommands() []*cli.Command {
|
|||||||
host := c.String("host")
|
host := c.String("host")
|
||||||
openBrowser := c.Bool("browser")
|
openBrowser := c.Bool("browser")
|
||||||
|
|
||||||
// Пробрасываем глобальный флаг debug для web-сервера
|
// Пробрасываем debug: флаг или переменная окружения LCG_DEBUG
|
||||||
// Позволяет запускать: lcg -d serve -p ...
|
// Позволяет запускать: LCG_DEBUG=1 lcg serve ... или lcg -d serve ...
|
||||||
if c.Bool("debug") {
|
config.AppConfig.MainFlags.Debug = c.Bool("debug") || config.GetEnvBool("LCG_DEBUG", false)
|
||||||
config.AppConfig.MainFlags.Debug = true
|
|
||||||
}
|
|
||||||
|
|
||||||
// Обновляем конфигурацию сервера с новыми параметрами
|
// Обновляем конфигурацию сервера с новыми параметрами
|
||||||
config.AppConfig.Server.Host = host
|
config.AppConfig.Server.Host = host
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ func validateJWTToken(tokenString string) (*JWTClaims, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Парсим токен
|
// Парсим токен
|
||||||
token, err := jwt.ParseWithClaims(tokenString, &JWTClaims{}, func(token *jwt.Token) (interface{}, error) {
|
token, err := jwt.ParseWithClaims(tokenString, &JWTClaims{}, func(token *jwt.Token) (any, error) {
|
||||||
// Проверяем метод подписи
|
// Проверяем метод подписи
|
||||||
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
|
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
|
||||||
return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
|
return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import (
|
|||||||
func handleLoginPage(w http.ResponseWriter, r *http.Request) {
|
func handleLoginPage(w http.ResponseWriter, r *http.Request) {
|
||||||
// Если пользователь уже авторизован, перенаправляем на главную
|
// Если пользователь уже авторизован, перенаправляем на главную
|
||||||
if isAuthenticated(r) {
|
if isAuthenticated(r) {
|
||||||
http.Redirect(w, r, "/", http.StatusSeeOther)
|
http.Redirect(w, r, makePath("/"), http.StatusSeeOther)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,6 +41,7 @@ func handleLoginPage(w http.ResponseWriter, r *http.Request) {
|
|||||||
Message: "",
|
Message: "",
|
||||||
Error: "",
|
Error: "",
|
||||||
CSRFToken: csrfToken,
|
CSRFToken: csrfToken,
|
||||||
|
BasePath: getBasePath(),
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := RenderLoginPage(w, data); err != nil {
|
if err := RenderLoginPage(w, data); err != nil {
|
||||||
@@ -73,6 +74,7 @@ type LoginPageData struct {
|
|||||||
Message string
|
Message string
|
||||||
Error string
|
Error string
|
||||||
CSRFToken string
|
CSRFToken string
|
||||||
|
BasePath string
|
||||||
}
|
}
|
||||||
|
|
||||||
// RenderLoginPage рендерит страницу входа
|
// RenderLoginPage рендерит страницу входа
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package serve
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/direct-dev-ru/linux-command-gpt/config"
|
"github.com/direct-dev-ru/linux-command-gpt/config"
|
||||||
)
|
)
|
||||||
@@ -15,8 +16,8 @@ func AuthMiddleware(next http.HandlerFunc) http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Исключаем страницу входа и API логина из проверки
|
// Исключаем страницу входа и API логина из проверки (с учетом BasePath)
|
||||||
if r.URL.Path == "/login" || r.URL.Path == "/api/login" || r.URL.Path == "/api/validate-token" {
|
if r.URL.Path == makePath("/login") || r.URL.Path == makePath("/api/login") || r.URL.Path == makePath("/api/validate-token") {
|
||||||
next(w, r)
|
next(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -31,8 +32,8 @@ func AuthMiddleware(next http.HandlerFunc) http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Для веб-запросов перенаправляем на страницу входа
|
// Для веб-запросов перенаправляем на страницу входа (с учетом BasePath)
|
||||||
http.Redirect(w, r, "/login", http.StatusSeeOther)
|
http.Redirect(w, r, makePath("/login"), http.StatusSeeOther)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,8 +51,8 @@ func CSRFMiddleware(next http.HandlerFunc) http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Исключаем некоторые API endpoints
|
// Исключаем некоторые API endpoints (с учетом BasePath)
|
||||||
if r.URL.Path == "/api/login" || r.URL.Path == "/api/logout" {
|
if r.URL.Path == makePath("/api/login") || r.URL.Path == makePath("/api/logout") {
|
||||||
next(w, r)
|
next(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -103,7 +104,8 @@ func CSRFMiddleware(next http.HandlerFunc) http.HandlerFunc {
|
|||||||
// isAPIRequest проверяет, является ли запрос API запросом
|
// isAPIRequest проверяет, является ли запрос API запросом
|
||||||
func isAPIRequest(r *http.Request) bool {
|
func isAPIRequest(r *http.Request) bool {
|
||||||
path := r.URL.Path
|
path := r.URL.Path
|
||||||
return len(path) >= 4 && path[:4] == "/api"
|
apiPrefix := makePath("/api")
|
||||||
|
return strings.HasPrefix(path, apiPrefix)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RequireAuth обертка для requireAuth из auth.go
|
// RequireAuth обертка для requireAuth из auth.go
|
||||||
|
|||||||
115
serve/results.go
115
serve/results.go
@@ -39,11 +39,12 @@ func generateAbbreviation(appName string) string {
|
|||||||
|
|
||||||
// FileInfo содержит информацию о файле
|
// FileInfo содержит информацию о файле
|
||||||
type FileInfo struct {
|
type FileInfo struct {
|
||||||
Name string
|
Name string
|
||||||
Size string
|
DisplayName string
|
||||||
ModTime string
|
Size string
|
||||||
Preview template.HTML
|
ModTime string
|
||||||
Content string // Полное содержимое для поиска
|
Preview template.HTML
|
||||||
|
Content string // Полное содержимое для поиска
|
||||||
}
|
}
|
||||||
|
|
||||||
// handleResultsPage обрабатывает главную страницу со списком файлов
|
// handleResultsPage обрабатывает главную страницу со списком файлов
|
||||||
@@ -133,11 +134,12 @@ func getResultFiles() ([]FileInfo, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
files = append(files, FileInfo{
|
files = append(files, FileInfo{
|
||||||
Name: entry.Name(),
|
Name: entry.Name(),
|
||||||
Size: formatFileSize(info.Size()),
|
DisplayName: formatFileDisplayName(entry.Name()),
|
||||||
ModTime: info.ModTime().Format("02.01.2006 15:04"),
|
Size: formatFileSize(info.Size()),
|
||||||
Preview: template.HTML(preview),
|
ModTime: info.ModTime().Format("02.01.2006 15:04"),
|
||||||
Content: fullContent,
|
Preview: template.HTML(preview),
|
||||||
|
Content: fullContent,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,24 +169,91 @@ func formatFileSize(size int64) string {
|
|||||||
return fmt.Sprintf("%.1f %cB", float64(size)/float64(div), "KMGTPE"[exp])
|
return fmt.Sprintf("%.1f %cB", float64(size)/float64(div), "KMGTPE"[exp])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// formatFileDisplayName преобразует имя файла вида
|
||||||
|
// gpt_request_GigaChat-2-Max_2025-10-22_13-50-13.md
|
||||||
|
// в "Gpt Request GigaChat 2 Max — 2025-10-22 13:50:13"
|
||||||
|
func formatFileDisplayName(filename string) string {
|
||||||
|
name := strings.TrimSuffix(filename, ".md")
|
||||||
|
// Разделим на части по '_'
|
||||||
|
parts := strings.Split(name, "_")
|
||||||
|
if len(parts) == 0 {
|
||||||
|
return filename
|
||||||
|
}
|
||||||
|
|
||||||
|
// Первая часть может быть префиксом gpt/request — заменим '_' на пробел и приведем регистр
|
||||||
|
var words []string
|
||||||
|
for _, p := range parts {
|
||||||
|
if p == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// Заменяем '-' на пробел в словах модели/текста
|
||||||
|
p = strings.ReplaceAll(p, "-", " ")
|
||||||
|
// Разбиваем по пробелам и капитализуем каждое слово
|
||||||
|
for _, w := range strings.Fields(p) {
|
||||||
|
if w == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
r := []rune(w)
|
||||||
|
r[0] = unicode.ToUpper(r[0])
|
||||||
|
words = append(words, string(r))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Попробуем распознать хвост как дату и время
|
||||||
|
// Ищем шаблон YYYY-MM-DD_HH-MM-SS в исходном имени
|
||||||
|
var pretty string
|
||||||
|
// ожидаем последние две части — дата и время
|
||||||
|
if len(parts) >= 3 {
|
||||||
|
datePart := parts[len(parts)-2]
|
||||||
|
timePart := parts[len(parts)-1]
|
||||||
|
// заменить '-' в времени на ':'
|
||||||
|
timePretty := strings.ReplaceAll(timePart, "-", ":")
|
||||||
|
if len(datePart) == 10 && len(timePart) == 8 { // примитивная проверка
|
||||||
|
// Собираем текст до датных частей
|
||||||
|
text := strings.Join(words[:len(words)-2], " ")
|
||||||
|
pretty = strings.TrimSpace(text)
|
||||||
|
if pretty != "" {
|
||||||
|
pretty += " — " + datePart + " " + timePretty
|
||||||
|
} else {
|
||||||
|
pretty = datePart + " " + timePretty
|
||||||
|
}
|
||||||
|
return pretty
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(words) > 0 {
|
||||||
|
pretty = strings.Join(words, " ")
|
||||||
|
return pretty
|
||||||
|
}
|
||||||
|
return filename
|
||||||
|
}
|
||||||
|
|
||||||
// handleFileView обрабатывает просмотр конкретного файла
|
// handleFileView обрабатывает просмотр конкретного файла
|
||||||
func handleFileView(w http.ResponseWriter, r *http.Request) {
|
func handleFileView(w http.ResponseWriter, r *http.Request) {
|
||||||
filename := strings.TrimPrefix(r.URL.Path, "/file/")
|
// Учитываем BasePath при извлечении имени файла
|
||||||
|
basePath := config.AppConfig.Server.BasePath
|
||||||
|
var filename string
|
||||||
|
if basePath != "" && basePath != "/" {
|
||||||
|
basePath = strings.TrimSuffix(basePath, "/")
|
||||||
|
filename = strings.TrimPrefix(r.URL.Path, basePath+"/file/")
|
||||||
|
} else {
|
||||||
|
filename = strings.TrimPrefix(r.URL.Path, "/file/")
|
||||||
|
}
|
||||||
if filename == "" {
|
if filename == "" {
|
||||||
http.NotFound(w, r)
|
renderNotFound(w, "Файл не указан", getBasePath())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Проверяем, что файл существует и находится в папке результатов
|
// Проверяем, что файл существует и находится в папке результатов
|
||||||
filePath := filepath.Join(config.AppConfig.ResultFolder, filename)
|
filePath := filepath.Join(config.AppConfig.ResultFolder, filename)
|
||||||
if !strings.HasPrefix(filePath, config.AppConfig.ResultFolder) {
|
if !strings.HasPrefix(filePath, config.AppConfig.ResultFolder) {
|
||||||
http.NotFound(w, r)
|
renderNotFound(w, "Запрошенный файл недоступен", getBasePath())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
content, err := os.ReadFile(filePath)
|
content, err := os.ReadFile(filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.NotFound(w, r)
|
renderNotFound(w, "Файл не найден или был удален", getBasePath())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,9 +264,11 @@ func handleFileView(w http.ResponseWriter, r *http.Request) {
|
|||||||
data := struct {
|
data := struct {
|
||||||
Filename string
|
Filename string
|
||||||
Content template.HTML
|
Content template.HTML
|
||||||
|
BasePath string
|
||||||
}{
|
}{
|
||||||
Filename: filename,
|
Filename: filename,
|
||||||
Content: template.HTML(htmlContent),
|
Content: template.HTML(htmlContent),
|
||||||
|
BasePath: getBasePath(),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Парсим и выполняем шаблон
|
// Парсим и выполняем шаблон
|
||||||
@@ -221,22 +292,30 @@ func handleDeleteFile(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
filename := strings.TrimPrefix(r.URL.Path, "/delete/")
|
// Учитываем BasePath при извлечении имени файла
|
||||||
|
basePath := config.AppConfig.Server.BasePath
|
||||||
|
var filename string
|
||||||
|
if basePath != "" && basePath != "/" {
|
||||||
|
basePath = strings.TrimSuffix(basePath, "/")
|
||||||
|
filename = strings.TrimPrefix(r.URL.Path, basePath+"/delete/")
|
||||||
|
} else {
|
||||||
|
filename = strings.TrimPrefix(r.URL.Path, "/delete/")
|
||||||
|
}
|
||||||
if filename == "" {
|
if filename == "" {
|
||||||
http.NotFound(w, r)
|
renderNotFound(w, "Файл не указан", getBasePath())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Проверяем, что файл существует и находится в папке результатов
|
// Проверяем, что файл существует и находится в папке результатов
|
||||||
filePath := filepath.Join(config.AppConfig.ResultFolder, filename)
|
filePath := filepath.Join(config.AppConfig.ResultFolder, filename)
|
||||||
if !strings.HasPrefix(filePath, config.AppConfig.ResultFolder) {
|
if !strings.HasPrefix(filePath, config.AppConfig.ResultFolder) {
|
||||||
http.NotFound(w, r)
|
renderNotFound(w, "Запрошенный файл недоступен", getBasePath())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Проверяем, что файл существует
|
// Проверяем, что файл существует
|
||||||
if _, err := os.Stat(filePath); os.IsNotExist(err) {
|
if _, err := os.Stat(filePath); os.IsNotExist(err) {
|
||||||
http.NotFound(w, r)
|
renderNotFound(w, "Файл не найден или уже удален", getBasePath())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,11 +3,13 @@ package serve
|
|||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"html/template"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/direct-dev-ru/linux-command-gpt/config"
|
"github.com/direct-dev-ru/linux-command-gpt/config"
|
||||||
|
"github.com/direct-dev-ru/linux-command-gpt/serve/templates"
|
||||||
"github.com/direct-dev-ru/linux-command-gpt/ssl"
|
"github.com/direct-dev-ru/linux-command-gpt/ssl"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -48,6 +50,18 @@ func StartResultServer(host, port string) error {
|
|||||||
return fmt.Errorf("failed to initialize CSRF manager: %v", err)
|
return fmt.Errorf("failed to initialize CSRF manager: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Гарантируем наличие папки результатов и файла истории
|
||||||
|
if _, err := os.Stat(config.AppConfig.ResultFolder); os.IsNotExist(err) {
|
||||||
|
if mkErr := os.MkdirAll(config.AppConfig.ResultFolder, 0755); mkErr != nil {
|
||||||
|
return fmt.Errorf("failed to create results folder: %v", mkErr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, err := os.Stat(config.AppConfig.ResultHistory); os.IsNotExist(err) {
|
||||||
|
if writeErr := Write(config.AppConfig.ResultHistory, []HistoryEntry{}); writeErr != nil {
|
||||||
|
return fmt.Errorf("failed to create history file: %v", writeErr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
addr := fmt.Sprintf("%s:%s", host, port)
|
addr := fmt.Sprintf("%s:%s", host, port)
|
||||||
|
|
||||||
// Проверяем, нужно ли использовать HTTPS
|
// Проверяем, нужно ли использовать HTTPS
|
||||||
@@ -138,15 +152,21 @@ func registerHTTPSRoutes() {
|
|||||||
// Регистрируем все маршруты кроме главной страницы
|
// Регистрируем все маршруты кроме главной страницы
|
||||||
registerRoutesExceptHome()
|
registerRoutesExceptHome()
|
||||||
|
|
||||||
// Регистрируем главную страницу с проверкой HTTPS
|
// Регистрируем главную страницу (строго по BasePath) с проверкой HTTPS
|
||||||
http.HandleFunc(makePath("/"), func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc(makePath("/"), func(w http.ResponseWriter, r *http.Request) {
|
||||||
// Проверяем, пришел ли запрос по HTTP (не HTTPS)
|
// Проверяем, пришел ли запрос по HTTP (не HTTPS)
|
||||||
if r.TLS == nil {
|
if r.TLS == nil {
|
||||||
handleHTTPSRedirect(w, r)
|
handleHTTPSRedirect(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Если уже HTTPS, обрабатываем как обычно
|
// Обрабатываем только точные пути: BasePath или BasePath/
|
||||||
AuthMiddleware(handleResultsPage)(w, r)
|
bp := getBasePath()
|
||||||
|
p := r.URL.Path
|
||||||
|
if (bp == "" && (p == "/" || p == "")) || (bp != "" && (p == bp || p == bp+"/")) {
|
||||||
|
AuthMiddleware(handleResultsPage)(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
renderNotFound(w, "Страница не найдена", bp)
|
||||||
})
|
})
|
||||||
|
|
||||||
// Регистрируем главную страницу без слэша в конце для BasePath
|
// Регистрируем главную страницу без слэша в конце для BasePath
|
||||||
@@ -163,6 +183,13 @@ func registerHTTPSRoutes() {
|
|||||||
AuthMiddleware(handleResultsPage)(w, r)
|
AuthMiddleware(handleResultsPage)(w, r)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Catch-all 404 для любых незарегистрированных путей (только когда BasePath задан)
|
||||||
|
if getBasePath() != "" {
|
||||||
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
renderNotFound(w, "Страница не найдена", getBasePath())
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// registerRoutesExceptHome регистрирует все маршруты кроме главной страницы
|
// registerRoutesExceptHome регистрирует все маршруты кроме главной страницы
|
||||||
@@ -203,6 +230,13 @@ func registerRoutesExceptHome() {
|
|||||||
// API для сохранения результатов и истории
|
// API для сохранения результатов и истории
|
||||||
http.HandleFunc(makePath("/api/save-result"), AuthMiddleware(CSRFMiddleware(handleSaveResult)))
|
http.HandleFunc(makePath("/api/save-result"), AuthMiddleware(CSRFMiddleware(handleSaveResult)))
|
||||||
http.HandleFunc(makePath("/api/add-to-history"), AuthMiddleware(CSRFMiddleware(handleAddToHistory)))
|
http.HandleFunc(makePath("/api/add-to-history"), AuthMiddleware(CSRFMiddleware(handleAddToHistory)))
|
||||||
|
|
||||||
|
// Catch-all 404 для любых незарегистрированных путей (только когда BasePath задан)
|
||||||
|
if getBasePath() != "" {
|
||||||
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
renderNotFound(w, "Страница не найдена", getBasePath())
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// registerRoutes регистрирует все маршруты сервера
|
// registerRoutes регистрирует все маршруты сервера
|
||||||
@@ -215,8 +249,17 @@ func registerRoutes() {
|
|||||||
http.HandleFunc(makePath("/api/logout"), handleLogout)
|
http.HandleFunc(makePath("/api/logout"), handleLogout)
|
||||||
http.HandleFunc(makePath("/api/validate-token"), handleValidateToken)
|
http.HandleFunc(makePath("/api/validate-token"), handleValidateToken)
|
||||||
|
|
||||||
// Главная страница и файлы
|
// Главная страница (строго по BasePath) и файлы
|
||||||
http.HandleFunc(makePath("/"), AuthMiddleware(handleResultsPage))
|
http.HandleFunc(makePath("/"), func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
// Обрабатываем только точные пути: BasePath или BasePath/
|
||||||
|
bp := getBasePath()
|
||||||
|
p := r.URL.Path
|
||||||
|
if (bp == "" && (p == "/" || p == "")) || (bp != "" && (p == bp || p == bp+"/")) {
|
||||||
|
AuthMiddleware(handleResultsPage)(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
renderNotFound(w, "Страница не найдена", bp)
|
||||||
|
})
|
||||||
http.HandleFunc(makePath("/file/"), AuthMiddleware(handleFileView))
|
http.HandleFunc(makePath("/file/"), AuthMiddleware(handleFileView))
|
||||||
http.HandleFunc(makePath("/delete/"), AuthMiddleware(handleDeleteFile))
|
http.HandleFunc(makePath("/delete/"), AuthMiddleware(handleDeleteFile))
|
||||||
|
|
||||||
@@ -251,4 +294,30 @@ func registerRoutes() {
|
|||||||
basePath = strings.TrimSuffix(basePath, "/")
|
basePath = strings.TrimSuffix(basePath, "/")
|
||||||
http.HandleFunc(basePath, AuthMiddleware(handleResultsPage))
|
http.HandleFunc(basePath, AuthMiddleware(handleResultsPage))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Catch-all 404 для любых незарегистрированных путей (только когда BasePath задан)
|
||||||
|
if getBasePath() != "" {
|
||||||
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
renderNotFound(w, "Страница не найдена", getBasePath())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// renderNotFound рендерит кастомную страницу 404
|
||||||
|
func renderNotFound(w http.ResponseWriter, message, basePath string) {
|
||||||
|
w.WriteHeader(http.StatusNotFound)
|
||||||
|
data := struct {
|
||||||
|
Message string
|
||||||
|
BasePath string
|
||||||
|
}{
|
||||||
|
Message: message,
|
||||||
|
BasePath: basePath,
|
||||||
|
}
|
||||||
|
tmpl, err := template.New("not_found").Parse(templates.NotFoundTemplate)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, "404 Not Found", http.StatusNotFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||||
|
_ = tmpl.Execute(w, data)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ const FileViewTemplate = `
|
|||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="header">
|
<div class="header">
|
||||||
<h1>📄 {{.Filename}}</h1>
|
<h1>📄 {{.Filename}}</h1>
|
||||||
<a href="/" class="back-btn">← Назад к списку</a>
|
<a href="{{.BasePath}}/" class="back-btn">← Назад к списку</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
{{.Content}}
|
{{.Content}}
|
||||||
|
|||||||
@@ -111,6 +111,11 @@ const HistoryPageTemplate = `
|
|||||||
font-size: 0.9em;
|
font-size: 0.9em;
|
||||||
color: #2d5016;
|
color: #2d5016;
|
||||||
border-left: 3px solid #2d5016;
|
border-left: 3px solid #2d5016;
|
||||||
|
max-height: 72px; /* ~4 строки */
|
||||||
|
overflow: hidden;
|
||||||
|
display: -webkit-box;
|
||||||
|
-webkit-line-clamp: 4;
|
||||||
|
-webkit-box-orient: vertical;
|
||||||
}
|
}
|
||||||
.delete-btn {
|
.delete-btn {
|
||||||
background: #e74c3c;
|
background: #e74c3c;
|
||||||
|
|||||||
@@ -285,7 +285,7 @@ const LoginPageTemplate = `
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const csrfToken = document.getElementById('csrf_token').value;
|
const csrfToken = document.getElementById('csrf_token').value;
|
||||||
const response = await fetch('/api/login', {
|
const response = await fetch('{{.BasePath}}/api/login', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@@ -302,7 +302,7 @@ const LoginPageTemplate = `
|
|||||||
|
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
// Успешная авторизация, перенаправляем на главную страницу
|
// Успешная авторизация, перенаправляем на главную страницу
|
||||||
window.location.href = '/';
|
window.location.href = '{{.BasePath}}/';
|
||||||
} else {
|
} else {
|
||||||
// Ошибка авторизации
|
// Ошибка авторизации
|
||||||
showMessage(data.error || 'Ошибка авторизации', 'error');
|
showMessage(data.error || 'Ошибка авторизации', 'error');
|
||||||
|
|||||||
147
serve/templates/not_found.go
Normal file
147
serve/templates/not_found.go
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
package templates
|
||||||
|
|
||||||
|
// NotFoundTemplate современная страница 404
|
||||||
|
const NotFoundTemplate = `
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="ru">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>Страница не найдена — 404</title>
|
||||||
|
<style>
|
||||||
|
:root {
|
||||||
|
--bg: #1a0b0b; /* глубокий темно-красный фон */
|
||||||
|
--bg2: #2a0f0f; /* второй оттенок фона */
|
||||||
|
--fg: #ffeaea; /* светлый текст с красным оттенком */
|
||||||
|
--accent: #ff3b30; /* основной красный (iOS red) */
|
||||||
|
--accent2: #ff6f61; /* дополнительный коралловый */
|
||||||
|
--accentGlow: rgba(255,59,48,0.35);
|
||||||
|
--accentGlow2: rgba(255,111,97,0.30);
|
||||||
|
}
|
||||||
|
* { box-sizing: border-box; }
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
min-height: 100vh;
|
||||||
|
display: grid;
|
||||||
|
place-items: center;
|
||||||
|
background:
|
||||||
|
radial-gradient(1200px 600px at 10% 10%, rgba(255,59,48,0.12), transparent),
|
||||||
|
radial-gradient(1200px 600px at 90% 90%, rgba(255,111,97,0.12), transparent),
|
||||||
|
linear-gradient(135deg, var(--bg), var(--bg2));
|
||||||
|
color: var(--fg);
|
||||||
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Inter, sans-serif;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
.glow {
|
||||||
|
position: absolute;
|
||||||
|
inset: -20%;
|
||||||
|
background:
|
||||||
|
radial-gradient(700px 340px at 20% 30%, rgba(255,59,48,0.22), transparent 60%),
|
||||||
|
radial-gradient(700px 340px at 80% 70%, rgba(255,111,97,0.20), transparent 60%);
|
||||||
|
filter: blur(40px);
|
||||||
|
z-index: 0;
|
||||||
|
}
|
||||||
|
.card {
|
||||||
|
position: relative;
|
||||||
|
z-index: 1;
|
||||||
|
width: min(720px, 92vw);
|
||||||
|
padding: 32px;
|
||||||
|
border-radius: 20px;
|
||||||
|
background: rgba(255,255,255,0.03);
|
||||||
|
border: 1px solid rgba(255,255,255,0.08);
|
||||||
|
box-shadow: 0 10px 40px rgba(80,0,0,0.45), inset 0 0 0 1px rgba(255,255,255,0.03);
|
||||||
|
backdrop-filter: blur(10px);
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.code {
|
||||||
|
font-size: clamp(48px, 12vw, 120px);
|
||||||
|
line-height: 0.9;
|
||||||
|
font-weight: 800;
|
||||||
|
letter-spacing: -2px;
|
||||||
|
background: linear-gradient(90deg, var(--accent), var(--accent2));
|
||||||
|
-webkit-background-clip: text;
|
||||||
|
background-clip: text;
|
||||||
|
color: transparent;
|
||||||
|
margin: 8px 0 12px 0;
|
||||||
|
text-shadow: 0 8px 40px var(--accentGlow);
|
||||||
|
}
|
||||||
|
.title {
|
||||||
|
font-size: clamp(18px, 3.2vw, 28px);
|
||||||
|
font-weight: 600;
|
||||||
|
opacity: 0.95;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
}
|
||||||
|
.desc {
|
||||||
|
font-size: 15px;
|
||||||
|
opacity: 0.75;
|
||||||
|
margin: 0 auto 20px auto;
|
||||||
|
max-width: 60ch;
|
||||||
|
}
|
||||||
|
.btns {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 12px;
|
||||||
|
justify-content: center;
|
||||||
|
margin-top: 8px;
|
||||||
|
}
|
||||||
|
.btn {
|
||||||
|
appearance: none;
|
||||||
|
border: none;
|
||||||
|
cursor: pointer;
|
||||||
|
padding: 12px 18px;
|
||||||
|
border-radius: 12px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: white;
|
||||||
|
background: linear-gradient(135deg, var(--accent), #c62828);
|
||||||
|
box-shadow: 0 6px 18px var(--accentGlow);
|
||||||
|
transition: transform .2s ease, box-shadow .2s ease, filter .2s ease;
|
||||||
|
text-decoration: none;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
.btn:hover { transform: translateY(-2px); filter: brightness(1.05); }
|
||||||
|
.btn.secondary { background: linear-gradient(135deg, #e65100, var(--accent2)); box-shadow: 0 6px 18px var(--accentGlow2); }
|
||||||
|
.hint { margin-top: 16px; font-size: 13px; opacity: 0.6; }
|
||||||
|
</style>
|
||||||
|
<script>
|
||||||
|
function goHome() {
|
||||||
|
window.location.href = '{{.BasePath}}/';
|
||||||
|
}
|
||||||
|
function bindEsc() {
|
||||||
|
const handler = (e) => { if (e.key === 'Escape' || e.key === 'Esc') { e.preventDefault(); goHome(); } };
|
||||||
|
window.addEventListener('keydown', handler);
|
||||||
|
document.addEventListener('keydown', handler);
|
||||||
|
// фокус на body для гарантии получения клавиш
|
||||||
|
if (document && document.body) {
|
||||||
|
document.body.setAttribute('tabindex', '-1');
|
||||||
|
document.body.focus({ preventScroll: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (document.readyState === 'loading') {
|
||||||
|
document.addEventListener('DOMContentLoaded', bindEsc);
|
||||||
|
} else {
|
||||||
|
bindEsc();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<meta http-equiv="refresh" content="30">
|
||||||
|
<meta name="robots" content="noindex">
|
||||||
|
<link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'><text y='50%' x='50%' dominant-baseline='middle' text-anchor='middle' font-size='42'>🚫</text></svg>">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="glow"></div>
|
||||||
|
<div class="card">
|
||||||
|
<div class="code">404</div>
|
||||||
|
<div class="title">Страница не найдена</div>
|
||||||
|
<p class="desc">{{.Message}}</p>
|
||||||
|
<div class="btns">
|
||||||
|
<a class="btn" href="{{.BasePath}}/">🏠 На главную</a>
|
||||||
|
<a class="btn secondary" href="{{.BasePath}}/run">🚀 К выполнению</a>
|
||||||
|
</div>
|
||||||
|
<div class="hint">Нажмите Esc, чтобы вернуться на главную</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
`
|
||||||
|
|
||||||
|
|
||||||
@@ -73,8 +73,10 @@ const ResultsPageTemplate = `
|
|||||||
}
|
}
|
||||||
.files-grid {
|
.files-grid {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
|
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
|
||||||
gap: 20px;
|
gap: 20px;
|
||||||
|
align-items: stretch;
|
||||||
|
grid-auto-rows: auto;
|
||||||
}
|
}
|
||||||
.file-card {
|
.file-card {
|
||||||
background: white;
|
background: white;
|
||||||
@@ -91,32 +93,36 @@ const ResultsPageTemplate = `
|
|||||||
}
|
}
|
||||||
.file-card-content {
|
.file-card-content {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
padding-left: 28px;
|
||||||
}
|
}
|
||||||
.file-actions {
|
.file-actions {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 10px;
|
top: 10px;
|
||||||
right: 10px;
|
left: 10px;
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 8px;
|
gap: 8px;
|
||||||
}
|
}
|
||||||
.delete-btn {
|
.delete-btn {
|
||||||
background: #e74c3c;
|
background: transparent;
|
||||||
color: white;
|
color: #ef9a9a; /* бледно-красный */
|
||||||
border: none;
|
border: none;
|
||||||
padding: 6px 12px;
|
padding: 4px 8px;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
font-size: 0.8em;
|
font-size: 18px;
|
||||||
transition: background 0.3s ease;
|
line-height: 1;
|
||||||
|
transition: color 0.2s ease, transform 0.2s ease;
|
||||||
}
|
}
|
||||||
.delete-btn:hover {
|
.delete-btn:hover {
|
||||||
background: #c0392b;
|
color:rgb(171, 27, 24); /* чуть ярче при ховере */
|
||||||
|
transform: translateY(-1px);
|
||||||
}
|
}
|
||||||
.file-name {
|
.file-name {
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
color: #333;
|
color: #333;
|
||||||
margin-bottom: 8px;
|
margin-bottom: 8px;
|
||||||
font-size: 1.1em;
|
font-size: 1.1em;
|
||||||
|
padding-right: 10px;
|
||||||
}
|
}
|
||||||
.file-info {
|
.file-info {
|
||||||
color: #666;
|
color: #666;
|
||||||
@@ -165,7 +171,7 @@ const ResultsPageTemplate = `
|
|||||||
body { padding: 10px; }
|
body { padding: 10px; }
|
||||||
.container { margin: 0; border-radius: 8px; box-shadow: 0 10px 20px rgba(0,0,0,0.1); }
|
.container { margin: 0; border-radius: 8px; box-shadow: 0 10px 20px rgba(0,0,0,0.1); }
|
||||||
.header { padding: 20px; }
|
.header { padding: 20px; }
|
||||||
.header h1 { font-size: 2em; }
|
.header h1 { font-size: 1.9em; }
|
||||||
.content { padding: 20px; }
|
.content { padding: 20px; }
|
||||||
.files-grid { grid-template-columns: 1fr; }
|
.files-grid { grid-template-columns: 1fr; }
|
||||||
.stats { grid-template-columns: 1fr 1fr; }
|
.stats { grid-template-columns: 1fr 1fr; }
|
||||||
@@ -174,7 +180,8 @@ const ResultsPageTemplate = `
|
|||||||
.search-container input { font-size: 16px; width: 96% !important; }
|
.search-container input { font-size: 16px; width: 96% !important; }
|
||||||
}
|
}
|
||||||
@media (max-width: 480px) {
|
@media (max-width: 480px) {
|
||||||
.header h1 { font-size: 1.8em; }
|
.header h1 { font-size: 1.6em; }
|
||||||
|
.content { padding: 16px; }
|
||||||
.stats { grid-template-columns: 1fr; }
|
.stats { grid-template-columns: 1fr; }
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
@@ -216,10 +223,10 @@ const ResultsPageTemplate = `
|
|||||||
{{range .Files}}
|
{{range .Files}}
|
||||||
<div class="file-card" data-content="{{.Content}}">
|
<div class="file-card" data-content="{{.Content}}">
|
||||||
<div class="file-actions">
|
<div class="file-actions">
|
||||||
<button class="delete-btn" onclick="deleteFile('{{.Name}}')" title="Удалить файл">🗑️</button>
|
<button class="delete-btn" onclick="deleteFile('{{.Name}}')" title="Удалить файл">✖</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="file-card-content" onclick="window.location.href='{{$.BasePath}}/file/{{.Name}}'">
|
<div class="file-card-content" onclick="window.location.href='{{$.BasePath}}/file/{{.Name}}'">
|
||||||
<div class="file-name">{{.Name}}</div>
|
<div class="file-name">{{.DisplayName}}</div>
|
||||||
<div class="file-info">
|
<div class="file-info">
|
||||||
📅 {{.ModTime}} | 📏 {{.Size}}
|
📅 {{.ModTime}} | 📏 {{.Size}}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
18
ssl/ssl.go
18
ssl/ssl.go
@@ -1,6 +1,7 @@
|
|||||||
package ssl
|
package ssl
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"slices"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"crypto/rsa"
|
"crypto/rsa"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
@@ -139,25 +140,22 @@ func LoadOrGenerateCert(host string) (*tls.Certificate, error) {
|
|||||||
// IsSecureHost проверяет, является ли хост безопасным для HTTP
|
// IsSecureHost проверяет, является ли хост безопасным для HTTP
|
||||||
func IsSecureHost(host string) bool {
|
func IsSecureHost(host string) bool {
|
||||||
secureHosts := []string{"localhost", "127.0.0.1", "::1"}
|
secureHosts := []string{"localhost", "127.0.0.1", "::1"}
|
||||||
for _, secureHost := range secureHosts {
|
return slices.Contains(secureHosts, host)
|
||||||
if host == secureHost {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ShouldUseHTTPS определяет, нужно ли использовать HTTPS
|
// ShouldUseHTTPS определяет, нужно ли использовать HTTPS
|
||||||
func ShouldUseHTTPS(host string) bool {
|
func ShouldUseHTTPS(host string) bool {
|
||||||
|
|
||||||
|
// Если явно разрешен HTTP, используем HTTP
|
||||||
|
if config.AppConfig.Server.AllowHTTP {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// Если хост не localhost/127.0.0.1, принуждаем к HTTPS
|
// Если хост не localhost/127.0.0.1, принуждаем к HTTPS
|
||||||
if !IsSecureHost(host) {
|
if !IsSecureHost(host) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Если явно разрешен HTTP, используем HTTP
|
|
||||||
if config.AppConfig.Server.AllowHTTP {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// По умолчанию для localhost используем HTTP
|
// По умолчанию для localhost используем HTTP
|
||||||
return false
|
return false
|
||||||
|
|||||||
Reference in New Issue
Block a user