diff --git a/SpellChecker/sources/server.js b/SpellChecker/sources/server.js index cbbaca923..756a45961 100644 --- a/SpellChecker/sources/server.js +++ b/SpellChecker/sources/server.js @@ -93,7 +93,7 @@ if (cluster.isMaster) { if (config.has('ssl')) { const privateKey = fs.readFileSync(config.get('ssl.key')).toString(); const certificateKey = fs.readFileSync(config.get('ssl.cert')).toString(); - //const trustedCertificate = fs.readFileSync(config.get('ssl.ca')).toString(); + //See detailed options format here: http://nodejs.org/api/tls.html#tls_tls_createserver_options_secureconnectionlistener const options = {key: privateKey, cert: certificateKey}; diff --git a/bin/common_util.py b/bin/common_util.py deleted file mode 100644 index 6df49b0a7..000000000 --- a/bin/common_util.py +++ /dev/null @@ -1,63 +0,0 @@ -import json -import os.path -import os -import sys - -def check_services_running(): - with open(processid_file_path, "r") as f: - data = json.load(f) - - if(data["docservice"] > 0 and check_pid(data["docservice"])): - sys.exit("Error : docservice running with pid (" + str(data["docservice"]) + ") ") - if(data["spellchecker"] > 0 and check_pid(data["spellchecker"])): - sys.exit("Error : spellchecker running with pid (" + str(data["spellchecker"]) + ") ") - if(data["converter"] > 0 and check_pid(data["converter"])): - sys.exit("Error : converter running with pid (" + str(data["converter"]) + ") ") - -def check_docservice_running(): - with open(processid_file_path, "r") as f: - data = json.load(f) - - if(data["docservice"] > 0 and check_pid(data["docservice"])): - sys.exit("Error : docservice running with pid (" + str(data["docservice"]) + ") ") - -def check_spellchecker_running(): - with open(processid_file_path, "r") as f: - data = json.load(f) - - if(data["spellchecker"] > 0 and check_pid(data["spellchecker"])): - sys.exit("Error : spellchecker running with pid (" + str(data["spellchecker"]) + ") ") - -def check_converter_running(): - with open(processid_file_path, "r") as f: - data = json.load(f) - - if(data["converter"] > 0 and check_pid(data["converter"])): - sys.exit("Error : converter running with pid (" + str(data["converter"]) + ") ") - -def check_pid(pid): - try: - os.kill(pid, 0) - except OSError: - return False - else: - return True - -def update_processid(docservice_process_id, spellchecker_process_id, converter_process_id): - with open(processid_file_path, "r") as f: - data = json.load(f) - - if(docservice_process_id > 0): - data["docservice"] = docservice_process_id - if(spellchecker_process_id > 0): - data["spellchecker"] = spellchecker_process_id - if(converter_process_id > 0): - data["converter"] = converter_process_id - - with open(processid_file_path, "w") as jsonFile: - json.dump(data, jsonFile, indent=4) - - with open(processid_file_path, "r") as f: - dataupdated = json.load(f) - #print("Process IDS docservice, spellchecker, converter :: "+str(dataupdated)) -processid_file_path = "process_id.json" \ No newline at end of file diff --git a/bin/configure.py b/bin/configure.py deleted file mode 100644 index 5e3024588..000000000 --- a/bin/configure.py +++ /dev/null @@ -1,239 +0,0 @@ -import json -import os.path -import getpass -import os - -from os import path - - -def is_port_in_use(port): - import socket - with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: - return s.connect_ex(('localhost', port)) == 0 - -####doc service config -def get_docservice_port(config): - fetch_docservice_port_from_user(config) - while config["docservice_port"] < 0 or is_port_in_use(config["docservice_port"]): - print(" Port : "+config["docservice_port"]+" is invalid or already open. Please enter a valid port.") - fetch_docservice_port_from_user(config) - - - print("docservice_port port is :" + str(config["docservice_port"])) - -def fetch_docservice_port_from_user(config): - #check valid default port and port not in use - with open(defaultjson_path, "r") as f: - data = json.load(f) - - while True: - docservice_port = input("Enter docservice port number (Press enter to keep default): ") - if docservice_port.isdigit(): - break - elif not docservice_port: - docservice_port = data["services"]["CoAuthoring"]["server"]["port"] - break - else: - print("Only numbers between 0-65535 accepted.") - - config["docservice_port"] = int(docservice_port) - -def get_docservice_ssl_crt(config): - docservice_cert_file_path = input("Enter docservice ssl .crt file path (Press enter to keep default): ") - - if docservice_cert_file_path: - while not (path.exists(docservice_cert_file_path)): - docservice_cert_file_path = input("Enter valid docservice ssl .crt file path : ") - else: - #check if the default path is valid - with open(defaultjson_path, "r") as f: - data = json.load(f) - - docservice_cert_file_path = data["services"]["CoAuthoring"]["ssl"]["cert"] - while not (path.exists(docservice_cert_file_path)): - docservice_cert_file_path = input("Enter valid docservice ssl .crt file path : ") - - config["docservice_cert_file_path"] = docservice_cert_file_path - - -def get_docservice_ssl_key(config): - docservice_key_file_path = input("Enter docservice ssl .key file path (Press enter to keep default): ") - - if docservice_key_file_path: - while not (path.exists(docservice_key_file_path)): - docservice_key_file_path = input("Enter valid docservice ssl .key file path : ") - else: - with open(defaultjson_path, "r") as f: - data = json.load(f) - - docservice_key_file_path = data["services"]["CoAuthoring"]["ssl"]["key"] - while not (path.exists(docservice_key_file_path)): - docservice_key_file_path = input("Enter valid docservice ssl .key file path : ") - - config["docservice_key_file_path"] = docservice_key_file_path - - - -### spellchecker config - -def get_spellchecker_port(config): - fetch_spellchecker_port_from_user(config) - while config["spellchecker_port"] < 0 or is_port_in_use(config["spellchecker_port"]): - print(" Port : "+config["spellchecker_port"]+" is invalid or already open. Please enter a valid port.") - fetch_spellchecker_port_from_user(config) - - print("spellchecker_port port is :" + str(config["spellchecker_port"])) - -def fetch_spellchecker_port_from_user(config): - #check valid default port and port not in use - with open(defaultjson_path, "r") as f: - data = json.load(f) - - while True: - spellchecker_port = input("Enter spellchecker port number (Press enter to keep default): ") - if spellchecker_port.isdigit(): - break - elif not spellchecker_port: - spellchecker_port = data["SpellChecker"]["server"]["port"] - break - else: - print("Only numbers between 0-65535 accepted.") - - config["spellchecker_port"] = int(spellchecker_port) - - -def get_spellchecker_ssl_crt(config): - spellchecker_cert_file_path = input("Enter spellchecker ssl .crt file path (Press enter to keep default): ") - - if spellchecker_cert_file_path: - while not (path.exists(spellchecker_cert_file_path)): - spellchecker_cert_file_path = input("Enter valid spellchecker ssl .crt file path : ") - else: - #check if the default path is valid - with open(defaultjson_path, "r") as f: - data = json.load(f) - - spellchecker_cert_file_path = data["SpellChecker"]["ssl"]["cert"] - while not (path.exists(spellchecker_cert_file_path)): - spellchecker_cert_file_path = input("Enter valid spellchecker ssl .crt file path : ") - - config["spellchecker_cert_file_path"] = spellchecker_cert_file_path - -def get_spellchecker_ssl_key(config): - spellchecker_key_file_path = input("Enter spellchecker ssl .key file path (Press enter to keep default): ") - - if spellchecker_key_file_path: - while not (path.exists(spellchecker_key_file_path)): - spellchecker_key_file_path = input("Enter valid spellchecker ssl .key file path : ") - else: - with open(defaultjson_path, "r") as f: - data = json.load(f) - - spellchecker_key_file_path = data["SpellChecker"]["ssl"]["key"] - while not (path.exists(spellchecker_key_file_path)): - spellchecker_key_file_path = input("Enter valid spellchecker ssl .key file path : ") - - config["spellchecker_key_file_path"] = spellchecker_key_file_path - - -def generate_fonts_data(): - if not os.path.exists('../documentserver/fonts'): - os.makedirs('../documentserver/fonts') - os.chdir("../documentserver") - os.system('LD_LIBRARY_PATH=${PWD}/server/FileConverter/bin server/tools/allfontsgen \ - --input="${PWD}/core-fonts" \ - --allfonts-web="${PWD}/sdkjs/common/AllFonts.js" \ - --allfonts="${PWD}/server/FileConverter/bin/AllFonts.js" \ - --images="${PWD}/sdkjs/common/Images" \ - --selection="${PWD}/server/FileConverter/bin/font_selection.bin" \ - --output-web=\'fonts\' \ - --use-system="true"') - os.chdir("../bin") - -def generate_presentation_themes(): - os.chdir("../documentserver") - os.system('LD_LIBRARY_PATH=${PWD}/server/FileConverter/bin server/tools/allthemesgen \ - --converter-dir="${PWD}/server/FileConverter/bin"\ - --src="${PWD}/sdkjs/slide/themes"\ - --output="${PWD}/sdkjs/common/Images"') - os.chdir("../bin") - -#updates default.json -def update_json(config): - with open(defaultjson_path, "r") as f: - data = json.load(f) - - # data["services"]["CoAuthoring"]["server"]["port"] = config["docservice_port"] - data["services"]["CoAuthoring"]["ssl"]["key"] = config["docservice_key_file_path"] - data["services"]["CoAuthoring"]["ssl"]["cert"] = config["docservice_cert_file_path"] - - # data["SpellChecker"]["server"]["port"] = config["spellchecker_port"] - data["SpellChecker"]["ssl"]["key"] = config["spellchecker_key_file_path"] - data["SpellChecker"]["ssl"]["cert"] = config["spellchecker_cert_file_path"] - - data["services"]["CoAuthoring"]["token"]["enable"]["browser"] = True - data["services"]["CoAuthoring"]["token"]["enable"]["request"]["inbox"] = True - data["services"]["CoAuthoring"]["token"]["enable"]["request"]["outbox"] = True - - data["services"]["CoAuthoring"]["requestDefaults"]["rejectUnauthorized"] = False - - data["services"]["CoAuthoring"]["secret"]["browser"]["string"] = config["jwt_secret"] - data["services"]["CoAuthoring"]["secret"]["inbox"]["string"] = config["jwt_secret"] - data["services"]["CoAuthoring"]["secret"]["outbox"]["string"] = config["jwt_secret"] - data["services"]["CoAuthoring"]["secret"]["session"]["string"] = config["jwt_secret"] - - data["services"]["CoAuthoring"]["sql"]["dbPort"] = config["mysql_port"] - data["services"]["CoAuthoring"]["sql"]["dbUser"] = config["mysql_user"] - data["services"]["CoAuthoring"]["sql"]["dbPass"] = config["mysql_password"] - - - data["services"]["CoAuthoring"]["secret"]["session"]["string"] = config["jwt_secret"] - - with open(defaultjson_path, "w") as jsonFile: - json.dump(data, jsonFile, indent=4) - - -### config -def config_docservice(config = {}): - - # get_docservice_port(config) - get_docservice_ssl_crt(config) - get_docservice_ssl_key(config) - -def config_spellchecker(config = {}): - - # get_spellchecker_port(config) - get_spellchecker_ssl_crt(config) - get_spellchecker_ssl_key(config) - - -defaultjson_path = "../documentserver/server/Common/config/default.json" - - -if __name__ == '__main__': - config ={} - config_docservice(config) - config_spellchecker(config) - - - jwt_secret = input("Enter onlyoffice secret : ") - - config["jwt_secret"] = jwt_secret - #print(config) - #mysql config - mysql_port = input("Enter mysql port : ") - config["mysql_port"] = mysql_port - - mysql_user = input("Enter mysql username : ") - config["mysql_user"] = mysql_user - - mysql_password = getpass.getpass('Enter mysql password :') - config["mysql_password"] = mysql_password - - - update_json(config) - - generate_fonts_data() - generate_presentation_themes() - - print("Configuration done.") diff --git a/bin/install_rabbitmq.py b/bin/install_rabbitmq.py deleted file mode 100644 index 3f9ff731a..000000000 --- a/bin/install_rabbitmq.py +++ /dev/null @@ -1,172 +0,0 @@ -#!/usr/bin/python -## get subprocess module -import subprocess -import sys -import os - -def install_erlang(): - # create file /etc/yum.repos.d/rabbitmq_erlang.repo - f= open("/etc/yum.repos.d/rabbitmq_erlang.repo","w+") - f.truncate(0) - f.write('[rabbitmq_erlang]\n\ -name=rabbitmq-rabbitmq-erlang\n\ -baseurl=https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-erlang/rpm/el/7/$basearch\n\ -repo_gpgcheck=1\n\ -enabled=1\n\ -gpgkey=https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-erlang/gpg.E495BB49CC4BBE5B.key\n\ - https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc\n\ -gpgcheck=1\n\ -sslverify=1\n\ -sslcacert=/etc/pki/tls/certs/ca-bundle.crt\n\ -metadata_expire=300\n\ -pkg_gpgcheck=1\n\ -autorefresh=1\n\ -type=rpm-md\n\ -\n\ -[rabbitmq_erlang-noarch]\n\ -name=rabbitmq-rabbitmq-erlang-noarch\n\ -baseurl=https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-erlang/rpm/el/7/noarch\n\ -repo_gpgcheck=1\n\ -enabled=1\n\ -gpgkey=https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-erlang/gpg.E495BB49CC4BBE5B.key\n\ - https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc\n\ -gpgcheck=1\n\ -sslverify=1\n\ -sslcacert=/etc/pki/tls/certs/ca-bundle.crt\n\ -metadata_expire=300\n\ -pkg_gpgcheck=1\n\ -autorefresh=1\n\ -type=rpm-md\n\ -\n\ -[rabbitmq_erlang-source]\n\ -name=rabbitmq-rabbitmq-erlang-source\n\ -baseurl=https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-erlang/rpm/el/7/SRPMS\n\ -repo_gpgcheck=1\n\ -enabled=1\n\ -gpgkey=https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-erlang/gpg.E495BB49CC4BBE5B.key\n\ - https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc\n\ -gpgcheck=1\n\ -sslverify=1\n\ -sslcacert=/etc/pki/tls/certs/ca-bundle.crt\n\ -metadata_expire=300\n\ -pkg_gpgcheck=1\n\ -autorefresh=1\n\ -type=rpm-md' - ) - - f.close() - print("FILE : /etc/yum.repos.d/rabbitmq_erlang.repo created.") - # yum update - p_yum_update = subprocess.Popen('yum --disablerepo="*" --enablerepo="rabbitmq_erlang" update -y', stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True) - (output, err) = p_yum_update.communicate() - - ## Wait for terminate. Get return returncode ## - p_yum_update_status = p_yum_update.wait() - out = output.decode('utf-8') - - if p_yum_update_status != 0: - print("Yum Update err : "+ str(err)) - sys.exit("Yum Update exited with status/return code : "+ str(p_yum_update_status)) - - print("Yum Updated.") - #yum install -y erlang-23.3.4 - p_install_erlang = subprocess.Popen('yum install -y erlang-23.3.4', stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True) - (erlang_output, err) = p_install_erlang.communicate() - - ## Wait for terminate. Get return returncode ## - p_install_erlang_status = p_install_erlang.wait() - p_install_erlang_out = erlang_output.decode('utf-8') - - if p_install_erlang_status != 0: - print("Yum Erlang Installation err : "+ str(err)) - sys.exit("Yum Erlang Installation exited with status/return code : "+ str(p_install_erlang_status)) - - print("Yum Erlang installation done.") - -def install_rabbitmq(): - # create file /etc/yum.repos.d/rabbitmq_server.repo - f= open("/etc/yum.repos.d/rabbitmq_server.repo","w+") - f.truncate(0) - f.write('[rabbitmq_server]\n\ -name=rabbitmq_server\n\ -baseurl=https://packagecloud.io/rabbitmq/rabbitmq-server/el/7/$basearch\n\ -repo_gpgcheck=1\n\ -gpgcheck=0\n\ -enabled=1\n\ -gpgkey=https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey\n\ -sslverify=1\n\ -sslcacert=/etc/pki/tls/certs/ca-bundle.crt\n\ -metadata_expire=300') - - f.close() - - #yum install rabbitmq-server -y - p_install_rabbitmq = subprocess.Popen('yum install rabbitmq-server -y', stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True) - (rmq_output, err) = p_install_rabbitmq.communicate() - - ## Wait for terminate. Get return returncode ## - p_install_rabbitmq_status = p_install_rabbitmq.wait() - p_install_rabbitmq_out = rmq_output.decode('utf-8') - - if p_install_rabbitmq_status != 0: - print("Yum RabbitMQ Server Installation err : "+ str(err)) - sys.exit("Yum RabbitMQ Server Installation exited with status/return code : "+ str(p_install_rabbitmq_status)) - print("RabbitMQ Server installation done.") - -def install(name_str): - if(os_ubuntu in name_str): - p_install = subprocess.Popen('sudo apt-get install rabbitmq-server -y', stdout=subprocess.PIPE, - stderr=subprocess.STDOUT, shell=True) - (output, err) = p_install.communicate() - - ## Wait for terminate. Get return returncode ## - p_install_status = p_install.wait() - out = output.decode('utf-8') - - if p_install_status != 0: - print("Install err : "+ str(err)) - sys.exit("Installation on Ubuntu exited with status/return code : "+ str(p_install_status)) - else: - print("Installation done : "+ out) - else: - #for other os - install_erlang() - install_rabbitmq() - #start and enable rabbitmq server - os.system('systemctl start rabbitmq-server') - os.system('systemctl enable rabbitmq-server') - print("Rabbit MQ Started. Use 'rpm -qi rabbitmq-server' to verify.") - - - -if __name__ == '__main__': - - p = subprocess.Popen('grep \'^NAME\' /etc/os-release', stdout=subprocess.PIPE, - stderr=subprocess.STDOUT, shell=True) - (output, err) = p.communicate() - - ## Wait for date to terminate. Get return returncode ## - p_status = p.wait() - out = output.decode('utf-8') - - if p_status != 0: - - print("Command err : "+ str(err)) - print("Command exit status/return code : "+ str(p_status)) - sys.exit(" Problem while Installing. OS name could not be fetched.") - - #split on \n - name_lines = out.split("\n") - - name = name_lines[0].split("=") - - os_ubuntu = "Ubuntu" - - if name and name[1]: - print("OS : "+str(name[1])) - install(str(name[1])) - else: - sys.exit(" Problem while fetching OS name.") - - - diff --git a/bin/jq b/bin/jq new file mode 100644 index 000000000..f48b0ca92 Binary files /dev/null and b/bin/jq differ diff --git a/bin/startall.py b/bin/startall.py deleted file mode 100644 index 69182ac63..000000000 --- a/bin/startall.py +++ /dev/null @@ -1,10 +0,0 @@ -import startdocservice -import startspellchecker -import startconverter -import common_util - -if __name__ == '__main__': - common_util.check_services_running() - startconverter.start_converter_service() - startspellchecker.start_spellchecker_service() - startdocservice.start_docservice_service() diff --git a/bin/startconverter.py b/bin/startconverter.py deleted file mode 100644 index fd150f39e..000000000 --- a/bin/startconverter.py +++ /dev/null @@ -1,19 +0,0 @@ -import os -import subprocess -import common_util - - -def start_converter_service(): - converter_process = subprocess.Popen([os.path.abspath("./../documentserver/server/FileConverter/converter"), "&"], env = env_var) - #docservice_process.wait() - print("converter pid : "+str(converter_process.pid)) - common_util.update_processid(-1, -1, converter_process.pid) - -env_var={} -env_var["NODE_ENV"] = "onlyofficeconfig" -env_var["NODE_CONFIG_DIR"] = os.path.abspath("../documentserver/server/Common/config") -env_var["LD_LIBRARY_PATH"] = os.path.abspath("../documentserver/server/FileConverter/bin") - -if __name__ == '__main__': - common_util.check_converter_running() - diff --git a/bin/startdocservice.py b/bin/startdocservice.py deleted file mode 100644 index 4d1edc2b6..000000000 --- a/bin/startdocservice.py +++ /dev/null @@ -1,18 +0,0 @@ -import os -import subprocess -import common_util - - -def start_docservice_service(): - docservice_process = subprocess.Popen([os.path.abspath("./../documentserver/server/DocService/docservice"), "&"], env = env_var) - #docservice_process.wait() - print("docservice pid : "+str(docservice_process.pid)) - common_util.update_processid(docservice_process.pid, -1, -1) - -env_var={} -env_var["NODE_ENV"] = "onlyofficeconfig" -env_var["NODE_CONFIG_DIR"] = os.path.abspath("../documentserver/server/Common/config") - -if __name__ == '__main__': - common_util.check_docservice_running() - start_docservice_service() \ No newline at end of file diff --git a/bin/startspellchecker.py b/bin/startspellchecker.py deleted file mode 100644 index 68ce98638..000000000 --- a/bin/startspellchecker.py +++ /dev/null @@ -1,16 +0,0 @@ -import os -import subprocess -import common_util - - -def start_spellchecker_service(): - spellchecker_process = subprocess.Popen([os.path.abspath("./../documentserver/server/SpellChecker/spellchecker"), "&"], env = env_var) - print("spellchecker pid : "+str(spellchecker_process.pid)) - common_util.update_processid(-1, spellchecker_process.pid, -1) - -env_var={} -env_var["NODE_ENV"] = "onlyofficeconfig" -env_var["NODE_CONFIG_DIR"] = os.path.abspath("../documentserver/server/Common/config") - -if __name__ == '__main__': - common_util.check_spellchecker_running() \ No newline at end of file diff --git a/bin/stopall.py b/bin/stopall.py deleted file mode 100644 index bb3ce73aa..000000000 --- a/bin/stopall.py +++ /dev/null @@ -1,9 +0,0 @@ -import stopconverter -import stopspellchecker -import stopdocservice - - -if __name__ == '__main__': - stopconverter.stop_converter_service() - stopspellchecker.stop_spellchecker_service() - stopdocservice.stop_docservice_service() \ No newline at end of file diff --git a/bin/stopconverter.py b/bin/stopconverter.py deleted file mode 100644 index 3142e6811..000000000 --- a/bin/stopconverter.py +++ /dev/null @@ -1,17 +0,0 @@ -import os -import subprocess -import common_util -import json - - -def stop_converter_service(): - with open(processid_file_path, "r") as f: - data = json.load(f) - - if(data["converter"] > 0 and common_util.check_pid(data["converter"])): - os.kill(int(data["converter"]), 9) - -processid_file_path = "process_id.json" - -if __name__ == '__main__': - stop_converter_service() \ No newline at end of file diff --git a/bin/stopdocservice.py b/bin/stopdocservice.py deleted file mode 100644 index 9aeb30320..000000000 --- a/bin/stopdocservice.py +++ /dev/null @@ -1,17 +0,0 @@ -import os -import subprocess -import common_util -import json - - -def stop_docservice_service(): - with open(processid_file_path, "r") as f: - data = json.load(f) - - if(data["docservice"] > 0 and common_util.check_pid(data["docservice"])): - os.kill(int(data["docservice"]), 9) - -processid_file_path = "process_id.json" - -if __name__ == '__main__': - stop_docservice_service() \ No newline at end of file diff --git a/bin/stopspellchecker.py b/bin/stopspellchecker.py deleted file mode 100644 index b2b055eb9..000000000 --- a/bin/stopspellchecker.py +++ /dev/null @@ -1,17 +0,0 @@ -import os -import subprocess -import common_util -import json - - -def stop_spellchecker_service(): - with open(processid_file_path, "r") as f: - data = json.load(f) - - if(data["spellchecker"] > 0 and common_util.check_pid(data["spellchecker"])): - os.kill(int(data["spellchecker"]), 9) - -processid_file_path = "process_id.json" - -if __name__ == '__main__': - stop_spellchecker_service() \ No newline at end of file diff --git a/bin/zmonlyofficeconfig b/bin/zmonlyofficeconfig new file mode 100644 index 000000000..2e9f77156 --- /dev/null +++ b/bin/zmonlyofficeconfig @@ -0,0 +1,256 @@ +#!/bin/bash +# +# ***** BEGIN LICENSE BLOCK ***** +# Zimbra Collaboration Suite Server +# Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2016, 2021 Synacor, Inc. +# +# This program is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software Foundation, +# version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; +# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU General Public License for more details. +# You should have received a copy of the GNU General Public License along with this program. +# If not, see . +# ***** END LICENSE BLOCK ***** +# + +source /opt/zimbra/bin/zmshutil || exit 1 +zmsetvars + +zmjq="/opt/zimbra/onlyoffice/bin/jq" + +defaultjson_path="/opt/zimbra/onlyoffice/documentserver/server/Common/config/default.json" +mysql_port=7306 +zimbra_mysql_user="zimbra" +zimbra_mysql_password="" +server_crt="/opt/zimbra/ssl/zimbra/server/server.crt" +server_key="/opt/zimbra/ssl/zimbra/server/server.key" + +STATUS=0 + +document_editing_JWT_secret="" + +usage() { + echo "" + echo "Invalid argument. Allowed :" + echo "new Configure Onlyoffice on the server" + echo "update-jwt-secret arg0 Update Onlyoffice server's jwt secret with the passed value" + echo "update-db Update Onlyoffice server's DB connection details from config" + echo "" + exit +} + +generate_random() +{ + length=8 + digits=({2..9}) + lower=({a..k} {m..n} {p..z}) + upper=({A..N} {P..Z}) + CharArray=(${digits[*]} ${lower[*]} ${upper[*]}) + ArrayLength=${#CharArray[*]} + password="" + for i in `seq 1 $length` + do + index=$(($RANDOM%$ArrayLength)) + char=${CharArray[$index]} + password=${password}${char} + done + echo $password + +} + +update_db_config() +{ + #port + config_mysql_port=$(su - zimbra -c "zmlocalconfig -x -s mysql_port") + if [ ! -z "$config_mysql_port" ]; then + IFS='=' + read -ra arr <<< "$config_mysql_port" + mysql_port=$(echo "${arr[1]}" | xargs) + + fi + + + content=$(${zmjq} --argjson mysql_port "$mysql_port" '.services.CoAuthoring.sql.dbPort=$mysql_port' ${defaultjson_path}) + echo "${content}" > ${defaultjson_path} + + #user + config_mysql_user=$(su - zimbra -c "zmlocalconfig -x -s zimbra_mysql_user") + if [ ! -z "$config_mysql_user" ]; then + IFS='=' + read -ra arr <<< "$config_mysql_user" + zimbra_mysql_user=$(echo "${arr[1]}" | xargs) + + fi + + content=$(${zmjq} --arg zimbra_mysql_user "$zimbra_mysql_user" '.services.CoAuthoring.sql.dbUser=$zimbra_mysql_user' ${defaultjson_path}) + echo "${content}" > ${defaultjson_path} + + #password + config_mysql_pass=$(su - zimbra -c "zmlocalconfig -x -s zimbra_mysql_password") + if [ ! -z "$config_mysql_pass" ]; then + IFS='=' + read -ra arr <<< "$config_mysql_pass" + zimbra_mysql_password=$(echo "${arr[1]}" | xargs) + + fi + + content=$(${zmjq} --arg zimbra_mysql_password "$zimbra_mysql_password" '.services.CoAuthoring.sql.dbPass=$zimbra_mysql_password' ${defaultjson_path}) + echo "${content}" > ${defaultjson_path} + +} + +update_certificate_path() +{ + content=$(${zmjq} --arg server_crt "$server_crt" '.services.CoAuthoring.ssl.cert=$server_crt' ${defaultjson_path}) + echo "${content}" > ${defaultjson_path} + + content=$(${zmjq} --arg server_crt "$server_crt" '.SpellChecker.ssl.cert=$server_crt' ${defaultjson_path}) + echo "${content}" > ${defaultjson_path} + + content=$(${zmjq} --arg server_key "$server_key" '.services.CoAuthoring.ssl.key=$server_key' ${defaultjson_path}) + echo "${content}" > ${defaultjson_path} + + content=$(${zmjq} --arg server_key "$server_key" '.SpellChecker.ssl.key=$server_key' ${defaultjson_path}) + echo "${content}" > ${defaultjson_path} +} + +update_token_config() +{ + + content=$(${zmjq} '.services.CoAuthoring.token.enable.browser=true' ${defaultjson_path}) + echo "${content}" > ${defaultjson_path} + + content=$(${zmjq} '.services.CoAuthoring.token.enable.request.inbox=true' ${defaultjson_path}) + echo "${content}" > ${defaultjson_path} + + content=$(${zmjq} '.services.CoAuthoring.token.enable.request.outbox=true' ${defaultjson_path}) + echo "${content}" > ${defaultjson_path} + + content=$(${zmjq} '.services.CoAuthoring.requestDefaults.rejectUnauthorized=false' ${defaultjson_path}) + echo "${content}" > ${defaultjson_path} + +} + +update_jwt_config() +{ + jwtsecret=$1 + cmd="su - zimbra -c \"zmprov -m -l mcf zimbraDocumentEditingJwtSecret ${jwtsecret}\"" + eval "$cmd" + RC=$? + if [ $RC -ne "0" ]; then + STATUS=$R + echo "Updating zimbraDocumentEditingJwtSecret faced problem." + fi + + #update the default.json + content=$(${zmjq} --arg jwtsecret "$jwtsecret" '.services.CoAuthoring.secret.browser.string=$jwtsecret' ${defaultjson_path}) + echo "${content}" > ${defaultjson_path} + + content=$(${zmjq} --arg jwtsecret "$jwtsecret" '.services.CoAuthoring.secret.inbox.string=$jwtsecret' ${defaultjson_path}) + echo "${content}" > ${defaultjson_path} + + content=$(${zmjq} --arg jwtsecret "$jwtsecret" '.services.CoAuthoring.secret.outbox.string=$jwtsecret' ${defaultjson_path}) + echo "${content}" > ${defaultjson_path} + + content=$(${zmjq} --arg jwtsecret "$jwtsecret" '.services.CoAuthoring.secret.session.string=$jwtsecret' ${defaultjson_path}) + echo "${content}" > ${defaultjson_path} +} + +set_jwt_secret() +{ + if [ -z "$1" ]; then + echo "Setting Random Secret..." + jwtsecret=$(generate_random) + update_jwt_config $jwtsecret + else + jwtsecret=$1 + update_jwt_config $jwtsecret + fi +} + +generate_fonts_data() +{ + mkdir -p /opt/zimbra/onlyoffice/documentserver/fonts + + fonts_gen=$(LD_LIBRARY_PATH=/opt/zimbra/onlyoffice/documentserver/server/FileConverter/bin /opt/zimbra/onlyoffice/documentserver/server/tools/allfontsgen \ + --input="/opt/zimbra/onlyoffice/documentserver/core-fonts" \ + --allfonts-web="/opt/zimbra/onlyoffice/documentserver/sdkjs/common/AllFonts.js" \ + --allfonts="/opt/zimbra/onlyoffice/documentserver/server/FileConverter/bin/AllFonts.js" \ + --images="/opt/zimbra/onlyoffice/documentserver/sdkjs/common/Images" \ + --selection="/opt/zimbra/onlyoffice/documentserver/server/FileConverter/bin/font_selection.bin" \ + --output-web="/opt/zimbra/onlyoffice/documentserver/fonts" \ + --use-system="true") + R=$? + if [ $R -ne "0" ]; then + STATUS=$R + echo "Error while generating fonts. ${fonts_gen}" + fi + +} + +generate_presentation_themes() +{ + presentation_themes_gen=$(LD_LIBRARY_PATH=/opt/zimbra/onlyoffice/documentserver/server/FileConverter/bin /opt/zimbra/onlyoffice/documentserver/server/tools/allthemesgen \ + --converter-dir="/opt/zimbra/onlyoffice/documentserver/server/FileConverter/bin"\ + --src="/opt/zimbra/onlyoffice/documentserver/sdkjs/slide/themes"\ + --output="/opt/zimbra/onlyoffice/documentserver/sdkjs/common/Images") + R=$? + if [ $R -ne "0" ]; then + STATUS=$R + echo "Error while generating presentation themes. ${presentation_themes_gen}" + fi +} + +type="$1" +if [ "$#" -eq 0 ]; then + type="new" +fi + + +case "$type" in + new) + + jwtsecret=$(su - zimbra -c "zmprov -m -l getConfig zimbraDocumentEditingJwtSecret") + if [ -z "$jwtsecret" ]; then + echo "JWT Secret not set." + set_jwt_secret + else + IFS=':' + read -ra arr <<< "$jwtsecret" + document_editing_JWT_secret=$(echo "${arr[1]}" | xargs) + update_jwt_config $document_editing_JWT_secret + fi + + update_certificate_path + update_token_config + update_db_config + generate_fonts_data + generate_presentation_themes + echo "Onlyoffice configuration done." + exit $STATUS + ;; + + update-jwt-secret) + + if [ "$#" -ne 2 ]; then + usage + exit 1 + fi + jwtsecret="$2" + + update_jwt_config $jwtsecret + exit $STATUS + ;; + + update-db ) + update_db_config + exit $STATUS + ;; + *) + usage + exit 1 + ;; +esac