Esempio n. 1
0
        public int RestoreItem(string tempFolder, System.Xml.XmlNode itemNode, int itemId, Type itemType, string itemName, int packageId, int serviceId, ResourceGroupInfo group)
        {
            if (itemType == typeof(FtpAccount))
            {
                FTPServer ftp = GetFTPServer(serviceId);

                // extract meta item
                XmlSerializer serializer = new XmlSerializer(typeof(FtpAccount));
                FtpAccount    account    = (FtpAccount)serializer.Deserialize(
                    new XmlNodeReader(itemNode.SelectSingleNode("FtpAccount")));

                // create DSN if required
                if (!ftp.AccountExists(itemName))
                {
                    account.Password = CryptoUtils.Decrypt(account.Password);
                    ftp.CreateAccount(account);

                    // restore password
                    account.Password = CryptoUtils.Encrypt(account.Password);
                }

                // add meta-item if required
                if (PackageController.GetPackageItemByName(packageId, itemName, typeof(FtpAccount)) == null)
                {
                    account.PackageId = packageId;
                    account.ServiceId = serviceId;
                    PackageController.AddPackageItem(account);
                }
            }

            return(0);
        }
Esempio n. 2
0
        public static int AddFtpAccount(FtpAccount item)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);

            if (accountCheck < 0)
            {
                return(accountCheck);
            }

            // check package
            int packageCheck = SecurityContext.CheckPackage(item.PackageId, DemandPackage.IsActive);

            if (packageCheck < 0)
            {
                return(packageCheck);
            }

            // check quota
            QuotaValueInfo quota = PackageController.GetPackageQuota(item.PackageId, Quotas.FTP_ACCOUNTS);

            if (quota.QuotaExhausted)
            {
                return(BusinessErrorCodes.ERROR_FTP_RESOURCE_QUOTA_LIMIT);
            }

            // check if FTP account already exists
            int serviceId = PackageController.GetPackageServiceId(item.PackageId, ResourceGroups.Ftp);

            if (serviceId == 0)
            {
                return(BusinessErrorCodes.ERROR_FTP_RESOURCE_UNAVAILABLE);
            }

            // place log record
            TaskManager.StartTask("FTP_ACCOUNT", "ADD", item.Name);
            TaskManager.WriteParameter("Folder", item.Folder);
            TaskManager.WriteParameter("CanRead", item.CanRead);
            TaskManager.WriteParameter("CanWrite", item.CanWrite);


            try
            {
                // check package items
                if (PackageController.GetPackageItemByName(item.PackageId, item.Name, typeof(FtpAccount)) != null)
                {
                    return(BusinessErrorCodes.ERROR_FTP_PACKAGE_ITEM_EXISTS);
                }

                // check service items
                FTPServer ftp = new FTPServer();
                ServiceProviderProxy.Init(ftp, serviceId);
                if (ftp.AccountExists(item.Name))
                {
                    return(BusinessErrorCodes.ERROR_FTP_SERVICE_ITEM_EXISTS);
                }

                // store original path
                string origFolder = item.Folder;

                // convert folder
                StringDictionary ftpSettings = ServerController.GetServiceSettings(serviceId);
                if (Utils.ParseBool(ftpSettings["BuildUncFilesPath"], false))
                {
                    // UNC
                    // get OS service
                    int osServiceId = PackageController.GetPackageServiceId(item.PackageId, ResourceGroups.Os);
                    item.Folder = FilesController.GetFullUncPackagePath(item.PackageId, osServiceId, item.Folder);
                }
                else
                {
                    // Absolute
                    item.Folder = FilesController.GetFullPackagePath(item.PackageId, item.Folder);
                }

                item.Enabled = true;

                // add service item
                ftp.CreateAccount(item);

                // save item
                item.Password  = CryptoUtils.Encrypt(item.Password);
                item.ServiceId = serviceId;
                item.Folder    = (origFolder == "") ? "\\" : origFolder;
                int itemId = PackageController.AddPackageItem(item);
                TaskManager.ItemId = itemId;
                return(itemId);
            }
            catch (Exception ex)
            {
                TaskManager.WriteError(ex);
                throw;
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }