diff --git a/.gitignore b/.gitignore index d50255837f826d6d08c4613cf61aa072c605551a..1d778eda57fec378d0f22d058ab13f54326148cf 100644 --- a/.gitignore +++ b/.gitignore @@ -77,3 +77,4 @@ build.sh packages/rocketchat-i18n/i18n/livechat.* tests/end-to-end/temporary_staged_test .screenshots +/private/livechat diff --git a/app/livechat/client/views/app/livechatInstallation.html b/app/livechat/client/views/app/livechatInstallation.html index 92d646c9052d17de44544f09e941b1c442d1f305..3aced66ab59610a1d7923afe5d97bc9261a4b742 100644 --- a/app/livechat/client/views/app/livechatInstallation.html +++ b/app/livechat/client/views/app/livechatInstallation.html @@ -1,10 +1,18 @@ <template name="livechatInstallation"> {{#requiresPermission 'view-livechat-manager'}} - <p>{{{_ "To_install_RocketChat_Livechat_in_your_website_copy_paste_this_code_above_the_last_body_tag_on_your_site"}}}</p> + <p>{{{_ "To_install_the_new_version_of_RocketChat_Livechat_in_your_website_copy_paste_this_code_above_the_last_body_tag_on_your_site"}}}</p> <div class="livechat-code"> <textarea class="clipboard" data-clipboard-target=".livechat-code textarea">{{script}}</textarea> <button class="button clipboard" data-clipboard-target=".livechat-code textarea"><i class="icon-docs"></i>{{_ "Copy_to_clipboard"}}</button> </div> + + <p>{{{_ "To_install_RocketChat_Livechat_in_your_website_copy_paste_this_code_above_the_last_body_tag_on_your_site"}}}</p> + + <div class="livechat-code clipboard-old"> + <textarea class="clipboard" data-clipboard-target=".clipboard-old textarea">{{oldScript}}</textarea> + <button class="button clipboard" data-clipboard-target=".clipboard-old textarea"><i class="icon-docs"></i>{{_ "Copy_to_clipboard"}}</button> + </div> + {{/requiresPermission}} </template> diff --git a/app/livechat/client/views/app/livechatInstallation.js b/app/livechat/client/views/app/livechatInstallation.js index 13edd998d83c202b9ef47060c7df22de1fccffee..f78b19cdbaf5218ccc4e8f2bd238ba9b60e32b0a 100644 --- a/app/livechat/client/views/app/livechatInstallation.js +++ b/app/livechat/client/views/app/livechatInstallation.js @@ -2,10 +2,11 @@ import { Template } from 'meteor/templating'; import { settings } from '../../../../settings'; import s from 'underscore.string'; +const latestVersion = '1.0.0'; + Template.livechatInstallation.helpers({ - script() { + oldScript() { const siteUrl = s.rtrim(settings.get('Site_Url'), '/'); - return `<!-- Start of Rocket.Chat Livechat Script --> <script type="text/javascript"> (function(w, d, s, u) { @@ -15,6 +16,20 @@ Template.livechatInstallation.helpers({ h.parentNode.insertBefore(j, h); })(window, document, 'script', '${ siteUrl }/livechat'); </script> +<!-- End of Rocket.Chat Livechat Script -->`; + }, + + script() { + const siteUrl = s.rtrim(settings.get('Site_Url'), '/'); + return `<!-- Start of Rocket.Chat Livechat Script --> +<script type="text/javascript"> +(function(w, d, s, u) { + w.RocketChat = function(c) { w.RocketChat._.push(c) }; w.RocketChat._ = []; w.RocketChat.url = u; + var h = d.getElementsByTagName(s)[0], j = d.createElement(s); + j.async = true; j.src = '${ siteUrl }/livechat/${ latestVersion }/rocketchat-livechat.min.js?_=201903270000'; + h.parentNode.insertBefore(j, h); +})(window, document, 'script', '${ siteUrl }/livechat?version=${ latestVersion }'); +</script> <!-- End of Rocket.Chat Livechat Script -->`; }, }); diff --git a/app/livechat/lib/Assets.js b/app/livechat/lib/Assets.js new file mode 100644 index 0000000000000000000000000000000000000000..c7252b5406ae5e33f2ccafb03b6b817ef0e7dc49 --- /dev/null +++ b/app/livechat/lib/Assets.js @@ -0,0 +1,29 @@ +import { Autoupdate } from 'meteor/autoupdate'; + +export const addServerUrlToIndex = (file) => file.replace('<body>', `<body><script> SERVER_URL = '${ __meteor_runtime_config__.ROOT_URL }'; </script>`); + +export const addServerUrlToHead = (head) => { + let baseUrl; + if (__meteor_runtime_config__.ROOT_URL_PATH_PREFIX && __meteor_runtime_config__.ROOT_URL_PATH_PREFIX.trim() !== '') { + baseUrl = __meteor_runtime_config__.ROOT_URL_PATH_PREFIX; + } else { + baseUrl = '/'; + } + if (/\/$/.test(baseUrl) === false) { + baseUrl += '/'; + } + + return `<html> + <head> + <link rel="stylesheet" type="text/css" class="__meteor-css__" href="${ baseUrl }livechat/livechat.css?_dc=${ Autoupdate.autoupdateVersion }"> + <script type="text/javascript"> + __meteor_runtime_config__ = ${ JSON.stringify(__meteor_runtime_config__) }; + </script> + <base href="${ baseUrl }"> + ${ head } + </head> + <body> + <script type="text/javascript" src="${ baseUrl }livechat/livechat.js?_dc=${ Autoupdate.autoupdateVersion }"></script> + </body> + </html>`; +}; diff --git a/app/livechat/server/livechat.js b/app/livechat/server/livechat.js index 9ad396433da3a6a6d6c319e9ee064b3ea58bdb6c..25ecbd9c137d91f30094bec6c282ab0feea57f5c 100644 --- a/app/livechat/server/livechat.js +++ b/app/livechat/server/livechat.js @@ -1,15 +1,24 @@ import { Meteor } from 'meteor/meteor'; import { WebApp } from 'meteor/webapp'; -import { settings } from '../../settings'; -import { Autoupdate } from 'meteor/autoupdate'; +import { settings } from '/app/settings'; +import { addServerUrlToIndex, addServerUrlToHead } from '../lib/Assets'; import _ from 'underscore'; import url from 'url'; +const latestVersion = '1.0.0'; +const indexHtmlWithServerURL = addServerUrlToIndex(Assets.getText('livechat/index.html')); +const headHtmlWithServerURL = addServerUrlToHead(Assets.getText('livechat/head.html')); +const isLatestVersion = (version) => version && version === latestVersion; + WebApp.connectHandlers.use('/livechat', Meteor.bindEnvironment((req, res, next) => { const reqUrl = url.parse(req.url); if (reqUrl.pathname !== '/') { return next(); } + + const { version } = req.query; + const html = isLatestVersion(version) ? indexHtmlWithServerURL : headHtmlWithServerURL; + res.setHeader('content-type', 'text/html; charset=utf-8'); let domainWhiteList = settings.get('Livechat_AllowedDomainsList'); @@ -27,34 +36,6 @@ WebApp.connectHandlers.use('/livechat', Meteor.bindEnvironment((req, res, next) res.setHeader('X-FRAME-OPTIONS', `ALLOW-FROM ${ referer.protocol }//${ referer.host }`); } - const head = Assets.getText('public/head.html'); - - let baseUrl; - if (__meteor_runtime_config__.ROOT_URL_PATH_PREFIX && __meteor_runtime_config__.ROOT_URL_PATH_PREFIX.trim() !== '') { - baseUrl = __meteor_runtime_config__.ROOT_URL_PATH_PREFIX; - } else { - baseUrl = '/'; - } - if (/\/$/.test(baseUrl) === false) { - baseUrl += '/'; - } - - const html = `<html> - <head> - <link rel="stylesheet" type="text/css" class="__meteor-css__" href="${ baseUrl }livechat/livechat.css?_dc=${ Autoupdate.autoupdateVersion }"> - <script type="text/javascript"> - __meteor_runtime_config__ = ${ JSON.stringify(__meteor_runtime_config__) }; - </script> - - <base href="${ baseUrl }"> - - ${ head } - </head> - <body> - <script type="text/javascript" src="${ baseUrl }livechat/livechat.js?_dc=${ Autoupdate.autoupdateVersion }"></script> - </body> - </html>`; - res.write(html); res.end(); })); diff --git a/packages/rocketchat-i18n/i18n/en.i18n.json b/packages/rocketchat-i18n/i18n/en.i18n.json index 1d73cbde30d0097ebe4b2100be1e6b038a997689..e7c5fd65d8a9e98d618a363a1a0ef4f7de217db1 100644 --- a/packages/rocketchat-i18n/i18n/en.i18n.json +++ b/packages/rocketchat-i18n/i18n/en.i18n.json @@ -2828,6 +2828,7 @@ "Today": "Today", "To_additional_emails": "To additional emails", "To_install_RocketChat_Livechat_in_your_website_copy_paste_this_code_above_the_last_body_tag_on_your_site": "To install Rocket.Chat Livechat in your website, copy & paste this code above the last <strong></body></strong> tag on your site.", + "To_install_the_new_version_of_RocketChat_Livechat_in_your_website_copy_paste_this_code_above_the_last_body_tag_on_your_site": "To install the <strong> new version</strong> of Rocket.Chat Livechat in your website, copy & paste this code above the last <strong></body></strong> tag on your site.", "to_see_more_details_on_how_to_integrate": "to see more details on how to integrate.", "To_users": "To Users", "Toggle_original_translated": "Toggle original/translated", diff --git a/packages/rocketchat-i18n/i18n/pt-BR.i18n.json b/packages/rocketchat-i18n/i18n/pt-BR.i18n.json index f70d135fef043aacf5c79e56caf1125c69333d0c..ac66b085e70950adc7c7e03deb5d705500cf3ce1 100644 --- a/packages/rocketchat-i18n/i18n/pt-BR.i18n.json +++ b/packages/rocketchat-i18n/i18n/pt-BR.i18n.json @@ -2777,6 +2777,7 @@ "Today": "Hoje", "To_additional_emails": "Para e-mails adicionais", "To_install_RocketChat_Livechat_in_your_website_copy_paste_this_code_above_the_last_body_tag_on_your_site": "Para instalar Rocket.Chat Livechat no seu website, copie e cole este código acima da última tag <strong></ body></strong> em seu site.", + "To_install_the_new_version_of_RocketChat_Livechat_in_your_website_copy_paste_this_code_above_the_last_body_tag_on_your_site": "Para instalar a <strong>nova versão</strong> do Rocket.Chat Livechat no seu website, copie e cole este código acima da última tag <strong></ body></strong> em seu site.", "to_see_more_details_on_how_to_integrate": "para ver mais detalhes sobre como integrar.", "To_users": "Para Usuários", "Toggle_original_translated": "Alternar original / traduzido", @@ -3121,4 +3122,4 @@ "Your_push_was_sent_to_s_devices": "Sua notificação foi enviada para %s dispositivos", "Your_server_link": "O link do seu servidor", "Your_workspace_is_ready": "O seu espaço de trabalho está pronto a usar 🎉" -} \ No newline at end of file +} diff --git a/packages/rocketchat-livechat/package.js b/packages/rocketchat-livechat/package.js index c56a04af9afeeb094dc2af95b5e56581282d08a3..ff93127da76789d0471a1d77bfc080f94e69e4a3 100644 --- a/packages/rocketchat-livechat/package.js +++ b/packages/rocketchat-livechat/package.js @@ -39,5 +39,4 @@ Package.onUse(function(api) { // DEPRECATED api.addAssets('assets/rocket-livechat.js', 'client'); // this file is still added to not break currently installed livechat widgets api.addAssets('assets/rocketchat-livechat.min.js', 'client'); - api.addAssets('public/head.html', 'server'); }); diff --git a/packages/rocketchat-livechat/plugin/build.sh b/packages/rocketchat-livechat/plugin/build.sh index eb5fa860c959a67a1d5a37a10e206e634f5f24b0..4422c8382b6ff5c98a335b2ad8094c872bebcb70 100644 --- a/packages/rocketchat-livechat/plugin/build.sh +++ b/packages/rocketchat-livechat/plugin/build.sh @@ -2,6 +2,8 @@ export NODE_ENV="production" export LIVECHAT_DIR="../../../public/livechat" export BUILD_DIR="../build" export BUNDLE_DIR="../build/bundle/programs/web.browser.legacy" +export LIVECHAT_ASSETS_DIR="../../../private/livechat" +export LATEST_LIVECHAT_VERSION="1.0.0" cd packages/rocketchat-livechat/.app meteor npm install --production @@ -12,8 +14,25 @@ mkdir -p $LIVECHAT_DIR cp $BUNDLE_DIR/*.css $LIVECHAT_DIR/livechat.css cp $BUNDLE_DIR/*.js $LIVECHAT_DIR/livechat.js -rm -rf ../public -mkdir -p ../public -cp $BUNDLE_DIR/head.html ../public/head.html +rm -rf $LIVECHAT_ASSETS_DIR +mkdir $LIVECHAT_ASSETS_DIR +cp $BUNDLE_DIR/head.html $LIVECHAT_ASSETS_DIR/head.html rm -rf $BUILD_DIR + +#NEW LIVECHAT# +echo "Installing new Livechat..." +cd $LIVECHAT_DIR +mkdir -p $LATEST_LIVECHAT_VERSION +cd $LATEST_LIVECHAT_VERSION + +curl -sOL "https://github.com/RocketChat/Rocket.Chat.Livechat/releases/download/v${LATEST_LIVECHAT_VERSION}/build.tar.gz" +tar -xf build.tar.gz +rm build.tar.gz + +# change to lowercase so all injected junk from rocket.chat is not sent: https://github.com/meteorhacks/meteor-inject-initial/blob/master/lib/inject-core.js#L10 +# this is not harmful since doctype is case-insesitive: https://www.w3.org/TR/html5/syntax.html#the-doctype +ex -s -c '%s/<!DOCTYPE/<!doctype/g|x' index.html + +cd $LIVECHAT_ASSETS_DIR +cp ../../public/livechat/$LATEST_LIVECHAT_VERSION/index.html .