mirror of
https://gitee.com/dgiiot/dgiot.git
synced 2024-12-02 12:18:30 +08:00
feat: add license
This commit is contained in:
parent
cbb32658cc
commit
35371b6a99
@ -24,8 +24,7 @@
|
|||||||
, check_lincense/3
|
, check_lincense/3
|
||||||
, gen_password/1
|
, gen_password/1
|
||||||
, get_hardkey/0
|
, get_hardkey/0
|
||||||
, check/0
|
, check/1
|
||||||
, check_lincense/0
|
|
||||||
, check_plugin/1
|
, check_plugin/1
|
||||||
, update_license/1
|
, update_license/1
|
||||||
, get_license/0
|
, get_license/0
|
||||||
@ -45,55 +44,25 @@ init({}) ->
|
|||||||
description() -> "dgiot license".
|
description() -> "dgiot license".
|
||||||
|
|
||||||
check_lincense(Type, Key, License) ->
|
check_lincense(Type, Key, License) ->
|
||||||
case Type of
|
|
||||||
<<"standard">> ->
|
|
||||||
check_standard_license(Key, dgiot_utils:to_list(License));
|
|
||||||
<<"enterprise">> ->
|
|
||||||
check_enterprise_license(Key, dgiot_utils:to_list(License));
|
|
||||||
<<"ultimate">> -> check_ultimate_license(Key, dgiot_utils:to_list(License));
|
|
||||||
_ -> check_old_license(Key, dgiot_utils:to_list(License))
|
|
||||||
end.
|
|
||||||
|
|
||||||
check_standard_license(Key, License) ->
|
|
||||||
write("data/newsw.key", Key),
|
write("data/newsw.key", Key),
|
||||||
NewLicense = gen_password(<<"dgiot_stand2020sdfsdf-", Key/binary, "-203019">>),
|
NewLicense = gen_password(<<Type/binary, Key/binary, "-203019">>),
|
||||||
License == NewLicense.
|
License == NewLicense.
|
||||||
|
|
||||||
check_enterprise_license(Key, License) ->
|
check(Type) ->
|
||||||
write("data/newsw.key", Key),
|
|
||||||
NewLicense = gen_password(<<"dgiot_133enterprise2020sdsfff8dfsdf-", Key/binary, "-2030dd19">>),
|
|
||||||
License == NewLicense.
|
|
||||||
|
|
||||||
check_ultimate_license(Key, License) ->
|
|
||||||
write("data/newsw.key", Key),
|
|
||||||
NewLicense = gen_password(<<"dgiot_133ultimate206420sd32sfff8dfsdf-", Key/binary, "-2030dd19">>),
|
|
||||||
License == NewLicense.
|
|
||||||
|
|
||||||
check_old_license(Key, License) ->
|
|
||||||
write("data/sw.key", Key),
|
|
||||||
Hash = <<"lorasouth2018test-", Key/binary, "-202019">>,
|
|
||||||
MyPassword = gen_password(Hash),
|
|
||||||
License == MyPassword.
|
|
||||||
|
|
||||||
check_lincense() ->
|
|
||||||
check().
|
|
||||||
|
|
||||||
check() ->
|
|
||||||
case (dgiot_datetime:now_secs() - 1639622310) < 0 of
|
case (dgiot_datetime:now_secs() - 1639622310) < 0 of
|
||||||
true -> true;
|
true -> true;
|
||||||
false ->
|
false ->
|
||||||
case application:get_env(dgiot_license, license) of
|
case application:get_env(dgiot_license, license) of
|
||||||
{ok, License} ->
|
{ok, License} ->
|
||||||
OldKey = get_key(),
|
OldKey = get_key(),
|
||||||
NewKey = get_hardkey(),
|
%% NewKey = get_hardkey(),
|
||||||
case check_old_license(OldKey, License) or check_standard_license(NewKey, License) or
|
case check_lincense(Type, OldKey, License) of
|
||||||
check_enterprise_license(NewKey, License) or check_ultimate_license(NewKey, License)
|
|
||||||
of
|
|
||||||
false ->
|
false ->
|
||||||
false;
|
false;
|
||||||
true ->
|
true ->
|
||||||
case os:type() of
|
case os:type() of
|
||||||
{win32, _} -> true;
|
{win32, _} ->
|
||||||
|
true;
|
||||||
_ ->
|
_ ->
|
||||||
case check_sudo() of
|
case check_sudo() of
|
||||||
not_root_user ->
|
not_root_user ->
|
||||||
@ -109,10 +78,10 @@ check() ->
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
gen_password(License) ->
|
gen_password(License) ->
|
||||||
binary_to_list(to_md5(License)).
|
dgiot_utils:to_list(to_md5(License)).
|
||||||
|
|
||||||
to_md5(V) ->
|
to_md5(V) ->
|
||||||
list_to_binary(lists:flatten([io_lib:format("~2.16.0b", [D]) || D <- binary_to_list(erlang:md5(V))])).
|
dgiot_utils:to_binary(lists:flatten([io_lib:format("~2.16.0b", [D]) || D <- dgiot_utils:to_list(erlang:md5(V))])).
|
||||||
|
|
||||||
get_key() ->
|
get_key() ->
|
||||||
S = lists:foldl(fun(Cmd, Acc) ->
|
S = lists:foldl(fun(Cmd, Acc) ->
|
||||||
@ -165,7 +134,7 @@ write(Path, Format, Args) ->
|
|||||||
io:fwrite(IoDevice, Format, Args),
|
io:fwrite(IoDevice, Format, Args),
|
||||||
file:close(IoDevice);
|
file:close(IoDevice);
|
||||||
{error, Why} ->
|
{error, Why} ->
|
||||||
?LOG(error,"write file error, ~p~n", [Why])
|
?LOG(error, "write file error, ~p~n", [Why])
|
||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user