mirror of
https://github.com/dkmstr/openuds.git
synced 2024-12-22 13:34:04 +03:00
Refactor variable names for logging in auth.py and log.py
This commit is contained in:
parent
c42b5f270b
commit
dd71811045
@ -57,7 +57,7 @@ if typing.TYPE_CHECKING:
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
authLogger = logging.getLogger('authLog')
|
||||
auth_logger = logging.getLogger('authLog')
|
||||
|
||||
|
||||
RT = typing.TypeVar('RT')
|
||||
@ -506,7 +506,7 @@ def log_login(
|
||||
|
||||
log_level = types.log.LogLevel.ERROR if as_error else types.log.LogLevel.INFO
|
||||
|
||||
authLogger.info(
|
||||
auth_logger.info(
|
||||
'|'.join(
|
||||
[
|
||||
authenticator.name,
|
||||
|
@ -49,7 +49,7 @@ except ImportError:
|
||||
if typing.TYPE_CHECKING:
|
||||
from django.db.models import Model
|
||||
|
||||
useLogger = logging.getLogger('useLog')
|
||||
use_logger = logging.getLogger('useLog')
|
||||
|
||||
|
||||
# Pattern for look for date and time in this format: 2023-04-20 04:03:08,776 (and trailing spaces)
|
||||
@ -84,7 +84,7 @@ def log_use(
|
||||
userServiceName = 'unknown' if userServiceName is None else userServiceName
|
||||
poolName = 'unknown' if poolName is None else poolName
|
||||
|
||||
useLogger.info(
|
||||
use_logger.info(
|
||||
'|'.join(
|
||||
[
|
||||
type_,
|
||||
|
@ -53,7 +53,7 @@ ReportAutoModel = typing.Union[
|
||||
models.Provider,
|
||||
]
|
||||
|
||||
reportAutoModelDct: collections.abc.Mapping[str, type[ReportAutoModel]] = {
|
||||
REPORT_AUTOMODEL: typing.Final[collections.abc.Mapping[str, type[ReportAutoModel]]] = {
|
||||
'ServicePool': models.ServicePool,
|
||||
'Authenticator': models.Authenticator,
|
||||
'Service': models.Service,
|
||||
@ -121,7 +121,7 @@ class ReportAuto(Report, metaclass=ReportAutoType):
|
||||
def getModel(self) -> type[ReportAutoModel]:
|
||||
data_source = self.data_source.split('.', maxsplit=1)[0]
|
||||
|
||||
return reportAutoModelDct[data_source]
|
||||
return REPORT_AUTOMODEL[data_source]
|
||||
|
||||
def init_gui(self) -> None:
|
||||
# Fills datasource
|
||||
|
@ -7,58 +7,66 @@ import os
|
||||
import errno
|
||||
import pwd
|
||||
|
||||
def logError(err):
|
||||
def log_error(err, username: str = None):
|
||||
with open('/tmp/uds-x2go-error-{}.log'.format(username or None), 'a') as f:
|
||||
f.write(err)
|
||||
|
||||
print(err)
|
||||
|
||||
|
||||
def updateAuthorizedKeys(user, pubKey):
|
||||
def update_authorized_keys(username, pubKey):
|
||||
# No X2Go server on windows
|
||||
if 'win' in sys.platform:
|
||||
logError('Not a linux platform')
|
||||
log_error('Not a linux platform')
|
||||
return
|
||||
|
||||
userInfo = pwd.getpwnam(user)
|
||||
user_info = pwd.getpwnam(username)
|
||||
user_info.
|
||||
|
||||
# Create .ssh on user home
|
||||
home = userInfo.pw_dir.rstrip('/')
|
||||
home = user_info.pw_dir.rstrip('/')
|
||||
|
||||
if not os.path.exists(home): # User not found, nothing done
|
||||
logError('Home folder for user {} not found'.format(user))
|
||||
log_error('Home folder for user {} not found'.format(username))
|
||||
return
|
||||
|
||||
uid = userInfo.pw_uid
|
||||
uid = user_info.pw_uid
|
||||
|
||||
sshFolder = '{}/.ssh'.format(home)
|
||||
if not os.path.exists(sshFolder):
|
||||
ssh_folder = '{}/.ssh'.format(home)
|
||||
if not os.path.exists(ssh_folder):
|
||||
try:
|
||||
os.makedirs(sshFolder, 0o700)
|
||||
os.chown(sshFolder, uid, -1)
|
||||
os.makedirs(ssh_folder, 0o700)
|
||||
os.chown(ssh_folder, uid, -1)
|
||||
except OSError as e:
|
||||
if e.errno != errno.EEXIST:
|
||||
logError('Error creating .ssh folder for user {}: {}'.format(user, e))
|
||||
log_error('Error creating .ssh folder for user {}: {}'.format(username, e), username)
|
||||
return
|
||||
# Folder has been created in between test & creation, thats ok
|
||||
|
||||
authorizedKeys = '{}/authorized_keys'.format(sshFolder)
|
||||
authorized_keys = '{}/authorized_keys'.format(ssh_folder)
|
||||
try:
|
||||
with open(authorizedKeys, 'r') as f:
|
||||
with open(authorized_keys, 'r') as f:
|
||||
lines = f.readlines()
|
||||
except Exception:
|
||||
lines = []
|
||||
|
||||
with open(authorizedKeys, 'w') as f:
|
||||
for line in lines:
|
||||
if 'UDS@X2GOCLIENT' not in line and line.strip():
|
||||
f.write(line)
|
||||
with open(authorized_keys, 'w') as f:
|
||||
f.writelines(
|
||||
filter(
|
||||
lambda x: 'UDS@X2GOCLIENT' not in x and x.strip(),
|
||||
lines
|
||||
)
|
||||
)
|
||||
# Append pubkey
|
||||
f.write('ssh-rsa {} UDS@X2GOCLIENT\n'.format(pubKey))
|
||||
|
||||
# Ensure access is correct
|
||||
os.chown(authorizedKeys, uid, -1)
|
||||
os.chmod(authorizedKeys, 0o600)
|
||||
os.chown(authorized_keys, uid, -1)
|
||||
os.chmod(authorized_keys, 0o600)
|
||||
|
||||
# Done
|
||||
|
||||
|
||||
# __USER__ and __KEY__ will be replaced by the real values, they are placeholders (and must be left as is)
|
||||
updateAuthorizedKeys('__USER__', '__KEY__')
|
||||
# __USER__ and __KEY__ will be replaced by the real values,
|
||||
# # they are placeholders for the real values so keep them.
|
||||
update_authorized_keys('__USER__', '__KEY__')
|
||||
|
Loading…
Reference in New Issue
Block a user