Browse Source

Fix ping button

devel
Dmitry Novikov 8 years ago
parent
commit
fd85dc9625
  1. 49
      abonapp/templates/abonapp/editAbon.html
  2. 10
      agent/mod_mikrotik.py

49
abonapp/templates/abonapp/editAbon.html

@ -94,22 +94,6 @@
</a> </a>
{% endif %} {% endif %}
{% if form.ip_address.value %}
{% if perms.abonapp.can_ping %}
<a href="{% url 'abonapp:ping' %}" class="btn btn-default btn-cmd" title="Ping" data-param="{{ form.ip_address.value }}">
<span class="glyphicon glyphicon-flash"></span> Ping
</a>
{% else %}
<a href="#" class="btn btn-default disabled" title="{% trans 'Permission denied' %}">
<span class="glyphicon glyphicon-flash"></span> Ping
</a>
{% endif %}
{% else %}
<a href="#" class="btn btn-default disabled">
<span class="glyphicon glyphicon-flash"></span> {% trans 'No have ip' %}
</a>
{% endif %}
{% if perms.dialing_app.can_send_sms %} {% if perms.dialing_app.can_send_sms %}
<a href="{% url 'dialapp:send_sms' %}?path={{ request.path|urlencode }}&dst={{ form.telephone.value|urlencode }}" class="btn btn-default btn-modal"> <a href="{% url 'dialapp:send_sms' %}?path={{ request.path|urlencode }}&dst={{ form.telephone.value|urlencode }}" class="btn btn-default btn-modal">
<span class="glyphicon glyphicon-envelope"></span> {% trans 'Send sms' %} <span class="glyphicon glyphicon-envelope"></span> {% trans 'Send sms' %}
@ -202,17 +186,31 @@
<h3 class="panel-title">{% trans 'Ip addresses' %}</h3> <h3 class="panel-title">{% trans 'Ip addresses' %}</h3>
</div> </div>
<ul class="list-group"> <ul class="list-group">
{% with can_ping=perms.abonapp.can_ping %}
{% for lease in abon.ip_addresses.all %} {% for lease in abon.ip_addresses.all %}
<li class="list-group-item"> <li class="list-group-item">
{% if lease.is_active %}
<a href="{% url 'abonapp:user_session_free' group.pk abon.username lease.pk %}" class="btn btn-danger btn-xs" title="{% trans 'Free session' %}" data-toggle="tooltip">
<span class="glyphicon glyphicon-remove"></span>
</a>
{% else %}
<a href="{% url 'abonapp:user_session_start' group.pk abon.username lease.pk %}" class="btn btn-success btn-xs" title="{% trans 'Start session' %}" data-toggle="tooltip">
<span class="glyphicon glyphicon-flash"></span>
</a>
{% endif %}
<div class="btn-group btn-group-xs">
{% if lease.is_active %}
<a href="{% url 'abonapp:user_session_free' group.pk abon.username lease.pk %}" class="btn btn-danger" title="{% trans 'Free session' %}" data-toggle="tooltip">
<span class="glyphicon glyphicon-remove"></span>
</a>
{% else %}
<a href="{% url 'abonapp:user_session_start' group.pk abon.username lease.pk %}" class="btn btn-success" title="{% trans 'Start session' %}" data-toggle="tooltip">
<span class="glyphicon glyphicon-flash"></span>
</a>
{% endif %}
{% if can_ping %}
<a href="{% url 'abonapp:ping' %}" class="btn btn-default btn-cmd" title="Ping" data-param="{{ lease.ip }}">
<span class="glyphicon glyphicon-flash"></span> Ping
</a>
{% else %}
<a href="#" class="btn btn-default disabled" title="{% trans 'Permission denied' %}">
<span class="glyphicon glyphicon-flash"></span> Ping
</a>
{% endif %}
</div>
<span{{ lease.is_active|yesno:', class="text-muted"'|safe }}> <span{{ lease.is_active|yesno:', class="text-muted"'|safe }}>
<b>{{ lease }}</b> <b>{{ lease }}</b>
<small>{% trans 'Leased by:' %} {{ lease.lease_time|date:'d-m H:i:s' }}. <small>{% trans 'Leased by:' %} {{ lease.lease_time|date:'d-m H:i:s' }}.
@ -225,6 +223,7 @@
{% empty %} {% empty %}
<li class="list-group-item">{% trans 'Leases does not found' %}</li> <li class="list-group-item">{% trans 'Leases does not found' %}</li>
{% endfor %} {% endfor %}
{% endwith %}
</ul> </ul>
<div class="panel-footer"> <div class="panel-footer">
<div class="btn-group btn-group-sm"> <div class="btn-group btn-group-sm">

10
agent/mod_mikrotik.py

@ -446,15 +446,17 @@ class MikrotikTransmitter(BaseTransmitter, ApiRos, metaclass=type('_ABC_Lazy_mcs
'/ip/arp/print', '/ip/arp/print',
'?address=%s' % host '?address=%s' % host
)) ))
if r == [{}]:
if r == {}:
return return
interface = r[0]['=interface']
interface = r['!re'].get('=interface')
r = self._exec_cmd(( r = self._exec_cmd((
'/ping', '=address=%s' % host, '=arp-ping=yes', '=interval=100ms', '=count=%d' % count, '/ping', '=address=%s' % host, '=arp-ping=yes', '=interval=100ms', '=count=%d' % count,
'=interface=%s' % interface '=interface=%s' % interface
)) ))
received, sent = int(r[-2:][0]['=received']), int(r[-2:][0]['=sent'])
return received, sent
res = r.get('!re')
if res is not None:
received, sent = int(res.get('=received')), int(res.get('=sent'))
return received, sent
def add_tariff_range(self, tariff_list: VectorTariff): def add_tariff_range(self, tariff_list: VectorTariff):
pass pass

Loading…
Cancel
Save