Пример #1
0
        public Configuration <T> OpenEdit(T fileId, int version, string doc, bool view)
        {
            DocumentServiceHelper.GetParams(fileId, version, doc, true, !view, true, out var configuration);
            configuration.EditorType = EditorType.External;
            if (configuration.EditorConfig.ModeWrite)
            {
                configuration.EditorConfig.CallbackUrl = DocumentServiceTracker.GetCallbackUrl(configuration.Document.Info.GetFile().ID.ToString());
            }

            if (configuration.Document.Info.GetFile().RootFolderType == FolderType.Privacy && PrivacyRoomSettings.GetEnabled(SettingsManager))
            {
                var keyPair = EncryptionKeyPairHelper.GetKeyPair();
                if (keyPair != null)
                {
                    configuration.EditorConfig.EncryptionKeys = new EncryptionKeysConfig
                    {
                        PrivateKeyEnc = keyPair.PrivateKeyEnc,
                        PublicKey     = keyPair.PublicKey,
                    };
                }
            }

            if (!configuration.Document.Info.GetFile().Encrypted&& !configuration.Document.Info.GetFile().ProviderEntry)
            {
                EntryManager.MarkAsRecent(configuration.Document.Info.GetFile());
            }

            configuration.Token = DocumentServiceHelper.GetSignature(configuration);
            return(configuration);
        }
        private void InitScript()
        {
            var inlineScript = new StringBuilder();

            inlineScript.AppendFormat("\nASC.Files.Constants.URL_WCFSERVICE = \"{0}\";" +
                                      "ASC.Files.Constants.DocsAPIundefined = \"{1}\";",
                                      PathProvider.GetFileServicePath,
                                      FilesCommonResource.DocsAPIundefined);

            if (!CoreContext.Configuration.Personal)
            {
                inlineScript.AppendFormat("\nASC.Files.Constants.URL_MAIL_ACCOUNTS = \"{0}\";",
                                          CommonLinkUtility.GetFullAbsolutePath("~/addons/mail/#accounts"));
            }

            var docServiceParams = new DocumentServiceParams
            {
                DocKeyForTrack     = _docKeyForTrack,
                EditByUrl          = _editByUrl,
                LinkToEdit         = _linkToEdit,
                OpenHistory        = RequestVersion != -1 && RequestView && !RequestHistoryClose && _configuration.Document.Info.File.Forcesave == ForcesaveType.None && !_configuration.Document.Info.File.Encrypted,
                OpeninigDate       = DateTime.UtcNow.ToString(CultureInfo.InvariantCulture),
                ShareLinkParam     = string.IsNullOrEmpty(RequestShareLinkKey) ? string.Empty : "&" + FilesLinkUtility.DocShareKey + "=" + RequestShareLinkKey,
                ServerErrorMessage = ErrorMessage,
                TabId            = _tabId.ToString(),
                ThirdPartyApp    = _thirdPartyApp,
                CanGetUsers      = SecurityContext.IsAuthenticated && !CoreContext.Configuration.Personal,
                PageTitlePostfix = GetPageTitlePostfix()
            };

            if (_configuration != null)
            {
                docServiceParams.FileId          = _configuration.Document.Info.File.ID.ToString();
                docServiceParams.FileProviderKey = _configuration.Document.Info.File.ProviderKey;
                docServiceParams.FileVersion     = _configuration.Document.Info.File.Version;

                if (!string.IsNullOrEmpty(FileUtility.SignatureSecret))
                {
                    _configuration.EditorConfig.CallbackUrl = DocumentServiceTracker.GetCallbackUrl(_configuration.Document.Info.File.ID.ToString());
                }

                _configuration.Token = DocumentServiceHelper.GetSignature(_configuration);
            }

            if (Request.DesktopApp() && SecurityContext.IsAuthenticated)
            {
                var user = CoreContext.UserManager.GetUsers(SecurityContext.CurrentAccount.ID);

                docServiceParams.DisplayName = DisplayUserSettings.GetFullUserName(user);
                docServiceParams.Email       = user.Email;
            }

            inlineScript.AppendFormat("\nASC.Files.Editor.docServiceParams = {0};",
                                      DocumentServiceParams.Serialize(docServiceParams));

            inlineScript.AppendFormat("\nASC.Files.Editor.configurationParams = {0};",
                                      Services.DocumentService.Configuration.Serialize(_configuration));

            InlineScripts.Scripts.Add(new Tuple <string, bool>(inlineScript.ToString(), false));
        }
        private void InitScript()
        {
            var inlineScript = new StringBuilder();

            inlineScript.AppendFormat("\nASC.Files.Constants.URL_WCFSERVICE = \"{0}\";",
                                      PathProvider.GetFileServicePath);

            if (!CoreContext.Configuration.Personal)
            {
                inlineScript.AppendFormat("\nASC.Files.Constants.URL_MAIL_ACCOUNTS = \"{0}\";",
                                          CommonLinkUtility.GetFullAbsolutePath("~/addons/mail/#accounts"));
            }

            var docServiceParams = new DocumentServiceParams
            {
                DocKeyForTrack     = _docKeyForTrack,
                EditByUrl          = _editByUrl,
                LinkToEdit         = _linkToEdit,
                OpeninigDate       = DateTime.UtcNow.ToString(CultureInfo.InvariantCulture),
                ShareLinkParam     = string.IsNullOrEmpty(RequestShareLinkKey) ? string.Empty : "&" + FilesLinkUtility.DocShareKey + "=" + RequestShareLinkKey,
                ServerErrorMessage = ErrorMessage,
                TabId         = _tabId.ToString(),
                ThirdPartyApp = _thirdPartyApp,
            };

            if (_configuration != null)
            {
                docServiceParams.FileId          = _configuration.Document.Info.File.ID.ToString();
                docServiceParams.FileProviderKey = _configuration.Document.Info.File.ProviderKey;
                docServiceParams.FileVersion     = _configuration.Document.Info.File.Version;

                _configuration.Token = DocumentServiceHelper.GetSignature(_configuration);

                if (!string.IsNullOrEmpty(_configuration.Token))
                {
                    _configuration.EditorConfig.CallbackUrl = DocumentServiceTracker.GetCallbackUrl(_configuration.Document.Info.File.ID.ToString());
                }
            }

            inlineScript.AppendFormat("\nASC.Files.Editor.docServiceParams = {0};",
                                      DocumentServiceParams.Serialize(docServiceParams));

            inlineScript.AppendFormat("\nASC.Files.Editor.configurationParams = {0};",
                                      Services.DocumentService.Configuration.Serialize(_configuration));

            InlineScripts.Scripts.Add(new Tuple <string, bool>(inlineScript.ToString(), false));
        }
Пример #4
0
        private static void TrackFile(HttpContext context)
        {
            var vkey   = context.Request["vkey"];
            var fileId = Common.Utils.Signature.Read <string>(vkey, StudioKeySettings.GetSKey());

            if (fileId == null)
            {
                Global.Logger.ErrorFormat("DocService track vkey error");
                throw new HttpException((int)HttpStatusCode.Forbidden, FilesCommonResource.ErrorMassage_SecurityException);
            }

            var isNew = (context.Request["new"] ?? "") == "true";

            Global.Logger.Debug("DocService track fileid: " + fileId);
            string body;

            try
            {
                using (var receiveStream = context.Request.InputStream)
                    using (var readStream = new StreamReader(receiveStream))
                    {
                        body = readStream.ReadToEnd();
                    }
            }
            catch (Exception e)
            {
                Global.Logger.Error("DocService track error read body", e);
                throw new HttpException((int)HttpStatusCode.BadRequest, e.Message);
            }

            string error;

            try
            {
                Global.Logger.Debug("DocService track body: " + body);
                error = DocumentServiceTracker.ProcessData(fileId, isNew, body);
            }
            catch (Exception e)
            {
                Global.Logger.Error("DocService track:", e);
                throw new HttpException((int)HttpStatusCode.BadRequest, e.Message);
            }

            context.Response.Write(string.Format("{{\"error\":{0}}}", (error ?? "0")));
        }
Пример #5
0
        public Configuration <T> OpenEdit(T fileId, int version, string doc)
        {
            DocumentServiceHelper.GetParams(fileId, version, doc, true, true, true, out var configuration);
            configuration.EditorType = EditorType.External;
            configuration.EditorConfig.CallbackUrl = DocumentServiceTracker.GetCallbackUrl(configuration.Document.Info.File.ID.ToString());

            if (configuration.Document.Info.File.RootFolderType == FolderType.Privacy && PrivacyRoomSettings.GetEnabled(SettingsManager))
            {
                var keyPair = EncryptionKeyPairHelper.GetKeyPair();
                if (keyPair != null)
                {
                    configuration.EditorConfig.EncryptionKeys = new EncryptionKeysConfig
                    {
                        PrivateKeyEnc = keyPair.PrivateKeyEnc,
                        PublicKey     = keyPair.PublicKey,
                    };
                }
            }


            configuration.Token = DocumentServiceHelper.GetSignature(configuration);
            return(configuration);
        }
Пример #6
0
        private static void TrackFile(HttpContext context)
        {
            var auth   = context.Request[FilesLinkUtility.AuthKey];
            var fileId = context.Request[FilesLinkUtility.FileId];

            Global.Logger.Debug("DocService track fileid: " + fileId);

            var callbackSpan   = TimeSpan.FromDays(128);
            var validateResult = EmailValidationKeyProvider.ValidateEmailKey(fileId, auth ?? "", callbackSpan);

            if (validateResult != EmailValidationKeyProvider.ValidationResult.Ok)
            {
                Global.Logger.ErrorFormat("DocService track auth error: {0}, {1}: {2}", validateResult.ToString(), FilesLinkUtility.AuthKey, auth);
                throw new HttpException((int)HttpStatusCode.Forbidden, FilesCommonResource.ErrorMassage_SecurityException);
            }

            JToken data;

            if (!string.IsNullOrEmpty(FileUtility.SignatureSecret))
            {
                var header = context.Request.Headers[FileUtility.SignatureHeader];
                if (string.IsNullOrEmpty(header) || !header.StartsWith("Bearer "))
                {
                    Global.Logger.Error("DocService track header is null");
                    throw new HttpException((int)HttpStatusCode.Forbidden, FilesCommonResource.ErrorMassage_SecurityException);
                }
                header = header.Substring("Bearer ".Length);

                try
                {
                    JsonWebToken.JsonSerializer = new DocumentService.JwtSerializer();
                    var stringPayload = JsonWebToken.Decode(header, FileUtility.SignatureSecret);

                    Global.Logger.Debug("DocService track payload: " + stringPayload);
                    var jsonPayload = JObject.Parse(stringPayload);
                    data = jsonPayload["payload"];
                }
                catch (SignatureVerificationException ex)
                {
                    Global.Logger.Error("DocService track header", ex);
                    throw new HttpException((int)HttpStatusCode.Forbidden, ex.Message);
                }
            }
            else
            {
                try
                {
                    string body;

                    using (var receiveStream = context.Request.InputStream)
                        using (var readStream = new StreamReader(receiveStream))
                        {
                            body = readStream.ReadToEnd();
                        }

                    Global.Logger.Debug("DocService track body: " + body);
                    if (string.IsNullOrEmpty(body))
                    {
                        throw new ArgumentException("DocService return null");
                    }

                    data = JToken.Parse(body);
                }
                catch (Exception e)
                {
                    Global.Logger.Error("DocService track error read body", e);
                    throw new HttpException((int)HttpStatusCode.BadRequest, e.Message);
                }
            }

            string error;

            try
            {
                if (data == null)
                {
                    throw new ArgumentException("DocService response is incorrect");
                }

                var fileData = data.ToObject <DocumentServiceTracker.TrackerData>();
                error = DocumentServiceTracker.ProcessData(fileId, fileData);
            }
            catch (Exception e)
            {
                Global.Logger.Error("DocService track:", e);
                throw new HttpException((int)HttpStatusCode.BadRequest, e.Message);
            }

            context.Response.Write(string.Format("{{\"error\":{0}}}", (error ?? "0")));
        }