Skip to content

Commit

Permalink
Merge pull request #277 from ONLYOFFICE/develop
Browse files Browse the repository at this point in the history
Release/1.2.0
  • Loading branch information
LinneyS authored Apr 18, 2022
2 parents 461a005 + 7a70a44 commit 5cc6b4c
Show file tree
Hide file tree
Showing 150 changed files with 3,612 additions and 1,515 deletions.
18 changes: 14 additions & 4 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
## Integration examples

Test examples are simple document management systems that can be built into your
application for testing (please, do not use it for production without proper code
modifications).
Test examples are simple document management systems that can be built into your application for testing.
Do NOT use these integration examples on your own server without proper code modifications!
In case you enabled any of the test examples, disable it before going for production.

These examples show the way to integrate [ONLYOFFICE Docs][2] into your own website or application using one of the programming languages. The package contains examples written in .Net (C# MVC), .Net (C#), Java, Node.js, PHP and Ruby.
These examples show the way to integrate [ONLYOFFICE Docs][2] into your own website or application using one of the programming languages.
The package contains examples written in .Net (C# MVC), .Net (C#), Java, Node.js, PHP and Ruby.

You should change `http://documentserver` to your server address in these files:
* [.Net (C# MVC)](https://github.com/ONLYOFFICE/document-server-integration/tree/master/web/documentserver-example/csharp-mvc) - `web/documentserver-example/csharp-mvc/web.appsettings.config`
Expand Down Expand Up @@ -66,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)
Expand Down
67 changes: 63 additions & 4 deletions web/documentserver-example/csharp-mvc/Content/media.css
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,6 @@
}

@media (max-width: 1008px) {
#portal-info {
width: 65vw;
}

.left-panel {
margin-left: 0;
}
Expand Down Expand Up @@ -128,6 +124,10 @@
height: 80px;
}

.main {
height: calc(100% - 128px);
}

.main-panel {
left: 0;
padding: 48px 18px 24px;
Expand Down Expand Up @@ -312,6 +312,9 @@
.tableRow td:first-child {
max-width: 17%;
}
#portal-info {
max-width: 60vw;
}
}

.downloadContentCellShift:after {
Expand Down Expand Up @@ -363,6 +366,10 @@
height: 80px;
}

.main {
height: calc(100% - 128px);
}

.copy {
width: 100%;
text-align: center;
Expand Down Expand Up @@ -436,6 +443,58 @@
display: none;
width: 1%;
}
/* Mobile Upload*/
.blockUI.blockMsg.blockPage.ui-dialog.ui-widget.ui-corner-all.ui-widget-content.ui-draggable {
width: 344px !important;
box-shadow: 0px 7px 15px rgba(85, 85, 85, 0.1);
border-radius: 2px;
top: 10% !important;
margin-left: -172px !important;
}

.ui-dialog .ui-dialog-titlebar {
padding: 0;
}
.ui-dialog .ui-dialog-content {
padding: 0 !important;
}
#mainProgress {
margin: 24px 16px 0 !important;
}
.blockTitle {
padding: 10px 10px 6px 16px !important;
font-size: 14px !important;
}
#mainProgress .describeUpload {
padding: 8px 0 !important;
}
.dialog-close {
margin: 0 !important;
}
.step-descr{
line-height: 150%;
}
.step {
line-height: 160%;
}
.buttonsMobile{
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-between;
align-items: center;
}
.button.gray{
margin: 0;
}
.button, .button:hover{
display: flex;
justify-content: center;
padding: 0 !important;
width: 144px;
height: 56px;
margin-bottom: 24px !important;
}
}

@media (max-width: 560px) and (min-width: 510px) {
Expand Down
11 changes: 7 additions & 4 deletions web/documentserver-example/csharp-mvc/Content/stylesheet.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
}

body {
display: block;
background: #FFFFFF;
color: #333333;
font-family: Open Sans;
Expand Down Expand Up @@ -71,6 +72,7 @@ header img {
}

.main {
display: table;
height: calc(100% - 112px);
min-height: 536px;
}
Expand All @@ -97,6 +99,10 @@ header img {
width: 896px;
}

#portal-info {
max-width: 65vw;
}

.portal-name {
color: #FF6F3D;
font-size: 24px;
Expand Down Expand Up @@ -728,12 +734,9 @@ html {
width: 30vw;
min-width: 200px;
max-width: 400px;
margin-top: 20px;
}

.user-descr > b {
margin-left: 25px;
}

.portal-descr:nth-child(3) {
margin-bottom: 20px;
}
79 changes: 73 additions & 6 deletions web/documentserver-example/csharp-mvc/Helpers/DocManagerHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using System.Web.Configuration;
using System.Web.Script.Serialization;
using OnlineEditorsExampleMVC.Models;
using System.Net;

namespace OnlineEditorsExampleMVC.Helpers
{
Expand Down Expand Up @@ -79,19 +80,37 @@ public static string CurUserHostAddress(string userAddress = null)
// get the storage path of the file
public static string StoragePath(string fileName, string userAddress = null)
{
var directory = HttpRuntime.AppDomainAppPath + CurUserHostAddress(userAddress) + "\\";
var directory = "";
if (!string.IsNullOrEmpty(WebConfigurationManager.AppSettings["storage-path"]) && Path.IsPathRooted(WebConfigurationManager.AppSettings["storage-path"]))
{
directory = WebConfigurationManager.AppSettings["storage-path"] + "\\";
}
else
{
directory = HttpRuntime.AppDomainAppPath + WebConfigurationManager.AppSettings["storage-path"] + CurUserHostAddress(userAddress) + "\\";
}

if (!Directory.Exists(directory))
{
Directory.CreateDirectory(directory);
}
return directory + Path.GetFileName(fileName);
return directory + (fileName.Contains("\\") ? fileName : Path.GetFileName(fileName));
}

// get the path to the forcesaved file version
public static string ForcesavePath(string fileName, string userAddress, Boolean create)
{
// create the directory to this file version
var directory = HttpRuntime.AppDomainAppPath + CurUserHostAddress(userAddress) + "\\";
var directory = "";
if (!string.IsNullOrEmpty(WebConfigurationManager.AppSettings["storage-path"]) && Path.IsPathRooted(WebConfigurationManager.AppSettings["storage-path"]))
{
directory = WebConfigurationManager.AppSettings["storage-path"] + "\\";
}
else
{
directory = HttpRuntime.AppDomainAppPath + WebConfigurationManager.AppSettings["storage-path"] + CurUserHostAddress(userAddress) + "\\";
}

if (!Directory.Exists(directory))
{
return "";
Expand Down Expand Up @@ -172,7 +191,16 @@ public static string GetCorrectName(string fileName, string userAddress = null)
// get all the stored files from the user host address
public static List<FileInfo> GetStoredFiles()
{
var directory = HttpRuntime.AppDomainAppPath + WebConfigurationManager.AppSettings["storage-path"] + CurUserHostAddress(null) + "\\";
var directory = "";
if (!string.IsNullOrEmpty(WebConfigurationManager.AppSettings["storage-path"]) && Path.IsPathRooted(WebConfigurationManager.AppSettings["storage-path"]))
{
directory = WebConfigurationManager.AppSettings["storage-path"] + "\\";
}
else
{
directory = HttpRuntime.AppDomainAppPath + WebConfigurationManager.AppSettings["storage-path"] + CurUserHostAddress(null) + "\\";
}

if (!Directory.Exists(directory)) return new List<FileInfo>();

var directoryInfo = new DirectoryInfo(directory);
Expand Down Expand Up @@ -228,8 +256,7 @@ public static string GetPathUri(string path)
{
var uri = new UriBuilder(GetServerUrl(true))
{
Path = HttpRuntime.AppDomainAppVirtualPath + "/"
+ path,
Path = HttpRuntime.AppDomainAppVirtualPath + "/" + path,
Query = ""
};

Expand Down Expand Up @@ -284,6 +311,24 @@ public static string GetCreateUrl(FileUtility.FileType fileType)
return createUrl.ToString();
}

// create the public history url
public static string GetHistoryDownloadUrl(string filename, string version, string file)
{
var downloadUrl = new UriBuilder(GetServerUrl(true))
{
Path =
HttpRuntime.AppDomainAppVirtualPath
+ (HttpRuntime.AppDomainAppVirtualPath.EndsWith("/") ? "" : "/")
+ "webeditor.ashx",
Query = "type=downloadhistory"
+ "&fileName=" + HttpUtility.UrlEncode(filename)
+ "&userAddress=" + HttpUtility.UrlEncode(HttpContext.Current.Request.UserHostAddress)
+ "&ver=" + version
+ "&file="+ file
};
return downloadUrl.ToString();
}

// get url to download a file
public static string GetDownloadUrl(string fileName)
{
Expand Down Expand Up @@ -372,5 +417,27 @@ public static List<Dictionary<string, object>> GetFilesInfo(string fileId = null

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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ public static int GetConvertedUri(string documentUri,
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
Expand Down
29 changes: 25 additions & 4 deletions web/documentserver-example/csharp-mvc/Helpers/TrackManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ public static Dictionary<string, object> readBody(HttpContext context)

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
{
Expand All @@ -95,7 +97,11 @@ public static int processSave(Dictionary<string, object> fileData, string fileNa
}
var downloadUri = (string)fileData["url"];
string curExt = Path.GetExtension(fileName).ToLower(); // get current file extension
string downloadExt = Path.GetExtension(downloadUri).ToLower() ?? ""; // get the extension of the downloaded file

var downloadExt = fileData.ContainsKey("filetype")
? "." + (string)fileData["filetype"]
: Path.GetExtension(downloadUri).ToLower() ?? ""; // TODO: Delete in version 7.0 or higher. Support for versions below 7.0

var newFileName = fileName;

// convert downloaded file to the file with the current extension if these extensions aren't equal
Expand All @@ -122,6 +128,8 @@ public static int processSave(Dictionary<string, object> fileData, string fileNa
}
}

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);
Expand Down Expand Up @@ -167,7 +175,11 @@ public static int processForceSave(Dictionary<string, object> fileData, string f
var downloadUri = (string)fileData["url"];

string curExt = Path.GetExtension(fileName).ToLower(); // get current file extension
string downloadExt = Path.GetExtension(downloadUri).ToLower(); // get the extension of the downloaded file

var downloadExt = fileData.ContainsKey("filetype")
? "." + (string)fileData["filetype"]
: Path.GetExtension(downloadUri).ToLower(); // TODO: Delete in version 7.0 or higher. Support for versions below 7.0

Boolean newFileName = false;

// convert downloaded file to the file with the current extension if these extensions aren't equal
Expand All @@ -193,6 +205,8 @@ public static int processForceSave(Dictionary<string, object> fileData, string f
}
}

DocManagerHelper.VerifySSL();

string forcesavePath = "";
Boolean isSubmitForm = fileData["forcesavetype"].ToString().Equals("3"); // SubmitForm

Expand Down Expand Up @@ -235,8 +249,10 @@ public static int processForceSave(Dictionary<string, object> fileData, string f
}

// 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);
Expand All @@ -248,6 +264,11 @@ public static void commandRequest(string method, string key)
{ "key", key }
};

if (meta != null)
{
body.Add("meta", meta);
}

// check if a secret key to generate token exists or not
if (JwtManager.Enabled)
{
Expand Down
Loading

0 comments on commit 5cc6b4c

Please sign in to comment.