From 6e8fcc4d11d9e51dbe9c1cba80cbebf858794034 Mon Sep 17 00:00:00 2001 From: Mbaush Date: Thu, 27 Jun 2013 16:46:59 +0300 Subject: [PATCH 1/2] first commit --- .../domain/frontlinesms2/Fconnection.groovy | 3 +- .../frontlinesms2/ShujaaSmsFconnection.groovy | 63 +++++++++++++++++ .../grails-app/i18n/messages.properties | 11 +++ .../migrations/changelog-2.0.groovy | 21 ++++++ .../shujaasms/ShujaaSmsPostProcessor.groovy | 70 +++++++++++++++++++ .../shujaasms/ShujaaSmsPreProcessor.groovy | 40 +++++++++++ 6 files changed, 207 insertions(+), 1 deletion(-) create mode 100644 plugins/frontlinesms-core/grails-app/domain/frontlinesms2/ShujaaSmsFconnection.groovy create mode 100644 plugins/frontlinesms-core/src/groovy/frontlinesms2/camel/shujaasms/ShujaaSmsPostProcessor.groovy create mode 100644 plugins/frontlinesms-core/src/groovy/frontlinesms2/camel/shujaasms/ShujaaSmsPreProcessor.groovy diff --git a/plugins/frontlinesms-core/grails-app/domain/frontlinesms2/Fconnection.groovy b/plugins/frontlinesms-core/grails-app/domain/frontlinesms2/Fconnection.groovy index 03379249a..3ca8e60ba 100644 --- a/plugins/frontlinesms-core/grails-app/domain/frontlinesms2/Fconnection.groovy +++ b/plugins/frontlinesms-core/grails-app/domain/frontlinesms2/Fconnection.groovy @@ -21,7 +21,8 @@ class Fconnection { IntelliSmsFconnection, NexmoFconnection, SmssyncFconnection, - SmppFconnection] + SmppFconnection, + ShujaaSmsFconnection] static getNonnullableConfigFields = { clazz -> def fields = clazz.configFields diff --git a/plugins/frontlinesms-core/grails-app/domain/frontlinesms2/ShujaaSmsFconnection.groovy b/plugins/frontlinesms-core/grails-app/domain/frontlinesms2/ShujaaSmsFconnection.groovy new file mode 100644 index 000000000..df2433c60 --- /dev/null +++ b/plugins/frontlinesms-core/grails-app/domain/frontlinesms2/ShujaaSmsFconnection.groovy @@ -0,0 +1,63 @@ +package frontlinesms2 + +import frontlinesms2.camel.shujaasms.* + +import org.apache.camel.Exchange +import org.apache.camel.builder.RouteBuilder +import org.apache.camel.model.RouteDefinition +import frontlinesms2.camel.exception.* + +class ShujaaSmsFconnection extends Fconnection { + private static final String SHUJAASMS_URL = 'http://sms.shujaa.mobi/sendsms?' + static final configFields = [name:null, username:null, password:null, account:null, source:null, network:null] + static defaultValues = [] + static String getShortName() { 'shujaasms' } + + String username + String password + String account + String source + String network + + static constraints = { + username blank:false + password blank:false + account blank:false + source blank:false + network blank:false + } + + static passwords = ['password'] + + + static mapping = { + password column: 'shujaa_password' + } + + List getRouteDefinitions() { + return new RouteBuilder() { + @Override void configure() {} + List getRouteDefinitions() { + return [from("seda:out-${ShujaaSmsFconnection.this.id}") + .onException(AuthenticationException, InvalidApiIdException, InsufficientCreditException) + .handled(true) + .beanRef('fconnectionService', 'handleDisconnection') + .end() + .setHeader(Fconnection.HEADER_FCONNECTION_ID, simple(ShujaaSmsFconnection.this.id.toString())) + .process(new ShujaaSmsPreProcessor()) + .setHeader(Exchange.HTTP_QUERY, + simple( 'username=${header.shujaasms.username}&' + + 'password=${header.shujaasms.password}&' + + 'account=${header.shujaasms.account}&' + + 'source=${header.shujaasms.source}&' + + 'network=${header.shujaasms.network}&' + + 'destination=${header.shujaasms.dst}&' + + 'message=${body}' + )) + .to(SHUJAASMS_URL) + .process(new ShujaaSmsPostProcessor()) + .routeId("out-internet-${ShujaaSmsFconnection.this.id}")] + } + }.routeDefinitions + } +} \ No newline at end of file diff --git a/plugins/frontlinesms-core/grails-app/i18n/messages.properties b/plugins/frontlinesms-core/grails-app/i18n/messages.properties index 8e7f89985..59330ec4f 100644 --- a/plugins/frontlinesms-core/grails-app/i18n/messages.properties +++ b/plugins/frontlinesms-core/grails-app/i18n/messages.properties @@ -1152,3 +1152,14 @@ routing.notification.no-available-route=Outgoing message(s) not sent due to your recipientSelector.keepTyping=Keep typing... recipientSelector.searching=Searching... + +# ShujaaSMS Fconnection +shujaasms.label=Shujaa SMS Account +shujaasms.type.label=Type +shujaasms.name.label=Name +shujaasms.username.label=Username +shujaasms.password.label=Password +shujaasms.account.label=Account +shujaasms.source.label=Source +shujaasms.network.label=Network +shujaasms.description=Send and receive messages through a Shujaa SMS Gateway account \ No newline at end of file diff --git a/plugins/frontlinesms-core/grails-app/migrations/changelog-2.0.groovy b/plugins/frontlinesms-core/grails-app/migrations/changelog-2.0.groovy index 9ef54282d..4f2669779 100644 --- a/plugins/frontlinesms-core/grails-app/migrations/changelog-2.0.groovy +++ b/plugins/frontlinesms-core/grails-app/migrations/changelog-2.0.groovy @@ -317,4 +317,25 @@ databaseChangeLog = { } } } + + changeSet(author: "geoffrey (generated)", id: "11355230052153-40") { + createTable(tableName: "shujaa_sms_fconnection") { + column(autoIncrement: "true", name: "id", type: "bigint") { + constraints(nullable: "false", primaryKey: "true", primaryKeyName: "shujaa_sms_fconnectionPK") + } + + column(name: "username", type: "varchar(255)") + + column(name: "shujaa_password", type: "varchar(255)") + + column(name: "account", type: "varchar(255)") + + column(name: "source", type: "varchar(255)") + + column(name: "network", type: "varchar(255)") + + + } + } + } diff --git a/plugins/frontlinesms-core/src/groovy/frontlinesms2/camel/shujaasms/ShujaaSmsPostProcessor.groovy b/plugins/frontlinesms-core/src/groovy/frontlinesms2/camel/shujaasms/ShujaaSmsPostProcessor.groovy new file mode 100644 index 000000000..430bdba8a --- /dev/null +++ b/plugins/frontlinesms-core/src/groovy/frontlinesms2/camel/shujaasms/ShujaaSmsPostProcessor.groovy @@ -0,0 +1,70 @@ +package frontlinesms2.camel.shujaasms + +import frontlinesms2.* +import frontlinesms2.camel.exception.* +import org.apache.camel.* + +class ShujaaSmsPostProcessor implements Processor { + public void process(Exchange exchange) throws Exception { + def log = { println "ShujaaSmsPostProcessor.process() : $it" } + log 'ENTRY' + log "in.body:" + exchange.in.body + byte[] bytes = exchange.in.getBody(byte[].class); + log "in.body as byte[]:" + bytes + String text = new String(bytes, "UTF-8").trim(); + log "in.body as byte[] as String:" + text + log "in.body got as a string" + exchange.in.getBody(String.class) + if(text ==~ "ID:.*"){ + log "message sent successfully" + }else { + if(text.endsWith(":0")){ + log "The message has been accepted by the gateway for delivery." + }else if(text.endsWith(":1")){ + log "The delivery to the destination address is successful." + }else if(text.endsWith(":2")){ + log "The delivery to the destination address has not been successful." + throw new AuthenticationException("Shujaa SMS Gateway : The delivery to the destination address has not been successful.") + }else if(text.endsWith(":4")){ + log "The message has been queued for delivery." + }else if(text.endsWith(":8")){ + log "The message has been submitted to the operator SMS gateway." + }else if(text.endsWith(":16")){ + log "The message has been rejected by the operator SMS gateway." + throw new AuthenticationException("Shujaa SMS Gateway : The message has been rejected by the operator SMS gateway.") + }else if(text.endsWith(":32")){ + log "Intermediate notifications by the operator SMS gateway." + }else if(text.endsWith(":200")){ + log "The username or email used to authenticate is not registered with the gateway." + throw new AuthenticationException("Shujaa SMS Gateway : The username or email used to authenticate is not registered with the gateway.") + }else if(text.endsWith(":201")){ + log "The password supplied does not match the username." + throw new AuthenticationException("Shujaa SMS Gateway : The password supplied does not match the username.") + }else if(text.endsWith(":202")){ + log "The account from which the send attempt has been made is not active, it may be in a suspended or deleted state." + throw new AuthenticationException("Shujaa SMS Gateway : The account from which the send attempt has been made is not active, it may be in a suspended or deleted state.") + }else if(text.endsWith(":203")){ + log "The destination address is not a valid MSISDN or is a destination that is supported by the gateway." + throw new AuthenticationException("Shujaa SMS Gateway : The destination address is not a valid MSISDN or is a destination that is supported by the gateway.") + }else if(text.endsWith(":204")){ + log "The source address is not allowed to be used by the particular account." + throw new AuthenticationException("Shujaa SMS Gateway : The source address is not allowed to be used by the particular account.") + }else if(text.endsWith(":205")){ + log "Not enough or invalid parameters have been provided when submitting a request to send a message." + throw new AuthenticationException("Shujaa SMS Gateway : Not enough or invalid parameters have been provided when submitting a request to send a message.") + }else if(text.endsWith(":206")){ + log "An internal problem with the gateway is preventing the delivery of the message." + throw new AuthenticationException("Shujaa SMS Gateway : An internal problem with the gateway is preventing the delivery of the message.") + }else if(text.endsWith(":207")){ + log "The user has exhausted the credits allowed for bulk SMS." + throw new AuthenticationException("Shujaa SMS Gateway : The user has exhausted the credits allowed for bulk SMS.") + }else if(text.endsWith(":208")){ + log "The message format is invalid, for example there is no content in the message." + throw new AuthenticationException("Shujaa SMS Gateway : The message format is invalid, for example there is no content in the message.") + }else if(text.endsWith(":209")){ + log "The phone number prefix provided is not in the range handled by this gateway." + throw new AuthenticationException("Shujaa SMS Gateway : The phone number prefix provided is not in the range handled by this gateway.") + } + } + log 'EXIT' + } +} \ No newline at end of file diff --git a/plugins/frontlinesms-core/src/groovy/frontlinesms2/camel/shujaasms/ShujaaSmsPreProcessor.groovy b/plugins/frontlinesms-core/src/groovy/frontlinesms2/camel/shujaasms/ShujaaSmsPreProcessor.groovy new file mode 100644 index 000000000..f4fafbbe8 --- /dev/null +++ b/plugins/frontlinesms-core/src/groovy/frontlinesms2/camel/shujaasms/ShujaaSmsPreProcessor.groovy @@ -0,0 +1,40 @@ +package frontlinesms2.camel.shujaasms + +import frontlinesms2.* +import org.apache.camel.* + +class ShujaaSmsPreProcessor implements Processor { + public void process(Exchange x) throws Exception { + def log = { println "ShujaaSmsPreProcessor.process() : $it" } + log 'ENTRY' + + // URL-encode body + def d = x.in.body + x.out.headers['frontlinesms.dispatch.id'] = d.id + x.out.body = urlEncode(d.text) + + def destination = d.dst + if(destination && destination.charAt(0)=='+') destination = destination.substring(1) + set x, 'dst', destination + + // Add auth details to header + log "Calculating connection ID..." + def connectionId = x.fconnectionId + log "connectionId=$connectionId" + def connection = ShujaaSmsFconnection.get(connectionId) + log "connection=$connection" + ['username', 'password', 'account', 'source' , 'network'].each { set x, it, connection."$it"} + + log 'EXIT' + } + + private def set(Exchange x, String header, String value) { + println "PreProcessor.set() : header=$header; value=$value" + x.out.headers["shujaasms.$header"] = urlEncode(value) + } + + private String urlEncode(String s) throws UnsupportedEncodingException { + println "PreProcessor.urlEncode : s=$s -> ${URLEncoder.encode(s, "UTF-8")}" + return URLEncoder.encode(s, "UTF-8"); + } +} From b30136173f3b096a71881425de41ec5ea0008323 Mon Sep 17 00:00:00 2001 From: Mbaush Date: Thu, 27 Jun 2013 16:56:43 +0300 Subject: [PATCH 2/2] first commit --- .../grails-app/i18n/messages_sw.properties | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/plugins/frontlinesms-core/grails-app/i18n/messages_sw.properties b/plugins/frontlinesms-core/grails-app/i18n/messages_sw.properties index 34c8ac8ca..cfc4c99a2 100644 --- a/plugins/frontlinesms-core/grails-app/i18n/messages_sw.properties +++ b/plugins/frontlinesms-core/grails-app/i18n/messages_sw.properties @@ -1130,3 +1130,14 @@ smppfconnection.fromNumber.label=From Number smppfconnection.description=Tuma na pata risala kwenye SMSC. smppfconnection.global.info=Utahitaji akaunti na mtandao yako. smppfconnection.send.validator.invalid = Huwezi tengeneza muunganisho isiyo tuma wala pata risala. + +# ShujaaSMS Fconnection +shujaasms.label=Akaunti ya Shujaa SMS +shujaasms.type.label=Aina +shujaasms.name.label=Jina +shujaasms.username.label=Jina la mtumuzi +shujaasms.password.label=Nywila +shujaasms.account.label=Akaunti +shujaasms.source.label=Jina au Nambari Litokapo +shujaasms.network.label=Mtandao wa kuhamisha data +shujaasms.description=Tuma na upokee risala kwa kutumia akaunti ya Shujaa SMS \ No newline at end of file