ftuzlu / forge-api
Laravel Forge API
Requires
- guzzlehttp/guzzle: ^7.8
README
这是一个与Laravel Forge API交互的PHP客户端库。它提供了一个方便的方式来管理Laravel Forge服务器的各个方面,例如备份、凭证、数据库、部署、防火墙规则、Git配置、监控、MySQL数据库、MySQL用户、Nginx模板等。
安装
使用Composer安装此包
composer require ftuzlu/forge-api
用法
初始化Forge客户端
use Fatihtuzlu\ForgeAPI\Forge; $forge = new Forge('YOUR_BEARER_TOKEN');
将YOUR_BEARER_TOKEN
替换为您实际的Forge APIBearer Token。
用户
use Fatihtuzlu\ForgeAPI\User; // Show user details $user = new User($forge); $userDetails = $user->show();
User
类提供了一个获取认证用户详细信息的方法。您可以使用它来获取诸如用户账户详情、订阅状态或任何其他相关的用户特定信息。
服务器
use Fatihtuzlu\ForgeAPI\Server; // Create Server $server = new Server($forge); $createdServer = $server->create($options); $servers = $server->list(); $serverId = 1; $specificServer = $server->get($serverId); $updatedServer = $server->update($serverId, $options); $server->delete($serverId);
服务
Service
类旨在处理对Forge API的HTTP请求。它扩展了ServiceAbstract
类,该类为处理API请求提供了一个基本结构。
服务类
构造函数
use Fatihtuzlu\ForgeAPI\Service; // Instantiate the Service class $service = new Service($forge); // Example: Sending a GET request $response = $service->sendReq('/api/v1/some-endpoint', 'GET');
防火墙
use Fatihtuzlu\ForgeAPI\Firewall; $firewall = new Firewall($forge); // Create a new firewall rule $newFirewallRule = $firewall->create($serverId, $options); // List firewall rules $firewallRules = $firewall->list($serverId); // Get details of a specific firewall rule $firewallRuleDetails = $firewall->get($serverId, $ruleId); // Delete a firewall rule $firewall->delete($serverId, $ruleId);
定时任务
ScheduledJob
类提供了管理Forge服务器上定时任务的方法。
构造函数
use Fatihtuzlu\ForgeAPI\ScheduledJob; use Fatihtuzlu\ForgeAPI\ScheduledJob; // Instantiate the ScheduledJob class by providing an instance of the Forge class $scheduledJob = new ScheduledJob($forge); // Example: Creating a new scheduled job $options = [ 'command' => 'php artisan my:command', 'user' => 'forge', 'frequency' => 'daily', 'hour' => 3, 'minute' => 30, ]; $response = $scheduledJob->create($serverId, $options); // Example: Listing all scheduled jobs on a server $jobs = $scheduledJob->list($serverId); // Example: Getting details of a specific scheduled job $jobId = 123; // Replace with the actual job ID $jobDetails = $scheduledJob->get($serverId, $jobId); // Example: Deleting a scheduled job $jobId = 123; // Replace with the actual job ID $scheduledJob->delete($serverId, $jobId);
PHP
PHP
类提供了管理Forge服务器上PHP配置的方法。
构造函数
use Fatihtuzlu\ForgeAPI\PHP; // Instantiate the PHP class by providing an instance of the Forge class $php = new PHP($forge); // Example: Listing PHP versions on a server $phpVersions = $php->list($serverId); // Example: Installing a PHP version $options = [ 'version' => 'php80', // Replace with the desired PHP version ]; $response = $php->install($serverId, $options); // Example: Upgrading PHP version $options = [ 'version' => 'php74', // Replace with the desired PHP version for upgrade ]; $response = $php->upgrade($serverId, $options); // Example: Enabling OPcache for PHP $response = $php->enable($serverId); // Example: Disabling OPcache for PHP $php->disable($serverId);
数据库
use Fatihtuzlu\ForgeAPI\Database; $database = new Database($forge); // List databases $databases = $database->list($serverId); // Create a new database $newDatabase = $database->create($serverId, $options); // Get details of a specific database $databaseDetails = $database->get($serverId, $databaseId); // Sync databases $database->sync($serverId); // Delete a database $database->delete($serverId, $databaseId);
MySQL数据库
MysqlDatabase
类提供了管理Forge服务器上MySQL数据库的方法。
构造函数
use Fatihtuzlu\ForgeAPI\MysqlDatabase; // Instantiate the MysqlDatabase class by providing an instance of the Forge class $mysqlDatabase = new MysqlDatabase($forge); // Example: Listing MySQL databases on a server $databases = $mysqlDatabase->list($serverId); // Example: Creating a new MySQL database $options = [ 'name' => 'example_database', // Replace with the desired database name ]; $response = $mysqlDatabase->create($serverId, $options); // Example: Getting details of a MySQL database $databaseId = 123; // Replace with the desired database ID $databaseDetails = $mysqlDatabase->get($serverId, $databaseId); // Example: Deleting a MySQL database $databaseId = 123; // Replace with the desired database ID $mysqlDatabase->delete($serverId, $databaseId);
MySQL数据库用户
MysqlDatabaseUser
类提供了管理Forge服务器上MySQL数据库用户的方法。
构造函数
use Fatihtuzlu\ForgeAPI\MysqlDatabaseUser; // Instantiate the MysqlDatabaseUser class by providing an instance of the Forge class $mysqlDatabaseUser = new MysqlDatabaseUser($forge); // Example: Listing MySQL database users on a server $users = $mysqlDatabaseUser->list($serverId); // Example: Creating a new MySQL database user $options = [ 'name' => 'example_user', // Replace with the desired username 'password' => 'secure_password', // Replace with the desired password ]; $response = $mysqlDatabaseUser->create($serverId, $options); // Example: Getting details of a MySQL database user $userId = 123; // Replace with the desired user ID $userDetails = $mysqlDatabaseUser->get($serverId, $userId); // Example: Updating details of a MySQL database user $userId = 123; // Replace with the desired user ID $options = [ 'password' => 'new_secure_password', // Replace with the desired new password ]; $response = $mysqlDatabaseUser->update($serverId, $userId, $options); // Example: Deleting a MySQL database user $userId = 123; // Replace with the desired user ID $mysqlDatabaseUser->delete($serverId, $userId);
Nginx
Nginx
类提供了管理Forge服务器上Nginx模板的方法。
构造函数
use Fatihtuzlu\ForgeAPI\Nginx; // Instantiate the Nginx class by providing an instance of the Forge class $nginx = new Nginx($forge); // Example: Listing the default Nginx template on a server $template = $nginx->list($serverId); // Example: Creating a new Nginx template $options = [ 'content' => '...nginx configuration content...', // Replace with the desired Nginx configuration content ]; $response = $nginx->create($serverId, $options); // Example: Getting details of the default Nginx template $templateId = 1; // Replace with the default template ID $templateDetails = $nginx->getDefault($serverId, $templateId); // Example: Getting details of a specific Nginx template $templateId = 123; // Replace with the desired template ID $templateDetails = $nginx->get($serverId, $templateId); // Example: Updating details of a specific Nginx template $templateId = 123; // Replace with the desired template ID $options = [ 'content' => '...updated nginx configuration content...', // Replace with the desired updated Nginx configuration content ]; $response = $nginx->update($serverId, $templateId, $options); // Example: Deleting a specific Nginx template $templateId = 123; // Replace with the desired template ID $nginx->delete($serverId, $templateId);
站点
Site
类提供了管理Forge服务器上站点的方法。
构造函数
use Fatihtuzlu\ForgeAPI\Site; // Instantiate the Site class by providing an instance of the Forge class $site = new Site($forge); // Example: Listing all sites on a server $sites = $site->list($serverId); // Example: Creating a new site $options = [ 'domain' => 'example.com', // Replace with the desired domain // ... other site configuration options ]; $response = $site->create($serverId, $options); // Example: Getting details of a specific site $siteId = 123; // Replace with the desired site ID $siteDetails = $site->get($serverId, $siteId); // Example: Updating details of a specific site $siteId = 123; // Replace with the desired site ID $options = [ 'domain' => 'updated-example.com', // Replace with the updated domain // ... other updated site configuration options ]; $response = $site->update($serverId, $siteId, $options); // Example: Deleting a specific site $siteId = 123; // Replace with the desired site ID $site->delete($serverId, $siteId); // Example: Changing PHP version for a specific site $siteId = 123; // Replace with the desired site ID $options = [ 'version' => 'php8.0', // Replace with the desired PHP version ]; $site->changePhpVersion($serverId, $siteId, $options); // Example: Adding aliases to a specific site $siteId = 123; // Replace with the desired site ID $options = [ 'aliases' => ['alias1.com', 'alias2.com'], // Replace with the desired aliases ]; $aliases = $site->addAliases($serverId, $siteId, $options); // Example: Retrieving load balancing details for a specific site $siteId = 123; // Replace with the desired site ID $balancingDetails = $site->loadBalancing($serverId, $siteId); // Example: Updating load balancing details for a specific site $siteId = 123; // Replace with the desired site ID $options = [ 'mode' => 'http', // Replace with the desired load balancing mode // ... other updated load balancing options ]; $site->updateLoadBalancing($serverId, $siteId, $options); // Example: Retrieving logs for a specific site $siteId = 123; // Replace with the desired site ID $siteLogs = $site->log($serverId, $siteId);
SSL证书
SSLCertificate
类提供了管理Forge服务器上站点SSL证书的方法。
构造函数
// Instantiate the SSLCertificate class by providing an instance of the Forge class $sslCertificate = new SSLCertificate($forge); // Example: Installing an existing SSL certificate $serverId = 123; $siteId = 456; $options = [ 'certificate' => '-----BEGIN CERTIFICATE----- ... -----END CERTIFICATE-----', 'private_key' => '-----BEGIN PRIVATE KEY----- ... -----END PRIVATE KEY-----', // ... other certificate installation options ]; $response = $sslCertificate->installAnExisting($serverId, $siteId, $options); // Example: Cloning an existing SSL certificate $serverId = 123; $siteId = 456; $options = [ 'certificate_id' => 789, // ... other certificate cloning options ]; $response = $sslCertificate->cloneAnExisting($serverId, $siteId, $options); // Example: Installing Let's Encrypt SSL certificate $serverId = 123; $siteId = 456; $options = [ 'subdomains' => ['www'], // ... other Let's Encrypt certificate installation options ]; $response = $sslCertificate->letsencrypt($serverId, $siteId, $options); // Example: Listing SSL certificates for a specific site $serverId = 123; $siteId = 456; $certificates = $sslCertificate->list($serverId, $siteId); // Example: Getting details of a specific SSL certificate $serverId = 123; $siteId = 456; $certificateId = 789; $certificateDetails = $sslCertificate->get($serverId, $siteId, $certificateId); // Example: Retrieving the signing request for a specific SSL certificate $serverId = 123; $siteId = 456; $certificateId = 789; $sslCertificate->getSigninReq($serverId, $siteId, $certificateId); // Example: Installing a specific SSL certificate $serverId = 123; $siteId = 456; $certificateId = 789; $options = [ 'private_key' => '-----BEGIN PRIVATE KEY----- ... -----END PRIVATE KEY-----', // ... other certificate installation options ]; $sslCertificate->install($serverId, $siteId, $certificateId, $options); // Example: Activating a specific SSL certificate $serverId = 123; $siteId = 456; $certificateId = 789; $sslCertificate->activate($serverId, $siteId, $certificateId); // Example: Deleting a specific SSL certificate $serverId = 123; $siteId = 456; $certificateId = 789; $sslCertificate->delete($serverId, $siteId, $certificateId);
SSH密钥
SSHKey
类提供了管理Forge服务器上SSH密钥的方法。
构造函数
// Instantiate the SSHKey class by providing an instance of the Forge class $sshKey = new SSHKey($forge); // Example: Creating a new SSH key for a server $serverId = 123; $newSSHKey = $sshKey->create($serverId); // Example: Listing all SSH keys for a server $serverId = 123; $sshKeys = $sshKey->list($serverId); // Example: Getting details of a specific SSH key $serverId = 123; $keyId = 456; $keyDetails = $sshKey->get($serverId, $keyId); // Example: Deleting a specific SSH key $serverId = 123; $keyId = 456; $sshKey->delete($serverId, $keyId);
工作进程
Worker
类提供了管理Forge服务器上站点工作进程的方法。
构造函数
use Fatihtuzlu\ForgeAPI\Worker; // Instantiate the Worker class by providing an instance of the Forge class // Instantiate the Worker class by providing an instance of the Forge class $worker = new Worker($forge); // Example: Adding a new worker to a site $serverId = 123; $siteId = 456; $options = [ 'command' => 'php artisan queue:work', 'queue' => 'default', // Add other options as needed ]; $newWorker = $worker->create($serverId, $siteId, $options); // Example: Listing all workers for a site $serverId = 123; $siteId = 456; $workers = $worker->list($serverId, $siteId); // Example: Getting details of a specific worker $serverId = 123; $siteId = 456; $workerId = 789; $workerDetails = $worker->get($serverId, $siteId, $workerId); // Example: Deleting a specific worker $serverId = 123; $siteId = 456; $workerId = 789; $worker->delete($serverId, $siteId, $workerId); // Example: Restarting a specific worker $serverId = 123; $siteId = 456; $workerId = 789; $worker->restart($serverId, $siteId, $workerId);
安全规则
SecurityRule
类提供了管理Forge服务器上站点安全规则的方法。
构造函数
use Fatihtuzlu\ForgeAPI\SecurityRule; // Instantiate the SecurityRule class by providing an instance of the Forge class $securityRule = new SecurityRule($forge); // Example: Adding a new security rule to a site $serverId = 123; // Replace with the desired server ID $siteId = 456; // Replace with the desired site ID $options = [ "name" => "Access Restricted", "path" => null, "credentials" => [ [ "username" => "taylor.otwell", "password" => "password123", ], [ "username" => "james.brooks", "password" => "secret123", ], ], // Add other options as needed ]; $newRule = $securityRule->create($serverId, $siteId, $options); // Example: Listing all security rules for a site $serverId = 123; $siteId = 456; $rules = $securityRule->list($serverId, $siteId); // Example: Getting details of a specific security rule $serverId = 123; $siteId = 456; $ruleId = 789; $ruleDetails = $securityRule->get($serverId, $siteId, $ruleId); // Example: Deleting a specific security rule $serverId = 123; $siteId = 456; $ruleId = 789; $securityRule->delete($serverId, $siteId, $ruleId);
部署
Deployment
类提供了管理Forge服务器上站点部署设置和操作的方法。
构造函数
use Fatihtuzlu\ForgeAPI\Forge; use Fatihtuzlu\ForgeAPI\Deployment; // Instantiate the Forge class (assuming you have set up your API key and other necessary configurations) $forge = new Forge('your-api-key', 'your-api-url'); // Instantiate the Deployment class $deployment = new Deployment($forge); // Example: Enable deployment for a site $serverId = 123; // Replace with the desired server ID $siteId = 456; // Replace with the desired site ID $deployment->enable($serverId, $siteId); // Example: Get the deployment script for a site $deploymentScript = $deployment->get($serverId, $siteId); print_r($deploymentScript); // Example: Update the deployment script for a site $options = [ "content" => "Updated content of the deployment script", "auto_source" => true, // Add other options as needed ]; $deployment->update($serverId, $siteId, $options); // Example: Deploy a site $deployment->deploy($serverId, $siteId); // Example: Reset deployment for a site $deployment->reset($serverId, $siteId); // Example: Get the deployment log for a site $deploymentLog = $deployment->log($serverId, $siteId); print_r($deploymentLog); // Example: Disable deployment for a site $deployment->disable($serverId, $siteId);
部署历史
Forge API包装器中的DeploymentHistory
类允许您与Forge服务器上特定站点的部署历史交互。
use Fatihtuzlu\ForgeAPI\Forge; use Fatihtuzlu\ForgeAPI\DeploymentHistory; // Instantiate the Forge class (assuming you have set up your API key and other necessary configurations) $forge = new Forge('your-api-key', 'your-api-url'); // Instantiate the DeploymentHistory class $deploymentHistory = new DeploymentHistory($forge); // Example: List deployment history for a site $serverId = 123; // Replace with the desired server ID $siteId = 456; // Replace with the desired site ID $deployments = $deploymentHistory->list($serverId, $siteId); print_r($deployments); // Example: Get details of a specific deployment in history $deploymentId = 789; // Replace with the desired deployment ID $deploymentDetails = $deploymentHistory->get($serverId, $siteId, $deploymentId); print_r($deploymentDetails); // Example: Get output of a specific deployment in history $deploymentOutput = $deploymentHistory->getOutput($serverId, $siteId, $deploymentId); print_r($deploymentOutput);
Nginx配置
Forge API包装器中的NginxConfiguration
类提供了管理Forge服务器上特定站点的Nginx配置和环境变量的方法。
use Fatihtuzlu\ForgeAPI\Forge; use Fatihtuzlu\ForgeAPI\NginxConfiguration; $forge = new Forge('YOUR_BEARER_TOKEN'); // Instantiate the NginxConfiguration class $nginxConfig = new NginxConfiguration($forge); // Replace with the desired server and site IDs $serverId = 123; $siteId = 456; // Get Nginx configuration for the site $nginxConfiguration = $nginxConfig->get($serverId, $siteId); print_r($nginxConfiguration); // Replace with the desired options for Nginx configuration $options = [ // Your Nginx configuration options here ]; // Update Nginx configuration for the site $updatedNginxConfig = $nginxConfig->update($serverId, $siteId, $options); print_r($updatedNginxConfig); // Get environment variables for the site $envVariables = $nginxConfig->getEnv($serverId, $siteId); print_r($envVariables); // Replace with the desired options for updating environment variables $envOptions = [ // Your environment variable options here ]; // Update environment variables for the site $updatedEnvVariables = $nginxConfig->updateEnv($serverId, $siteId, $envOptions); print_r($updatedEnvVariables);
Git
Forge API包装器中的Git
类提供了管理Forge服务器上特定站点的Git配置、部署和部署密钥的方法。
use Fatihtuzlu\ForgeAPI\Forge; use Fatihtuzlu\ForgeAPI\Git; $forge = new Forge('YOUR_BEARER_TOKEN'); // Instantiate the Git class $git = new Git($forge); // Replace with the desired server and site IDs $serverId = 123; $siteId = 456; // Replace with the desired options for Git installation $installOptions = [ // Your Git installation options here ]; // Install Git for the site $gitInstallation = $git->install($serverId, $siteId, $installOptions); print_r($gitInstallation);
站点命令
Forge API包装器中的SiteCommand
类提供了执行命令、列出已执行的命令和获取特定已执行命令详细信息的方法。
use Fatihtuzlu\ForgeAPI\Forge; use Fatihtuzlu\ForgeAPI\SiteCommand; // Instantiate the Forge class with your Bearer token $forge = new Forge('YOUR_BEARER_TOKEN'); // Instantiate the SiteCommand class $siteCommand = new SiteCommand($forge); // Replace with the desired server and site IDs $serverId = 123; $siteId = 456; // 1. Execute a Command for the Site // Replace with the desired options for the command execution $executionOptions = [ 'command' => 'php artisan migrate', 'script' => 'YOUR_CUSTOM_SCRIPT', // Optional // Additional options as needed ]; $commandExecution = $siteCommand->execute($serverId, $siteId, $executionOptions); print_r($commandExecution); // 2. List Executed Commands for the Site $executedCommands = $siteCommand->list($serverId, $siteId); print_r($executedCommands); // 3. Get Details of a Specific Executed Command // Replace with the desired command ID $commandId = 789; $commandDetails = $siteCommand->get($serverId, $siteId, $commandId); print_r($commandDetails);
WordPress
Forge API包装器中的Wordpress
类提供了为Forge服务器上的站点安装和卸载WordPress的方法。
use Fatihtuzlu\ForgeAPI\Forge; use Fatihtuzlu\ForgeAPI\Wordpress; // Instantiate the Forge class with your Bearer token $forge = new Forge('YOUR_BEARER_TOKEN'); // Instantiate the Wordpress class $wordpress = new Wordpress($forge); // Replace with the desired server and site IDs $serverId = 123; $siteId = 456; // 1. Install WordPress for the Site // Replace with the desired options for WordPress installation $installOptions = [ "database"=> "forge", "user"=> 1 ]; $wordpress->install($serverId, $siteId, $installOptions); // 2. Uninstall WordPress for the Site $wordpress->uninstall($serverId, $siteId);
PhpMyAdmin
Forge API包装器中的PhpMyAdmin
类提供了为Forge服务器上的站点安装和卸载PhpMyAdmin的方法。
use Fatihtuzlu\ForgeAPI\Forge; use Fatihtuzlu\ForgeAPI\PhpMyAdmin; // Instantiate the Forge class with your Bearer token $forge = new Forge('YOUR_BEARER_TOKEN'); // Instantiate the PhpMyAdmin class $phpMyAdmin = new PhpMyAdmin($forge); // Replace with the desired server and site IDs $serverId = 123; $siteId = 456; // 1. Install PhpMyAdmin for the Site // Replace with the desired options for PhpMyAdmin installation $installOptions = [ "database" => "forge", "user" => 1 ]; $phpMyAdmin->install($serverId, $siteId, $installOptions); // 2. Uninstall PhpMyAdmin for the Site $phpMyAdmin->uninstall($serverId, $siteId);
Webhook
Forge API包装器中的Webhook
类提供用于管理Forge服务器上站点webhook的方法。
use Fatihtuzlu\ForgeAPI\Forge; use Fatihtuzlu\ForgeAPI\Webhook; // Instantiate the Forge class with your Bearer token $forge = new Forge('YOUR_BEARER_TOKEN'); // Instantiate the Webhook class $webhook = new Webhook($forge); // Replace with the desired server and site IDs $serverId = 123; $siteId = 456; // 1. List Webhooks for the Site $webhooks = $webhook->list($serverId, $siteId); print_r($webhooks); // 2. Show Details of a Webhook // Replace with the desired webhook ID $webhookId = 789; $webhookDetails = $webhook->show($serverId, $siteId, $webhookId); print_r($webhookDetails); // 3. Create a New Webhook // Replace with the desired options for webhook creation $createOptions = [ "url" => "http://domain.com" ]; $newWebhook = $webhook->create($serverId, $siteId, $createOptions); print_r($newWebhook); // 4. Delete a Webhook // Replace with the desired webhook ID to be deleted $webhookIdToDelete = 789; $deletedWebhook = $webhook->delete($serverId, $siteId, $webhookIdToDelete); print_r($deletedWebhook);
配方
Forge API包装器中的Recipe
类提供用于管理配方的方法。
use Fatihtuzlu\ForgeAPI\Forge; use Fatihtuzlu\ForgeAPI\Recipe; // Instantiate the Forge class with your Bearer token $forge = new Forge('YOUR_BEARER_TOKEN'); // Instantiate the Recipe class $recipe = new Recipe($forge); // 1. List Recipes $recipes = $recipe->list(); print_r($recipes); // 2. Create a New Recipe // Replace with the desired options for recipe creation $createOptions = [ 'name' => 'Example Recipe', 'script' => '#!/bin/bash echo "Hello, Forge!"', // Additional options as needed ]; $newRecipe = $recipe->create($createOptions); print_r($newRecipe); // 3. Get Details of a Recipe // Replace with the desired recipe ID $recipeId = 123; $recipeDetails = $recipe->get($recipeId); print_r($recipeDetails); // 4. Update a Recipe // Replace with the desired recipe ID and options for updating $recipeIdToUpdate = 123; $updateOptions = [ 'name' => 'Updated Recipe', 'script' => '#!/bin/bash echo "Updated Forge Recipe!"', // Additional options as needed ]; $updatedRecipe = $recipe->update($recipeIdToUpdate, $updateOptions); print_r($updatedRecipe); // 5. Delete a Recipe // Replace with the desired recipe ID to be deleted $recipeIdToDelete = 123; $recipe->delete($recipeIdToDelete); echo "Recipe deleted successfully.\n"; // 6. Run a Recipe // Replace with the desired recipe ID and options for running $recipeIdToRun = 123; $runOptions = [ 'servers' => [456, 789], // Server IDs to run the recipe on // Additional options as needed ]; $recipe->run($recipeIdToRun, $runOptions); echo "Recipe execution initiated.\n";
区域
Forge API包装器中的Region
类提供了一个方法来检索可用的区域列表。
use Fatihtuzlu\ForgeAPI\Forge; use Fatihtuzlu\ForgeAPI\Region; // Instantiate the Forge class with your Bearer token $forge = new Forge('YOUR_BEARER_TOKEN'); // Instantiate the Region class $region = new Region($forge); // List Available Regions $regions = $region->list(); print_r($regions);
凭证
Forge API包装器中的Credential
类提供了一个方法来检索可用的凭证列表。
use Fatihtuzlu\ForgeAPI\Forge; use Fatihtuzlu\ForgeAPI\Credential; // Instantiate the Forge class with your Bearer token $forge = new Forge('YOUR_BEARER_TOKEN'); // Instantiate the Credential class $credential = new Credential($forge); // List Available Credentials $credentials = $credential->list(); print_r($credentials);
备份
Forge API包装器中的Backup
类提供了用于管理服务器上备份配置的方法。
use Fatihtuzlu\ForgeAPI\Forge; use Fatihtuzlu\ForgeAPI\Backup; // Instantiate the Forge class with your Bearer token $forge = new Forge('YOUR_BEARER_TOKEN'); // Instantiate the Backup class $backup = new Backup($forge); // List Backup Configurations for a Server $serverId = 123; // Replace with your server ID $backupConfigurations = $backup->list($serverId); print_r($backupConfigurations); // Create a Backup Configuration $backupOptions = [ "provider" => "spaces", "credentials" => [ "endpoint" => "https://my-endpoint.com", "region" => "region-key", "bucket" => "bucket-name", "access_key" => "", "secret_key" => "" ], "frequency" => [ "type" => "weekly", "time" => "12:30", "day" => 1 ], "directory" => "backups/server/db", "email" => "forge@laravel.com", "retention" => 7, "databases" => [ 24 ] ]; $newBackup = $backup->create($serverId, $backupOptions); print_r($newBackup); // Get Backup Configuration Details $backupConfigurationId = 456; // Replace with the actual backup configuration ID $backupDetails = $backup->get($serverId, $backupConfigurationId); print_r($backupDetails); // Run a Backup for a Backup Configuration $backup->run($serverId, $backupConfigurationId); // Delete Backup Configuration $backup->deleteBackupConfigiration($serverId, $backupConfigurationId); // Restore from Backup $backupId = 789; // Replace with the actual backup ID $backup->restore($serverId, $backupConfigurationId, $backupId); // Delete Backup $backup->deleteBackup($serverId, $backupConfigurationId, $backupId);
监控
Forge API包装器中的Monitoring
类提供了用于管理服务器上监控器的方法。
use Fatihtuzlu\ForgeAPI\Forge; use Fatihtuzlu\ForgeAPI\Monitoring; // Instantiate the Forge class with your Bearer token $forge = new Forge('YOUR_BEARER_TOKEN'); // Instantiate the Monitoring class $monitoring = new Monitoring($forge); // List Monitors for a Server $serverId = 123; // Replace with your server ID $monitors = $monitoring->list($serverId); print_r($monitors); // Create a Monitor $monitorOptions = [ "type" => "cpu_load", "operator" => "gte", "threshold" => "1.3", "minutes" => "5", "notify" => "forge@laravel.com" ]; $newMonitor = $monitoring->create($serverId, $monitorOptions); print_r($newMonitor); // Get Monitor Details $monitorId = 456; // Replace with the actual monitor ID $monitorDetails = $monitoring->get($serverId, $monitorId); print_r($monitorDetails); // Delete a Monitor $monitoring->delete($serverId, $monitorId);
服务器日志
Forge API包装器中的ServerLogs
类提供了一个用于检索特定服务器日志的方法。
use Fatihtuzlu\ForgeAPI\Forge; use Fatihtuzlu\ForgeAPI\ServerLogs; // Instantiate the Forge class with your Bearer token $forge = new Forge('YOUR_BEARER_TOKEN'); // Instantiate the ServerLogs class $serverLogs = new ServerLogs($forge); // Retrieve Logs for a Server $serverId = 123; // Replace with your server ID $logs = $serverLogs->logs($serverId); if (!empty($logs)) { // Process and display logs foreach ($logs as $log) { echo "Log Entry:\n"; echo "Timestamp: " . $log['timestamp'] . "\n"; echo "Message: " . $log['message'] . "\n\n"; } } else { echo "No logs available for the specified server.\n"; }