-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcloudflaremanager.php
More file actions
212 lines (196 loc) · 7.16 KB
/
cloudflaremanager.php
File metadata and controls
212 lines (196 loc) · 7.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<?php
/**
* Cloudflare Manager - WHMCS Addon Module
* Professional Cloudflare Domain and DNS Management Module
*
* @package WHMCS
* @author Ali Çömez / Slaweally
* @copyright Copyright (c) 2025, Megabre.com
* @version 2.0.0
* @link https://github.com/megabre
*/
if (!defined("WHMCS")) {
die("This file cannot be accessed directly");
}
use WHMCS\Database\Capsule;
/**
* Module Configuration
*/
function cloudflaremanager_config() {
return [
"name" => "Cloudflare Manager",
"description" => "Professional Cloudflare domain and DNS management module with registrar support",
"version" => "2.0.0",
"author" => "Ali Çömez / Slaweally",
"language" => "turkish",
"fields" => [
"api_email" => [
"FriendlyName" => "Cloudflare Email",
"Type" => "text",
"Size" => "40",
"Description" => "Your Cloudflare account email (leave empty if using API Token)",
"Default" => "",
"Required" => false,
],
"api_key" => [
"FriendlyName" => "API Key / Token",
"Type" => "password",
"Size" => "40",
"Description" => "Your Cloudflare Global API Key or API Token",
"Default" => "",
"Required" => true,
],
"client_permissions" => [
"FriendlyName" => "Client Permissions",
"Type" => "checkboxes",
"Options" => [
"view_domain_details" => "View Domain Details",
"view_dns_records" => "View DNS Records",
"edit_dns_records" => "Edit DNS Records",
"view_ssl_status" => "View SSL Status",
"view_cache_status" => "View Cache Status",
],
"Description" => "Select which features clients can access",
"Default" => "view_domain_details,view_dns_records",
],
"use_cache" => [
"FriendlyName" => "Enable API Cache",
"Type" => "yesno",
"Description" => "Cache API responses to improve performance",
"Default" => "yes",
],
"cache_expiry" => [
"FriendlyName" => "Cache Duration (seconds)",
"Type" => "text",
"Size" => "5",
"Description" => "How long to keep API cache (minimum 60 seconds)",
"Default" => "300",
],
],
];
}
/**
* Module Activation
*/
function cloudflaremanager_activate() {
try {
// Domains table
if (!Capsule::schema()->hasTable('mod_cloudflaremanager_domains')) {
Capsule::schema()->create('mod_cloudflaremanager_domains', function ($table) {
$table->increments('id');
$table->string('domain', 255);
$table->string('zone_id', 50)->unique();
$table->integer('client_id')->default(0);
$table->string('zone_status', 50)->nullable();
$table->dateTime('created_at');
$table->dateTime('updated_at');
$table->dateTime('expiry_date')->nullable();
$table->string('registrar', 100)->nullable();
$table->text('settings')->nullable();
$table->text('analytics')->nullable();
$table->index(['zone_id']);
$table->index(['client_id']);
$table->index(['domain']);
});
}
// DNS records table
if (!Capsule::schema()->hasTable('mod_cloudflaremanager_dns_records')) {
Capsule::schema()->create('mod_cloudflaremanager_dns_records', function ($table) {
$table->increments('id');
$table->integer('domain_id');
$table->string('record_id', 50);
$table->string('type', 10);
$table->string('name', 255);
$table->text('content');
$table->integer('ttl')->default(1);
$table->boolean('proxied')->default(false);
$table->integer('priority')->nullable();
$table->dateTime('created_at');
$table->dateTime('updated_at');
$table->index(['domain_id']);
$table->index(['record_id']);
$table->index(['type']);
});
}
// Cache table
if (!Capsule::schema()->hasTable('mod_cloudflaremanager_cache')) {
Capsule::schema()->create('mod_cloudflaremanager_cache', function ($table) {
$table->increments('id');
$table->string('cache_key', 255)->unique();
$table->longText('cache_value');
$table->dateTime('expires_at');
$table->dateTime('created_at');
$table->dateTime('updated_at')->nullable();
$table->index(['cache_key']);
$table->index(['expires_at']);
});
}
return [
'status' => 'success',
'description' => 'Cloudflare Manager module successfully activated.'
];
} catch (\Exception $e) {
return [
'status' => "error",
'description' => 'Could not create database tables: ' . $e->getMessage(),
];
}
}
/**
* Module Deactivation
*/
function cloudflaremanager_deactivate() {
return [
'status' => 'success',
'description' => 'Cloudflare Manager has been deactivated. Database tables were preserved.'
];
}
/**
* Module Upgrade
*/
function cloudflaremanager_upgrade($vars) {
$currentVersion = $vars['version'] ?? '1.0.0';
// Upgrade to version 2.0.0
if (version_compare($currentVersion, '2.0.0', '<')) {
try {
// Clear cache for fresh start
Capsule::table('mod_cloudflaremanager_cache')->truncate();
return [
'status' => 'success',
'description' => 'Cloudflare Manager successfully upgraded to version 2.0.0.'
];
} catch (\Exception $e) {
return [
'status' => 'error',
'description' => 'Error during upgrade: ' . $e->getMessage()
];
}
}
return [
'status' => 'success',
'description' => 'No upgrade required.'
];
}
/**
* Admin Panel Output
*/
function cloudflaremanager_output($vars) {
require_once __DIR__ . '/lib/CloudflareAPI.php';
require_once __DIR__ . '/lib/DomainManager.php';
require_once __DIR__ . '/lib/DNSManager.php';
require_once __DIR__ . '/lib/AjaxHandler.php';
require_once __DIR__ . '/lib/Admin.php';
$admin = new CloudflareManager\Admin($vars);
$admin->display();
}
/**
* Client Area Output
*/
function cloudflaremanager_clientarea($vars) {
require_once __DIR__ . '/lib/CloudflareAPI.php';
require_once __DIR__ . '/lib/DomainManager.php';
require_once __DIR__ . '/lib/DNSManager.php';
require_once __DIR__ . '/lib/Client.php';
$client = new CloudflareManager\Client($vars);
return $client->display();
}