Skip to content

Commit

Permalink
Server now shows a list of all ips reported by the hub
Browse files Browse the repository at this point in the history
  • Loading branch information
OrenLederman committed Jun 9, 2018
1 parent 7bec53f commit 97a5094
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
8 changes: 5 additions & 3 deletions openbadge-server/openbadge/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def render(self, name, value, attrs=None):
class MemberInline(admin.TabularInline, GetLocalTimeMixin):
model = Member
extra = 3
fields = ('key','id', 'name', 'badge', 'observed_id',
fields = ('key', 'id', 'name', 'badge', 'observed_id',
'last_seen', 'last_voltage', 'last_audio', 'last_proximity', 'last_unsync', 'last_contacted',
'active', 'comments',
'last_audio_ts', 'last_audio_ts_fract', 'last_proximity_ts', 'last_unsync_ts', 'last_contacted_ts',
Expand Down Expand Up @@ -93,7 +93,8 @@ class MeetingInLine(admin.TabularInline, GetLocalTimeMixin):
class HubInline(admin.TabularInline, GetLocalTimeMixin):
model = Hub

fields = ("name", "god", "uuid", "last_seen", "last_hub_time", "time_difference_in_seconds", "ip_address", "key")
fields = ("name", "god", "uuid", "last_seen", "last_hub_time", "time_difference_in_seconds", "ip_address",
"all_ip_addresses", "key")
readonly_fields = ("key", 'last_seen', "last_hub_time", "time_difference_in_seconds")

def last_seen(self, obj):
Expand All @@ -109,7 +110,8 @@ def time_difference_in_seconds(self, obj):
@register(Project)
class ProjectAdmin(admin.ModelAdmin):
readonly_fields = ("key",)
list_display = ('name', 'key', 'id', 'advertisement_project_id', 'number_of_members', 'number_of_beacons', 'number_of_meetings', 'total_meeting_time')
list_display = ('name', 'key', 'id', 'advertisement_project_id', 'number_of_members', 'number_of_beacons',
'number_of_meetings', 'total_meeting_time')
list_filter = ('name',)
inlines = (MemberInline, BeaconInline, HubInline, MeetingInLine)
actions_on_top = True
Expand Down
19 changes: 19 additions & 0 deletions openbadge-server/openbadge/migrations/0009_hub_all_ip_addresses.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
('openbadge', '0008_auto_20180516_1520'),
]

operations = [
migrations.AddField(
model_name='hub',
name='all_ip_addresses',
field=models.CharField(max_length=512, null=True, blank=True),
),
]
3 changes: 3 additions & 0 deletions openbadge-server/openbadge/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ class Hub(BaseModel):
ip_address = models.GenericIPAddressField(null=True, blank=True)
"""IP address of the hub (if relevant)"""

all_ip_addresses = models.CharField(max_length=512, blank=True, null=True)
"""All IP addresses of the hub (if relevant)"""

last_seen_ts = models.DecimalField(max_digits=20, decimal_places=3, default=Decimal(0))
"""The last time the hub was seen by the server (in epoch time)"""

Expand Down
6 changes: 5 additions & 1 deletion openbadge-server/openbadge/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def has_permission(self, request, view):
try:
hub = Hub.objects.get(uuid=hub_uuid)
except Hub.DoesNotExist:
return False
return False

hub.last_seen_ts = int(time.time())
if hub_time is not None:
Expand All @@ -39,6 +39,10 @@ def has_permission(self, request, view):
elif remote_addr is not None:
hub.ip_address = remote_addr

hub_all_ips = request.META.get("HTTP_X_ALL_IPS")
if hub_all_ips is not None:
hub.all_ip_addresses = hub_all_ips

hub.save()

return True
Expand Down

0 comments on commit 97a5094

Please sign in to comment.