Ejemplo n.º 1
0
 protected LicenceManager()
 {
     status = LICSTATUS.INITIATING;
 }
Ejemplo n.º 2
0
    internal async Task <bool> CheckLicenceAsync(bool increment = true)
    {
        #region SEE IF NEEDS TO CHECK ONLINE
        string iO = getValue(false);
        Cn = CreateMD5(Environment.MachineName);
        if (iO.Length < 2)
        {
            status = LICSTATUS.UNACTIVATED;
            return(false);
        }
        Licence licence = GetLicence();
        bool    checkOn = false;
        if (licence == null)
        {
            checkOn = true;
            if (VirtualMachineDetector.Assert())
            {
                status = LICSTATUS.UNACTIVATED;
                return(false);
            }
        }
        #endregion
        #region CHECK ONLINE
        if (checkOn)
        {
            try
            {
                Dictionary <string, Object> datax = new Dictionary <string, Object>();
                datax["user"]     = tobase64(iO);
                datax["ruser"]    = tobase64(Cn);
                datax["computer"] = tobase64(Iu.MotherBoard);
                string datapost = tobase64(JsonConvert.SerializeObject(datax));
                string url      = URL + "?par=" + datapost;


                string json = await GetResponse(url).ConfigureAwait(false);

                if (json != null)
                {
                    Dictionary <string, Object> dataen = JsonConvert.DeserializeObject <Dictionary <string, object> >(json);
                    var    keyper = dataen["value"].ToString();
                    var    iv     = "45287112549354892144548565451985";
                    var    key    = "hexdiez822443idx";
                    string ms     = DecryptRJ256(FromBase64String(keyper), key, iv);
                    Dictionary <string, object> response = JsonConvert.DeserializeObject <Dictionary <string, object> >(ms);
                    string dkey = response["u"].ToString();
                    LicenceName = response["x"].ToString();
                    bool isNew = bool.Parse(response["b"].ToString());
                    LicenceManager.TimeLeft = int.Parse(response["a"].ToString());
                    bool a   = LicenceManager.TimeLeft > 0;
                    int  max = int.Parse(response["r"].ToString());
                    if (response["z"].ToString() == "PERMANENT")
                    {
                        type = LICENCETYPE.PERMANENT;
                        a    = true;
                    }
                    else if (response["z"].ToString() == "ADMIN")
                    {
                        type = LICENCETYPE.ADMIN;
                        a    = true;
                    }
                    else
                    {
                        type = LICENCETYPE.TIMED;
                    }

                    LicenceManager.message = response["m"].ToString();
                    isActivated            = iO.Equals(dkey) && a;
                    if (!File.Exists(Xp))
                    {
                        File.WriteAllText(Xp, iO.Substring(0, iO.Length - 5) + "%");
                    }

                    if (isActivated)
                    {
                        Products = JsonConvert.DeserializeObject <int[]>(frombase64(response["p"].ToString()));
                        Licence Licence = new Licence
                        {
                            LicenceName  = LicenceName,
                            HardwereHash = iO,
                            HardwereName = Cn,
                            Products     = Products,
                            MaxTimes     = max,
                            OpenTimes    = 0,
                            Msg          = LicenceManager.message,
                            Type         = (int)type
                        };
                        if (a)
                        {
                            Licence.RecheckTime = Time.timeStampMilisecond + ONE_MINUTE_MILISECOND * 60; //1 hour
                            SaveLicence(Licence);
                            status = LICSTATUS.READY;
                            return(true);
                        }
                        else
                        {
                            status = LICSTATUS.UNACTIVATED;
                        }
                        return(true);
                    }
                    else
                    {
                        status = LICSTATUS.UNACTIVATED;
                    }
                }
                else
                {
                    status = LICSTATUS.UNACTIVATED;
                }

                return(false);
            }
            catch { status = LICSTATUS.UNACTIVATED; return(false); }
        }
        #endregion
        #region OFFLINE
        else
        {
            if (licence == null)
            {
                status = LICSTATUS.UNACTIVATED;
                return(false);
            }
            else
            {
                isActivated            = true;
                Products               = licence.Products;
                LicenceManager.message = licence.Msg;
                LicenceName            = licence.LicenceName;
                type = (LICENCETYPE)licence.Type;
                if (increment)
                {
                    licence.OpenTimes++; //Increment OpenTimes
                }
                SaveLicence(licence);
                status = LICSTATUS.READY;
                return(true);
            }
        }
        #endregion
    }