Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send sms #74

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions main/web/templates/web/content/send_sms.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% extends "web/base.html" %}
{% load static i18n %}
{% block title %}{% trans "Send SMS" %}{% endblock title %}
{% block extracss %}{% endblock extracss %}
{% block content %}
<h1 class="h3 mb-2 text-gray-800">{% trans "Send SMS" %}</h1>
<form action="{% url 'web:send_sms_view_manage' %}" method="post">
{% csrf_token %}
<label for="msisdn">msisdn: </label>
<input id="msisdn" type="text" name="msisdn" value="{{ msisdn }}">
<label for="sms">sms: </label>
<input id="sms" type="text" name="sms" value="{{ sms }}">
<input type="submit" value="OK">
</form>
{% endblock content %}
{% block extrajs %}
<script>
var main_trans = {};
</script>
<script src="{% static 'web/content/httpccm.js' %}"></script>
{% endblock extrajs %}
5 changes: 5 additions & 0 deletions main/web/templates/web/includes/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
<li class="nav-item morouter-menu">
<a class="nav-link" href="{% url 'web:morouter_view' %}"><i class="fas fa-fw fa-cloud-upload-alt"></i><span>{% trans 'MO Router' %}</span></a>
</li>

<li class="nav-item send-sms-menu">
<a class="nav-link" href="{% url 'web:send_sms_view' %}"><i class="fas fa-fw fa-cloud-upload-alt"></i><span>{% trans 'Send SMS' %}</span></a>
</li>

{% if SETTINGS.SUBMIT_LOG %}
<hr class="sidebar-divider d-none d-md-block">

Expand Down
2 changes: 2 additions & 0 deletions main/web/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@
path('users/manage/', users_view_manage, name='users_view_manage'),
path('users/', users_view, name='users_view'),
path('manage/', global_manage, name='global_manage'),
path('send_sms/', send_sms_view, name='send_sms_view'),
path('send_sms/manage/', send_sms_view_manage, name='send_sms_view_manage'),
path('', dashboard_view, name='dashboard_view'),
]
2 changes: 2 additions & 0 deletions main/web/views/content/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
from .smppccm import smppccm_view, smppccm_view_manage
from .submit_logs import submit_logs_view, submit_logs_view_manage
from .users import users_view, users_view_manage
from .sms import send_sms_view, send_sms_view_manage

86 changes: 86 additions & 0 deletions main/web/views/content/sms copy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
from django.utils.translation import gettext_lazy as _
from django.shortcuts import render, redirect, get_object_or_404
from django.http import JsonResponse, HttpResponse
from django.contrib.auth.decorators import login_required

import sys

import smpplib.gsm
import smpplib.client
import smpplib.consts
from time import sleep
import json

from main.core.smpp import HTTPCCM

def send_message(dest, string):
parts, encoding_flag, msg_type_flag = smpplib.gsm.make_parts(string)

#logging.info('Sending SMS "%s" to %s' % (string, dest))
for part in parts:
pdu = client.send_message(
source_addr_ton=smpplib.consts.SMPP_TON_SBSCR,
source_addr_npi=smpplib.consts.SMPP_NPI_ISDN,
source_addr="jasmin",
dest_addr_ton=smpplib.consts.SMPP_TON_SBSCR,
dest_addr_npi=smpplib.consts.SMPP_NPI_ISDN,
destination_addr=dest,
short_message=part,
data_coding=encoding_flag,
#esm_class=msg_type_flag,
esm_class=smpplib.consts.SMPP_MSGMODE_FORWARD,
registered_delivery=False,
)
#logging.debug(pdu.sequence)


def received_handler(pdu):
print ('* delivered {}'.format(pdu.sequence))

def sent_handler(pdu):
print ('* sent seq={} msgid={}'.format(pdu.sequence, pdu.message_id))

@login_required
def send_sms_view(request):
return render(request, "web/content/send_sms.html")


@login_required
def send_sms_view_manage(request):
args, res_status, res_message = {}, 400, _("Sorry, Command does not matched.")
args['msisdn'] = request.POST.get("msisdn")
args['sms'] = request.POST.get("sms")
callee = request.POST.get("msisdn")
sms = request.POST.get("sms")
client = smpplib.client.Client('172.22.0.31', 2775)
client.set_message_sent_handler(sent_handler)
client.set_message_received_handler(received_handler)
client.connect()
client.bind_transceiver(system_id='test', password='test')
parts, encoding_flag, msg_type_flag = smpplib.gsm.make_parts(sms)
#logging.info('Sending SMS "%s" to %s' % (string, dest))
for part in parts:
pdu = client.send_message(
source_addr_ton=smpplib.consts.SMPP_TON_SBSCR,
source_addr_npi=smpplib.consts.SMPP_NPI_ISDN,
source_addr="jasmin",
dest_addr_ton=smpplib.consts.SMPP_TON_SBSCR,
dest_addr_npi=smpplib.consts.SMPP_NPI_ISDN,
destination_addr=callee,
short_message=part,
data_coding=encoding_flag,
#esm_class=msg_type_flag,
esm_class=smpplib.consts.SMPP_MSGMODE_FORWARD,
registered_delivery=False,
)
sleep(.2)
try:
client.read_once()
res_stats = 200
except Exception as e:
res_message = str(e)
rest_status = 500
args['error'] = res_message
sleep(.8)
client.unbind()
return HttpResponse(json.dumps(args), status=res_status, content_type="application/json")
59 changes: 59 additions & 0 deletions main/web/views/content/sms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from django.utils.translation import gettext_lazy as _
from django.shortcuts import render, redirect, get_object_or_404
from django.http import JsonResponse, HttpResponse
from django.contrib.auth.decorators import login_required

import sys

import urllib.request, urllib.error, urllib.parse
import urllib.request, urllib.parse, urllib.error

from time import sleep
import json

from main.core.smpp import HTTPCCM

def send_message(dest, string):
parts, encoding_flag, msg_type_flag = smpplib.gsm.make_parts(string)

#logging.info('Sending SMS "%s" to %s' % (string, dest))
for part in parts:
pdu = client.send_message(
source_addr_ton=smpplib.consts.SMPP_TON_SBSCR,
source_addr_npi=smpplib.consts.SMPP_NPI_ISDN,
source_addr="jasmin",
dest_addr_ton=smpplib.consts.SMPP_TON_SBSCR,
dest_addr_npi=smpplib.consts.SMPP_NPI_ISDN,
destination_addr=dest,
short_message=part,
data_coding=encoding_flag,
#esm_class=msg_type_flag,
esm_class=smpplib.consts.SMPP_MSGMODE_FORWARD,
registered_delivery=False,
)
#logging.debug(pdu.sequence)


def received_handler(pdu):
print ('* delivered {}'.format(pdu.sequence))

def sent_handler(pdu):
print ('* sent seq={} msgid={}'.format(pdu.sequence, pdu.message_id))

@login_required
def send_sms_view(request):
return render(request, "web/content/send_sms.html")


@login_required
def send_sms_view_manage(request):
args, res_status, res_message = {}, 400, _("Sorry, Command does not matched.")
args['msisdn'] = request.POST.get("msisdn")
args['sms'] = request.POST.get("sms")
callee = request.POST.get("msisdn")
sms = request.POST.get("sms")
baseParams = {'username':'foo', 'password':'bar', 'from': 'jasmin', 'to': callee, 'content': sms}
res = urllib.request.urlopen("http://172.22.0.4:1401/send?%s" % urllib.parse.urlencode(baseParams)).read().decode('utf-8')
res_status = 200
args['result'] = res
return HttpResponse(json.dumps(args), status=res_status, content_type="application/json")