Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
dev:gsoc_2008_msg_sms_login [2008/06/07 00:08] ajay_kumar created |
dev:gsoc_2008_msg_sms_login [2009/07/06 20:36] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | SMS Login Architecture | + | ====== |
- | Current login architecture takes into consideration only Sahana Core users, i.e. users who are registered as users in the Sahana system and their record exists in the DB. | + | |
+ | **Author:** Ajay Kumar [ ajuonline at gmail dot com]\\ | ||
+ | **Created: | ||
+ | **Link Back:** [[dev: | ||
+ | |||
+ | Current login architecture takes into consideration only Sahana Core users, i.e. users who are registered as users in the Sahana system and their record exists in the DB.\\ | ||
Public usage for potential news alert broadcasts, or public information IVR via SMS can be implemented following the similar approach. The module is being written keeping this in mind. | Public usage for potential news alert broadcasts, or public information IVR via SMS can be implemented following the similar approach. The module is being written keeping this in mind. | ||
- | Files to be added: | ||
- | 1. / | ||
- | 2. / | ||
- | 3. lib_sms_session.inc | ||
- | 4. lib_sms_errors.inc | ||
- | 5. lib_sms_process.inc | ||
- | 6. lib_sms_menu.inc | ||
- | Changes in SQL Schema: | ||
- | 1. Add 1 field in table " | ||
- | 2. Add 2 field in table " | ||
- | Pseudocode: | ||
- | /** | ||
- | * 1. Take SMS Input from SMS Plugin' | ||
- | * 2. We get the following values in the array $received_message[]: | ||
- | | ||
- | | ||
- | | ||
- | * 3. Check " | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | in / | ||
- | | ||
- | Sahana SMS Server. Kindly login or contact Sahana Administrator" | ||
- | Parser Function: | ||
- | function _shn_msg_parse_short_message($message){ | ||
- | $parsed_message=array(); | ||
- | $parsed_message = explode(" | ||
- | return $parsed_message; | ||
- | } | ||
- | Small Prototype in PHP Demonstrating the Login via SMS to Sahana DB | ||
- | <? | ||
- | $message=$_GET[" | ||
+ | |||
+ | ===== Files to be added: ===== | ||
+ | |||
+ | - **/ | ||
+ | - __Purpose of File:__ Main include file for the SMS System calls other files and performs functions | ||
+ | - **/ | ||
+ | - __Purpose of File:__ Handles all communication as a result of SMS input. Parse SMS, Check keywords, Trigger corresponding functions as per SMS input | ||
+ | - **/ | ||
+ | - __Purpose of File:__ Provide SMS Based Session management based on caller ID/mobile number | ||
+ | - **/ | ||
+ | - {{dev: | ||
+ | - __Purpose of File:__ Provide SMS Based Authorisation as per Sahana Framework draws from lib_auth.inc | ||
+ | - **/ | ||
+ | - __Purpose of File:__ Provide SMS Based Authentication and assigns role to User as per Sahana Framework draws from lib_acl.inc | ||
+ | - **/ | ||
+ | - __Purpose of File:__ Errors sent to users as output via SMS on receiving SMS input. | ||
+ | - **/ | ||
+ | - __Purpose of File:__ SMS Menu sent to users | ||
+ | |||
+ | |||
+ | |||
+ | ===== Changes in SQL Schema: ===== | ||
+ | |||
+ | - Add 1 field in table " | ||
+ | - Add 1 field in table " | ||
+ | |||
+ | ** This needs to be done in one of the messaging tables. Still to figure out where and how exactly. | ||
+ | |||
+ | |||
+ | ===== Pseudocode: ===== | ||
+ | |||
+ | |||
+ | - Take SMS Input from SMS Plugin' | ||
+ | - We get the following values in the array $received_message[]: | ||
+ | - [' | ||
+ | - [' | ||
+ | - [' | ||
+ | - Check " | ||
+ | - if " | ||
+ | - If " | ||
+ | - If " | ||
+ | - If " | ||
+ | - if value of " | ||
+ | - retrieve " | ||
+ | - check " | ||
+ | - If " | ||
+ | - return login result as 1 | ||
+ | - proceed to message parsing & keyword check. | ||
+ | - else if [sms_auth_status!=active] | ||
+ | - send_sms_error(" | ||
+ | - Code Terminates | ||
+ | - else if value of " | ||
+ | - This part checks for keyword "login username password" | ||
+ | - Parse the message by $parsed_message = _shn_msg_parse_short_message($message); | ||
+ | - Check if $parsed_message[0] == " | ||
+ | - Else if $parsed_message[0] != " | ||
+ | |||
+ | ==== Parser Function: ==== | ||
+ | |||
+ | <code php> | ||
function _shn_msg_parse_short_message($message){ | function _shn_msg_parse_short_message($message){ | ||
- | | + | $parsed_message=array(); |
- | $parsed_message = explode(" | + | |
- | return $parsed_message; | + | |
- | } | + | } |
+ | </ | ||
- | $output | + | ==== Small Prototype in PHP Demonstrating the Login via SMS to Sahana DB ==== |
- | $count | + | |
- | echo " | + | |
- | print_r($output); | + | |
- | echo "< | + | |
- | if($output[0]==' | + | |
- | { | + | |
- | $user = $output[1]; | + | |
- | echo "User name: " | + | |
- | echo "< | + | |
- | for($i=2; $i< | + | |
- | $password .= $output[$i]; | + | |
- | if($i!=$count-1) $password .= " "; // to avoid additional space | + | |
- | } | + | |
- | } | + | <code php> |
- | echo " | + | <? |
- | $pass = $password; | + | |
- | //Sahana Login replace DB functions from sysconf.inc and / | + | |
- | mysql_connect(" | + | |
- | mysql_select_db("sahana") or die(mysql_error()); | + | $parsed_message = explode(" ", $message); |
+ | | ||
+ | } | ||
- | //Sahana Password building from lib_auth.inc | + | $output |
- | $q = " | + | $count |
- | WHERE user_name | + | echo " |
- | // AND password | + | print_r($output); |
- | $res=mysql_query($q) or die(mysql_error()); | + | echo "< |
- | if(mysql_num_rows($res)==0){ | + | if($output[0]==' |
- | echo "User name does not exists"; | + | { |
- | break; | + | $user = $output[1]; |
- | }else{ | + | echo "User name: ".$user; |
- | while($result | + | echo "< |
- | $salt=$result[' | + | for($i=2; $i< |
- | } | + | |
- | echo "< | + | if($i!=$count-1) $password |
- | } | + | |
- | $pwd=substr($pass, | + | } |
+ | echo " | ||
+ | $pass = $password; | ||
- | // Create a digest of the password collected | + | //Sahana Login replace DB functions |
- | $password_digest = md5(trim($pwd)); | + | mysql_connect(" |
- | echo " | + | mysql_select_db(" |
- | // Formulate the SQL to find the user | + | |
- | $q = " | + | |
- | WHERE user_name = ' | + | |
- | AND password = ' | + | |
- | $res=mysql_query($q) or die(mysql_error()); | + | |
- | if(mysql_num_rows($res)==0){ | + | |
- | echo "< | + | |
- | }else{ | + | |
- | echo "< | + | |
- | } | + | |
+ | // | ||
+ | $q = " | ||
+ | WHERE user_name = ' | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
+ | | ||
+ | } | ||
+ | |||
+ | | ||
+ | |||
+ | // Create a digest of the password collected from the challenge | ||
+ | | ||
+ | echo " | ||
+ | // Formulate the SQL to find the user | ||
+ | $q = " | ||
+ | WHERE user_name = ' | ||
+ | AND password = ' | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
?> | ?> | ||
+ | </ | ||
+ | |||
+ | * --- // |