Skip to content
Draft
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
7 changes: 4 additions & 3 deletions mig/server/checkconf.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# --- BEGIN_HEADER ---
#
# checkconf - check MiGserver.conf file
# Copyright (C) 2003-2024 The MiG Project lead by Brian Vinter
# Copyright (C) 2003-2026 The MiG Project by the Science HPC Center at UCPH
#
# This file is part of MiG.
#
Expand All @@ -20,7 +20,8 @@
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
#
# -- END_HEADER ---
#
Expand Down Expand Up @@ -53,7 +54,7 @@
"""Print usage help"""

return """Usage: checkconf.py [server_conf]
The script checks the default MiG server configuration or server_conf for errors."""

Check warning on line 57 in mig/server/checkconf.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (84 > 80 characters)


def ask_reply(question):
Expand Down Expand Up @@ -117,7 +118,7 @@

attrs = []
ignore_attrs = ['__class__', '__doc__', '__module__']
path_re = re.compile('(' + os.sep + "[\w\._-]*)+$")
path_re = re.compile(r'(%s[\w\._-]*)+$' % os.sep)

_logger = conf.logger
_logger.info('Checking configuration paths in %s ...', conf_file)
Expand Down Expand Up @@ -158,7 +159,7 @@
else:
_logger.warning('%s: %s does not exist!', name, val)
print('* WARNING *: %s: %s does not exist!' % (name, val))
if not path in missing_paths:

Check warning on line 162 in mig/server/checkconf.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

test for membership should be 'not in'
missing_paths.append(path)
warnings += 1

Expand All @@ -177,12 +178,12 @@
for path in missing_paths:
if ALWAYS == answer:

# 'always' answer reults in default type for all missing entries

Check warning on line 181 in mig/server/checkconf.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (84 > 80 characters)

path_type = None
elif YES == answer:
path_type = \
ask_reply('Create %s as a (d)irectory, (f)ile or (p)ipe? [D/f/p] '

Check warning on line 186 in mig/server/checkconf.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (90 > 80 characters)
% path)
if not path_type or 'D' == path_type.upper():
try:
Expand Down
7 changes: 4 additions & 3 deletions mig/server/chksidroot.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env -S python -u
# -*- coding: utf-8 -*-
#
# --- BEGIN_HEADER ---
#
# chksidroot - Simple Apache httpd SID chroot helper daemon
# Copyright (C) 2003-2025 The MiG Project by the Science HPC Center at UCPH
# Copyright (C) 2003-2026 The MiG Project by the Science HPC Center at UCPH
#
# This file is part of MiG.
#
Expand All @@ -20,7 +20,8 @@
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
#
# -- END_HEADER ---
#
Expand Down Expand Up @@ -98,7 +99,7 @@
chksidroot_stdin = sys.stdin

addr_path_pattern = re.compile(
"^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})::(/.*)$")
r"^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})::(/.*)$")
keep_running = True
if verbose:
print('Reading commands from sys stdin')
Expand Down Expand Up @@ -209,7 +210,7 @@
is_file = not os.path.isdir(real_target)
base_path = real_target
else:
logger.warning("could not narrow down base root link from %s: %r" %

Check warning on line 213 in mig/server/chksidroot.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (83 > 80 characters)
(client_ip, link_target))

# We manually expand sid base.
Expand All @@ -232,7 +233,7 @@
# IMPORTANT: use path and not real_path here in order to test both
if not valid_user_path(configuration, path, base_path,
allow_equal=is_file, apache_scripts=True):
logger.error("request from %s is outside sid chroot %s: %r (%r)" %

Check warning on line 236 in mig/server/chksidroot.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (82 > 80 characters)
(client_ip, base_path, raw_path, real_path))
print(INVALID_MARKER)
continue
Expand Down
7 changes: 4 additions & 3 deletions mig/server/chkuserroot.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env -S python -u
# -*- coding: utf-8 -*-
#
# --- BEGIN_HEADER ---
#
# chkuserroot - Simple Apache httpd user chroot helper daemon
# Copyright (C) 2003-2025 The MiG Project by the Science HPC Center at UCPH
# Copyright (C) 2003-2026 The MiG Project by the Science HPC Center at UCPH
#
# This file is part of MiG.
#
Expand All @@ -20,7 +20,8 @@
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
#
# -- END_HEADER ---
#
Expand Down Expand Up @@ -99,7 +100,7 @@
chkuserroot_stdin = sys.stdin

addr_path_pattern = re.compile(
"^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})::(/.*)$")
r"^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})::(/.*)$")
keep_running = True
if verbose:
print('Reading commands from sys stdin')
Expand Down Expand Up @@ -159,7 +160,7 @@
continue
elif not check_account_accessible(configuration, user_id, 'https'):
# Only warn to avoid excessive noise from scanners
logger.warning("path from %s in inaccessible %s account: %r (%r)"

Check warning on line 163 in mig/server/chkuserroot.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (81 > 80 characters)
% (client_ip, user_id, raw_path, real_path))
print(INVALID_MARKER)
continue
Expand Down
7 changes: 4 additions & 3 deletions mig/server/genjobscriptpython.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
Expand Down Expand Up @@ -138,7 +138,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Check warning on line 141 in mig/server/genjobscriptpython.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (81 > 80 characters)
#
# -- END_HEADER ---
#
Expand Down Expand Up @@ -214,7 +214,7 @@
mig_server_filename = "%s" % parts[0]
try:
resource_filename = "%s" % parts[1]
except:

Check warning on line 217 in mig/server/genjobscriptpython.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

do not use bare 'except'
resource_filename = mig_server_filename

# Source may be external in which case implicit destination needs
Expand Down Expand Up @@ -268,7 +268,7 @@
mig_server_filename = "%s" % parts[0]
try:
resource_filename = "%s" % parts[1]
except:

Check warning on line 271 in mig/server/genjobscriptpython.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

do not use bare 'except'
resource_filename = mig_server_filename

# Source may be external in which case implicit destination needs
Expand Down Expand Up @@ -713,9 +713,10 @@
):
"""Print msg unless last command exitted with successcode"""

cmd = 'if ' + result + ' != ' + successcode + ':\n'
cmd += '\tprint "WARNING: ' + msg + "\(\" + " + result + " + \"\)\"\n"
cmd += '\n'
cmd = r'''
if %s != %s:
print("WARNING: %r \(" + %s + "\)")
''' % (result, successcode, msg, result)
return cmd

def log_on_error(
Expand Down
8 changes: 5 additions & 3 deletions mig/server/genjobscriptsh.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
Expand Down Expand Up @@ -1105,9 +1105,11 @@
):
"""Print msg unless result contains success code"""

cmd = 'if [ $' + result + ' -ne ' + successcode + ' ]; then\n'
cmd += '\techo "WARNING: ' + msg + "\($" + result + "\)\"\n"
cmd += 'fi\n'
cmd = r'''
if [ $%s -ne %s ]; then
echo "WARNING: %r \($%s\)"
fi
''' % (result, successcode, msg, result)
return cmd

def log_on_error(
Expand Down
2 changes: 1 addition & 1 deletion mig/server/grid_openid.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
Expand Down Expand Up @@ -137,7 +137,7 @@

# NOTE: response may contain password on the form
# (<Symbol Bare namespace>, 'password'): 'S3cr3tP4ssw0rd'
pw_pattern = "\(<Symbol Bare namespace>, 'password'\): '(.+)'"
pw_pattern = r"\(<Symbol Bare namespace>, 'password'\): '(.+)'"
pw_regexp = re.compile(pw_pattern)


Expand Down
8 changes: 4 additions & 4 deletions mig/shared/accountreq.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
Expand Down Expand Up @@ -80,7 +80,7 @@
<script type="text/javascript" src="/images/js/jquery.form.js"></script>
<script type="text/javascript" src="/images/js/jquery.accountform.js"></script>
'''
add_init = """
add_init = r"""
/* Helper to define countries for which State field makes sense */
var enable_state = ['US', 'CA', 'AU'];
var peers_mandatory = %(peers_mandatory)s;
Expand Down Expand Up @@ -507,7 +507,7 @@
</div>
"""

email_text_pattern = '.*[^ ]+@[a-zA-Z0-9.-]+\.[a-zA-Z]+.*'
email_text_pattern = r'.*[^ ]+@[a-zA-Z0-9.-]+\.[a-zA-Z]+.*'
if configuration.site_peers_explicit_fields:
# NOTE: dedicated peers field(s) instead of legacy Comment use
comment_add = ''
Expand All @@ -529,7 +529,7 @@
comment_pattern = ''

if 'full_name' in configuration.site_peers_explicit_fields:
html += """
html += r"""
<div class='form-row single-entry %(show_peers_full_name)s'>
<div class='col-md-12 mb-3 form-cell'>
<!-- NOTE: this simple form control just looks for one or more full names.
Expand All @@ -546,7 +546,7 @@
</div>
"""
if 'email' in configuration.site_peers_explicit_fields:
html += """
html += r"""
<div class='form-row single-entry %(show_peers_email)s'>
<div class='col-md-12 mb-3 form-cell'>
<!-- NOTE: this simple form control just looks for one or more emails.
Expand Down
11 changes: 6 additions & 5 deletions mig/shared/functionality/datatransfer.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# --- BEGIN_HEADER ---
#
# datatransfer - import and export data in the backgroud
# Copyright (C) 2003-2023 The MiG Project lead by Brian Vinter
# Copyright (C) 2003-2026 The MiG Project by the Science HPC Center at UCPH
#
# This file is part of MiG.
#
Expand All @@ -20,7 +20,8 @@
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
#
# -- END_HEADER ---
#
Expand Down Expand Up @@ -56,8 +57,8 @@
get_actions = ['show', 'fillimport', 'fillexport']
transfer_actions = ['import', 'export', 'deltransfer', 'redotransfer']
# TODO: add these internal data shuffling targets on a separate tab without
#address and creds
#shuffling_actions = ['move', 'copy', 'unpack', 'pack', 'remove']
# address and creds
# shuffling_actions = ['move', 'copy', 'unpack', 'pack', 'remove']
shuffling_actions = []
key_actions = ['generatekey', 'delkey']
post_actions = transfer_actions + shuffling_actions + key_actions
Expand Down Expand Up @@ -596,7 +597,7 @@
selected = ''
transfer_html += '<option %s value="%s">%s</option>' % \
(selected, key, val)
transfer_html += '''
transfer_html += r'''
</select>
</td></tr>
<tr><td>
Expand Down
2 changes: 1 addition & 1 deletion mig/shared/functionality/docs.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
Expand Down Expand Up @@ -215,7 +215,7 @@
lic_text = ''.join(lic_lines[2:-1])
output_objects.append({'object_type': 'html_form', 'text':
'<code>%s</code><br />' %
lic_text.replace('\n', '<br \>')})
lic_text.replace('\n', '<br />')})

output_objects.append(
{'object_type': 'header', 'text': 'Acknowledgements'})
Expand Down
9 changes: 5 additions & 4 deletions mig/shared/functionality/fileman.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# --- BEGIN_HEADER ---
#
# fileman - File manager UI for browsing and manipulating files and folders
# Copyright (C) 2003-2025 The MiG Project by the Science HPC Center at UCPH
# Copyright (C) 2003-2026 The MiG Project by the Science HPC Center at UCPH
#
# This file is part of MiG.
#
Expand All @@ -20,7 +20,8 @@
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
#
# -- END_HEADER ---
#
Expand Down Expand Up @@ -463,7 +464,7 @@
('%s' % (configuration.site_enable_transfers and legacy_buttons)).lower(),
'enable_gdp':
('%s' % configuration.site_enable_gdp).lower(),
'max_stream_size': 64*1024*1024
'max_stream_size': 64 * 1024 * 1024
}

js_import = '''
Expand All @@ -480,7 +481,7 @@
js_import += '''
csrf_map["%s"] = "%s";
''' % (target_op, token)
js_import += '''
js_import += r'''
</script>
<script type="text/javascript" src="/images/js/jquery.filemanager.js"></script>
<script type="text/javascript" src="/images/js/jquery.tablesorter.js"></script>
Expand Down
38 changes: 24 additions & 14 deletions mig/shared/functionality/reqjupyterservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# --- BEGIN_HEADER ---
#
# reqjupyterservice - Redirect the user to a backend jupyter service host
# Copyright (C) 2003-2021 The MiG Project lead by Brian Vinter
# Copyright (C) 2003-2026 The MiG Project by the Science HPC Center at UCPH
#
# This file is part of MiG.
#
Expand All @@ -20,7 +20,8 @@
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
#
# -- END_HEADER ---
#
Expand All @@ -41,6 +42,7 @@
server can be instantiated and mount the users linked homedrive with the passed
keyset.
"""

from __future__ import print_function
from __future__ import absolute_import

Expand Down Expand Up @@ -116,7 +118,7 @@ def to_unix_account(input_str):
if not isinstance(input_str, basestring) or not input_str:
return None
input_str = input_str.lower()
valid_unix_name = "".join(re.findall('[a-z0-9_.\-]+', input_str))
valid_unix_name = "".join(re.findall(r'[a-z0-9_.\-]+', input_str))
if not valid_unix_name:
return None
return valid_unix_name[:32]
Expand All @@ -135,8 +137,9 @@ def mig_to_mount_adapt(mig):
if "@" in mount_string and ":" in mount_string:
# Expects that the mount_string is in the format
# @mount_url:mount_path
target_host = mount_string[mount_string.index("@")+1:mount_string.index(":")]
target_path = mount_string[mount_string.index(":")+1:]
target_host = mount_string[mount_string.index(
"@") + 1:mount_string.index(":")]
target_path = mount_string[mount_string.index(":") + 1:]

mount = {
'targetHost': target_host,
Expand Down Expand Up @@ -229,6 +232,7 @@ def get_newest_mount(jupyter_mounts):
old_mounts.append(mount)
return latest, old_mounts


@__require_requests
def get_host_from_service(configuration, service, base_url=None):
"""
Expand Down Expand Up @@ -352,6 +356,7 @@ def signature():
}
return ['', defaults]


@__require_requests
def main(client_id, user_arguments_dict):
"""Main function used by front end"""
Expand Down Expand Up @@ -410,7 +415,8 @@ def main(client_id, user_arguments_dict):
)
return (output_objects, returnvalues.SYSTEM_ERROR)

host = get_host_from_service(configuration, service, base_url="/%s" % service["service_name"])
host = get_host_from_service(configuration, service, base_url="/%s" %
service["service_name"])
# Get an active jupyterhost
if not host:
logger.error("No active jupyterhub host could be found")
Expand Down Expand Up @@ -526,8 +532,8 @@ def main(client_id, user_arguments_dict):
workflow_session_id = get_workflow_session_id(configuration,
client_id)
if not workflow_session_id:
workflow_session_id = create_workflow_session_id(configuration,
client_id)
workflow_session_id = create_workflow_session_id(
configuration, client_id)
# TODO get these dynamically
workflows_url = configuration.migserver_https_sid_url + \
'/cgi-sid/jsoninterface.py?output_format=json'
Expand All @@ -543,10 +549,12 @@ def main(client_id, user_arguments_dict):
# Refresh cookies
session.get(url_hub)
# Authenticate and submit data
response = jupyterhub_session_post_request(session, url_auth, headers=auth_header)
response = jupyterhub_session_post_request(session, url_auth,
headers=auth_header)
if response.status_code == 200:
for user_data_type, user_data in user_post_data.items():
response = jupyterhub_session_post_request(session, url_data, json={user_data_type: user_data})
response = jupyterhub_session_post_request(
session, url_data, json={user_data_type: user_data})
if response.status_code != 200:
logger.error(
"Jupyter: User %s failed to submit data %s to %s"
Expand All @@ -562,7 +570,7 @@ def main(client_id, user_arguments_dict):

# Create a new keyset
# Create login session id
session_id = generate_random_ascii(2*session_id_bytes,
session_id = generate_random_ascii(2 * session_id_bytes,
charset='0123456789abcdef')

# Generate private/public keys
Expand Down Expand Up @@ -654,13 +662,15 @@ def main(client_id, user_arguments_dict):
# Refresh cookies
session.get(url_hub)
# Authenticate
response = jupyterhub_session_post_request(session, url_auth, headers=auth_header)
response = jupyterhub_session_post_request(session, url_auth,
headers=auth_header)
if response.status_code == 200:
for user_data_type, user_data in user_post_data.items():
response = jupyterhub_session_post_request(session, url_data, json={user_data_type: user_data})
response = jupyterhub_session_post_request(
session, url_data, json={user_data_type: user_data})
if response.status_code != 200:
logger.error("Jupyter: User %s failed to submit data %s to %s"
% (client_id, user_data, url_data))
% (client_id, user_data, url_data))
else:
logger.error("Jupyter: User %s failed to authenticate against %s"
% (client_id, url_auth))
Expand Down
Loading
Loading