-
Notifications
You must be signed in to change notification settings - Fork 17
/
cyberpanel.php
142 lines (116 loc) · 4.44 KB
/
cyberpanel.php
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
<?php
/**
* Plugin Name: CyberPanel
* Plugin URI: https://cyberwp.cloud
* Description: Manage multiple CyberPanel installations via WordPress.
* Version: 1.0.0
* Requires at least: 5.2
* Requires PHP: 7.1
* Author: Usman Nasir
* Author URI: https://cyberwp.cloud
* License: GPL v2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('WPINC')) {
die("Please don't run via command line.");
}
define('CPWP_PLUGIN_DIR_URL', plugin_dir_url(__FILE__));
define('CPWP_PLUGIN_DIR', plugin_dir_path(__FILE__));
define('CPWP_ERROR_LOGS', CPWP_PLUGIN_DIR . 'error_log');
// Table names for CyberPanel
define('TN_CYBERPANEL_SERVERS', 'cyberpanel_servers');
define('TN_CYBERPANEL_JOBS', 'cyberpanel_jobs');
define('TN_CYBERPANEL_PVD', 'cyberpanel_providers');
/// Jobs Statues
define('WPCP_StartingJob', 0);
define('WPCP_JobFailed', 1);
define('WPCP_JobSuccess', 2);
define('WPCP_JobRunning', 3);
define('WPCP_ACTIVE', 1);
define('WPCP_SUSPENDED', 2);
define('WPCP_TERMINATED', 3);
define('WPCP_CANCELLED', 4);
## META VALUES
define('WPCP_PROVIDER', 'wpcp_provider');
define('WPCP_PROVIDERPLANS', 'wpcp_providerplans');
define('WPCP_DUEDATE', 'wpcp_duedate');
define('WPCP_ACTIVEINVOICE', 'wpcp_activeinvoice');
define('WPCP_ORDERID', 'wpcp_orderid');
define('WPCP_INTERVAL', 'P30D');
define('WPCP_PRODUCTID', 'wpcp_productid');
define('WPCP_INVOICE', 'wpcp_invoice');
define('WPCP_PAYMENTID', 'wpcp_paymentid');
define('WPCP_LOCATION', 'wpcp_location');
define('WPCP_PRODUCTNAME', 'wpcp_productname');
define('WPCP_AUTOSUSPEND', 'wpcp_auto_suspend');
define('WPCP_TERMINATE', 'wpcp_terminate');
define('WPCP_DATEFORMAT', 'Y-m-d H:i:s');
define('WPCP_STATE', 'wp_state');
define('WPCP_INVOICESERVER', 'wpcp_invoiceserver');
define('WPCP_TOKEN', 'wpcp_token');
define('WPCP_ORDER_PRICE', 'wpcp_order_price');
define('WPCP_CYBERPANEL_USER', 'wpcp_cyberpanel_user');
define('WPCP_SUB_ID', 'wpcp_sub_id');
// Email Templates Options
define('WPCP_NEW_SERVER', 'wpcp_new_server');
define('WPCP_SERVER_CANCELLED', 'wpcp_server_cancelled');
define('WPCP_SERVER_SUSPENDED', 'wpcp_server_suspended');
define('WPCP_SERVER_TERMINATED', 'wpcp_server_terminated');
require_once(CPWP_PLUGIN_DIR . 'main/functions.php');
// Create Table where Connected servers will be stored
register_activation_hook(__FILE__, 'wpcp_on_activation');
function wpcp_on_activation()
{
/**
* Check if WooCommerce is active
**/
if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
// Put your plugin code here
add_action( 'admin_notices', 'CyberPanel Plugin requires WooCommerce plugin.' );
die('CyberPanel Plugin requires WooCommerce plugin.');
}
global $wpdb;
/// Table that will contain details of currently queued jobs.
$table_name = $wpdb->prefix . TN_CYBERPANEL_JOBS;
$sql = "CREATE TABLE IF NOT EXISTS $table_name (
id mediumint(9) NOT NULL AUTO_INCREMENT,
userid mediumint(9) NOT NULL,
function varchar(50) DEFAULT '' NOT NULL,
description varchar(500) DEFAULT '' NOT NULL,
status mediumint(9) DEFAULT 0 NOT NULL,
percentage mediumint(9) DEFAULT 0,
token varchar(200) DEFAULT '' NOT NULL,
date datetime(6) DEFAULT NOW(),
PRIMARY KEY (id)
)";
$wpdb->query( $sql );
$table_name = $wpdb->prefix . TN_CYBERPANEL_PVD;
$sql = "CREATE TABLE IF NOT EXISTS $table_name (
id mediumint(9) NOT NULL AUTO_INCREMENT,
provider varchar(200) DEFAULT '' NOT NULL,
name varchar(200) DEFAULT '' NOT NULL,
apidetails varchar(800) DEFAULT '' NOT NULL,
PRIMARY KEY (id),
UNIQUE (name)
)";
$wpdb->query( $sql );
## Create Servers Page
$post_details = array(
'post_title' => 'Servers',
'post_content' => '<!-- wp:shortcode -->[wpcpservers]<!-- /wp:shortcode -->',
'post_status' => 'publish',
'post_author' => 1,
'post_type' => 'page'
);
wp_insert_post( $post_details );
}
register_deactivation_hook( __FILE__, 'wpcp_on_deactivation' );
function wpcp_on_deactivation()
{
//unregister_post_type( 'wpcp_server' );
//flush_rewrite_rules();
remove_filter( 'woocommerce_add_cart_item_data', 'wpcp_add_custom_field_item_data');
remove_filter( 'woocommerce_add_to_cart_validation', 'wpcp_validate_custom_field' );
remove_filter( 'the_content', 'filter_the_content_in_the_main_loop' );
remove_shortcode('wpcp_servers');
}