예제 #1
0
파일: views.py 프로젝트: phonelab/server
def show(request, deviceId):
    user = request.user
    userprofile = UserProfile.objects.get(user_id=user.id)
    # define default response
    response = {"err": "", "data": ""}

    #check deviceId to control accesses
    if is_valid_device(user, deviceId):
        # get device
        try:
            dev = Device.objects.get(id=deviceId)
            # device exists
            app_list = {}
            apps = {}
            unapps = {}
            # get apps of particular device
            for o in DeviceApplication.objects.filter(dev=dev.id).values(
                    'app', 'dev'):
                app_list[o['app']] = o['dev']
            # get list of apps to download
            for app in Application.objects.all():
                if app_list.has_key(app.id):
                    apps[app.id] = {
                        "app_object": app,
                    }
                else:
                    unapps[app.id] = {
                        "app_object": app,
                    }

            # get log data list from deviceId directory
            path = os.path.join(RAW_LOG_ROOT, dev.meid)
            # empty
            filelist = {}
            try:
                os.chdir(path)
                filelist = os.listdir(".")
                re_sort_nicely(filelist)

            except OSError, e:
                if e.errno != errno.EEXIST:
                    response['err'] = {
                        'no': 'err1',
                        'msg': 'cannot change dir, failed upload'
                    }
            return render_to_response(
                'device/show.html',
                {
                    'device': dev,
                    'apps': apps,
                    'unapps': unapps,
                    'filelist': filelist,
                    'userprofile': userprofile,
                    #          'group': userprofile.group
                },
                context_instance=RequestContext(request))

        # device does not exist
        except Device.DoesNotExist:
            response['err'] = {'no': 'err1', 'msg': 'invalid device'}
예제 #2
0
파일: views.py 프로젝트: phonelab/server
def edit(request, deviceId):
  user = request.user
  # define default response
  response = { "err": "", "data": "" }

  #check deviceId to control accesses
  if is_valid_device(user, deviceId):
    # get device
    try:
      device = Device.objects.get(id=deviceId)
      # device exists
      return render_to_response(
        'device/edit.html', 
          {
            'device': device
          },
          context_instance=RequestContext(request)
        )
    # device does not exist
    except Device.DoesNotExist: 
      response['err'] = {
        'no' : 'err1',
        'msg': 'invalid device'
      }
    return json_response_from(response)
  else:
    return HttpResponseRedirect('/')
예제 #3
0
def show(request, deviceId, logFilename):
    user = request.user
    # define default response
    response = {"err": "", "data": ""}

    if is_valid_device(user, deviceId):
        # get device
        device = Device.objects.filter(id=deviceId)
        # if device exists, update
        if device.count() == 1:
            # generate file name
            filename = os.path.join(RAW_LOG_ROOT, device[0].meid,
                                    logFilename + ".log")
            if os.path.isfile(filename):
                # open log file
                Logfile = open(filename, 'r+')
                # read file
                Logdata = Logfile.read()
                # render respone
                return render_to_response(
                    'device/log.html', {
                        'device': device[0],
                        'logFilename': logFilename,
                        'Logdata': Logdata
                    },
                    context_instance=RequestContext(request))
            #the file does not exist
            else:
                response['err'] = {'no': 'err2', 'msg': 'No such log file'}
        #device does not exist
        else:
            response['err'] = {'no': 'err1', 'msg': 'invalid device'}
        return json_response_from(response)
    else:
        return HttpResponseRedirect('/')
예제 #4
0
파일: views.py 프로젝트: phonelab/server
def show(request, deviceId):
  user = request.user
  userprofile = UserProfile.objects.get(user_id=user.id)
  # define default response
  response = { "err": "", "data": "" }

  #check deviceId to control accesses
  if is_valid_device(user, deviceId):
    # get device
    try:
      dev = Device.objects.get(id=deviceId)
      # device exists
      app_list = {}
      apps = {}
      unapps = {}
      # get apps of particular device
      for o in DeviceApplication.objects.filter(dev=dev.id).values('app', 'dev'):
        app_list[o['app']] = o['dev']
      # get list of apps to download
      for app in Application.objects.all():
        if app_list.has_key(app.id):
          apps[app.id] = {"app_object": app,}
        else:
          unapps[app.id] = {"app_object": app,}

      # get log data list from deviceId directory
      path = os.path.join(RAW_LOG_ROOT, dev.meid)
      # empty
      filelist = {}
      try:
        os.chdir(path)
        filelist = os.listdir(".")
        re_sort_nicely(filelist)

      except OSError, e:
        if e.errno != errno.EEXIST:
          response['err'] = {
            'no' : 'err1', 
            'msg': 'cannot change dir, failed upload'
          }
      return render_to_response(
    	  'device/show.html', 
  	    {
    	    'device' : dev,
    	    'apps'     : apps,
          'unapps'   : unapps,
          'filelist' : filelist,
          'userprofile': userprofile,
#          'group': userprofile.group
    	  },
        context_instance=RequestContext(request)
      )
    
    # device does not exist
    except Device.DoesNotExist: 
      response['err'] = {
        'no' : 'err1',
        'msg': 'invalid device'
      }
예제 #5
0
파일: views.py 프로젝트: phonelab/server
def edit(request, deviceId):
    user = request.user
    # define default response
    response = {"err": "", "data": ""}

    #check deviceId to control accesses
    if is_valid_device(user, deviceId):
        # get device
        try:
            device = Device.objects.get(id=deviceId)
            # device exists
            return render_to_response('device/edit.html', {'device': device},
                                      context_instance=RequestContext(request))
        # device does not exist
        except Device.DoesNotExist:
            response['err'] = {'no': 'err1', 'msg': 'invalid device'}
        return json_response_from(response)
    else:
        return HttpResponseRedirect('/')
예제 #6
0
파일: views.py 프로젝트: phonelab/server
def show(request, deviceId, logFilename):
  user = request.user
  # define default response  
  response = { "err": "", "data": "" }  

  if is_valid_device(user, deviceId):
    # get device  
    device = Device.objects.filter(id=deviceId)
    # if device exists, update  
    if device.count() == 1:
      # generate file name    
      filename = os.path.join(RAW_LOG_ROOT, device[0].meid, logFilename + ".log")		
      if os.path.isfile(filename):			
        # open log file
        Logfile = open(filename, 'r+')
        # read file
        Logdata = Logfile.read()
        # render respone
        return render_to_response(
          'device/log.html',
          {
            'device': device[0],
            'logFilename': logFilename,
            'Logdata': Logdata
          },
          context_instance=RequestContext(request)
        )
      #the file does not exist 
      else:
        response['err'] = {
          'no' : 'err2',
          'msg': 'No such log file'
        }
    #device does not exist		
    else:
      response['err'] = {
        'no' : 'err1',
        'msg': 'invalid device'
      }
    return json_response_from(response)
  else:
    return HttpResponseRedirect('/')
예제 #7
0
 def _validate(self):
     if not is_valid_device(self.device):
         exit_with(f"Error: no such device: {self.device} (try `hciconfig list')")
예제 #8
0
파일: views.py 프로젝트: phonelab/server
def status(request, deviceId, statusType):
  user = request.user
  # define default response
  response = { "err": "", "data": "" }

  #check deviceId to control accesses
  if is_valid_device(user, deviceId):
    # get device
    try:
      device = Device.objects.get(id=deviceId)
      # device exists
      # get log data list from deviceId directory
      path = os.path.join(RAW_LOG_ROOT, device.meid)
      # empty
      filelist = {}
      tagName = ''
      if statusType == '1':
        tagName = 'Battery_level'
        #tagName = 'Battery level'
      elif statusType == '2':
        tagName = 'Location_Latitude'
        #tagName = 'Location: Latitude'
      else:
        tagName = 'Signal_Strength'
        #tagName = 'Signal Strength'
      try:
        os.chdir(path)
        filelist = os.listdir(".")
        sort_nicely(filelist)
        Tagdata = ''
        for file in filelist:
          filename = os.path.join(RAW_LOG_ROOT, device.meid, file)
          Logfile = open(filename, 'r+')
          for line in Logfile:
            #Logdata = Logfile.readline()
            if re.search(tagName, line):
              temp = line.split()
              Tagdata += ' [ ' + temp[0] + ' ' + temp[1] + ' ] '
              if statusType == '1':
                Tagdata += 'Battery Level: ' + temp[7] + '\n'
              elif statusType == '2':
                Tagdata += 'GPS Latitude: ' + temp[7] + ', Longitude: ' + temp[9] + ', Accuracy: ' + temp[11] + '\n'
              else:
                Tagdata += 'Signal Strengh: ' + temp[7] + ', asu: ' + temp[9] + '\n'

        # render respone
        return render_to_response(
          'device/status.html',
          {
            'device': device,
            'TagName': tagName,
            'Tagdata': Tagdata
          },
          context_instance=RequestContext(request)
        )
        Logfile.close()
        Tagfile.close()
      except OSError, e:
        if e.errno != errno.EEXIST:
          response['err'] = {
            'no' : 'err1', 
            'msg': 'cannot change dir'
          }
    # device does not exist
    except Device.DoesNotExist: 
      response['err'] = {
        'no' : 'err1',
        'msg': 'invalid device'
      }
    return json_response_from(response)
  else:
    return HttpResponseRedirect('/')
예제 #9
0
파일: views.py 프로젝트: phonelab/server
def status(request, deviceId, statusType):
    user = request.user
    # define default response
    response = {"err": "", "data": ""}

    #check deviceId to control accesses
    if is_valid_device(user, deviceId):
        # get device
        try:
            device = Device.objects.get(id=deviceId)
            # device exists
            # get log data list from deviceId directory
            path = os.path.join(RAW_LOG_ROOT, device.meid)
            # empty
            filelist = {}
            tagName = ''
            if statusType == '1':
                tagName = 'Battery_level'
                #tagName = 'Battery level'
            elif statusType == '2':
                tagName = 'Location_Latitude'
                #tagName = 'Location: Latitude'
            else:
                tagName = 'Signal_Strength'
                #tagName = 'Signal Strength'
            try:
                os.chdir(path)
                filelist = os.listdir(".")
                sort_nicely(filelist)
                Tagdata = ''
                for file in filelist:
                    filename = os.path.join(RAW_LOG_ROOT, device.meid, file)
                    Logfile = open(filename, 'r+')
                    for line in Logfile:
                        #Logdata = Logfile.readline()
                        if re.search(tagName, line):
                            temp = line.split()
                            Tagdata += ' [ ' + temp[0] + ' ' + temp[1] + ' ] '
                            if statusType == '1':
                                Tagdata += 'Battery Level: ' + temp[7] + '\n'
                            elif statusType == '2':
                                Tagdata += 'GPS Latitude: ' + temp[
                                    7] + ', Longitude: ' + temp[
                                        9] + ', Accuracy: ' + temp[11] + '\n'
                            else:
                                Tagdata += 'Signal Strengh: ' + temp[
                                    7] + ', asu: ' + temp[9] + '\n'

                # render respone
                return render_to_response(
                    'device/status.html', {
                        'device': device,
                        'TagName': tagName,
                        'Tagdata': Tagdata
                    },
                    context_instance=RequestContext(request))
                Logfile.close()
                Tagfile.close()
            except OSError, e:
                if e.errno != errno.EEXIST:
                    response['err'] = {
                        'no': 'err1',
                        'msg': 'cannot change dir'
                    }
        # device does not exist
        except Device.DoesNotExist:
            response['err'] = {'no': 'err1', 'msg': 'invalid device'}
        return json_response_from(response)
    else:
        return HttpResponseRedirect('/')