How to send Apple Push Notifications by using apnotic gem? - ruby

I am trying to send Apple's push notification by following the instruction of apnotic gem.
https://github.com/ostinelli/apnotic
require 'apnotic'
connection = Apnotic::Connection.development(
auth_method: :token,
cert_path: "AuthKey_foobar.p8",
key_id: "foobar",
team_id: "abcd1234"
)
# create a notification for a specific device token
token = 'abcdef123456..'
notification = Apnotic::Notification.new(token)
notification.topic = "bundle_id"
notification.alert = "Notification from Apnotic!"
# send notifications and get results
response = connection.push(notification)
puts response.status
puts response.body
connection.close
However, I got the response.
403
{"reason"=>"ExpiredProviderToken"}
I don't think the token is actually expired because I can send notifications by using the app and same IDs and tokens.
https://github.com/onmyway133/PushNotifications

The problem was my virtual machine's clock. After adjusting the clock(by installing ntp), it worked.
$ sudo apt install ntp
$ sudo service ntp status
● ntp.service - Network Time Service
Loaded: loaded (/lib/systemd/system/ntp.service; enabled; vendor preset: enab
Active: active (running) since Sat 2019-08-17 05:46:06 UTC; 7s ago
:
$ ruby push.rb
200
{":status"=>"200", "apns-id"=>"......"}

Related

Mac App Store testing receipt validation (from receigen) "app is damaged and can't be opened."

I'm using Receigen (http://receigen.etiemble.com/) to do receipt validation for one of my MacOS apps. This has worked beautifully for several years, but something has changed. I haven't made an update to this app for a year or so and submitted a change but it was rejected because the receipt validation wasn't working.
When I try to test the receipts locally, it pops up the App Store login, I enter my email+password, and then I get the "app is damaged" message.
I used the Receigen Code Assistant to generate validation code (it generates receipt validation code and randomizes as much as it can so you can't just easily crack every app that uses receigen).
I'm using macOS 10.14.3 and Xcode 10.2.
This is the header from my receigen generated code:
//
// This code was generated by RECEIGEN 4.0.4 on 2019-04-08 15:54:01 and will use:
//
// Bundle Identifier : com.inadaydevelopment.mac10biiFinancialCalculator
// Bundle Version : 2.1.0
// Receipt Identifier : com.inadaydevelopment.mac10biiFinancialCalculator
// Receipt Version : 2.1.0
//
// Language : ObjC
// Platform : OSX
// Code Prefix : ReceiptValidation
// Success Behavior : RunApplication
// Failure Behavior : ExitWith173
//
// Certificate Name : Apple Root CA
// Certificate Fingerprint : 611E5B662C593A08FF58D14AE22452D198DF6C60
// Signer Certificate OID : 1.2.840.113635.100.6.11.1
//
// OpenSSL Version : 1.0
//
// This generated code has to be linked with OpenSSL libcrypto (either statically or dynamically)
// Refer to the website for more details and specific cases.
//
I have verified that the Bundle Id and Version match what I have in XCode (the text field isn't long enough, but it DOES start with com.inaday...):
I looked through Receigen's diagnostic page to see the possible fixes for this, but nothing helped:
1) I looked/searched through my console for any "storeagent" entries and I never find any. Perhaps the Diagnostics page has info for an older version of macOS?
2) I did the "killall" and "rm -r" commands to fix any caching problems associated with the damaged message. I also rebooted several times.
3) I looked inside the app package and I didn't see any receipt.
4) I deleted the only other copy of the app that I know of (the one I've installed from the App Store) and tried everything again. Same problem.
5) Tried removing the Container. Same problem.
6) I tried "sudo pkill -f CommerceKit". Same problem.
This is what I found in my console:
ReceiptRefreshRequest: Error fetching receipt for
/Users/kenny/Library/Developer/Xcode/DerivedData/10bii_Financial_Calculator-edfoaceclymbdsazqdpinclhsejp/Build/Products/Debug/10bii
Financial Calculator.app - Error Domain=com.apple.commerce.server
Code=500317 "(null)"
Here's the full section from the console:
default 11:52:42.776265 -0700 commerce StoreSession: StatusCode: 200; <private>; Environment: SB; URL: https://p100-sandbox.itunes.apple.com/WebObjects/MZFinance.woa/wa/createAppReceipt
debug 11:52:42.776776 -0700 commerce looked up value <private> for key PrimaryAccount:1 in CFPrefsPlistSource<0x7fe4eb803860> (Domain: com.apple.appstore.commerce, User: kCFPreferencesCurrentUser, ByHost: No, Container: (null), Contents Need Refresh: No)
debug 11:52:42.776811 -0700 commerce looked up value <private> for key KnownAccounts:1 in CFPrefsPlistSource<0x7fe4ea6058a0> (Domain: com.apple.commerce, User: kCFPreferencesCurrentUser, ByHost: No, Container: (null), Contents Need Refresh: No)
debug 11:52:42.776909 -0700 commerce Handling response <private> for URL <private>...
debug 11:52:42.776943 -0700 commerce No handling for HTTP status code 200 in response for URL <private>
default 11:52:42.777268 -0700 storeuid ReceiptRefreshRequest: Error fetching receipt for /Users/kenny/Library/Developer/Xcode/DerivedData/10bii_Financial_Calculator-edfoaceclymbdsazqdpinclhsejp/Build/Products/Debug/10bii Financial Calculator.app - Error Domain=com.apple.commerce.server Code=500317 "(null)"
debug 11:52:42.777338 -0700 storeuid Bundle: <private>, key: APP_IS_DAMAGED_TITLE, value: , table: MacAppStore, localizationName: (null), result: APP_IS_DAMAGED_TITLE
debug 11:52:42.777400 -0700 storeuid Bundle: <private>, key: APP_IS_DAMAGED_TITLE, value: , table: Localizable, localizationName: (null), result: “%#” is damaged and can’t be opened. Delete “%#” and download it again from the App Store.
debug 11:52:42.777427 -0700 storelegacy Bundle: <private>, key: com.apple.commerce.server, value: com.apple.commerce.server, table: Error, localizationName: (null), result: com.apple.commerce.server
debug 11:52:42.777496 -0700 storeuid Resource lookup at <private>
Request : appStore type: icns
Result : file:///System/Library/PrivateFrameworks/CommerceKit.framework/Resources/appStore.icns
debug 11:52:42.777471 -0700 storelegacy Bundle: <private>, key: The operation couldn\U2019t be completed. (%# error %ld.), value: The operation couldn\U2019t be completed. (%# error %ld.), table: Error, localizationName: (null), result: The operation couldn’t be completed. (%1$# error %2$ld.)
debug 11:52:42.777544 -0700 storeuid Bundle: <private>, key: OK, value: , table: MacAppStore, localizationName: (null), result: OK
default 11:52:42.777540 -0700 storelegacy StoreLegacy: Failed to renew receipt for application at path /Users/kenny/Library/Developer/Xcode/DerivedData/10bii_Financial_Calculator-edfoaceclymbdsazqdpinclhsejp/Build/Products/Debug/10bii Financial Calculator.app : 'The operation couldn’t be completed. (com.apple.commerce.server error 500317.)'
Found the answer here, replicated below in case the original goes away:
https://forums.developer.apple.com/thread/92419
The problem was that I was trying to login using my normal iTunes Account.
... the user must use a Sandbox Test User Apple ID, not their own Apple ID which was not clear to me at the time. Also, I have found that the user needs to log out of the Mac App Store with their own Apple ID in order to be able to even enter the Sandbox Test User Apple ID when requested.
However, the Sandbox Test User accounts are Country specific. So you need a Sandbox Test User per country. And right now, I have very similar error messages for a user in a new country. Am probably going to have to use another DTS request to figure it out.

HTTPS request restarts NodeMCU

NodeMCU Info:
> NodeMCU custom build by frightanic.com
> branch: dev
> SSL: true
> modules: crypto,file,gpio,http,net,node,sjson,tmr,uart,wifi,tls
> powered by Lua 5.1.4 on SDK 2.2.1
> commit: d5aca39f485bf46e6d77b7fb05eaf71b8ea51bee
> Build type: integer -- tried float, same error
> LFS : disabled
Build bin file
When I requested HTTPS request before adding the tls module it returned code -1 after I added tls module requesting HTTPS restarts the NodeMCU.
The code I used to send request.
print(node.heap()) -- 31824
http.request("https://www.google.com", "HEAD", "", "",
function(code, data)
if (code < 0) then
print("HTTP request failed")
else
print(code, data)
end
end)
and I tried the net module.
print(node.heap()) -- 31824
srv = tls.createConnection()
srv:on("receive", function(sck, c) print(c) end)
srv:on("connection", function(sck, c)
sck:send("GET / HTTP/1.1\r\nHost: google.com\r\nConnection: keep-alive\r\nAccept: */*\r\n\r\n")
end)
srv:connect(443,"google.com")
I got the same restart reason for both codes.
HTTP client: hostname=google.com
HTTP client: port=443
HTTP client: method=GET
HTTP client: path=/
HTTP client: DNS request
HTTP client: DNS pending
> HTTP client: DNS found google.com 172.217.18.46
client handshake start.
Fatal exception 0(IllegalInstructionCause):
epc1=0x4027ca20, epc2=0x00000000, epc3=0x00000000, excvaddr=0x402993e7, depc=0x00000000
þ
ets Jan 8 2013,rst cause:2, boot mode:(3,x) -- sometimes x is 0, 6 or 7
load 0x40100000, len 26104, room 16
tail 8
chksum 0xc0
load 0x3ffe8000, len 2332, room 0
tail 12
chksum 0x3c
ho 0 tail 12 room 4
load 0x3ffe891c, len 136, room 12
tail 12
chksum 0x56
csum 0x56
in the net moudle code the restart happens when srv:connect(443,"google.com") is called and shows one additional line RecvHold, By pespconn,find conn_msg fail
Assuming the date in your error is because of something you executed recently, I suggest that you set the time to a more recent one. If your time has drifted too much your OS cannot operate normally. Set time manuelly if NTP refuse your connection. How to set RTC rtctime module, but also look at sntp module or other relevant ones.
I overcome this problem by building the same SDK Firmware 2.2.1 with Docker with the same modules and same configuration, can't control cases and lines to debug in the Cloud Build version so cant know what exactly went wrong in the Cloud Build.
The Docker Firmware info
NodeMCU 2.2.0.0 built with Docker provided by frightanic.com
branch: master
commit: 4095c408e6a8cc9718cb06007b408d0aad15d9cd
SSL: true
Build type: integer
LFS: disabled
modules: crypto,file,gpio,http,net,node,sjson,tls,tmr,uart,wifi
build created on 2018-11-29 17:45
powered by Lua 5.1.4 on SDK 2.2.1(6ab97e9)

Redis Pub/Sub causes web socket connection to hang

I'm building a web application that connects to a server via web sockets. The server component is a small Ruby application based on sinatra, redis, and faye-websocket. The server is running on Phusion Passenger. A separate updater daemon is constantly pulling updates from various sources and publishes them to redis (using the redis gem and Redis::publish).
In order to push the updates to the clients I tried the following in my Sinatra app:
get '/' do
if Faye::WebSocket.websocket?(request.env)
store = Redis.new
ws = Faye::WebSocket.new(request.env)
ws.on(:open) do |event|
store.incr('connection_count')
puts 'Client connected (connection count: %s)' % store.get('connection_count')
end
ws.on(:close) do |event|
store.decr('connection_count')
puts 'Client disconnected (connection count: %s)' % store.get('connection_count')
end
ws.rack_response
store.subscribe(:updates) do |on|
on.message do |ch, payload|
puts "Got update"
ws.send(payload) if payload
end
end
end
end
This works only partially. A client can connect successfully and also receives updates but the store.incr and store.decr calls don't work. Also, the connections don't seem to be closed correctly—when I fire up multiple clients, I noticed that the connections pile up and the Passenger server stops working eventually.
Log output:
devserver_1 | App 614 stdout: Got update
devserver_1 | App 614 stdout: Got update
devserver_1 | App 614 stdout: Got update
When I comment out the following block, keeping track of the connections suddenly works:
store.subscribe(:updates) do |on|
on.message do |ch, payload|
puts "Got update"
ws.send(payload) if payload
end
end
Log output:
devserver_1 | App 1028 stdout: Client connected (connection count: 1)
devserver_1 | App 1039 stdout: Client connected (connection count: 2)
devserver_1 | App 1039 stdout: Client disconnected (connection count: 1)
devserver_1 | App 1028 stdout: Client disconnected (connection count: 0)
So using Redis::subscribe seems to somehow interfere with the web socket connection.
How can I solve this?
Phusion Passenger version 4.0.58
ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-linux-gnu]
sinatra (1.4.6)
faye-websocket (0.9.2)
I think the problem here is that Faye uses EventMachine which means there's a reactor on your thread that is handling events, and calling your callbacks ws.on(:open) and ws.on(:close).
Now when you hit
store.subscribe(:updates) do |on|
on.message do |ch, payload|
puts "Got update"
ws.send(payload) if payload
end
end
This is a blocking operation - it entirely blocks the current thread. If your current thread is blocked, the reactor can't listen for events and then call your callbacks.
One solution to this is to run your store.subscribe on a different thread so it doesn't matter if it blocks that thread.
But I think a better solution is to use a non-blocking version of the Redis library:
From the documentation:
redis = EM::Hiredis.connect
pubsub = redis.pubsub
pubsub.subscribe(:updates).callback do
puts "Got update"
ws.send(payload) if payload
end
Both of these (Redis + Faye) should register with the EventMachine reactor loop, so that it dispatches events to both.

kannel 1.5 addons sqlbox on mac connect to Postgresql 9.3.5 with "Segmentation fault: 11" error

I am trying to build my own sms gateway by compile Kannel 1.5.0 on my mac 10.10. I installed all depends that Kannel required. I configured Kannel to work with Postgresql 9.3.5. BearerBox and smsBox are in good work order. I can send/receive sms from my HUAWEI E3131 3G WCDMA modem.
After I got sms gateway worked, I go next step by trying compile Kannel addons sqlbox to support sms sql storage and insert sms to database to trigger sms services. Following steps used:
use bootstrap to configure environments
.bootstrap
configure sqlbox with Kannel support
./configure --with-kannel-dir=/usr/local/kannel --disable-docs --enable-drafts
make to compile
make
make install to install sqlbox to proper location
make bindir=/usr/local/kannel install
configure sqlbox by edit sqlbox.conf file like:
group = pgsql-connection
id = pgsqlbox-db
host = "10.0.1.100"
username = any
password = any
database = dlr
max-connections = 1
port=5433
group = sqlbox
id = pgsqlbox-db
smsbox-id = sqlbox
global-sender = ""
bearerbox-host = localhost
bearerbox-port = 13001
smsbox-port = 13002
smsbox-port-ssl = false
sql-log-table = sent_sms
sql-insert-table = send_sms
log-file = "/usr/local/var/log/kannel/kannel-sqlbox.log"
log-level = 0
configure postgresql to add table send_sms and sent_sms and test by using PSQL client to test, data base is working order
start services from terminal
./bearerbox -v 1 /usr/local/kannel/conf/smskannel.conf
./smsbox -v 1 /usr/local/kannel/conf/smskannel.conf
bearerbox and smsbox is in working order.
start sqlbox service
./sqlbox -v 1 /usr/local/kannel/conf/sqlbox.conf
error message was given:
2015-05-01 10:06:01 [11407] [0] INFO: Debug_lvl = 1, log_file = <none>, log_lvl = 0
2015-05-01 10:06:01 [11407] [0] INFO: Starting to log to file /usr/local/var/log/kannel/kannel-sqlbox.log level 0
2015-05-01 10:06:01 [11407] [0] INFO: Added logfile `/usr/local/var/log/kannel/kannel-sqlbox.log' with level `0'.
2015-05-01 10:06:01 [11407] [0] INFO: PGSQL: Connected to server at '10.0.1.100'.
Segmentation fault: 11
in my understanding, Segmentation fault: 11 was thrown out by Postgresql server. So I configured Postgresql server to get more detail level debug information. Seems Postgresql is working fine.
Does anyone have a better idea about it? I totally lost my direction. Any advice are welcome.
Kannel is probably too old to care out the work in new system.
I changed it to Gammu 1.36.0,
make sure cmake installed.
autoconf and other required depends installed.
download Gammu 1.36.0
compile and install
.configure
make
sudo make install
configure Gammu by using [gammu] and [smsd] sections
enable log file in system
use newest db schema to create tables in database
start service by
gammu-smsd
check log make sure it works
10.send test message by
gammu-smsd-inject
11.receive sms
12.check database tables inbox and sentitems
13.done

Gitlab email configuration issue

I'm using Gitlab 7.1 CE on debian.
I set up smtp in /etc/gitlab/gitlab.rb
unicorn['port'] = 8081
external_url 'http://server_hostname.com:8081'
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.smtp_host.com"
gitlab_rails['smtp_port'] = 587
gitlab_rails['smtp_user_name'] = "gitlab#smtp_host.com"
gitlab_rails['smtp_password'] = "secret"
gitlab_rails['smtp_domain'] = "smtp_host.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = false
I'm getting error
WARN: 553 5.7.1 : Sender address rejected: not owned by user gitlab#smtp_host.com
I don't know why sender email is set to gitlab#server_hostname.com instead of gitlab#smtp_host.com and no idea how to change it.
From email can be set in gitlab.rb:
gitlab_rails['gitlab_email_from'] = "gitlab#smtp_host.com"
Do you use Exim? https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/install/installation.md#1-packages-dependencies Note: In order to receive mail notifications, make sure to install a mail server. By default, Debian is shipped with exim4 whereas Ubuntu does not ship with one. The recommended mail server is postfix and you can install it with:

Resources