Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
FROM python:2-alpine
MAINTAINER Cat'Killer <catkiller@catkiller.org>

# The "exec" plugins are all written in bash and won't
# work with bourne. Install bash to ensure they work.
RUN apk add --no-cache bash
FROM python:3.12.0-slim-bookworm
WORKDIR /app

# gcc and other build tools not in alpine. Add them as virtual packages, build Twisted and delete them.
RUN apk add --no-cache --virtual .build-deps gcc musl-dev
RUN pip install --upgrade pip
RUN pip install typing
RUN pip install twisted
RUN apk del .build-deps
COPY requirements.txt /app

WORKDIR /app
RUN pip install -r requirements.txt

COPY config.py /app/config.py
COPY phxd /app/phxd
Expand Down
1 change: 1 addition & 0 deletions config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
import os
################################################################################
# database configuration
Expand Down
4 changes: 3 additions & 1 deletion configure_phxd.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
TODO: This is unecessarily complex. Need to use a
better config file format instead
"""
from __future__ import absolute_import
from __future__ import print_function
__author__ = "Cat'Killer"
__version__ = "0.0.1"
__license__ = "WTFPL"
Expand Down Expand Up @@ -55,7 +57,7 @@ def rewrite_config_file(filepath, values_dict):
"""
if not values_dict:
return
keys = values_dict.keys()
keys = list(values_dict.keys())
with open(filepath, 'r') as config_file:
config_str = config_file.read()
with tempfile.NamedTemporaryFile(delete=False) as tmpconfig:
Expand Down
12 changes: 7 additions & 5 deletions phxd
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env python

from __future__ import absolute_import
from __future__ import print_function
from twisted.internet import reactor
from server.HLServer import HLServer
from shared.HLTypes import *
Expand All @@ -8,11 +10,11 @@ import server.handlers
serv = HLServer()

for modName in server.handlers.__all__:
try:
mod = __import__( "server.handlers.%s" % modName , None , None , "server.handlers" )
mod.installHandler( serv )
except ImportError:
print "error importing server.handlers.%s" % modName
try:
mod = __import__( "server.handlers.%s" % modName , None , None , "server.handlers" )
mod.installHandler( serv )
except ImportError:
print("error importing server.handlers.%s" % modName)

serv.logEvent( LOG_TYPE_GENERAL , "Server started on port %d" % serv.port )
reactor.run()
Expand Down
92 changes: 47 additions & 45 deletions server/HLDatabase.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,53 @@
from __future__ import absolute_import
from __future__ import print_function
from shared.HLTypes import *
import server.database

def getDatabase( type ):
""" Returns a HLDatabase subclass based on the type string (used as a prefix). """
cls = "%sDatabase" % type
try:
mod = __import__( "server.database.%s" % cls , None , None , "server.database" )
db = eval( "mod.%s()" % cls )
return db
except ImportError:
print "error importing server.database.%s" % cls
return None
""" Returns a HLDatabase subclass based on the type string (used as a prefix). """
cls = "%sDatabase" % type
try:
mod = __import__( "server.database.%s" % cls , None , None , "server.database" )
db = eval( "mod.%s()" % cls )
return db
except ImportError:
print("error importing server.database.%s" % cls)
return None

class HLDatabase:
""" Base class for phxd database implementations. Should be overridden by classes in the database directory. """
def __init__( self ):
pass
def loadAccount( self , login ):
""" Creates a new HLAccount object and loads information for the specified login into it. Returns None if unsuccessful. """
return None
def saveAccount( self , acct ):
""" Saves the specified HLAccount object to the database. If the HLAccount has a non-zero ID, the information is updated, otherwise a new account is inserted. """
pass
def deleteAccount( self , login ):
""" Deletes an account with the specified login from the database. """
return False
def updateAccountStats( self , login , downloaded , uploaded , setDate = False ):
""" Updates statistics for an account in the database. """
pass
def loadNewsPosts( self , limit = 0 ):
""" Loads and returns a list of HLNewsPost objects from the database. If limit > 0, the returned list will contain no more than limit posts. """
return []
def saveNewsPost( self , post ):
""" Saves a HLNewsPost object to the database. """
pass
def checkBanlist( self , addr ):
""" Checks the banlist table, returns a reason, or None if no entry was found. """
return None
def logEvent( self , type , event , login = "" , nick = "" , ip = "" ):
""" Logs an event to the database (see HLTypes for log types). """
pass
""" Base class for phxd database implementations. Should be overridden by classes in the database directory. """
def __init__( self ):
pass
def loadAccount( self , login ):
""" Creates a new HLAccount object and loads information for the specified login into it. Returns None if unsuccessful. """
return None
def saveAccount( self , acct ):
""" Saves the specified HLAccount object to the database. If the HLAccount has a non-zero ID, the information is updated, otherwise a new account is inserted. """
pass
def deleteAccount( self , login ):
""" Deletes an account with the specified login from the database. """
return False
def updateAccountStats( self , login , downloaded , uploaded , setDate = False ):
""" Updates statistics for an account in the database. """
pass
def loadNewsPosts( self , limit = 0 ):
""" Loads and returns a list of HLNewsPost objects from the database. If limit > 0, the returned list will contain no more than limit posts. """
return []
def saveNewsPost( self , post ):
""" Saves a HLNewsPost object to the database. """
pass
def checkBanlist( self , addr ):
""" Checks the banlist table, returns a reason, or None if no entry was found. """
return None
def logEvent( self , type , event , login = "" , nick = "" , ip = "" ):
""" Logs an event to the database (see HLTypes for log types). """
pass
19 changes: 10 additions & 9 deletions server/HLDatabaseLogger.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from __future__ import absolute_import
from logging import Handler

class HLDatabaseLogger( Handler ):
def __init__( self , db ):
Handler.__init__( self )
self.db = db
def emit( self , record ):
if record.args:
( type , msg , login , nick , ip ) = record.args
self.db.logEvent( type , msg , login , nick , ip )
def __init__( self , db ):
Handler.__init__( self )
self.db = db
def emit( self , record ):
if record.args:
( type , msg , login , nick , ip ) = record.args
self.db.logEvent( type , msg , login , nick , ip )
Loading