Skip to content

Commit 9daa171

Browse files
committed
v1.1.3 - Shell safety
1 parent 83e98dc commit 9daa171

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Then: `require_once "/path/to/vendor/autoload.php";` & `use Technitium\DNSServer
3333
require_once "/vendor/autoload.php";
3434
use Technitium\DNSServer\API;
3535

36-
$api = new API();
36+
$api = new API("path/to/env", "env-name");
3737

3838
// Get all zones
3939
$zones = $api->zones()->get();
@@ -64,7 +64,7 @@ if($api->apps->downloadAndInstall($sampleApp["name"], $sampleApp["url"])) {
6464
require_once "/vendor/autoload.php";
6565
use Technitium\DNSServer\API;
6666

67-
$api = new API();
67+
$api = new API("path/to/env", "env-name");
6868
// You have to set <bool>$bypass to true to use this feature
6969
echo var_dump($api->sendCall(data: array("field" => "value"), endpoint: "admin/users/list", skip: false, bypass: true))
7070

@@ -87,7 +87,7 @@ $ddns->updateRecords($path_to_configJSON);
8787

8888
// OR
8989

90-
$ddns_result = new DDNS(new API(), file_get_contents($path_to_configJSON)); // starts automatically updating the records
90+
$ddns_result = new DDNS(new API("path/to/env"), file_get_contents($path_to_configJSON)); // starts automatically updating the records
9191

9292
// OR
9393
$api = new API();
@@ -115,14 +115,19 @@ require_once "/vendor/autoload.php";
115115
use Technitium\DNSServer\API;
116116
use Technitium\DNSServer\API\Helper\DDNS;
117117

118-
DDNS(new API(), file_get_contents("/my/config.json"));
118+
DDNS(new API("path/to/env"), file_get_contents("/my/config.json"));
119119
DDNS(new API(__DIR__), file_get_contents("/my/config2.json"));
120120
DDNS(new API(__DIR__ . "/configurations", ".env-custom"), file_get_contents("/my/config3.json"));
121121

122122
```
123123

124124
## Changes
125125

126+
### v1.1.3: Shell safe
127+
128+
- Library is now shell safe (you are now required to specify the path to the `.env` file)
129+
- Silenced most $_SERVER['argv'] warnings when running the library in shell
130+
126131
### v1.1.2: Quality
127132

128133
- Added more documentation to the classes

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "ente/technitium-dnsserver-php-api",
33
"type": "library",
44
"license": "GPL-3.0-only",
5-
"version": "1.1.2",
5+
"version": "1.1.3",
66
"authors": [
77
{
88
"name": "Ente",

src/API.dnsserver.ente.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class API {
3939
const PREFIX_GET = "&token=";
4040
const PREFIX_POST = "?token=";
4141

42-
public function __construct($confPath = null, $name = null){
42+
public function __construct($confPath, $name = null){
4343
$this->loader();
4444
$this->loadConf($confPath, $name);
4545
$this->setProtocol();
@@ -59,8 +59,11 @@ private function setProtocol(){
5959
* @param mixed $name The name of the .env file. (optional)
6060
* @return void
6161
*/
62-
private function loadConf($path = null, $name = null){
62+
private function loadConf($path, $name = null){
6363
$this->conf = $name ?? ".env";
64+
if(!isset($_SERVER)){
65+
$path = __DIR__;
66+
}
6467
$this->path = $path ?? $_SERVER["DOCUMENT_ROOT"];
6568
$this->fullPath = $this->path . "/" . $this->conf;
6669
if($path != null){

src/helper/Log.Helper.API.dnsserver.ente.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,19 @@ public function __toString(): string {
2929
*/
3030
public static function error_rep($message, $method = null){
3131
$error_file = self::logrotate(); // file on your fs, e.g. /var/www/html/error.log
32-
$version = @file_get_contents($_SERVER["DOCUMENT_ROOT"] . "/VERSION") ?? "N/A"; //optional value
32+
$version = NULL;
3333
if($method == null){
3434
$method = @$_SERVER["REQUEST_METHOD"];
3535
}
36+
$uri = @$_SERVER["REQUEST_URI"];
37+
$host = @$_SERVER["HTTP_HOST"];
38+
$port = @$_SERVER["SERVER_PORT"];
39+
$script = @$_SERVER["SCRIPT_FILENAME"];
40+
$name = @$_SERVER["SERVER_NAME"] ?? "N/A";
3641
$addr = @$_SERVER["SERVER_ADDR"] ?? "N/A";
3742
$rhost = @$_SERVER["REMOTE_HOST"] ?? "N/A";
3843
$time = date("[d.m.Y | H:i:s]");
39-
error_log("{$time} \"{$message}\"\nURL: {$_SERVER["HTTP_HOST"]}{$_SERVER["REQUEST_URI"]} \nVersion: {$version} Server IP:{$addr} - Server Name: {$_SERVER["SERVER_NAME"]} - Request Method: '{$method}'\nRemote Addresse: {$_SERVER["REMOTE_ADDR"]} - Remote Name: '{$rhost}' - Remote Port: {$_SERVER["REMOTE_PORT"]}\nScript Name: '{$_SERVER["SCRIPT_FILENAME"]}'\n=======================\n", 3, $error_file);
44+
error_log("{$time} \"{$message}\"\nURL: {$host}{$uri} \nVersion: {$version} Server IP:{$addr} - Server Name: {$name} - Request Method: '{$method}'\nRemote Addresse: {$addr} - Remote Name: '{$rhost}' - Remote Port: {$port}\nScript Name: '{$script}'\n=======================\n", 3, $error_file);
4045

4146
}
4247

0 commit comments

Comments
 (0)