コード例 #1
0
        public static List <string> GetComServerLogs(int comServerId)
        {
            var comServer    = new ServiceClientComServer().GetServer(comServerId);
            var intercomKey  = ServiceSetting.GetSettingValue(SettingStrings.IntercomKeyEncrypted);
            var decryptedKey = new EncryptionServices().DecryptText(intercomKey);

            return(new APICall().ClientComServerApi.GetComServerLogs(comServer.Url, "", decryptedKey));
        }
コード例 #2
0
ファイル: ServiceProvision.cs プロジェクト: theopenem/Toems
        private byte[] GenerateDeviceCert(string symmKey, EntityComputer computer)
        {
            var iCert = new ServiceCertificate().GetIntermediate();

            byte[] symmetricKey;
            using (RSACryptoServiceProvider rsa = (RSACryptoServiceProvider)iCert.PrivateKey)
            {
                var encryptedKey = Convert.FromBase64String(symmKey);
                symmetricKey = rsa.Decrypt(encryptedKey, true);
            }

            var intermediateEntity = new ServiceCertificate().GetIntermediateEntity();
            var pass             = new EncryptionServices().DecryptText(intermediateEntity.Password);
            var intermediateCert = new X509Certificate2(intermediateEntity.PfxBlob, pass, X509KeyStorageFlags.Exportable);
            var certRequest      = new CertificateRequest();
            var organization     = ServiceSetting.GetSettingValue(SettingStrings.CertificateOrganization);

            certRequest.SubjectName = string.Format("O={0},CN={1}", organization, computer.Guid);
            certRequest.NotBefore   = DateTime.UtcNow;
            certRequest.NotAfter    = certRequest.NotBefore.AddYears(10);
            var certificate = new ServiceGenerateCertificate(certRequest).IssueCertificate(intermediateCert, false, false);

            var c = new EntityCertificate();

            c.NotAfter  = certificate.NotAfter;
            c.NotBefore = certificate.NotBefore;
            c.Serial    = certificate.SerialNumber;
            var pfxPass = Membership.GeneratePassword(10, 0);

            c.Password    = new EncryptionServices().EncryptText(pfxPass);
            c.PfxBlob     = certificate.Export(X509ContentType.Pfx, pfxPass);
            c.SubjectName = certificate.Subject;
            c.Type        = EnumCertificate.CertificateType.Device;

            var base64DeviceCert = Convert.ToBase64String(certificate.RawData);
            var encryptedCert    = new ServiceSymmetricEncryption().EncryptData(symmetricKey, base64DeviceCert);

            new ServiceCertificate().AddCertificate(c);
            computer.CertificateId    = c.Id;
            computer.ProvisionStatus  = EnumProvisionStatus.Status.PendingConfirmation;
            computer.SymmKeyEncrypted = new EncryptionServices().EncryptText(Convert.ToBase64String(symmetricKey));

            return(encryptedCert);
        }
コード例 #3
0
        public DtoFreeSpace GetStorageFreeSpace(bool isRemote)
        {
            var storageType = ServiceSetting.GetSettingValue(SettingStrings.StorageType);

            if (storageType.Equals("Local") && isRemote)
            {
                return(null);                                         //no remote share setup
            }
            var dpFreeSpace = new DtoFreeSpace();

            if (isRemote)
            {
                var basePath = ServiceSetting.GetSettingValue(SettingStrings.StoragePath);
                var username = ServiceSetting.GetSettingValue(SettingStrings.StorageUsername);
                var domain   = ServiceSetting.GetSettingValue(SettingStrings.StorageDomain);
                var password = ServiceSetting.GetSettingValue(SettingStrings.StoragePassword);
                dpFreeSpace.dPPath = basePath;
                using (var unc = new UncServices())
                {
                    var smbPassword = new EncryptionServices().DecryptText(password);
                    if (
                        unc.NetUseWithCredentials(basePath, username, domain,
                                                  smbPassword) || unc.LastError == 1219)
                    {
                        ulong freespace = 0;
                        ulong total     = 0;
                        var   success   = DriveFreeBytes(basePath, out freespace, out total);

                        if (!success)
                        {
                            return(null);
                        }

                        var freePercent = 0;
                        var usedPercent = 0;

                        if (total > 0 && freespace > 0)
                        {
                            freePercent = (int)(0.5f + 100f * Convert.ToInt64(freespace) / Convert.ToInt64(total));
                            usedPercent =
                                (int)(0.5f + 100f * Convert.ToInt64(total - freespace) / Convert.ToInt64(total));
                        }
                        dpFreeSpace.freespace   = freespace;
                        dpFreeSpace.total       = total;
                        dpFreeSpace.freePercent = freePercent;
                        dpFreeSpace.usedPercent = usedPercent;
                    }
                    else
                    {
                        log.Error("Failed to connect to " + basePath + "\r\nLastError = " + unc.LastError);
                    }
                }
            }
            else
            {
                string path;
                if (storageType.Equals("Local"))
                {
                    path = ServiceSetting.GetSettingValue(SettingStrings.StoragePath);
                }
                else
                {
                    path = ConfigurationManager.AppSettings["LocalStoragePath"];
                }
                dpFreeSpace.dPPath = path;

                if (Directory.Exists(path))
                {
                    ulong freespace = 0;
                    ulong total     = 0;


                    bool success;

                    success = DriveFreeBytes(path, out freespace, out total);



                    if (!success)
                    {
                        return(null);
                    }

                    var freePercent = 0;
                    var usedPercent = 0;

                    if (total > 0 && freespace > 0)
                    {
                        freePercent = (int)(0.5f + 100f * Convert.ToInt64(freespace) / Convert.ToInt64(total));
                        usedPercent =
                            (int)(0.5f + 100f * Convert.ToInt64(total - freespace) / Convert.ToInt64(total));
                    }
                    dpFreeSpace.freespace   = freespace;
                    dpFreeSpace.total       = total;
                    dpFreeSpace.freePercent = freePercent;
                    dpFreeSpace.usedPercent = usedPercent;
                }
            }

            return(dpFreeSpace);
        }