From b84648fa3730d8b258bbc4ada0dcbde5a033f747 Mon Sep 17 00:00:00 2001 From: CruiseDevice Date: Mon, 19 Feb 2018 15:01:22 +0530 Subject: initial commit --- sbhs_server/credentials.py-bkup | 12 ++++++++++++ sbhs_server/helpers/mailer.py | 4 ++-- sbhs_server/helpers/test_mail.py | 17 +++++++++++++++++ sbhs_server/map_machine_ids.txt | 34 ++++------------------------------ sbhs_server/scan_rpis.sh | 6 +++++- sbhs_server/settings.py | 22 ++++++++++++++-------- sbhs_server/tables/models.py | 14 ++++++++++---- 7 files changed, 64 insertions(+), 45 deletions(-) create mode 100644 sbhs_server/credentials.py-bkup create mode 100644 sbhs_server/helpers/test_mail.py mode change 100644 => 100755 sbhs_server/scan_rpis.sh (limited to 'sbhs_server') diff --git a/sbhs_server/credentials.py-bkup b/sbhs_server/credentials.py-bkup new file mode 100644 index 0000000..3906e73 --- /dev/null +++ b/sbhs_server/credentials.py-bkup @@ -0,0 +1,12 @@ +PROJECT_SECRET_KEY = 'iujfhiuwfr43873herfh8734684375hjfhg' +EMAIL_HOST_USER = 'sbhs.lolmax@gmail.com' +EMAIL_HOST_PASSWORD = '1qaz2wsx@' +MAP_FILE = '/home/vlabs-sbhs/code/sbhs/map_machine_ids.txt' +LOG_FILE = '/tmp/sbhserr.log' +ADMIN_EMAIL='rupakrokade@gmail.com' +DB_NAME = 'sbhs' +DB_USER = 'root' +DB_PASS = 'fossee@iitb' +DB_HOST = 'localhost' +DB_PORT = '3306' + diff --git a/sbhs_server/helpers/mailer.py b/sbhs_server/helpers/mailer.py index 4c61035..2ba901e 100644 --- a/sbhs_server/helpers/mailer.py +++ b/sbhs_server/helpers/mailer.py @@ -9,11 +9,11 @@ def email(to, subject, message): smtpserver.ehlo() smtpserver.starttls() smtpserver.ehlo() - #smtpserver.esmtp_features['auth']='LOGIN DIGEST-MD5 PLAIN' + smtpserver.esmtp_features['auth']='LOGIN DIGEST-MD5 PLAIN' smtpserver.login(settings.EMAIL_HOST_USER, settings.EMAIL_HOST_PASSWORD) header = 'To: ' + to + '\n' + 'From: ' + settings.EMAIL_HOST_USER + '@iitb.ac.in\n' + 'Subject: ' + subject +' \n' msg = header + '\n' + message + '\n\n' #smtpserver.sendmail(settings.EMAIL_HOST_USER + '@iitb.ac.in', to, msg) smtpserver.sendmail(settings.EMAIL_HOST_USER , to, msg) - smtpserver.close() \ No newline at end of file + smtpserver.close() diff --git a/sbhs_server/helpers/test_mail.py b/sbhs_server/helpers/test_mail.py new file mode 100644 index 0000000..24af4b8 --- /dev/null +++ b/sbhs_server/helpers/test_mail.py @@ -0,0 +1,17 @@ +import smtplib + +def email(to, subject, message): + smtpserver = smtplib.SMTP() + smtpserver.connect('smtp-auth.iitb.ac.in', 25) + smtpserver.ehlo() + smtpserver.starttls() + smtpserver.ehlo() + smtpserver.esmtp_features['auth']='LOGIN DIGEST-MD5 PLAIN' + smtpserver.login('rupakrokade', '*rupak*iit') + + header = 'To: ' + to + '\n' + 'From: ' + 'rupakrokade' + '@iitb.ac.in\n' + 'Subject: ' + subject +' \n' + msg = header + '\n' + message + '\n\n' + smtpserver.sendmail('rupakrokade' + '@iitb.ac.in', to, msg) + smtpserver.close() + +email('rupakrokade@gmail.com','hello','hello') diff --git a/sbhs_server/map_machine_ids.txt b/sbhs_server/map_machine_ids.txt index ceb2b7b..0954fe1 100644 --- a/sbhs_server/map_machine_ids.txt +++ b/sbhs_server/map_machine_ids.txt @@ -1,30 +1,4 @@ -15=/dev/ttyUSB31 -32=/dev/ttyUSB30 -20=/dev/ttyUSB29 -25=/dev/ttyUSB28 -28=/dev/ttyUSB26 -24=/dev/ttyUSB25 -22=/dev/ttyUSB24 -18=/dev/ttyUSB23 -27=/dev/ttyUSB22 -26=/dev/ttyUSB21 -30=/dev/ttyUSB20 -29=/dev/ttyUSB19 -11=/dev/ttyUSB18 -1=/dev/ttyUSB17 -8=/dev/ttyUSB16 -7=/dev/ttyUSB15 -3=/dev/ttyUSB14 -6=/dev/ttyUSB13 -2=/dev/ttyUSB12 -13=/dev/ttyUSB11 -14=/dev/ttyUSB10 -16=/dev/ttyUSB9 -21=/dev/ttyUSB7 -31=/dev/ttyUSB8 -19=/dev/ttyUSB6 -23=/dev/ttyUSB5 -10=/dev/ttyUSB4 -5=/dev/ttyUSB3 -12=/dev/ttyUSB2 -9=/dev/ttyUSB1 +12=/dev/ttyUSB1 +16=/dev/ttyUSB0 +255=/dev/ttyUSB8 +9=/dev/ttyUSB4 diff --git a/sbhs_server/scan_rpis.sh b/sbhs_server/scan_rpis.sh old mode 100644 new mode 100755 index 14edac1..a3bf724 --- a/sbhs_server/scan_rpis.sh +++ b/sbhs_server/scan_rpis.sh @@ -5,6 +5,10 @@ cd sbhs_server mkdir -p RPi_data mkdir -p RPi_data/map RPi_data/report +DIR="$( cd "$( dirname "$0" )" && pwd )" +cd $DIR + + # Get map_machine_ids.txt and server reports from all connected Raspberry Pi's while read -r ip do @@ -12,7 +16,7 @@ do curl -o RPi_data/map/$ip.txt $ip/map_machine_ids.txt curl -o RPi_data/report/$ip.txt $ip/report.json rsync -arz --exclude="django_error.log" -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" --progress pi@$ip:/home/pi/sbhs-pi/log/ /home/vlabs-sbhs/code/sbhs/log/ - rsync -arz --remove-source-files -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" --progress pi@$ip:/home/pi/sbhs-pi/experiments/ /home/vlabs-sbhs/code/sbhs/experiments/ + rsync -arz --remove-source-files --rsync-path="sudo rsync" -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" --progress pi@$ip:/home/pi/sbhs-pi/experiments/ /home/vlabs-sbhs/code/sbhs/experiments/ done < "RPi_data/ipaddrs.txt" # Execute script to create IP map diff --git a/sbhs_server/settings.py b/sbhs_server/settings.py index fd70f92..4f8db33 100644 --- a/sbhs_server/settings.py +++ b/sbhs_server/settings.py @@ -14,7 +14,9 @@ import sbhs_server.credentials as credentials hostname = socket.gethostname() -is_production = hostname == "vlabssbhs" +is_production = True + +hostname == "vlabs-sbhs" # Build paths inside the project like this: os.path.join(BASE_DIR, ...) import os @@ -27,6 +29,8 @@ BASE_DIR = os.path.dirname(os.path.dirname(__file__)) # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = credentials.PROJECT_SECRET_KEY + + # SECURITY WARNING: don't run with debug turned on in production! DEBUG = not is_production @@ -40,6 +44,7 @@ ALLOWED_HOSTS = [ "192.168.43.208", "192.168.43.144", "10.42.0.1", + "vlabs.iitb.ac.in", ] if is_production: @@ -78,6 +83,7 @@ INSTALLED_APPS = ( 'sbhs_server.tables', 'webcam', 'maintenance', + 'django_extensions', ) MIDDLEWARE = ( @@ -132,9 +138,9 @@ USE_L10N = True USE_TZ = False AUTH_USER_MODEL = 'tables.Account' -LOGIN_URL = '/sbhs-rpi/enter' -LOGOUT_URL = '/sbhs-rpi/logout' -SESSION_EXPIRE_AT_BROWSER_CLOSE = True +LOGIN_URL = '/sbhs/enter' +LOGOUT_URL = '/sbhs/logout' +SESSION_EXPIRE_AT_BROWSER_CLOSE = True # Browser-length session CSRF_COOKIE_NAME = "pfesgbxra" SESSION_COOKIE_NAME = "frffvbaVq" @@ -150,8 +156,8 @@ ADMIN_EMAIL=credentials.ADMIN_EMAIL if is_production: - BASE_URL = "http://vlabs.iitb.ac.in/sbhs-rpi/" - FORCE_SCRIPT_NAME = "/sbhs-rpi" + BASE_URL = "http://vlabs.iitb.ac.in/sbhs/" + FORCE_SCRIPT_NAME = "/sbhs" USE_X_FORWARDED_HOST = True else: BASE_URL = "http://127.0.0.1/" @@ -164,7 +170,7 @@ STATICFILES_DIRS = ( if is_production: STATIC_ROOT = os.path.join(BASE_DIR, "production_static_files") - STATIC_URL = 'http://vlabs.iitb.ac.in/sbhs-rpi/static/' + STATIC_URL = 'http://vlabs.iitb.ac.in/sbhs/static/' else: STATIC_URL = '/static/' @@ -256,4 +262,4 @@ online_mids = list(pi_ip_map.keys()) print "No of machines online : ", len(online_mids) import sys -print >>sys.stderr, online_mids[:] \ No newline at end of file +print >>sys.stderr, online_mids[:] diff --git a/sbhs_server/tables/models.py b/sbhs_server/tables/models.py index 813e6cc..7861acc 100644 --- a/sbhs_server/tables/models.py +++ b/sbhs_server/tables/models.py @@ -9,6 +9,8 @@ from django.core.exceptions import ObjectDoesNotExist #from yaksh.models import Profile # Create your models here. +print 'inside model' + class Board(TrashableMixin): """ Declaring varibales mid = Integer and unique @@ -21,6 +23,7 @@ class Board(TrashableMixin): mid = models.IntegerField(unique=True) online = models.BooleanField(default=True) temp_offline = models.BooleanField(default=False) + power_status = models.BooleanField(default=False) created_at = models.DateTimeField(auto_now_add=True, editable=False) updated_at = models.DateTimeField(auto_now=True, editable=False) @@ -68,7 +71,7 @@ class Board(TrashableMixin): def image_link(self): """ Function to show the image obtained from webcam """ - return settings.WEBCAM_STATIC_DIR + "image" + str(self.mid) + ".jpeg" + return settings.WEBCAM_STATIC_DIR + "image" + '0'+str(self.mid) + ".jpeg" class Account(TrashableMixin, AbstractBaseUser): @@ -270,6 +273,9 @@ class Webcam(): def load_image(className,mid): if int(mid) : - command = "timeout 2s streamer -q -f jpeg -c /dev/video" + str(mid) - command += " -o " + settings.WEBCAM_DIR + "image" + str(mid) + ".jpeg" - os.system(command) \ No newline at end of file + command = "timeout 2s streamer -q -f jpeg -c /dev/video" + '0'+str(mid) + print 'command1', command + command += " -o " + settings.WEBCAM_DIR + "image" + '0'+str(mid) + ".jpeg" + print 'command2', command + os.system(command) + \ No newline at end of file -- cgit