Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/introducing-composer #83

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"autoload": {
"psr-4": {
"TasmoBackup\\": "./src"
}
}
}
18 changes: 18 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 11 additions & 14 deletions lib/functions.inc.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
<?php
require __DIR__ . '/../vendor/autoload.php';
require_once (__DIR__.'/db.inc.php');

$strJsonFileContents = file_get_contents(__DIR__.'/../HA_addon/config.json');
$array = json_decode($strJsonFileContents, true);
$GLOBALS['VERSION']=$array['version'];

function getBetween($content, $start, $end)
{
$r = explode($start, $content);
Expand Down Expand Up @@ -61,7 +58,7 @@ function getTasmotaScan($ip, $user, $password)
CURLOPT_TIMEOUT => 30,
CURLOPT_CONNECTTIMEOUT => 12,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_USERAGENT => 'TasmoBackup '.$GLOBALS['VERSION'],
CURLOPT_USERAGENT => 'TasmoBackup ' . TasmoBackup\Config\HomeAssistantConfigReader::getVersion(),
CURLOPT_ENCODING => "",
CURLOPT_REFERER => 'http://'.$ip.'/',
CURLOPT_HTTPHEADER => array('Origin: http://'.$ip),
Expand Down Expand Up @@ -100,7 +97,7 @@ function getTasmotaScanRange($iprange, $user, $password)
CURLOPT_TIMEOUT => 30,
CURLOPT_CONNECTTIMEOUT => 12,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_USERAGENT => 'TasmoBackup '.$GLOBALS['VERSION'],
CURLOPT_USERAGENT => 'TasmoBackup ' . TasmoBackup\Config\HomeAssistantConfigReader::getVersion(),
CURLOPT_ENCODING => "",
);
$range=15;
Expand Down Expand Up @@ -172,7 +169,7 @@ function getTasmotaStatus($ip, $user, $password, $type=0)
CURLOPT_TIMEOUT => 30,
CURLOPT_CONNECTTIMEOUT => 12,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_USERAGENT => 'TasmoBackup '.$GLOBALS['VERSION'],
CURLOPT_USERAGENT => 'TasmoBackup ' . TasmoBackup\Config\HomeAssistantConfigReader::getVersion(),
CURLOPT_ENCODING => "",
CURLOPT_REFERER => 'http://'.$ip.'/',
CURLOPT_HTTPHEADER => array('Origin: http://'.$ip),
Expand Down Expand Up @@ -208,7 +205,7 @@ function getTasmotaOldStatus($ip, $user, $password)
CURLOPT_TIMEOUT => 30,
CURLOPT_CONNECTTIMEOUT => 12,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_USERAGENT => 'TasmoBackup '.$GLOBALS['VERSION'],
CURLOPT_USERAGENT => 'TasmoBackup ' . TasmoBackup\Config\HomeAssistantConfigReader::getVersion(),
CURLOPT_ENCODING => "",
CURLOPT_REFERER => 'http://'.$ip.'/',
CURLOPT_HTTPHEADER => array('Origin: http://'.$ip),
Expand All @@ -234,7 +231,7 @@ function getTasmotaStatus2($ip, $user, $password)
CURLOPT_TIMEOUT => 30,
CURLOPT_CONNECTTIMEOUT => 12,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_USERAGENT => 'TasmoBackup '.$GLOBALS['VERSION'],
CURLOPT_USERAGENT => 'TasmoBackup ' . TasmoBackup\Config\HomeAssistantConfigReader::getVersion(),
CURLOPT_ENCODING => "",
CURLOPT_REFERER => 'http://'.$ip.'/',
CURLOPT_HTTPHEADER => array('Origin: http://'.$ip),
Expand All @@ -260,7 +257,7 @@ function getTasmotaStatus5($ip, $user, $password)
CURLOPT_TIMEOUT => 30,
CURLOPT_CONNECTTIMEOUT => 12,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_USERAGENT => 'TasmoBackup '.$GLOBALS['VERSION'],
CURLOPT_USERAGENT => 'TasmoBackup ' . TasmoBackup\Config\HomeAssistantConfigReader::getVersion(),
CURLOPT_ENCODING => "",
CURLOPT_REFERER => 'http://'.$ip.'/',
CURLOPT_HTTPHEADER => array('Origin: http://'.$ip),
Expand Down Expand Up @@ -289,7 +286,7 @@ function restoreTasmotaBackup($ip, $user, $password, $filename)
CURLOPT_TIMEOUT => 60,
CURLOPT_CONNECTTIMEOUT => 12,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_USERAGENT => 'TasmoBackup '.$GLOBALS['VERSION'],
CURLOPT_USERAGENT => 'TasmoBackup ' . TasmoBackup\Config\HomeAssistantConfigReader::getVersion(),
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $fields,
CURLOPT_HTTPHEADER => array('Content-Type: multipart/form-data'),
Expand Down Expand Up @@ -343,7 +340,7 @@ function getTasmotaBackup($ip, $user, $password, $filename, $type=0)
CURLOPT_TIMEOUT => 60,
CURLOPT_CONNECTTIMEOUT => 12,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_USERAGENT => 'TasmoBackup '.$GLOBALS['VERSION'],
CURLOPT_USERAGENT => 'TasmoBackup ' . TasmoBackup\Config\HomeAssistantConfigReader::getVersion(),
CURLOPT_ENCODING => "",
CURLOPT_REFERER => 'http://'.$ip.'/',
CURLOPT_HTTPHEADER => array('Origin: http://'.$ip),
Expand All @@ -367,7 +364,7 @@ function getTasmotaBackup($ip, $user, $password, $filename, $type=0)
CURLOPT_TIMEOUT => 60,
CURLOPT_CONNECTTIMEOUT => 12,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_USERAGENT => 'TasmoBackup '.$GLOBALS['VERSION'],
CURLOPT_USERAGENT => 'TasmoBackup ' . TasmoBackup\Config\HomeAssistantConfigReader::getVersion(),
CURLOPT_ENCODING => "",
CURLOPT_REFERER => 'http://'.$ip.'/',
CURLOPT_HTTPHEADER => array('Origin: http://'.$ip),
Expand Down Expand Up @@ -746,7 +743,7 @@ function TBFooter()
global $VERSION;
?>
<br><br>
<div style='text-align:right;font-size:11px;'><hr/><a href='https://github.com/danmed/TasmoBackupV1' target='_blank' style='color:#aaa;'>TasmoBackup <?php echo $GLOBALS['VERSION']; ?> by Dan Medhurst</a></div>
<div style='text-align:right;font-size:11px;'><hr/><a href='https://github.com/danmed/TasmoBackupV1' target='_blank' style='color:#aaa;'>TasmoBackup <?php echo TasmoBackup\Config\HomeAssistantConfigReader::getVersion(); ?> by Dan Medhurst</a></div>
<?php
}

Expand Down
2 changes: 1 addition & 1 deletion lib/phpMQTT2.php
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ protected function _fwrite($buffer)
*/
public function message($msg)
{
$tlen = (ord($msg{0}) << 8) + ord($msg[1]);
$tlen = (ord($msg[0]) << 8) + ord($msg[1]);
$topic = substr($msg, 2, $tlen);
$msg = substr($msg, ($tlen + 2));
$found = false;
Expand Down
39 changes: 39 additions & 0 deletions src/Config/HomeAssistantConfigReader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace TasmoBackup\Config;

/**
* Reads config.json from HA_addon folder and provides information
*/
final class HomeAssistantConfigReader
{
private static $config;

/**
* Reads config from HA_addon folder
*/
private static function readConfig(): void
{
$content = file_get_contents(__DIR__ . '/../../HA_addon/config.json');
self::$config = json_decode($content, true);
}

/**
* Provides config values
*/
public static function getConfig(): array
{
if (null === self::$config) {
self::readConfig();
}
return self::$config;
}

/**
* Provide current addon version
*/
public static function getVersion(): string
{
return self::getConfig()['version'] ?: '';
}
}
12 changes: 12 additions & 0 deletions vendor/autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

// autoload.php @generated by Composer

if (PHP_VERSION_ID < 50600) {
echo 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL;
exit(1);
}

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInit9652864dded9e7d7b60414870bb7085c::getLoader();
Loading