Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import sys
- import urllib
- import urllib2
- import httplib
- import re
- import os
- import time
- import datetime
- import commands
- def main ():
- #Firstly make sure there are no offline sessions running which could mess with our logic checking
- for name in names:
- if not getStatus(name):
- print 'offline' + name
- status, pid = commands.getstatusoutput("ps -ef | grep -v grep | grep -i "+ name + " | grep -i chrom | head -n 1 | awk '{print $2}'")
- if pid :
- print "killing " + pid
- os.system("kill -9 " + pid)
- #Secondly check who is online and if there are any recording conflicts
- for name in names:
- #check person is online of not
- if getStatus(name):
- #create url variable
- url = "www.cam4.com/" + name
- #sucess user is online
- print "Online: " + name
- #check if we are already recording for this user, if so then exit the script
- status, pid = commands.getstatusoutput("ps -ef | grep -i "+ name + " | grep -v grep | grep chrom | head -n 1 | wc -l")
- if "1" in pid:
- print "We are already recodring for this user"
- continue
- #Check if we are recording for another user, if so send an email saying the user is online but we are currently recording another user
- status, pid = commands.getstatusoutput("ps -ef | grep -v grep | grep -i cam4 | head -n 1 | wc -l")
- if "1" in pid:
- print "Recodring conflict for user " + name
- os.system('(echo "Subject: Recodring Conflict" ; echo We are recording another stream and the following user has came online "' + url + '" ) | /usr/sbin/sendmail ' + email)
- continue
- #Looks like this is a new stream, start recording and email
- os.system('(echo "Subject: User Online" ; echo "' + url + '" ) | /usr/sbin/sendmail ' + email)
- os.system('su - ' + disp_user + ' -c "export DISPLAY=:2; chromium-browser ' + url + ' &">/dev/null 2>&1')
- def getStatus(name):
- url = 'http://www.cam4.com/' + name
- req = urllib2.Request(url)
- response = urllib2.urlopen(req)
- the_page = response.read()
- if '<div id="camPaneBig">' in the_page:
- return True
- else:
- return False
- if __name__ == "__main__":
- #user who owns the unix display
- disp_user = "bob"
- #email to receive the alerts
- email = "bob@bob.com"
- #profiles you want to monitor
- names =['sally','sam']
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement