403 ) ); } require_once __DIR__ . '/api_client.php'; $agis_account_name = current_account_name(); $agis_msg = ''; $agis_last_action_ok = null; $agis_request_method = isset( $_SERVER['REQUEST_METHOD'] ) ? strtoupper( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_METHOD'] ) ) ) : ''; // GET filters (whitelist + sanitize). $agis_get_status = isset( $_GET['status'] ) ? sanitize_text_field( wp_unslash( $_GET['status'] ) ) : ''; $agis_get_plan_raw = isset( $_GET['plan'] ) ? sanitize_text_field( wp_unslash( $_GET['plan'] ) ) : ''; $agis_get_unassigned = isset( $_GET['unassigned'] ) && '1' === sanitize_text_field( wp_unslash( $_GET['unassigned'] ) ); $agis_valid_statuses = array( '', 'new', 'active', 'inactive', 'revoked', 'expired' ); if ( ! in_array( $agis_get_status, $agis_valid_statuses, true ) ) { $agis_get_status = ''; } $agis_valid_plans = array( '', 'basic', 'pro', 'max', 'enterprise' ); $agis_get_plan = strtolower( $agis_get_plan_raw ); if ( ! in_array( $agis_get_plan, $agis_valid_plans, true ) ) { $agis_get_plan = ''; } // Handle POST actions: create / assign / deactivate / delete. if ( 'POST' === $agis_request_method && isset( $_POST['action'] ) ) { $agis_nonce_value = isset( $_POST['agis_licenses_nonce'] ) ? sanitize_text_field( wp_unslash( $_POST['agis_licenses_nonce'] ) ) : ''; if ( ! wp_verify_nonce( $agis_nonce_value, 'agis_licenses' ) ) { $agis_msg = __( 'Security check failed. Please try again.', 'ai-chat-by-agis' ); $agis_last_action_ok = false; } else { $agis_action = strtolower( trim( sanitize_text_field( wp_unslash( $_POST['action'] ) ) ) ); if ( 'create' === $agis_action ) { $agis_plan = isset( $_POST['plan'] ) ? strtolower( sanitize_text_field( wp_unslash( $_POST['plan'] ) ) ) : 'pro'; $agis_billing_cadence = isset( $_POST['billingCadence'] ) ? strtolower( sanitize_text_field( wp_unslash( $_POST['billingCadence'] ) ) ) : 'monthly'; $agis_owner_account_id = isset( $_POST['ownerAccountId'] ) ? sanitize_text_field( wp_unslash( $_POST['ownerAccountId'] ) ) : ''; if ( ! in_array( $agis_plan, array( 'basic', 'pro', 'max', 'enterprise' ), true ) ) { $agis_plan = 'pro'; } if ( ! in_array( $agis_billing_cadence, array( 'monthly', 'yearly' ), true ) ) { $agis_billing_cadence = 'monthly'; } $agis_payload = array( 'plan' => $agis_plan, 'billingCadence' => $agis_billing_cadence, ); if ( '' !== $agis_owner_account_id ) { $agis_payload['ownerAccountId'] = $agis_owner_account_id; } $agis_resp = api_call_json( 'https://jason5-dev.agis.ai:6081/api/licenses', 'POST', $agis_account_name, $agis_payload ); $agis_last_action_ok = ( ! $agis_resp['err'] && $agis_resp['http'] >= 200 && $agis_resp['http'] < 300 ); if ( $agis_resp['err'] ) { $agis_msg = 'Create license cURL error: ' . $agis_resp['err']; } else { $agis_msg = 'Create license: HTTP ' . (int) $agis_resp['http']; } } elseif ( 'assign' === $agis_action ) { $agis_license_key = isset( $_POST['licenseKey'] ) ? strtoupper( sanitize_text_field( wp_unslash( $_POST['licenseKey'] ) ) ) : ''; $agis_client_account = isset( $_POST['clientAccount'] ) ? sanitize_text_field( wp_unslash( $_POST['clientAccount'] ) ) : ''; $agis_domain = isset( $_POST['domain'] ) ? sanitize_text_field( wp_unslash( $_POST['domain'] ) ) : ''; $agis_resp = api_call_json( 'https://jason5-dev.agis.ai:6081/api/licenses/assign', 'POST', $agis_account_name, array( 'licenseKey' => $agis_license_key, 'clientAccount' => $agis_client_account, 'domain' => $agis_domain, ) ); $agis_last_action_ok = ( ! $agis_resp['err'] && $agis_resp['http'] >= 200 && $agis_resp['http'] < 300 ); if ( $agis_resp['err'] ) { $agis_msg = 'Assign cURL error: ' . $agis_resp['err']; } else { $agis_msg = 'Assign: HTTP ' . (int) $agis_resp['http']; } } elseif ( 'deactivate' === $agis_action ) { $agis_license_key = isset( $_POST['licenseKey'] ) ? strtoupper( sanitize_text_field( wp_unslash( $_POST['licenseKey'] ) ) ) : ''; $agis_clear_activation = isset( $_POST['clearActivation'] ) && '1' === sanitize_text_field( wp_unslash( $_POST['clearActivation'] ) ); $agis_payload = array( 'licenseKey' => $agis_license_key, ); if ( $agis_clear_activation ) { $agis_payload['clearActivation'] = true; } $agis_resp = api_call_json( 'https://jason5-dev.agis.ai:6081/api/licenses/deactivate', 'POST', $agis_account_name, $agis_payload ); $agis_last_action_ok = ( ! $agis_resp['err'] && $agis_resp['http'] >= 200 && $agis_resp['http'] < 300 ); if ( $agis_resp['err'] ) { $agis_msg = 'Deactivate cURL error: ' . $agis_resp['err']; } else { $agis_msg = 'Deactivate: HTTP ' . (int) $agis_resp['http']; } } elseif ( 'delete' === $agis_action ) { $agis_license_key = isset( $_POST['licenseKey'] ) ? strtoupper( sanitize_text_field( wp_unslash( $_POST['licenseKey'] ) ) ) : ''; $agis_resp = api_call_json( 'https://jason5-dev.agis.ai:6081/api/licenses/delete', 'POST', $agis_account_name, array( 'licenseKey' => $agis_license_key ) ); $agis_last_action_ok = ( ! $agis_resp['err'] && $agis_resp['http'] >= 200 && $agis_resp['http'] < 300 ); if ( $agis_resp['err'] ) { $agis_msg = 'Delete cURL error: ' . $agis_resp['err']; } else { $agis_msg = 'Delete: HTTP ' . (int) $agis_resp['http']; } } else { $agis_msg = 'Unknown action: ' . $agis_action; $agis_last_action_ok = false; } } } // Always fetch list. $agis_query = array( 'page' => '1', 'pageSize' => '200', ); if ( '' !== $agis_get_status ) { $agis_query['status'] = $agis_get_status; } if ( '' !== $agis_get_plan ) { $agis_query['plan'] = $agis_get_plan; } if ( $agis_get_unassigned ) { $agis_query['unassigned'] = '1'; } $agis_list_url = 'https://jason5-dev.agis.ai:6081/api/licenses?' . http_build_query( $agis_query ); $agis_list = api_call_json( $agis_list_url, 'GET', $agis_account_name, null ); $agis_rows = $agis_list['json']['rows'] ?? array(); $agis_total = $agis_list['json']['total'] ?? 0; /** * Format a date/time string for display. * * @param string $agis_datetime_string Raw datetime string. * @return string */ function agis_fmt_dt( $agis_datetime_string ) { if ( ! $agis_datetime_string ) { return ''; } try { $agis_dt = new DateTime( $agis_datetime_string ); return $agis_dt->format( 'Y-m-d H:i:s' ); } catch ( Exception $agis_exception ) { return $agis_datetime_string; } } ?> Licenses

Licenses

Account:

Create new license

Leave blank to create under your own account.

Filters

(reset)

Existing licenses

cURL error:
List licenses: HTTP
License Key Plan Status Pool Owner Assigned To Reserved / Activated Domain Starts Expires Last Validated Created Actions
reserved
active
(none)
Assigned — waiting activation
Activated