Skip to content

Commit

Permalink
PowerBox for Rocket.Chat Push fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
peterlee0127 committed Nov 27, 2017
1 parent 713d77d commit 523f983
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 40 deletions.
24 changes: 12 additions & 12 deletions .meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
# 'meteor add' and 'meteor remove' will edit this file for you,
# but you can also edit it by hand.

rocketchat:cors
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
#rocketchat:cors
#[email protected]
#[email protected]
#[email protected]
#[email protected]
#[email protected]
#[email protected]
blaze-html-templates
[email protected]
[email protected]
Expand All @@ -36,7 +36,7 @@ spacebars
[email protected]
[email protected]

rocketchat:2fa
#rocketchat:2fa
rocketchat:action-links
rocketchat:analytics
rocketchat:api
Expand Down Expand Up @@ -94,7 +94,7 @@ rocketchat:oembed
rocketchat:otr
rocketchat:push-notifications
rocketchat:reactions
#rocketchat:sandstorm
rocketchat:sandstorm
#rocketchat:slackbridge
rocketchat:slashcommands-archive
rocketchat:slashcommands-asciiarts
Expand All @@ -113,7 +113,7 @@ rocketchat:slashcommands-topic
rocketchat:slashcommands-unarchive
rocketchat:slider
rocketchat:smarsh-connector
rocketchat:spotify
#rocketchat:spotify
rocketchat:statistics
rocketchat:streamer
rocketchat:theme
Expand All @@ -134,9 +134,9 @@ rocketchat:webrtc
rocketchat:wordpress
rocketchat:message-snippet
#rocketchat:google-natural-language
rocketchat:drupal
#rocketchat:drupal
rocketchat:monitoring
#rocketchat:chatops
rocketchat:chatops

konecty:change-case
konecty:delayed-task
Expand Down
13 changes: 3 additions & 10 deletions .meteor/versions
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
aldeed:[email protected]
[email protected]
[email protected]
Expand All @@ -25,6 +20,7 @@ [email protected]
[email protected]_1
[email protected]_1
dandv:[email protected]
dburles:[email protected]
[email protected]
[email protected]
[email protected]
Expand All @@ -47,7 +43,6 @@ [email protected]
[email protected]
francocatena:[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
Expand Down Expand Up @@ -80,7 +75,6 @@ matb33:[email protected]
mdg:[email protected]
[email protected]
[email protected]
[email protected]
meteorhacks:[email protected]
meteorhacks:[email protected]
meteorspark:[email protected]
Expand Down Expand Up @@ -136,13 +130,12 @@ rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
Expand Down Expand Up @@ -189,6 +182,7 @@ rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
Expand All @@ -207,7 +201,6 @@ rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
Expand Down
13 changes: 13 additions & 0 deletions .sandstorm/sandstorm-pkgdef.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,19 @@ const pkgdef :Spk.PackageDefinition = (
(name = "privateMessage", verbPhrase = (defaultText = "sent private message"), requiredPermission = (explicitList = void)),
]
),
powerboxApis = [
(
name = "rocket.chat push gateway",
displayInfo = (
title = (defaultText = "Rocket.Chat Push Gateway"),
),
path = "/",
tag = (
canonicalUrl = "https://gateway.rocket.chat"
),
permissions = [true, true], # read and write
)
],
saveIdentityCaps = true,
),
);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
"prom-client": "^10.1.1",
"semver": "^5.4.1",
"toastr": "^2.1.2",
"request":"",
"wolfy87-eventemitter": "^5.2.2"
}
}
3 changes: 3 additions & 0 deletions packages/rocketchat-api/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ Package.onUse(function(api) {
api.addFiles('server/v1/settings.js', 'server');
api.addFiles('server/v1/stats.js', 'server');
api.addFiles('server/v1/users.js', 'server');

api.addFiles('server/v1/powerbox.js', 'server');

});

Npm.depends({
Expand Down
39 changes: 39 additions & 0 deletions packages/rocketchat-api/server/v1/powerbox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const request = require('request');
const fs = require('fs');

RocketChat.API.v1.addRoute('claimToken', { authRequired: false }, {
post() {
const par = this.requestParams();
const headers = this.request.headers;
const claimToken = par.token;
const sessionId = headers['x-sandstorm-session-id'];
// console.log(headers);
// console.log("claimToken:"+claimToken);
// console.log("sessionId:"+sessionId);
request({
proxy: process.env.HTTP_PROXY,
method: "POST",
url: "http://http-bridge/session/" + sessionId + "/claim",
json: {
requestToken: claimToken,
requiredPermissions: ["read","write"]
}
}, (err, httpResponse, body) => {
if (err) {
console.error(err);
} else {
// console.log(httpResponse);
// console.log("body:"+body.cap);
if (body.cap !== undefined) {
fs.writeFile("/var/token.txt",body.cap,function(err){
if(err){console.log(err); }
// const powerBoxToken = fs.readFileSync("/var/token.txt",'utf8');
// console.log("token:"+powerBoxToken);
});
}
}
});//request
return RocketChat.API.v1.success();
// return RocketChat.API.v1.failure();
}//post
});
6 changes: 3 additions & 3 deletions packages/rocketchat-ui-sidenav/client/accountBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ Template.accountBox.events({
id: 'account'
},
{
icon: 'sign-out',
name: t('Logout'),
icon: 'circle',
name: t('Powerbox'),
type: 'open',
id: 'logout'
id: 'powerbox'
}
])
}
Expand Down
6 changes: 4 additions & 2 deletions packages/rocketchat-ui-sidenav/client/userStatus.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ <h4>{{username}}</h4>
{{#if showAdminOption }}
<button id="admin" class='account-link'><i class="icon-wrench"></i><span>{{_ "Administration"}}</span></button>
{{/if}}
<button id="logout"><i class="icon-logout"></i><span>{{_ "Logout"}}</span></button>
</div>
<button id="powerbox"><i class="icon-wrench"></i><span>Powerbox</span></button>
<!--<button id="logout"><i class="icon-logout"></i><span>{{_ "Logout"}}</span></button>
-->
</div>
</nav>
{{/with}}
</div>
Expand Down
45 changes: 38 additions & 7 deletions packages/rocketchat-ui/client/views/app/popover.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,40 @@
/* globals popover isRtl */
window.addEventListener('message', function(event) {
if (event.source !== window.parent) {
// SECURITY: ignore postMessages that didn't come from the parent frame.
return;
}
var response = event.data;
if (response.rpcId !== 1) {
return;
}
if (response.error) {
alert(response.error);
return;
}
if (response.canceled) {
return;
}
$.post("/api/v1/claimToken",
{
token:response.token
},
function(data, status){
// console.log(data);
console.log(status);
});
});

function powerBoxRequest() {
//EA1QAQEAABEBF1EEAQH/x80lxnnjecgAQAMRCeIAAf9odHRwczovLwJnYXRld2F5LnJvY2tldC5jB2hhdA== //rocket.chat push gateway
window.parent.postMessage({
powerboxRequest: {
rpcId: 1,
query: ['EA1QAQEAABEBF1EEAQH/x80lxnnjecgAQAMRCeIAAf9odHRwczovLwJnYXRld2F5LnJvY2tldC5jB2hhdA=='],
saveLabel: {defaultText: 'Enable Powerbox for Push Gateway'}
}
}, '*');
}

this.popover = {
renderedPopover: null,
Expand Down Expand Up @@ -152,13 +188,8 @@ Template.popover.events({
SideNav.openFlex();
FlowRouter.go('account');
break;
case 'logout':
const user = Meteor.user();
Meteor.logout(() => {
RocketChat.callbacks.run('afterLogoutCleanUp', user);
Meteor.call('logoutCleanUp', user);
FlowRouter.go('home');
});
case 'powerbox':
powerBoxRequest();
break;
case 'administration':
SideNav.setFlex('adminFlex');
Expand Down
22 changes: 16 additions & 6 deletions server/lib/cordova.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,23 @@ Meteor.methods({

function sendPush(service, token, options, tries = 0) {
const data = {
data: {
token,
options
}
token,
options
};

return HTTP.post(`${ RocketChat.settings.get('Push_gateway') }/push/${ service }/send`, data, function(error, response) {
//`${ RocketChat.settings.get('Push_gateway') }/push/${ service }/send`
const pushURL = "http://http-bridge/push/"+service+"/send";
const fs = require('fs');
const powerBoxToken = fs.readFileSync("/var/token.txt",'utf8');
const authString = "Bearer "+powerBoxToken;
const option = {
'headers':{
'proxy': process.env.HTTP_PROXY,
'Authorization': authString
},
'data': data
};
return HTTP.call('POST', pushURL, option, function(error, response) {
// console.log("response:"+response);
if (response && response.statusCode === 406) {
console.log('removing push token', token);
Push.appCollection.remove({
Expand Down

0 comments on commit 523f983

Please sign in to comment.