Submit
Path:
~
/
/
opt
/
alt
/
python37
/
lib
/
python3.7
/
site-packages
/
File Content:
cllicenselib.py
# -*- coding: utf-8 -*- # CL LICENSE CHECK python lib # # Copyright © Cloud Linux GmbH & Cloud Linux Software, Inc 2010-2019 All Rights Reserved # # Licensed under CLOUD LINUX LICENSE AGREEMENT # http://cloudlinux.com/docs/LICENSE.TXT # CLASSES: # # LicenseData - main class for CL licence check # : check_license # : get_ip # : date_format # : open_letter_template # : format_letter # # FUNCTIONS: # # License update cron : update_license_timestamp_file # License update new key : update license with new key # Check license : check_license # Return Last License check date : last_license_check # Return Template to display : return_template_to_display from __future__ import print_function from __future__ import absolute_import from future.moves.urllib import request, error import os, sys, subprocess, struct, time, datetime, socket import cldetectlib as detect from clcommon.utils import mod_makedirs from clcommon.lib.cledition import is_cl_solo_edition RHN_CHECK_FILE = '/usr/sbin/rhn_check' RHN_UPDATE_NEW_KEY = '/usr/sbin/rhnreg_ks' LICENSE_TIMESTAMP_FILE = '/var/lve/lveinfo.ver' LICENSE_TIMESTAMP_DIR = os.path.dirname(LICENSE_TIMESTAMP_FILE) RHN_DIRECTORY = '/etc/sysconfig/rhn' RHN_SYSTEMID = os.path.join(RHN_DIRECTORY, 'systemid') JWT_TOKEN = os.path.join(RHN_DIRECTORY, 'jwt.token') JWT_TOKEN_TIMESTAMP_FILE = os.path.join(LICENSE_TIMESTAMP_DIR, 'jwt_last_update_ts') # 1h if solo else 3 days CACHE_TIME = 3600 if is_cl_solo_edition(skip_jwt_check=True) else 259200 JWT_UPDATE_INTERVAL = 3600 * 4 NO_VALID_LICENSE_FOUND_TEMPLATE = '/usr/share/cloudlinux/no_valid_license_screen.txt' LICENSE_OUT_OF_DATE_EMAIL_TEMPLATE = '/usr/share/cloudlinux/license_out_of_date_email.txt' TEMPLATES = { 'Email': { 'template_file': LICENSE_OUT_OF_DATE_EMAIL_TEMPLATE, 'error_msg': 'Error: License out of date, email template missing.' }, 'NoValid': { 'template_file': NO_VALID_LICENSE_FOUND_TEMPLATE, 'error_msg': 'Error: No valid license found, template is missing.' } } SHOW_IP_LINK = 'http://cloudlinux.com/showip.php' # License Data Class class LicenseData: _license_last_timestamp = '' _server_ip = '' _letter_template = '' @staticmethod def _is_license_needs_update(license_timestamp_file): """ Update license when: in case JWT token present: - if no timestamp file with jwt token last update time - if jwt token was not updated during last 4 hours - if jwt token was updated later than our timestamp in file in case JWT token is not present, but systemid exists (fallback for licensing w/o token) - update license only if systemid was changed after last timestamp update when no jwt and no systemid - re-update license """ if os.path.exists(JWT_TOKEN): if not os.path.exists(JWT_TOKEN_TIMESTAMP_FILE): return True rhn_updated = int(os.path.getmtime(JWT_TOKEN)) if rhn_updated < int(time.time()) - JWT_UPDATE_INTERVAL: return True jwt_last_update_timestamp = read_time_from_file(JWT_TOKEN_TIMESTAMP_FILE) if jwt_last_update_timestamp < rhn_updated: return True return False elif os.path.exists(RHN_SYSTEMID): rhn_updated = os.path.getmtime(RHN_SYSTEMID) return rhn_updated > os.path.getmtime(license_timestamp_file) return True def check_license(self, license_timestamp_file): """ Checks license: 1. Reads cache file with timestamp 2. Ensures license must be re-checked: - if timestamp in cache file > CACHE_TIME -> check if we need to re-update licensing """ try: # Get timestamp of last license check self._license_last_timestamp = read_time_from_file(license_timestamp_file) if (int(time.time()) - self._license_last_timestamp) > CACHE_TIME: if self._is_license_needs_update(license_timestamp_file): return update_license_timestamp_file() # because if server does not have jwt token and license is not needed update # consider no license return os.path.exists(JWT_TOKEN) else: return True except (IOError, struct.error): return False # Get IP def get_ip(self): if not self._server_ip: try: self._server_ip = request.urlopen(SHOW_IP_LINK).read().strip() except error.URLError as e: print('Error: Get server IP. ' + str(e)) sys.exit(1) # Format Date def date_format(self, format): return datetime.datetime.fromtimestamp(self._license_last_timestamp).strftime(format) # Open letter template def open_letter_template(self, template): try: self._letter_template = open(template, "r").read() except IOError as e: print('Error: Failed to open template file. ' +str(e)) sys.exit(1) # Format Screen def format_letter(self): admin_email = detect.getCPAdminEmail() if admin_email: self.get_ip() if not self._license_last_timestamp: return self._letter_template.replace('%LIC_DATE%','').replace('%IP%',self._server_ip).replace('%HOSTNAME%',socket.gethostname()).replace('%FROM%',admin_email) else: return self._letter_template.replace('%LIC_DATE%',' since ' + self.date_format('%b %d, %y')).replace('%IP%',self._server_ip).replace('%HOSTNAME%',socket.gethostname()).replace('%FROM%',admin_email) else: return None # License Data Class Object License = LicenseData() def read_time_from_file(file: str): with open(file, 'rb') as f: return struct.unpack('i', f.read())[0] def write_time_to_file(file: str, timestamp: int): with open(file, 'wb') as f: f.write(struct.pack('i', timestamp)) # License update cron def update_license_timestamp_file(): try: if not os.path.isdir(LICENSE_TIMESTAMP_DIR): mod_makedirs(LICENSE_TIMESTAMP_DIR, 0o755) p = subprocess.Popen([RHN_CHECK_FILE], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) (out, err) = p.communicate() if p.returncode == 0: write_time_to_file(LICENSE_TIMESTAMP_FILE, int(time.time())) if os.path.exists(JWT_TOKEN): write_time_to_file(JWT_TOKEN_TIMESTAMP_FILE, int(os.path.getmtime(JWT_TOKEN))) return True return False except (OSError, IOError): return False # update license with new key def update_license_with_key(key): try: if not os.path.isdir(LICENSE_TIMESTAMP_DIR): mod_makedirs(LICENSE_TIMESTAMP_DIR, 0o755) p = subprocess.Popen([RHN_UPDATE_NEW_KEY, '--activationkey='+key, '--force'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) (out, err) = p.communicate() if p.returncode == 0: write_time_to_file(LICENSE_TIMESTAMP_FILE, int(time.time())) if os.path.exists(JWT_TOKEN): write_time_to_file(JWT_TOKEN_TIMESTAMP_FILE, int(os.path.getmtime(JWT_TOKEN))) print('OK') return True else: print(out.strip()) return False except (OSError, IOError): print('Error: New key activation failed, please try again later.') return False # Returns: # True == license is Ok # False == license expired or not found def check_license(): # Check for license timestamp file in /var/lve/lveinfo.ver if os.path.isfile(LICENSE_TIMESTAMP_FILE): return License.check_license(LICENSE_TIMESTAMP_FILE) # try to re-update license file if jwt token is present # or systemid file as fallback when jwt absent (goDaddy) elif os.path.exists(JWT_TOKEN) or os.path.exists(RHN_SYSTEMID): return update_license_timestamp_file() return False # Return Last license check Date def last_license_check(is_valid): if is_valid: return 'OK' # Check for license timestamp file in /var/lve/lveinfo.ver if os.path.isfile(LICENSE_TIMESTAMP_FILE): return 'No valid license found, last successful check was on ' + License.date_format('%b %d, %y') else: return 'No valid license found.' def get_email_template(): return get_template_to_display(TEMPLATES['Email']) def get_novalid_template(): return get_template_to_display(TEMPLATES['NoValid']) # Return Template Email, No Valid license found template. def get_template_to_display(template): # check for template in /usr/share/cloudlinux if os.path.isfile(template['template_file']): if check_license(): return None else: # set template text into License class attr. License.open_letter_template(template['template_file']) # Return Formatted Template return License.format_letter() else: return template['error_msg']
Submit
FILE
FOLDER
Name
Size
Permission
Action
Babel-2.9.1-py3.7.egg-info
---
0755
Beaker-1.11.0-py3.7.egg-info
---
0755
Jinja2-3.0.3-py3.7.egg-info
---
0755
Mako-1.1.0-py3.7.egg-info
---
0755
OpenSSL
---
0755
Paste-1.7.5.1-py3.7.egg-info
---
0755
PyJWT-1.7.1-py3.7.egg-info
---
0755
Tempita-0.5.1-py3.7.egg-info
---
0755
__pycache__
---
0755
_distutils_hack
---
0755
aiosignal
---
0755
aiosignal-1.2.0a0-py3.7.egg-info
---
0755
alembic
---
0755
alembic-0.8.3-py3.7.egg-info
---
0755
asn1crypto
---
0755
asn1crypto-0.22.0-py3.7.egg-info
---
0755
async_timeout
---
0755
async_timeout-4.0.2-py3.7.egg-info
---
0755
attr
---
0755
attrs-17.4.0-py3.7.egg-info
---
0755
babel
---
0755
beaker
---
0755
beautifulsoup4-4.5.1-py3.7.egg-info
---
0755
bs4
---
0755
certifi
---
0755
certifi-2018.4.16-py3.7.egg-info
---
0755
chardet
---
0755
chardet-3.0.4-py3.7.egg-info
---
0755
charset_normalizer
---
0755
charset_normalizer-2.0.12-py3.7.egg-info
---
0755
cl_dom_collector
---
0755
clcommon
---
0755
clconfig
---
0755
clconfigure
---
0755
cldashboard
---
0755
clevents
---
0755
cllicense
---
0755
cllimits
---
0755
cllimits_validator
---
0755
cllimitslib_v2
---
0755
clpackages
---
0755
clquota
---
0755
clselect
---
0755
clselector
---
0755
clsentry
---
0755
clsummary
---
0755
clveconfig
---
0755
clwizard
---
0755
clwpos
---
0755
cssselect
---
0755
cssselect-0.9.2-py3.7.egg-info
---
0755
distlib
---
0755
docopt-0.6.2-py3.7.egg-info
---
0755
filelock
---
0755
filelock-0.0.0-py3.7.egg-info
---
0755
future
---
0755
future-0.17.0-py3.7.egg-info
---
0755
html5lib
---
0755
html5lib-1.0.1-py3.7.egg-info
---
0755
idna
---
0755
idna-2.5-py3.7.egg-info
---
0755
importlib_metadata
---
0755
importlib_metadata-0.0.0-py3.7.egg-info
---
0755
jinja2
---
0755
jsonschema
---
0755
jsonschema-3.2.0-py3.7.egg-info
---
0755
jwt
---
0755
libfuturize
---
0755
libpasteurize
---
0755
lve_utils
---
0755
lvemanager
---
0755
lvestats
---
0755
mako
---
0755
nose
---
0755
nose-1.3.7-py3.7.egg-info
---
0755
packaging
---
0755
packaging-16.8-py3.7.egg-info
---
0755
past
---
0755
paste
---
0755
pip
---
0755
pip-20.2.4.dist-info
---
0755
pkg_resources
---
0755
platformdirs
---
0755
platformdirs-0.0.0-py3.7.egg-info
---
0755
ply
---
0755
ply-3.8-py3.7.egg-info
---
0755
prettytable-0.7.2-py3.7.egg-info
---
0755
pyOpenSSL-17.3.0-py3.7.egg-info
---
0755
pycparser
---
0755
pycparser-2.14-py3.7.egg-info
---
0755
pyparsing-2.1.10-py3.7.egg-info
---
0755
python_editor-0.4-py3.7.egg-info
---
0755
pytz
---
0755
pytz-2017.2-py3.7.egg-info
---
0755
raven
---
0755
raven-6.3.0-py3.7.egg-info
---
0755
requests
---
0755
requests-2.26.0-py3.7.egg-info
---
0755
schema-0.7.1-py3.7.egg-info
---
0755
sentry_sdk
---
0755
sentry_sdk-0.19.4-py3.7.egg-info
---
0755
setuptools
---
0755
setuptools-58.3.0.dist-info
---
0755
six-1.15.0-py3.7.egg-info
---
0755
ssa
---
0755
svgwrite
---
0755
svgwrite-1.3.0-py3.7.egg-info
---
0755
tempita
---
0755
typing_extensions-3.7.4.3-py3.7.egg-info
---
0755
urllib3
---
0755
urllib3-1.26.6-py3.7.egg-info
---
0755
vendors_api
---
0755
virtualenv
---
0755
virtualenv-20.13.0-py3.7.egg-info
---
0755
webencodings
---
0755
webencodings-0.5.1-py3.7.egg-info
---
0755
wmt
---
0755
zipp-0.0.0-py3.7.egg-info
---
0755
Paste-1.7.5.1-py3.7-nspkg.pth
534 bytes
0644
PySocks-1.5.7-py3.7.egg-info
322 bytes
0644
cl_proc_hidepid.py
4549 bytes
0644
clcontrollib.py
53127 bytes
0644
cldetectlib.py
18745 bytes
0644
cldiaglib.py
48675 bytes
0644
clhooklib.py
1432 bytes
0644
cli_utils.py
1775 bytes
0644
cllicenselib.py
8220 bytes
0644
clsetuplib.py
4422 bytes
0644
clsudo.py
15049 bytes
0644
cpanel.py
29687 bytes
0644
distlib-0.3.4-py3.7.egg-info
1162 bytes
0644
distutils-precedence.pth
152 bytes
0644
docopt.py
19946 bytes
0644
editor.py
2550 bytes
0755
lve_stats-2.0-py3.7.egg-info
185 bytes
0644
lveapi.py
19697 bytes
0644
lvectllib.py
94545 bytes
0644
lvestat.py
7106 bytes
0644
prettytable.py
54204 bytes
0644
pyparsing.py
229867 bytes
0644
remove_ubc.py
5670 bytes
0755
schema.py
29198 bytes
0644
secureio.py
17387 bytes
0644
six.py
34159 bytes
0644
socks.py
29952 bytes
0644
sockshandler.py
2913 bytes
0644
typing_extensions.py
83727 bytes
0644
zipp.py
8425 bytes
0644
N4ST4R_ID | Naxtarrr