2024-10-29 19:11:29 +01:00
|
|
|
package Exd;
|
|
|
|
|
|
|
|
use v5.40.0;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use utf8;
|
|
|
|
|
|
|
|
use Moo;
|
|
|
|
use JSON;
|
|
|
|
use Path::Tiny;
|
|
|
|
use UUID::URandom qw/create_uuid_string/;
|
|
|
|
|
2024-11-10 18:04:52 +01:00
|
|
|
require XSLoader;
|
|
|
|
XSLoader::load();
|
|
|
|
|
2024-10-29 19:11:29 +01:00
|
|
|
has config => ( is => 'lazy' );
|
|
|
|
|
|
|
|
sub _build_config($self) {
|
|
|
|
return JSON::from_json( $self->_config_file_name->slurp_utf8 );
|
|
|
|
}
|
|
|
|
|
|
|
|
sub _config_file_name($self) {
|
2024-11-10 18:04:52 +01:00
|
|
|
$self->root->child('app_config.json');
|
|
|
|
}
|
|
|
|
|
|
|
|
sub root($class) {
|
|
|
|
return path(__FILE__)->parent->parent->parent;
|
2024-10-29 19:11:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sub licenser_server($self) {
|
|
|
|
return $self->config->{'licenser-server'};
|
|
|
|
}
|
|
|
|
|
|
|
|
sub debug($self) {
|
|
|
|
return $self->config->{debug};
|
|
|
|
}
|
|
|
|
|
|
|
|
sub uuid($self) {
|
|
|
|
require Exd::DB;
|
|
|
|
my $dbh = Exd::DB->connect;
|
|
|
|
my $key = 'licenser-uuid';
|
|
|
|
my $option =
|
|
|
|
$dbh->selectrow_hashref( 'SELECT value FROM options WHERE name = ?;',
|
|
|
|
{}, $key );
|
|
|
|
my $uuid;
|
|
|
|
if (defined $option) {
|
|
|
|
$uuid = $option->{value};
|
|
|
|
}
|
|
|
|
if ( !defined $uuid ) {
|
|
|
|
$uuid = create_uuid_string();
|
|
|
|
$dbh->do( 'INSERT OR IGNORE INTO options (name, value) VALUES (?, ?);',
|
|
|
|
{}, $key, $uuid );
|
|
|
|
}
|
|
|
|
return $uuid;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
my $key = 'activated';
|
|
|
|
sub is_activated_license($self) {
|
|
|
|
require Exd::DB;
|
|
|
|
my $dbh = Exd::DB->connect;
|
|
|
|
my $option =
|
|
|
|
$dbh->selectrow_hashref( 'SELECT value FROM options WHERE name = ?;',
|
|
|
|
{}, $key );
|
|
|
|
if (!defined $option) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return $option->{value};
|
|
|
|
}
|
|
|
|
|
|
|
|
sub activate_license($self) {
|
|
|
|
require Exd::DB;
|
|
|
|
my $dbh = Exd::DB->connect;
|
|
|
|
$dbh->do( 'INSERT OR IGNORE INTO options (name, value) VALUES (?, ?);',
|
|
|
|
{}, $key, 1 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
1;
|