Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * R O U T E R S C R I P T
- * messages are ideally submitted to this smsc and are
- * consequently routed via configured routing rules
- * contained in routing.ini
- *
- * NOTE: Country codes represented as detailed in ISO 8601
- */
- require_once('/var/www/sms.solami.co.ke/Utilities/Url-lib.php');
- /*
- * Some rudimentary configs
- */
- $msisdn_regexes = './routing_configs/country_msisdn_regexes.ini';
- $routing_path = './routing_configs/routing.ini';
- $kannel_configs = './routing_configs/kannel_configs.ini';
- /*
- * Main
- */
- print submit_message_to_kannel();
- /*
- * Fetch routing configs
- */
- function get_routing_configs ($country="ke") {
- global $routing_path;
- $routes = parse_ini_file($routing_path, true);
- print "SPECIFIC => [" . $country . "] " . print_r($routes[$country], true);
- return $routes["$country"];
- }
- /*
- * Get msisdn filter regex
- */
- function get_sanitize_regex ($key) {
- global $msisdn_regexes;
- $regexes = parse_ini_file($msisdn_regexes);
- return $regexes[$key];
- }
- /*
- * Clean up the mobile number
- */
- function sanitize_msisdn ($number) {
- $sanitize_regex = get_sanitize_regex('ke');
- return preg_replace($sanitize_regex,"254$1", $number);
- }
- /*
- * Pick a route that matches repeatedly and return all
- * routes that match in an array
- */
- function select_route ($msisdn, $country=null) {
- $hits = [];
- $msisdn = sanitize_msisdn($msisdn);
- $routes = get_routing_configs($country);
- print "ROUTES => " . print_r($routes, true);
- array_walk($routes,
- function ($route, $regex, $number)
- use (&$hits)
- {
- if (preg_match(
- '/^' . $regex . '/',
- $number
- )) {
- $hits[] = $route;
- }
- },
- $msisdn
- );
- /* SET ROUTE */
- if (count($hits) == 0)
- $route = 'INFOBIP';
- else
- $route = $hits[0];
- return $route;
- }
- /*
- * http://localhost/solami/api/route_msg.php?dest=%p&message=%a&source=%P&udh=%u&msgID=%I&box=%n&coding=%C&user=%n&METADATA=%D
- * ----------------------------------------------------------------------------------------------------------------------------------
- * from=22677
- * to=254708146140
- * text=Hi+click+http%3A%2F%2Fmuziq.co.ke%2Fb%2Fcca9f0+to+get+Handu+Hau+by+Charles+Njoroge.+Bonyeza+*699*20%23+For+Your+Slice+of+Gospel
- * priority=0
- * smsc=safaricom
- * username=safaricom
- * password=safaricom-pass
- * dlr-mask=
- * dlr-url=http%3A%2F%2F172.31.186.204%3A9000%2Fapi%2Fdlr%3Ftype%3D%25d%26time%3D%25t%26usr%3D%25n%26message%3D%25b%26kannel_id%3D%25F%26MSISDN%3D%25p%26dlrvalue%3D%25A%26message_id%3D176127627
- * http://ke-pr-gw2:13013/cgi-bin/sendsms
- * ----------------------------------------------------------------------------------------------------------------------------------
- */
- /*
- * Upack data from the get params into data
- * then return that data array
- */
- function get_data () {
- global $kannel_configs;
- $gateway_configs = parse_ini_file($kannel_configs);
- $data = [
- 'source' => $_GET['source'],
- 'msisdn' => $_GET['dest'],
- 'message' => urlencode($_GET['message']),
- 'smsc' => select_route($_GET['dest']),
- 'metadata' => $_GET['METADATA'],
- ];
- $data = array_merge($gateway_configs, $data);
- print print_r($data, true);
- return $data;
- }
- /*
- * Construct kannel URL
- */
- function construct_kannel_link ( $data ) {
- /* Base URL */
- $format_string .= "http://localhost:%d/cgi-bin/sendsms?";
- /* Auth */
- $format_string .= "username=%s&password=%s&";
- /* Message Params */
- $format_string .= "from=%s&to=%d&text=%s&";
- /* ! ! R O U T I N G ! ! */
- $format_string .= "smsc=%s&";
- /* Metadata */
- $format_string .= "meta-data=%s";
- return vsprintf($format_string, $data);
- }
- /*
- * Call kannel URL
- */
- function submit_message_to_kannel () {
- $url = construct_kannel_link(get_data());
- $link = new Url($url);
- $link->callUrl();
- return $link;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement