@artilingo/artiframe-cli 2.0.4 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/LICENSE +660 -660
  2. package/README.md +64 -118
  3. package/bin/artiframe.js +0 -0
  4. package/bin/artiframe.php +0 -0
  5. package/core-stubs/app/ApiAuthControl.php +76 -0
  6. package/core-stubs/app/ApiControl.php +81 -35
  7. package/core-stubs/app/AuthControl.php +39 -0
  8. package/core-stubs/app/Database.php +36 -35
  9. package/core-stubs/app/DotEnv.php +19 -1
  10. package/core-stubs/app/ViewControl.php +47 -1
  11. package/core-stubs/bin/SQLMethod.php +261 -0
  12. package/core-stubs/bin/SystemMethod.php +115 -74
  13. package/core-stubs/bin/ViewMethod.php +19 -5
  14. package/core-stubs/docs/de.html +4325 -4347
  15. package/core-stubs/docs/en.html +4325 -4347
  16. package/core-stubs/docs/es.html +4325 -4347
  17. package/core-stubs/docs/fr.html +4325 -4347
  18. package/core-stubs/docs/tr.html +117 -46
  19. package/core-stubs/public/403.php +52 -0
  20. package/core-stubs/public/assets/css/components/header.css +174 -0
  21. package/core-stubs/public/assets/css/components/mobilenav.css +198 -0
  22. package/core-stubs/public/assets/css/components/sidebar.css +184 -0
  23. package/core-stubs/public/assets/css/root/app.css +975 -38
  24. package/core-stubs/public/assets/css/root/root.css +64 -0
  25. package/core-stubs/public/assets/js/components/header.js +380 -0
  26. package/core-stubs/public/assets/js/components/mobilenav.js +97 -0
  27. package/core-stubs/public/assets/js/components/theme-modal.js +74 -0
  28. package/core-stubs/public/assets/js/root/app.js +1870 -0
  29. package/core-stubs/public/includes/footer.php +4 -5
  30. package/core-stubs/public/includes/head-auth.php +65 -0
  31. package/core-stubs/public/includes/head.php +56 -17
  32. package/core-stubs/public/includes/header.php +135 -1
  33. package/core-stubs/public/includes/mobilenav.php +75 -3
  34. package/core-stubs/public/includes/sidebar.php +186 -1
  35. package/core-stubs/public/includes/theme-modal.php +1 -0
  36. package/db-studio/debug.log +3 -0
  37. package/db-studio/index.html +1755 -0
  38. package/db-studio/launcher.html +102 -0
  39. package/db-studio/launcher.js +180 -0
  40. package/db-studio/logo.svg +22 -0
  41. package/db-studio/main.js +568 -0
  42. package/db-studio/package-lock.json +1034 -0
  43. package/db-studio/package.json +16 -0
  44. package/db-studio/preload.js +29 -0
  45. package/devops-studio/api-inspector.js +222 -0
  46. package/devops-studio/index.html +1892 -0
  47. package/devops-studio/logo.svg +22 -0
  48. package/devops-studio/main.js +67 -0
  49. package/devops-studio/make-wizard.js +635 -0
  50. package/devops-studio/package-lock.json +871 -0
  51. package/devops-studio/package.json +12 -0
  52. package/package.json +5 -2
  53. package/scripts/postinstall.js +44 -8
  54. package/server-studio/.json-404-guard +1 -0
  55. package/server-studio/index.html +283 -0
  56. package/server-studio/logo.svg +22 -0
  57. package/server-studio/main.js +133 -0
  58. package/server-studio/package-lock.json +1179 -0
  59. package/server-studio/package.json +15 -0
  60. package/server-studio/router.php +99 -0
  61. package/src/App.php +29 -0
  62. package/src/Commands/AddCommand.php +26 -9
  63. package/src/Commands/DbExportCommand.php +131 -0
  64. package/src/Commands/DbStartCommand.php +46 -0
  65. package/src/Commands/DevopsCommand.php +35 -0
  66. package/src/Commands/GoCommand.php +48 -48
  67. package/src/Commands/ListCommand.php +68 -68
  68. package/src/Commands/MakeApiCommand.php +6 -1
  69. package/src/Commands/MakeViewCommand.php +25 -2
  70. package/src/Commands/NewProjectCommand.php +16 -11
  71. package/src/Commands/OptimizeCommand.php +61 -0
  72. package/src/Commands/RemoveCommand.php +35 -7
  73. package/src/Commands/ServeCommand.php +46 -91
  74. package/src/Commands/ShowCommand.php +24 -24
  75. package/src/Commands/UpgradeCommand.php +39 -10
  76. package/stubs/make/api-switch-case.stub +1 -1
  77. package/stubs/make/auth-api-standart.stub +20 -0
  78. package/stubs/make/auth-api-switch-case.stub +38 -0
  79. package/stubs/make/auth-view.stub +26 -0
  80. package/stubs/make/class.stub +10 -2
  81. package/stubs/make/view.stub +3 -0
  82. package/stubs/service/image.stub +334 -334
  83. package/stubs/service/iyzico.stub +637 -637
  84. package/stubs/service/jwt.stub +312 -312
  85. package/stubs/service/phpmailer.stub +143 -143
  86. package/stubs/service/pusher.stub +232 -232
  87. package/stubs/service/qrcode.stub +169 -169
  88. package/stubs/service/redis.stub +361 -361
  89. package/stubs/service/s3.stub +377 -377
  90. package/stubs/service/stripe.stub +526 -526
  91. package/stubs/service/twilio.stub +361 -361
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  <br />
6
6
 
7
- **Zero-dependency · Native PHP · Multilingual CLI**
7
+ **Zero-dependency · Native PHP · DevOps Studio · DB Designer · Live Server**
8
8
 
9
9
  <br />
10
10
 
@@ -27,205 +27,151 @@
27
27
 
28
28
  ## 🇹🇷 Türkçe
29
29
 
30
- **ArtiFrame**, sıfır dış bağımlılık felsefesiyle inşa edilmiş, native PHP için modern bir web geliştirme çerçevesidir. Composer paket karmaşasından arınmış, güvenlik öncelikli ve CLI güdümlü bir ekosistem sunar.
30
+ **ArtiFrame 3.0**, native PHP için sadece bir framework değil, eksiksiz bir **geliştirme ekosistemidir**. Sıfır dış bağımlılık felsefesine sadık kalarak, artık içinde DevOps Studio (GUI), DB Studio (Global ER Tasarımcısı) ve Server Studio (Canlı Log Monitörü) gibi muazzam arayüzler barındırır.
31
31
 
32
- ### Özellikler
32
+ ### Yeni v3.0 Özellikleri (The Studio Update)
33
33
 
34
- - 🚫 **Sıfır Bağımlılık** — Composer paketlerine ihtiyaç yok, her satır kendi kodunuz
35
- - 🛡️ **Güvenlik Önce** — XSS, CSRF, SQL Injection koruması varsayılan olarak yerleşik
36
- - **Hızlı Kurulum** — Tek komutla eksiksiz proje iskeleti
37
- - 🌍 **5 Dil Desteği** — TR · EN · DE · FR · ES
38
- - 📐 **Katı Kural Seti** — `data-js` mimarisi, iki bootstrapper modeli, tutarlı dizin yapısı
34
+ - 🎨 **DevOps Studio** — `artiframe devops` komutuyla açılan yerleşik masaüstü GUI. API Testleri (Inspector), Cron Tasarımcısı, Supervisor Yönetimi ve Env Optimize işlemlerini görsel olarak yönetin!
35
+ - 🗄️ **DB Studio** — Sürükle bırak ile veritabanı şemalarınızı tasarlayın ve `db:onproject` ile doğrudan projenize entegre edin.
36
+ - 🌐 **Server Studio** — `artiframe serve` ile projenizi anında yayına alın ve HTTP isteklerini canlı log (Gateway logger) üzerinden analiz edin.
37
+ - 📦 **Workspace Mimarisi** — Projeleriniz artık global ve izole bir workspace dizininde (`C:\ArtiFrame` veya `~/ArtiFrame`) güvenle yaşar.
38
+ - 🚀 **Semantik Sürüm ve Eklenti Yönetimi** — `version upgrade` ve `add <package>` gibi yerleşik paket/sürüm yöneticileriyle Composer olmadan hayatınıza devam edin.
39
+ - 🚫 **Sıfır Bağımlılık** — Güvenlik (XSS, CSRF) ve mimari altyapı hala native PHP.
39
40
 
40
41
  ### Kurulum
41
42
 
42
- > PHP 8.1 veya üzeri gereklidir.
43
+ > Node.js ve PHP 8.1+ gereklidir.
43
44
 
44
45
  ```bash
45
46
  npm install -g @artilingo/artiframe-cli
46
47
  ```
48
+ *(Kurulum sonrasında işletim sisteminize uygun global Workspace dizini otomatik olarak oluşturulacaktır.)*
47
49
 
48
50
  ### Kullanım
49
51
 
50
52
  ```bash
51
- # İnteraktif kabuk açar
53
+ # Grafik Arayüzlü Kontrol Merkezini Aç (YENİ!)
54
+ artiframe devops
55
+
56
+ # İnteraktif CLI Kabuğunu Aç
52
57
  artiframe
53
58
 
54
59
  # Yeni proje oluştur
55
60
  artiframe> new benim-projem
56
61
 
57
- # View oluştur
58
- artiframe> make:view admin/kullanicilar.php
62
+ # Veritabanını SQL olarak dışa aktar (Veri + Şema)
63
+ artiframe> db:export within
59
64
 
60
- # API endpoint oluştur
65
+ # View veya API oluştur
66
+ artiframe> make:view admin/kullanicilar.php
61
67
  artiframe> make:api standart api/auth/giris.php
62
-
63
- # Sürüm güncelle
64
- artiframe> version upgrade minor
65
68
  ```
66
69
 
67
70
  ---
68
71
 
69
72
  ## 🇬🇧 English
70
73
 
71
- **ArtiFrame** is a modern web development framework for native PHP, built on a zero external dependency philosophy. It offers a security-first, CLI-driven ecosystem free from Composer package chaos.
74
+ **ArtiFrame 3.0** is no longer just a framework for native PHP—it's a complete **development ecosystem**. Staying true to its zero external dependency philosophy, it now ships with massive graphical interfaces including DevOps Studio (GUI), DB Studio (Global ER Designer), and Server Studio (Live Log Monitor).
72
75
 
73
- ### Features
76
+ ### New in v3.0 (The Studio Update)
74
77
 
75
- - 🚫 **Zero Dependencies** — No Composer packages needed, every line of code is yours
76
- - 🛡️ **Security First** — XSS, CSRF, SQL Injection protection built-in by default
77
- - **Quick Setup** — Complete project skeleton with a single command
78
- - 🌍 **5 Language Support** — TR · EN · DE · FR · ES
79
- - 📐 **Strict Ruleset** — `data-js` architecture, dual bootstrapper model, consistent directory structure
78
+ - 🎨 **DevOps Studio** — Built-in desktop GUI launched via `artiframe devops`. Manage API Inspections, Cron jobs, Supervisor configs, and Env optimization visually!
79
+ - 🗄️ **DB Studio** — Drag and drop database schema designer. Sync schemas directly into your active project via `db:onproject`.
80
+ - 🌐 **Server Studio** — Launch your project instantly with `artiframe serve` and monitor HTTP requests live via the gateway logger.
81
+ - 📦 **Global Workspace** — Projects are now securely sandboxed in a global workspace directory (`C:\ArtiFrame` or `~/ArtiFrame`).
82
+ - 🚀 **Version & Package Manager** — Built-in `version upgrade` and `add <package>` commands to survive without Composer.
83
+ - 🚫 **Zero Dependencies** — Security (XSS, CSRF) and architectural foundations are still purely native PHP.
80
84
 
81
85
  ### Installation
82
86
 
83
- > Requires PHP 8.1 or higher.
87
+ > Requires Node.js and PHP 8.1+.
84
88
 
85
89
  ```bash
86
90
  npm install -g @artilingo/artiframe-cli
87
91
  ```
92
+ *(Your global Workspace directory will be automatically generated post-installation.)*
88
93
 
89
94
  ### Usage
90
95
 
91
96
  ```bash
92
- # Opens the interactive shell
97
+ # Launch the Graphical Control Center (NEW!)
98
+ artiframe devops
99
+
100
+ # Open interactive CLI shell
93
101
  artiframe
94
102
 
95
103
  # Create a new project
96
104
  artiframe> new my-project
97
105
 
98
- # Generate a view
99
- artiframe> make:view admin/users.php
106
+ # Export database to SQL (Data + Schema)
107
+ artiframe> db:export within
100
108
 
101
- # Generate an API endpoint
109
+ # Generate a view or API
110
+ artiframe> make:view admin/users.php
102
111
  artiframe> make:api standart api/auth/login.php
103
-
104
- # Update version
105
- artiframe> version upgrade minor
106
112
  ```
107
113
 
108
114
  ---
109
115
 
110
116
  ## 🇩🇪 Deutsch
111
117
 
112
- **ArtiFrame** ist ein modernes Web-Entwicklungs-Framework für natives PHP, das auf einer Philosophie ohne externe Abhängigkeiten aufgebaut ist. Es bietet ein sicherheitsorientiertes, CLI-gesteuertes Ökosystem, frei von Composer-Paketchaos.
113
-
114
- ### Funktionen
118
+ **ArtiFrame 3.0** ist nicht mehr nur ein Framework für natives PHP es ist ein komplettes **Entwicklungsökosystem**. Es bleibt seiner Philosophie (Null externe Abhängigkeiten) treu und wird nun mit grafischen Schnittstellen wie DevOps Studio (GUI), DB Studio (Global ER Designer) und Server Studio (Live Log Monitor) ausgeliefert.
115
119
 
116
- - 🚫 **Null Abhängigkeiten** Keine Composer-Pakete erforderlich, jede Codezeile gehört Ihnen
117
- - 🛡️ **Sicherheit zuerst** — XSS, CSRF, SQL-Injection-Schutz standardmäßig integriert
118
- - ⚡ **Schnelle Einrichtung** — Vollständiges Projektskelett mit einem einzigen Befehl
119
- - 🌍 **5 Sprachunterstützung** — TR · EN · DE · FR · ES
120
- - 📐 **Striktes Regelwerk** — `data-js`-Architektur, duales Bootstrapper-Modell, konsistente Verzeichnisstruktur
121
-
122
- ### Installation
120
+ ### Neu in v3.0 (Das Studio-Update)
123
121
 
124
- > Erfordert PHP 8.1 oder höher.
122
+ - 🎨 **DevOps Studio** Integrierte Desktop-GUI, die über `artiframe devops` gestartet wird (API-Inspektor, Cron-Designer, Env-Optimierung).
123
+ - 🗄️ **DB Studio** — Drag & Drop Datenbank-Schema-Designer.
124
+ - 🌐 **Server Studio** — Überwachen Sie HTTP-Anfragen live via `artiframe serve`.
125
+ - 📦 **Global Workspace** — Projekte leben nun sicher in einem globalen Verzeichnis (`C:\ArtiFrame` oder `~/ArtiFrame`).
125
126
 
127
+ ### Installation & Verwendung
126
128
  ```bash
127
129
  npm install -g @artilingo/artiframe-cli
128
- ```
129
-
130
- ### Verwendung
131
-
132
- ```bash
133
- # Öffnet die interaktive Shell
134
- artiframe
135
130
 
136
- # Neues Projekt erstellen
137
- artiframe> new mein-projekt
138
-
139
- # View erstellen
140
- artiframe> make:view admin/benutzer.php
141
-
142
- # API-Endpunkt erstellen
143
- artiframe> make:api standart api/auth/anmelden.php
144
-
145
- # Version aktualisieren
146
- artiframe> version upgrade minor
131
+ # GUI Starten
132
+ artiframe devops
147
133
  ```
148
134
 
149
135
  ---
150
136
 
151
137
  ## 🇫🇷 Français
152
138
 
153
- **ArtiFrame** est un framework de développement web moderne pour PHP natif, construit sur une philosophie zéro dépendance externe. Il offre un écosystème axé sur la sécurité et piloté par CLI, sans le chaos des paquets Composer.
139
+ **ArtiFrame 3.0** n'est plus seulement un framework, c'est un **écosystème de développement** complet. Il est désormais livré avec des interfaces graphiques massives : DevOps Studio (GUI), DB Studio (Global ER Designer) et Server Studio (Live Log Monitor).
154
140
 
155
- ### Fonctionnalités
141
+ ### Nouveautés v3.0 (La mise à jour Studio)
156
142
 
157
- - 🚫 **Zéro Dépendance** — Aucun paquet Composer nécessaire, chaque ligne de code vous appartient
158
- - 🛡️ **La Sécurité d'Abord** — Protection XSS, CSRF, injection SQL intégrée par défaut
159
- - **Configuration Rapide** — Squelette de projet complet en une seule commande
160
- - 🌍 **Support 5 Langues** — TR · EN · DE · FR · ES
161
- - 📐 **Règles Strictes** — Architecture `data-js`, modèle double bootstrapper, structure de répertoires cohérente
162
-
163
- ### Installation
164
-
165
- > Nécessite PHP 8.1 ou supérieur.
143
+ - 🎨 **DevOps Studio** — GUI bureau intégrée lancée via `artiframe devops`.
144
+ - 🗄️ **DB Studio** — Concepteur de schéma de base de données par glisser-déposer.
145
+ - 🌐 **Server Studio** — Serveur HTTP intégré avec journalisation en direct (`artiframe serve`).
146
+ - 📦 **Espace de Travail** — Les projets sont désormais isolés dans un répertoire global (`C:\ArtiFrame` ou `~/ArtiFrame`).
166
147
 
148
+ ### Installation & Utilisation
167
149
  ```bash
168
150
  npm install -g @artilingo/artiframe-cli
169
- ```
170
-
171
- ### Utilisation
172
-
173
- ```bash
174
- # Ouvre le shell interactif
175
- artiframe
176
-
177
- # Créer un nouveau projet
178
- artiframe> new mon-projet
179
-
180
- # Générer une vue
181
- artiframe> make:view admin/utilisateurs.php
182
151
 
183
- # Générer un endpoint API
184
- artiframe> make:api standart api/auth/connexion.php
185
-
186
- # Mettre à jour la version
187
- artiframe> version upgrade minor
152
+ # Lancer la GUI
153
+ artiframe devops
188
154
  ```
189
155
 
190
156
  ---
191
157
 
192
158
  ## 🇪🇸 Español
193
159
 
194
- **ArtiFrame** es un framework de desarrollo web moderno para PHP nativo, construido sobre una filosofía de cero dependencias externas. Ofrece un ecosistema orientado a la seguridad y guiado por CLI, libre del caos de paquetes Composer.
195
-
196
- ### Características
160
+ **ArtiFrame 3.0** ya no es solo un framework, es un **ecosistema de desarrollo** completo. Ahora incluye interfaces gráficas masivas: DevOps Studio (GUI), DB Studio (Global ER Designer) y Server Studio (Live Log Monitor).
197
161
 
198
- - 🚫 **Cero Dependencias** Sin paquetes Composer, cada línea de código es tuya
199
- - 🛡️ **Seguridad Primero** — Protección XSS, CSRF, inyección SQL integrada por defecto
200
- - ⚡ **Configuración Rápida** — Esqueleto de proyecto completo con un solo comando
201
- - 🌍 **Soporte 5 Idiomas** — TR · EN · DE · FR · ES
202
- - 📐 **Reglas Estrictas** — Arquitectura `data-js`, modelo dual de bootstrapper, estructura de directorios consistente
162
+ ### Novedades en v3.0 (La actualización Studio)
203
163
 
204
- ### Instalación
205
-
206
- > Requiere PHP 8.1 o superior.
164
+ - 🎨 **DevOps Studio** — GUI de escritorio integrada lanzada mediante `artiframe devops`.
165
+ - 🗄️ **DB Studio** — Diseñador visual de esquemas de bases de datos.
166
+ - 🌐 **Server Studio** Servidor HTTP integrado con monitor en vivo (`artiframe serve`).
167
+ - 📦 **Espacio de Trabajo** — Los proyectos ahora residen en un directorio global (`C:\ArtiFrame` o `~/ArtiFrame`).
207
168
 
169
+ ### Instalación y Uso
208
170
  ```bash
209
171
  npm install -g @artilingo/artiframe-cli
210
- ```
211
-
212
- ### Uso
213
-
214
- ```bash
215
- # Abre el shell interactivo
216
- artiframe
217
-
218
- # Crear un nuevo proyecto
219
- artiframe> new mi-proyecto
220
-
221
- # Generar una vista
222
- artiframe> make:view admin/usuarios.php
223
-
224
- # Generar un endpoint API
225
- artiframe> make:api standart api/auth/login.php
226
172
 
227
- # Actualizar la versión
228
- artiframe> version upgrade minor
173
+ # Iniciar la GUI
174
+ artiframe devops
229
175
  ```
230
176
 
231
177
  ---
package/bin/artiframe.js CHANGED
File without changes
package/bin/artiframe.php CHANGED
File without changes
@@ -0,0 +1,76 @@
1
+ <?php
2
+ /**
3
+ * ArtiFrame Core Engine
4
+ *
5
+ * @package ArtiFrame
6
+ * @author Artilingo
7
+ * @license AGPLv3 (Attribution-ShareAlike Required)
8
+ */
9
+
10
+ require_once __DIR__ . '/../vendor/autoload.php';
11
+
12
+ // 1. Ortam değişkenlerini yükle (.env)
13
+ \App\DotEnv::load(__DIR__ . '/../.env');
14
+
15
+ // 2. Uygulama sabitlerini yükle (APP_ENV, APP_VERSION)
16
+ require_once __DIR__ . '/../config/app-version.php';
17
+
18
+ // 3. Sadece API'ye özgü metodları yükle
19
+ require_once __DIR__ . '/../bin/SystemMethod.php';
20
+
21
+ // 4. API Konfigürasyonları (JSON Response Header vs.)
22
+ header('Content-Type: application/json; charset=utf-8');
23
+
24
+ // 5. İzin Verilen HTTP Metodlarının Kontrolü
25
+ $allowed = isset($allowedMethods) && is_array($allowedMethods) ? $allowedMethods : ['POST'];
26
+ $requestMethod = $_SERVER['REQUEST_METHOD'] ?? 'UNKNOWN';
27
+
28
+ if ($requestMethod === 'OPTIONS') {
29
+ http_response_code(200);
30
+ exit;
31
+ }
32
+
33
+ if (!in_array($requestMethod, $allowed)) {
34
+ http_response_code(405);
35
+ echo json_encode([
36
+ 'status' => 'error',
37
+ 'message' => "Geçersiz istek metodu. Sadece " . implode(', ', $allowed) . " kabul edilir."
38
+ ]);
39
+ exit;
40
+ }
41
+
42
+ // NOT: Bu dosya (ApiAuthControl), sadece Auth (Giriş/Kayıt) işlemleri içindir.
43
+ // İleride ApiControl.php dosyasına RBAC veya Oturum kontrolleri eklense bile,
44
+ // buraya giriş yapmamış (guest) kullanıcıların istek atabilmesi için
45
+ // oturum engeli KOYULMAMALIDIR.
46
+
47
+ // 6. Rate Limiting (Kaba Kuvvet ve Spam Koruması)
48
+ // Aynı IP'den saniyede maksimum 1 istek atılmasına izin verilir.
49
+ $ip = $_SERVER['REMOTE_ADDR'] ?? 'unknown';
50
+ $rateKey = 'auth_rate_limit:' . $ip;
51
+ $limit = 1;
52
+
53
+ try {
54
+ $redis = \Src\Service\RedisService::getInstance();
55
+ $currentCount = $redis->get($rateKey);
56
+
57
+ if ($currentCount !== false && $currentCount >= $limit) {
58
+ http_response_code(429); // Too Many Requests
59
+ echo json_encode([
60
+ 'status' => 'error',
61
+ 'message' => 'Lütfen yavaşlayın. Çok sık istek gönderiyorsunuz.'
62
+ ]);
63
+ exit;
64
+ }
65
+
66
+ $redis->incr($rateKey);
67
+
68
+ // Eğer anahtar ilk defa oluşturuluyorsa ömrünü 1 saniye olarak belirle
69
+ if ($currentCount === false || $currentCount == 0) {
70
+ $redis->expire($rateKey, 1);
71
+ }
72
+ } catch (\Exception $e) {
73
+ // Redis'e ulaşılamazsa (sunucu çökmesi vs.) kayıt olma akışını tamamen durdurmak yerine
74
+ // loglanabilir veya sessizce pas geçilebilir.
75
+ error_log("Redis Bağlantı Hatası (Rate Limit Aşıldı): " . $e->getMessage());
76
+ }
@@ -18,15 +18,26 @@ require_once __DIR__ . '/../config/app-version.php';
18
18
  // 3. Sadece API'ye özgü metodları yükle
19
19
  require_once __DIR__ . '/../bin/SystemMethod.php';
20
20
 
21
- // 4. API Konfigürasyonları (JSON Response Header vs.)
21
+ // 4. Oturum (Session) Konfigürasyonları
22
+ if (session_status() === PHP_SESSION_NONE) {
23
+ session_start();
24
+ }
25
+
26
+ // Beni Hatırla Kontrolü
27
+ if (empty($_SESSION['kullaniciId']) && !empty($_COOKIE['remember_me'])) {
28
+ $rememberedIdHex = \Bin\SystemMethod::validateRememberMeCookie();
29
+ if ($rememberedIdHex) {
30
+ $_SESSION['kullaniciId'] = hex2bin($rememberedIdHex);
31
+ }
32
+ }
33
+
34
+ // 5. API Konfigürasyonları (JSON Response Header vs.)
22
35
  header('Content-Type: application/json; charset=utf-8');
23
36
 
24
- // 5. İzin Verilen HTTP Metodlarının Kontrolü
25
- // API uç noktalarında tanımlanan $allowedMethods dizisini baz alır. Tanımsızsa sadece POST kabul eder.
37
+ // 6. İzin Verilen HTTP Metodlarının Kontrolü
26
38
  $allowed = isset($allowedMethods) && is_array($allowedMethods) ? $allowedMethods : ['POST'];
27
39
  $requestMethod = $_SERVER['REQUEST_METHOD'] ?? 'UNKNOWN';
28
40
 
29
- // Preflight istekleri (OPTIONS) CORS için hayati öneme sahiptir, her halükarda 200 dönüp çıkış yapmasını sağlarız.
30
41
  if ($requestMethod === 'OPTIONS') {
31
42
  http_response_code(200);
32
43
  exit;
@@ -34,48 +45,83 @@ if ($requestMethod === 'OPTIONS') {
34
45
 
35
46
  if (!in_array($requestMethod, $allowed)) {
36
47
  http_response_code(405);
37
- echo json_encode([
38
- 'status' => 'error',
39
- 'message' => "Geçersiz istek metodu. Sadece " . implode(', ', $allowed) . " kabul edilir."
40
- ]);
48
+ echo json_encode(['status' => 'error', 'message' => "Geçersiz istek metodu. Sadece " . implode(', ', $allowed) . " kabul edilir."]);
41
49
  exit;
42
50
  }
43
51
 
44
- /*
52
+ // 7. Global CSRF Duvarı
53
+ if (in_array($requestMethod, ['POST', 'PUT', 'DELETE'])) {
54
+ // 1. Header'dan kontrol et (Fetch/Axios SPA uyumu)
55
+ $token = $_SERVER['HTTP_X_CSRF_TOKEN'] ?? '';
56
+
57
+ // 2. Eğer Header'da yoksa, JSON Body'den kontrol et
58
+ if (empty($token)) {
59
+ $input = json_decode(file_get_contents('php://input'), true);
60
+ if (is_array($input) && !empty($input['csrf_token'])) {
61
+ $token = $input['csrf_token'];
62
+ }
63
+ }
64
+
65
+ // 3. Eğer JSON'da da yoksa standart POST datasından kontrol et (Eski usül form)
66
+ if (empty($token)) {
67
+ $token = $_POST['csrf_token'] ?? '';
68
+ }
69
+
70
+ if (!\Bin\SystemMethod::verifyCsrf($token)) {
71
+ http_response_code(403);
72
+ echo json_encode([
73
+ 'status' => 'error',
74
+ 'message' => 'CSRF doğrulaması başarısız. Lütfen sayfayı yenileyip tekrar deneyin.'
75
+ ]);
76
+ exit;
77
+ }
78
+ }
79
+
80
+ // 8. CORS (Cross-Origin Resource Sharing) Kuralları
81
+ // Geliştirme aşamasında her yerden gelen isteklere izin ver
82
+ if ($_ENV['APP_ENV'] === 'development') {
83
+ header('Access-Control-Allow-Origin: *');
84
+ } else {
85
+ // Canlı ortamda sadece belirlenen adreslere izin ver
86
+ header('Access-Control-Allow-Origin: https://senindomainin.com');
87
+ }
88
+
89
+ /*
45
90
  // -------------------------------------------------------------------------
46
- // 6. CORS (Cross-Origin Resource Sharing) Kuralları
91
+ // 8. Auth Guard (Oturum Kalkanı - API İçin)
47
92
  // -------------------------------------------------------------------------
48
- // Başka domainlerden veya mobil uygulamalardan gelen API isteklerini kabul
49
- // etmek isterseniz aşağıdaki satırları aktifleştirin. "*" yerine kendi
50
- // domaininizi (örn: "https://artilingo.com") yazarak güvenliği artırabilirsiniz.
93
+ // Eğer bu API noktasının (endpoint) ZORUNLU olarak giriş yapmış üyelere
94
+ // açık olmasını istiyorsanız aşağıdaki bloğu kullanabilirsiniz.
95
+ // Not: Auth. işlem yapmayan tüm özel (private) API'ler için önerilir.
51
96
 
52
- header("Access-Control-Allow-Origin: *");
53
- header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE");
54
- header("Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With");
97
+ if (empty($_SESSION['kullaniciId']) && empty($_SESSION['kullanici_id'])) {
98
+ http_response_code(401);
99
+ echo json_encode([
100
+ 'status' => 'error',
101
+ 'message' => 'Bu işlemi yapabilmek için giriş yapmalısınız.'
102
+ ]);
103
+ exit;
104
+ }
55
105
  */
56
106
 
57
107
  /*
58
108
  // -------------------------------------------------------------------------
59
- // 7. Rate Limiting (Basit IP Tabanlı Hız Sınırlandırma - Redis Örneği)
109
+ // 9. RBAC (Rol Bazlı Erişim Kontrolü - API İçin)
60
110
  // -------------------------------------------------------------------------
61
- // Kötü niyetli kişilerin veya botların API'nizi flood etmesini engeller.
62
- // Redis servisinizi aktif ettiyseniz bu bloğu kullanabilirsiniz.
63
- // Aşağıdaki örnekte, aynı IP adresinin 1 dakikada 60'tan fazla istek yapması engellenir.
64
-
65
- $ip = $_SERVER['REMOTE_ADDR'] ?? 'unknown';
66
- $rateKey = 'rate_limit:' . $ip;
67
- $limit = 60; // 1 dakikadaki maksimum istek sayısı
68
- $redis = \Src\Service\RedisService::getInstance();
69
-
70
- $currentCount = $redis->get($rateKey);
71
- if ($currentCount !== null && $currentCount >= $limit) {
72
- http_response_code(429); // 429 Too Many Requests
73
- echo json_encode(['status' => 'error', 'message' => 'Çok fazla istek gönderdiniz. Lütfen daha sonra tekrar deneyin.']);
74
- exit;
75
- }
111
+ // Belirli bir API işleminin (örn: ürün silme) sadece Admin veya yetkili
112
+ // roller tarafından yapılmasını sağlamak için.
113
+ // API dosyanızın en tepesinde $allowedRoles = [1]; şeklinde tanımlayabilirsiniz.
76
114
 
77
- $redis->incr($rateKey);
78
- if ($currentCount === null) {
79
- $redis->expire($rateKey, 60); // Sayacı 60 saniye sonra sıfırla
115
+ if (isset($allowedRoles) && is_array($allowedRoles)) {
116
+ $userRole = $_SESSION['rol'] ?? 3; // Örn: 1=Admin, 2=Mod, 3=User
117
+
118
+ if (!in_array($userRole, $allowedRoles)) {
119
+ http_response_code(403);
120
+ echo json_encode([
121
+ 'status' => 'error',
122
+ 'message' => 'Bu işlem için yeterli yetkiniz bulunmuyor.'
123
+ ]);
124
+ exit;
125
+ }
80
126
  }
81
127
  */
@@ -0,0 +1,39 @@
1
+ <?php
2
+ /**
3
+ * ArtiFrame Auth Engine (Guest Only)
4
+ *
5
+ * @package ArtiFrame
6
+ * @author Artilingo
7
+ * @license AGPLv3 (Attribution-ShareAlike Required)
8
+ */
9
+
10
+ require_once __DIR__ . '/../vendor/autoload.php';
11
+
12
+ // 1. Ortam değişkenlerini yükle (.env)
13
+ \App\DotEnv::load(__DIR__ . '/../.env');
14
+
15
+ // 2. Uygulama sabitlerini yükle (APP_ENV, APP_VERSION)
16
+ require_once __DIR__ . '/../config/app-version.php';
17
+
18
+ // 3. Sadece View'a özgü metodları yükle
19
+ require_once __DIR__ . '/../bin/ViewMethod.php';
20
+
21
+ // 4. Oturum (Session) Başlatma
22
+ if (session_status() === PHP_SESSION_NONE) {
23
+ session_start();
24
+ }
25
+
26
+ // Beni Hatırla Kontrolü
27
+ if (empty($_SESSION['kullaniciId']) && !empty($_COOKIE['remember_me'])) {
28
+ $rememberedIdHex = \Bin\SystemMethod::validateRememberMeCookie();
29
+ if ($rememberedIdHex) {
30
+ $_SESSION['kullaniciId'] = hex2bin($rememberedIdHex);
31
+ }
32
+ }
33
+
34
+ // 5. Ziyaretçi (Guest) Kontrolü
35
+ // Kullanıcı zaten giriş yapmışsa Auth sayfalarına (kayıt, giriş) giremez, yönlendirilir.
36
+ if (isset($_SESSION['kullaniciId']) || isset($_SESSION['kullanici_id'])) {
37
+ header("Location: /");
38
+ exit;
39
+ }
@@ -5,11 +5,6 @@
5
5
  * @package ArtiFrame
6
6
  * @author Artilingo
7
7
  * @license AGPLv3 (Attribution-ShareAlike Required)
8
- * @link https://artiframe.artilingo.com
9
- *
10
- * NOTICE: This file is part of the ArtiFrame ecosystem.
11
- * Any derivative works or patches MUST retain this original copyright notice
12
- * and remain open-source under the AGPLv3 license.
13
8
  */
14
9
 
15
10
  namespace App;
@@ -22,48 +17,54 @@ class Database
22
17
  private static ?PDO $instance = null;
23
18
 
24
19
  private function __construct() {}
20
+
25
21
  private function __clone() {}
26
22
 
27
23
  public static function getInstance(): PDO
28
24
  {
29
25
  if (self::$instance === null) {
30
-
31
- // .env henüz yüklenmediyse tam ve temiz yoldan otomatik yükle
32
- if (empty($_ENV['DB_HOST'])) {
33
- // src/ katmanından bir üst klasöre (htdocs köküne) direkt geçiş:
34
- $envPath = dirname(__DIR__) . '/.env';
35
- DotEnv::load($envPath);
26
+ $host = $_ENV['DB_HOST'] ?? '127.0.0.1';
27
+ $name = $_ENV['DB_NAME'] ?? 'artiframe';
28
+ $user = $_ENV['DB_USER'] ?? 'root';
29
+ $pass = $_ENV['DB_PASSWORD'] ?? '';
30
+ $port = $_ENV['DB_PORT'] ?? 3306;
31
+
32
+ // Eğer veritabanı adı veya kullanıcı boşsa, veritabanı henüz kurulmamış olabilir.
33
+ if (empty($name) || empty($user)) {
34
+ die("Veritabanı bağlantı bilgileri eksik. Lütfen .env dosyasını kontrol edin.");
36
35
  }
37
36
 
38
- $host = $_ENV['DB_HOST'] ?? 'localhost';
39
- $dbname = $_ENV['DB_NAME'] ?? 'portfobase';
40
- $user = $_ENV['DB_USER'] ?? 'root';
41
- $pass = $_ENV['DB_PASS'] ?? '';
42
-
43
- $dsn = sprintf("mysql:host=%s;dbname=%s;charset=utf8mb4", $host, $dbname);
44
-
45
- $options = [
46
- PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
47
- PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
48
- PDO::ATTR_EMULATE_PREPARES => false,
49
- ];
50
-
51
37
  try {
52
- self::$instance = new PDO($dsn, $user, $pass, $options);
38
+ $dsn = "mysql:host={$host};port={$port};dbname={$name};charset=utf8mb4";
39
+ self::$instance = new PDO($dsn, $user, $pass, [
40
+ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
41
+ PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
42
+ PDO::ATTR_EMULATE_PREPARES => false,
43
+ ]);
53
44
  } catch (PDOException $e) {
54
- $isDev = (defined('APP_ENV') && APP_ENV == 1);
55
-
56
- $msg = !$isDev
57
- ? 'Veritabanı bağlantı hatası. Sistem yöneticisi ile görüşün.'
58
- : 'Veritabanı Hatası (Dev Mod): ' . $e->getMessage();
59
-
60
- header('Content-Type: application/json; charset=utf-8');
61
- http_response_code(500);
62
- echo json_encode(['success' => false, 'message' => $msg]);
63
- exit;
45
+ die("Veritabanı bağlantı hatası: " . $e->getMessage());
64
46
  }
65
47
  }
66
48
 
67
49
  return self::$instance;
68
50
  }
51
+
52
+ /**
53
+ * Long-running worker'lar için veritabanı bağlantısının
54
+ * düşüp düşmediğini kontrol eder, düşmüşse yeniden bağlanır.
55
+ */
56
+ public static function ping(): void
57
+ {
58
+ if (self::$instance !== null) {
59
+ try {
60
+ self::$instance->query('SELECT 1');
61
+ } catch (PDOException $e) {
62
+ $msg = strtolower($e->getMessage());
63
+ if (strpos($msg, 'gone away') !== false || strpos($msg, 'lost connection') !== false) {
64
+ self::$instance = null;
65
+ self::getInstance();
66
+ }
67
+ }
68
+ }
69
+ }
69
70
  }