Introduce Composer
This commit is contained in:
parent
ef51985bf0
commit
7cd237485a
|
|
@ -1,3 +1,6 @@
|
|||
# Config files:
|
||||
/config/*.json
|
||||
!/config/pb-dydns.example.json
|
||||
|
||||
# Composer files:
|
||||
/vendor/
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
require __DIR__ . "/PorkbunAPI.php";
|
||||
require __DIR__ . "/Config.php";
|
||||
require __DIR__ . "/Logger.php";
|
||||
require __DIR__ . "/UpdateDnsCommand.php";
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
$config = new Config(__DIR__ . "/pb-dydns.json");
|
||||
$logger = new Logger(__DIR__ . "/pb-dydns.log");
|
||||
use App\Config\Config;
|
||||
use App\Util\Logger;
|
||||
use App\Command\UpdateDnsCommand;
|
||||
|
||||
$config = new Config(__DIR__ . "/../config/pb-dydns.json");
|
||||
$logger = new Logger(__DIR__ . "/../logs/pb-dydns.log");
|
||||
|
||||
$cmd = new UpdateDnsCommand($config, $logger);
|
||||
$cmd->run($argv);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"name": "ramoncaballero.dev/pb-dydns",
|
||||
"description": "Dynamic DNS updater for Porkbun",
|
||||
"type": "project",
|
||||
"autoload":
|
||||
{
|
||||
"psr-4":
|
||||
{
|
||||
"App\\": "src/"
|
||||
}
|
||||
},
|
||||
"require": {}
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"_readme": [
|
||||
"This file locks the dependencies of your project to a known state",
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "9462733d0fea3fd21d03aa382b606406",
|
||||
"packages": [],
|
||||
"packages-dev": [],
|
||||
"aliases": [],
|
||||
"minimum-stability": "stable",
|
||||
"stability-flags": {},
|
||||
"prefer-stable": false,
|
||||
"prefer-lowest": false,
|
||||
"platform": {},
|
||||
"platform-dev": {},
|
||||
"plugin-api-version": "2.6.0"
|
||||
}
|
||||
|
|
@ -1,5 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace App\Api;
|
||||
|
||||
use stdClass;
|
||||
use App\Util\Console;
|
||||
|
||||
//
|
||||
// Wrapper class to communicate with Porkbun API.
|
||||
//
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
<?php
|
||||
|
||||
require_once __DIR__ . '/../Api/PorkbunAPI.php';
|
||||
require_once __DIR__ . '/../Config/Config.php';
|
||||
require_once __DIR__ . '/../Util/Logger.php';
|
||||
require_once __DIR__ . '/../Util/Console.php';
|
||||
namespace App\Command;
|
||||
|
||||
use App\Api\PorkbunAPI;
|
||||
use App\Config\Config;
|
||||
use App\Util\Logger;
|
||||
use App\Util\Console;
|
||||
|
||||
class UpdateDnsCommand
|
||||
{
|
||||
|
|
@ -78,9 +80,14 @@ class UpdateDnsCommand
|
|||
if ($record->content != $myIp)
|
||||
{
|
||||
Console::echo("Let's change that... ");
|
||||
|
||||
$name = rtrim(strstr($record->name, $domain, true), ".");
|
||||
$result = json_decode($api->edit($domain, $record->id, $myIp, $name));
|
||||
if ($result->status == "SUCCESS") Console::echo("Done!" . PHP_EOL);
|
||||
|
||||
if ($result->status == "SUCCESS")
|
||||
{
|
||||
Console::echo("Done!" . PHP_EOL);
|
||||
}
|
||||
|
||||
$this->logger->log("Updated DNS on $record->name from $record->content to $myIp");
|
||||
}
|
||||
|
|
@ -89,6 +96,8 @@ class UpdateDnsCommand
|
|||
{
|
||||
Console::echo("Nothing needs to be changed!" . PHP_EOL);
|
||||
}
|
||||
|
||||
Console::echo("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace App\Config;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
class Config
|
||||
{
|
||||
private array $data;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace App\Util;
|
||||
|
||||
class Console
|
||||
{
|
||||
public static function echo(string $message): void
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace App\Util;
|
||||
|
||||
class Logger
|
||||
{
|
||||
private string $filename;
|
||||
|
|
|
|||
Loading…
Reference in New Issue