mirror of
https://github.com/ONLYOFFICE/document-server-integration.git
synced 2026-04-07 14:06:11 +08:00
Compare commits
280 Commits
v7.1.0.89
...
v99.99.99.
| Author | SHA1 | Date | |
|---|---|---|---|
| cda8a86c2a | |||
| 16584c0abb | |||
| 5b76d798fb | |||
| 1bdb3c03bc | |||
| 111dc14f2b | |||
| 4a656c025f | |||
| ce9930e5bc | |||
| 9da22d7803 | |||
| d78c677c99 | |||
| b204142c13 | |||
| fd1c26ab9f | |||
| 5993d10bee | |||
| c5771c9008 | |||
| 2fad227272 | |||
| ada438ff0b | |||
| 0dbd65a577 | |||
| 48e5b8d4e0 | |||
| 7f08a96681 | |||
| 3549b4bc2a | |||
| c9265d9ddc | |||
| 44d9ca88c6 | |||
| d964b43087 | |||
| 5a0debd9e8 | |||
| 3b0f942eee | |||
| 4ee110c2d5 | |||
| ad1d93dd20 | |||
| d2d98df5ab | |||
| 7805f7dc91 | |||
| 51ec27d67c | |||
| 9e94716df0 | |||
| 988a8339b1 | |||
| a482635e3f | |||
| d2c679f6b1 | |||
| 1da452d857 | |||
| d9b8d2b7e9 | |||
| 24aee6d194 | |||
| bd108a9c77 | |||
| e737e8ed48 | |||
| b425d15f0a | |||
| 0f8dec1e6e | |||
| 193b31fe75 | |||
| 583403cf78 | |||
| 641e45e24f | |||
| 53c30fbb7d | |||
| 87a1755729 | |||
| 752a2a2364 | |||
| d1affa2911 | |||
| 0ef2a4f3fd | |||
| 675d3f318a | |||
| 05512ffa23 | |||
| 2eeed5d26d | |||
| 9e3dbd5eb5 | |||
| efbab7c113 | |||
| b8f0f6447c | |||
| 8779a90433 | |||
| b3162ee410 | |||
| 42edd5e208 | |||
| e041baeef7 | |||
| 5bf682a007 | |||
| 6dacf49faa | |||
| 63c9c4242e | |||
| b5e345ed50 | |||
| 33f8436d42 | |||
| c5217242ab | |||
| c910d5193b | |||
| 58c27f8f2f | |||
| 1ec831789b | |||
| 0510fd1354 | |||
| 25238b5614 | |||
| 901bb61883 | |||
| 7f3e6c6364 | |||
| b3512ea0ce | |||
| 642a1bd19a | |||
| ac471588de | |||
| 17674ef5bc | |||
| dc2ee2a997 | |||
| c358fa814a | |||
| 143a73e083 | |||
| c266592434 | |||
| 19ed666d56 | |||
| 84b9202af0 | |||
| 8fb698bb75 | |||
| 00f46ef080 | |||
| 5c194da95d | |||
| 0d5cebe28e | |||
| dacf72cae2 | |||
| 208b8926be | |||
| 55c4853f04 | |||
| ccae7c6a06 | |||
| dc84dd3b29 | |||
| 65d3671b09 | |||
| 1fb5ef8bfd | |||
| b630c3802b | |||
| ad3993b532 | |||
| 35ee61e011 | |||
| ee59ab3dfd | |||
| 500f076e38 | |||
| e578f29d9d | |||
| 9de9bc90a4 | |||
| 7a9ebdbbe5 | |||
| 887089bcad | |||
| 680e53823a | |||
| 33e1489cd6 | |||
| 8c90737bf6 | |||
| e5f1bc8ed6 | |||
| 985b179475 | |||
| 775d15132f | |||
| 4a4298ca10 | |||
| cdbd264ed5 | |||
| e61f6cae89 | |||
| 22039078ef | |||
| 62793a42ab | |||
| f49f96a2c2 | |||
| 2031d65adb | |||
| 7f54659d3b | |||
| a3bc13bb6e | |||
| 29ea16c124 | |||
| 6d4c8b926e | |||
| 22d2031426 | |||
| fcc51e8154 | |||
| 8cd85ad63c | |||
| 1d51688884 | |||
| 2c63a85b00 | |||
| d1545c4db4 | |||
| bd8e4d6ec7 | |||
| e1c815b574 | |||
| 4042d2bb8a | |||
| 8c9d2d80bd | |||
| 3a9259d713 | |||
| 39129a537e | |||
| dfaf552bf8 | |||
| cc8b6f3716 | |||
| 13726b3c2f | |||
| 8bcc15e320 | |||
| 8fca045dd7 | |||
| a018cc5787 | |||
| 054236ef8a | |||
| 05a3110c99 | |||
| e662c765e6 | |||
| 058bb0d2e2 | |||
| 8bafa3ff3a | |||
| 56679a3b75 | |||
| d4d758770f | |||
| ac78d1fc08 | |||
| 874ebff886 | |||
| 070dac6878 | |||
| 4f2f877f0e | |||
| cfa0fb1b74 | |||
| 1d624e6831 | |||
| fe83e98b37 | |||
| f9ea7f7b50 | |||
| 328ea46693 | |||
| 41ec2742a7 | |||
| 76fc55c2d4 | |||
| e10f3962b6 | |||
| b9859ef5ca | |||
| 1cb2b586b1 | |||
| e5d31eebbf | |||
| 1ac40c539f | |||
| 371366befa | |||
| 0bee4817e7 | |||
| ad941e0ba4 | |||
| 93c69e51ed | |||
| 8b8b7d3938 | |||
| f8f01a033e | |||
| f497f10913 | |||
| 8b2478ac71 | |||
| 391c347419 | |||
| 5a08009b7b | |||
| 4e5b65f673 | |||
| 13e3d7673b | |||
| c0a46866ce | |||
| e7b76729a4 | |||
| 5cc6b4cb15 | |||
| 7a70a44bcb | |||
| ce2e7f97d6 | |||
| e42bd53664 | |||
| 23e616aade | |||
| f035da0db4 | |||
| 3e12ec4ebe | |||
| 589ca9b601 | |||
| 32f1ec82d1 | |||
| 54bb5b0a24 | |||
| 8274c16f6d | |||
| 7a982fc785 | |||
| 6f5800fbde | |||
| 8ec632eebd | |||
| b6ca4535ce | |||
| 089fc8bfa0 | |||
| 0b4c17ea0a | |||
| 405be2847b | |||
| f809c7e525 | |||
| 44061c82a9 | |||
| ef4e283804 | |||
| 4b0ad1a192 | |||
| 60469b0dba | |||
| f5ac95e1cc | |||
| c4c2fbb945 | |||
| 99b5fcd562 | |||
| 7e34067410 | |||
| a44787c625 | |||
| 105afb2c34 | |||
| 002f9b958e | |||
| 56d5913808 | |||
| 6664864bed | |||
| 6c9e6e9304 | |||
| 416b1fde8c | |||
| 383f240825 | |||
| 642e145142 | |||
| 8f09dadfa0 | |||
| 495f1cf49a | |||
| cf01b5e0ae | |||
| 0673fed928 | |||
| 9b0b30a0b0 | |||
| 200187edce | |||
| 23176ddf07 | |||
| 9857cef8fc | |||
| 204f770401 | |||
| 61834e3ec6 | |||
| 2ca6185ac4 | |||
| e818bb978b | |||
| 3a4cf5e6e6 | |||
| 7ec16b90e3 | |||
| fcfb6efda7 | |||
| e4c72c98d1 | |||
| c2bbda542a | |||
| 2c12393c78 | |||
| 4e93f6ebac | |||
| d10ba9f773 | |||
| a0bf7db118 | |||
| e40e7cc41c | |||
| f616655f4c | |||
| 4ba708631e | |||
| b9c1bc0f42 | |||
| 215ade01a3 | |||
| 4d25418fc8 | |||
| 4539bac5db | |||
| eb196613e7 | |||
| 7ac788f589 | |||
| 55119458af | |||
| 3c18add1fc | |||
| 6bf63b7166 | |||
| 32df2d3e34 | |||
| 97c7859db5 | |||
| 492f9c7baa | |||
| e0c0595796 | |||
| 40b8fb88a8 | |||
| b0df0d72df | |||
| 1053add1d9 | |||
| f1fc0e5fae | |||
| a192c6ce1f | |||
| e8aec0b68c | |||
| d9667f9757 | |||
| 3a985da120 | |||
| a88f84ddac | |||
| 6525d7210f | |||
| 6b93311ce5 | |||
| 999561ffd6 | |||
| e539c1205f | |||
| 9a52a538cb | |||
| e8038a8e88 | |||
| 1045b314b6 | |||
| 1636732521 | |||
| daa9a5f3fa | |||
| 9bf3973215 | |||
| cad2a20cdf | |||
| 82a5a68e6c | |||
| 0e1a580a86 | |||
| c09f3fc4b9 | |||
| d4d7c4e222 | |||
| 14429c5b05 | |||
| 131e33c6af | |||
| 8a04e5fbc4 | |||
| 1b6435a7dc | |||
| b8eecab45f | |||
| f7259409a2 | |||
| 0ea9e68c7c | |||
| 4b72e0a664 | |||
| 935377a941 | |||
| 3690aacb66 |
41
CHANGELOG.md
Normal file
41
CHANGELOG.md
Normal file
@ -0,0 +1,41 @@
|
||||
# Change Log
|
||||
|
||||
- nodejs: referenceData
|
||||
|
||||
## 1.4.0
|
||||
- nodejs: option to send directUrl
|
||||
- opening file on client by directUrl
|
||||
- offline viewer for anonymous
|
||||
- added hy, eu, zh-TW, ms, pt-PT
|
||||
|
||||
## 1.3.1
|
||||
- charp: fix references
|
||||
- ruby: update rails
|
||||
|
||||
## 1.3.0
|
||||
- update empty files
|
||||
- anonymous without chat
|
||||
- changed jwt implementation in csharp, csharp-mvc, php, ruby
|
||||
|
||||
## 1.2.0
|
||||
- ruby v3.0
|
||||
- set filetype in setHistoryData
|
||||
- read filetype from input request
|
||||
- creating file on WOPI
|
||||
- upload on WOPI page
|
||||
- fix xss
|
||||
- set userInfoGroups
|
||||
- check JWT on downloading history
|
||||
- upload dialog on mobile
|
||||
- anonymous without id
|
||||
- renaming from editor
|
||||
- new skin languages
|
||||
- ignore certificate
|
||||
|
||||
## 1.1.0
|
||||
- creating docxf
|
||||
- opening docxf, oform
|
||||
|
||||
|
||||
## 1.0.0
|
||||
- added java spring
|
||||
@ -67,6 +67,15 @@ The methods described below are available for all of the test examples.
|
||||
| **Response** | **Code:** 200 OK <br />**Content on success:**<br /> `[{ "version": <file_version>, "id": <file_id>, "contentLength": <file_size_in_kilobytes>, "pureContentLength": <file_size_in_bytes>, "title": <file_name>, "updated": <last_change_date>}]`<br />**Content on error:**<br /> `"File not found"` |
|
||||
| **Sample** | `curl -X GET http://localhost/files/{fileId}` |
|
||||
|
||||
## Important security info
|
||||
|
||||
Please keep in mind the following security aspects when you are using test examples:
|
||||
|
||||
* There is no protection of the storage from unauthorized access since there is no need for authorization.
|
||||
* There are no checks against parameter substitution in links, since the parameters are generated by the code according to the pre-arranged scripts.
|
||||
* There are no data checks in requests of saving the file after editing, since each test example is intended for requests only from ONLYOFFICE Document Server.
|
||||
* There are no prohibitions on using test examples from other sites, since they are intended to interact with ONLYOFFICE Document Server from another domain.
|
||||
|
||||
## Project Information
|
||||
|
||||
Official website: [https://www.onlyoffice.com](https://www.onlyoffice.com/?utm_source=github&utm_medium=cpc&utm_campaign=GitHubIntegrationEx)
|
||||
|
||||
@ -24,11 +24,15 @@ jQuery.UI - jQuery UI is an open source library of interface components —
|
||||
License: MIT
|
||||
License File: jQuery.UI.license
|
||||
|
||||
JWT - JWT (JSON Web Token) Implementation for .NET (Public Domain) (https://github.com/jwt-dotnet/jwt/)
|
||||
License: MIT
|
||||
License File: JWT.license
|
||||
|
||||
Microsoft.Web.Infrastructure - This package contains the Microsoft.Web.Infrastructure assembly that lets you dynamically register HTTP modules at run time. (https://www.microsoft.com/web/webpi/eula/aspnetmvc3update-eula.htm)
|
||||
License: MS-EULA License
|
||||
License File: Microsoft.Web.Infrastructure.license
|
||||
|
||||
Newtonsoft.Json - Json.NET is a popular high-performance JSON framework for .NET (https://licenses.nuget.org/MIT)
|
||||
Newtonsoft.Json - Json.NET is a popular high-performance JSON framework for .NET (https://github.com/JamesNK/Newtonsoft.Json)
|
||||
License: MIT
|
||||
License File: Newtonsoft.Json.license
|
||||
|
||||
|
||||
@ -25,6 +25,7 @@ using System.Web;
|
||||
using System.Web.Configuration;
|
||||
using System.Web.Script.Serialization;
|
||||
using OnlineEditorsExampleMVC.Models;
|
||||
using System.Net;
|
||||
|
||||
namespace OnlineEditorsExampleMVC.Helpers
|
||||
{
|
||||
@ -241,7 +242,8 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
{
|
||||
var uri = new UriBuilder(GetServerUrl(forDocumentServer))
|
||||
{
|
||||
Path = HttpRuntime.AppDomainAppVirtualPath + "/"
|
||||
Path = HttpRuntime.AppDomainAppVirtualPath
|
||||
+ (HttpRuntime.AppDomainAppVirtualPath.EndsWith("/") ? "" : "/")
|
||||
+ CurUserHostAddress() + "/"
|
||||
+ fileName,
|
||||
Query = ""
|
||||
@ -291,7 +293,7 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
+ "webeditor.ashx",
|
||||
Query = "type=track"
|
||||
+ "&fileName=" + HttpUtility.UrlEncode(fileName)
|
||||
+ "&userAddress=" + HttpUtility.UrlEncode(HttpContext.Current.Request.UserHostAddress)
|
||||
+ "&userAddress=" + HttpUtility.UrlEncode(CurUserHostAddress(HttpContext.Current.Request.UserHostAddress))
|
||||
};
|
||||
return callbackUrl.ToString();
|
||||
}
|
||||
@ -311,9 +313,10 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
}
|
||||
|
||||
// create the public history url
|
||||
public static string GetHistoryDownloadUrl(string filename, string version, string file)
|
||||
public static string GetHistoryDownloadUrl(string filename, string version, string file, Boolean isServer = true)
|
||||
{
|
||||
var downloadUrl = new UriBuilder(GetServerUrl(true))
|
||||
var userAddress = "&userAddress=" + HttpUtility.UrlEncode(CurUserHostAddress(HttpContext.Current.Request.UserHostAddress));
|
||||
var downloadUrl = new UriBuilder(GetServerUrl(isServer))
|
||||
{
|
||||
Path =
|
||||
HttpRuntime.AppDomainAppVirtualPath
|
||||
@ -321,7 +324,7 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
+ "webeditor.ashx",
|
||||
Query = "type=downloadhistory"
|
||||
+ "&fileName=" + HttpUtility.UrlEncode(filename)
|
||||
+ "&userAddress=" + HttpUtility.UrlEncode(HttpContext.Current.Request.UserHostAddress)
|
||||
+ userAddress
|
||||
+ "&ver=" + version
|
||||
+ "&file="+ file
|
||||
};
|
||||
@ -329,9 +332,10 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
}
|
||||
|
||||
// get url to download a file
|
||||
public static string GetDownloadUrl(string fileName)
|
||||
public static string GetDownloadUrl(string fileName, Boolean isServer = true)
|
||||
{
|
||||
var downloadUrl = new UriBuilder(GetServerUrl(true))
|
||||
var userAddress = isServer ? "&userAddress=" + HttpUtility.UrlEncode(CurUserHostAddress(HttpContext.Current.Request.UserHostAddress)) : "";
|
||||
var downloadUrl = new UriBuilder(GetServerUrl(isServer))
|
||||
{
|
||||
Path =
|
||||
HttpRuntime.AppDomainAppVirtualPath
|
||||
@ -339,7 +343,7 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
+ "webeditor.ashx",
|
||||
Query = "type=download"
|
||||
+ "&fileName=" + HttpUtility.UrlEncode(fileName)
|
||||
+ "&userAddress=" + HttpUtility.UrlEncode(HttpContext.Current.Request.UserHostAddress)
|
||||
+ userAddress
|
||||
};
|
||||
return downloadUrl.ToString();
|
||||
}
|
||||
@ -416,5 +420,27 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
// enable certificate ignore
|
||||
public static void VerifySSL()
|
||||
{
|
||||
// hack. http://ubuntuforums.org/showthread.php?t=1841740
|
||||
if(WebConfigurationManager.AppSettings["files.docservice.verify-peer-off"].Equals("true")) {
|
||||
ServicePointManager.ServerCertificateValidationCallback += (s, ce, ca, p) => true;
|
||||
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
|
||||
}
|
||||
}
|
||||
|
||||
public static Dictionary<string, string> GetLanguages()
|
||||
{
|
||||
var languages = new Dictionary<string, string>();
|
||||
String[] couples = (WebConfigurationManager.AppSettings["files.docservice.languages"] ?? "").Split('|');
|
||||
foreach (string couple in couples)
|
||||
{
|
||||
String[] tmp = couple.Split(':');
|
||||
languages.Add(tmp[0],tmp[1]);
|
||||
}
|
||||
return languages;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -143,6 +143,8 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
requestStream.Write(bytes, 0, bytes.Length); // and write the serialized body object to it
|
||||
}
|
||||
|
||||
DocManagerHelper.VerifySSL();
|
||||
|
||||
string dataResponse;
|
||||
using (var response = request.GetResponse())
|
||||
using (var stream = response.GetResponseStream()) // get the response stream
|
||||
|
||||
@ -16,12 +16,12 @@
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using JWT;
|
||||
using JWT.Algorithms;
|
||||
using JWT.Builder;
|
||||
using JWT.Serializers;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Web.Configuration;
|
||||
using System.Web.Script.Serialization;
|
||||
|
||||
namespace OnlineEditorsExampleMVC.Helpers
|
||||
{
|
||||
@ -30,31 +30,19 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
private static readonly string Secret;
|
||||
public static readonly bool Enabled;
|
||||
|
||||
private static readonly JavaScriptSerializer Serializer;
|
||||
|
||||
static JwtManager()
|
||||
{
|
||||
Secret = WebConfigurationManager.AppSettings["files.docservice.secret"] ?? ""; // get token secret from the config parameters
|
||||
Enabled = !string.IsNullOrEmpty(Secret); // check if the token is enabled
|
||||
Serializer = new JavaScriptSerializer(); // define java script serializer
|
||||
}
|
||||
|
||||
// encode a payload object into a token using a secret key
|
||||
public static string Encode(IDictionary<string, object> payload)
|
||||
{
|
||||
// define the hashing algorithm and the token type
|
||||
var header = new Dictionary<string, object>
|
||||
{
|
||||
{ "alg", "HS256" },
|
||||
{ "typ", "JWT" }
|
||||
};
|
||||
|
||||
// three parts of token
|
||||
var encHeader = Base64UrlEncode(Serializer.Serialize(header)); // header
|
||||
var encPayload = Base64UrlEncode(Serializer.Serialize(payload)); // payload
|
||||
var hashSum = Base64UrlEncode(CalculateHash(encHeader, encPayload)); // signature
|
||||
|
||||
return string.Format("{0}.{1}.{2}", encHeader, encPayload, hashSum);
|
||||
var encoder = new JwtEncoder(new HMACSHA256Algorithm(),
|
||||
new JsonNetSerializer(),
|
||||
new JwtBase64UrlEncoder());
|
||||
return encoder.Encode(payload, Secret);
|
||||
}
|
||||
|
||||
// decode a token into a payload object using a secret key
|
||||
@ -62,52 +50,11 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
{
|
||||
if (!Enabled || string.IsNullOrEmpty(token)) return "";
|
||||
|
||||
var split = token.Split('.');
|
||||
if (split.Length != 3) return "";
|
||||
|
||||
var hashSum = Base64UrlEncode(CalculateHash(split[0], split[1])); // get signature
|
||||
if (hashSum != split[2]) return ""; // and check if it is equal to the signature from the token
|
||||
return Base64UrlDecode(split[1]); // decode payload
|
||||
}
|
||||
|
||||
// generate a hash code based on a key using the HMAC method
|
||||
private static byte[] CalculateHash(string encHeader, string encPayload)
|
||||
{
|
||||
using (var hasher = new HMACSHA256(Encoding.UTF8.GetBytes(Secret)))
|
||||
{
|
||||
var bytes = Encoding.UTF8.GetBytes(string.Format("{0}.{1}", encHeader, encPayload));
|
||||
return hasher.ComputeHash(bytes);
|
||||
}
|
||||
}
|
||||
|
||||
// encode a string into the base64 value
|
||||
private static string Base64UrlEncode(string str)
|
||||
{
|
||||
return Base64UrlEncode(Encoding.UTF8.GetBytes(str));
|
||||
}
|
||||
|
||||
// encode bytes into the base64 value
|
||||
private static string Base64UrlEncode(byte[] bytes)
|
||||
{
|
||||
return Convert.ToBase64String(bytes)
|
||||
.TrimEnd('=').Replace('+', '-').Replace('/', '_');
|
||||
}
|
||||
|
||||
// decode a base64 value into the string
|
||||
private static string Base64UrlDecode(string payload)
|
||||
{
|
||||
var b64 = payload.Replace('_', '/').Replace('-', '+');
|
||||
switch (b64.Length%4)
|
||||
{
|
||||
case 2:
|
||||
b64 += "==";
|
||||
break;
|
||||
case 3:
|
||||
b64 += "=";
|
||||
break;
|
||||
}
|
||||
var bytes = Convert.FromBase64String(b64);
|
||||
return Encoding.UTF8.GetString(bytes);
|
||||
return JwtBuilder.Create()
|
||||
.WithAlgorithm(new HMACSHA256Algorithm())
|
||||
.WithSecret(Secret)
|
||||
.MustVerifySignature()
|
||||
.Decode(token);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -76,7 +76,9 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
|
||||
if (token != null && !token.Equals("")) // invalid signature error
|
||||
{
|
||||
fileData = (Dictionary<string, object>)jss.Deserialize<Dictionary<string, object>>(token)["payload"];
|
||||
fileData = jss.Deserialize<Dictionary<string, object>>(token);
|
||||
if (fileData.ContainsKey("payload"))
|
||||
fileData = (Dictionary<string, object>)fileData["payload"];
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -126,6 +128,8 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
}
|
||||
}
|
||||
|
||||
DocManagerHelper.VerifySSL();
|
||||
|
||||
var storagePath = DocManagerHelper.StoragePath(newFileName, userAddress); // get the file path
|
||||
var histDir = DocManagerHelper.HistoryDir(storagePath); // get the path to the history directory
|
||||
if (!Directory.Exists(histDir)) Directory.CreateDirectory(histDir);
|
||||
@ -201,6 +205,8 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
}
|
||||
}
|
||||
|
||||
DocManagerHelper.VerifySSL();
|
||||
|
||||
string forcesavePath = "";
|
||||
Boolean isSubmitForm = fileData["forcesavetype"].ToString().Equals("3"); // SubmitForm
|
||||
|
||||
@ -243,8 +249,10 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
}
|
||||
|
||||
// create a command request
|
||||
public static void commandRequest(string method, string key)
|
||||
public static void commandRequest(string method, string key, object meta = null)
|
||||
{
|
||||
DocManagerHelper.VerifySSL();
|
||||
|
||||
string documentCommandUrl = WebConfigurationManager.AppSettings["files.docservice.url.site"] + WebConfigurationManager.AppSettings["files.docservice.url.command"];
|
||||
|
||||
var request = (HttpWebRequest)WebRequest.Create(documentCommandUrl);
|
||||
@ -256,6 +264,11 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
{ "key", key }
|
||||
};
|
||||
|
||||
if (meta != null)
|
||||
{
|
||||
body.Add("meta", meta);
|
||||
}
|
||||
|
||||
// check if a secret key to generate token exists or not
|
||||
if (JwtManager.Enabled)
|
||||
{
|
||||
|
||||
@ -66,7 +66,10 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
"The file favorite state is undefined",
|
||||
"Can't mention others in comments",
|
||||
"Can't create new files from the editor",
|
||||
"Can’t see anyone’s information"
|
||||
"Can’t see anyone’s information",
|
||||
"Can't rename files from the editor",
|
||||
"Can't view chat",
|
||||
"View file without collaboration",
|
||||
};
|
||||
|
||||
private static List<User> users = new List<User>() {
|
||||
|
||||
61
web/documentserver-example/csharp-mvc/Models/FileModel.cs
Normal file → Executable file
61
web/documentserver-example/csharp-mvc/Models/FileModel.cs
Normal file → Executable file
@ -97,6 +97,7 @@ namespace OnlineEditorsExampleMVC.Models
|
||||
var actionLink = request.GetOrDefault("actionLink", null); // get the action link (comment or bookmark) if it exists
|
||||
var actionData = string.IsNullOrEmpty(actionLink) ? null : jss.DeserializeObject(actionLink); // get action data for the action link
|
||||
|
||||
var directUrl = DocManagerHelper.GetDownloadUrl(FileName, false);
|
||||
var createUrl = DocManagerHelper.GetCreateUrl(FileUtility.GetFileType(FileName));
|
||||
var templatesImageUrl = DocManagerHelper.GetTemplateImageUrl(FileUtility.GetFileType(FileName)); // image url for templates
|
||||
var templates = new List<Dictionary<string, string>>
|
||||
@ -125,6 +126,7 @@ namespace OnlineEditorsExampleMVC.Models
|
||||
{
|
||||
{ "title", FileName },
|
||||
{ "url", DownloadUrl },
|
||||
{ "directUrl", directUrl },
|
||||
{ "fileType", ext.Trim('.') },
|
||||
{ "key", Key },
|
||||
{
|
||||
@ -148,6 +150,7 @@ namespace OnlineEditorsExampleMVC.Models
|
||||
{ "modifyFilter", editorsMode != "filter" },
|
||||
{ "modifyContentControl", editorsMode != "blockcontent" },
|
||||
{ "review", canEdit && (editorsMode == "edit" || editorsMode == "review") },
|
||||
{ "chat", !user.id.Equals("uid-0") },
|
||||
{ "reviewGroups", user.reviewGroups },
|
||||
{ "commentGroups", user.commentGroups },
|
||||
{ "userInfoGroups", user.userInfoGroups }
|
||||
@ -162,6 +165,11 @@ namespace OnlineEditorsExampleMVC.Models
|
||||
{ "mode", mode },
|
||||
{ "lang", request.Cookies.GetOrDefault("ulang", "en") },
|
||||
{ "callbackUrl", CallbackUrl }, // absolute URL to the document storage service
|
||||
{ "coEditing", editorsMode == "view" && user.id.Equals("uid-0") ?
|
||||
new Dictionary<string, object>{
|
||||
{"mode", "strict"},
|
||||
{"change", false}
|
||||
} : null },
|
||||
{ "createUrl", !user.id.Equals("uid-0") ? createUrl : null },
|
||||
{ "templates", user.templates ? templates : null },
|
||||
{
|
||||
@ -177,9 +185,9 @@ namespace OnlineEditorsExampleMVC.Models
|
||||
// the parameters for the embedded document type
|
||||
"embedded", new Dictionary<string, object>
|
||||
{
|
||||
{ "saveUrl", FileUriUser }, // the absolute URL that will allow the document to be saved onto the user personal computer
|
||||
{ "embedUrl", FileUriUser }, // the absolute URL to the document serving as a source file for the document embedded into the web page
|
||||
{ "shareUrl", FileUriUser }, // the absolute URL that will allow other users to share this document
|
||||
{ "saveUrl", directUrl }, // the absolute URL that will allow the document to be saved onto the user personal computer
|
||||
{ "embedUrl", directUrl }, // the absolute URL to the document serving as a source file for the document embedded into the web page
|
||||
{ "shareUrl", directUrl }, // the absolute URL that will allow other users to share this document
|
||||
{ "toolbarDocked", "top" } // the place for the embedded viewer toolbar (top or bottom)
|
||||
}
|
||||
},
|
||||
@ -188,13 +196,14 @@ namespace OnlineEditorsExampleMVC.Models
|
||||
"customization", new Dictionary<string, object>
|
||||
{
|
||||
{ "about", true }, // the About section display
|
||||
{ "comments", true },
|
||||
{ "feedback", true }, // the Feedback & Support menu button display
|
||||
{ "forcesave", false }, // adds the request for the forced file saving to the callback handler
|
||||
{ "submitForm", submitForm }, // if the Submit form button is displayed or not
|
||||
{
|
||||
"goback", new Dictionary<string, object> // settings for the Open file location menu button and upper right corner button
|
||||
{
|
||||
{ "url", url.Action("Index", "Home") } // the absolute URL to the website address which will be opened when clicking the Open file location menu button
|
||||
{ "url", DocManagerHelper.GetServerUrl(false) } // the absolute URL to the website address which will be opened when clicking the Open file location menu button
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -261,17 +270,23 @@ namespace OnlineEditorsExampleMVC.Models
|
||||
dataObj.Add("key", key);
|
||||
// write file url to the data object
|
||||
string prevFileUrl;
|
||||
string directPrevFileUrl;
|
||||
if (Path.IsPathRooted(storagePath) && !string.IsNullOrEmpty(storagePath))
|
||||
{
|
||||
prevFileUrl = i == currentVersion ? DocManagerHelper.GetHistoryDownloadUrl(FileName, i.ToString(), "prev" + ext)
|
||||
: DocManagerHelper.GetDownloadUrl(Directory.GetFiles(verDir, "prev.*")[0].Replace(storagePath + "\\", ""));
|
||||
directPrevFileUrl = i == currentVersion ? DocManagerHelper.GetHistoryDownloadUrl(FileName, i.ToString(), "prev" + ext, false)
|
||||
: DocManagerHelper.GetDownloadUrl(Directory.GetFiles(verDir, "prev.*")[0].Replace(storagePath + "\\", ""), false);
|
||||
}
|
||||
else {
|
||||
prevFileUrl = i == currentVersion ? FileUri
|
||||
: DocManagerHelper.GetHistoryDownloadUrl(FileName, i.ToString(), "prev" + ext);
|
||||
prevFileUrl = i == currentVersion ? FileUri
|
||||
: DocManagerHelper.GetHistoryDownloadUrl(FileName, i.ToString(), "prev" + ext);
|
||||
directPrevFileUrl = i == currentVersion ? DocManagerHelper.GetHistoryDownloadUrl(FileName, i.ToString(), "prev" + ext, false)
|
||||
: DocManagerHelper.GetDownloadUrl(Directory.GetFiles(verDir, "prev.*")[0].Replace(storagePath + "\\", ""), false);
|
||||
}
|
||||
|
||||
dataObj.Add("url", prevFileUrl);
|
||||
dataObj.Add("directUrl", directPrevFileUrl);
|
||||
dataObj.Add("version", i);
|
||||
if (i > 1) // check if the version number is greater than 1 (the file was modified)
|
||||
{
|
||||
@ -293,6 +308,7 @@ namespace OnlineEditorsExampleMVC.Models
|
||||
{ "fileType", prev["fileType"] },
|
||||
{ "key", prev["key"] }, // write key and url information about previous file version
|
||||
{ "url", prev["url"] },
|
||||
{ "directUrl", prev["directUrl"] },
|
||||
});
|
||||
// write the path to the diff.zip archive with differences in this file version
|
||||
var changesUrl = DocManagerHelper.GetHistoryDownloadUrl(FileName, (i - 1).ToString(), "diff.zip");
|
||||
@ -331,11 +347,20 @@ namespace OnlineEditorsExampleMVC.Models
|
||||
Query = "type=assets&fileName=" + HttpUtility.UrlEncode("sample.docx")
|
||||
};
|
||||
|
||||
var directCompareFileUrl = new UriBuilder(DocManagerHelper.GetServerUrl(false))
|
||||
{
|
||||
Path = HttpRuntime.AppDomainAppVirtualPath
|
||||
+ (HttpRuntime.AppDomainAppVirtualPath.EndsWith("/") ? "" : "/")
|
||||
+ "webeditor.ashx",
|
||||
Query = "type=assets&fileName=" + HttpUtility.UrlEncode("sample.docx")
|
||||
};
|
||||
|
||||
// create an object with the information about the compared file
|
||||
var dataCompareFile = new Dictionary<string, object>
|
||||
{
|
||||
{ "fileType", "docx" },
|
||||
{ "url", compareFileUrl.ToString() }
|
||||
{ "url", compareFileUrl.ToString() },
|
||||
{ "directUrl", directCompareFileUrl.ToString()}
|
||||
};
|
||||
|
||||
if (JwtManager.Enabled) // if the secret key to generate token exists
|
||||
@ -360,11 +385,19 @@ namespace OnlineEditorsExampleMVC.Models
|
||||
+ "Content\\images\\logo.png"
|
||||
};
|
||||
|
||||
var directMailMergeUrl = new UriBuilder(DocManagerHelper.GetServerUrl(false))
|
||||
{
|
||||
Path = HttpRuntime.AppDomainAppVirtualPath
|
||||
+ (HttpRuntime.AppDomainAppVirtualPath.EndsWith("/") ? "" : "/")
|
||||
+ "Content\\images\\logo.png"
|
||||
};
|
||||
|
||||
// create a logo config
|
||||
var logoConfig = new Dictionary<string, object>
|
||||
{
|
||||
{ "fileType", "png"},
|
||||
{ "url", mailMergeUrl.ToString()}
|
||||
{ "url", mailMergeUrl.ToString()},
|
||||
{ "directUrl", directMailMergeUrl.ToString()}
|
||||
};
|
||||
|
||||
if (JwtManager.Enabled) // if the secret key to generate token exists
|
||||
@ -391,11 +424,21 @@ namespace OnlineEditorsExampleMVC.Models
|
||||
Query = "type=csv"
|
||||
};
|
||||
|
||||
var directMailMergeUrl = new UriBuilder(DocManagerHelper.GetServerUrl(false))
|
||||
{
|
||||
Path =
|
||||
HttpRuntime.AppDomainAppVirtualPath
|
||||
+ (HttpRuntime.AppDomainAppVirtualPath.EndsWith("/") ? "" : "/")
|
||||
+ "webeditor.ashx",
|
||||
Query = "type=csv"
|
||||
};
|
||||
|
||||
// create a mail merge config
|
||||
var mailMergeConfig = new Dictionary<string, object>
|
||||
{
|
||||
{ "fileType", "csv" },
|
||||
{ "url", mailMergeUrl.ToString()}
|
||||
{ "url", mailMergeUrl.ToString()},
|
||||
{ "directUrl", directMailMergeUrl.ToString()}
|
||||
};
|
||||
|
||||
if (JwtManager.Enabled) // if the secret key to generate token exists
|
||||
|
||||
@ -43,6 +43,9 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="JWT, Version=9.0.0.0, Culture=neutral, PublicKeyToken=6f98bca0f40f2ecf, processorArchitecture=MSIL">
|
||||
<HintPath>packages\JWT.9.0.3\lib\net46\JWT.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||
@ -50,49 +53,49 @@
|
||||
<Reference Include="System.Web" />
|
||||
<Reference Include="System.Web.Extensions" />
|
||||
<Reference Include="System.Web.Services" />
|
||||
<Reference Include="Antlr3.Runtime">
|
||||
<Reference Include="Antlr3.Runtime, Version=3.5.0.2, Culture=neutral, PublicKeyToken=eb42632606e9261f, processorArchitecture=MSIL">
|
||||
<HintPath>packages\Antlr.3.5.0.2\lib\Antlr3.Runtime.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="EntityFramework">
|
||||
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
|
||||
<HintPath>packages\EntityFramework.6.4.4\lib\net45\EntityFramework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Web.Infrastructure">
|
||||
<Reference Include="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json">
|
||||
<HintPath>packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Net.Http.Formatting">
|
||||
<Reference Include="System.Net.Http.Formatting, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>packages\Microsoft.AspNet.WebApi.Client.5.2.7\lib\net45\System.Net.Http.Formatting.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.Helpers">
|
||||
<Reference Include="System.Web.Helpers, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.Helpers.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.Http">
|
||||
<Reference Include="System.Web.Http, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>packages\Microsoft.AspNet.WebApi.Core.5.2.7\lib\net45\System.Web.Http.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.Http.WebHost">
|
||||
<Reference Include="System.Web.Http.WebHost, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>packages\Microsoft.AspNet.WebApi.WebHost.5.2.7\lib\net45\System.Web.Http.WebHost.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.Mvc">
|
||||
<Reference Include="System.Web.Mvc, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>packages\Microsoft.AspNet.Mvc.5.2.7\lib\net45\System.Web.Mvc.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.Optimization">
|
||||
<Reference Include="System.Web.Optimization, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>packages\Microsoft.AspNet.Web.Optimization.1.1.3\lib\net40\System.Web.Optimization.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.Razor">
|
||||
<Reference Include="System.Web.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>packages\Microsoft.AspNet.Razor.3.2.7\lib\net45\System.Web.Razor.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.WebPages">
|
||||
<Reference Include="System.Web.WebPages, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.WebPages.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.WebPages.Deployment">
|
||||
<Reference Include="System.Web.WebPages.Deployment, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.WebPages.Deployment.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.WebPages.Razor">
|
||||
<Reference Include="System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.WebPages.Razor.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="WebGrease">
|
||||
<Reference Include="WebGrease, Version=1.6.5135.21930, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>packages\WebGrease.1.6.0\lib\WebGrease.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
@ -182,10 +185,12 @@
|
||||
<Content Include="assets\AUTHORS.md" />
|
||||
<Content Include="assets\LICENSE" />
|
||||
<Content Include="assets\new\new.docx" />
|
||||
<Content Include="assets\new\new.docxf" />
|
||||
<Content Include="assets\new\new.pptx" />
|
||||
<Content Include="assets\new\new.xlsx" />
|
||||
<Content Include="assets\sample\csv.csv" />
|
||||
<Content Include="assets\sample\sample.docx" />
|
||||
<Content Include="assets\sample\sample.docxf" />
|
||||
<Content Include="assets\sample\sample.pptx" />
|
||||
<Content Include="assets\sample\sample.xlsx" />
|
||||
<None Include="packages.config" />
|
||||
|
||||
@ -70,3 +70,12 @@ Configure the IIS components for the server to work correctly:
|
||||
In case the example and Document Server are installed on different computers, make sure that your server with the example installed has access to the Document Server with the address which you specify instead of **documentserver** in the configuration files.
|
||||
|
||||
Make sure that the Document Server has access to the server with the example installed with the address which you specify instead of **example.com** in the configuration files.
|
||||
|
||||
## Important security info
|
||||
|
||||
Please keep in mind the following security aspects when you are using test examples:
|
||||
|
||||
* There is no protection of the storage from unauthorized access since there is no need for authorization.
|
||||
* There are no checks against parameter substitution in links, since the parameters are generated by the code according to the pre-arranged scripts.
|
||||
* There are no data checks in requests of saving the file after editing, since each test example is intended for requests only from ONLYOFFICE Document Server.
|
||||
* There are no prohibitions on using test examples from other sites, since they are intended to interact with ONLYOFFICE Document Server from another domain.
|
||||
@ -46,6 +46,7 @@
|
||||
<script type="text/javascript" language="javascript">
|
||||
|
||||
var docEditor;
|
||||
var config;
|
||||
|
||||
var innerAlert = function (message, inEditor) {
|
||||
if (console && console.log)
|
||||
@ -107,10 +108,14 @@
|
||||
|
||||
// the meta information of the document is changed via the meta command
|
||||
var onMetaChange = function (event) {
|
||||
var favorite = !!event.data.favorite;
|
||||
var title = document.title.replace(/^\☆/g, "");
|
||||
document.title = (favorite ? "☆" : "") + title;
|
||||
docEditor.setFavorite(favorite); // change the Favorite icon state
|
||||
if (event.data.favorite) {
|
||||
var favorite = !!event.data.favorite;
|
||||
var title = document.title.replace(/^\☆/g, "");
|
||||
document.title = (favorite ? "☆" : "") + title;
|
||||
docEditor.setFavorite(favorite); // change the Favorite icon state
|
||||
}
|
||||
|
||||
innerAlert("onMetaChange: " + JSON.stringify(event.data));
|
||||
};
|
||||
|
||||
// the user is trying to insert an image by clicking the Image from Storage button
|
||||
@ -146,7 +151,7 @@
|
||||
};
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", "webeditor.ashx?type=saveas");
|
||||
xhr.setRequestHeader( 'Content-Type', 'application/json');
|
||||
xhr.setRequestHeader('Content-Type', 'application/json');
|
||||
xhr.send(JSON.stringify(data));
|
||||
xhr.onload = function () {
|
||||
innerAlert(xhr.responseText);
|
||||
@ -154,7 +159,26 @@
|
||||
}
|
||||
};
|
||||
|
||||
var config = <%= Model.GetDocConfig(Request, Url) %>;
|
||||
var onRequestRename = function(event) { // the user is trying to rename file by clicking Rename... button
|
||||
innerAlert("onRequestRename: " + JSON.stringify(event.data));
|
||||
|
||||
var newfilename = event.data;
|
||||
var data = {
|
||||
newfilename: newfilename,
|
||||
dockey: config.document.key,
|
||||
ext: config.document.fileType
|
||||
};
|
||||
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", "webeditor.ashx?type=rename");
|
||||
xhr.setRequestHeader('Content-Type', 'application/json');
|
||||
xhr.send(JSON.stringify(data));
|
||||
xhr.onload = function () {
|
||||
innerAlert(xhr.responseText);
|
||||
}
|
||||
};
|
||||
|
||||
config = <%= Model.GetDocConfig(Request, Url) %>;
|
||||
|
||||
config.width = "100%";
|
||||
config.height = "100%";
|
||||
@ -174,42 +198,49 @@
|
||||
|
||||
<% string hist, histData; %>
|
||||
<% Model.GetHistory(out hist, out histData); %>
|
||||
<% if (!string.IsNullOrEmpty(hist) && !string.IsNullOrEmpty(histData))
|
||||
{ %>
|
||||
// the user is trying to show the document version history
|
||||
config.events['onRequestHistory'] = function () {
|
||||
docEditor.refreshHistory(<%= hist %>); // show the document version history
|
||||
};
|
||||
// the user is trying to click the specific document version in the document version history
|
||||
config.events['onRequestHistoryData'] = function (event) {
|
||||
var ver = event.data;
|
||||
var histData = <%= histData %>;
|
||||
docEditor.setHistoryData(histData[ver - 1]); // send the link to the document for viewing the version history
|
||||
};
|
||||
// the user is trying to go back to the document from viewing the document version history
|
||||
config.events['onRequestHistoryClose '] = function () {
|
||||
document.location.reload();
|
||||
};
|
||||
<% } %>
|
||||
|
||||
<% string usersForMentions; %>
|
||||
<% Model.GetUsersMentions(Request, out usersForMentions); %>
|
||||
<% if (!string.IsNullOrEmpty(usersForMentions))
|
||||
// add mentions for not anonymous users
|
||||
{ %>
|
||||
config.events['onRequestUsers'] = function () {
|
||||
docEditor.setUsers({ // set a list of users to mention in the comments
|
||||
"users": <%= usersForMentions%>
|
||||
});
|
||||
};
|
||||
// the user is mentioned in a comment
|
||||
config.events['onRequestSendNotify'] = function (event) {
|
||||
event.data.actionLink = replaceActionLink(location.href, event.data.actionLink);
|
||||
var data = JSON.stringify(event.data);
|
||||
innerAlert("onRequestSendNotify: " + data);
|
||||
};
|
||||
<% } %>
|
||||
|
||||
|
||||
if (config.editorConfig.user.id) {
|
||||
<% if (!string.IsNullOrEmpty(hist) && !string.IsNullOrEmpty(histData))
|
||||
{ %>
|
||||
// the user is trying to show the document version history
|
||||
config.events['onRequestHistory'] = function () {
|
||||
docEditor.refreshHistory(<%= hist %>); // show the document version history
|
||||
};
|
||||
// the user is trying to click the specific document version in the document version history
|
||||
config.events['onRequestHistoryData'] = function (event) {
|
||||
var ver = event.data;
|
||||
var histData = <%= histData %>;
|
||||
docEditor.setHistoryData(histData[ver - 1]); // send the link to the document for viewing the version history
|
||||
};
|
||||
// the user is trying to go back to the document from viewing the document version history
|
||||
config.events['onRequestHistoryClose '] = function () {
|
||||
document.location.reload();
|
||||
};
|
||||
<% } %>
|
||||
|
||||
// add mentions for not anonymous users
|
||||
<% if (!string.IsNullOrEmpty(usersForMentions))
|
||||
{ %>
|
||||
config.events['onRequestUsers'] = function () {
|
||||
docEditor.setUsers({ // set a list of users to mention in the comments
|
||||
"users": <%= usersForMentions %>
|
||||
});
|
||||
};
|
||||
<% } %>
|
||||
|
||||
// the user is mentioned in a comment
|
||||
config.events['onRequestSendNotify'] = function (event) {
|
||||
event.data.actionLink = replaceActionLink(location.href, JSON.stringify(event.data.actionLink));
|
||||
var data = JSON.stringify(event.data);
|
||||
innerAlert("onRequestSendNotify: " + data);
|
||||
};
|
||||
// prevent file renaming for anonymous users
|
||||
config.events['onRequestRename'] = onRequestRename;
|
||||
}
|
||||
|
||||
if (config.editorConfig.createUrl) {
|
||||
config.events.onRequestSaveAs = onRequestSaveAs;
|
||||
};
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
<%@ Import Namespace="System.Web.Configuration" %>
|
||||
<%@ Import Namespace="OnlineEditorsExampleMVC.Helpers" %>
|
||||
<%@ Import Namespace="OnlineEditorsExampleMVC.Models" %>
|
||||
<%@ Import Namespace="System.Collections.Generic" %>
|
||||
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
@ -89,7 +90,7 @@
|
||||
<select class="select-user" id="user">
|
||||
<% foreach (User user in Users.getAllUsers())
|
||||
{ %>
|
||||
<option value=<%= user.id %> ><%= user.name.IsEmpty() ? "Anonymous" : user.name %></option>
|
||||
<option value="<%= user.id %>"><%= user.name.IsEmpty() ? "Anonymous" : user.name %></option>
|
||||
<% } %>
|
||||
</select>
|
||||
</td>
|
||||
@ -98,37 +99,11 @@
|
||||
<td valign="middle">
|
||||
<span class="select-user">Language editors interface</span>
|
||||
<select class="select-user" id="language">
|
||||
<option value="en">English</option>
|
||||
<option value="be">Belarusian</option>
|
||||
<option value="bg">Bulgarian</option>
|
||||
<option value="ca">Catalan</option>
|
||||
<option value="zh">Chinese</option>
|
||||
<option value="cs">Czech</option>
|
||||
<option value="da">Danish</option>
|
||||
<option value="nl">Dutch</option>
|
||||
<option value="fi">Finnish</option>
|
||||
<option value="fr">French</option>
|
||||
<option value="de">German</option>
|
||||
<option value="el">Greek</option>
|
||||
<option value="hu">Hungarian</option>
|
||||
<option value="id">Indonesian</option>
|
||||
<option value="it">Italian</option>
|
||||
<option value="ja">Japanese</option>
|
||||
<option value="ko">Korean</option>
|
||||
<option value="lv">Latvian</option>
|
||||
<option value="lo">Lao</option>
|
||||
<option value="nb">Norwegian</option>
|
||||
<option value="pl">Polish</option>
|
||||
<option value="pt">Portuguese</option>
|
||||
<option value="ro">Romanian</option>
|
||||
<option value="ru">Russian</option>
|
||||
<option value="sk">Slovak</option>
|
||||
<option value="sl">Slovenian</option>
|
||||
<option value="sv">Swedish</option>
|
||||
<option value="es">Spanish</option>
|
||||
<option value="tr">Turkish</option>
|
||||
<option value="uk">Ukrainian</option>
|
||||
<option value="vi">Vietnamese</option>
|
||||
<% Dictionary<string, string> languages = DocManagerHelper.GetLanguages();
|
||||
foreach (var lang in languages)
|
||||
{ %>
|
||||
<option value="<%= lang.Key %>"><%= lang.Value %></option>
|
||||
<% } %>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
@ -188,7 +163,7 @@
|
||||
var isFillFormDoc = DocManagerHelper.FillFormExts.Contains(ext);
|
||||
%>
|
||||
|
||||
<tr class="tableRow" title="<%= storedFile.Name %> [<%= DocManagerHelper.GetFileVersion(storedFile.Name, HttpContext.Current.Request.UserHostAddress) %>]">
|
||||
<tr class="tableRow" title="<%= storedFile.Name %> [<%= DocManagerHelper.GetFileVersion(storedFile.Name, HttpContext.Current.Request.UserHostAddress.Replace(':', '_')) %>]">
|
||||
<td class="contentCells">
|
||||
<a class="stored-edit <%= docType %>" href="<%= Url.Action("Editor", "Home", new { fileName = storedFile.Name }) %>" target="_blank">
|
||||
<span><%= storedFile.Name %></span>
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
For more information on how to configure your ASP.NET application, please visit
|
||||
http://go.microsoft.com/fwlink/?LinkId=152368
|
||||
@ -26,11 +26,11 @@
|
||||
</system.web>
|
||||
<system.webServer>
|
||||
<validation validateIntegratedModeConfiguration="false" />
|
||||
<httpProtocol>
|
||||
<customHeaders>
|
||||
<add name="Access-Control-Allow-Origin" value="*" />
|
||||
</customHeaders>
|
||||
</httpProtocol>
|
||||
<httpProtocol>
|
||||
<customHeaders>
|
||||
<add name="Access-Control-Allow-Origin" value="*" />
|
||||
</customHeaders>
|
||||
</httpProtocol>
|
||||
<handlers>
|
||||
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
|
||||
<remove name="OPTIONSVerbHandler" />
|
||||
@ -46,13 +46,21 @@
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
|
||||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
|
||||
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
|
||||
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
|
||||
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
|
||||
<bindingRedirect oldVersion="1.0.0.0-5.2.7.0" newVersion="5.2.7.0" />
|
||||
@ -63,7 +71,4 @@
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
<entityFramework>
|
||||
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
|
||||
</entityFramework>
|
||||
</configuration>
|
||||
@ -19,6 +19,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Web;
|
||||
@ -70,6 +71,9 @@ namespace OnlineEditorsExampleMVC
|
||||
case "saveas":
|
||||
SaveAs(context);
|
||||
break;
|
||||
case "rename":
|
||||
Rename(context);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -113,6 +117,8 @@ namespace OnlineEditorsExampleMVC
|
||||
|
||||
var req = (HttpWebRequest)WebRequest.Create(fileUrl);
|
||||
|
||||
DocManagerHelper.VerifySSL();
|
||||
|
||||
using (var stream = req.GetResponse().GetResponseStream())
|
||||
{
|
||||
|
||||
@ -151,6 +157,8 @@ namespace OnlineEditorsExampleMVC
|
||||
context.Response.ContentType = "text/plain";
|
||||
try
|
||||
{
|
||||
DocManagerHelper.VerifySSL();
|
||||
|
||||
var httpPostedFile = context.Request.Files[0];
|
||||
string fileName;
|
||||
|
||||
@ -250,6 +258,8 @@ namespace OnlineEditorsExampleMVC
|
||||
|
||||
var req = (HttpWebRequest)WebRequest.Create(newFileUri);
|
||||
|
||||
DocManagerHelper.VerifySSL();
|
||||
|
||||
using (var stream = req.GetResponse().GetResponseStream()) // get response stream of the converting file
|
||||
{
|
||||
if (stream == null) throw new Exception("Stream is null");
|
||||
@ -541,5 +551,44 @@ namespace OnlineEditorsExampleMVC
|
||||
context.Response.Write("{ \"error\": \"File not found!\"}");
|
||||
}
|
||||
}
|
||||
|
||||
// rename a file
|
||||
private static void Rename(HttpContext context)
|
||||
{
|
||||
// read request body
|
||||
context.Response.ContentType = "text/plain";
|
||||
string fileData;
|
||||
try
|
||||
{
|
||||
using (var receiveStream = context.Request.InputStream)
|
||||
using (var readStream = new StreamReader(receiveStream))
|
||||
{
|
||||
fileData = readStream.ReadToEnd();
|
||||
if (string.IsNullOrEmpty(fileData)) context.Response.Write("{\"error\":\"Request stream is empty\"}");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new HttpException((int)HttpStatusCode.BadRequest, e.Message);
|
||||
}
|
||||
|
||||
var jss = new JavaScriptSerializer();
|
||||
var body = jss.Deserialize<Dictionary<string, object>>(fileData);
|
||||
var newFileName = (string) body["newfilename"];
|
||||
var docKey = (string) body["dockey"];
|
||||
|
||||
var origExt = '.' + (string) body["ext"];
|
||||
var curExt = Path.GetExtension(newFileName).ToLower();
|
||||
|
||||
if (string.Compare(origExt, curExt, true) != 0)
|
||||
{
|
||||
newFileName += origExt;
|
||||
}
|
||||
var meta = new Dictionary<string, object>() {
|
||||
{ "title", newFileName }
|
||||
};
|
||||
TrackManager.commandRequest("meta", docKey, meta);
|
||||
context.Response.Write("{ \"result\": \"OK\"}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Submodule web/documentserver-example/csharp-mvc/assets updated: af97a54226...1fc823afa9
@ -24,11 +24,15 @@ jQuery.UI - jQuery UI is an open source library of interface components —
|
||||
License: MIT
|
||||
License File: jQuery.UI.license
|
||||
|
||||
JWT - JWT (JSON Web Token) Implementation for .NET (Public Domain) (https://github.com/jwt-dotnet/jwt/)
|
||||
License: MIT
|
||||
License File: JWT.license
|
||||
|
||||
Microsoft.Web.Infrastructure - This package contains the Microsoft.Web.Infrastructure assembly that lets you dynamically register HTTP modules at run time. (https://www.microsoft.com/web/webpi/eula/aspnetmvc3update-eula.htm)
|
||||
License: MS-EULA License
|
||||
License File: Microsoft.Web.Infrastructure.license
|
||||
|
||||
Newtonsoft.Json - Json.NET is a popular high-performance JSON framework for .NET (https://licenses.nuget.org/MIT)
|
||||
Newtonsoft.Json - Json.NET is a popular high-performance JSON framework for .NET (https://github.com/JamesNK/Newtonsoft.Json)
|
||||
License: MIT
|
||||
License File: Newtonsoft.Json.license
|
||||
|
||||
|
||||
21
web/documentserver-example/csharp-mvc/licenses/JWT.license
Normal file
21
web/documentserver-example/csharp-mvc/licenses/JWT.license
Normal file
@ -0,0 +1,21 @@
|
||||
# Public Domain
|
||||
|
||||
Written by John Sheehan (http://john-sheehan.com)
|
||||
|
||||
This work is public domain.
|
||||
|
||||
The person who associated a work with this deed has dedicated the work to the public domain by waiving all of his or her rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law.
|
||||
|
||||
For more information, please visit: http://creativecommons.org/publicdomain/zero/1.0/
|
||||
|
||||
# MIT
|
||||
|
||||
Copyright (c) 2019 Jwt.Net Maintainers and Contributors.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
For more information, please visit: https://opensource.org/licenses/MIT
|
||||
@ -1,16 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Antlr" version="3.5.0.2" targetFramework="net45" />
|
||||
<package id="EntityFramework" version="6.4.4" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.Mvc" version="5.2.7" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.Razor" version="3.2.7" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.Web.Optimization" version="1.1.3" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.7" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.7" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.7" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.WebPages" version="3.2.7" targetFramework="net45" />
|
||||
<package id="Microsoft.CSharp" version="4.7.0" targetFramework="net45" />
|
||||
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
|
||||
<package id="Newtonsoft.Json" version="12.0.3" targetFramework="net45" />
|
||||
<package id="WebGrease" version="1.6.0" targetFramework="net45" />
|
||||
<package id="Antlr" version="3.5.0.2" targetFramework="net48" />
|
||||
<package id="EntityFramework" version="6.4.4" targetFramework="net48" />
|
||||
<package id="JWT" version="9.0.3" targetFramework="net48" />
|
||||
<package id="Microsoft.AspNet.Mvc" version="5.2.7" targetFramework="net48" />
|
||||
<package id="Microsoft.AspNet.Razor" version="3.2.7" targetFramework="net48" />
|
||||
<package id="Microsoft.AspNet.Web.Optimization" version="1.1.3" targetFramework="net48" />
|
||||
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.7" targetFramework="net48" />
|
||||
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.7" targetFramework="net48" />
|
||||
<package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.7" targetFramework="net48" />
|
||||
<package id="Microsoft.AspNet.WebPages" version="3.2.7" targetFramework="net48" />
|
||||
<package id="Microsoft.CSharp" version="4.7.0" targetFramework="net48" />
|
||||
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net48" />
|
||||
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net48" />
|
||||
<package id="WebGrease" version="1.6.0" targetFramework="net48" />
|
||||
</packages>
|
||||
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0"?>
|
||||
<?xml version="1.0"?>
|
||||
<appSettings>
|
||||
<clear />
|
||||
<add key="version" value="1.1.0"/>
|
||||
<add key="version" value="1.4.0"/>
|
||||
|
||||
<add key="filesize-max" value="52428800"/>
|
||||
<add key="storage-path" value=""/>
|
||||
@ -14,6 +14,10 @@
|
||||
<add key="files.docservice.secret" value="" />
|
||||
<add key="files.docservice.header" value="Authorization" />
|
||||
|
||||
<add key="files.docservice.verify-peer-off" value="true"/>
|
||||
|
||||
<add key="files.docservice.languages" value="en:English|hy:Armenian|az:Azerbaijani|eu:Basque|be:Belarusian|bg:Bulgarian|ca:Catalan|zh:Chinese (People's Republic of China)|zh-TW:Chinese (Traditional, Taiwan)|cs:Czech|da:Danish|nl:Dutch|fi:Finnish|fr:French|gl:Galego|de:German|el:Greek|hu:Hungarian|id:Indonesian|it:Italian|ja:Japanese|ko:Korean|lv:Latvian|lo:Lao|ms:Malay (Malaysia)|nb:Norwegian|pl:Polish|pt:Portuguese (Brazil)|pt-PT:Portuguese (Portugal)|ro:Romanian|ru:Russian|sk:Slovak|sl:Slovenian|es:Spanish|sv:Swedish|tr:Turkish|uk:Ukrainian|vi:Vietnamese"/>
|
||||
|
||||
<add key="files.docservice.url.site" value="http://documentserver/"/>
|
||||
|
||||
<add key="files.docservice.url.converter" value="ConvertService.ashx"/>
|
||||
|
||||
@ -19,3 +19,11 @@ License File: jQuery.iframe-transport.license
|
||||
jQuery.UI - jQuery UI is an open source library of interface components — interactions, full-featured widgets, and animation effects — based on the stellar jQuery javascript library . Each component is built according to jQuery's event-driven architecture (find something, manipulate it) and is themeable, making it easy for developers of any skill level to integrate and extend into their own code. (https://jquery.org/license/)
|
||||
License: MIT
|
||||
License File: jQuery.UI.license
|
||||
|
||||
JWT - JWT (JSON Web Token) Implementation for .NET (Public Domain) (https://github.com/jwt-dotnet/jwt/)
|
||||
License: MIT
|
||||
License File: JWT.license
|
||||
|
||||
Newtonsoft.Json - Json.NET is a popular high-performance JSON framework for .NET (https://github.com/JamesNK/Newtonsoft.Json)
|
||||
License: MIT
|
||||
License File: Newtonsoft.Json.license
|
||||
@ -5,6 +5,7 @@
|
||||
<%@ Import Namespace="System.Linq" %>
|
||||
<%@ Import Namespace="System.Web.Configuration" %>
|
||||
<%@ Import Namespace="OnlineEditorsExample" %>
|
||||
<%@ Import Namespace="System.Collections.Generic" %>
|
||||
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
@ -100,37 +101,11 @@
|
||||
<td valign="middle">
|
||||
<span class="select-user">Language editors interface</span>
|
||||
<select class="select-user" id="language">
|
||||
<option value="en">English</option>
|
||||
<option value="be">Belarusian</option>
|
||||
<option value="bg">Bulgarian</option>
|
||||
<option value="ca">Catalan</option>
|
||||
<option value="zh">Chinese</option>
|
||||
<option value="cs">Czech</option>
|
||||
<option value="da">Danish</option>
|
||||
<option value="nl">Dutch</option>
|
||||
<option value="fi">Finnish</option>
|
||||
<option value="fr">French</option>
|
||||
<option value="de">German</option>
|
||||
<option value="el">Greek</option>
|
||||
<option value="hu">Hungarian</option>
|
||||
<option value="id">Indonesian</option>
|
||||
<option value="it">Italian</option>
|
||||
<option value="ja">Japanese</option>
|
||||
<option value="ko">Korean</option>
|
||||
<option value="lv">Latvian</option>
|
||||
<option value="lo">Lao</option>
|
||||
<option value="nb">Norwegian</option>
|
||||
<option value="pl">Polish</option>
|
||||
<option value="pt">Portuguese</option>
|
||||
<option value="ro">Romanian</option>
|
||||
<option value="ru">Russian</option>
|
||||
<option value="sk">Slovak</option>
|
||||
<option value="sl">Slovenian</option>
|
||||
<option value="sv">Swedish</option>
|
||||
<option value="es">Spanish</option>
|
||||
<option value="tr">Turkish</option>
|
||||
<option value="uk">Ukrainian</option>
|
||||
<option value="vi">Vietnamese</option>
|
||||
<% Dictionary<string, string> languages = GetLanguages();
|
||||
foreach (var lang in languages)
|
||||
{ %>
|
||||
<option value="<%= lang.Key %>"><%= lang.Value %></option>
|
||||
<% } %>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
@ -190,7 +165,7 @@
|
||||
var isFillFormDoc = FillFormsExts.Contains(ext);
|
||||
%>
|
||||
|
||||
<tr class="tableRow" title="<%= storedFile.Name %> [<%= GetFileVersion(storedFile.Name, HttpContext.Current.Request.UserHostAddress) %>]">
|
||||
<tr class="tableRow" title="<%= storedFile.Name %> [<%= GetFileVersion(storedFile.Name, HttpContext.Current.Request.UserHostAddress.Replace(':','_')) %>]">
|
||||
<td class="contentCells">
|
||||
<a class="stored-edit <%= docType %>" href="<%= editUrl %>" target="_blank">
|
||||
<span><%= storedFile.Name %></span>
|
||||
|
||||
@ -353,11 +353,7 @@ namespace OnlineEditorsExample
|
||||
|
||||
try
|
||||
{
|
||||
// hack. http://ubuntuforums.org/showthread.php?t=1841740
|
||||
if (IsMono)
|
||||
{
|
||||
ServicePointManager.ServerCertificateValidationCallback += (s, ce, ca, p) => true;
|
||||
}
|
||||
VerifySSL();
|
||||
|
||||
using (var stream = req.GetResponse().GetResponseStream()) // get response stream of the uploading file
|
||||
{
|
||||
@ -420,11 +416,7 @@ namespace OnlineEditorsExample
|
||||
|
||||
var req = (HttpWebRequest)WebRequest.Create(fileUrl);
|
||||
|
||||
// hack. http://ubuntuforums.org/showthread.php?t=1841740
|
||||
if (IsMono)
|
||||
{
|
||||
ServicePointManager.ServerCertificateValidationCallback += (s, ce, ca, p) => true;
|
||||
}
|
||||
VerifySSL();
|
||||
|
||||
using (var stream = req.GetResponse().GetResponseStream())
|
||||
{
|
||||
@ -493,7 +485,7 @@ namespace OnlineEditorsExample
|
||||
+ (HttpRuntime.AppDomainAppVirtualPath.EndsWith("/") ? "" : "/")
|
||||
+ "webeditor.ashx";
|
||||
fileUrl.Query = "type=download&fileName=" + HttpUtility.UrlEncode(_fileName)
|
||||
+ "&userAddress=" + HttpUtility.UrlEncode(HttpContext.Current.Request.UserHostAddress);
|
||||
+ "&userAddress=" + HttpUtility.UrlEncode(CurUserHostAddress(HttpContext.Current.Request.UserHostAddress));
|
||||
|
||||
// get the url to the converted file
|
||||
string newFileUri;
|
||||
@ -508,11 +500,7 @@ namespace OnlineEditorsExample
|
||||
|
||||
var req = (HttpWebRequest)WebRequest.Create(newFileUri);
|
||||
|
||||
// hack. http://ubuntuforums.org/showthread.php?t=1841740
|
||||
if (IsMono)
|
||||
{
|
||||
ServicePointManager.ServerCertificateValidationCallback += (s, ce, ca, p) => true;
|
||||
}
|
||||
VerifySSL();
|
||||
|
||||
using (var stream = req.GetResponse().GetResponseStream()) // get response stream of the converting file
|
||||
{
|
||||
@ -616,5 +604,27 @@ namespace OnlineEditorsExample
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
// enable certificate ignore
|
||||
public static void VerifySSL()
|
||||
{
|
||||
// hack. http://ubuntuforums.org/showthread.php?t=1841740
|
||||
if(WebConfigurationManager.AppSettings["files.docservice.verify-peer-off"].Equals("true")) {
|
||||
ServicePointManager.ServerCertificateValidationCallback += (s, ce, ca, p) => true;
|
||||
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
|
||||
}
|
||||
}
|
||||
|
||||
public static Dictionary<string, string> GetLanguages()
|
||||
{
|
||||
var languages = new Dictionary<string, string>();
|
||||
String[] couples = (WebConfigurationManager.AppSettings["files.docservice.languages"] ?? "").Split('|');
|
||||
foreach (string couple in couples)
|
||||
{
|
||||
String[] tmp = couple.Split(':');
|
||||
languages.Add(tmp[0],tmp[1]);
|
||||
}
|
||||
return languages;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -64,6 +64,7 @@
|
||||
<script type="text/javascript" language="javascript">
|
||||
|
||||
var docEditor;
|
||||
var config;
|
||||
|
||||
var innerAlert = function (message, inEditor) {
|
||||
if (console && console.log)
|
||||
@ -125,10 +126,14 @@
|
||||
|
||||
// the meta information of the document is changed via the meta command
|
||||
var onMetaChange = function (event) {
|
||||
var favorite = !!event.data.favorite;
|
||||
var title = document.title.replace(/^\☆/g, "");
|
||||
document.title = (favorite ? "☆" : "") + title;
|
||||
docEditor.setFavorite(favorite); // change the Favorite icon state
|
||||
if (event.data.favorite) {
|
||||
var favorite = !!event.data.favorite;
|
||||
var title = document.title.replace(/^\☆/g, "");
|
||||
document.title = (favorite ? "☆" : "") + title;
|
||||
docEditor.setFavorite(favorite); // change the Favorite icon state
|
||||
}
|
||||
|
||||
innerAlert("onMetaChange: " + JSON.stringify(event.data));
|
||||
};
|
||||
|
||||
// the user is trying to insert an image by clicking the Image from Storage button
|
||||
@ -158,7 +163,7 @@
|
||||
};
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", "webeditor.ashx?type=saveas");
|
||||
xhr.setRequestHeader( 'Content-Type', 'application/json');
|
||||
xhr.setRequestHeader('Content-Type', 'application/json');
|
||||
xhr.send(JSON.stringify(data));
|
||||
xhr.onload = function () {
|
||||
innerAlert(xhr.responseText);
|
||||
@ -166,7 +171,26 @@
|
||||
}
|
||||
};
|
||||
|
||||
var config = <%= DocConfig %>;
|
||||
var onRequestRename = function(event) { // the user is trying to rename file by clicking Rename... button
|
||||
innerAlert("onRequestRename: " + JSON.stringify(event.data));
|
||||
|
||||
var newfilename = event.data;
|
||||
var data = {
|
||||
newfilename: newfilename,
|
||||
dockey: config.document.key,
|
||||
ext: config.document.fileType
|
||||
};
|
||||
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", "webeditor.ashx?type=rename");
|
||||
xhr.setRequestHeader('Content-Type', 'application/json');
|
||||
xhr.send(JSON.stringify(data));
|
||||
xhr.onload = function () {
|
||||
innerAlert(xhr.responseText);
|
||||
}
|
||||
};
|
||||
|
||||
config = <%= DocConfig %>;
|
||||
|
||||
config.width = "100%";
|
||||
config.height = "100%";
|
||||
@ -184,37 +208,42 @@
|
||||
"onRequestMailMergeRecipients": onRequestMailMergeRecipients,
|
||||
};
|
||||
|
||||
<% if (!string.IsNullOrEmpty(History) && !string.IsNullOrEmpty(HistoryData))
|
||||
{ %>
|
||||
config.events['onRequestHistory'] = function () { // the user is trying to show the document version history
|
||||
docEditor.refreshHistory(<%= History %>); // show the document version history
|
||||
};
|
||||
config.events['onRequestHistoryData'] = function (event) { // the user is trying to click the specific document version in the document version history
|
||||
var ver = event.data;
|
||||
var histData = <%= HistoryData %>;
|
||||
docEditor.setHistoryData(histData[ver - 1]); // send the link to the document for viewing the version history
|
||||
};
|
||||
config.events['onRequestHistoryClose '] = function () { // the user is trying to go back to the document from viewing the document version history
|
||||
document.location.reload();
|
||||
};
|
||||
<% } %>
|
||||
if (config.editorConfig.user.id) {
|
||||
<% if (!string.IsNullOrEmpty(History) && !string.IsNullOrEmpty(HistoryData))
|
||||
{ %>
|
||||
config.events['onRequestHistory'] = function () { // the user is trying to show the document version history
|
||||
docEditor.refreshHistory(<%= History %>); // show the document version history
|
||||
};
|
||||
config.events['onRequestHistoryData'] = function (event) { // the user is trying to click the specific document version in the document version history
|
||||
var ver = event.data;
|
||||
var histData = <%= HistoryData %>;
|
||||
docEditor.setHistoryData(histData[ver - 1]); // send the link to the document for viewing the version history
|
||||
};
|
||||
config.events['onRequestHistoryClose '] = function () { // the user is trying to go back to the document from viewing the document version history
|
||||
document.location.reload();
|
||||
};
|
||||
<% } %>
|
||||
|
||||
// add mentions for not anonymous users
|
||||
<% if (!string.IsNullOrEmpty(UsersForMentions))
|
||||
{ %>
|
||||
config.events['onRequestUsers'] = function () {
|
||||
docEditor.setUsers({ // set a list of users to mention in the comments
|
||||
"users": <%= UsersForMentions %>
|
||||
});
|
||||
};
|
||||
<% } %>
|
||||
|
||||
// the user is mentioned in a comment
|
||||
config.events['onRequestSendNotify'] = function (event) {
|
||||
event.data.actionLink = replaceActionLink(location.href, JSON.stringify(event.data.actionLink));
|
||||
var data = JSON.stringify(event.data);
|
||||
innerAlert("onRequestSendNotify: " + data);
|
||||
};
|
||||
// prevent file renaming for anonymous users
|
||||
config.events['onRequestRename'] = onRequestRename;
|
||||
}
|
||||
|
||||
<% if (!string.IsNullOrEmpty(UsersForMentions))
|
||||
{ %>
|
||||
// add mentions for not anonymous users
|
||||
config.events['onRequestUsers'] = function () {
|
||||
docEditor.setUsers({ // set a list of users to mention in the comments
|
||||
"users": <%= UsersForMentions %>
|
||||
});
|
||||
};
|
||||
// the user is mentioned in a comment
|
||||
config.events['onRequestSendNotify'] = function (event) {
|
||||
event.data.actionLink = replaceActionLink(location.href, event.data.actionLink);
|
||||
var data = JSON.stringify(event.data);
|
||||
innerAlert("onRequestSendNotify: " + data);
|
||||
};
|
||||
<% } %>
|
||||
|
||||
if (config.editorConfig.createUrl) {
|
||||
config.events.onRequestSaveAs = onRequestSaveAs;
|
||||
};
|
||||
|
||||
62
web/documentserver-example/csharp/DocEditor.aspx.cs
Normal file → Executable file
62
web/documentserver-example/csharp/DocEditor.aspx.cs
Normal file → Executable file
@ -81,7 +81,7 @@ namespace OnlineEditorsExample
|
||||
+ "webeditor.ashx";
|
||||
callbackUrl.Query = "type=track"
|
||||
+ "&fileName=" + HttpUtility.UrlEncode(FileName)
|
||||
+ "&userAddress=" + HttpUtility.UrlEncode(HttpContext.Current.Request.UserHostAddress);
|
||||
+ "&userAddress=" + HttpUtility.UrlEncode(_Default.CurUserHostAddress(HttpContext.Current.Request.UserHostAddress));
|
||||
return callbackUrl.ToString();
|
||||
}
|
||||
}
|
||||
@ -100,16 +100,17 @@ namespace OnlineEditorsExample
|
||||
}
|
||||
|
||||
// get url to download a file
|
||||
public static string getDownloadUrl(string fileName)
|
||||
public static string getDownloadUrl(string fileName, Boolean isServer = true)
|
||||
{
|
||||
var downloadUrl = new UriBuilder(_Default.GetServerUrl(true));
|
||||
var userAddress = isServer ? "&userAddress=" + HttpUtility.UrlEncode(_Default.CurUserHostAddress(HttpContext.Current.Request.UserHostAddress)) : "";
|
||||
var downloadUrl = new UriBuilder(_Default.GetServerUrl(isServer));
|
||||
downloadUrl.Path =
|
||||
HttpRuntime.AppDomainAppVirtualPath
|
||||
+ (HttpRuntime.AppDomainAppVirtualPath.EndsWith("/") ? "" : "/")
|
||||
+ "webeditor.ashx";
|
||||
downloadUrl.Query = "type=download"
|
||||
+ "&fileName=" + HttpUtility.UrlEncode(fileName)
|
||||
+ "&userAddress=" + HttpUtility.UrlEncode(HttpContext.Current.Request.UserHostAddress);
|
||||
+ userAddress;
|
||||
return downloadUrl.ToString();
|
||||
}
|
||||
|
||||
@ -165,6 +166,7 @@ namespace OnlineEditorsExample
|
||||
var actionLink = Request.GetOrDefault("actionLink", null); // get the action link (comment or bookmark) if it exists
|
||||
var actionData = string.IsNullOrEmpty(actionLink) ? null : jss.DeserializeObject(actionLink); // get action data for the action link
|
||||
|
||||
var directUrl = getDownloadUrl(FileName, false);
|
||||
var createUrl = getCreateUrl(DocumentType, editorsType);
|
||||
var templatesImageUrl = GetTemplateImageUrl(ext); // image url for templates
|
||||
var templates = new List<Dictionary<string, string>>
|
||||
@ -193,6 +195,7 @@ namespace OnlineEditorsExample
|
||||
{
|
||||
{ "title", FileName },
|
||||
{ "url", getDownloadUrl(FileName) },
|
||||
{ "directUrl", directUrl },
|
||||
{ "fileType", ext.Trim('.') },
|
||||
{ "key", Key },
|
||||
{
|
||||
@ -216,6 +219,7 @@ namespace OnlineEditorsExample
|
||||
{ "modifyFilter", editorsMode != "filter" },
|
||||
{ "modifyContentControl", editorsMode != "blockcontent" },
|
||||
{ "review", canEdit && (editorsMode == "edit" || editorsMode == "review") },
|
||||
{ "chat", !user.id.Equals("uid-0") },
|
||||
{ "reviewGroups", user.reviewGroups },
|
||||
{ "commentGroups", user.commentGroups },
|
||||
{ "userInfoGroups", user.userInfoGroups }
|
||||
@ -230,6 +234,11 @@ namespace OnlineEditorsExample
|
||||
{ "mode", mode },
|
||||
{ "lang", Request.Cookies.GetOrDefault("ulang", "en") },
|
||||
{ "callbackUrl", CallbackUrl }, // absolute URL to the document storage service
|
||||
{ "coEditing", editorsMode == "view" && user.id.Equals("uid-0") ?
|
||||
new Dictionary<string, object>{
|
||||
{"mode", "strict"},
|
||||
{"change", false}
|
||||
} : null },
|
||||
{ "createUrl", !user.id.Equals("uid-0") ? createUrl : null },
|
||||
{ "templates", user.templates ? templates : null },
|
||||
{
|
||||
@ -245,9 +254,9 @@ namespace OnlineEditorsExample
|
||||
// the parameters for the embedded document type
|
||||
"embedded", new Dictionary<string, object>
|
||||
{
|
||||
{ "saveUrl", FileUriUser }, // the absolute URL that will allow the document to be saved onto the user personal computer
|
||||
{ "embedUrl", FileUriUser }, // the absolute URL to the document serving as a source file for the document embedded into the web page
|
||||
{ "shareUrl", FileUriUser }, // the absolute URL that will allow other users to share this document
|
||||
{ "saveUrl", directUrl }, // the absolute URL that will allow the document to be saved onto the user personal computer
|
||||
{ "embedUrl", directUrl }, // the absolute URL to the document serving as a source file for the document embedded into the web page
|
||||
{ "shareUrl", directUrl }, // the absolute URL that will allow other users to share this document
|
||||
{ "toolbarDocked", "top" } // the place for the embedded viewer toolbar (top or bottom)
|
||||
}
|
||||
},
|
||||
@ -256,6 +265,7 @@ namespace OnlineEditorsExample
|
||||
"customization", new Dictionary<string, object>
|
||||
{
|
||||
{ "about", true }, // the About section display
|
||||
{ "comments", true },
|
||||
{ "feedback", true }, // the Feedback & Support menu button display
|
||||
{ "forcesave", false }, // adds the request for the forced file saving to the callback handler
|
||||
{ "submitForm", submitForm }, // if the Submit form button is displayed or not
|
||||
@ -358,13 +368,16 @@ namespace OnlineEditorsExample
|
||||
dataObj.Add("fileType", ext.Replace(".", ""));
|
||||
dataObj.Add("key", key);
|
||||
// write file url to the data object
|
||||
var directPrevFileUrl = i == currentVersion ? _Default.FileUri(FileName, false) : MakePublicHistoryUrl(FileName, i.ToString(), "prev" + ext, false);
|
||||
var prevFileUrl = i == currentVersion ? FileUri : MakePublicHistoryUrl(FileName, i.ToString(), "prev" + ext);
|
||||
if (Path.IsPathRooted(storagePath))
|
||||
{
|
||||
prevFileUrl = i == currentVersion ? getDownloadUrl(FileName) : getDownloadUrl(Directory.GetFiles(verDir, "prev.*")[0].Replace(storagePath + "\\", ""));
|
||||
directPrevFileUrl = i == currentVersion ? getDownloadUrl(FileName, false) : getDownloadUrl(Directory.GetFiles(verDir, "prev.*")[0].Replace(storagePath + "\\", ""), false);
|
||||
}
|
||||
|
||||
dataObj.Add("url", prevFileUrl); // write file url to the data object
|
||||
dataObj.Add("directUrl", directPrevFileUrl); // write direct url to the data object
|
||||
dataObj.Add("version", i);
|
||||
if (i > 1) // check if the version number is greater than 1 (the file was modified)
|
||||
{
|
||||
@ -386,6 +399,7 @@ namespace OnlineEditorsExample
|
||||
{ "fileType", prev["fileType"] },
|
||||
{ "key", prev["key"] }, // write key and url information about previous file version
|
||||
{ "url", prev["url"] },
|
||||
{ "directUrl", prev["directUrl"] },
|
||||
});
|
||||
// write the path to the diff.zip archive with differences in this file version
|
||||
var changesUrl = MakePublicHistoryUrl(FileName, (i - 1).ToString(), "diff.zip");
|
||||
@ -419,11 +433,17 @@ namespace OnlineEditorsExample
|
||||
+ (HttpRuntime.AppDomainAppVirtualPath.EndsWith("/") ? "" : "/")
|
||||
+ "App_Themes\\images\\logo.png";
|
||||
|
||||
var DirectImageUrl = new UriBuilder(_Default.GetServerUrl(false));
|
||||
DirectImageUrl.Path = HttpRuntime.AppDomainAppVirtualPath
|
||||
+ (HttpRuntime.AppDomainAppVirtualPath.EndsWith("/") ? "" : "/")
|
||||
+ "App_Themes\\images\\logo.png";
|
||||
|
||||
// create a logo config
|
||||
Dictionary<string, object> logoConfig = new Dictionary<string, object>
|
||||
{
|
||||
{ "fileType", "png"},
|
||||
{ "url", InsertImageUrl.ToString()}
|
||||
{ "url", InsertImageUrl.ToString()},
|
||||
{ "directUrl", DirectImageUrl.ToString()}
|
||||
};
|
||||
|
||||
if (JwtManager.Enabled) // if the secret key to generate token exists
|
||||
@ -445,11 +465,18 @@ namespace OnlineEditorsExample
|
||||
+ "webeditor.ashx";
|
||||
compareFileUrl.Query = "type=assets&fileName=" + HttpUtility.UrlEncode("sample.docx");
|
||||
|
||||
var DirectFileUrl = new UriBuilder(_Default.GetServerUrl(false));
|
||||
DirectFileUrl.Path = HttpRuntime.AppDomainAppVirtualPath
|
||||
+ (HttpRuntime.AppDomainAppVirtualPath.EndsWith("/") ? "" : "/")
|
||||
+ "webeditor.ashx";
|
||||
DirectFileUrl.Query = "type=assets&fileName=" + HttpUtility.UrlEncode("sample.docx");
|
||||
|
||||
// create an object with the information about the compared file
|
||||
Dictionary<string, object> dataCompareFile = new Dictionary<string, object>
|
||||
{
|
||||
{ "fileType", "docx" },
|
||||
{ "url", compareFileUrl.ToString() }
|
||||
{ "url", compareFileUrl.ToString() },
|
||||
{ "directUrl", DirectFileUrl.ToString() }
|
||||
};
|
||||
|
||||
if (JwtManager.Enabled) // if the secret key to generate token exists
|
||||
@ -472,11 +499,19 @@ namespace OnlineEditorsExample
|
||||
+ "webeditor.ashx";
|
||||
mailmergeUrl.Query = "type=csv";
|
||||
|
||||
var DirectMailMergeUrl = new UriBuilder(_Default.GetServerUrl(false));
|
||||
DirectMailMergeUrl.Path =
|
||||
HttpRuntime.AppDomainAppVirtualPath
|
||||
+ (HttpRuntime.AppDomainAppVirtualPath.EndsWith("/") ? "" : "/")
|
||||
+ "webeditor.ashx";
|
||||
DirectMailMergeUrl.Query = "type=csv";
|
||||
|
||||
// create a mail merge config
|
||||
Dictionary<string, object> mailMergeConfig = new Dictionary<string, object>
|
||||
{
|
||||
{ "fileType", "csv" },
|
||||
{ "url", mailmergeUrl.ToString() }
|
||||
{ "url", mailmergeUrl.ToString() },
|
||||
{ "directUrl", DirectMailMergeUrl.ToString() }
|
||||
};
|
||||
|
||||
if (JwtManager.Enabled) // if the secret key to generate token exists
|
||||
@ -520,15 +555,16 @@ namespace OnlineEditorsExample
|
||||
|
||||
|
||||
// create the public history url
|
||||
private string MakePublicHistoryUrl(string filename, string version, string file)
|
||||
private string MakePublicHistoryUrl(string filename, string version, string file, Boolean isServer = true)
|
||||
{
|
||||
var fileUrl = new UriBuilder(_Default.GetServerUrl(true));
|
||||
var userAddress = isServer ? "&userAddress=" + HttpUtility.UrlEncode(_Default.CurUserHostAddress(HttpContext.Current.Request.UserHostAddress)) : "";
|
||||
var fileUrl = new UriBuilder(_Default.GetServerUrl(isServer));
|
||||
fileUrl.Path = HttpRuntime.AppDomainAppVirtualPath
|
||||
+ (HttpRuntime.AppDomainAppVirtualPath.EndsWith("/") ? "" : "/")
|
||||
+ "webeditor.ashx";
|
||||
fileUrl.Query = "type=downloadhistory&fileName=" + HttpUtility.UrlEncode(filename)
|
||||
+ "&ver=" + version + "&file=" + file
|
||||
+ "&userAddress=" + HttpUtility.UrlEncode(HttpContext.Current.Request.UserHostAddress);
|
||||
+ userAddress;
|
||||
return fileUrl.ToString();
|
||||
}
|
||||
|
||||
|
||||
@ -145,11 +145,7 @@ namespace ASC.Api.DocumentConverter
|
||||
requestStream.Write(bytes, 0, bytes.Length); // and write the serialized body object to it
|
||||
}
|
||||
|
||||
// hack. http://ubuntuforums.org/showthread.php?t=1841740
|
||||
if (_Default.IsMono)
|
||||
{
|
||||
ServicePointManager.ServerCertificateValidationCallback += (s, ce, ca, p) => true;
|
||||
}
|
||||
_Default.VerifySSL();
|
||||
|
||||
string dataResponse;
|
||||
using (var response = request.GetResponse())
|
||||
|
||||
@ -16,12 +16,12 @@
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using JWT;
|
||||
using JWT.Algorithms;
|
||||
using JWT.Builder;
|
||||
using JWT.Serializers;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Web.Configuration;
|
||||
using System.Web.Script.Serialization;
|
||||
|
||||
namespace OnlineEditorsExample
|
||||
{
|
||||
@ -30,31 +30,19 @@ namespace OnlineEditorsExample
|
||||
private static readonly string Secret;
|
||||
public static readonly bool Enabled;
|
||||
|
||||
private static readonly JavaScriptSerializer Serializer;
|
||||
|
||||
static JwtManager()
|
||||
{
|
||||
Secret = WebConfigurationManager.AppSettings["files.docservice.secret"] ?? ""; // get token secret from the config parameters
|
||||
Enabled = !string.IsNullOrEmpty(Secret); // check if the token is enabled
|
||||
Serializer = new JavaScriptSerializer(); // define java script serializer
|
||||
}
|
||||
|
||||
// encode a payload object into a token using a secret key
|
||||
public static string Encode(IDictionary<string, object> payload)
|
||||
{
|
||||
// define the hashing algorithm and the token type
|
||||
var header = new Dictionary<string, object>
|
||||
{
|
||||
{ "alg", "HS256" },
|
||||
{ "typ", "JWT" }
|
||||
};
|
||||
|
||||
// three parts of token
|
||||
var encHeader = Base64UrlEncode(Serializer.Serialize(header)); // header
|
||||
var encPayload = Base64UrlEncode(Serializer.Serialize(payload)); // payload
|
||||
var hashSum = Base64UrlEncode(CalculateHash(encHeader, encPayload)); // signature
|
||||
|
||||
return string.Format("{0}.{1}.{2}", encHeader, encPayload, hashSum);
|
||||
var encoder = new JwtEncoder(new HMACSHA256Algorithm(),
|
||||
new JsonNetSerializer(),
|
||||
new JwtBase64UrlEncoder());
|
||||
return encoder.Encode(payload, Secret);
|
||||
}
|
||||
|
||||
// decode a token into a payload object using a secret key
|
||||
@ -62,52 +50,11 @@ namespace OnlineEditorsExample
|
||||
{
|
||||
if (!Enabled || string.IsNullOrEmpty(token)) return "";
|
||||
|
||||
var split = token.Split('.');
|
||||
if (split.Length != 3) return "";
|
||||
|
||||
var hashSum = Base64UrlEncode(CalculateHash(split[0], split[1])); // get signature
|
||||
if (hashSum != split[2]) return ""; // and check if it is equal to the signature from the token
|
||||
return Base64UrlDecode(split[1]); // decode payload
|
||||
}
|
||||
|
||||
// generate a hash code based on a key using the HMAC method
|
||||
private static byte[] CalculateHash(string encHeader, string encPayload)
|
||||
{
|
||||
using (var hasher = new HMACSHA256(Encoding.UTF8.GetBytes(Secret)))
|
||||
{
|
||||
var bytes = Encoding.UTF8.GetBytes(string.Format("{0}.{1}", encHeader, encPayload));
|
||||
return hasher.ComputeHash(bytes);
|
||||
}
|
||||
}
|
||||
|
||||
// encode a string into the base64 value
|
||||
private static string Base64UrlEncode(string str)
|
||||
{
|
||||
return Base64UrlEncode(Encoding.UTF8.GetBytes(str));
|
||||
}
|
||||
|
||||
// encode bytes into the base64 value
|
||||
private static string Base64UrlEncode(byte[] bytes)
|
||||
{
|
||||
return Convert.ToBase64String(bytes)
|
||||
.TrimEnd('=').Replace('+', '-').Replace('/', '_');
|
||||
}
|
||||
|
||||
// decode a base64 value into the string
|
||||
private static string Base64UrlDecode(string payload)
|
||||
{
|
||||
var b64 = payload.Replace('_', '/').Replace('-', '+');
|
||||
switch (b64.Length%4)
|
||||
{
|
||||
case 2:
|
||||
b64 += "==";
|
||||
break;
|
||||
case 3:
|
||||
b64 += "=";
|
||||
break;
|
||||
}
|
||||
var bytes = Convert.FromBase64String(b64);
|
||||
return Encoding.UTF8.GetString(bytes);
|
||||
return JwtBuilder.Create()
|
||||
.WithAlgorithm(new HMACSHA256Algorithm())
|
||||
.WithSecret(Secret)
|
||||
.MustVerifySignature()
|
||||
.Decode(token);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -23,6 +23,8 @@
|
||||
<IISExpressWindowsAuthentication />
|
||||
<IISExpressUseClassicPipelineMode />
|
||||
<TargetFrameworkProfile />
|
||||
<Use64BitIISExpress />
|
||||
<UseGlobalApplicationHostFile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
@ -44,27 +46,33 @@
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="JWT, Version=9.0.0.0, Culture=neutral, PublicKeyToken=6f98bca0f40f2ecf, processorArchitecture=MSIL">
|
||||
<HintPath>packages\JWT.9.0.3\lib\net46\JWT.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="Microsoft.Web.Infrastructure">
|
||||
<Reference Include="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Web.Extensions" />
|
||||
<Reference Include="System.Web" />
|
||||
<Reference Include="System.Web.Helpers">
|
||||
<Reference Include="System.Web.Helpers, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.Helpers.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.Razor">
|
||||
<Reference Include="System.Web.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>packages\Microsoft.AspNet.Razor.3.2.7\lib\net45\System.Web.Razor.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.Services" />
|
||||
<Reference Include="System.Web.WebPages">
|
||||
<Reference Include="System.Web.WebPages, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.WebPages.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.WebPages.Deployment">
|
||||
<Reference Include="System.Web.WebPages.Deployment, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.WebPages.Deployment.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.WebPages.Razor">
|
||||
<Reference Include="System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.WebPages.Razor.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
@ -153,10 +161,12 @@
|
||||
<Content Include="assets\AUTHORS.md" />
|
||||
<Content Include="assets\LICENSE" />
|
||||
<Content Include="assets\new\new.docx" />
|
||||
<Content Include="assets\new\new.docxf" />
|
||||
<Content Include="assets\new\new.pptx" />
|
||||
<Content Include="assets\new\new.xlsx" />
|
||||
<Content Include="assets\sample\csv.csv" />
|
||||
<Content Include="assets\sample\sample.docx" />
|
||||
<Content Include="assets\sample\sample.docxf" />
|
||||
<Content Include="assets\sample\sample.pptx" />
|
||||
<Content Include="assets\sample\sample.xlsx" />
|
||||
<None Include="packages.config" />
|
||||
|
||||
@ -72,3 +72,12 @@ Configure the IIS components for the server to work correctly:
|
||||
In case the example and Document Server are installed on different computers, make sure that your server with the example installed has access to the Document Server with the address which you specify instead of **documentserver** in the configuration files.
|
||||
|
||||
Make sure that the Document Server in its turn has access to the server with the example installed with the address which you specify instead of **example.com** in the configuration files.
|
||||
|
||||
## Important security info
|
||||
|
||||
Please keep in mind the following security aspects when you are using test examples:
|
||||
|
||||
* There is no protection of the storage from unauthorized access since there is no need for authorization.
|
||||
* There are no checks against parameter substitution in links, since the parameters are generated by the code according to the pre-arranged scripts.
|
||||
* There are no data checks in requests of saving the file after editing, since each test example is intended for requests only from ONLYOFFICE Document Server.
|
||||
* There are no prohibitions on using test examples from other sites, since they are intended to interact with ONLYOFFICE Document Server from another domain.
|
||||
@ -78,7 +78,9 @@ namespace OnlineEditorsExample
|
||||
|
||||
if (token != null && !token.Equals("")) // invalid signature error
|
||||
{
|
||||
fileData = (Dictionary<string, object>)jss.Deserialize<Dictionary<string, object>>(token)["payload"];
|
||||
fileData = jss.Deserialize<Dictionary<string, object>>(token);
|
||||
if (fileData.ContainsKey("payload"))
|
||||
fileData = (Dictionary<string, object>)fileData["payload"];
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -128,11 +130,7 @@ namespace OnlineEditorsExample
|
||||
}
|
||||
}
|
||||
|
||||
// hack. http://ubuntuforums.org/showthread.php?t=1841740
|
||||
if (_Default.IsMono)
|
||||
{
|
||||
ServicePointManager.ServerCertificateValidationCallback += (s, ce, ca, p) => true;
|
||||
}
|
||||
_Default.VerifySSL();
|
||||
|
||||
var storagePath = _Default.StoragePath(newFileName, userAddress); // get the file path
|
||||
var histDir = _Default.HistoryDir(storagePath); // get the path to the history directory
|
||||
@ -209,11 +207,7 @@ namespace OnlineEditorsExample
|
||||
}
|
||||
}
|
||||
|
||||
// hack. http://ubuntuforums.org/showthread.php?t=1841740
|
||||
if (_Default.IsMono)
|
||||
{
|
||||
ServicePointManager.ServerCertificateValidationCallback += (s, ce, ca, p) => true;
|
||||
}
|
||||
_Default.VerifySSL();
|
||||
|
||||
string forcesavePath = "";
|
||||
Boolean isSubmitForm = fileData["forcesavetype"].ToString().Equals("3"); // SubmitForm
|
||||
@ -258,8 +252,10 @@ namespace OnlineEditorsExample
|
||||
}
|
||||
|
||||
// create a command request
|
||||
public static void commandRequest(string method, string key)
|
||||
public static void commandRequest(string method, string key, object meta = null)
|
||||
{
|
||||
_Default.VerifySSL();
|
||||
|
||||
string documentCommandUrl = WebConfigurationManager.AppSettings["files.docservice.url.site"] + WebConfigurationManager.AppSettings["files.docservice.url.command"];
|
||||
|
||||
var request = (HttpWebRequest)WebRequest.Create(documentCommandUrl);
|
||||
@ -271,13 +267,18 @@ namespace OnlineEditorsExample
|
||||
{ "key", key }
|
||||
};
|
||||
|
||||
if (meta != null)
|
||||
{
|
||||
body.Add("meta", meta);
|
||||
}
|
||||
|
||||
// check if a secret key to generate token exists or not
|
||||
if (JwtManager.Enabled)
|
||||
{
|
||||
var payload = new Dictionary<string, object>
|
||||
{
|
||||
{ "payload", body }
|
||||
};
|
||||
{
|
||||
{ "payload", body }
|
||||
};
|
||||
|
||||
var payloadToken = JwtManager.Encode(payload); // encode a payload object into a header token
|
||||
var bodyToken = JwtManager.Encode(body); // encode body into a body token
|
||||
|
||||
@ -65,7 +65,10 @@ namespace OnlineEditorsExample
|
||||
"The file favorite state is undefined",
|
||||
"Can't mention others in comments",
|
||||
"Can't create new files from the editor",
|
||||
"Can’t see anyone’s information"
|
||||
"Can’t see anyone’s information",
|
||||
"Can't rename files from the editor",
|
||||
"Can't view chat",
|
||||
"View file without collaboration",
|
||||
};
|
||||
|
||||
private static List<User> users = new List<User>() {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<appSettings configSource="settings.config" />
|
||||
<system.web>
|
||||
@ -9,9 +9,9 @@
|
||||
</system.web>
|
||||
<system.webServer>
|
||||
<httpProtocol>
|
||||
<customHeaders>
|
||||
<add name="Access-Control-Allow-Origin" value="*" />
|
||||
</customHeaders>
|
||||
<customHeaders>
|
||||
<add name="Access-Control-Allow-Origin" value="*" />
|
||||
</customHeaders>
|
||||
</httpProtocol>
|
||||
<security>
|
||||
<requestFiltering>
|
||||
@ -25,4 +25,20 @@
|
||||
</requestFiltering>
|
||||
</security>
|
||||
</system.webServer>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
|
||||
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
|
||||
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
||||
@ -68,6 +68,9 @@ namespace OnlineEditorsExample
|
||||
case "saveas":
|
||||
SaveAs(context);
|
||||
break;
|
||||
case "rename":
|
||||
Rename(context);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -204,7 +207,7 @@ namespace OnlineEditorsExample
|
||||
try
|
||||
{
|
||||
var fileName = Path.GetFileName(context.Request["fileName"]);
|
||||
var path = _Default.StoragePath(fileName, HttpUtility.UrlEncode(HttpContext.Current.Request.UserHostAddress));
|
||||
var path = _Default.StoragePath(fileName, HttpUtility.UrlEncode(_Default.CurUserHostAddress(HttpContext.Current.Request.UserHostAddress)));
|
||||
var histDir = _Default.HistoryDir(path);
|
||||
|
||||
if (File.Exists(path)) File.Delete(path); // delete file
|
||||
@ -368,5 +371,43 @@ namespace OnlineEditorsExample
|
||||
context.Response.Write("{ \"error\": \"File not found!\"}");
|
||||
}
|
||||
}
|
||||
|
||||
// rename a file
|
||||
private static void Rename(HttpContext context)
|
||||
{
|
||||
string fileData;
|
||||
try
|
||||
{
|
||||
using (var receiveStream = context.Request.InputStream)
|
||||
using (var readStream = new StreamReader(receiveStream))
|
||||
{
|
||||
fileData = readStream.ReadToEnd();
|
||||
if (string.IsNullOrEmpty(fileData)) return;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new HttpException((int)HttpStatusCode.BadRequest, e.Message);
|
||||
}
|
||||
|
||||
var jss = new JavaScriptSerializer();
|
||||
var body = jss.Deserialize<Dictionary<string, object>>(fileData);
|
||||
var newFileName = (string) body["newfilename"];
|
||||
var docKey = (string) body["dockey"];
|
||||
|
||||
var origExt = '.' + (string) body["ext"];
|
||||
var curExt = Path.GetExtension(newFileName).ToLower();
|
||||
|
||||
if (string.Compare(origExt, curExt, true) != 0)
|
||||
{
|
||||
newFileName += origExt;
|
||||
}
|
||||
|
||||
var meta = new Dictionary<string, object>() {
|
||||
{ "title", newFileName }
|
||||
};
|
||||
TrackManager.commandRequest("meta", docKey, meta);
|
||||
context.Response.Write("{ \"result\": \"OK\"}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Submodule web/documentserver-example/csharp/assets updated: af97a54226...1fc823afa9
@ -19,3 +19,11 @@ License File: jQuery.iframe-transport.license
|
||||
jQuery.UI - jQuery UI is an open source library of interface components — interactions, full-featured widgets, and animation effects — based on the stellar jQuery javascript library . Each component is built according to jQuery's event-driven architecture (find something, manipulate it) and is themeable, making it easy for developers of any skill level to integrate and extend into their own code. (https://jquery.org/license/)
|
||||
License: MIT
|
||||
License File: jQuery.UI.license
|
||||
|
||||
JWT - JWT (JSON Web Token) Implementation for .NET (Public Domain) (https://github.com/jwt-dotnet/jwt/)
|
||||
License: MIT
|
||||
License File: JWT.license
|
||||
|
||||
Newtonsoft.Json - Json.NET is a popular high-performance JSON framework for .NET (https://github.com/JamesNK/Newtonsoft.Json)
|
||||
License: MIT
|
||||
License File: Newtonsoft.Json.license
|
||||
21
web/documentserver-example/csharp/licenses/JWT.license
Normal file
21
web/documentserver-example/csharp/licenses/JWT.license
Normal file
@ -0,0 +1,21 @@
|
||||
# Public Domain
|
||||
|
||||
Written by John Sheehan (http://john-sheehan.com)
|
||||
|
||||
This work is public domain.
|
||||
|
||||
The person who associated a work with this deed has dedicated the work to the public domain by waiving all of his or her rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law.
|
||||
|
||||
For more information, please visit: http://creativecommons.org/publicdomain/zero/1.0/
|
||||
|
||||
# MIT
|
||||
|
||||
Copyright (c) 2019 Jwt.Net Maintainers and Contributors.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
For more information, please visit: https://opensource.org/licenses/MIT
|
||||
@ -0,0 +1,20 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2007 James Newton-King
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
@ -1,6 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Microsoft.AspNet.Razor" version="3.2.7" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.WebPages" version="3.2.7" targetFramework="net45" />
|
||||
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
|
||||
<package id="JWT" version="9.0.3" targetFramework="net48" />
|
||||
<package id="Microsoft.AspNet.Razor" version="3.2.7" targetFramework="net48" />
|
||||
<package id="Microsoft.AspNet.WebPages" version="3.2.7" targetFramework="net48" />
|
||||
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net48" />
|
||||
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net48" />
|
||||
</packages>
|
||||
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<appSettings>
|
||||
<clear />
|
||||
<add key="version" value="1.1.0"/>
|
||||
<add key="version" value="1.4.0"/>
|
||||
|
||||
<add key="filesize-max" value="52428800"/>
|
||||
<add key="storage-path" value=""/>
|
||||
@ -13,6 +13,9 @@
|
||||
<add key="files.docservice.timeout" value="120000" />
|
||||
<add key="files.docservice.secret" value="" />
|
||||
<add key="files.docservice.header" value="Authorization" />
|
||||
<add key="files.docservice.verify-peer-off" value="true"/>
|
||||
|
||||
<add key="files.docservice.languages" value="en:English|hy:Armenian|az:Azerbaijani|eu:Basque|be:Belarusian|bg:Bulgarian|ca:Catalan|zh:Chinese (People's Republic of China)|zh-TW:Chinese (Traditional, Taiwan)|cs:Czech|da:Danish|nl:Dutch|fi:Finnish|fr:French|gl:Galego|de:German|el:Greek|hu:Hungarian|id:Indonesian|it:Italian|ja:Japanese|ko:Korean|lv:Latvian|lo:Lao|ms:Malay (Malaysia)|nb:Norwegian|pl:Polish|pt:Portuguese (Brazil)|pt-PT:Portuguese (Portugal)|ro:Romanian|ru:Russian|sk:Slovak|sl:Slovenian|es:Spanish|sv:Swedish|tr:Turkish|uk:Ukrainian|vi:Vietnamese"/>
|
||||
|
||||
<add key="files.docservice.url.site" value="http://documentserver/"/>
|
||||
|
||||
|
||||
@ -236,3 +236,12 @@ Make sure that the Document Server has access to the server with the example ins
|
||||
```
|
||||
http://server.address:server.port/
|
||||
```
|
||||
|
||||
## Important security info
|
||||
|
||||
Please keep in mind the following security aspects when you are using test examples:
|
||||
|
||||
* There is no protection of the storage from unauthorized access since there is no need for authorization.
|
||||
* There are no checks against parameter substitution in links, since the parameters are generated by the code according to the pre-arranged scripts.
|
||||
* There are no data checks in requests of saving the file after editing, since each test example is intended for requests only from ONLYOFFICE Document Server.
|
||||
* There are no prohibitions on using test examples from other sites, since they are intended to interact with ONLYOFFICE Document Server from another domain.
|
||||
4
web/documentserver-example/java-spring/pom.xml
Executable file → Normal file
4
web/documentserver-example/java-spring/pom.xml
Executable file → Normal file
@ -48,7 +48,7 @@
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.8.5</version>
|
||||
<version>2.8.9</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.inversoft</groupId>
|
||||
@ -64,7 +64,7 @@
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.12.2</version>
|
||||
<version>2.12.6.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.modelmapper</groupId>
|
||||
|
||||
@ -41,7 +41,10 @@ public class ExampleData {
|
||||
"The file favorite state is undefined",
|
||||
"Can't mention others in comments",
|
||||
"Can't create new files from the editor",
|
||||
"Can’t see anyone’s information"
|
||||
"Can’t see anyone’s information",
|
||||
"Can't rename files from the editor",
|
||||
"Can't view chat",
|
||||
"View file without collaboration"
|
||||
);
|
||||
List<String> description_user_1 = List.of( // the description for user 1
|
||||
"File author by default",
|
||||
@ -50,7 +53,8 @@ public class ExampleData {
|
||||
"He can do everything with the comments",
|
||||
"The file favorite state is undefined",
|
||||
"Can create a file from a template with data from the editor",
|
||||
"Can see the information about all users"
|
||||
"Can see the information about all users",
|
||||
"Can view chat"
|
||||
);
|
||||
List<String> description_user_2 = List.of( // the description for user 2
|
||||
"He belongs to Group2",
|
||||
@ -58,7 +62,8 @@ public class ExampleData {
|
||||
"He can view every comment, edit his comments and the comments left by the users who don't belong to any of the groups and remove only his comments",
|
||||
"This file is favorite",
|
||||
"Can create a file from an editor",
|
||||
"Can see the information about users from Group2 and users who don’t belong to any group"
|
||||
"Can see the information about users from Group2 and users who don’t belong to any group",
|
||||
"Can view chat"
|
||||
);
|
||||
List<String> description_user_3 = List.of( // the description for user 3
|
||||
"He belongs to Group3",
|
||||
@ -69,7 +74,8 @@ public class ExampleData {
|
||||
"He can’t download the file",
|
||||
"He can’t print the file",
|
||||
"Can create a file from an editor",
|
||||
"Can see the information about Group2 users"
|
||||
"Can see the information about Group2 users",
|
||||
"Can view chat"
|
||||
);
|
||||
userService.createUser("John Smith", "smith@example.com", // create user 1 with the specified parameters
|
||||
description_user_1, "", List.of(FilterState.NULL.toString()),
|
||||
@ -77,15 +83,18 @@ public class ExampleData {
|
||||
List.of(FilterState.NULL.toString()),
|
||||
List.of(FilterState.NULL.toString()),
|
||||
List.of(FilterState.NULL.toString()),
|
||||
null);
|
||||
null, true);
|
||||
userService.createUser("Mark Pottato", "pottato@example.com", // create user 2 with the specified parameters
|
||||
description_user_2, "group-2", List.of("","group-2"), List.of(FilterState.NULL.toString()),
|
||||
List.of("group-2", ""), List.of("group-2"), List.of("group-2", ""), true);
|
||||
List.of("group-2", ""), List.of("group-2"), List.of("group-2", ""), true,
|
||||
true);
|
||||
userService.createUser("Hamish Mitchell", "mitchell@example.com", // create user 3 with the specified parameters
|
||||
description_user_3, "group-3", List.of("group-2"), List.of("group-2", "group-3"),
|
||||
List.of("group-2"), new ArrayList<>(), List.of("group-2"), false);
|
||||
List.of("group-2"), new ArrayList<>(), List.of("group-2"), false,
|
||||
true);
|
||||
userService.createUser("Anonymous",null, // create user 0 with the specified parameters
|
||||
description_user_0,"", List.of(FilterState.NULL.toString()), List.of(FilterState.NULL.toString()),
|
||||
List.of(FilterState.NULL.toString()), List.of(FilterState.NULL.toString()), new ArrayList<>(),null);
|
||||
List.of(FilterState.NULL.toString()), List.of(FilterState.NULL.toString()), new ArrayList<>(),null,
|
||||
false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,15 +30,23 @@ import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import com.onlyoffice.integration.documentserver.util.SSLUtils;
|
||||
|
||||
@Configuration
|
||||
public class IntegrationConfiguration {
|
||||
|
||||
@Value("${files.storage}")
|
||||
private String storageAddress;
|
||||
|
||||
@Value("${files.docservice.verify-peer-off}")
|
||||
private String verifyPerrOff;
|
||||
|
||||
@Autowired
|
||||
private FileStoragePathBuilder storagePathBuilder;
|
||||
|
||||
@Autowired
|
||||
private SSLUtils ssl;
|
||||
|
||||
@Bean
|
||||
public ModelMapper mapper(){ // create the model mapper
|
||||
ModelMapper mapper = new ModelMapper();
|
||||
@ -58,6 +66,17 @@ public class IntegrationConfiguration {
|
||||
@PostConstruct
|
||||
public void init(){ // initialize the storage path builder
|
||||
storagePathBuilder.configure(storageAddress.isBlank() ? null : storageAddress);
|
||||
if(!verifyPerrOff.isEmpty()) {
|
||||
try{
|
||||
if(verifyPerrOff.equals("true")) {
|
||||
ssl.turnOffSslChecking(); //the certificate will be ignored
|
||||
} else {
|
||||
ssl.turnOnSslChecking(); //the certificate will be verified
|
||||
}
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@ -138,6 +138,7 @@ public class EditorController {
|
||||
Map<String, Object> dataInsertImage = new HashMap<>();
|
||||
dataInsertImage.put("fileType", "png");
|
||||
dataInsertImage.put("url", storagePathBuilder.getServerUrl(true) + "/css/img/logo.png");
|
||||
dataInsertImage.put("directUrl", storagePathBuilder.getServerUrl(false) + "/css/img/logo.png");
|
||||
|
||||
// check if the document token is enabled
|
||||
if(jwtManager.tokenEnabled()){
|
||||
@ -152,6 +153,7 @@ public class EditorController {
|
||||
Map<String, Object> dataCompareFile = new HashMap<>();
|
||||
dataCompareFile.put("fileType", "docx");
|
||||
dataCompareFile.put("url", storagePathBuilder.getServerUrl(true) + "/assets?name=sample.docx");
|
||||
dataCompareFile.put("directUrl", storagePathBuilder.getServerUrl(false) + "/assets?name=sample.docx");
|
||||
|
||||
// check if the document token is enabled
|
||||
if(jwtManager.tokenEnabled()){
|
||||
@ -166,6 +168,7 @@ public class EditorController {
|
||||
Map<String, Object> dataMailMergeRecipients = new HashMap<>(); // get recipients data for mail merging
|
||||
dataMailMergeRecipients.put("fileType", "csv");
|
||||
dataMailMergeRecipients.put("url", storagePathBuilder.getServerUrl(true) + "/csv");
|
||||
dataMailMergeRecipients.put("directUrl", storagePathBuilder.getServerUrl(false) + "/csv");
|
||||
|
||||
// check if the document token is enabled
|
||||
if(jwtManager.tokenEnabled()){
|
||||
|
||||
@ -31,6 +31,7 @@ import com.onlyoffice.integration.services.UserServices;
|
||||
import com.onlyoffice.integration.documentserver.util.file.FileUtility;
|
||||
import com.onlyoffice.integration.documentserver.util.service.ServiceConverter;
|
||||
import com.onlyoffice.integration.documentserver.managers.document.DocumentManager;
|
||||
import com.onlyoffice.integration.documentserver.managers.callback.CallbackManager;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@ -61,6 +62,12 @@ public class FileController {
|
||||
@Value("${filesize-max}")
|
||||
private String filesizeMax;
|
||||
|
||||
@Value("${files.docservice.url.site}")
|
||||
private String docserviceUrlSite;
|
||||
|
||||
@Value("${files.docservice.url.command}")
|
||||
private String docserviceUrlCommand;
|
||||
|
||||
@Autowired
|
||||
private FileUtility fileUtility;
|
||||
@Autowired
|
||||
@ -79,6 +86,8 @@ public class FileController {
|
||||
private ObjectMapper objectMapper;
|
||||
@Autowired
|
||||
private ServiceConverter serviceConverter;
|
||||
@Autowired
|
||||
private CallbackManager callbackManager;
|
||||
|
||||
// create user metadata
|
||||
private String createUserMetadata(String uid, String fullFileName) {
|
||||
@ -155,7 +164,7 @@ public class FileController {
|
||||
public String convert(@RequestBody Converter body, // convert a file
|
||||
@CookieValue("uid") String uid, @CookieValue("ulang") String lang){
|
||||
String fileName = body.getFileName(); // get file name
|
||||
String fileUri = documentManager.getDownloadUrl(fileName); // get URL for downloading a file with the specified name
|
||||
String fileUri = documentManager.getDownloadUrl(fileName, true); // get URL for downloading a file with the specified name
|
||||
String filePass = body.getFilePass() != null ? body.getFilePass() : null; // get file password if it exists
|
||||
String fileExt = fileUtility.getFileExtension(fileName); // get file extension
|
||||
DocumentType type = fileUtility.getDocumentType(fileName); // get document type (word, cell or slide)
|
||||
@ -356,4 +365,32 @@ public class FileController {
|
||||
return "{ \"error\" : 1, \"message\" : \"" + e.getMessage() + "\"}";
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/rename")
|
||||
@ResponseBody
|
||||
public String rename(@RequestBody JSONObject body) {
|
||||
String newfilename = (String) body.get("newfilename");
|
||||
String dockey = (String) body.get("dockey");
|
||||
String origExt = "." + (String) body.get("ext");
|
||||
String curExt = newfilename;
|
||||
|
||||
if(newfilename.indexOf(".") != -1) {
|
||||
curExt = (String) fileUtility.getFileExtension(newfilename);
|
||||
}
|
||||
|
||||
if(origExt.compareTo(curExt) != 0) {
|
||||
newfilename += origExt;
|
||||
}
|
||||
|
||||
HashMap<String, String> meta = new HashMap<>();
|
||||
meta.put("title", newfilename);
|
||||
|
||||
try {
|
||||
callbackManager.commandRequest("meta", dockey, meta);
|
||||
return "result ok";
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return e.getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -64,6 +64,9 @@ public class IndexController {
|
||||
@Value("${url.editor}")
|
||||
private String urlEditor;
|
||||
|
||||
@Value("${files.docservice.languages}")
|
||||
private String langs;
|
||||
|
||||
@GetMapping("${url.index}")
|
||||
public String index(Model model){
|
||||
java.io.File[] files = storageMutator.getStoredFiles(); // get all the stored files from the storage
|
||||
@ -71,6 +74,14 @@ public class IndexController {
|
||||
List<Boolean> filesEditable = new ArrayList<>();
|
||||
List<String> versions = new ArrayList<>();
|
||||
List<Boolean> isFillFormDoc = new ArrayList<>();
|
||||
List<String> langsAndKeys = Arrays.asList(langs.split("\\|"));
|
||||
|
||||
Map<String, String> languages = new LinkedHashMap<>();
|
||||
|
||||
langsAndKeys.forEach((str) -> {
|
||||
String[] couple = str.split(":");
|
||||
languages.put(couple[0], couple[1]);
|
||||
});
|
||||
|
||||
List<User> users = userService.findAll(); // get a list of all the users
|
||||
|
||||
@ -95,6 +106,7 @@ public class IndexController {
|
||||
model.addAttribute("datadocs", docserviceSite+docservicePreloader);
|
||||
model.addAttribute("tooltip", tooltip);
|
||||
model.addAttribute("users", users);
|
||||
model.addAttribute("languages", languages);
|
||||
|
||||
return "index.html";
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@ public class EditCallback implements Callback {
|
||||
if (!body.getUsers().contains(user)) { // if this user is not specified in the body
|
||||
String key = body.getKey(); // get document key
|
||||
try {
|
||||
callbackManager.commandRequest("forcesave", key); // create a command request to forcibly save the document being edited without closing it
|
||||
callbackManager.commandRequest("forcesave", key, null); // create a command request to forcibly save the document being edited without closing it
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
result = 1;
|
||||
|
||||
@ -19,9 +19,10 @@
|
||||
package com.onlyoffice.integration.documentserver.managers.callback;
|
||||
|
||||
import com.onlyoffice.integration.dto.Track;
|
||||
import java.util.HashMap;
|
||||
|
||||
public interface CallbackManager { // specify the callback manager functions
|
||||
void processSave(Track body, String fileName); // file saving process
|
||||
void commandRequest(String method, String key); // create a command request
|
||||
void commandRequest(String method, String key, HashMap meta); // create a command request
|
||||
void processForceSave(Track body, String fileName); // file force saving process
|
||||
}
|
||||
|
||||
@ -153,16 +153,20 @@ public class DefaultCallbackManager implements CallbackManager {
|
||||
|
||||
//TODO: Replace (String method) with (Enum method)
|
||||
@SneakyThrows
|
||||
public void commandRequest(String method, String key) { // create a command request
|
||||
public void commandRequest(String method, String key, HashMap meta) { // create a command request
|
||||
String DocumentCommandUrl = docserviceUrlSite + docserviceUrlCommand;
|
||||
|
||||
URL url = new URL(DocumentCommandUrl);
|
||||
java.net.HttpURLConnection connection = (java.net.HttpURLConnection) url.openConnection();
|
||||
|
||||
HashMap<String, Object> params = new HashMap<>();
|
||||
HashMap<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("c", method);
|
||||
params.put("key", key);
|
||||
|
||||
if (meta != null) {
|
||||
params.put("meta", meta);
|
||||
}
|
||||
|
||||
String headerToken;
|
||||
if (jwtManager.tokenEnabled()) // check if a secret key to generate token exists or not
|
||||
{
|
||||
|
||||
@ -118,10 +118,10 @@ public class DefaultDocumentManager implements DocumentManager {
|
||||
String hostAddress = storagePathBuilder.getStorageLocation(); // get the storage directory
|
||||
String filePathDownload = !fileName.contains(InetAddress.getLocalHost().getHostAddress()) ? fileName
|
||||
: fileName.substring(fileName.indexOf(InetAddress.getLocalHost().getHostAddress()) + InetAddress.getLocalHost().getHostAddress().length() + 1);
|
||||
|
||||
String userAddress = forDocumentServer ? "&userAddress" + URLEncoder.encode(hostAddress, java.nio.charset.StandardCharsets.UTF_8.toString()) : "";
|
||||
String filePath = serverPath + "/downloadhistory?fileName=" + URLEncoder.encode(filePathDownload, java.nio.charset.StandardCharsets.UTF_8.toString())
|
||||
+ "&ver=" + version + "&file="+file
|
||||
+ "&userAddress" + URLEncoder.encode(hostAddress, java.nio.charset.StandardCharsets.UTF_8.toString());
|
||||
+ userAddress;
|
||||
return filePath;
|
||||
}
|
||||
catch (UnsupportedEncodingException | UnknownHostException e)
|
||||
@ -149,15 +149,15 @@ public class DefaultDocumentManager implements DocumentManager {
|
||||
}
|
||||
|
||||
// get URL to download a file
|
||||
public String getDownloadUrl(String fileName) {
|
||||
String serverPath = storagePathBuilder.getServerUrl(true);
|
||||
public String getDownloadUrl(String fileName, Boolean isServer) {
|
||||
String serverPath = storagePathBuilder.getServerUrl(isServer);
|
||||
String storageAddress = storagePathBuilder.getStorageLocation();
|
||||
try
|
||||
{
|
||||
String userAddress = isServer ? "&userAddress=" + URLEncoder.encode(storageAddress, java.nio.charset.StandardCharsets.UTF_8.toString()) : "";
|
||||
String query = downloadUrl+"?fileName="
|
||||
+ URLEncoder.encode(fileName, java.nio.charset.StandardCharsets.UTF_8.toString())
|
||||
+ "&userAddress="
|
||||
+ URLEncoder.encode(storageAddress, java.nio.charset.StandardCharsets.UTF_8.toString());
|
||||
+ userAddress;
|
||||
|
||||
return serverPath + query;
|
||||
}
|
||||
|
||||
@ -27,7 +27,7 @@ public interface DocumentManager {
|
||||
String getFileUri(String fileName, Boolean forDocumentServer); // get file URL
|
||||
String getHistoryFileUrl(String fileName, Integer version, String file, Boolean forDocumentServer); // get file URL
|
||||
String getCallback(String fileName); // get the callback URL
|
||||
String getDownloadUrl(String fileName); // get URL to download a file
|
||||
String getDownloadUrl(String fileName, Boolean forDocumentServer); // get URL to download a file
|
||||
ArrayList<Map<String, Object>> getFilesInfo(); // get file information
|
||||
ArrayList<Map<String, Object>> getFilesInfo(String fileId); // get file information by its ID
|
||||
String versionDir(String path, Integer version, boolean historyPath); // get the path to the file version by the history path and file version
|
||||
|
||||
@ -91,6 +91,8 @@ public class DefaultHistoryManager implements HistoryManager {
|
||||
dataObj.put("key", key);
|
||||
dataObj.put("url", i == curVer ? document.getUrl() :
|
||||
documentManager.getHistoryFileUrl(document.getTitle(), i, "prev" + fileUtility.getFileExtension(document.getTitle()), true));
|
||||
dataObj.put("directUrl", i == curVer ? document.getDirectUrl() :
|
||||
documentManager.getHistoryFileUrl(document.getTitle(), i, "prev" + fileUtility.getFileExtension(document.getTitle()), false));
|
||||
dataObj.put("version", i);
|
||||
|
||||
if (i > 1) { //check if the version number is greater than 1
|
||||
@ -109,6 +111,7 @@ public class DefaultHistoryManager implements HistoryManager {
|
||||
prevInfo.put("fileType", prev.get("fileType"));
|
||||
prevInfo.put("key", prev.get("key")); // write key and URL information about previous file version
|
||||
prevInfo.put("url", prev.get("url"));
|
||||
prevInfo.put("directUrl", prev.get("directUrl"));
|
||||
dataObj.put("previous", prevInfo); // write information about previous file version to the data object
|
||||
// write the path to the diff.zip archive with differences in this file version
|
||||
Integer verdiff = i - 1;
|
||||
|
||||
@ -34,7 +34,6 @@ public class Customization { // the parameters which allow to customize the edi
|
||||
@Autowired
|
||||
private Goback goback; // the settings for the Open file location menu button and upper right corner button
|
||||
private Boolean autosave = true; // if the Autosave menu option is enabled or disabled
|
||||
private Boolean chat = true; // if the Chat menu button is displayed or hidden
|
||||
private Boolean comments = true; // if the Comments menu button is displayed or hidden
|
||||
private Boolean compactHeader = false; // if the additional action buttons are displayed in the upper part of the editor window header next to the logo (false) or in the toolbar (true)
|
||||
private Boolean compactToolbar = false; // if the top toolbar type displayed is full (false) or compact (true)
|
||||
|
||||
@ -25,6 +25,7 @@ public enum Action {
|
||||
embedded,
|
||||
filter,
|
||||
comment,
|
||||
chat,
|
||||
fillForms,
|
||||
blockcontent
|
||||
}
|
||||
|
||||
@ -49,5 +49,7 @@ public enum Language {
|
||||
es,
|
||||
tr,
|
||||
uk,
|
||||
vi
|
||||
vi,
|
||||
gl,
|
||||
az
|
||||
}
|
||||
|
||||
@ -39,4 +39,5 @@ public class Document { // the parameters pertaining to the document (title, ur
|
||||
private String urlUser; // the absolute URL that will allow the document to be saved onto the user personal computer
|
||||
private String title; // the desired file name for the viewed or edited document which will also be used as file name when the document is downloaded
|
||||
private String url; // the absolute URL where the source viewed or edited document is stored
|
||||
private String directUrl;
|
||||
}
|
||||
|
||||
@ -38,6 +38,7 @@ import java.util.List;
|
||||
public class EditorConfig { // the parameters pertaining to the editor interface: opening mode (viewer or editor), interface language, additional buttons, etc.
|
||||
private HashMap<String, Object> actionLink = null; // the data which contains the information about the action in the document that will be scrolled to
|
||||
private String callbackUrl; // the absolute URL to the document storage service
|
||||
private HashMap<String, Object> coEditing = null;
|
||||
private String createUrl; // the absolute URL of the document where it will be created and available after creation
|
||||
@Autowired
|
||||
private Customization customization; // the parameters which allow to customize the editor interface so that it looked like your other products (if there are any) and change the presence or absence of the additional buttons, links, change logos and editor owner details
|
||||
|
||||
@ -43,6 +43,7 @@ public class Permission extends AbstractModel { // the permission for the docum
|
||||
private Boolean modifyFilter = true; // if the filter can applied globally (true) affecting all the other users, or locally (false)
|
||||
private Boolean modifyContentControl = true; // if the content control settings can be changed
|
||||
private Boolean review = true; // if the document can be reviewed or not
|
||||
private Boolean chat = true; // if a chat can be used
|
||||
@JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = SerializerFilter.class)
|
||||
private List<String> reviewGroups; // the groups whose changes the user can accept/reject
|
||||
@Autowired
|
||||
|
||||
@ -0,0 +1,59 @@
|
||||
package com.onlyoffice.integration.documentserver.util;
|
||||
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.cert.X509Certificate;
|
||||
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLSession;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
/**
|
||||
* Disables and enables certificate and host-name checking in
|
||||
* HttpsURLConnection, the default JVM implementation of the HTTPS/TLS protocol.
|
||||
* Has no effect on implementations such as Apache Http Client, Ok Http.
|
||||
*/
|
||||
@Component
|
||||
public final class SSLUtils {
|
||||
|
||||
private final HostnameVerifier jvmHostnameVerifier = HttpsURLConnection.getDefaultHostnameVerifier();
|
||||
|
||||
private final HostnameVerifier trivialHostnameVerifier = new HostnameVerifier() {
|
||||
public boolean verify(String hostname, SSLSession sslSession) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
private final TrustManager[] UNQUESTIONING_TRUST_MANAGER = new TrustManager[] { new X509TrustManager() {
|
||||
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void checkClientTrusted(X509Certificate[] certs, String authType) {
|
||||
}
|
||||
|
||||
public void checkServerTrusted(X509Certificate[] certs, String authType) {
|
||||
}
|
||||
} };
|
||||
|
||||
public void turnOffSslChecking() throws NoSuchAlgorithmException, KeyManagementException {
|
||||
HttpsURLConnection.setDefaultHostnameVerifier(trivialHostnameVerifier);
|
||||
// Install the all-trusting trust manager
|
||||
SSLContext sc = SSLContext.getInstance("SSL");
|
||||
sc.init(null, UNQUESTIONING_TRUST_MANAGER, null);
|
||||
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
|
||||
}
|
||||
|
||||
public void turnOnSslChecking() throws KeyManagementException, NoSuchAlgorithmException {
|
||||
HttpsURLConnection.setDefaultHostnameVerifier(jvmHostnameVerifier);
|
||||
// Return it to the initial state (discovered by reflection, now hardcoded)
|
||||
SSLContext sc = SSLContext.getInstance("SSL");
|
||||
sc.init(null, null, null);
|
||||
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
|
||||
}
|
||||
|
||||
}
|
||||
@ -38,6 +38,7 @@ public class Permission extends AbstractEntity {
|
||||
private Boolean modifyFilter = true;
|
||||
private Boolean modifyContentControl = true;
|
||||
private Boolean review = true;
|
||||
private Boolean chat = true;
|
||||
private Boolean templates=true;
|
||||
@ManyToMany
|
||||
private List<Group> reviewGroups;
|
||||
|
||||
@ -37,7 +37,8 @@ public class PermissionServices {
|
||||
List<Group> commentViewGroups,
|
||||
List<Group> commentEditGroups,
|
||||
List<Group> commentRemoveGroups,
|
||||
List<Group> userInfoGroups){
|
||||
List<Group> userInfoGroups,
|
||||
Boolean chat){
|
||||
|
||||
Permission permission = new Permission();
|
||||
permission.setReviewGroups(reviewGroups); // define the groups whose changes the user can accept/reject
|
||||
@ -45,6 +46,7 @@ public class PermissionServices {
|
||||
permission.setCommentsEditGroups(commentEditGroups); // defines the groups whose comments the user can edit
|
||||
permission.setCommentsRemoveGroups(commentRemoveGroups); // defines the groups whose comments the user can remove
|
||||
permission.setUserInfoGroups(userInfoGroups);
|
||||
permission.setChat(chat);
|
||||
|
||||
permissionRepository.save(permission); // save new permissions
|
||||
|
||||
|
||||
@ -56,7 +56,9 @@ public class UserServices {
|
||||
List<String> reviewGroups,
|
||||
List<String> viewGroups,
|
||||
List<String> editGroups,
|
||||
List<String> removeGroups, List<String> userInfoGroups, Boolean favoriteDoc){
|
||||
List<String> removeGroups,
|
||||
List<String> userInfoGroups, Boolean favoriteDoc,
|
||||
Boolean chat){
|
||||
User newUser = new User();
|
||||
newUser.setName(name); // set the user name
|
||||
newUser.setEmail(email); // set the user email
|
||||
@ -71,7 +73,7 @@ public class UserServices {
|
||||
List<Group> usInfoGroups = groupServices.createGroups(userInfoGroups);
|
||||
|
||||
Permission permission = permissionService
|
||||
.createPermission(groupsReview, commentGroupsView, commentGroupsEdit, commentGroupsRemove, usInfoGroups); // specify permissions for the current user
|
||||
.createPermission(groupsReview, commentGroupsView, commentGroupsEdit, commentGroupsRemove, usInfoGroups, chat); // specify permissions for the current user
|
||||
newUser.setPermissions(permission);
|
||||
|
||||
userRepository.save(newUser); // save a new user
|
||||
|
||||
@ -53,8 +53,9 @@ public class DefaultDocumentConfigurer implements DocumentConfigurer<DefaultDocu
|
||||
Permission permission = wrapper.getPermission(); // get the permission parameter from the document wrapper
|
||||
|
||||
document.setTitle(fileName); // set the title to the document config
|
||||
document.setUrl(documentManager.getDownloadUrl(fileName)); // set the URL to download a file to the document config
|
||||
document.setUrl(documentManager.getDownloadUrl(fileName, true)); // set the URL to download a file to the document config
|
||||
document.setUrlUser(documentManager.getFileUri(fileName, false)); // set the file URL to the document config
|
||||
document.setDirectUrl(documentManager.getDownloadUrl(fileName, false));
|
||||
document.setFileType(fileUtility.getFileExtension(fileName).replace(".","")); // set the file type to the document config
|
||||
document.getInfo().setFavorite(wrapper.getFavorite()); // set the favorite parameter to the document config
|
||||
|
||||
|
||||
@ -82,6 +82,10 @@ public class DefaultEditorConfigConfigurer implements EditorConfigConfigurer<Def
|
||||
config.setLang(wrapper.getLang()); // set the language to the editorConfig
|
||||
Boolean canEdit = wrapper.getCanEdit(); // check if the file of the specified type can be edited or not
|
||||
Action action = wrapper.getAction(); // get the action parameter from the editorConfig wrapper
|
||||
config.setCoEditing(action.equals(Action.view) && userIsAnon ? new HashMap<String, Object>() {{
|
||||
put("mode", "strict");
|
||||
put("change", false);
|
||||
}} : null);
|
||||
|
||||
defaultCustomizationConfigurer.configure(config.getCustomization(), DefaultCustomizationWrapper.builder() // define the customization configurer
|
||||
.action(action)
|
||||
|
||||
@ -37,7 +37,7 @@ public class DefaultEmbeddedConfigurer implements EmbeddedConfigurer<DefaultEmbe
|
||||
|
||||
public void configure(Embedded embedded, DefaultEmbeddedWrapper wrapper){ // define the embedded configurer
|
||||
if(wrapper.getType().equals(Type.embedded)) { // check if the type from the embedded wrapper is embedded
|
||||
String url = documentManager.getFileUri(wrapper.getFileName(), false); // get file URL of the specified file
|
||||
String url = documentManager.getDownloadUrl(wrapper.getFileName(), false); // get file URL of the specified file
|
||||
embedded.setEmbedUrl(url); // set the embedURL parameter to the embedded config (the absolute URL to the document serving as a source file for the document embedded into the web page)
|
||||
embedded.setSaveUrl(url); // set the saveURL parameter to the embedded config (the absolute URL that will allow the document to be saved onto the user personal computer)
|
||||
embedded.setShareUrl(url); // set the shareURL parameter to the embedded config (the absolute URL that will allow other users to share this document)
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
server.version=1.1.0
|
||||
server.version=1.4.0
|
||||
|
||||
server.address=
|
||||
server.port=4000
|
||||
@ -25,6 +25,10 @@ files.docservice.url.example=
|
||||
files.docservice.secret=
|
||||
files.docservice.header=Authorization
|
||||
|
||||
files.docservice.verify-peer-off=true
|
||||
|
||||
files.docservice.languages=en:English|hy:Armenian|az:Azerbaijani|eu:Basque|be:Belarusian|bg:Bulgarian|ca:Catalan|zh:Chinese (People's Republic of China)|zh-TW:Chinese (Traditional, Taiwan)|cs:Czech|da:Danish|nl:Dutch|fi:Finnish|fr:French|gl:Galego|de:German|el:Greek|hu:Hungarian|id:Indonesian|it:Italian|ja:Japanese|ko:Korean|lv:Latvian|lo:Lao|ms:Malay (Malaysia)|nb:Norwegian|pl:Polish|pt:Portuguese (Brazil)|pt-PT:Portuguese (Portugal)|ro:Romanian|ru:Russian|sk:Slovak|sl:Slovenian|es:Spanish|sv:Swedish|tr:Turkish|uk:Ukrainian|vi:Vietnamese
|
||||
|
||||
spring.datasource.url=jdbc:h2:mem:usersdb
|
||||
spring.datasource.driverClassName=org.h2.Driver
|
||||
spring.datasource.username=sa
|
||||
|
||||
@ -72,6 +72,7 @@ header img {
|
||||
}
|
||||
|
||||
.main{
|
||||
display: table;
|
||||
height: calc(100% - 112px);
|
||||
min-height: 536px;
|
||||
}
|
||||
|
||||
@ -30,6 +30,7 @@
|
||||
|
||||
<script th:inline="javascript">
|
||||
var docEditor;
|
||||
var config;
|
||||
|
||||
var innerAlert = function (message, inEditor) {
|
||||
if (console && console.log)
|
||||
@ -90,10 +91,13 @@
|
||||
|
||||
// the meta information of the document is changed via the meta command
|
||||
var onMetaChange = function (event) {
|
||||
var favorite = !!event.data.favorite;
|
||||
var title = document.title.replace(/^\☆/g, "");
|
||||
document.title = (favorite ? "☆" : "") + title;
|
||||
docEditor.setFavorite(favorite);
|
||||
if (event.data.favorite) {
|
||||
var favorite = !!event.data.favorite;
|
||||
var title = document.title.replace(/^\☆/g, "");
|
||||
document.title = (favorite ? "☆" : "") + title;
|
||||
docEditor.setFavorite(favorite);
|
||||
}
|
||||
innerAlert("onMetaChange: " + JSON.stringify(event.data));
|
||||
};
|
||||
|
||||
|
||||
@ -115,7 +119,7 @@
|
||||
docEditor.setMailMergeRecipients([[${dataMailMergeRecipients}]]);
|
||||
};
|
||||
|
||||
var config = [[${model}]];
|
||||
config = [[${model}]];
|
||||
|
||||
if (config.editorConfig.user.name == "Anonymous") {
|
||||
config.editorConfig.user.name = "";
|
||||
@ -130,7 +134,7 @@
|
||||
};
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", "saveas");
|
||||
xhr.setRequestHeader( 'Content-Type', 'application/json');
|
||||
xhr.setRequestHeader('Content-Type', 'application/json');
|
||||
xhr.send(JSON.stringify(data));
|
||||
xhr.onload = function () {
|
||||
innerAlert(xhr.responseText);
|
||||
@ -138,6 +142,24 @@
|
||||
}
|
||||
};
|
||||
|
||||
var onRequestRename = function(event) { // the user is trying to rename file by clicking Rename... button
|
||||
innerAlert("onRequestRename: " + JSON.stringify(event.data));
|
||||
|
||||
var newfilename = event.data;
|
||||
var data = {
|
||||
newfilename: newfilename,
|
||||
dockey: config.document.key,
|
||||
ext: config.document.fileType
|
||||
};
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", "rename");
|
||||
xhr.setRequestHeader('Content-Type', 'application/json');
|
||||
xhr.send(JSON.stringify(data));
|
||||
xhr.onload = function () {
|
||||
innerAlert(xhr.responseText);
|
||||
}
|
||||
};
|
||||
|
||||
config.width = "100%";
|
||||
config.height = "100%";
|
||||
config.events = {
|
||||
@ -158,24 +180,23 @@
|
||||
var historyData = histArray[1];
|
||||
var usersForMentions = [[${usersForMentions}]];
|
||||
|
||||
if (hist && historyData) {
|
||||
// the user is trying to show the document version history
|
||||
config.events['onRequestHistory'] = function () {
|
||||
docEditor.refreshHistory(JSON.parse(hist)); // show the document version history
|
||||
};
|
||||
// the user is trying to click the specific document version in the document version history
|
||||
config.events['onRequestHistoryData'] = function (event) {
|
||||
var ver = event.data;
|
||||
var histData = historyData;
|
||||
docEditor.setHistoryData(JSON.parse(histData)[ver - 1]); // send the link to the document for viewing the version history
|
||||
};
|
||||
// the user is trying to go back to the document from viewing the document version history
|
||||
config.events['onRequestHistoryClose'] = function () {
|
||||
document.location.reload();
|
||||
};
|
||||
}
|
||||
|
||||
if(usersForMentions){
|
||||
if (config.editorConfig.user.id != 4) {
|
||||
if (hist && historyData) {
|
||||
// the user is trying to show the document version history
|
||||
config.events['onRequestHistory'] = function () {
|
||||
docEditor.refreshHistory(JSON.parse(hist)); // show the document version history
|
||||
};
|
||||
// the user is trying to click the specific document version in the document version history
|
||||
config.events['onRequestHistoryData'] = function (event) {
|
||||
var ver = event.data;
|
||||
var histData = historyData;
|
||||
docEditor.setHistoryData(JSON.parse(histData)[ver - 1]); // send the link to the document for viewing the version history
|
||||
};
|
||||
// the user is trying to go back to the document from viewing the document version history
|
||||
config.events['onRequestHistoryClose'] = function () {
|
||||
document.location.reload();
|
||||
};
|
||||
}
|
||||
// add mentions for not anonymous users
|
||||
config.events['onRequestUsers'] = function () {
|
||||
docEditor.setUsers({ // set a list of users to mention in the comments
|
||||
@ -184,10 +205,12 @@
|
||||
};
|
||||
// the user is mentioned in a comment
|
||||
config.events['onRequestSendNotify'] = function (event) {
|
||||
event.data.actionLink = replaceActionLink(location.href, event.data.actionLink);
|
||||
event.data.actionLink = replaceActionLink(location.href, JSON.stringify(event.data.actionLink));
|
||||
var data = JSON.stringify(event.data);
|
||||
innerAlert("onRequestSendNotify: " + data);
|
||||
};
|
||||
// prevent file renaming for anonymous users
|
||||
config.events['onRequestRename'] = onRequestRename;
|
||||
}
|
||||
|
||||
if (config.editorConfig.createUrl) {
|
||||
|
||||
@ -87,37 +87,9 @@
|
||||
<td valign="middle">
|
||||
<span class="select-user">Language editors interface</span>
|
||||
<select class="select-user" id="language">
|
||||
<option value="en" selected="selected">English</option>
|
||||
<option value="be">Belarusian</option>
|
||||
<option value="bg">Bulgarian</option>
|
||||
<option value="ca">Catalan</option>
|
||||
<option value="zh">Chinese</option>
|
||||
<option value="cs">Czech</option>
|
||||
<option value="da">Danish</option>
|
||||
<option value="nl">Dutch</option>
|
||||
<option value="fi">Finnish</option>
|
||||
<option value="fr">French</option>
|
||||
<option value="de">German</option>
|
||||
<option value="el">Greek</option>
|
||||
<option value="hu">Hungarian</option>
|
||||
<option value="id">Indonesian</option>
|
||||
<option value="it">Italian</option>
|
||||
<option value="ja">Japanese</option>
|
||||
<option value="ko">Korean</option>
|
||||
<option value="lv">Latvian</option>
|
||||
<option value="lo">Lao</option>
|
||||
<option value="nb">Norwegian</option>
|
||||
<option value="pl">Polish</option>
|
||||
<option value="pt">Portuguese</option>
|
||||
<option value="ro">Romanian</option>
|
||||
<option value="ru">Russian</option>
|
||||
<option value="sk">Slovak</option>
|
||||
<option value="sl">Slovenian</option>
|
||||
<option value="sv">Swedish</option>
|
||||
<option value="es">Spanish</option>
|
||||
<option value="tr">Turkish</option>
|
||||
<option value="uk">Ukrainian</option>
|
||||
<option value="vi">Vietnamese</option>
|
||||
<option th:each="language: ${languages}"
|
||||
th:value="${language.key}"
|
||||
th:text="${language.value}"/>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
@ -345,5 +317,10 @@
|
||||
<script type="text/javascript" src="scripts/jquery.dropdownToggle.js"></script>
|
||||
<script type="text/javascript" src="scripts/jscript.js"></script>
|
||||
<script type="text/javascript" src="scripts/converter.js"></script>
|
||||
<script type="text/javascript">
|
||||
document.addEventListener('DOMContentLoaded', function(){
|
||||
document.getElementById("language").value="en";
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@ -263,3 +263,12 @@ Make sure that the Document Server has access to the server with the example ins
|
||||
```
|
||||
|
||||
4. After it, all the *bin* files will be passed to the *./target* folder.
|
||||
|
||||
## Important security info
|
||||
|
||||
Please keep in mind the following security aspects when you are using test examples:
|
||||
|
||||
* There is no protection of the storage from unauthorized access since there is no need for authorization.
|
||||
* There are no checks against parameter substitution in links, since the parameters are generated by the code according to the pre-arranged scripts.
|
||||
* There are no data checks in requests of saving the file after editing, since each test example is intended for requests only from ONLYOFFICE Document Server.
|
||||
* There are no prohibitions on using test examples from other sites, since they are intended to interact with ONLYOFFICE Document Server from another domain.
|
||||
@ -29,7 +29,7 @@
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.8.5</version>
|
||||
<version>2.8.9</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.inversoft</groupId>
|
||||
|
||||
@ -78,16 +78,19 @@ public class EditorServlet extends HttpServlet
|
||||
Map<String, Object> dataInsertImage = new HashMap<>();
|
||||
dataInsertImage.put("fileType", "png");
|
||||
dataInsertImage.put("url", DocumentManager.GetServerUrl(true) + "/css/img/logo.png");
|
||||
dataInsertImage.put("directUrl", DocumentManager.GetServerUrl(false) + "/css/img/logo.png");
|
||||
|
||||
// a document that will be compared with the current document
|
||||
Map<String, Object> dataCompareFile = new HashMap<>();
|
||||
dataCompareFile.put("fileType", "docx");
|
||||
dataCompareFile.put("url", DocumentManager.GetServerUrl(true) + "/IndexServlet?type=assets&name=sample.docx");
|
||||
dataCompareFile.put("directUrl", DocumentManager.GetServerUrl(false) + "/IndexServlet?type=assets&name=sample.docx");
|
||||
|
||||
// recipients data for mail merging
|
||||
Map<String, Object> dataMailMergeRecipients = new HashMap<>();
|
||||
dataMailMergeRecipients.put("fileType", "csv");
|
||||
dataMailMergeRecipients.put("url", DocumentManager.GetServerUrl(true) + "/IndexServlet?type=csv");
|
||||
dataMailMergeRecipients.put("directUrl", DocumentManager.GetServerUrl(false) + "/IndexServlet?type=csv");
|
||||
|
||||
// users data for mentions
|
||||
List<Map<String, Object>> usersForMentions = Users.getUsersForMentions(user.id);
|
||||
|
||||
@ -29,6 +29,7 @@ import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
import javax.servlet.ServletContextEvent;
|
||||
import javax.servlet.ServletContextListener;
|
||||
import helpers.*;
|
||||
|
||||
public class GlobalServletContextListener implements ServletContextListener
|
||||
{
|
||||
@ -70,16 +71,19 @@ public class GlobalServletContextListener implements ServletContextListener
|
||||
|
||||
SSLContext sc;
|
||||
|
||||
try
|
||||
{
|
||||
// register the all-trusting trust manager for HTTPS
|
||||
sc = SSLContext.getInstance("SSL");
|
||||
sc.init(null, trustAllCerts, new java.security.SecureRandom());
|
||||
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
|
||||
}
|
||||
catch (NoSuchAlgorithmException | KeyManagementException ex)
|
||||
{
|
||||
if(!ConfigManager.GetProperty("files.docservice.verify-peer-off").isEmpty()) {
|
||||
try
|
||||
{
|
||||
// register the all-trusting trust manager for HTTPS
|
||||
sc = SSLContext.getInstance("SSL");
|
||||
sc.init(null, trustAllCerts, new java.security.SecureRandom());
|
||||
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
|
||||
}
|
||||
catch (NoSuchAlgorithmException | KeyManagementException ex)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// create all-trusting host name verifier
|
||||
HostnameVerifier allHostsValid = new HostnameVerifier()
|
||||
|
||||
49
web/documentserver-example/java/src/main/java/controllers/IndexServlet.java
Normal file → Executable file
49
web/documentserver-example/java/src/main/java/controllers/IndexServlet.java
Normal file → Executable file
@ -29,6 +29,8 @@ import java.util.*;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.MultipartConfig;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
@ -36,7 +38,9 @@ import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.Part;
|
||||
|
||||
import entities.FileType;
|
||||
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
@ -45,6 +49,7 @@ import org.primeframework.jwt.Verifier;
|
||||
import org.primeframework.jwt.domain.JWT;
|
||||
import org.primeframework.jwt.hmac.HMACVerifier;
|
||||
|
||||
|
||||
@WebServlet(name = "IndexServlet", urlPatterns = {"/IndexServlet"})
|
||||
@MultipartConfig
|
||||
public class IndexServlet extends HttpServlet
|
||||
@ -97,6 +102,9 @@ public class IndexServlet extends HttpServlet
|
||||
case "saveas":
|
||||
SaveAs(request, response, writer);
|
||||
break;
|
||||
case "rename":
|
||||
Rename(request, response, writer);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -226,7 +234,7 @@ public class IndexServlet extends HttpServlet
|
||||
String fileName = FileUtility.GetFileName((String) body.get("filename"));
|
||||
String lang = cm.getCookie("ulang");
|
||||
String filePass = body.get("filePass") != null ? (String) body.get("filePass") : null;
|
||||
String fileUri = DocumentManager.GetDownloadUrl(fileName);
|
||||
String fileUri = DocumentManager.GetDownloadUrl(fileName, true);
|
||||
String fileExt = FileUtility.GetFileExtension(fileName);
|
||||
FileType fileType = FileUtility.GetFileType(fileName);
|
||||
String internalFileExt = DocumentManager.GetInternalExtension(fileType);
|
||||
@ -321,7 +329,7 @@ public class IndexServlet extends HttpServlet
|
||||
if (users.indexOf(user) == -1) {
|
||||
String key = (String) body.get("key");
|
||||
try {
|
||||
TrackManager.commandRequest("forcesave", key); // create a command request with the forcesave method
|
||||
TrackManager.commandRequest("forcesave", key, null); // create a command request with the forcesave method
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -551,6 +559,43 @@ public class IndexServlet extends HttpServlet
|
||||
}
|
||||
}
|
||||
|
||||
// rename a file
|
||||
private static void Rename(HttpServletRequest request, HttpServletResponse response, PrintWriter writer) {
|
||||
try {
|
||||
Scanner scanner = new Scanner(request.getInputStream());
|
||||
scanner.useDelimiter("\\A");
|
||||
String bodyString = scanner.hasNext() ? scanner.next() : "";
|
||||
scanner.close();
|
||||
|
||||
JSONParser parser = new JSONParser();
|
||||
JSONObject body = (JSONObject) parser.parse(bodyString);
|
||||
|
||||
String newfilename = (String) body.get("newfilename");
|
||||
String dockey = (String) body.get("dockey");
|
||||
|
||||
String origExt = "." + (String) body.get("ext");
|
||||
String curExt = newfilename;
|
||||
|
||||
if(newfilename.indexOf(".") != -1) {
|
||||
curExt = (String) FileUtility.GetFileExtension(newfilename);
|
||||
}
|
||||
|
||||
if(origExt.compareTo(curExt) != 0) {
|
||||
newfilename += origExt;
|
||||
}
|
||||
|
||||
HashMap<String, String> meta = new HashMap<>();
|
||||
meta.put("title", newfilename);
|
||||
|
||||
TrackManager.commandRequest("meta", dockey, meta);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
writer.write("{ \"error\" : 1, \"message\" : \"" + e.getMessage() + "\"}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// process get request
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||
|
||||
@ -51,7 +51,8 @@ public class FileModel
|
||||
// set the document parameters
|
||||
document = new Document();
|
||||
document.title = fileName;
|
||||
document.url = DocumentManager.GetDownloadUrl(fileName); // get file url
|
||||
document.url = DocumentManager.GetDownloadUrl(fileName, true); // get file url
|
||||
document.directUrl = DocumentManager.GetDownloadUrl(fileName, false); // get direct url
|
||||
document.fileType = FileUtility.GetFileExtension(fileName).replace(".", ""); // get file extension from the file name
|
||||
// generate document key
|
||||
document.key = ServiceConverter.GenerateRevisionId(DocumentManager.CurUserHostAddress(null) + "/" + fileName + "/" + Long.toString(new File(DocumentManager.StoragePath(fileName, null)).lastModified()));
|
||||
@ -77,6 +78,12 @@ public class FileModel
|
||||
// set the editor config parameters
|
||||
editorConfig = new EditorConfig(actionData);
|
||||
editorConfig.callbackUrl = DocumentManager.GetCallback(fileName); // get callback url
|
||||
|
||||
editorConfig.coEditing = mode.equals("view") && user.id.equals("uid-0") ?
|
||||
new HashMap<String, Object>() {{
|
||||
put("mode", "strict");
|
||||
put("change", false);
|
||||
}} : null;
|
||||
|
||||
if (lang != null) editorConfig.lang = lang; // write language parameter to the config
|
||||
|
||||
@ -121,7 +128,7 @@ public class FileModel
|
||||
|
||||
public void InitDesktop(String fileName)
|
||||
{
|
||||
editorConfig.InitDesktop(DocumentManager.GetDownloadUrl(fileName) + "&dmode=emb");
|
||||
editorConfig.InitDesktop(DocumentManager.GetDownloadUrl(fileName, false) + "&dmode=emb");
|
||||
}
|
||||
|
||||
// generate document token
|
||||
@ -177,7 +184,8 @@ public class FileModel
|
||||
|
||||
dataObj.put("fileType", FileUtility.GetFileExtension(document.title).substring(1));
|
||||
dataObj.put("key", key);
|
||||
dataObj.put("url", i == curVer ? document.url : DocumentManager.GetDownloadHistoryUrl(document.title, i, "prev" + FileUtility.GetFileExtension(document.title)));
|
||||
dataObj.put("url", i == curVer ? document.url : DocumentManager.GetDownloadHistoryUrl(document.title, i, "prev" + FileUtility.GetFileExtension(document.title), true));
|
||||
dataObj.put("directUrl", i == curVer ? document.url : DocumentManager.GetDownloadHistoryUrl(document.title, i, "prev" + FileUtility.GetFileExtension(document.title), false));
|
||||
dataObj.put("version", i);
|
||||
|
||||
if (i > 1) { //check if the version number is greater than 1
|
||||
@ -199,7 +207,7 @@ public class FileModel
|
||||
dataObj.put("previous", prevInfo); // write information about previous file version to the data object
|
||||
// write the path to the diff.zip archive with differences in this file version
|
||||
Integer verdiff = i - 1;
|
||||
String changesUrl = DocumentManager.GetDownloadHistoryUrl(document.title, verdiff, "diff.zip");
|
||||
String changesUrl = DocumentManager.GetDownloadHistoryUrl(document.title, verdiff, "diff.zip", true);
|
||||
dataObj.put("changesUrl", changesUrl);
|
||||
}
|
||||
|
||||
@ -247,6 +255,7 @@ public class FileModel
|
||||
{
|
||||
public String title;
|
||||
public String url;
|
||||
public String directUrl;
|
||||
public String fileType;
|
||||
public String key;
|
||||
public Info info;
|
||||
@ -265,9 +274,11 @@ public class FileModel
|
||||
public Boolean modifyFilter;
|
||||
public Boolean modifyContentControl;
|
||||
public Boolean review;
|
||||
public Boolean chat;
|
||||
public List<String> reviewGroups;
|
||||
public CommentGroups commentGroups;
|
||||
public List<String> userInfoGroups;
|
||||
//public Gson gson = new Gson();
|
||||
|
||||
// defines what can be done with a document
|
||||
public Permissions(String mode, String type, Boolean canEdit, User user)
|
||||
@ -281,6 +292,7 @@ public class FileModel
|
||||
modifyFilter = !mode.equals("filter");
|
||||
modifyContentControl = !mode.equals("blockcontent");
|
||||
review = canEdit && (mode.equals("edit") || mode.equals("review"));
|
||||
chat = !user.id.equals("uid-0");
|
||||
reviewGroups = user.reviewGroups;
|
||||
commentGroups = user.commentGroups;
|
||||
userInfoGroups = user.userInfoGroups;
|
||||
@ -305,6 +317,7 @@ public class FileModel
|
||||
public HashMap<String, Object> actionLink = null;
|
||||
public String mode = "edit";
|
||||
public String callbackUrl;
|
||||
public HashMap<String, Object> coEditing = null;
|
||||
public String lang = "en";
|
||||
public String createUrl;
|
||||
public List<Map<String, String>> templates;
|
||||
@ -348,14 +361,12 @@ public class FileModel
|
||||
public Boolean forcesave;
|
||||
public Boolean submitForm;
|
||||
public Boolean about;
|
||||
public Boolean chat;
|
||||
public Boolean comments;
|
||||
public Boolean feedback;
|
||||
|
||||
public Customization()
|
||||
{
|
||||
about = true;
|
||||
chat = true;
|
||||
comments = true;
|
||||
feedback = true;
|
||||
forcesave = false;
|
||||
|
||||
31
web/documentserver-example/java/src/main/java/helpers/DocumentManager.java
Normal file → Executable file
31
web/documentserver-example/java/src/main/java/helpers/DocumentManager.java
Normal file → Executable file
@ -354,7 +354,7 @@ public class DocumentManager
|
||||
|
||||
String filePath = serverPath + "/" + storagePath + "/" + hostAddress + "/" + URLEncoder.encode(fileName, java.nio.charset.StandardCharsets.UTF_8.toString()).replace("+", "%20");
|
||||
if (f.isAbsolute() && f.isFile()) {
|
||||
filePath = GetDownloadUrl(fileName);
|
||||
filePath = GetDownloadUrl(fileName, true);
|
||||
if (!Files.isWritable(f.toPath())) {
|
||||
throw new SecurityException("No write permission to path: " + f.toPath());
|
||||
}
|
||||
@ -450,12 +450,13 @@ public class DocumentManager
|
||||
}
|
||||
|
||||
// get url to download a file
|
||||
public static String GetDownloadUrl(String fileName) {
|
||||
String serverPath = GetServerUrl(true);
|
||||
public static String GetDownloadUrl(String fileName, Boolean forDocumentServer) {
|
||||
String serverPath = GetServerUrl(forDocumentServer);
|
||||
String hostAddress = CurUserHostAddress(null);
|
||||
try
|
||||
{
|
||||
String query = "?type=download&fileName=" + URLEncoder.encode(fileName, java.nio.charset.StandardCharsets.UTF_8.toString()) + "&userAddress=" + URLEncoder.encode(hostAddress, java.nio.charset.StandardCharsets.UTF_8.toString());
|
||||
String userAddress = forDocumentServer ? "&userAddress=" + URLEncoder.encode(hostAddress, java.nio.charset.StandardCharsets.UTF_8.toString()) : "";
|
||||
String query = "?type=download&fileName=" + URLEncoder.encode(fileName, java.nio.charset.StandardCharsets.UTF_8.toString()) + userAddress;
|
||||
|
||||
return serverPath + "/IndexServlet" + query;
|
||||
}
|
||||
@ -466,12 +467,13 @@ public class DocumentManager
|
||||
}
|
||||
|
||||
// get url to download a file to History prev.*
|
||||
public static String GetDownloadHistoryUrl(String fileName, Integer version, String file) {
|
||||
String serverPath = GetServerUrl(true);
|
||||
public static String GetDownloadHistoryUrl(String fileName, Integer version, String file, Boolean forDocumentServer) {
|
||||
String serverPath = GetServerUrl(forDocumentServer);
|
||||
String hostAddress = CurUserHostAddress(null);
|
||||
try
|
||||
{
|
||||
String query = "?type=downloadhistory&fileName=" + URLEncoder.encode(fileName, java.nio.charset.StandardCharsets.UTF_8.toString()) + "&userAddress=" + URLEncoder.encode(hostAddress, java.nio.charset.StandardCharsets.UTF_8.toString());
|
||||
String userAddress = forDocumentServer ? "&userAddress=" + URLEncoder.encode(hostAddress, java.nio.charset.StandardCharsets.UTF_8.toString()) : "";
|
||||
String query = "?type=downloadhistory&fileName=" + URLEncoder.encode(fileName, java.nio.charset.StandardCharsets.UTF_8.toString()) + userAddress;
|
||||
query = query + "&ver=" + version + "&file=" + URLEncoder.encode(file, java.nio.charset.StandardCharsets.UTF_8.toString());
|
||||
|
||||
return serverPath + "/IndexServlet" + query;
|
||||
@ -568,4 +570,19 @@ public class DocumentManager
|
||||
{
|
||||
return ConfigManager.GetProperty("files.docservice.secret");
|
||||
}
|
||||
|
||||
// get languages
|
||||
public static Map<String, String> GetLanguages()
|
||||
{
|
||||
String langs = ConfigManager.GetProperty("files.docservice.languages");
|
||||
List<String> langsAndKeys = Arrays.asList(langs.split("\\|"));
|
||||
|
||||
Map<String, String> languages = new LinkedHashMap<>();
|
||||
|
||||
langsAndKeys.forEach((str) -> {
|
||||
String[] couple = str.split(":");
|
||||
languages.put(couple[0], couple[1]);
|
||||
});
|
||||
return languages;
|
||||
}
|
||||
}
|
||||
8
web/documentserver-example/java/src/main/java/helpers/TrackManager.java
Normal file → Executable file
8
web/documentserver-example/java/src/main/java/helpers/TrackManager.java
Normal file → Executable file
@ -277,7 +277,7 @@ public class TrackManager {
|
||||
}
|
||||
|
||||
// create a command request
|
||||
public static void commandRequest(String method, String key) throws Exception {
|
||||
public static void commandRequest(String method, String key, HashMap meta) throws Exception {
|
||||
String DocumentCommandUrl = ConfigManager.GetProperty("files.docservice.url.site") + ConfigManager.GetProperty("files.docservice.url.command");
|
||||
|
||||
URL url = new URL(DocumentCommandUrl);
|
||||
@ -287,6 +287,10 @@ public class TrackManager {
|
||||
params.put("c", method);
|
||||
params.put("key", key);
|
||||
|
||||
if (meta != null) {
|
||||
params.put("meta", meta);
|
||||
}
|
||||
|
||||
String headerToken = "";
|
||||
if (DocumentManager.TokenEnabled()) // check if a secret key to generate token exists or not
|
||||
{
|
||||
@ -314,7 +318,7 @@ public class TrackManager {
|
||||
try (OutputStream os = connection.getOutputStream()) {
|
||||
os.write(bodyByte); // write bytes to the output stream
|
||||
}
|
||||
InputStream stream = connection.getInputStream();; // get input stream
|
||||
InputStream stream = connection.getInputStream(); // get input stream
|
||||
|
||||
if (stream == null)
|
||||
throw new Exception("Could not get an answer");
|
||||
|
||||
@ -64,6 +64,9 @@ public class Users {
|
||||
add("Can't mention others in comments");
|
||||
add("Can't create new files from the editor");
|
||||
add("Can’t see anyone’s information");
|
||||
add("Can't rename files from the editor");
|
||||
add("Can't view chat");
|
||||
add("View file without collaboration");
|
||||
}};
|
||||
|
||||
private static List<User> users = new ArrayList<User>() {{
|
||||
|
||||
Submodule web/documentserver-example/java/src/main/resources/assets updated: af97a54226...1fc823afa9
@ -1,4 +1,4 @@
|
||||
version=1.1.0
|
||||
version=1.4.0
|
||||
|
||||
filesize-max=5242880
|
||||
storage-folder=app_data
|
||||
@ -16,5 +16,9 @@ files.docservice.url.api=web-apps/apps/api/documents/api.js
|
||||
files.docservice.url.preloader=web-apps/apps/api/documents/cache-scripts.html
|
||||
files.docservice.url.example=
|
||||
|
||||
files.docservice.languages=en:English|hy:Armenian|az:Azerbaijani|eu:Basque|be:Belarusian|bg:Bulgarian|ca:Catalan|zh:Chinese (People's Republic of China)|zh-TW:Chinese (Traditional, Taiwan)|cs:Czech|da:Danish|nl:Dutch|fi:Finnish|fr:French|gl:Galego|de:German|el:Greek|hu:Hungarian|id:Indonesian|it:Italian|ja:Japanese|ko:Korean|lv:Latvian|lo:Lao|ms:Malay (Malaysia)|nb:Norwegian|pl:Polish|pt:Portuguese (Brazil)|pt-PT:Portuguese (Portugal)|ro:Romanian|ru:Russian|sk:Slovak|sl:Slovenian|es:Spanish|sv:Swedish|tr:Turkish|uk:Ukrainian|vi:Vietnamese
|
||||
|
||||
files.docservice.secret=
|
||||
files.docservice.header=Authorization
|
||||
files.docservice.header=Authorization
|
||||
|
||||
files.docservice.verify-peer-off=TRUE
|
||||
@ -36,6 +36,7 @@
|
||||
<script type="text/javascript" language="javascript">
|
||||
|
||||
var docEditor;
|
||||
var config;
|
||||
|
||||
var innerAlert = function (message, inEditor) {
|
||||
if (console && console.log)
|
||||
@ -97,10 +98,14 @@
|
||||
|
||||
// the meta information of the document is changed via the meta command
|
||||
var onMetaChange = function (event) {
|
||||
var favorite = !!event.data.favorite;
|
||||
var title = document.title.replace(/^\☆/g, "");
|
||||
document.title = (favorite ? "☆" : "") + title;
|
||||
docEditor.setFavorite(favorite); // change the Favorite icon state
|
||||
if (event.data.favorite) {
|
||||
var favorite = !!event.data.favorite;
|
||||
var title = document.title.replace(/^\☆/g, "");
|
||||
document.title = (favorite ? "☆" : "") + title;
|
||||
docEditor.setFavorite(favorite); // change the Favorite icon state
|
||||
}
|
||||
|
||||
innerAlert("onMetaChange: " + JSON.stringify(event.data));
|
||||
};
|
||||
|
||||
// the user is trying to insert an image by clicking the Image from Storage button
|
||||
@ -130,7 +135,7 @@
|
||||
};
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", "IndexServlet?type=saveas");
|
||||
xhr.setRequestHeader( 'Content-Type', 'application/json');
|
||||
xhr.setRequestHeader('Content-Type', 'application/json');
|
||||
xhr.send(JSON.stringify(data));
|
||||
xhr.onload = function () {
|
||||
innerAlert(xhr.responseText);
|
||||
@ -138,7 +143,25 @@
|
||||
}
|
||||
};
|
||||
|
||||
var config = JSON.parse('<%= FileModel.Serialize(Model) %>');
|
||||
var onRequestRename = function(event) { // the user is trying to rename file by clicking Rename... button
|
||||
innerAlert("onRequestRename: " + JSON.stringify(event.data));
|
||||
|
||||
var newfilename = event.data;
|
||||
var data = {
|
||||
newfilename: newfilename,
|
||||
dockey: config.document.key,
|
||||
ext: config.document.fileType
|
||||
};
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", "IndexServlet?type=rename");
|
||||
xhr.setRequestHeader('Content-Type', 'application/json');
|
||||
xhr.send(JSON.stringify(data));
|
||||
xhr.onload = function () {
|
||||
innerAlert(xhr.responseText);
|
||||
}
|
||||
};
|
||||
|
||||
config = JSON.parse('<%= FileModel.Serialize(Model) %>');
|
||||
config.width = "100%";
|
||||
config.height = "100%";
|
||||
config.events = {
|
||||
@ -161,37 +184,38 @@
|
||||
String usersForMentions = (String) request.getAttribute("usersForMentions");
|
||||
%>
|
||||
|
||||
<% if (!history.isEmpty() && !historyData.isEmpty()) { %>
|
||||
// the user is trying to show the document version history
|
||||
config.events['onRequestHistory'] = function () {
|
||||
docEditor.refreshHistory(<%= history %>); // show the document version history
|
||||
};
|
||||
// the user is trying to click the specific document version in the document version history
|
||||
config.events['onRequestHistoryData'] = function (event) {
|
||||
var ver = event.data;
|
||||
var histData = <%= historyData %>;
|
||||
docEditor.setHistoryData(histData[ver - 1]); // send the link to the document for viewing the version history
|
||||
};
|
||||
// the user is trying to go back to the document from viewing the document version history
|
||||
config.events['onRequestHistoryClose'] = function () {
|
||||
document.location.reload();
|
||||
};
|
||||
<% } %>
|
||||
|
||||
<% if (usersForMentions != null) { %>
|
||||
if (config.editorConfig.user.id) {
|
||||
<% if (!history.isEmpty() && !historyData.isEmpty()) { %>
|
||||
// the user is trying to show the document version history
|
||||
config.events['onRequestHistory'] = function () {
|
||||
docEditor.refreshHistory(<%= history %>); // show the document version history
|
||||
};
|
||||
// the user is trying to click the specific document version in the document version history
|
||||
config.events['onRequestHistoryData'] = function (event) {
|
||||
var ver = event.data;
|
||||
var histData = <%= historyData %>;
|
||||
docEditor.setHistoryData(histData[ver - 1]); // send the link to the document for viewing the version history
|
||||
};
|
||||
// the user is trying to go back to the document from viewing the document version history
|
||||
config.events['onRequestHistoryClose'] = function () {
|
||||
document.location.reload();
|
||||
};
|
||||
<% } %>
|
||||
// add mentions for not anonymous users
|
||||
config.events['onRequestUsers'] = function () {
|
||||
docEditor.setUsers({ // set a list of users to mention in the comments
|
||||
"users": ${usersForMentions}
|
||||
"users": <%=usersForMentions%>
|
||||
});
|
||||
};
|
||||
// the user is mentioned in a comment
|
||||
config.events['onRequestSendNotify'] = function (event) {
|
||||
event.data.actionLink = replaceActionLink(location.href, event.data.actionLink);
|
||||
event.data.actionLink = replaceActionLink(location.href, JSON.stringify(event.data.actionLink));
|
||||
var data = JSON.stringify(event.data);
|
||||
innerAlert("onRequestSendNotify: " + data);
|
||||
};
|
||||
<% } %>
|
||||
// prevent file renaming for anonymous users
|
||||
config.events['onRequestRename'] = onRequestRename;
|
||||
}
|
||||
|
||||
if (config.editorConfig.createUrl) {
|
||||
config.events.onRequestSaveAs = onRequestSaveAs;
|
||||
|
||||
42
web/documentserver-example/java/src/main/webapp/index.jsp
Normal file → Executable file
42
web/documentserver-example/java/src/main/webapp/index.jsp
Normal file → Executable file
@ -4,6 +4,8 @@
|
||||
<%@page import="java.util.Calendar"%>
|
||||
<%@page import="java.io.File"%>
|
||||
<%@page import="java.net.URLEncoder"%>
|
||||
<%@page import="java.util.Map.Entry"%>
|
||||
<%@page import="java.util.Map"%>
|
||||
<%@page import="helpers.Users"%>
|
||||
<%@page import="entities.User"%>
|
||||
|
||||
@ -97,37 +99,10 @@
|
||||
<td valign="middle">
|
||||
<span class="select-user">Language editors interface</span>
|
||||
<select class="select-user" id="language">
|
||||
<option value="en">English</option>
|
||||
<option value="be">Belarusian</option>
|
||||
<option value="bg">Bulgarian</option>
|
||||
<option value="ca">Catalan</option>
|
||||
<option value="zh">Chinese</option>
|
||||
<option value="cs">Czech</option>
|
||||
<option value="da">Danish</option>
|
||||
<option value="nl">Dutch</option>
|
||||
<option value="fi">Finnish</option>
|
||||
<option value="fr">French</option>
|
||||
<option value="de">German</option>
|
||||
<option value="el">Greek</option>
|
||||
<option value="hu">Hungarian</option>
|
||||
<option value="id">Indonesian</option>
|
||||
<option value="it">Italian</option>
|
||||
<option value="ja">Japanese</option>
|
||||
<option value="ko">Korean</option>
|
||||
<option value="lv">Latvian</option>
|
||||
<option value="lo">Lao</option>
|
||||
<option value="nb">Norwegian</option>
|
||||
<option value="pl">Polish</option>
|
||||
<option value="pt">Portuguese</option>
|
||||
<option value="ro">Romanian</option>
|
||||
<option value="ru">Russian</option>
|
||||
<option value="sk">Slovak</option>
|
||||
<option value="sl">Slovenian</option>
|
||||
<option value="sv">Swedish</option>
|
||||
<option value="es">Spanish</option>
|
||||
<option value="tr">Turkish</option>
|
||||
<option value="uk">Ukrainian</option>
|
||||
<option value="vi">Vietnamese</option>
|
||||
<% Map<String, String> languages = DocumentManager.GetLanguages(); %>
|
||||
<% for (Map.Entry<String, String> language : languages.entrySet()) { %>
|
||||
<option value="<%=language.getKey()%>"><%=language.getValue()%></option>
|
||||
<% } %>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
@ -373,7 +348,10 @@
|
||||
var EditedExtList = "<%= String.join(",", DocumentManager.GetEditedExts()) %>";
|
||||
var UrlConverter = "IndexServlet?type=convert";
|
||||
var UrlEditor = "EditorServlet";
|
||||
</script>
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function(){
|
||||
document.getElementById("language").value="en";
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@ -1,28 +0,0 @@
|
||||
FROM node:buster
|
||||
LABEL maintainer Ascensio System SIA <support@onlyoffice.com>
|
||||
|
||||
ENV LANG=en_US.UTF-8 \
|
||||
LANGUAGE=en_US:en \
|
||||
LC_ALL=en_US.UTF-8 \
|
||||
NODE_ENV=production-linux \
|
||||
NODE_CONFIG_DIR=/etc/onlyoffice/documentserver-example/
|
||||
|
||||
WORKDIR /var/www/onlyoffice/documentserver-example/
|
||||
COPY . /var/www/onlyoffice/documentserver-example/
|
||||
|
||||
RUN groupadd --system --gid 1001 ds && \
|
||||
useradd --system -g ds --no-create-home --shell /sbin/nologin --uid 1001 ds && \
|
||||
chown -R ds:ds /var/www/onlyoffice/documentserver-example/ && \
|
||||
mkdir -p /var/lib/onlyoffice/documentserver-example/ && \
|
||||
chown -R ds:ds /var/lib/onlyoffice/ && \
|
||||
mv files /var/lib/onlyoffice/documentserver-example/ && \
|
||||
mkdir -p /etc/onlyoffice/documentserver-example/ && \
|
||||
chown -R ds:ds /etc/onlyoffice/ && \
|
||||
mv config/* /etc/onlyoffice/documentserver-example/ && \
|
||||
npm install
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
USER ds
|
||||
|
||||
ENTRYPOINT /var/www/onlyoffice/documentserver-example/docker-entrypoint.sh npm start
|
||||
@ -146,3 +146,12 @@ See the detailed guide to learn how to [install Document Server for Linux](https
|
||||
In case the example and Document Server are installed on different computers, make sure that your server with the example installed has access to the Document Server with the address which you specify instead of **documentserver** in the configuration files.
|
||||
|
||||
Make sure that the Document Server has access to the server with the example installed with the address which you specify instead of **example.com** in the configuration files.
|
||||
|
||||
## Important security info
|
||||
|
||||
Please keep in mind the following security aspects when you are using test examples:
|
||||
|
||||
* There is no protection of the storage from unauthorized access since there is no need for authorization.
|
||||
* There are no checks against parameter substitution in links, since the parameters are generated by the code according to the pre-arranged scripts.
|
||||
* There are no data checks in requests of saving the file after editing, since each test example is intended for requests only from ONLYOFFICE Document Server.
|
||||
* There are no prohibitions on using test examples from other sites, since they are intended to interact with ONLYOFFICE Document Server from another domain.
|
||||
227
web/documentserver-example/nodejs/app.js
Normal file → Executable file
227
web/documentserver-example/nodejs/app.js
Normal file → Executable file
@ -29,6 +29,7 @@ const config = require('config');
|
||||
const configServer = config.get('server');
|
||||
const storageFolder = configServer.get("storageFolder");
|
||||
const mime = require("mime");
|
||||
const urlModule = require("url");
|
||||
const docManager = require("./helpers/docManager");
|
||||
const documentService = require("./helpers/documentService");
|
||||
const fileUtility = require("./helpers/fileUtility");
|
||||
@ -44,9 +45,12 @@ const cfgSignatureAuthorizationHeaderPrefix = configServer.get('token.authorizat
|
||||
const cfgSignatureSecretExpiresIn = configServer.get('token.expiresIn');
|
||||
const cfgSignatureSecret = configServer.get('token.secret');
|
||||
const urllib = require("urllib");
|
||||
const { emitWarning } = require("process");
|
||||
const verifyPeerOff = configServer.get('verify_peer_off');
|
||||
|
||||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
|
||||
|
||||
if(verifyPeerOff) {
|
||||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
|
||||
}
|
||||
|
||||
String.prototype.hashCode = function () {
|
||||
const len = this.length;
|
||||
@ -70,6 +74,7 @@ String.prototype.format = function () {
|
||||
|
||||
|
||||
const app = express(); // create an application object
|
||||
app.disable("x-powered-by");
|
||||
app.set("views", path.join(__dirname, "views")); // specify the path to the main template
|
||||
app.set("view engine", "ejs"); // specify which template engine is used
|
||||
|
||||
@ -108,6 +113,7 @@ app.get("/", function (req, res) { // define a handler for default page
|
||||
params: req.docManager.getCustomParams(),
|
||||
users: users,
|
||||
serverUrl: req.docManager.getServerUrl(),
|
||||
languages: configServer.get('languages'),
|
||||
});
|
||||
|
||||
}
|
||||
@ -124,9 +130,8 @@ app.get("/download", function(req, res) { // define a handler for downloading f
|
||||
|
||||
var fileName = fileUtility.getFileName(req.query.fileName);
|
||||
var userAddress = req.query.useraddress;
|
||||
var isEmbedded = req.query.dmode;
|
||||
|
||||
if ((cfgSignatureEnable && cfgSignatureUseForRequest) && isEmbedded == null ) {
|
||||
if ((cfgSignatureEnable && cfgSignatureUseForRequest)) {
|
||||
var authorization = req.get(cfgSignatureAuthorizationHeader);
|
||||
if (authorization && authorization.startsWith(cfgSignatureAuthorizationHeaderPrefix)) {
|
||||
var token = authorization.substring(cfgSignatureAuthorizationHeaderPrefix.length);
|
||||
@ -208,7 +213,6 @@ app.post("/upload", function (req, res) { // define a handler for uploading fil
|
||||
const form = new formidable.IncomingForm(); // create a new incoming form
|
||||
form.uploadDir = uploadDirTmp; // and write there all the necessary parameters
|
||||
form.keepExtensions = true;
|
||||
form.maxFileSize = configServer.get("maxFileSize");
|
||||
|
||||
form.parse(req, function (err, fields, files) { // parse this form
|
||||
if (err) { // if an error occurs
|
||||
@ -321,7 +325,7 @@ app.post("/convert", function (req, res) { // define a handler for converting f
|
||||
var fileName = fileUtility.getFileName(req.body.filename);
|
||||
var filePass = req.body.filePass ? req.body.filePass : null;
|
||||
var lang = req.body.lang ? req.body.lang : null;
|
||||
var fileUri = req.docManager.getFileUri(fileName);
|
||||
var fileUri = req.docManager.getDownloadUrl(fileName, true);
|
||||
var fileExt = fileUtility.getFileExtension(fileName);
|
||||
var fileType = fileUtility.getFileType(fileName);
|
||||
var internalFileExt = req.docManager.getInternalExtension(fileType);
|
||||
@ -345,7 +349,7 @@ app.post("/convert", function (req, res) { // define a handler for converting f
|
||||
response.end();
|
||||
};
|
||||
|
||||
var callback = function (err, data) {
|
||||
var callback = async function (err, res) {
|
||||
if (err) { // if an error occurs
|
||||
if (err.name === "ConnectionTimeoutError" || err.name === "ResponseTimeoutError") { // check what type of error it is
|
||||
writeResult(fileName, 0, null); // despite the timeout errors, write the file to the result object
|
||||
@ -356,7 +360,7 @@ app.post("/convert", function (req, res) { // define a handler for converting f
|
||||
}
|
||||
|
||||
try {
|
||||
var responseUri = documentService.getResponseUri(data.toString());
|
||||
var responseUri = documentService.getResponseUri(res.toString());
|
||||
var result = responseUri.key;
|
||||
var newFileUri = responseUri.value; // get the callback url
|
||||
|
||||
@ -367,10 +371,11 @@ app.post("/convert", function (req, res) { // define a handler for converting f
|
||||
|
||||
var correctName = req.docManager.getCorrectName(fileUtility.getFileName(fileName, true) + internalFileExt); // get the file name with a new extension
|
||||
|
||||
urllib.request(newFileUri, {method: "GET"},function(err, data) {
|
||||
fileSystem.writeFileSync(req.docManager.storagePath(correctName), data); // write a file with a new extension, but with the content from the origin file
|
||||
});
|
||||
const {status, data} = await urllib.request(newFileUri, {method: "GET"});
|
||||
|
||||
if (status != 200) throw new Error("Conversion service returned status: " + status);
|
||||
|
||||
fileSystem.writeFileSync(req.docManager.storagePath(correctName), data); // write a file with a new extension, but with the content from the origin file
|
||||
fileSystem.unlinkSync(req.docManager.storagePath(fileName)); // remove file with the origin extension
|
||||
|
||||
var userAddress = req.docManager.curUserHostAddress();
|
||||
@ -465,7 +470,76 @@ app.get("/csv", function (req, res) { // define a handler for downloading csv f
|
||||
filestream.pipe(res); // send file information to the response by streams
|
||||
})
|
||||
|
||||
app.post("/track", function (req, res) { // define a handler for tracking file changes
|
||||
app.post("/reference", function (req, res) { //define a handler for renaming file
|
||||
|
||||
req.docManager = new docManager(req, res);
|
||||
|
||||
var result = function(data) {
|
||||
res.writeHead(200, {"Content-Type": "application/json" });
|
||||
res.write(JSON.stringify(data));
|
||||
res.end();
|
||||
};
|
||||
|
||||
var referenceData = req.body.referenceData;
|
||||
if (!!referenceData) {
|
||||
var portalName = referenceData.portalName;
|
||||
|
||||
if (portalName != req.docManager.getServerUrl()) {
|
||||
result({ "error": "You do not have access to this site" });
|
||||
return;
|
||||
}
|
||||
|
||||
var fileId = JSON.parse(referenceData.fileId);
|
||||
var userAddress = fileId.userAddress;
|
||||
if (userAddress != req.docManager.curUserHostAddress()) {
|
||||
result({ "error": "You do not have access to this file" });
|
||||
return;
|
||||
}
|
||||
|
||||
var fileName = fileId.fileName;
|
||||
if (!req.docManager.existsSync(req.docManager.storagePath(fileName, userAddress))) {
|
||||
result({ "error": "File is not exist" });
|
||||
return;
|
||||
}
|
||||
} else if (!!req.body.link) {
|
||||
if (req.body.link.indexOf(req.docManager.curUserHostAddress()) != -1) {
|
||||
result({ "error": "You do not have access to this site" });
|
||||
return;
|
||||
}
|
||||
|
||||
var urlObj = urlModule.parse(req.body.link, true);
|
||||
var fileName = urlObj.query.fileName;
|
||||
if (!req.docManager.existsSync(req.docManager.storagePath(fileName, userAddress))) {
|
||||
result({ "error": "File is not exist" });
|
||||
return;
|
||||
}
|
||||
} else if (!!req.body.path) {
|
||||
var fileName = fileUtility.getFileName(req.body.path);
|
||||
if (!req.docManager.existsSync(req.docManager.storagePath(fileName, userAddress))) {
|
||||
result({ "error": "File is not exist" });
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!fileName) {
|
||||
result({ "error": "File is not found" });
|
||||
return;
|
||||
}
|
||||
|
||||
result({
|
||||
key: req.docManager.getKey(fileName),
|
||||
url: req.docManager.getDownloadUrl(fileName, true),
|
||||
directUrl: req.docManager.getDownloadUrl(fileName),
|
||||
referenceData: {
|
||||
fileId: JSON.stringify({ fileName: fileName, userAddress: req.docManager.curUserHostAddress()}),
|
||||
portalName: req.docManager.getServerUrl()
|
||||
},
|
||||
link: req.docManager.getServerUrl() + "/editor?fileName=" + encodeURIComponent(fileName),
|
||||
path: fileName,
|
||||
});
|
||||
});
|
||||
|
||||
app.post("/track", async function (req, res) { // define a handler for tracking file changes
|
||||
|
||||
req.docManager = new docManager(req, res);
|
||||
|
||||
@ -474,11 +548,15 @@ app.post("/track", function (req, res) { // define a handler for tracking file
|
||||
var version = 0;
|
||||
|
||||
// track file changes
|
||||
var processTrack = function (response, body, fileName, userAddress) {
|
||||
var processTrack = async function (response, body, fileName, userAddress) {
|
||||
|
||||
// callback file saving process
|
||||
var callbackProcessSave = function (downloadUri, body, fileName, userAddress, newFileName) {
|
||||
var callbackProcessSave = async function (downloadUri, body, fileName, userAddress, newFileName) {
|
||||
try {
|
||||
const {status, data} = await urllib.request(downloadUri, {method: "GET"});
|
||||
|
||||
if (status != 200) throw new Error("Document editing service returned status: " + status);
|
||||
|
||||
var storagePath = req.docManager.storagePath(newFileName, userAddress);
|
||||
|
||||
var historyPath = req.docManager.historyPath(newFileName, userAddress); // get the path to the history data
|
||||
@ -495,9 +573,12 @@ app.post("/track", function (req, res) { // define a handler for tracking file
|
||||
var downloadZip = body.changesurl;
|
||||
if (downloadZip) {
|
||||
var path_changes = req.docManager.diffPath(newFileName, userAddress, version); // get the path to the file with document versions differences
|
||||
urllib.request(downloadZip, {method: "GET"},function(err, data) {
|
||||
const {status, data} = await urllib.request(downloadZip, {method: "GET"});
|
||||
if (status == 200) {
|
||||
fileSystem.writeFileSync(path_changes, data); // write the document version differences to the archive
|
||||
});
|
||||
} else {
|
||||
emitWarning("Document editing service returned status: " + status);
|
||||
}
|
||||
}
|
||||
|
||||
var changeshistory = body.changeshistory || JSON.stringify(body.history);
|
||||
@ -512,9 +593,7 @@ app.post("/track", function (req, res) { // define a handler for tracking file
|
||||
var path_prev = path.join(versionPath, "prev" + fileUtility.getFileExtension(fileName)); // get the path to the previous file version
|
||||
fileSystem.renameSync(req.docManager.storagePath(fileName, userAddress), path_prev); // and write it to the current path
|
||||
|
||||
urllib.request(downloadUri, {method: "GET"},function(err, data) {
|
||||
fileSystem.writeFileSync(storagePath, data);
|
||||
});
|
||||
fileSystem.writeFileSync(storagePath, data);
|
||||
|
||||
var forcesavePath = req.docManager.forcesavePath(newFileName, userAddress, false); // get the path to the forcesaved file
|
||||
if (forcesavePath != "") { // if this path is empty
|
||||
@ -522,6 +601,7 @@ app.post("/track", function (req, res) { // define a handler for tracking file
|
||||
}
|
||||
|
||||
} catch (ex) {
|
||||
console.log(ex);
|
||||
response.write("{\"error\":1}");
|
||||
response.end();
|
||||
return;
|
||||
@ -532,7 +612,7 @@ app.post("/track", function (req, res) { // define a handler for tracking file
|
||||
}
|
||||
|
||||
// file saving process
|
||||
var processSave = function (downloadUri, body, fileName, userAddress) {
|
||||
var processSave = async function (downloadUri, body, fileName, userAddress) {
|
||||
|
||||
if (!downloadUri) {
|
||||
response.write("{\"error\":1}");
|
||||
@ -553,18 +633,18 @@ app.post("/track", function (req, res) { // define a handler for tracking file
|
||||
var key = documentService.generateRevisionId(downloadUri);
|
||||
newFileName = req.docManager.getCorrectName(fileUtility.getFileName(fileName, true) + downloadExt, userAddress); // get the correct file name if it already exists
|
||||
try {
|
||||
documentService.getConvertedUriSync(downloadUri, downloadExt, curExt, key, function (err, data) {
|
||||
documentService.getConvertedUriSync(downloadUri, downloadExt, curExt, key, async function (err, data) {
|
||||
if (err) {
|
||||
callbackProcessSave(downloadUri, body, fileName, userAddress, newFileName);
|
||||
await callbackProcessSave(downloadUri, body, fileName, userAddress, newFileName);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
var res = documentService.getResponseUri(data);
|
||||
callbackProcessSave(res.value, body, fileName, userAddress, fileName);
|
||||
await callbackProcessSave(res.value, body, fileName, userAddress, fileName);
|
||||
return;
|
||||
} catch (ex) {
|
||||
console.log(ex);
|
||||
callbackProcessSave(downloadUri, body, fileName, userAddress, newFileName);
|
||||
await callbackProcessSave(downloadUri, body, fileName, userAddress, newFileName);
|
||||
return;
|
||||
}
|
||||
});
|
||||
@ -573,12 +653,16 @@ app.post("/track", function (req, res) { // define a handler for tracking file
|
||||
console.log(ex);
|
||||
}
|
||||
}
|
||||
callbackProcessSave(downloadUri, body, fileName, userAddress, newFileName);
|
||||
await callbackProcessSave(downloadUri, body, fileName, userAddress, newFileName);
|
||||
};
|
||||
|
||||
// callback file force saving process
|
||||
var callbackProcessForceSave = function (downloadUri, body, fileName, userAddress, newFileName = false){
|
||||
var callbackProcessForceSave = async function (downloadUri, body, fileName, userAddress, newFileName = false){
|
||||
try {
|
||||
const {status, data} = await urllib.request(downloadUri, {method: "GET"});
|
||||
|
||||
if (status != 200) throw new Error("Document editing service returned status: " + status);
|
||||
|
||||
var downloadExt = "." + body.fileType;
|
||||
|
||||
/// TODO [Delete in version 7.0 or higher]
|
||||
@ -606,9 +690,7 @@ app.post("/track", function (req, res) { // define a handler for tracking file
|
||||
}
|
||||
}
|
||||
|
||||
urllib.request(downloadUri, {method: "GET"},function(err, data) {
|
||||
fileSystem.writeFileSync(forcesavePath, data);
|
||||
});
|
||||
fileSystem.writeFileSync(forcesavePath, data);
|
||||
|
||||
if (isSubmitForm) {
|
||||
var uid =body.actions[0].userid
|
||||
@ -625,7 +707,7 @@ app.post("/track", function (req, res) { // define a handler for tracking file
|
||||
}
|
||||
|
||||
// file force saving process
|
||||
var processForceSave = function (downloadUri, body, fileName, userAddress) {
|
||||
var processForceSave = async function (downloadUri, body, fileName, userAddress) {
|
||||
|
||||
if (!downloadUri) {
|
||||
response.write("{\"error\":1}");
|
||||
@ -643,18 +725,18 @@ app.post("/track", function (req, res) { // define a handler for tracking file
|
||||
if (downloadExt != curExt) {
|
||||
var key = documentService.generateRevisionId(downloadUri);
|
||||
try {
|
||||
documentService.getConvertedUriSync(downloadUri, downloadExt, curExt, key, function (err, data) {
|
||||
documentService.getConvertedUriSync(downloadUri, downloadExt, curExt, key, async function (err, data) {
|
||||
if (err) {
|
||||
callbackProcessForceSave(downloadUri, body, fileName, userAddress, true);
|
||||
await callbackProcessForceSave(downloadUri, body, fileName, userAddress, true);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
var res = documentService.getResponseUri(data);
|
||||
callbackProcessForceSave(res.value, body, fileName, userAddress, false);
|
||||
await callbackProcessForceSave(res.value, body, fileName, userAddress, false);
|
||||
return;
|
||||
} catch (ex) {
|
||||
console.log(ex);
|
||||
callbackProcessForceSave(downloadUri, body, fileName, userAddress, true);
|
||||
await callbackProcessForceSave(downloadUri, body, fileName, userAddress, true);
|
||||
return;
|
||||
}
|
||||
});
|
||||
@ -663,7 +745,7 @@ app.post("/track", function (req, res) { // define a handler for tracking file
|
||||
console.log(ex);
|
||||
}
|
||||
}
|
||||
callbackProcessForceSave (downloadUri, body, fileName, userAddress, false);
|
||||
await callbackProcessForceSave (downloadUri, body, fileName, userAddress, false);
|
||||
};
|
||||
|
||||
if (body.status == 1) { // editing
|
||||
@ -679,10 +761,10 @@ app.post("/track", function (req, res) { // define a handler for tracking file
|
||||
}
|
||||
}
|
||||
} else if (body.status == 2 || body.status == 3) { // MustSave, Corrupted
|
||||
processSave(body.url, body, fileName, userAddress); // save file
|
||||
await processSave(body.url, body, fileName, userAddress); // save file
|
||||
return;
|
||||
} else if (body.status == 6 || body.status == 7) { // MustForceSave, CorruptedForceSave
|
||||
processForceSave(body.url, body, fileName, userAddress); // force save file
|
||||
await processForceSave(body.url, body, fileName, userAddress); // force save file
|
||||
return;
|
||||
}
|
||||
|
||||
@ -691,14 +773,14 @@ app.post("/track", function (req, res) { // define a handler for tracking file
|
||||
};
|
||||
|
||||
// read request body
|
||||
var readbody = function (request, response, fileName, userAddress) {
|
||||
var readbody = async function (request, response, fileName, userAddress) {
|
||||
var content = "";
|
||||
request.on('data', function (data) { // get data from the request
|
||||
request.on('data', async function (data) { // get data from the request
|
||||
content += data;
|
||||
});
|
||||
request.on('end', function () {
|
||||
request.on('end', async function () {
|
||||
var body = JSON.parse(content);
|
||||
processTrack(response, body, fileName, userAddress); // and track file changes
|
||||
await processTrack(response, body, fileName, userAddress); // and track file changes
|
||||
});
|
||||
};
|
||||
|
||||
@ -730,14 +812,14 @@ app.post("/track", function (req, res) { // define a handler for tracking file
|
||||
res.end();
|
||||
return;
|
||||
}
|
||||
processTrack(res, body, fileName, userAddress);
|
||||
await processTrack(res, body, fileName, userAddress);
|
||||
return;
|
||||
}
|
||||
|
||||
if (req.body.hasOwnProperty("status")) { // if the request body has status parameter
|
||||
processTrack(res, req.body, fileName, userAddress); // track file changes
|
||||
await processTrack(res, req.body, fileName, userAddress); // track file changes
|
||||
} else {
|
||||
readbody(req, res, fileName, userAddress); // otherwise, read request body first
|
||||
await readbody(req, res, fileName, userAddress); // otherwise, read request body first
|
||||
}
|
||||
});
|
||||
|
||||
@ -752,6 +834,7 @@ app.get("/editor", function (req, res) { // define a handler for editing docume
|
||||
var historyData = [];
|
||||
var lang = req.docManager.getLang();
|
||||
var user = users.getUser(req.query.userid);
|
||||
var userDirectUrl = req.query.directUrl == "true";
|
||||
|
||||
var userid = user.id;
|
||||
var name = user.name;
|
||||
@ -766,6 +849,11 @@ app.get("/editor", function (req, res) { // define a handler for editing docume
|
||||
}
|
||||
}
|
||||
|
||||
var referenceData = {
|
||||
fileId: JSON.stringify({ fileName: fileName, userAddress: req.docManager.curUserHostAddress()}),
|
||||
portalName: req.docManager.getServerUrl()
|
||||
};
|
||||
|
||||
var templatesImageUrl = req.docManager.getTemplateImageUrl(fileUtility.getFileType(fileName));
|
||||
var createUrl = req.docManager.getCreateUrl(fileUtility.getFileType(fileName), userid, type, lang);
|
||||
var templates = [
|
||||
@ -803,8 +891,8 @@ app.get("/editor", function (req, res) { // define a handler for editing docume
|
||||
};
|
||||
}
|
||||
var key = req.docManager.getKey(fileName);
|
||||
var url = req.docManager.getDownloadUrl(fileName);
|
||||
var urlUser = path.isAbsolute(storageFolder) ? req.docManager.getDownloadUrl(fileName) + "&dmode=emb" : req.docManager.getlocalFileUri(fileName, 0, false);
|
||||
var url = req.docManager.getDownloadUrl(fileName, true);
|
||||
var directUrl = req.docManager.getDownloadUrl(fileName);
|
||||
var mode = req.query.mode || "edit"; // mode: view/edit/review/comment/fillForms/embedded
|
||||
|
||||
var type = req.query.type || ""; // type: embedded/mobile/desktop
|
||||
@ -848,7 +936,8 @@ app.get("/editor", function (req, res) { // define a handler for editing docume
|
||||
fileType: fileExt.slice(1),
|
||||
version: i,
|
||||
key: keyVersion,
|
||||
url: i == countVersion ? url : (`${req.docManager.getServerUrl(false)}/history?fileName=${encodeURIComponent(fileName)}&file=prev${fileExt}&ver=${i}&useraddress=${userAddress}`),
|
||||
url: i == countVersion ? url : (`${req.docManager.getServerUrl(true)}/history?fileName=${encodeURIComponent(fileName)}&file=prev${fileExt}&ver=${i}&useraddress=${userAddress}`),
|
||||
directUrl: !userDirectUrl ? null : i == countVersion ? directUrl : (`${req.docManager.getServerUrl(false)}/history?fileName=${encodeURIComponent(fileName)}&file=prev${fileExt}&ver=${i}`),
|
||||
};
|
||||
|
||||
if (i > 1 && req.docManager.existsSync(req.docManager.diffPath(fileName, userAddress, i-1))) { // check if the path to the file with document versions differences exists
|
||||
@ -856,8 +945,9 @@ app.get("/editor", function (req, res) { // define a handler for editing docume
|
||||
fileType: historyData[i-2].fileType,
|
||||
key: historyData[i-2].key,
|
||||
url: historyData[i-2].url,
|
||||
directUrl: !userDirectUrl ? null : historyData[i-2].directUrl,
|
||||
};
|
||||
let changesUrl = `${req.docManager.getServerUrl(false)}/history?fileName=${encodeURIComponent(fileName)}&file=diff.zip&ver=${i-1}&useraddress=${userAddress}`;
|
||||
let changesUrl = `${req.docManager.getServerUrl(true)}/history?fileName=${encodeURIComponent(fileName)}&file=diff.zip&ver=${i-1}&useraddress=${userAddress}`;
|
||||
historyD.changesUrl = changesUrl; // get the path to the diff.zip file and write it to the history object
|
||||
}
|
||||
|
||||
@ -873,7 +963,8 @@ app.get("/editor", function (req, res) { // define a handler for editing docume
|
||||
historyData.push({
|
||||
version: countVersion,
|
||||
key: key,
|
||||
url: url
|
||||
url: url,
|
||||
directUrl: !userDirectUrl ? null : directUrl,
|
||||
});
|
||||
}
|
||||
|
||||
@ -890,7 +981,8 @@ app.get("/editor", function (req, res) { // define a handler for editing docume
|
||||
name: fileName,
|
||||
ext: fileUtility.getFileExtension(fileName, true),
|
||||
uri: url,
|
||||
uriUser: urlUser,
|
||||
directUrl: !userDirectUrl ? null : directUrl,
|
||||
uriUser: directUrl,
|
||||
version: countVersion,
|
||||
created: new Date().toDateString(),
|
||||
favorite: user.favorite != null ? user.favorite : "null"
|
||||
@ -905,6 +997,8 @@ app.get("/editor", function (req, res) { // define a handler for editing docume
|
||||
templates: user.templates ? templates : null,
|
||||
isEdit: canEdit && (mode == "edit" || mode == "view" || mode == "filter" || mode == "blockcontent"),
|
||||
review: canEdit && (mode == "edit" || mode == "review"),
|
||||
chat: userid != "uid-0",
|
||||
coEditing: mode == "view" && userid == "uid-0" ? {mode: "strict", change: false} : null,
|
||||
comment: mode != "view" && mode != "fillForms" && mode != "embedded" && mode != "blockcontent",
|
||||
fillForms: mode != "view" && mode != "comment" && mode != "embedded" && mode != "blockcontent",
|
||||
modifyFilter: mode != "filter",
|
||||
@ -926,21 +1020,25 @@ app.get("/editor", function (req, res) { // define a handler for editing docume
|
||||
fileChoiceUrl: fileChoiceUrl,
|
||||
submitForm: submitForm,
|
||||
plugins: JSON.stringify(plugins),
|
||||
actionData: actionData
|
||||
actionData: actionData,
|
||||
referenceData: userid != "uid-0" ? referenceData : null
|
||||
},
|
||||
history: history,
|
||||
historyData: historyData,
|
||||
dataInsertImage: {
|
||||
fileType: "png",
|
||||
url: req.docManager.getServerUrl(true) + "/images/logo.png"
|
||||
url: req.docManager.getServerUrl(true) + "/images/logo.png",
|
||||
directUrl: !userDirectUrl ? null : req.docManager.getServerUrl() + "/images/logo.png",
|
||||
},
|
||||
dataCompareFile: {
|
||||
fileType: "docx",
|
||||
url: req.docManager.getServerUrl(true) + "/assets/sample/sample.docx"
|
||||
url: req.docManager.getServerUrl(true) + "/assets/sample/sample.docx",
|
||||
directUrl: !userDirectUrl ? null : req.docManager.getServerUrl() + "/assets/sample/sample.docx",
|
||||
},
|
||||
dataMailMergeRecipients: {
|
||||
fileType: "csv",
|
||||
url: req.docManager.getServerUrl(true) + "/csv"
|
||||
url: req.docManager.getServerUrl(true) + "/csv",
|
||||
directUrl: !userDirectUrl ? null : req.docManager.getServerUrl() + "/csv",
|
||||
},
|
||||
usersForMentions: user.id != "uid-0" ? users.getUsersForMentions(user.id) : null,
|
||||
};
|
||||
@ -969,6 +1067,27 @@ app.get("/editor", function (req, res) { // define a handler for editing docume
|
||||
}
|
||||
});
|
||||
|
||||
app.post("/rename", function (req, res) { //define a handler for renaming file
|
||||
|
||||
var newfilename = req.body.newfilename;
|
||||
var origExt = req.body.ext;
|
||||
var curExt = fileUtility.getFileExtension(newfilename, true);
|
||||
if (curExt !== origExt) {
|
||||
newfilename += '.' + origExt;
|
||||
}
|
||||
|
||||
var dockey = req.body.dockey;
|
||||
var meta = {title: newfilename};
|
||||
|
||||
var result = function(err, data, ress) {
|
||||
res.writeHead(200, {"Content-Type": "application/json" });
|
||||
res.write(JSON.stringify({ "result": ress }));
|
||||
res.end();
|
||||
};
|
||||
|
||||
documentService.commandRequest("meta", dockey, meta, result);
|
||||
});
|
||||
|
||||
wopiApp.registerRoutes(app);
|
||||
|
||||
// "Not found" error with 404 status
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": "1.1.0",
|
||||
"version": "1.4.0",
|
||||
"log": {
|
||||
"appenders": [
|
||||
{
|
||||
@ -44,6 +44,47 @@
|
||||
"authorizationHeaderPrefix": "Bearer ",
|
||||
"secret": "secret",
|
||||
"expiresIn": "5m"
|
||||
},
|
||||
"verify_peer_off": true,
|
||||
"languages": {
|
||||
"en": "English",
|
||||
"hy": "Armenian",
|
||||
"az": "Azerbaijani",
|
||||
"eu": "Basque",
|
||||
"be": "Belarusian",
|
||||
"bg": "Bulgarian",
|
||||
"ca": "Catalan",
|
||||
"zh" : "Chinese (People's Republic of China)",
|
||||
"zh-TW" : "Chinese (Traditional, Taiwan)",
|
||||
"cs": "Czech",
|
||||
"da": "Danish",
|
||||
"nl": "Dutch",
|
||||
"fi": "Finnish",
|
||||
"fr": "French",
|
||||
"gl": "Galego",
|
||||
"de": "German",
|
||||
"el": "Greek",
|
||||
"hu": "Hungarian",
|
||||
"id": "Indonesian",
|
||||
"it": "Italian",
|
||||
"ja": "Japanese",
|
||||
"ko": "Korean",
|
||||
"lv": "Latvian",
|
||||
"lo": "Lao",
|
||||
"ms": "Malay (Malaysia)",
|
||||
"nb": "Norwegian",
|
||||
"pl": "Polish",
|
||||
"pt" : "Portuguese (Brazil)",
|
||||
"pt-PT" : "Portuguese (Portugal)",
|
||||
"ro": "Romanian",
|
||||
"ru": "Russian",
|
||||
"sk": "Slovak",
|
||||
"sl": "Slovenian",
|
||||
"es": "Spanish",
|
||||
"sv": "Swedish",
|
||||
"tr": "Turkish",
|
||||
"uk": "Ukrainian",
|
||||
"vi": "Vietnamese"
|
||||
}
|
||||
},
|
||||
"plugins": {
|
||||
|
||||
@ -66,6 +66,9 @@ docManager.prototype.getCustomParams = function () {
|
||||
const lang = this.req.query.lang; // language
|
||||
params += (lang ? "&lang=" + this.getLang() : "");
|
||||
|
||||
const directUrl = this.req.query.directUrl; // directUrl
|
||||
params += (directUrl ? "&directUrl=" + (directUrl == "true") : "");
|
||||
|
||||
const fileName = this.req.query.fileName; // file name
|
||||
params += (fileName ? "&fileName=" + fileName : "");
|
||||
|
||||
@ -163,22 +166,6 @@ docManager.prototype.getFileData = function (fileName, userAddress) {
|
||||
return ((fileSystem.readFileSync(history)).toString()).split(",");
|
||||
};
|
||||
|
||||
// get url to the original file
|
||||
docManager.prototype.getFileUri = function (fileName) {
|
||||
return this.getlocalFileUri(fileName, 0, true);
|
||||
};
|
||||
|
||||
// get local file url
|
||||
docManager.prototype.getlocalFileUri = function (fileName, version, forDocumentServer) {
|
||||
const serverPath = this.getServerUrl(forDocumentServer);
|
||||
const hostAddress = this.curUserHostAddress();
|
||||
let url = serverPath + configServer.get("storagePath") + "/" + hostAddress + "/" + encodeURIComponent(fileName); // get full url address to the file
|
||||
if (!version) {
|
||||
return url;
|
||||
}
|
||||
return url + "-history/" + version; // return history path to the specified file version
|
||||
};
|
||||
|
||||
// get server url
|
||||
docManager.prototype.getServerUrl = function (forDocumentServer) {
|
||||
return (forDocumentServer && !!configServer.get("exampleUrl")) ? configServer.get("exampleUrl") : this.getServerPath();
|
||||
@ -218,10 +205,13 @@ docManager.prototype.getCreateUrl = function (docType, userid, type, lang) {
|
||||
}
|
||||
|
||||
// get url to download a file
|
||||
docManager.prototype.getDownloadUrl = function (fileName) {
|
||||
const server = this.getServerUrl(true);
|
||||
const hostAddress = this.curUserHostAddress();
|
||||
const handler = "/download?fileName=" + encodeURIComponent(fileName) + "&useraddress=" + encodeURIComponent(hostAddress);
|
||||
docManager.prototype.getDownloadUrl = function (fileName, forDocumentServer) {
|
||||
const server = this.getServerUrl(forDocumentServer);
|
||||
var handler = "/download?fileName=" + encodeURIComponent(fileName);
|
||||
if (forDocumentServer) {
|
||||
const hostAddress = this.curUserHostAddress();
|
||||
handler += "&useraddress=" + encodeURIComponent(hostAddress);
|
||||
}
|
||||
|
||||
return server + handler;
|
||||
};
|
||||
@ -385,9 +375,9 @@ docManager.prototype.getTemplateImageUrl = function (fileType) {
|
||||
}
|
||||
|
||||
// get document key
|
||||
docManager.prototype.getKey = function (fileName) {
|
||||
const userAddress = this.curUserHostAddress();
|
||||
let key = userAddress + this.getlocalFileUri(fileName); // get document key by adding local file url to the current user host address
|
||||
docManager.prototype.getKey = function (fileName, userAddress) {
|
||||
userAddress = userAddress || this.curUserHostAddress();
|
||||
let key = userAddress + fileName; // get document key by adding local file url to the current user host address
|
||||
|
||||
let historyPath = this.historyPath(fileName, userAddress); // get the path to the file history
|
||||
if (historyPath != ""){ // if the path to the file history exists
|
||||
|
||||
9
web/documentserver-example/nodejs/helpers/documentService.js
Normal file → Executable file
9
web/documentserver-example/nodejs/helpers/documentService.js
Normal file → Executable file
@ -168,13 +168,18 @@ documentService.getResponseUri = function (json) {
|
||||
};
|
||||
|
||||
// create a command request
|
||||
documentService.commandRequest = function (method, documentRevisionId, callback) {
|
||||
documentService.commandRequest = function (method, documentRevisionId, meta = null, callback) {
|
||||
|
||||
documentRevisionId = documentService.generateRevisionId(documentRevisionId); // generate the document key value
|
||||
var params = { // create a parameter object with command method and the document key value in it
|
||||
params = { // create a parameter object with command method and the document key value in it
|
||||
c: method,
|
||||
key: documentRevisionId
|
||||
};
|
||||
|
||||
if (meta) {
|
||||
params.meta = meta;
|
||||
}
|
||||
|
||||
var uri = siteUrl + configServer.get('commandUrl'); // get the absolute command url
|
||||
var headers = { // create a headers object
|
||||
'Content-Type': 'application/json'
|
||||
|
||||
@ -22,7 +22,9 @@ var fileUtility = {};
|
||||
fileUtility.getFileName = function (url, withoutExtension) {
|
||||
if (!url) return "";
|
||||
|
||||
var parts = url.split("/");
|
||||
var parts = url.split("\\");
|
||||
parts = parts.pop();
|
||||
parts = parts.split("/");
|
||||
var fileName = parts.pop(); // get the file name from the last part of the url
|
||||
fileName = fileName.split("?")[0];
|
||||
|
||||
|
||||
@ -59,6 +59,9 @@ var descr_user_0 = [
|
||||
"Can't mention others in comments",
|
||||
"Can't create new files from the editor",
|
||||
"Can’t see anyone’s information",
|
||||
"Can't rename files from the editor",
|
||||
"Can't view chat",
|
||||
"View file without collaboration",
|
||||
//"Can’t submit forms"
|
||||
];
|
||||
|
||||
|
||||
@ -23,6 +23,7 @@ const fileSystem = require("fs");
|
||||
const mime = require("mime");
|
||||
const path = require("path");
|
||||
const users = require("../users");
|
||||
const docManager = require("../docManager");
|
||||
|
||||
const actionMapping = {};
|
||||
actionMapping[reqConsts.requestType.GetFile] = getFile;
|
||||
@ -255,8 +256,8 @@ function putFile(wopi, req, res, userHost) {
|
||||
// return information about the file properties, access rights and editor settings
|
||||
function checkFileInfo(wopi, req, res, userHost) {
|
||||
let userAddress = req.docManager.curUserHostAddress(userHost);
|
||||
let version = req.docManager.getKey(wopi.id);
|
||||
|
||||
let version = req.docManager.getKey(wopi.id, userAddress);
|
||||
|
||||
let path = req.docManager.storagePath(wopi.id, userAddress);
|
||||
// add wopi query
|
||||
var query = new URLSearchParams(wopi.accessToken);
|
||||
@ -289,6 +290,7 @@ function returnLockMismatch(res, lock, reason) {
|
||||
|
||||
exports.fileRequestHandler = (req, res) => {
|
||||
let userAddress = null;
|
||||
req.docManager = new docManager(req, res);
|
||||
if (req.params['id'].includes("@")) { // if there is the "@" sign in the id parameter
|
||||
let split = req.params['id'].split("@"); // split this parameter by "@"
|
||||
req.params['id'] = split[0]; // rewrite id with the first part of the split parameter
|
||||
@ -310,5 +312,5 @@ exports.fileRequestHandler = (req, res) => {
|
||||
return;
|
||||
}
|
||||
|
||||
action(wopiData, req, res);
|
||||
action(wopiData, req, res, userAddress);
|
||||
}
|
||||
1
web/documentserver-example/nodejs/helpers/wopi/wopiRouting.js
Normal file → Executable file
1
web/documentserver-example/nodejs/helpers/wopi/wopiRouting.js
Normal file → Executable file
@ -83,6 +83,7 @@ exports.registerRoutes = function(app) {
|
||||
convertExts: configServer.get('convertedDocs'),
|
||||
editedExts: editedExts,
|
||||
fillExts: fillExts,
|
||||
languages: configServer.get('languages'),
|
||||
});
|
||||
|
||||
} catch (ex) {
|
||||
|
||||
2130
web/documentserver-example/nodejs/npm-shrinkwrap.json
generated
2130
web/documentserver-example/nodejs/npm-shrinkwrap.json
generated
File diff suppressed because it is too large
Load Diff
Submodule web/documentserver-example/nodejs/public/assets updated: af97a54226...1fc823afa9
@ -18,12 +18,14 @@
|
||||
|
||||
var language;
|
||||
var userid;
|
||||
var directUrl;
|
||||
|
||||
if (typeof jQuery != "undefined") {
|
||||
jq = jQuery.noConflict();
|
||||
|
||||
userid = getUrlVars()["userid"];
|
||||
language = getUrlVars()["lang"];
|
||||
directUrl = getUrlVars()["directUrl"] == "true";
|
||||
|
||||
mustReload = false;
|
||||
|
||||
@ -34,19 +36,29 @@ if (typeof jQuery != "undefined") {
|
||||
|
||||
|
||||
jq("#language").change(function() {
|
||||
window.location = "?lang=" + jq(this).val() + "&userid=" + userid;
|
||||
window.location = "?lang=" + jq(this).val() + "&userid=" + userid + "&directUrl=" + directUrl;
|
||||
});
|
||||
|
||||
|
||||
if ("" != userid && undefined != userid)
|
||||
jq("#user").val(userid);
|
||||
else
|
||||
userid = jq("#user").val();
|
||||
|
||||
jq("#user").change(function() {
|
||||
window.location = "?lang=" + language + "&userid=" + jq(this).val();
|
||||
window.location = "?lang=" + language + "&userid=" + jq(this).val() + "&directUrl=" + directUrl;
|
||||
});
|
||||
|
||||
|
||||
if (directUrl)
|
||||
jq("#directUrl").prop("checked", directUrl);
|
||||
else
|
||||
directUrl = jq("#directUrl").prop("checked");
|
||||
|
||||
jq("#directUrl").change(function() {
|
||||
window.location = "?lang=" + language + "&userid=" + userid + "&directUrl=" + jq(this).prop("checked");
|
||||
});
|
||||
|
||||
|
||||
jq(function () {
|
||||
jq('#fileupload').fileupload({
|
||||
dataType: 'json',
|
||||
@ -228,7 +240,7 @@ if (typeof jQuery != "undefined") {
|
||||
if (UrlEditor == "wopi-action"){
|
||||
var url = UrlEditor + "/" + fileId + "?action=edit";
|
||||
}else{
|
||||
var url = UrlEditor + "?fileName=" + fileId + "&lang=" + language + "&userid=" + userid;
|
||||
var url = UrlEditor + "?fileName=" + fileId + "&lang=" + language + "&userid=" + userid + "&directUrl=" + directUrl;
|
||||
}
|
||||
window.open(url, "_blank");
|
||||
jq('#hiddenFileName').val("");
|
||||
@ -241,7 +253,7 @@ if (typeof jQuery != "undefined") {
|
||||
if (UrlEditor == "wopi-action"){
|
||||
var url = UrlEditor + "/" + fileId + "?action=view";
|
||||
}else{
|
||||
var url = UrlEditor + "?mode=view&fileName=" + fileId + "&lang=" + language + "&userid=" + userid;
|
||||
var url = UrlEditor + "?mode=view&fileName=" + fileId + "&lang=" + language + "&userid=" + userid + "&directUrl=" + directUrl;
|
||||
}
|
||||
window.open(url, "_blank");
|
||||
jq('#hiddenFileName').val("");
|
||||
@ -251,7 +263,7 @@ if (typeof jQuery != "undefined") {
|
||||
|
||||
jq(document).on("click", "#beginEmbedded:not(.disable)", function () {
|
||||
var fileId = encodeURIComponent(jq('#hiddenFileName').val());
|
||||
var url = UrlEditor + "?type=embedded&fileName=" + fileId + "&lang=" + language + "&userid=" + userid;
|
||||
var url = UrlEditor + "?type=embedded&fileName=" + fileId + "&lang=" + language + "&userid=" + userid + "&directUrl=" + directUrl;
|
||||
|
||||
jq("#mainProgress").addClass("embedded");
|
||||
jq("#beginEmbedded").addClass("disable");
|
||||
@ -328,12 +340,12 @@ if (typeof jQuery != "undefined") {
|
||||
if (hideTooltipTimeout != null) {
|
||||
clearTimeout(hideTooltipTimeout);
|
||||
}
|
||||
jq(".info").on("touchend", function () {
|
||||
jq("#info").on("touchend", function () {
|
||||
showUserTooltip(true);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
jq(".info").mouseover(function (event) {
|
||||
jq("#info").mouseover(function (event) {
|
||||
if (fileList.length > 0) {
|
||||
if (hideTooltipTimeout != null) {
|
||||
clearTimeout(hideTooltipTimeout);
|
||||
@ -357,6 +369,20 @@ if (typeof jQuery != "undefined") {
|
||||
}, 500);
|
||||
});
|
||||
}
|
||||
|
||||
jq(".info-tooltip").mouseover(function (event) {
|
||||
var target = event.target;
|
||||
var id = target.dataset.id ? target.dataset.id : target.id;
|
||||
var tooltip = target.dataset.tooltip;
|
||||
|
||||
jq("<div class='tooltip'>" + tooltip + "<div class='arrow'></div></div>").appendTo("body");
|
||||
|
||||
var top = jq("#" + id).offset().top + jq("#" + id).outerHeight() / 2 - jq("div.tooltip").outerHeight() / 2;
|
||||
var left = jq("#" + id).offset().left + jq("#" + id).outerWidth() + 20;
|
||||
jq("div.tooltip").css({"top": top, "left": left});
|
||||
}).mouseout(function () {
|
||||
jq("div.tooltip").remove();
|
||||
});
|
||||
}
|
||||
|
||||
function getUrlVars() {
|
||||
|
||||
@ -165,7 +165,7 @@ label .checkbox {
|
||||
background-image: url("../images/file_docxf.svg");
|
||||
}
|
||||
|
||||
.create-sample {
|
||||
.side-option {
|
||||
color: #666666;
|
||||
line-height: 24px;
|
||||
}
|
||||
@ -620,6 +620,31 @@ footer table tr td:first-child {
|
||||
margin: -2px 5px;
|
||||
}
|
||||
|
||||
.tooltip {
|
||||
background: #FFFFFF;
|
||||
border-radius: 5px;
|
||||
box-shadow: 0px 7px 25px rgba(85, 85, 85, 0.15);
|
||||
color: #666666;
|
||||
line-height: 160%;
|
||||
max-width: 455px;
|
||||
padding: 14px;
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
.tooltip ul {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.arrow {
|
||||
border-top: 8px solid transparent;
|
||||
border-bottom: 8px solid transparent;
|
||||
border-right: 8px solid #FFFFFF;
|
||||
left: -4px;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
}
|
||||
|
||||
.user-block-table {
|
||||
height: 100%;
|
||||
padding-top: 14px;
|
||||
|
||||
61
web/documentserver-example/nodejs/views/config.ejs
Normal file → Executable file
61
web/documentserver-example/nodejs/views/config.ejs
Normal file → Executable file
@ -1,54 +1,39 @@
|
||||
"width": "100%",
|
||||
"height": "100%",
|
||||
"type": "<%- editor.type %>",
|
||||
"documentType": "<%- editor.documentType %>",
|
||||
"token": "<%- editor.token %>",
|
||||
"document": {
|
||||
"title": "<%- file.name %>",
|
||||
"url": "<%- file.uri %>",
|
||||
"document": {
|
||||
"directUrl": "<%- file.directUrl %>",
|
||||
"fileType": "<%- file.ext %>",
|
||||
"key": "<%- editor.key %>",
|
||||
"info": {
|
||||
"owner": "Me",
|
||||
"uploaded": "<%- file.created %>",
|
||||
"favorite": <%- file.favorite %>
|
||||
},
|
||||
"key": "<%- editor.key %>",
|
||||
"permissions": {
|
||||
"chat": <%- editor.chat %>,
|
||||
"comment": <%- editor.comment %>,
|
||||
"copy": <%- editor.copy %>,
|
||||
"download": <%- editor.download %>,
|
||||
"edit": <%- editor.isEdit %>,
|
||||
"print": <%- editor.print %>,
|
||||
"fillForms": <%- editor.fillForms %>,
|
||||
"modifyFilter": <%- editor.modifyFilter %>,
|
||||
"modifyContentControl": <%- editor.modifyContentControl %>,
|
||||
"modifyFilter": <%- editor.modifyFilter %>,
|
||||
"print": <%- editor.print %>,
|
||||
"review": <%- editor.review %>,
|
||||
"reviewGroups": <%- editor.reviewGroups %>,
|
||||
"commentGroups": <%- editor.commentGroups %>,
|
||||
"userInfoGroups": <%- editor.userInfoGroups %>
|
||||
}
|
||||
},
|
||||
"referenceData": <%- JSON.stringify(editor.referenceData) %>,
|
||||
"title": "<%- file.name %>",
|
||||
"url": "<%- file.uri %>"
|
||||
},
|
||||
"documentType": "<%- editor.documentType %>",
|
||||
"editorConfig": {
|
||||
"actionLink": <%- editor.actionData %>,
|
||||
"mode": "<%- editor.mode %>",
|
||||
"lang": "<%- editor.lang %>",
|
||||
"callbackUrl": "<%- editor.callbackUrl %>",
|
||||
"coEditing": <%- JSON.stringify(editor.coEditing) %>,
|
||||
"createUrl": <%- JSON.stringify(editor.createUrl) %>,
|
||||
"templates": <%- JSON.stringify(editor.templates) %>,
|
||||
"user": {
|
||||
"group": "<%- editor.userGroup %>",
|
||||
"id": "<%- editor.userid %>",
|
||||
"name": "<%- editor.name %>"
|
||||
},
|
||||
"embedded": {
|
||||
"saveUrl": "<%- file.uriUser %>",
|
||||
"embedUrl": "<%- file.uriUser %>",
|
||||
"shareUrl": "<%- file.uriUser %>",
|
||||
"toolbarDocked": "top"
|
||||
},
|
||||
"customization": {
|
||||
"about": true,
|
||||
"chat": true,
|
||||
"comments": true,
|
||||
"feedback": true,
|
||||
"forcesave": false,
|
||||
@ -57,6 +42,24 @@
|
||||
},
|
||||
"submitForm": <%- editor.submitForm %>
|
||||
},
|
||||
"embedded": {
|
||||
"embedUrl": "<%- file.uriUser %>",
|
||||
"saveUrl": "<%- file.uriUser %>",
|
||||
"shareUrl": "<%- file.uriUser %>",
|
||||
"toolbarDocked": "top"
|
||||
},
|
||||
"fileChoiceUrl": "<%- editor.fileChoiceUrl %>",
|
||||
"plugins": <%- editor.plugins %>
|
||||
}
|
||||
"lang": "<%- editor.lang %>",
|
||||
"mode": "<%- editor.mode %>",
|
||||
"plugins": <%- editor.plugins %>,
|
||||
"templates": <%- JSON.stringify(editor.templates) %>,
|
||||
"user": {
|
||||
"group": "<%- editor.userGroup %>",
|
||||
"id": "<%- editor.userid %>",
|
||||
"name": "<%- editor.name %>"
|
||||
}
|
||||
},
|
||||
"height": "100%",
|
||||
"token": "<%- editor.token %>",
|
||||
"type": "<%- editor.type %>",
|
||||
"width": "100%"
|
||||
|
||||
@ -38,6 +38,7 @@
|
||||
<script type="text/javascript" language="javascript">
|
||||
|
||||
var docEditor;
|
||||
var config;
|
||||
|
||||
var innerAlert = function (message, inEditor) {
|
||||
if (console && console.log)
|
||||
@ -56,10 +57,14 @@
|
||||
};
|
||||
|
||||
var onMetaChange = function (event) { // the meta information of the document is changed via the meta command
|
||||
var favorite = !!event.data.favorite;
|
||||
var title = document.title.replace(/^\☆/g, "");
|
||||
document.title = (favorite ? "☆" : "") + title;
|
||||
docEditor.setFavorite(favorite); // change the Favorite icon state
|
||||
if (event.data.favorite) {
|
||||
var favorite = !!event.data.favorite;
|
||||
var title = document.title.replace(/^\☆/g, "");
|
||||
document.title = (favorite ? "☆" : "") + title;
|
||||
docEditor.setFavorite(favorite); // change the Favorite icon state
|
||||
}
|
||||
|
||||
innerAlert("onMetaChange: " + JSON.stringify(event.data));
|
||||
};
|
||||
|
||||
var onRequestEditRights = function () { // the user is trying to switch the document from the viewing into the editing mode
|
||||
@ -141,11 +146,25 @@
|
||||
};
|
||||
|
||||
var onRequestSendNotify = function(event) { // the user is mentioned in a comment
|
||||
event.data.actionLink = replaceActionLink(location.href, event.data.actionLink);
|
||||
event.data.actionLink = replaceActionLink(location.href, JSON.stringify(event.data.actionLink));
|
||||
var data = JSON.stringify(event.data);
|
||||
innerAlert("onRequestSendNotify: " + data);
|
||||
};
|
||||
|
||||
var onRequestReferenceData = function(event) { // user refresh external data source
|
||||
innerAlert("onRequestReferenceData");
|
||||
innerAlert(event.data);
|
||||
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", "reference");
|
||||
xhr.setRequestHeader("Content-Type", "application/json");
|
||||
xhr.send(JSON.stringify(event.data));
|
||||
xhr.onload = function () {
|
||||
innerAlert(xhr.responseText);
|
||||
docEditor.setReferenceData(JSON.parse(xhr.responseText));
|
||||
}
|
||||
};
|
||||
|
||||
var onRequestSaveAs = function (event) { // the user is trying to save file by clicking Save Copy as... button
|
||||
var title = event.data.title;
|
||||
var url = event.data.url;
|
||||
@ -155,7 +174,7 @@
|
||||
}
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", "create");
|
||||
xhr.setRequestHeader( 'Content-Type', 'application/json');
|
||||
xhr.setRequestHeader('Content-Type', 'application/json');
|
||||
xhr.send(JSON.stringify(data));
|
||||
xhr.onload = function () {
|
||||
innerAlert(xhr.responseText);
|
||||
@ -163,27 +182,48 @@
|
||||
}
|
||||
}
|
||||
|
||||
var config = {<%- include("config") %>,
|
||||
events: {
|
||||
"onAppReady": onAppReady,
|
||||
"onDocumentStateChange": onDocumentStateChange,
|
||||
"onRequestEditRights": onRequestEditRights,
|
||||
"onError": onError,
|
||||
"onRequestHistory": onRequestHistory,
|
||||
"onRequestHistoryData": onRequestHistoryData,
|
||||
"onRequestHistoryClose": onRequestHistoryClose,
|
||||
"onOutdatedVersion": onOutdatedVersion,
|
||||
"onMakeActionLink": onMakeActionLink,
|
||||
"onMetaChange": onMetaChange,
|
||||
"onRequestInsertImage": onRequestInsertImage,
|
||||
"onRequestCompareFile": onRequestCompareFile,
|
||||
"onRequestMailMergeRecipients": onRequestMailMergeRecipients,
|
||||
}
|
||||
};
|
||||
var onRequestRename = function(event) { // the user is trying to rename file by clicking Rename... button
|
||||
innerAlert("onRequestRename: " + JSON.stringify(event.data));
|
||||
|
||||
if (<%- JSON.stringify(usersForMentions) %> != null) {
|
||||
var newfilename = event.data;
|
||||
var data = {
|
||||
newfilename: newfilename,
|
||||
dockey: config.document.key,
|
||||
ext: config.document.fileType
|
||||
};
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", "rename");
|
||||
xhr.setRequestHeader('Content-Type', 'application/json');
|
||||
xhr.send(JSON.stringify(data));
|
||||
xhr.onload = function () {
|
||||
innerAlert(xhr.responseText);
|
||||
}
|
||||
};
|
||||
|
||||
config = {
|
||||
<%- include("config") %>
|
||||
};
|
||||
config.events = {
|
||||
"onAppReady": onAppReady,
|
||||
"onDocumentStateChange": onDocumentStateChange,
|
||||
"onRequestEditRights": onRequestEditRights,
|
||||
"onError": onError,
|
||||
"onOutdatedVersion": onOutdatedVersion,
|
||||
"onMakeActionLink": onMakeActionLink,
|
||||
"onMetaChange": onMetaChange,
|
||||
"onRequestInsertImage": onRequestInsertImage,
|
||||
"onRequestCompareFile": onRequestCompareFile,
|
||||
"onRequestMailMergeRecipients": onRequestMailMergeRecipients,
|
||||
};
|
||||
|
||||
if (<%- JSON.stringify(editor.userid) %> != null) {
|
||||
config.events.onRequestHistory = onRequestHistory;
|
||||
config.events.onRequestHistoryData = onRequestHistoryData;
|
||||
config.events.onRequestHistoryClose = onRequestHistoryClose;
|
||||
config.events.onRequestRename = onRequestRename;
|
||||
config.events.onRequestUsers = onRequestUsers;
|
||||
config.events.onRequestSendNotify = onRequestSendNotify;
|
||||
config.events.onRequestReferenceData = onRequestReferenceData;
|
||||
}
|
||||
|
||||
if (config.editorConfig.createUrl) {
|
||||
|
||||
49
web/documentserver-example/nodejs/views/index.ejs
Normal file → Executable file
49
web/documentserver-example/nodejs/views/index.ejs
Normal file → Executable file
@ -60,7 +60,7 @@
|
||||
<a class="try-editor form reload-page" target="_blank" href="editor?fileExt=docxf<%= params %>" title="Create new form template">Form template</a>
|
||||
</li>
|
||||
</ul>
|
||||
<label class="create-sample">
|
||||
<label class="side-option">
|
||||
<input id="createSample" type="checkbox" class="checkbox" />With sample content
|
||||
</label>
|
||||
</div>
|
||||
@ -76,7 +76,7 @@
|
||||
<tr>
|
||||
<td valign="middle">
|
||||
<span class="select-user">Username</span>
|
||||
<img class="info" src="images/info.svg" />
|
||||
<img id="info" class="info" src="images/info.svg" />
|
||||
<select class="select-user" id="user">
|
||||
<% users.forEach(user => { %>
|
||||
<option value="<%= user.id %>"><%= user.name == null ? "Anonymous" : user.name %></option>
|
||||
@ -86,42 +86,23 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="middle">
|
||||
<span class="select-user">Language editors interface</span>
|
||||
<span class="select-user">Language</span>
|
||||
<img class="info info-tooltip" data-id="language" data-tooltip="Choose the language for ONLYOFFICE editors interface" src="images/info.svg" />
|
||||
<select class="select-user" id="language">
|
||||
<option value="en">English</option>
|
||||
<option value="be">Belarusian</option>
|
||||
<option value="bg">Bulgarian</option>
|
||||
<option value="ca">Catalan</option>
|
||||
<option value="zh">Chinese</option>
|
||||
<option value="cs">Czech</option>
|
||||
<option value="da">Danish</option>
|
||||
<option value="nl">Dutch</option>
|
||||
<option value="fi">Finnish</option>
|
||||
<option value="fr">French</option>
|
||||
<option value="de">German</option>
|
||||
<option value="el">Greek</option>
|
||||
<option value="hu">Hungarian</option>
|
||||
<option value="id">Indonesian</option>
|
||||
<option value="it">Italian</option>
|
||||
<option value="ja">Japanese</option>
|
||||
<option value="ko">Korean</option>
|
||||
<option value="lv">Latvian</option>
|
||||
<option value="lo">Lao</option>
|
||||
<option value="nb">Norwegian</option>
|
||||
<option value="pl">Polish</option>
|
||||
<option value="pt">Portuguese</option>
|
||||
<option value="ro">Romanian</option>
|
||||
<option value="ru">Russian</option>
|
||||
<option value="sk">Slovak</option>
|
||||
<option value="sl">Slovenian</option>
|
||||
<option value="sv">Swedish</option>
|
||||
<option value="es">Spanish</option>
|
||||
<option value="tr">Turkish</option>
|
||||
<option value="uk">Ukrainian</option>
|
||||
<option value="vi">Vietnamese</option>
|
||||
<% Object.keys(languages).forEach(key => { %>
|
||||
<option value="<%= key %>"><%= languages[key] %></option>
|
||||
<% }) %>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="middle">
|
||||
<label class="side-option">
|
||||
<input id="directUrl" type="checkbox" class="checkbox" />Try opening on client
|
||||
<img id="directUrlInfo" class="info info-tooltip" data-id="directUrlInfo" data-tooltip="Some files can be opened in the user's browser without connecting to the document server." src="images/info.svg" />
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user