Replaced hard coded IP address (of permitted analysis clients to from end) with the...
authorUnknown Author <unknown>
Fri, 8 Aug 2008 23:32:30 +0000 (23:32 +0000)
committerUnknown Author <unknown>
Fri, 8 Aug 2008 23:32:30 +0000 (23:32 +0000)
gaworkflow/frontend/exp_track/exptrack.py

index 38daaab4f6f143ada5f717445ae06f3321049042..8cd5d6d1b71728366a69df1645d17a4d4d453c3f 100644 (file)
@@ -3,8 +3,9 @@ from django.http import HttpResponse
 from datetime import datetime
 from string import *
 import re
-from gaworkflow.frontend.exp_track.models import DataRun
-from gaworkflow.frontend.fctracker.models import FlowCell, Library
+from gaworkflow.frontend import settings
+from gaworkflow.frontend.exp_track.models import FlowCell, DataRun
+from gaworkflow.frontend.fctracker.models import Library
 from django.core.exceptions import ObjectDoesNotExist
 from django.core.mail import send_mail, mail_admins
 
@@ -13,11 +14,20 @@ def updStatus(request):
     user = 'none'
     pswd = ''
     UpdatedStatus = 'unknown'
-    ClIP = 'unknown'
-    granted = False
     fcid = 'none'
     runfolder = 'unknown'
-    
+    ClIP = request.META['REMOTE_ADDR']
+    granted = False    
+
+    if request.has_key('user'):
+      user = request['user']
+
+    #Check access permission 
+    if (user == 'rami' and settings.ALLOWED_IPS.has_key(ClIP)):  granted = True
+    if not granted: return HttpResponse("access denied.")
+
+
+    # ~~~~~~Parameters for the job ~~~~
     if request.has_key('fcid'):
       fcid = request['fcid']
     else:
@@ -27,51 +37,35 @@ def updStatus(request):
       runfolder = request['runf']
     else:
       return HttpResponse('missing runf')
-    
-    if request.has_key('user'):  
-      user = request['user']
-    else:
-      return HttpResponse('access denied')
-
-    #TO DO: pswd decode etc..
-    #if request.has_key('pswd'):
-    #  pswd = request['pswd']
-    #else: 
-    #  return HttpResponse('access denied')
 
-    ClIP = request.META['REMOTE_ADDR']
     
-    #Check permission to update
-    if (user == 'rami' and (ClIP == '171.65.76.167' or ClIP == '171.65.76.51' or ClIP == '171.65.76.194' or (ClIP == '74.51.115.100' or ClIP == '64.89.97.100'))): ## or ClIP == '127.0.0.1')):
-      granted = True
+    if request.has_key('updst'):
+      UpdatedStatus = request['updst']
+    else:
+      return HttpResponse('missing status')
     
-    if granted:
-      if request.has_key('updst'):
-        UpdatedStatus = request['updst']
-      else:
-        return HttpResponse('missing status')
-      # Update Data Run status in DB
-      # Try get rec. If not found return 'entry not found + <fcid><runfolder>', if found try update and return updated 
-      try:
-        rec = DataRun.objects.get(run_folder=runfolder)
-        rec.run_status = UpdatedStatus
-
-        #if there's a message update that too
-        mytimestamp = datetime.now().__str__()
-        mytimestamp = re.sub(pattern=":[^:]*$",repl="",string=mytimestamp)
-        if request.has_key('msg'):
-          rec.run_note += ", "+request['msg']+" ("+mytimestamp+")"
-        else :
-          if UpdatedStatus == '1':
-            rec.run_note = "Started ("+mytimestamp+")"
-
-        rec.save()
-        output = "updated to:'"+DataRun.RUN_STATUS_CHOICES[int(UpdatedStatus)][1].__str__()+"'"
-      except ObjectDoesNotExist:
-        output = "entry not found: "+fcid+", "+runfolder
-    else: 
-      output ="access denied.. u: "+user+", ClIP: "+ClIP
+    # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
+
+    # Update Data Run status in DB
+    # Try get rec. If not found return 'entry not found + <fcid><runfolder>', if found try update and return updated 
+    try:
+      rec = DataRun.objects.get(run_folder=runfolder)
+      rec.run_status = UpdatedStatus
+
+      #if there's a message update that too
+      mytimestamp = datetime.now().__str__()
+      mytimestamp = re.sub(pattern=":[^:]*$",repl="",string=mytimestamp)
+      if request.has_key('msg'):
+        rec.run_note += ", "+request['msg']+" ("+mytimestamp+")"
+      else :
+        if UpdatedStatus == '1':
+          rec.run_note = "Started ("+mytimestamp+")"
+
+      rec.save()
+      output = "Hello "+settings.ALLOWED_IPS[ClIP]+". Updated to:'"+DataRun.RUN_STATUS_CHOICES[int(UpdatedStatus)][1].__str__()+"'"
+    except ObjectDoesNotExist:
+      output = "entry not found: "+fcid+", "+runfolder
+
 
     #Notify researcher by email
     # Doesn't work
@@ -81,6 +75,12 @@ def updStatus(request):
     return HttpResponse(output)
 
 def generateConfile(fcid):
+    granted = False
+    ClIP = request.META['REMOTE_ADDR']
+    if (settings.ALLOWED_IPS.has_key(ClIP)):  granted = True
+
+    if not granted: return HttpResponse("access denied.")
+
     cnfgfile = 'READ_LENGTH 25\n'
     cnfgfile += 'ANALYSIS eland\n'
     cnfgfile += 'GENOME_FILE all_chr.fa\n'
@@ -121,6 +121,12 @@ def generateConfile(fcid):
     return cnfgfile
 
 def getConfile(request):
+    granted = False
+    ClIP = request.META['REMOTE_ADDR']
+    if (settings.ALLOWED_IPS.has_key(ClIP)):  granted = True
+
+    if not granted: return HttpResponse("access denied.")
+
     fcid = 'none'
     cnfgfile = ''
     runfolder = 'unknown'
@@ -148,6 +154,12 @@ def getConfile(request):
     return HttpResponse(cnfgfile)
 
 def getLaneLibs(request):
+    granted = False
+    ClIP = request.META['REMOTE_ADDR']
+    if (settings.ALLOWED_IPS.has_key(ClIP)):  granted = True
+
+    if not granted: return HttpResponse("access denied.")
+
     fcid = 'none'
     outputfile = ''
     if request.has_key('fcid'):
@@ -165,15 +177,15 @@ def getLaneLibs(request):
         else: day = day.__str__()
         mydate = year+month+day
         outputfile = '<?xml version="1.0" ?>'
-        outputfile += '\n<SolexaResult Date="'+mydate+'" Flowcell="'+fcid+'">'
-        outputfile += '\n<Lane Index="1" Name="'+rec.lane_1_library.library_name+'" Library="'+rec.lane_1_library.library_id+'" Genome="'+rec.lane_1_library.library_species.use_genome_build+'"/>'
-        outputfile += '\n<Lane Index="2" Name="'+rec.lane_2_library.library_name+'" Library="'+rec.lane_2_library.library_id+'" Genome="'+rec.lane_2_library.library_species.use_genome_build+'"/>'
-        outputfile += '\n<Lane Index="3" Name="'+rec.lane_3_library.library_name+'" Library="'+rec.lane_3_library.library_id+'" Genome="'+rec.lane_3_library.library_species.use_genome_build+'"/>'
-        outputfile += '\n<Lane Index="4" Name="'+rec.lane_4_library.library_name+'" Library="'+rec.lane_4_library.library_id+'" Genome="'+rec.lane_4_library.library_species.use_genome_build+'"/>'
-        outputfile += '\n<Lane Index="5" Name="'+rec.lane_5_library.library_name+'" Library="'+rec.lane_5_library.library_id+'" Genome="'+rec.lane_5_library.library_species.use_genome_build+'"/>'
-        outputfile += '\n<Lane Index="6" Name="'+rec.lane_6_library.library_name+'" Library="'+rec.lane_6_library.library_id+'" Genome="'+rec.lane_6_library.library_species.use_genome_build+'"/>'
-        outputfile += '\n<Lane Index="7" Name="'+rec.lane_7_library.library_name+'" Library="'+rec.lane_7_library.library_id+'" Genome="'+rec.lane_7_library.library_species.use_genome_build+'"/>'
-        outputfile += '\n<Lane Index="8" Name="'+rec.lane_8_library.library_name+'" Library="'+rec.lane_8_library.library_id+'" Genome="'+rec.lane_8_library.library_species.use_genome_build+'"/>'
+        outputfile += '\n<SolexaResult Date="'+mydate+'" Flowcell="'+fcid+'" Client="'+settings.ALLOWED_IPS[ClIP]+'">'
+        outputfile += '\n<Lane Index="1" Name="'+rec.lane_1_library.library_name+'" Library="'+rec.lane_1_library.library_id+'" Genome="'+rec.lane_1_library.library_species.use_genome_build+'" PrimerName="" PrimerSeq=""/>'
+        outputfile += '\n<Lane Index="2" Name="'+rec.lane_2_library.library_name+'" Library="'+rec.lane_2_library.library_id+'" Genome="'+rec.lane_2_library.library_species.use_genome_build+'" PrimerName="" PrimerSeq=""/>'
+        outputfile += '\n<Lane Index="3" Name="'+rec.lane_3_library.library_name+'" Library="'+rec.lane_3_library.library_id+'" Genome="'+rec.lane_3_library.library_species.use_genome_build+'" PrimerName="" PrimerSeq=""/>'
+        outputfile += '\n<Lane Index="4" Name="'+rec.lane_4_library.library_name+'" Library="'+rec.lane_4_library.library_id+'" Genome="'+rec.lane_4_library.library_species.use_genome_build+'" PrimerName="" PrimerSeq=""/>'
+        outputfile += '\n<Lane Index="5" Name="'+rec.lane_5_library.library_name+'" Library="'+rec.lane_5_library.library_id+'" Genome="'+rec.lane_5_library.library_species.use_genome_build+'" PrimerName="" PrimerSeq=""/>'
+        outputfile += '\n<Lane Index="6" Name="'+rec.lane_6_library.library_name+'" Library="'+rec.lane_6_library.library_id+'" Genome="'+rec.lane_6_library.library_species.use_genome_build+'" PrimerName="" PrimerSeq=""/>'
+        outputfile += '\n<Lane Index="7" Name="'+rec.lane_7_library.library_name+'" Library="'+rec.lane_7_library.library_id+'" Genome="'+rec.lane_7_library.library_species.use_genome_build+'" PrimerName="" PrimerSeq=""/>'
+        outputfile += '\n<Lane Index="8" Name="'+rec.lane_8_library.library_name+'" Library="'+rec.lane_8_library.library_id+'" Genome="'+rec.lane_8_library.library_species.use_genome_build+'" PrimerName="" PrimerSeq=""/>'
         outputfile += '\n</SolexaResult>'
       except ObjectDoesNotExist:
         outputfile = 'Flowcell entry not found for: '+fcid