Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/release/v8.0.0' into dev…
Browse files Browse the repository at this point in the history
…elop

# Conflicts:
#	Common/sources/storage-fs.js
#	DocService/package.json
#	DocService/sources/DocsCoServer.js
#	DocService/sources/databaseConnectors/connectorUtilities.js
#	DocService/sources/databaseConnectors/postgreConnector.js
#	DocService/sources/gc.js
#	DocService/sources/mySqlBaseConnector.js
#	DocService/sources/wopiClient.js
  • Loading branch information
konovalovsergey committed Feb 5, 2024
2 parents 0d5b109 + 0521e77 commit b6b1132
Show file tree
Hide file tree
Showing 14 changed files with 181 additions and 53 deletions.
6 changes: 5 additions & 1 deletion Common/config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@
"modulusOld": "qnro3nUUjvZK1i7UqeOlXmCrVPiDtHlRgIPReAjt2nKL1GG3SBXO6N0aPbiM5rtK0XRPUoLmKu2rYvSJ/Kmkdp14a/3uiEl788VVn0hb/l9OuQtH3HBjmM0/LKRgJQuU3LgHI67uRVZYtSJ/n9fYdZqnLfveLsrgZpgRCoabrp+H5Uem9N+x0OJR3LpToVRZhzSkYQrxnERJmF3bhR5yF8Zn+3BoSiUpVOCAvJRAYl8cAIs3BwQcTEyXJjnt+wW5Q1VyKr+bXp/39+tnugQeTe1jjdPy6rOTftQwzjro81oZpOMazwwR1aeQuQWCrmHQZqyV3Rvo6X3xYlOQnlo1/w==",
"exponentOld": "AQAB",
"privateKeyOld": "MIIEowIBAAKCAQEAqnro3nUUjvZK1i7UqeOlXmCrVPiDtHlRgIPReAjt2nKL1GG3SBXO6N0aPbiM5rtK0XRPUoLmKu2rYvSJ/Kmkdp14a/3uiEl788VVn0hb/l9OuQtH3HBjmM0/LKRgJQuU3LgHI67uRVZYtSJ/n9fYdZqnLfveLsrgZpgRCoabrp+H5Uem9N+x0OJR3LpToVRZhzSkYQrxnERJmF3bhR5yF8Zn+3BoSiUpVOCAvJRAYl8cAIs3BwQcTEyXJjnt+wW5Q1VyKr+b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ezj0c6HAn8nlDRUzRVBEDXWMdV6kCcGpCccTIrqHzpqTY0vV0UkOTQFnDQKBgAxSEhm/gtCYJIMCBe+KBJT9uECV5xDQopTTjsGOkd4306EN2dyPOIlAfwM6K/0qWisa0Ei5i8TbRRuBeTTdLEYLqXCJ7fj5tdD1begBdSVtHQ2WHqzPJSuImTkFi9NXxd1XUyZFM3y6YQvlssSuL7QSxUIEtZHnrJTt3QDd10dj",
"refreshLockInterval": "10m"
"refreshLockInterval": "10m",
"dummy" : {
"enable": true,
"sampleFilePath": ""
}
},
"tenants": {
"baseDir": "",
Expand Down
4 changes: 2 additions & 2 deletions Common/sources/storage-s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ let configS3 = {
};

if (configS3.endpoint) {
configS3.sslEnabled = cfgSslEnabled;
configS3.s3ForcePathStyle = cfgS3ForcePathStyle;
configS3.tls = cfgSslEnabled;
configS3.forcePathStyle = cfgS3ForcePathStyle;
}
const client = new S3Client(configS3);

Expand Down
6 changes: 3 additions & 3 deletions DocService/npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion DocService/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"multi-integer-range": "4.0.7",
"multiparty": "4.2.1",
"mysql2": "2.3.3",
"oracledb": "6.0.1",
"oracledb": "6.3.0",
"pg": "8.11.3",
"redis": "4.6.11",
"retry": "0.12.0",
Expand Down
3 changes: 2 additions & 1 deletion DocService/sources/DocsCoServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1396,7 +1396,7 @@ function getRequestParams(ctx, req, opt_isNotInBody) {
const tenTokenEnableRequestInbox = ctx.getCfg('services.CoAuthoring.token.enable.request.inbox', cfgTokenEnableRequestInbox);
const tenTokenRequiredParams = ctx.getCfg('services.CoAuthoring.server.tokenRequiredParams', cfgTokenRequiredParams);

let res = {code: constants.NO_ERROR, isDecoded: false, params: undefined};
let res = {code: constants.NO_ERROR, description: "", isDecoded: false, params: undefined};
if (req.body && Buffer.isBuffer(req.body) && req.body.length > 0 && !opt_isNotInBody) {
res.params = JSON.parse(req.body.toString('utf8'));
} else {
Expand Down Expand Up @@ -1427,6 +1427,7 @@ function getRequestParams(ctx, req, opt_isNotInBody) {
} else if (constants.JWT_EXPIRED_CODE == checkJwtRes.code) {
res.code = constants.VKEY_KEY_EXPIRE;
}
res.description = checkJwtRes.description;
}
}
return res;
Expand Down
62 changes: 35 additions & 27 deletions DocService/sources/canvasservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ var getOutputData = co.wrap(function* (ctx, cmd, outputData, key, optConn, optAd
}
break;
case commonDefines.FileStatus.None:
outputData.setStatus('none');
//this status has no handler
break;
case commonDefines.FileStatus.WaitQueue:
//task in the queue. response will be after convertion
Expand All @@ -302,6 +302,7 @@ var getOutputData = co.wrap(function* (ctx, cmd, outputData, key, optConn, optAd
outputData.setData(constants.UNKNOWN);
break;
}
return status;
});
function* addRandomKeyTaskCmd(ctx, cmd) {
var task = yield* taskResult.addRandomKeyTask(ctx, cmd.getDocId());
Expand Down Expand Up @@ -517,8 +518,8 @@ function* commandOpen(ctx, conn, cmd, outputData, opt_upsertRes, opt_bIsRestore)
}
}
function* commandOpenFillOutput(ctx, conn, cmd, outputData, opt_bIsRestore) {
yield getOutputData(ctx, cmd, outputData, cmd.getDocId(), conn, undefined, opt_bIsRestore);
return 'none' === outputData.getStatus();
let status = yield getOutputData(ctx, cmd, outputData, cmd.getDocId(), conn, undefined, opt_bIsRestore);
return commonDefines.FileStatus.None === status;
}
function* commandReopen(ctx, conn, cmd, outputData) {
const tenOpenProtectedFile = ctx.getCfg('services.CoAuthoring.server.openProtectedFile', cfgOpenProtectedFile);
Expand Down Expand Up @@ -1336,7 +1337,7 @@ exports.openDocument = function(ctx, conn, cmd, opt_upsertRes, opt_bIsRestore) {
outputData.setData(constants.UNKNOWN);
}
finally {
if (outputData && outputData.getStatus()) {
if (outputData?.getStatus()) {
ctx.logger.debug('Response command: %s', JSON.stringify(outputData));
docsCoServer.sendData(ctx, conn, new OutputDataWrap('documentOpen', outputData));
}
Expand Down Expand Up @@ -1583,8 +1584,12 @@ exports.downloadFile = function(req, res) {
}
ctx.initFromRequest(req);
yield ctx.initTenantCache();
let url = decodeURI(req.get('x-url'));
ctx.setDocId(req.params.docid);
//todo remove in 8.1. For compatibility
let url = req.get('x-url');
if (url) {
url = decodeURI(url);
}
ctx.logger.info('Start downloadFile');
const tenTokenEnableBrowser = ctx.getCfg('services.CoAuthoring.token.enable.browser', cfgTokenEnableBrowser);
const tenDownloadMaxBytes = ctx.getCfg('FileConverter.converter.maxDownloadBytes', cfgDownloadMaxBytes);
Expand All @@ -1593,32 +1598,35 @@ exports.downloadFile = function(req, res) {
const tenAllowPrivateIPAddressForSignedRequests = ctx.getCfg('services.CoAuthoring.server.allowPrivateIPAddressForSignedRequests', cfgAllowPrivateIPAddressForSignedRequests);

let authorization;
if (tenTokenEnableBrowser) {
let checkJwtRes = yield docsCoServer.checkJwtHeader(ctx, req, 'Authorization', 'Bearer ', commonDefines.c_oAscSecretType.Browser);
let errorDescription;
if (checkJwtRes.decoded) {
let decoded = checkJwtRes.decoded;
if (decoded.changesUrl) {
url = decoded.changesUrl;
} else if (decoded.document && -1 !== tenDownloadFileAllowExt.indexOf(decoded.document.fileType)) {
url = decoded.document.url;
} else if (decoded.url && -1 !== tenDownloadFileAllowExt.indexOf(decoded.fileType)) {
let errorDescription;
let authRes = yield docsCoServer.getRequestParams(ctx, req);
if (authRes.code === constants.NO_ERROR) {
let decoded = authRes.params;
if (decoded.changesUrl) {
url = decoded.changesUrl;
} else if (decoded.document && -1 !== tenDownloadFileAllowExt.indexOf(decoded.document.fileType)) {
url = decoded.document.url;
} else if (decoded.url && -1 !== tenDownloadFileAllowExt.indexOf(decoded.fileType)) {
url = decoded.url;
} else if (!tenTokenEnableBrowser) {
//todo token required
if (decoded.url) {
url = decoded.url;
} else {
errorDescription = 'access deny';
}
} else {
errorDescription = checkJwtRes.description;
}
if (errorDescription) {
ctx.logger.warn('Error downloadFile jwt: description = %s', errorDescription);
res.sendStatus(403);
return;
}
if (utils.canIncludeOutboxAuthorization(ctx, url)) {
let secret = yield tenantManager.getTenantSecret(ctx, commonDefines.c_oAscSecretType.Outbox);
authorization = utils.fillJwtForRequest(ctx, {url: url}, secret, false);
errorDescription = 'access deny';
}
} else {
errorDescription = authRes.description || 'need token';
}
if (errorDescription) {
ctx.logger.warn('Error downloadFile jwt: description = %s', errorDescription);
res.sendStatus(403);
return;
}
if (utils.canIncludeOutboxAuthorization(ctx, url)) {
let secret = yield tenantManager.getTenantSecret(ctx, commonDefines.c_oAscSecretType.Outbox);
authorization = utils.fillJwtForRequest(ctx, {url: url}, secret, false);
}
let urlParsed = urlModule.parse(url);
let filterStatus = yield* utils.checkHostFilter(ctx, urlParsed.hostname);
Expand Down
17 changes: 12 additions & 5 deletions DocService/sources/converterservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ function convertRequest(req, res, isJson) {
cmd.setFormat(filetype);
cmd.setDocId(docId);
cmd.setOutputFormat(outputFormat);
let outputExt = formatChecker.getStringFromFormat(cmd.getOutputFormat());

cmd.setCodepage(commonDefines.c_oAscEncodingsMap[params.codePage] || commonDefines.c_oAscCodePageUtf8);
cmd.setDelimiter(parseIntParam(params.delimiter) || commonDefines.c_oAscCsvDelimiter.Comma);
Expand All @@ -283,11 +284,18 @@ function convertRequest(req, res, isJson) {
if (params.region && locale[params.region.toLowerCase()]) {
cmd.setLCID(locale[params.region.toLowerCase()].id);
}
let jsonParams = {};
if (params.documentLayout) {
cmd.setJsonParams(JSON.stringify({'documentLayout': params.documentLayout}));
jsonParams['documentLayout'] = params.documentLayout;
}
if (params.spreadsheetLayout) {
cmd.setJsonParams(JSON.stringify({'spreadsheetLayout': params.spreadsheetLayout}));
jsonParams['spreadsheetLayout'] = params.spreadsheetLayout;
}
if (params.watermark) {
jsonParams['watermark'] = params.watermark;
}
if (Object.keys(jsonParams).length > 0) {
cmd.setJsonParams(JSON.stringify(jsonParams));
}
if (params.password) {
if (params.password.length > constants.PASSWORD_MAX_LENGTH) {
Expand Down Expand Up @@ -323,8 +331,8 @@ function convertRequest(req, res, isJson) {
break;
}
cmd.setThumbnail(thumbnailData);
if (false == thumbnailData.getFirst()) {
cmd.setOutputFormat(constants.AVS_OFFICESTUDIO_FILE_IMAGE);
if (false === thumbnailData.getFirst() && 0 !== (constants.AVS_OFFICESTUDIO_FILE_IMAGE & cmd.getOutputFormat())) {
outputExt = 'zip';
}
}
var documentRenderer = params.documentRenderer;
Expand All @@ -350,7 +358,6 @@ function convertRequest(req, res, isJson) {
}
cmd.setTextParams(textParamsData);
}
let outputExt = formatChecker.getStringFromFormat(cmd.getOutputFormat());
if (params.title) {
cmd.setTitle(path.basename(params.title, path.extname(params.title)) + '.' + outputExt);
}
Expand Down
2 changes: 1 addition & 1 deletion DocService/sources/databaseConnectors/mssqlConnector.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const connectionConfiguration = {
user: configSql.get('dbUser'),
password: configSql.get('dbPass'),
server: configSql.get('dbHost'),
port: configSql.get('dbPort'),
port: parseInt(configSql.get('dbPort')),
database: configSql.get('dbName'),
pool: {
max: configSql.get('connectionlimit'),
Expand Down
2 changes: 1 addition & 1 deletion DocService/sources/databaseConnectors/mysqlConnector.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const cfgTableResult = config.get('services.CoAuthoring.sql.tableResult');

const pool = mysql.createPool({
host : configSql.get('dbHost'),
port : configSql.get('dbPort'),
port : parseInt(configSql.get('dbPort')),
user : configSql.get('dbUser'),
password : configSql.get('dbPass'),
database : configSql.get('dbName'),
Expand Down
11 changes: 10 additions & 1 deletion DocService/sources/databaseConnectors/oracleConnector.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,16 @@ async function executeQuery(ctx, sqlCommand, values = [], noModifyRes = false, n

throw error;
} finally {
connection?.close();
if (connection) {
try {
// Put the connection back in the pool
await connection.close();
} catch (error) {
if (!noLog) {
ctx.logger.error(`connection.close() error while executing query: ${sqlCommand}\n${error.stack}`);
}
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion DocService/sources/databaseConnectors/postgreConnector.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const cfgEditor = config.get('services.CoAuthoring.editor');

let connectionConfig = {
host: configSql.get('dbHost'),
port: configSql.get('dbPort'),
port: parseInt(configSql.get('dbPort')),
user: configSql.get('dbUser'),
password: configSql.get('dbPass'),
database: configSql.get('dbName'),
Expand Down
26 changes: 25 additions & 1 deletion DocService/sources/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const tenantManager = require('./../../Common/sources/tenantManager');
const configStorage = config.get('storage');

const cfgWopiEnable = config.get('wopi.enable');
const cfgWopiDummyEnable = config.get('wopi.dummy.enable');
const cfgHtmlTemplate = config.get('wopi.htmlTemplate');
const cfgTokenEnableBrowser = config.get('services.CoAuthoring.token.enable.browser');
const cfgTokenEnableRequestInbox = config.get('services.CoAuthoring.token.enable.request.inbox');
Expand Down Expand Up @@ -249,6 +250,7 @@ docsCoServer.install(server, () => {
app.post('/savefile/:docid', rawFileParser, canvasService.saveFile);
app.get('/printfile/:docid/:filename', canvasService.printFile);
app.get('/downloadfile/:docid', canvasService.downloadFile);
app.post('/downloadfile/:docid', rawFileParser, canvasService.downloadFile);
app.get('/healthcheck', utils.checkClientIp, docsCoServer.healthCheck);

app.get('/baseurl', (req, res) => {
Expand Down Expand Up @@ -292,6 +294,24 @@ docsCoServer.install(server, () => {
res.sendStatus(404);
});
}
function checkWopiDummyEnable(req, res, next) {
//todo may be move code into wopiClient or wopiClient.discovery...
let ctx = new operationContext.Context();
ctx.initFromRequest(req);
ctx.initTenantCache()
.then(() => {
const tenWopiEnable = ctx.getCfg('wopi.enable', cfgWopiEnable);
const tenWopiDummyEnable = ctx.getCfg('wopi.dummy.enable', cfgWopiDummyEnable);
if (tenWopiEnable && tenWopiDummyEnable) {
next();
} else {
res.sendStatus(404);
}
}).catch((err) => {
ctx.logger.error('checkWopiDummyEnable error: %s', err.stack);
res.sendStatus(404);
});
}
//todo dest
let fileForms = multer({limits: {fieldSize: cfgDownloadMaxBytes}});
app.get('/hosting/discovery', checkWopiEnable, utils.checkClientIp, wopiClient.discovery);
Expand All @@ -301,8 +321,12 @@ docsCoServer.install(server, () => {
app.post('/hosting/wopi/:documentType/:mode', checkWopiEnable, urleEcodedParser, forms.none(), utils.lowercaseQueryString, wopiClient.getEditorHtml);
app.post('/hosting/wopi/convert-and-edit/:ext/:targetext', checkWopiEnable, urleEcodedParser, forms.none(), utils.lowercaseQueryString, wopiClient.getConverterHtml);
app.get('/hosting/wopi/convert-and-edit-handler', checkWopiEnable, utils.lowercaseQueryString, converterService.getConverterHtmlHandler);
app.get('/wopi/files/:docid', apicache.middleware("5 minutes"), checkWopiDummyEnable, utils.lowercaseQueryString, wopiClient.dummyCheckFileInfo);
app.post('/wopi/files/:docid', checkWopiDummyEnable, wopiClient.dummyOk);
app.get('/wopi/files/:docid/contents', apicache.middleware("5 minutes"), checkWopiDummyEnable, wopiClient.dummyGetFile);
app.post('/wopi/files/:docid/contents', checkWopiDummyEnable, wopiClient.dummyOk);

app.post('/dummyCallback', utils.checkClientIp, rawFileParser, function(req, res){
app.post('/dummyCallback', utils.checkClientIp, apicache.middleware("5 minutes"), rawFileParser, function(req, res){
let ctx = new operationContext.Context();
ctx.initFromRequest(req);
//yield ctx.initTenantCache();//no need
Expand Down
Loading

0 comments on commit b6b1132

Please sign in to comment.