Skip to content

Commit

Permalink
Added Authentication and Prowl Functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Dlesk committed Jan 9, 2012
1 parent 88df904 commit 62df0d9
Show file tree
Hide file tree
Showing 15 changed files with 77 additions and 20 deletions.
Binary file modified Gamez.db
Binary file not shown.
12 changes: 7 additions & 5 deletions Gamez.ini
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
[global]
server.socket_host = "127.0.0.1"
server.socket_port = 8085
user_name = ""
password = ""

[NZBMatrix]
username =
api_key =
username = ""
api_key = ""

[Newznab]
api_key =
api_key = ""
wii_category_id = "1030"
xbox360_category_id = "1050"
host =
host = ""
port =

[Sabnzbd]
api_key =
api_key = ""
host = "127.0.0.1"
port = 8081

Expand Down
13 changes: 12 additions & 1 deletion Gamez.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from lib.ConfigFunctions import CheckConfigForAllKeys
from lib.DBFunctions import ValidateDB
from lib.Logger import LogEvent
import cherrypy.lib.auth_basic

app_path = os.path.dirname(os.path.abspath("__FILE__"))
config_path = os.path.join(app_path,'Gamez.ini')
Expand All @@ -30,13 +31,23 @@ def RunWebServer(self,isToDaemonize):
js_path = os.path.join(app_path,'js')
theme_path = os.path.join(css_path,'redmond')
theme_images_path = os.path.join(theme_path,'images')
config = ConfigParser.RawConfigParser()
config.read('Gamez.ini')
username = config.get('global','user_name').replace('"','')
password = config.get('global','password').replace('"','')
useAuth = False
if(username <> "" or password <> ""):
useAuth = True
userPassDict = {username:password}
checkpassword = cherrypy.lib.auth_basic.checkpassword_dict(userPassDict)
conf = {
'/':{'tools.auth_basic.on':useAuth,'tools.auth_basic.realm':'Gamez','tools.auth_basic.checkpassword':checkpassword},
'/css': {'tools.staticdir.on':True,'tools.staticdir.dir':css_path},
'/js':{'tools.staticdir.on':True,'tools.staticdir.dir':js_path},
'/css/redmond':{'tools.staticdir.on':True,'tools.staticdir.dir':theme_path},
'/css/redmond/images':{'tools.staticdir.on':True,'tools.staticdir.dir':theme_images_path},
'/css/navigation_images':{'tools.staticdir.on':True,'tools.staticdir.dir':navigation_images_path},
'/css/datatables_images':{'tools.staticdir.on':True,'tools.staticdir.dir':datatables_images_path}
'/css/datatables_images':{'tools.staticdir.on':True,'tools.staticdir.dir':datatables_images_path},
}
daemon = Daemonizer(cherrypy.engine)

Expand Down
8 changes: 8 additions & 0 deletions lib/ConfigFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ def CheckConfigForAllKeys(app_path):
config.set('global','server.socket_port','8085')
changesMade = True

if(config.has_option('global','user_name') == False):
config.set('global','user_name','""')
changesMade = True

if(config.has_option('global','password') == False):
config.set('global','password','""')
changesMade = True

if(config.has_option('NZBMatrix','username') == False):
config.set('NZBMatrix','username','""')
changesMade = True
Expand Down
Binary file modified lib/ConfigFunctions.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion lib/Constants.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
def VersionNumber():
return "1.1.4.0"
return "1.1.5.0"
Binary file modified lib/Constants.pyc
Binary file not shown.
21 changes: 17 additions & 4 deletions lib/DBFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from Logger import LogEvent
import urllib
import json
import Notifications

def GetGamesFromTerm(term):
db_path = os.path.join(os.path.abspath(""),"Gamez.db")
Expand Down Expand Up @@ -121,17 +122,29 @@ def GetRequestedGamesAsArray():
cursor.close()
return result

def UpdateStatus(game_id,status):
def UpdateStatus(game_id,status,appPath):
LogEvent("Update status of game to " + status)
db_path = os.path.join(os.path.abspath(""),"Gamez.db")
sql = "update requested_games set status='" + status + "' where ID='" + game_id + "'"
game_name = ""
system = ""
sql = "select game_name,system from requested_games where ID='" + game_id + "'"
connection = sqlite3.connect(db_path)
cursor = connection.cursor()
cursor.execute(sql)
result = cursor.fetchall()
tables = list()
for record in result:
game_name = str(record[0])
system = str(record[1])
cursor.close()
sql = "update requested_games set status='" + status + "' where game_name = '" + game_name + "' and system = '" + system + "'"
connection = sqlite3.connect(db_path)
cursor = connection.cursor()
cursor.execute(sql)
connection.commit()
cursor.close()

Notifications.HandleNotifications(game_id,status)
message = "Gamez Notification: " + system + " Game: " + game_name + " has been " + status
Notifications.HandleNotifications(status,message,appPath)
return

def ValidateDB():
Expand Down
Binary file modified lib/DBFunctions.pyc
Binary file not shown.
27 changes: 20 additions & 7 deletions lib/Notifications.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
import DBFunctions
import ConfigParser
import os
import prowlpy
from Logger import LogEvent

def LogEvent(message):
DBFunctions.AddEventToDB(message)
return

def ClearLog():
ClearDBLog()
def HandleNotifications(status,message,appPath):
config = ConfigParser.RawConfigParser()
configFilePath = os.path.join(appPath,'Gamez.ini')
config.read(configFilePath)
prowlApi = config.get('Notifications','prowl_api').replace('"','')
if(prowlApi <> ""):
SendNotificationToProwl(status,message,prowlApi)
return

def SendNotificationToProwl(status,message,prowlApi):
prowl = prowlpy.Prowl(prowlApi)
try:
prowl.add('Gamez',status,message,1,None,"http://www.prowlapp.com/")
LogEvent("Prowl Notification Sent")
except Exception,msg:
LogEvent("Prowl Notification Error: " + msg)
return
Binary file added lib/Notifications.pyc
Binary file not shown.
14 changes: 12 additions & 2 deletions lib/WebRoot.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,12 @@ def settings(self):
<label>Gamez Port</label>
<input type="text" name="cherrypyPort" id="cherrypyPort" value='""" + config.get('global','server.socket_port').replace('"','') + """' />
<label>Gamez Username</label>
<input type="text" name="gamezUsername" id="gamezUsername" value='""" + config.get('global','user_name').replace('"','') + """' />
<label>Gamez Port</label>
<input type="text" name="gamezPassword" id="gamezPassword" value='""" + config.get('global','password').replace('"','') + """' />
<label>Download Interval (In Seconds)</label>
<input type="text" name="downloadInterval" id="downloadInterval" value='""" + config.get('Scheduler','download_interval').replace('"','') + """' />
Expand Down Expand Up @@ -482,7 +488,7 @@ def updatestatus(self,game_id='',status=''):
if(os.name <> 'nt'):
os.chdir(WebRoot.appPath)
if(status <> ''):
UpdateStatus(game_id,status)
UpdateStatus(game_id,status,WebRoot.appPath)
raise cherrypy.InternalRedirect('/')

@cherrypy.expose
Expand Down Expand Up @@ -518,7 +524,7 @@ def upgradetolatestversion(self,verification):
raise cherrypy.InternalRedirect("/?status_message=" + status)

@cherrypy.expose
def savesettings(self,cherrypyHost='', nzbMatrixUsername='', downloadInterval=3600, sabPort='', nzbMatrixApi='', sabApi='', cherrypyPort='', sabHost='',gamezApiKey='',newznabHost='',newznabPort='',newznabApi='',newznabWiiCat='',newznabXbox360Cat='',prowlApi=''):
def savesettings(self,cherrypyHost='', nzbMatrixUsername='', downloadInterval=3600, sabPort='', nzbMatrixApi='', sabApi='', cherrypyPort='', sabHost='',gamezApiKey='',newznabHost='',newznabPort='',newznabApi='',newznabWiiCat='',newznabXbox360Cat='',prowlApi='',gamezUsername='',gamezPassword=''):
cherrypyHost = '"' + cherrypyHost + '"'
nzbMatrixUsername = '"' + nzbMatrixUsername + '"'
nzbMatrixApi = '"' + nzbMatrixApi + '"'
Expand All @@ -530,11 +536,15 @@ def savesettings(self,cherrypyHost='', nzbMatrixUsername='', downloadInterval=36
newznabWiiCat = '"' + newznabWiiCat + '"'
newznabXbox360Cat = '"' + newznabXbox360Cat + '"'
prowlApi = '"' + prowlApi + '"'
gamezUsername = '"' + gamezUsername + '"'
gamezPassword = '"' + gamezPassword + '"'
config = ConfigParser.RawConfigParser()
configFilePath = os.path.join(WebRoot.appPath,'Gamez.ini')
config.read(configFilePath)
config.set('global','server.socket_host',cherrypyHost)
config.set('global','server.socket_port',cherrypyPort)
config.set('global','user_name',gamezUsername)
config.set('global','password',gamezPassword)
config.set('NZBMatrix','username',nzbMatrixUsername)
config.set('NZBMatrix','api_key',nzbMatrixApi)
config.set('Sabnzbd','host',sabHost)
Expand Down
Binary file modified lib/WebRoot.pyc
Binary file not shown.
Binary file added prowlpy/__init__.pyc
Binary file not shown.
Binary file added prowlpy/prowlpy.pyc
Binary file not shown.

0 comments on commit 62df0d9

Please sign in to comment.