-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjadmin_functions.php
More file actions
265 lines (215 loc) · 4.75 KB
/
Copy pathjadmin_functions.php
File metadata and controls
265 lines (215 loc) · 4.75 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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
<?php
/*
Functions
*/
/*
* Name:
* get_client( $ID )
*
* Args:
* ID: Client ID
*
* Return:
* Array with client information.
*/
function get_client( $ID ){
global $wpdb;
$table = $wpdb->prefix.'clients';
$query = "SELECT * FROM $table WHERE ID = %d;";
$client = $wpdb->get_row( $wpdb->prepare($query, $ID) );
return $client;
}
function get_clients(){
global $wpdb;
$table = $wpdb->prefix.'clients';
$query = "SELECT * FROM $table ORDER BY ID DESC";
$clients = $wpdb->get_results( $wpdb->prepare($query) );
return $clients;
}
/*
* Name:
* get_domain( $ID )
*
* Args:
* ID: Domain ID
*
* Return:
* Array with domain information.
*/
function get_domain( $ID ){
global $wpdb;
$table = $wpdb->prefix.'domains';
$query = "SELECT * FROM $table WHERE ID = %d;";
$domain = $wpdb->get_row( $wpdb->prepare($query, $ID) );
return $domain;
}
function get_domains(){
global $wpdb;
$table = $wpdb->prefix.'domains';
$query = "SELECT * FROM $table ORDER BY ID DESC";
$domains = $wpdb->get_results( $wpdb->prepare($query) );
return $domains;
}
function get_linode_domains(){
$settings = get_option( 'jadmin_settings' );
if( $settings['linode_key'] != '' ):
require_once('Services/Linode.php');
try {
$linode = new Services_Linode($settings['linode_key']);
$linode = $linode->domain_list();
$domains = $linode['DATA'];
} catch (Services_Linode_Exception $e) {
echo $e->getMessage();
}
return $domains;
endif;
}
/*
* Name:
* get_database( $ID )
*
* Args:
* ID: Database ID
*
* Return:
* Array with database information.
*/
function get_database( $ID ){
global $wpdb;
$table = $wpdb->prefix.'databases';
$query = "SELECT * FROM $table WHERE ID = %d;";
$database = $wpdb->get_row( $wpdb->prepare($query, $ID) );
return $database;
}
function get_databases(){
global $wpdb;
$table = $wpdb->prefix.'databases';
$query = "SELECT * FROM $table ORDER BY ID DESC";
$databases = $wpdb->get_results( $wpdb->prepare($query) );
return $databases;
}
function get_database_by_domain( $ID ){
global $wpdb;
$table = $wpdb->prefix.'databases';
$query = "SELECT * FROM $table WHERE domain_id = %d;";
$database = $wpdb->get_row( $wpdb->prepare($query, $ID) );
return $database;
}
function get_projects(){
global $wpdb;
$table = $wpdb->prefix.'projects';
$query = "SELECT * FROM $table ORDER BY ID DESC";
$projects = $wpdb->get_results( $wpdb->prepare($query) );
return $projects;
}
function get_project($ID){
global $wpdb;
$table = $wpdb->prefix.'projects';
$query = "SELECT * FROM $table WHERE ID = %d;";
return $wpdb->get_row( $wpdb->prepare($query, $ID) );
}
function get_projects_by_url($url){
global $wpdb;
$table = $wpdb->prefix.'projects';
$query = "SELECT * FROM $table WHERE url = %s;";
return $wpdb->get_results( $wpdb->prepare($query, $url) );
}
/*
* Name:
* has_domains( $ID )
*
* Args:
* ID: Client ID
*
* Return:
* Boolean: True if has domains or False if doesn't.
*/
function has_domains( $ID ){
global $wpdb;
$table = $wpdb->prefix.'domains';
$query = "SELECT COUNT(*) FROM $table WHERE client_id = %d;";
$result = $wpdb->get_var( $wpdb->prepare($query, $ID) );
if( $result > 0 )
return TRUE;
else
return FALSE;
}
/*
* Name:
* get_domains_count( $ID )
*
* Args:
* ID: Client ID
*
* Return:
* Integer: Count of domains.
*/
function get_domains_count( $ID ){
global $wpdb;
$table = $wpdb->prefix.'domains';
$query = "SELECT COUNT(*) FROM $table WHERE client_id = %d;";
$result = $wpdb->get_var( $wpdb->prepare($query, $ID) );
if( $result == NULL )
return 0;
else
return $result;
}
/*
* Name:
* get_linode_domain_name( $ID )
*
* Args:
* ID: Linode Domain ID
*
* Return:
* String: Domain name from Linode.
*/
function get_linode_domain_name( $ID ){
$settings = get_option( 'jadmin_settings' );
require_once('Services/Linode.php');
try {
$linode = new Services_Linode($settings['linode_key']);
$linode = $linode->domain_list(
array(
'DomainID' => $ID
)
);
$name = $linode['DATA'][0]['DOMAIN'];
} catch (Services_Linode_Exception $e) {
echo $e->getMessage();
}
return $name;
}
function update_git($ID){
$project = get_project($ID);
$exec = 'cd '.$project->location.' && env GIT_SSL_NO_VERIFY=true git pull';
return shell_exec($exec);
}
function update_plugin(){
$exec = 'cd '.BASEPATH.'&& git pull';
return shell_exec( $exec );
}
/*
* Name:
* get_data( $url )
*
* Args:
* url: URL you want to get data from.
*
* Return:
* String: URL Data.
*/
function get_data( $url ){
$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
function restart_apache(){
return shell_exec('/etc/init.d/apache2 reload');
}
?>