From 31c2cb7c8fbea1ad4cc6753a4343dbfc65552fa5 Mon Sep 17 00:00:00 2001 From: Denver Gingerich Date: Mon, 12 Feb 2018 21:30:48 +0000 Subject: [PATCH] record total SMS/MMS sent by each num in TAI days --- README.creole | 2 ++ sgx-catapult.rb | 24 +++++++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/README.creole b/README.creole index 1bf7e1e6a7b39a43c94e810d44f8a1f552d078ae..a4e3cc0b2f2329e41323d3116ad38af9cf325ef1 100644 --- a/README.creole +++ b/README.creole @@ -3,3 +3,5 @@ An XMPP to SMS gateway for Catapult (also known as Bandwidth AP), using XEP-0100. The "SGX" stands for "Soprani.ca Gateway to XMPP", as this is associated with the Soprani.ca project. Note that the canonical location for this repository is https://gitlab.com/ossguy/sgx-catapult . Please use that location for all pull requests, issue reports, etc. Other locations are likely out-of-date. + +This program expects a binary named "tai" to be in its working directory, which should be a compiled version of https://ossguy.com/tai.c for the platform it is running on. diff --git a/sgx-catapult.rb b/sgx-catapult.rb index d36bbc79fae2a3a9aeed11b05d464cb980df39ac..78d72df35a82ae2c4d80d024ca42c8ba0f508325 100755 --- a/sgx-catapult.rb +++ b/sgx-catapult.rb @@ -1,6 +1,6 @@ #!/usr/bin/env ruby # -# Copyright (C) 2017 Denver Gingerich +# Copyright (C) 2017-2018 Denver Gingerich # Copyright (C) 2017 Stephen Paul Weber # # This file is part of sgx-catapult. @@ -263,6 +263,20 @@ module SGXcatapult [:cancel, 'internal-server-error'] ) } + + t = Time.now + tai_timestamp = `./tai`.strip + tai_yyyymmdd = Time.at(tai_timestamp.to_i).strftime('%Y%m%d') + puts "SMU %d.%09d, %s: msg for %s sent on %s - incrementing\n" % + [t.to_i, t.nsec, tai_timestamp, usern, tai_yyyymmdd] + + REDIS.incr('usage_messages-' + tai_yyyymmdd + '-' + + usern).then { |total| + + t = Time.now + puts "SMU %d.%09d: total msgs for %s-%s now at %s\n" % + [t.to_i, t.nsec, tai_yyyymmdd, usern, total] + } end def self.validate_num(num) @@ -766,8 +780,8 @@ module SGXcatapult "API Secret is password, Phone Number is phone"\ ".\n\nThe source code for this gateway is at "\ "https://gitlab.com/ossguy/sgx-catapult ."\ - "\nCopyright (C) 2017 Denver Gingerich and "\ - "others, licensed under AGPLv3+." + "\nCopyright (C) 2017-2018 Denver Gingerich "\ + "and others, licensed under AGPLv3+." n2 = Nokogiri::XML::Node.new 'nick', msg.document n3 = Nokogiri::XML::Node.new 'username', msg.document n4 = Nokogiri::XML::Node.new 'password', msg.document @@ -805,8 +819,8 @@ module SGXcatapult "account you want to use (ie. '+12345678901')"\ ".\n\nThe source code for this gateway is at "\ "https://gitlab.com/ossguy/sgx-catapult ."\ - "\nCopyright (C) 2017 Denver Gingerich and "\ - "others, licensed under AGPLv3+." + "\nCopyright (C) 2017-2018 Denver Gingerich "\ + "and others, licensed under AGPLv3+." msg.add_child(x) orig.add_child(msg)