Beispiel #1
0
        // GET: UEditor
        public ContentResult Handle()
        {
            UploadConfig   config = null;
            IUEditorHandle handle = null;
            string         action = Request.Query["action"].ToString();

            switch (action)
            {
            case "config":
                handle = new ConfigHandler();
                break;

            case "uploadimage":
                config = new UploadConfig()
                {
                    AllowExtensions = Config.GetStringList("imageAllowFiles"),
                    PathFormat      = Config.GetString("imagePathFormat"),
                    SizeLimit       = Config.GetInt("imageMaxSize"),
                    UploadFieldName = Config.GetString("imageFieldName")
                };
                handle = new UploadHandle(config);
                break;

            default:
                handle = new NotSupportedHandler();
                break;
            }

            var result     = handle.Process();
            var jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(result);

            return(Content(jsonString));
        }
Beispiel #2
0
        private void FinishFile(UploadHandle handle, string uploadHandle)
        {
            handle.Mac = new byte[16];
            foreach (var chunk in handle.Chunks)
            {
                handle.Mac = handle.Mac.Xor(chunk.Mac);
                handle.Mac = Crypto.Encrypt(handle.AesAlg, handle.Mac);
            }
            PrepareNodeKeys(handle);
            var node = new MegaNode
            {
                Id         = uploadHandle,
                ParentId   = handle.UploadTargetNode,
                Type       = MegaNodeType.File,
                Attributes = new NodeAttributes {
                    Name = handle.Name
                },
                NodeKey = new NodeKeys(handle.NodeKeys, User)
            };
            var r = new MRequestCompleteUpload <MResponseCompleteUpload>(User, node);

            //Console.WriteLine("Sending finish request");
            r.Success += (s, a) =>
            {
                handle.Node = a.NewNode.FirstOrDefault();
                handle.EndTransfer(null);
            };
            r.Error += (s, a) =>
            {
                handle.EndTransfer(a.Error);
            };
            transport.EnqueueRequest(r);
        }
Beispiel #3
0
        public ContentResult Handle()
        {
            IUEditorHandle configHandler = null;
            string         item          = base.Request["action"];
            string         str           = item;

            if (item != null)
            {
                if (str == "config")
                {
                    configHandler = new ConfigHandler();
                    return(base.Content(JsonConvert.SerializeObject(configHandler.Process())));
                }
                else
                {
                    if (str != "uploadimage")
                    {
                        configHandler = new NotSupportedHandler();
                        return(base.Content(JsonConvert.SerializeObject(configHandler.Process())));
                    }
                    UploadConfig uploadConfig = new UploadConfig()
                    {
                        AllowExtensions = Config.GetStringList("imageAllowFiles"),
                        PathFormat      = Config.GetString("imagePathFormat"),
                        SizeLimit       = Config.GetInt("imageMaxSize"),
                        UploadFieldName = Config.GetString("imageFieldName")
                    };
                    configHandler = new UploadHandle(uploadConfig);
                    return(base.Content(JsonConvert.SerializeObject(configHandler.Process())));
                }
            }
            configHandler = new NotSupportedHandler();
            return(base.Content(JsonConvert.SerializeObject(configHandler.Process())));
        }
        // GET: UEditor
        public ContentResult Handle(string action)
        {
            UploadConfig   config = null;
            IUEditorHandle handle = null;

            action = Request["action"];
            switch (action)
            {
            case "config":
                handle = new ConfigHandler();
                break;

            case "uploadimage":
                config = new UploadConfig()
                {
                    AllowExtensions = Config.GetStringList("imageAllowFiles"),
                    PathFormat      = Config.GetString("imagePathFormat"),
                    SizeLimit       = Config.GetInt("imageMaxSize"),
                    UploadFieldName = Config.GetString("imageFieldName")
                };
                handle = new UploadHandle(config);
                break;

            case "uploadtemplateimage":
                var controllerName = Request["areaName"].ToString();
                var shopId         = "0";
                if (controllerName.ToLower().Equals("selleradmin"))
                {
                    ManagerInfo sellerManager = null;
                    //long userId = UserCookieEncryptHelper.Decrypt(WebHelper.GetCookie(CookieKeysCollection.SELLER_MANAGER), "SellerAdmin");
                    string _tmpstr = Request["ShopId"];
                    //if (userId != 0)
                    //{
                    //    sellerManager = ServiceHelper.Create<IManagerService>().GetSellerManager(userId);
                    //}
                    shopId = (string.IsNullOrWhiteSpace(_tmpstr) ? "NonShopID" : _tmpstr);
                }
                config = new UploadConfig()
                {
                    AllowExtensions = Config.GetStringList("templateimageAllowFiles"),
                    PathFormat      = Config.GetString("templateimagePathFormat").Replace("{ShopID}", shopId),
                    SizeLimit       = Config.GetInt("templateimageMaxSize"),
                    UploadFieldName = Config.GetString("templateimageFieldName"),
                    ShopId          = long.Parse(shopId)
                };
                handle = new UploadHandle(config);
                break;

            default:
                handle = new NotSupportedHandler();
                break;
            }

            var result     = handle.Process();
            var jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(result);

            return(Content(jsonString));
        }
Beispiel #5
0
 void PrepareNodeKeys(UploadHandle handle)
 {
     handle.NodeKeys = new byte[32];
     // oook:
     Array.Copy(handle.UploadKey.XorWith(0, handle.UploadKey, 16, 8), handle.NodeKeys, 8);
     Array.Copy(handle.UploadKey, 16, handle.NodeKeys, 16, 8);
     Array.Copy(handle.Mac.XorWith(0, handle.Mac, 4, 4), 0, handle.NodeKeys, 24, 4);
     Array.Copy(handle.Mac.XorWith(8, handle.Mac, 12, 4), 8, handle.NodeKeys, 28, 4);
     // already xored:
     Array.Copy(handle.UploadKey.XorWith(8, handle.Mac, 0, 4), 8, handle.NodeKeys, 8, 4);
     Array.Copy(handle.UploadKey.XorWith(12, handle.Mac, 8, 4), 12, handle.NodeKeys, 12, 4);
 }
Beispiel #6
0
 void PrepareNodeKeys(UploadHandle handle)
 {
     handle.NodeKeys = new byte[32];
     // oook:
     Array.Copy(handle.UploadKey.XorWith(0, handle.UploadKey, 16, 8), handle.NodeKeys, 8);
     Array.Copy(handle.UploadKey, 16, handle.NodeKeys, 16, 8);
     Array.Copy(handle.Mac.XorWith(0, handle.Mac, 4, 4), 0, handle.NodeKeys, 24, 4);
     Array.Copy(handle.Mac.XorWith(8, handle.Mac, 12, 4), 8, handle.NodeKeys, 28, 4);
     // already xored:
     Array.Copy(handle.UploadKey.XorWith(8, handle.Mac, 0, 4), 8, handle.NodeKeys, 8, 4);
     Array.Copy(handle.UploadKey.XorWith(12, handle.Mac, 8, 4), 12, handle.NodeKeys, 12, 4);
 }
Beispiel #7
0
        public static UploadHandle GetHandle(
            Stream fileStream, 
            string name, 
            long fileSize, 
            string targetNode, 
            string uploadUrl,
            string tempPath = null)
        {
            var handle = new UploadHandle(fileStream, name, fileSize, tempPath);

            handle.UploadUrl = uploadUrl;
            handle.UploadTargetNode = targetNode;
            handle.Node = new MegaNode
            {
                Type = MegaNodeType.Dummy,
                Attributes = new NodeAttributes { Name = name }
            };
            return handle;
        }
Beispiel #8
0
        public override void StartTransfer(TransferHandle hndl)
        {
            UploadHandle handle = null;

            try{ handle = (UploadHandle)hndl; }
            catch (InvalidCastException)
            {
                throw new ArgumentException("Only UploadHandle is supported");
            }
            handle.UploadKey = Crypto.RandomKey(24);
            var ul_aes_key = new byte[16];

            Array.Copy(handle.UploadKey, ul_aes_key, 16);
            handle.AesAlg = Crypto.CreateAes(ul_aes_key);
            handle.Nonce  = new byte[8];
            Array.Copy(handle.UploadKey, 16, handle.Nonce, 0, 8);

            EnqueueCrypt(handle.Chunks);
        }
Beispiel #9
0
        public static UploadHandle GetHandle(
            Stream fileStream,
            string name,
            long fileSize,
            string targetNode,
            string uploadUrl,
            string tempPath = null)
        {
            var handle = new UploadHandle(fileStream, name, fileSize, tempPath);

            handle.UploadUrl        = uploadUrl;
            handle.UploadTargetNode = targetNode;
            handle.Node             = new MegaNode
            {
                Type       = MegaNodeType.Dummy,
                Attributes = new NodeAttributes {
                    Name = name
                }
            };
            return(handle);
        }
Beispiel #10
0
 private void FinishFile(UploadHandle handle, string uploadHandle)
 {
     handle.Mac = new byte[16];
     foreach (var chunk in handle.Chunks)
     {
         handle.Mac = handle.Mac.Xor(chunk.Mac);
         handle.Mac = Crypto.Encrypt(handle.AesAlg, handle.Mac);
     }
     PrepareNodeKeys(handle);
     var node = new MegaNode
     {
         Id = uploadHandle,
         ParentId = handle.UploadTargetNode,
         Type = MegaNodeType.File,
         Attributes = new NodeAttributes { Name = handle.Name },
         NodeKey = new NodeKeys(handle.NodeKeys, User)
     };
     var r = new MRequestCompleteUpload<MResponseCompleteUpload>(User, node);
     //Console.WriteLine("Sending finish request");
     r.Success += (s, a) =>
     {
         handle.Node = a.NewNode.FirstOrDefault();
         handle.EndTransfer(null);
     };
     r.Error += (s, a) =>
     {
         handle.EndTransfer(a.Error);
     };
     transport.EnqueueRequest(r);
 }