2019-06-04 00:08:13 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2019-06-04 00:08:13 +02:00
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2021-01-03 22:54:54 +01:00
|
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
2019-06-04 00:08:13 +02:00
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Utils;
|
|
|
|
|
2019-10-16 22:12:38 +02:00
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
2019-06-04 00:08:13 +02:00
|
|
|
/**
|
|
|
|
* Class Ninja.
|
|
|
|
*/
|
|
|
|
class Ninja
|
|
|
|
{
|
2020-03-17 09:40:10 +01:00
|
|
|
const TEST_USERNAME = 'user@example.com';
|
|
|
|
|
2019-10-16 22:12:38 +02:00
|
|
|
public static function isSelfHost()
|
|
|
|
{
|
|
|
|
return config('ninja.environment') === 'selfhost';
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function isHosted()
|
|
|
|
{
|
|
|
|
return config('ninja.environment') === 'hosted';
|
|
|
|
}
|
|
|
|
|
2020-03-01 11:18:13 +01:00
|
|
|
public static function isNinja()
|
|
|
|
{
|
|
|
|
return config('ninja.production');
|
|
|
|
}
|
|
|
|
|
2020-03-18 10:40:15 +01:00
|
|
|
public static function isNinjaDev()
|
|
|
|
{
|
2020-03-28 12:34:04 +01:00
|
|
|
return config('ninja.environment') == 'development';
|
2020-03-18 10:40:15 +01:00
|
|
|
}
|
|
|
|
|
2019-10-16 22:12:38 +02:00
|
|
|
public static function getDebugInfo()
|
|
|
|
{
|
2020-09-06 11:38:10 +02:00
|
|
|
$mysql_version = DB::select(DB::raw('select version() as version'))[0]->version;
|
|
|
|
|
|
|
|
$info = 'App Version: v'.config('ninja.app_version').'\\n'.
|
|
|
|
'White Label: '.'\\n'. // TODO: Implement white label with hasFeature.
|
|
|
|
'Server OS: '.php_uname('s').' '.php_uname('r').'\\n'.
|
|
|
|
'PHP Version: '.phpversion().'\\n'.
|
|
|
|
'MySQL Version: '.$mysql_version;
|
2019-06-04 00:08:13 +02:00
|
|
|
|
2019-10-16 22:12:38 +02:00
|
|
|
return $info;
|
|
|
|
}
|
2020-03-07 13:46:45 +01:00
|
|
|
|
|
|
|
public static function boot()
|
|
|
|
{
|
2020-03-26 04:23:57 +01:00
|
|
|
if (self::isNinjaDev()) {
|
2020-03-25 03:50:08 +01:00
|
|
|
return true;
|
2020-03-26 04:23:57 +01:00
|
|
|
}
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-03-07 13:46:45 +01:00
|
|
|
$data = [
|
|
|
|
'license' => config('ninja.license'),
|
|
|
|
];
|
|
|
|
|
|
|
|
$data = trim(CurlUtils::post('https://license.invoiceninja.com/api/check', $data));
|
|
|
|
$data = json_decode($data);
|
|
|
|
|
2020-03-22 21:45:16 +01:00
|
|
|
if ($data && property_exists($data, 'message') && $data->message == sha1(config('ninja.license'))) {
|
2020-03-07 13:46:45 +01:00
|
|
|
return true;
|
2020-03-28 12:34:04 +01:00
|
|
|
} else {
|
|
|
|
return false;
|
2020-03-21 06:37:30 +01:00
|
|
|
}
|
2020-03-07 13:46:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function parse()
|
|
|
|
{
|
|
|
|
return 'Invalid license.';
|
|
|
|
}
|
2020-03-07 23:15:11 +01:00
|
|
|
|
|
|
|
public static function selfHostedMessage()
|
|
|
|
{
|
|
|
|
return 'Self hosted installation limited to one account';
|
|
|
|
}
|
2020-03-17 09:40:10 +01:00
|
|
|
|
|
|
|
public static function registerNinjaUser($user)
|
|
|
|
{
|
2020-03-18 10:40:15 +01:00
|
|
|
if (! $user || $user->email == self::TEST_USERNAME || self::isNinjaDev()) {
|
2020-03-17 09:40:10 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$url = config('ninja.license_url').'/signup/register';
|
2020-03-17 09:40:10 +01:00
|
|
|
$data = '';
|
|
|
|
$fields = [
|
|
|
|
'first_name' => urlencode($user->first_name),
|
|
|
|
'last_name' => urlencode($user->last_name),
|
|
|
|
'email' => urlencode($user->email),
|
|
|
|
];
|
|
|
|
|
|
|
|
foreach ($fields as $key => $value) {
|
|
|
|
$data .= $key.'='.$value.'&';
|
|
|
|
}
|
|
|
|
rtrim($data, '&');
|
|
|
|
|
|
|
|
$ch = curl_init();
|
|
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
|
|
curl_setopt($ch, CURLOPT_POST, count($fields));
|
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
|
curl_exec($ch);
|
|
|
|
curl_close($ch);
|
|
|
|
}
|
2020-07-08 14:02:16 +02:00
|
|
|
|
|
|
|
public static function eventVars()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'ip' => request()->getClientIp(),
|
|
|
|
'token' => request()->header('X-API-TOKEN'),
|
|
|
|
'is_system' => app()->runningInConsole(),
|
|
|
|
];
|
|
|
|
}
|
2020-11-10 04:36:16 +01:00
|
|
|
|
|
|
|
public static function transformTranslations($settings) :array
|
|
|
|
{
|
|
|
|
$translations = [];
|
|
|
|
|
|
|
|
$trans = (array)$settings->translations;
|
|
|
|
|
2020-11-25 15:19:52 +01:00
|
|
|
if (count($trans) == 0) {
|
2020-11-10 04:36:16 +01:00
|
|
|
return $translations;
|
2020-11-25 15:19:52 +01:00
|
|
|
}
|
2020-11-10 04:36:16 +01:00
|
|
|
|
2020-11-25 15:19:52 +01:00
|
|
|
foreach ($trans as $key => $value) {
|
|
|
|
$translations['texts.'.$key] = $value;
|
2020-11-10 04:36:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $translations;
|
|
|
|
}
|
2019-06-04 00:08:13 +02:00
|
|
|
}
|