Initial commit: ROA2WEB - FastAPI + Vue.js + Telegram Bot
Modern ERP Reports Application with microservices architecture Tech Stack: - Backend: FastAPI + python-oracledb (Oracle DB integration) - Frontend: Vue.js 3 + PrimeVue + Vite - Telegram Bot: python-telegram-bot + SQLite - Infrastructure: Shared database pool, JWT authentication, SSH tunnel Features: - FastAPI backend with async Oracle connection pool - Vue.js 3 responsive frontend with PrimeVue components - Telegram bot alternative interface - Microservices architecture with shared components - Complete deployment support (Linux Docker + Windows IIS) - Comprehensive testing (Playwright E2E + pytest) Repository Structure: - reports-app/ - Main application (backend, frontend, telegram-bot) - shared/ - Shared components (database pool, auth, utils) - deployment/ - Deployment scripts (Linux & Windows) - docs/ - Project documentation - security/ - Security scanning and git hooks
This commit is contained in:
40
ssh-tunnel/Dockerfile
Normal file
40
ssh-tunnel/Dockerfile
Normal file
@@ -0,0 +1,40 @@
|
||||
# SSH Tunnel Container for Oracle Database Connection
|
||||
FROM alpine:3.18
|
||||
|
||||
# Install OpenSSH client and necessary tools
|
||||
RUN apk add --no-cache \
|
||||
openssh-client \
|
||||
bash \
|
||||
curl \
|
||||
netcat-openbsd \
|
||||
&& rm -rf /var/cache/apk/*
|
||||
|
||||
# Create non-root user
|
||||
RUN addgroup -g 1001 -S tunnel && \
|
||||
adduser -S -D -H -u 1001 -s /bin/bash -G tunnel tunnel
|
||||
|
||||
# Create SSH directory
|
||||
RUN mkdir -p /home/tunnel/.ssh && \
|
||||
chown -R tunnel:tunnel /home/tunnel
|
||||
|
||||
# Copy SSH key and set permissions (before switching to non-root user)
|
||||
COPY ../secrets/roa_oracle_server /home/tunnel/.ssh/roa_oracle_server
|
||||
RUN chown tunnel:tunnel /home/tunnel/.ssh/roa_oracle_server && \
|
||||
chmod 600 /home/tunnel/.ssh/roa_oracle_server
|
||||
|
||||
# Copy SSH tunnel script
|
||||
COPY ssh_tunnel_docker.sh /usr/local/bin/ssh_tunnel.sh
|
||||
RUN chmod +x /usr/local/bin/ssh_tunnel.sh
|
||||
|
||||
# Switch to non-root user
|
||||
USER tunnel
|
||||
|
||||
# Health check - verify tunnel is working
|
||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=15s --retries=3 \
|
||||
CMD nc -z localhost 1521 || exit 1
|
||||
|
||||
# Expose the tunneled port
|
||||
EXPOSE 1521
|
||||
|
||||
# Start SSH tunnel
|
||||
ENTRYPOINT ["/usr/local/bin/ssh_tunnel.sh"]
|
||||
34
ssh-tunnel/README_SSH_KEY.md
Normal file
34
ssh-tunnel/README_SSH_KEY.md
Normal file
@@ -0,0 +1,34 @@
|
||||
# SSH Key Configuration
|
||||
|
||||
## 🔐 SSH Private Key Location
|
||||
|
||||
The SSH private key `roa_oracle_server` has been moved to a secure location for security reasons.
|
||||
|
||||
### Current Location:
|
||||
```
|
||||
roa2web/secrets/roa_oracle_server
|
||||
```
|
||||
|
||||
### Security Measures Applied:
|
||||
- ✅ File moved to `secrets/` directory (protected by .gitignore)
|
||||
- ✅ File permissions set to 600 (owner read/write only)
|
||||
- ✅ Directory `secrets/` is excluded from git tracking
|
||||
|
||||
### Usage in Scripts:
|
||||
Update any scripts that reference the SSH key to use the new path:
|
||||
|
||||
```bash
|
||||
# Old path (INSECURE):
|
||||
# ssh -i roa2web/ssh-tunnel/roa_oracle_server
|
||||
|
||||
# New path (SECURE):
|
||||
ssh -i roa2web/secrets/roa_oracle_server
|
||||
```
|
||||
|
||||
### Important Notes:
|
||||
- ⚠️ The SSH key is no longer tracked in git history after security cleanup
|
||||
- 🔄 Consider regenerating the SSH key if it was compromised
|
||||
- 📋 Ensure all team members update their scripts to use the new path
|
||||
|
||||
---
|
||||
*SSH key secured: 2025-08-03*
|
||||
166
ssh-tunnel/docs/BITVISE_SSH_SETUP.md
Normal file
166
ssh-tunnel/docs/BITVISE_SSH_SETUP.md
Normal file
@@ -0,0 +1,166 @@
|
||||
# 🔐 Bitvise SSH Server Setup pentru ROA2WEB
|
||||
|
||||
Instrucțiuni pentru configurarea cheii SSH în Bitvise SSH Server pe Windows.
|
||||
|
||||
## 🔑 Cheia SSH Publică
|
||||
|
||||
### 📋 Format OpenSSH (încercați primul):
|
||||
```
|
||||
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCcRM+WWxoBqCSpaTo+vNCrvCLx1UFmKqqSh6smS4c/lh1Hkku+oiq65iUHwRMu5X9jDXSGUR1Fmig+OgIhoTnT4Hd3v4Fe2zienOFiJ/AZOTE+pgxpwmIrkScGTSv7ZSp4xFcXsFwho8W/Li0P0kyB+kGs2tFYaQM192E5Gx9qjlPGSM55fdksElRXKIrRHE4ARjt5+kMt4WFgUXpVNqhHQFEcz/oW6sC0OkufTbzQ+MHefBIlMNUlNHRxbHc3C6CTuMmzMM847y6rmQlDyScX0tizDhUnQ1UgA3ZyICJp9CVF4weAM6ihZhNTFi7drXiCEihUVLNU+EuEpWdWeVNebqBqlkJT0KXR3IgEQ3zKYKuAmICFO056WI3eKcJWuWEFNDrSYsxo+HydAbqBSqEprJFCUSU90175ngnpY4WoH7CFUbCnGjxEnRXUjUktaCdqYhH0ZjGHSGujK+KGPVxvBi1h7BjE33SEH6PAVZBYmdpGDri69n6H+v6dhaW26scFcc6ldrOcbaRsX7q4M8gFIwotAu6jTuid8FensF/j9yQRDkcOS8OWXHr5z2lZTCSDPik83p8mvvEZ/R7dP60ldwz2INX8rbCxi5frEdijqrwZCq9D2tzUJJgG8h3KUKfd3QfThCyq6AdE9X2+EnmU1yP2SJsolgM7euuDBH0/qQ== roa2web-wsl-marius@Mihai-HXG0G
|
||||
```
|
||||
|
||||
### 🔧 Format RFC4716 (dacă primul spune "Input is not valid"):
|
||||
```
|
||||
---- BEGIN SSH2 PUBLIC KEY ----
|
||||
Comment: "4096-bit RSA, converted by marius@Mihai-HXG0G from OpenSSH"
|
||||
AAAAB3NzaC1yc2EAAAADAQABAAACAQCcRM+WWxoBqCSpaTo+vNCrvCLx1UFmKqqSh6smS4
|
||||
c/lh1Hkku+oiq65iUHwRMu5X9jDXSGUR1Fmig+OgIhoTnT4Hd3v4Fe2zienOFiJ/AZOTE+
|
||||
pgxpwmIrkScGTSv7ZSp4xFcXsFwho8W/Li0P0kyB+kGs2tFYaQM192E5Gx9qjlPGSM55fd
|
||||
ksElRXKIrRHE4ARjt5+kMt4WFgUXpVNqhHQFEcz/oW6sC0OkufTbzQ+MHefBIlMNUlNHRx
|
||||
bHc3C6CTuMmzMM847y6rmQlDyScX0tizDhUnQ1UgA3ZyICJp9CVF4weAM6ihZhNTFi7drX
|
||||
iCEihUVLNU+EuEpWdWeVNebqBqlkJT0KXR3IgEQ3zKYKuAmICFO056WI3eKcJWuWEFNDrS
|
||||
Ysxo+HydAbqBSqEprJFCUSU90175ngnpY4WoH7CFUbCnGjxEnRXUjUktaCdqYhH0ZjGHSG
|
||||
ujK+KGPVxvBi1h7BjE33SEH6PAVZBYmdpGDri69n6H+v6dhaW26scFcc6ldrOcbaRsX7q4
|
||||
M8gFIwotAu6jTuid8FensF/j9yQRDkcOS8OWXHr5z2lZTCSDPik83p8mvvEZ/R7dP60ldw
|
||||
z2INX8rbCxi5frEdijqrwZCq9D2tzUJJgG8h3KUKfd3QfThCyq6AdE9X2+EnmU1yP2SJso
|
||||
lgM7euuDBH0/qQ==
|
||||
---- END SSH2 PUBLIC KEY ----
|
||||
```
|
||||
|
||||
## 📋 Pași pentru Bitvise SSH Server
|
||||
|
||||
### 1. 🖥️ Deschide Bitvise SSH Server Control Panel
|
||||
|
||||
- Lansează **Bitvise SSH Server Control Panel** pe serverul Windows
|
||||
- Ar trebui să fie în System Tray sau în Start Menu
|
||||
|
||||
### 2. 👤 Configurează utilizatorul
|
||||
|
||||
**În Bitvise SSH Server Control Panel:**
|
||||
|
||||
1. **Click pe tab "Users"**
|
||||
2. **Găsește utilizatorul tău** (sau creează unul nou dacă nu există)
|
||||
3. **Double-click pe utilizator** pentru a-l edita
|
||||
|
||||
### 3. 🔐 Adaugă cheia SSH publică
|
||||
|
||||
**În fereastra User Properties:**
|
||||
|
||||
1. **Authentication tab:**
|
||||
- Setează **"Public key authentication"** la **"Required"** sau **"Optional"**
|
||||
|
||||
2. **Public Keys section:**
|
||||
- Click pe **"Import"** sau **"Add"**
|
||||
- **Paste** cheia publică de mai sus în câmpul text
|
||||
- Sau salvează cheia într-un fișier `.pub` și importă fișierul
|
||||
|
||||
3. **Virtual filesystem:**
|
||||
- Asigură-te că utilizatorul are acces la directorul de lucru dorit
|
||||
- De obicei setează **Root directory** la `C:\` sau un folder specific
|
||||
|
||||
### 4. ✅ Salvează configurația
|
||||
|
||||
1. **Click "OK"** pentru a salva setările utilizatorului
|
||||
2. **Apply Configuration** în Control Panel principal
|
||||
3. **Restart SSH Server** dacă este necesar
|
||||
|
||||
## 🔧 Configurare WSL SSH Tunnel Script
|
||||
|
||||
**Editează `ssh_tunnel.sh` cu username-ul corect:**
|
||||
|
||||
```bash
|
||||
nano /mnt/d/PROIECTE/roa-flask/ssh_tunnel.sh
|
||||
|
||||
# Găsește și actualizează:
|
||||
SSH_USER="your_bitvise_username" # Numele utilizatorului din Bitvise
|
||||
```
|
||||
|
||||
## 🧪 Testarea conexiunii
|
||||
|
||||
### 1. Test manual SSH:
|
||||
```bash
|
||||
ssh -p 22122 -i ~/.ssh/roa_oracle_server your_username@83.103.197.79
|
||||
```
|
||||
|
||||
### 2. Test tunnel SSH:
|
||||
```bash
|
||||
cd /mnt/d/PROIECTE/roa-flask/roa2web
|
||||
./ssh_tunnel.sh start
|
||||
```
|
||||
|
||||
### 3. Test Oracle pool:
|
||||
```bash
|
||||
source venv/bin/activate
|
||||
python shared/database/test_pool.py
|
||||
```
|
||||
|
||||
## 🎯 Output așteptat
|
||||
|
||||
### SSH Connection Test:
|
||||
```bash
|
||||
$ ssh -p 22122 -i ~/.ssh/roa_oracle_server marius@83.103.197.79
|
||||
Welcome to Bitvise SSH Server!
|
||||
Microsoft Windows [Version 10.0.19044]
|
||||
(c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
C:\Users\marius>exit
|
||||
```
|
||||
|
||||
### SSH Tunnel Start:
|
||||
```
|
||||
================================
|
||||
ROA2WEB SSH Tunnel Manager
|
||||
================================
|
||||
🔄 Starting SSH tunnel...
|
||||
Server: 83.103.197.79:22122
|
||||
Local: 127.0.0.1:1521
|
||||
Remote: localhost:1521
|
||||
|
||||
🔍 Testing SSH connectivity...
|
||||
✅ SSH connectivity OK
|
||||
|
||||
🚀 Creating SSH tunnel...
|
||||
✅ SSH tunnel started successfully (PID: 12345)
|
||||
🔍 Testing tunnel connectivity...
|
||||
✅ Tunnel is working! Port 1521 is accessible
|
||||
```
|
||||
|
||||
## ❌ Troubleshooting Bitvise
|
||||
|
||||
### "Permission denied (publickey)"
|
||||
- **Verifică**: Cheia SSH este corect adăugată în User Properties
|
||||
- **Verifică**: Authentication method include "Public key"
|
||||
- **Verifică**: Username-ul din script este corect
|
||||
|
||||
### "Connection refused"
|
||||
- **Verifică**: Bitvise SSH Server este pornit și funcționează
|
||||
- **Verifică**: Portul 22122 este configurat corect în server
|
||||
- **Verifică**: Windows Firewall permite conexiuni pe port 22122
|
||||
|
||||
### "User access denied"
|
||||
- **Verifică**: Utilizatorul există în lista Users din Bitvise
|
||||
- **Verifică**: Utilizatorul are permisiuni de login (Account enabled)
|
||||
- **Verifică**: Virtual filesystem este configurat corect
|
||||
|
||||
### "Input is not valid" în Bitvise
|
||||
- **🔧 Soluție 1**: Folosește formatul **RFC4716** (vezi mai sus)
|
||||
- **🔧 Soluție 2**: Salvează cheia într-un fișier `.pub` și importă fișierul în loc să faci paste
|
||||
- **🔧 Soluție 3**: Asigură-te că nu ai spații extra la începutul/sfârșitul cheii
|
||||
- **🔧 Soluție 4**: Încearcă să ștergi și să adaugi din nou utilizatorul în Bitvise
|
||||
|
||||
### Cheia SSH nu este acceptată
|
||||
- **Format cheie**: Asigură-te că ai copiat toată cheia, inclusiv header-ul și comment-ul
|
||||
- **Tip cheie**: Bitvise suportă RSA, DSA, ECDSA, Ed25519 - folosim RSA 4096
|
||||
- **Import method**: Dacă paste nu funcționează, salvează într-un fișier și importă
|
||||
- **Line endings**: Verifică că nu sunt caractere ascunse în cheie
|
||||
|
||||
## 📝 Note specifice Bitvise
|
||||
|
||||
1. **User management**: Bitvise are propriul sistem de utilizatori, independent de Windows users
|
||||
2. **Virtual filesystem**: Poți controla la ce directoare are acces utilizatorul SSH
|
||||
3. **Port forwarding**: Bitvise poate restricționa port forwarding - asigură-te că este permis
|
||||
4. **Logging**: Verifică log-urile din Bitvise pentru detalii despre conexiuni failed
|
||||
|
||||
---
|
||||
|
||||
*Configurare Bitvise SSH Server pentru ROA2WEB Development* 🔐
|
||||
170
ssh-tunnel/docs/SSH_SETUP_INSTRUCTIONS.md
Normal file
170
ssh-tunnel/docs/SSH_SETUP_INSTRUCTIONS.md
Normal file
@@ -0,0 +1,170 @@
|
||||
# 🔐 SSH Setup Instructions pentru ROA2WEB
|
||||
|
||||
Instrucțiuni pentru configurarea tunelului SSH din WSL către serverul Oracle.
|
||||
|
||||
## 📋 Pași de Setup
|
||||
|
||||
### 1. 🔑 Generarea cheii SSH
|
||||
|
||||
**Dacă nu ai cheia SSH generată, creează-o astfel:**
|
||||
|
||||
```bash
|
||||
# Generează cheia SSH (RSA 4096-bit)
|
||||
ssh-keygen -t rsa -b 4096 -f ~/.ssh/roa_oracle_server -N "" -C "roa2web-wsl-$(whoami)@$(hostname)"
|
||||
|
||||
# Verifică că s-a creat
|
||||
ls -la ~/.ssh/roa_oracle_server*
|
||||
```
|
||||
|
||||
**Output așteptat:**
|
||||
```
|
||||
Generating public/private rsa key pair.
|
||||
Your identification has been saved in /home/user/.ssh/roa_oracle_server
|
||||
Your public key has been saved in /home/user/.ssh/roa_oracle_server.pub
|
||||
```
|
||||
|
||||
**Cheia SSH existentă este în: `~/.ssh/roa_oracle_server`**
|
||||
|
||||
**Pentru a afișa cheia PUBLICĂ:**
|
||||
```bash
|
||||
cat ~/.ssh/roa_oracle_server.pub
|
||||
```
|
||||
|
||||
**Cheia PUBLICĂ pentru server:**
|
||||
```
|
||||
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCcRM+WWxoBqCSpaTo+vNCrvCLx1UFmKqqSh6smS4c/lh1Hkku+oiq65iUHwRMu5X9jDXSGUR1Fmig+OgIhoTnT4Hd3v4Fe2zienOFiJ/AZOTE+pgxpwmIrkScGTSv7ZSp4xFcXsFwho8W/Li0P0kyB+kGs2tFYaQM192E5Gx9qjlPGSM55fdksElRXKIrRHE4ARjt5+kMt4WFgUXpVNqhHQFEcz/oW6sC0OkufTbzQ+MHefBIlMNUlNHRxbHc3C6CTuMmzMM847y6rmQlDyScX0tizDhUnQ1UgA3ZyICJp9CVF4weAM6ihZhNTFi7drXiCEihUVLNU+EuEpWdWeVNebqBqlkJT0KXR3IgEQ3zKYKuAmICFO056WI3eKcJWuWEFNDrSYsxo+HydAbqBSqEprJFCUSU90175ngnpY4WoH7CFUbCnGjxEnRXUjUktaCdqYhH0ZjGHSGujK+KGPVxvBi1h7BjE33SEH6PAVZBYmdpGDri69n6H+v6dhaW26scFcc6ldrOcbaRsX7q4M8gFIwotAu6jTuid8FensF/j9yQRDkcOS8OWXHr5z2lZTCSDPik83p8mvvEZ/R7dP60ldwz2INX8rbCxi5frEdijqrwZCq9D2tzUJJgG8h3KUKfd3QfThCyq6AdE9X2+EnmU1yP2SJsolgM7euuDBH0/qQ== roa2web-wsl-marius@Mihai-HXG0G
|
||||
```
|
||||
|
||||
### 2. 📤 Instalarea cheii pe Bitvise SSH Server
|
||||
|
||||
**🔴 IMPORTANT: Serverul folosește Bitvise SSH Server pe Windows**
|
||||
|
||||
Consultă **`BITVISE_SSH_SETUP.md`** pentru instrucțiuni detaliate!
|
||||
|
||||
**Pași rapid:**
|
||||
1. Deschide **Bitvise SSH Server Control Panel**
|
||||
2. Mergi la **Users tab** → selectează/creează utilizatorul
|
||||
3. În **User Properties** → **Authentication** → setează **Public key authentication**
|
||||
4. În **Public Keys** → **Import/Add** → paste cheia publică:
|
||||
|
||||
```
|
||||
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCcRM+WWxoBqCSpaTo+vNCrvCLx1UFmKqqSh6smS4c/lh1Hkku+oiq65iUHwRMu5X9jDXSGUR1Fmig+OgIhoTnT4Hd3v4Fe2zienOFiJ/AZOTE+pgxpwmIrkScGTSv7ZSp4xFcXsFwho8W/Li0P0kyB+kGs2tFYaQM192E5Gx9qjlPGSM55fdksElRXKIrRHE4ARjt5+kMt4WFgUXpVNqhHQFEcz/oW6sC0OkufTbzQ+MHefBIlMNUlNHRxbHc3C6CTuMmzMM847y6rmQlDyScX0tizDhUnQ1UgA3ZyICJp9CVF4weAM6ihZhNTFi7drXiCEihUVLNU+EuEpWdWeVNebqBqlkJT0KXR3IgEQ3zKYKuAmICFO056WI3eKcJWuWEFNDrSYsxo+HydAbqBSqEprJFCUSU90175ngnpY4WoH7CFUbCnGjxEnRXUjUktaCdqYhH0ZjGHSGujK+KGPVxvBi1h7BjE33SEH6PAVZBYmdpGDri69n6H+v6dhaW26scFcc6ldrOcbaRsX7q4M8gFIwotAu6jTuid8FensF/j9yQRDkcOS8OWXHr5z2lZTCSDPik83p8mvvEZ/R7dP60ldwz2INX8rbCxi5frEdijqrwZCq9D2tzUJJgG8h3KUKfd3QfThCyq6AdE9X2+EnmU1yP2SJsolgM7euuDBH0/qQ== roa2web-wsl-marius@Mihai-HXG0G
|
||||
```
|
||||
|
||||
5. **OK** → **Apply Configuration** → **Restart SSH Server** dacă necesar
|
||||
|
||||
### 3. ⚙️ Configurarea username-ului
|
||||
|
||||
**✅ IMPORTANT**: Folosește utilizatorul `roa2web` care are port forwarding activat în Bitvise!
|
||||
|
||||
**În WSL, editează scriptul SSH:**
|
||||
|
||||
```bash
|
||||
nano /mnt/d/PROIECTE/roa-flask/ssh_tunnel.sh
|
||||
```
|
||||
|
||||
**Actualizează linia:**
|
||||
```bash
|
||||
SSH_USER="roa2web" # Utilizator cu port forwarding activat
|
||||
```
|
||||
|
||||
**💡 Notă**: Utilizatorul `roa2web` poate să nu aibă shell access, dar poate face port forwarding.
|
||||
|
||||
### 4. 🚀 Testarea setup-ului
|
||||
|
||||
```bash
|
||||
cd /mnt/d/PROIECTE/roa-flask/roa2web
|
||||
|
||||
# Afișează ajutorul
|
||||
./ssh_tunnel.sh help
|
||||
|
||||
# Testează și pornește tunelul
|
||||
./ssh_tunnel.sh start
|
||||
|
||||
# Verifică statusul
|
||||
./ssh_tunnel.sh status
|
||||
```
|
||||
|
||||
## 🔧 Comenzi utile
|
||||
|
||||
### Gestionarea tunelului SSH:
|
||||
```bash
|
||||
# Pornește tunelul
|
||||
./ssh_tunnel.sh start
|
||||
|
||||
# Oprește tunelul
|
||||
./ssh_tunnel.sh stop
|
||||
|
||||
# Verifică statusul
|
||||
./ssh_tunnel.sh status
|
||||
|
||||
# Repornește tunelul
|
||||
./ssh_tunnel.sh restart
|
||||
```
|
||||
|
||||
### Testarea pool-ului Oracle:
|
||||
```bash
|
||||
# Cu tunelul SSH activ
|
||||
cd /mnt/d/PROIECTE/roa-flask/roa2web
|
||||
source venv/bin/activate
|
||||
python shared/database/test_pool.py
|
||||
```
|
||||
|
||||
## 🔍 Troubleshooting
|
||||
|
||||
### ❌ "Permission denied (publickey)"
|
||||
- Verifică că cheia publică este corect instalată pe server
|
||||
- Verifică permisiunile: `chmod 600 ~/.ssh/authorized_keys`
|
||||
- Verifică că SSH_USER este corect în script
|
||||
|
||||
### ❌ "Connection refused" sau "Connection timed out"
|
||||
- Verifică că serverul SSH este accesibil: `telnet 83.103.197.79 22122`
|
||||
- Verifică că portul 22122 nu este blocat de firewall
|
||||
|
||||
### ❌ "Port 1521 not responding"
|
||||
- Normal dacă Oracle listener nu este pornit pe server
|
||||
- Tunelul SSH poate fi OK, dar Oracle nu răspunde
|
||||
|
||||
### ❌ Oracle connection errors
|
||||
- Verifică că tunelul SSH este activ: `./ssh_tunnel.sh status`
|
||||
- Verifică că configurația Oracle din `.env` este corectă
|
||||
- Testează manual: `telnet 127.0.0.1 1521`
|
||||
|
||||
## 📊 Output așteptat
|
||||
|
||||
### SSH Tunnel Start:
|
||||
```
|
||||
================================
|
||||
ROA2WEB SSH Tunnel Manager
|
||||
================================
|
||||
🔄 Starting SSH tunnel...
|
||||
Server: 83.103.197.79:22122
|
||||
Local: 127.0.0.1:1521
|
||||
Remote: localhost:1521
|
||||
|
||||
🔍 Testing SSH connectivity...
|
||||
✅ SSH connectivity OK
|
||||
|
||||
🚀 Creating SSH tunnel...
|
||||
✅ SSH tunnel started successfully (PID: 12345)
|
||||
🔍 Testing tunnel connectivity...
|
||||
✅ Tunnel is working! Port 1521 is accessible
|
||||
```
|
||||
|
||||
### Oracle Pool Test:
|
||||
```
|
||||
🚀 ROA2WEB Oracle Pool Test - 2025-07-30 16:00:00
|
||||
==================================================
|
||||
🔄 Testing Oracle connection pool...
|
||||
📊 Initializing Oracle pool...
|
||||
✅ Pool initialized successfully
|
||||
🔍 Testing database connection...
|
||||
✅ Simple query successful: (1,)
|
||||
...
|
||||
🎉 ALL TESTS PASSED!
|
||||
✅ Oracle pool is fully functional and ready for production!
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
*Instrucțiuni SSH pentru ROA2WEB Development Environment* 🔐
|
||||
139
ssh-tunnel/docs/SSH_TUNNEL_DOCKER.md
Normal file
139
ssh-tunnel/docs/SSH_TUNNEL_DOCKER.md
Normal file
@@ -0,0 +1,139 @@
|
||||
# SSH Tunnel Docker Integration
|
||||
|
||||
SSH tunnel-ul pentru conexiunea la Oracle database este acum complet integrat în Docker setup.
|
||||
|
||||
## 🔧 Configurare Automată
|
||||
|
||||
### Development Mode
|
||||
SSH tunnel-ul pornește automat când rulezi:
|
||||
```bash
|
||||
docker-compose up
|
||||
```
|
||||
|
||||
### Servicii incluse:
|
||||
- **roa-ssh-tunnel**: Container dedicat pentru SSH tunnel
|
||||
- **roa-backend**: Conectat prin tunnel la Oracle
|
||||
- **roa-frontend**: Interface-ul web
|
||||
- **roa-gateway**: Nginx reverse proxy
|
||||
- **roa-redis**: Cache și sesiuni
|
||||
|
||||
## 📋 Cerințe
|
||||
|
||||
### SSH Key
|
||||
Asigură-te că ai cheia SSH în locația corectă:
|
||||
```bash
|
||||
~/.ssh/roa_oracle_server
|
||||
```
|
||||
|
||||
### Configurare Environment
|
||||
Variabilele sunt setate automat din `.env.development`:
|
||||
```env
|
||||
SSH_SERVER=83.103.197.79
|
||||
SSH_PORT=22122
|
||||
SSH_USER=roa2web
|
||||
REMOTE_HOST=10.0.20.36
|
||||
ORACLE_HOST=localhost # Se conectează prin tunnel
|
||||
```
|
||||
|
||||
## 🚀 Utilizare
|
||||
|
||||
### Start complet cu SSH tunnel:
|
||||
```bash
|
||||
# Copiază environment-ul de development
|
||||
cp .env.development .env
|
||||
|
||||
# Pornește toate serviciile (inclusiv SSH tunnel)
|
||||
docker-compose up --build
|
||||
```
|
||||
|
||||
### Verificare SSH tunnel:
|
||||
```bash
|
||||
# Check tunnel health
|
||||
docker-compose ps roa-ssh-tunnel
|
||||
|
||||
# Check tunnel logs
|
||||
docker-compose logs -f roa-ssh-tunnel
|
||||
|
||||
# Test Oracle connection through tunnel
|
||||
docker-compose exec roa-backend python -c "
|
||||
from shared.database.oracle_pool import test_connection
|
||||
test_connection()
|
||||
"
|
||||
```
|
||||
|
||||
## 🔍 Monitoring
|
||||
|
||||
### SSH Tunnel Status:
|
||||
- **Health check**: Verifică portul 1521 la fiecare 30s
|
||||
- **Auto-restart**: Tunnel-ul se restartează automat dacă se întrerupe
|
||||
- **Logs**: Monitorizare în timp real cu `docker-compose logs -f roa-ssh-tunnel`
|
||||
|
||||
### Service Dependencies:
|
||||
```
|
||||
roa-ssh-tunnel (first)
|
||||
↓
|
||||
roa-redis
|
||||
↓
|
||||
roa-backend (depends on tunnel + redis)
|
||||
↓
|
||||
roa-frontend
|
||||
↓
|
||||
roa-gateway (last)
|
||||
```
|
||||
|
||||
## 🏭 Producție
|
||||
|
||||
În producție, SSH tunnel-ul este automat dezactivat:
|
||||
|
||||
```bash
|
||||
# Production deployment (fără SSH tunnel)
|
||||
docker-compose -f docker-compose.yml -f docker-compose.production.yml up -d
|
||||
```
|
||||
|
||||
Backend-ul se conectează direct la Oracle server în producție.
|
||||
|
||||
## 🛠️ Troubleshooting
|
||||
|
||||
### SSH Tunnel nu pornește:
|
||||
```bash
|
||||
# Verifică că ai cheia SSH
|
||||
ls -la ~/.ssh/roa_oracle_server
|
||||
|
||||
# Verifică permissions
|
||||
chmod 600 ~/.ssh/roa_oracle_server
|
||||
|
||||
# Restart tunnel container
|
||||
docker-compose restart roa-ssh-tunnel
|
||||
```
|
||||
|
||||
### Backend nu se conectează la Oracle:
|
||||
```bash
|
||||
# Check tunnel status
|
||||
docker-compose exec roa-ssh-tunnel nc -z localhost 1521
|
||||
|
||||
# Check backend logs
|
||||
docker-compose logs -f roa-backend
|
||||
|
||||
# Test manual connection
|
||||
docker-compose exec roa-ssh-tunnel nc -z 10.0.20.36 1521
|
||||
```
|
||||
|
||||
### Connection timeout:
|
||||
```bash
|
||||
# Verifică că serverul SSH rulează
|
||||
ssh -p 22122 roa2web@83.103.197.79
|
||||
|
||||
# Restart toate serviciile
|
||||
docker-compose down && docker-compose up --build
|
||||
```
|
||||
|
||||
## 📊 Avantaje
|
||||
|
||||
✅ **Automat**: Nu mai trebuie să pornești manual SSH tunnel-ul
|
||||
✅ **Robust**: Auto-restart dacă tunnel-ul se întrerupe
|
||||
✅ **Monitorizat**: Health checks și logging complet
|
||||
✅ **Development-only**: Exclus automat în producție
|
||||
✅ **Containerizat**: Izolat în propriul container
|
||||
✅ **Dependencies**: Backend așteaptă tunnel-ul să fie gata
|
||||
|
||||
Nu mai trebuie să rulezi `./ssh_tunnel.sh start` manual - totul e automat în Docker! 🎉
|
||||
144
ssh-tunnel/ssh_tunnel_docker.sh
Normal file
144
ssh-tunnel/ssh_tunnel_docker.sh
Normal file
@@ -0,0 +1,144 @@
|
||||
#!/bin/bash
|
||||
# SSH Tunnel Docker Container Script
|
||||
# Maintains SSH tunnel to Oracle database
|
||||
|
||||
set -e
|
||||
|
||||
# Configuration from environment variables
|
||||
SSH_SERVER="${SSH_SERVER:-83.103.197.79}"
|
||||
SSH_PORT="${SSH_PORT:-22122}"
|
||||
SSH_USER="${SSH_USER:-roa2web}"
|
||||
SSH_KEY_PATH="${SSH_KEY_PATH:-/home/tunnel/.ssh/roa_oracle_server}"
|
||||
LOCAL_PORT="${LOCAL_PORT:-1521}"
|
||||
REMOTE_HOST="${REMOTE_HOST:-10.0.20.36}"
|
||||
REMOTE_PORT="${REMOTE_PORT:-1521}"
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
log() {
|
||||
echo -e "[$(date +'%Y-%m-%d %H:%M:%S')] $1"
|
||||
}
|
||||
|
||||
log "${BLUE}🚀 Starting SSH tunnel container...${NC}"
|
||||
log "${BLUE}Tunnel: localhost:${LOCAL_PORT} -> ${SSH_SERVER}:${SSH_PORT} -> ${REMOTE_HOST}:${REMOTE_PORT}${NC}"
|
||||
|
||||
# Check if SSH key exists
|
||||
if [ ! -f "$SSH_KEY_PATH" ]; then
|
||||
log "${RED}❌ SSH private key not found at $SSH_KEY_PATH${NC}"
|
||||
log "${YELLOW}Please mount your SSH key as a volume:${NC}"
|
||||
log "${YELLOW} -v ~/.ssh/roa_oracle_server:/home/tunnel/.ssh/roa_oracle_server:ro${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Set proper permissions for SSH key (skip if operation not permitted)
|
||||
chmod 600 "$SSH_KEY_PATH" 2>/dev/null || log "${YELLOW}⚠️ Could not set SSH key permissions (continuing anyway)${NC}"
|
||||
|
||||
# Create SSH config for better connection handling
|
||||
mkdir -p /home/tunnel/.ssh
|
||||
cat > /home/tunnel/.ssh/config << EOF
|
||||
Host tunnel-server
|
||||
HostName ${SSH_SERVER}
|
||||
Port ${SSH_PORT}
|
||||
User ${SSH_USER}
|
||||
IdentityFile ${SSH_KEY_PATH}
|
||||
StrictHostKeyChecking no
|
||||
UserKnownHostsFile /dev/null
|
||||
ServerAliveInterval 30
|
||||
ServerAliveCountMax 3
|
||||
TCPKeepAlive yes
|
||||
ExitOnForwardFailure yes
|
||||
BatchMode yes
|
||||
EOF
|
||||
|
||||
chmod 600 /home/tunnel/.ssh/config
|
||||
|
||||
# Function to establish tunnel
|
||||
establish_tunnel() {
|
||||
log "${YELLOW}🔗 Establishing SSH tunnel...${NC}"
|
||||
|
||||
ssh -N -T \
|
||||
-o ConnectTimeout=30 \
|
||||
-o ServerAliveInterval=30 \
|
||||
-o ServerAliveCountMax=3 \
|
||||
-o ExitOnForwardFailure=yes \
|
||||
-o GatewayPorts=yes \
|
||||
-L "0.0.0.0:${LOCAL_PORT}:${REMOTE_HOST}:${REMOTE_PORT}" \
|
||||
tunnel-server &
|
||||
|
||||
SSH_PID=$!
|
||||
echo $SSH_PID > /tmp/ssh_tunnel.pid
|
||||
|
||||
# Wait a moment for tunnel to establish
|
||||
sleep 5
|
||||
|
||||
# Test tunnel
|
||||
if nc -z localhost "$LOCAL_PORT" >/dev/null 2>&1; then
|
||||
log "${GREEN}✅ SSH tunnel established successfully (PID: $SSH_PID)${NC}"
|
||||
return 0
|
||||
else
|
||||
log "${RED}❌ Failed to establish SSH tunnel${NC}"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to monitor tunnel
|
||||
monitor_tunnel() {
|
||||
while true; do
|
||||
if [ -f /tmp/ssh_tunnel.pid ]; then
|
||||
local pid=$(cat /tmp/ssh_tunnel.pid)
|
||||
|
||||
# Check if process is still running
|
||||
if ! ps -p "$pid" > /dev/null 2>&1; then
|
||||
log "${YELLOW}⚠️ SSH tunnel process died, restarting...${NC}"
|
||||
establish_tunnel
|
||||
fi
|
||||
|
||||
# Check if port is still accessible
|
||||
if ! nc -z localhost "$LOCAL_PORT" >/dev/null 2>&1; then
|
||||
log "${YELLOW}⚠️ SSH tunnel port not accessible, restarting...${NC}"
|
||||
if [ -f /tmp/ssh_tunnel.pid ]; then
|
||||
kill $(cat /tmp/ssh_tunnel.pid) 2>/dev/null || true
|
||||
rm -f /tmp/ssh_tunnel.pid
|
||||
fi
|
||||
establish_tunnel
|
||||
fi
|
||||
else
|
||||
log "${YELLOW}⚠️ SSH tunnel not running, starting...${NC}"
|
||||
establish_tunnel
|
||||
fi
|
||||
|
||||
sleep 30
|
||||
done
|
||||
}
|
||||
|
||||
# Function to handle shutdown gracefully
|
||||
cleanup() {
|
||||
log "${YELLOW}📋 Shutting down SSH tunnel...${NC}"
|
||||
if [ -f /tmp/ssh_tunnel.pid ]; then
|
||||
local pid=$(cat /tmp/ssh_tunnel.pid)
|
||||
kill "$pid" 2>/dev/null || true
|
||||
rm -f /tmp/ssh_tunnel.pid
|
||||
fi
|
||||
log "${GREEN}✅ SSH tunnel stopped${NC}"
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Set up signal handlers
|
||||
trap cleanup SIGTERM SIGINT
|
||||
|
||||
# Initial tunnel establishment
|
||||
if establish_tunnel; then
|
||||
log "${GREEN}🎉 SSH tunnel container ready!${NC}"
|
||||
log "${BLUE}Oracle database accessible at localhost:${LOCAL_PORT}${NC}"
|
||||
|
||||
# Start monitoring
|
||||
monitor_tunnel
|
||||
else
|
||||
log "${RED}💥 Failed to establish initial SSH tunnel${NC}"
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user