OwlCyberSecurity - MANAGER
Edit File: db_governor_lib.cpython-311.opt-1.pyc
� �����h�<����������������������������d�dl�Z�d�dlZd�dlmZ�d�dlmZ�d�dlmZ�d�dlm Z �ddl mZmZm Z mZ��G�d��d e������������Zd dd d dd ddd�d dd d�ddd�ddd�d� ZdZd��Zd"d�Zd��Zd��Zd��Zd��Zd��Zd"d�Zd��Zd ��Zd!��ZdS�)#�����N)�Optional)�etree)�FormattedException)� MySQLGovernor����)�boolean_to_on_off�str_to_boolean�time_convertor_to_dict�time_unit_to_letterc�������������������������e�Zd�ZdS�)�DBGovernorExceptionN)�__name__� __module__�__qualname__��������py/clconfig/db_governor_lib.pyr ���r ������s���������������Dr���r ����off�on�������limit�60s��mode�unlimit��kill�logPath�timeout�LONG�r����format�ERROR) �modeOfOperation�gatherDataForDetailedStats�save_uid�logRestrictedUsersQueries� scriptPath�userMaxConnections�restrictType�slowQueries�restrictLog�errorLogz!/etc/container/mysql-governor.xmlc������������������$�����t����������|�d�������������S�)Nzutf-8)�encoding)�open)� file_names��� r����_openr3���>���s������� �G�,�,�,�,r���c����������������������� �dt����������|������������z���dz���t����������|������������z���}|����������������������|������������d���������}n#�t����������t����������f$�r�|cY�S�w�xY�w|S�)a�� Gets data from specified node and attribute :param x: Parent node object :param node: Node name to extract data :param attrib: Attribute name to extract data :param default: Default value to return if specified node/attribute not found :return: Value �//�/@r���)�str�xpath�AttributeError� IndexError)�x�node�attrib�default�path�datas��� r����get_data_from_xmlrA���B���sk��������c�$�i�i��$�&��V���4���w�w�t�}�}�Q������J�'����������������Ks����A�A��A�Ac�����������������������t����������|������������������������������������������������}�|����������������������d������������rt����������|�dd����������������������dz��}n�|����������������������d������������rt����������|�dd����������������������dz��dz��}nr|����������������������d������������r!t����������|�dd����������������������dz��dz��dz��}n<|����������������������d������������rt����������|�dd����������������������}nt����������|�������������}|S�) z~ Convert value in minutes, hours, days to seconds :param value: value of slow limit :return: value in seconds �mN����<����h�d�����s)r7����lower�endswith�int)�value�results��� r����convert_time_value_to_secondsrO���S���s�������� ��J�J�����E��~�~�c���� ��U�3�B�3�Z���2�%��� ���� � ����U�3�B�3�Z���2�%��*��� ���� � ����U�3�B�3�Z���2�%��*�R�/��� ���� � ����U�3�B�3�Z������U�����Mr���c����������������������� �|�����������������������d������������d���������}t����������|������������}t����������|������������S�#�t����������t����������t ����������f$�r�|cY�S�w�xY�w)z� Gets slow queries timeout :param x: Root node :param default: Default value to return if timeout not found :return: Timeout z$default/limit[@name='slow']/@currentr���)r8���rO���rL���r9���r:���� ValueError)r;���r>���r@���s��� r����get_slow_queries_timeoutrR���h���sb��������w�w�=�>�>�q�A��,�T�2�2���4�y�y����J� �3��������������s����8;��A�Ac����������������������d}|�����������������������|������������}t����������|������������dk����r�|�����������������������d������������}t����������|������������dk����r)t����������j��������d������������}|����������������������|�������������|�����������������������d������������d���������}t����������j��������d������������}|���������������������|�������������|���������������������dd�������������n|d���������}|���������������������dt ����������|�������������������������dS�) z{ Sets slow queries timeout :param node: Root node :param slow_timeout: new timeout value :return: None zdefault/limit[@name='slow']r���r>���r����name�slow�currentN)r8����lenr����Element�append�setr7���)r<����slow_timeoutr?����tag_list� node_list�new_node�default_node� tag_to_sets��� r����set_slow_queries_timeoutra���w���s��������)�D��z�z�$���H� �8�}�}�����J�J�y�)�)� ��y�>�>�Q����}�Y�/�/�H��K�K��!�!�!��z�z�)�,�,�Q�/���]�7�+�+� ����J�'�'�'����v�v�&�&�&�&��a�[� ��N�N�9�c�,�/�/�0�0�0�0�0r���c������������������2����dt����������|������������z���}|����������������������|������������}t����������|������������dk����r>t����������j��������|������������}|����������������������|�������������|����������������������|������������}|d���������}|���������������������||�������������dS�)z� Sets value to specified node/attribute :param x: Parent node :param node_name: Node name :param attribute_name: Attribute name :param value: Value to set :return: None r5���r���N)r7���r8���rW���r���rX���rY���rZ���)r;���� node_name�attribute_namerM���r?���r\���r^����tags��� r����set_data_to_xmlrf�������s���������#�i�.�.� �D��w�w�t�}�}�H� �8�}�}�����=��+�+�� ��������7�7�4�=�=�� �1�+�C��G�G�N�E�"�"�"�"�"r���c�����������������������t����������|�||������������} �t����������|������������S�#�t����������$�r"}t����������t������������d|��d|���������������|�d}~ww�xY�w)z� Get time from specified tag/attribute as seconds :param x: XML object :param tag_name: XML tag name :param attr_name: XML object name :return: Number of seconds. Throws DBGovernorException if any error z has invalid value in governer/r6���N)rA���r ���� Exceptionr ����DbGovConfig)r;����tag_name� attr_namerM����es��� r����_get_timedict_from_xmlrm�������su������� �a��9�5�5�E��%�e�,�,�,���������!��R�R�8�R�R�y�R�R� �� �� ��������s����"�� A�A � Ac����������������������t�����������j�����������������������������t����������������������sdS�|��;t ����������t����������������������}t����������j��������|�����������������������������������������������}n|�}t����������|ddt����������d���������������������S�)z� Get MySQL Governor mode. We return None if governor config isn't exists All exceptions will be catched in top level functions :param parsed_xml_tree: parsed governor config N�lve�user%���) �osr?����existsri���r3���r����parse�getrootrA���� DEFAULTS_DICT)�parsed_xml_tree�fr;���s��� r����get_gov_mode_operationrx�������sl��������7�>�>�+�&�&����t����+�����K��N�N�"�"�$�$������Q��u�m�<M�.N�O�O�Or���c������������ ����������� �t�����������j�����������������������������t����������������������si�S�t ����������t����������������������}�t����������j��������|������������������������������������������������}i�}t����������|�������������|d<���t����������t����������|ddt����������d���������������������������������|d<���t����������t����������|ddt����������d���������������������������������|d<���t����������|d d t����������d���������������������|d<���t����������t����������|d dt����������d ���������������������������������|d <���t����������|d d������������t����������|d d������������t����������|d d������������t����������|d d������������t����������|d d������������d�|d<���t����������|ddt����������d���������d���������������������t����������t����������|ddt����������d���������d���������������������������������d�|d<���t����������t����������|ddt����������d���������d���������������������������������t����������|ddt����������d���������d���������������������t����������|t����������d���������d���������������������d�|d<���t����������|d dt����������d ���������d���������������������t����������|d d!t����������d ���������d!���������������������d"�|d <���t����������|dd#t����������d$���������d���������������������t����������|ddt����������d$���������d!���������������������d%�|d$<���|���������������������t#�������������������������������������d&|iS�#�t$����������t&����������t ����������j��������t ����������j��������t ����������j��������t.����������f$�r}t/����������t������������d'|���������������|�d(}~ww�xY�w))zL Get MySQL Governer config :return: Dictionary with config data )rv���r%���� statisticr���r&���� logqueriesrp���r(����restrict�scriptr)����user_max_connectionsr*����level1�level2�level3�level4r ���)r���r����r����r����r ����restrictedTimePeriods� restrict_moder+���r���r����slow_queries�runr,���r����logr���r���r-���r#���r"����filer.���)r����level�mySQLGovSettingsz read/parse error: N)rq���r?���rr���ri���r3���r���rs���rt���rx���r ���rA���ru���rL���rm���r ���rR����update�get_db_gov_stat_info�OSError�IOError�XMLSyntaxError�XMLSchemaParseError�XMLSchemaErrorr ���)rw���r;����result_dictrl���s��� r����get_db_gov_configr��������sk�����-Q��w�~�~�k�*�*�� ��I��+�����K��N�N�"�"�$�$����)?�PQ�)R�)R�)R��%�&�4B��a��f�m�D`�6a�b�b�5d��5d��0�1�3A��a��u�m�D_�6`�a�a�4c��4c��/�0�$5�a��X�}�]i�Oj�$k�$k��L�!�,/��a��-C�]�Sg�Eh�i�i�-k��-k��(�)��-�Q� �H�E�E�,�Q� �H�E�E�,�Q� �H�E�E�,�Q� �H�E�E�-�a��Y�G�G�0 ��0 ��+�,��&�a��%��~�A^�_e�Af�g�g�-�!�!�_�i��~�A^�_h�Ai�j�j�l��l�' ��' ��N�#� �/=�=N�q�R`�bg�O\�]j�Ok�lr�Os�>u��>u��/v��/v�1B�1�n�V[�CP�Q^�C_�`i�Cj�2l��2l�1I�!�]�[h�Mi�js�Mt�1u�1u� &(��&(��M�"��)��J��}�]�?[�\e�?f�g�g�'��:�x��}�A]�^f�Ag�h�h�& ��& ��M�"��/@��5�&�R_�`j�Rk�lu�Rv�.w�.w�,=�a���P]�^h�Pi�jr�Ps�,t�,t�#%��#%��J��� ���/�1�1�2�2�2�"�K�0�0���W�e�2�E�4M�� �"5�7��Q��Q��Q�!�[�"H�"H�Q�"H�"H�I�I�q�P�����Q���s����%K;��KK;��;8M�3M � Mc������������������T���� �t�����������j�����������������������������t����������������������sdS�t ����������t����������������������}t����������j��������|�����������������������������������������������}|������������������������������������dddt����������fdddt����������fdd d t����������fdddt����������fd ddt����������fdddt����������fdddt����������fdddt����������fddd t����������fdddt����������fdddt����������fdddt����������fg}|D�]G} �|\��}}}}t����������d|���������������} t����������|||�|| ��������������������������8#�t����������$�r�Y��Dw�xY�wg�d�} | D�]a}|\��}}}} �t����������d|���������������} t����������t����������d|���������������������������}t����������|||| ��|�����������������R#�t����������$�r�Y��^w�xY�w �|�d���������d���������}t����������||�������������n#�t����������$�r�Y�nw�xY�wt����������j��������|������������}t#����������t����������d ������������5�}|���������������������d!|z���������������ddd�������������n#�1�swxY�w�Y���nd#�t&����������t(����������t ����������j��������t ����������j��������t ����������j��������f$�r/}t1����������d"t����������|������������z���d#t����������id$�������������|�d}~ww�xY�wt3����������j��������d%d&d'd(�)�������������dS�)*a%�� Set MySQL governer config :param parameters_dict: Parameters to set dictionary. For example: { u'modeOfOperation': u'abusers', u'scriptPath': u'', u'gatherDataForDetailedStats': True, u'userMaxConnections': 30, u'logRestrictedUsersQueries': False, u'restrictLog': {u'logPath': u'/var/log/dbgovernor-restrict.log', u'format': u'LONG'}, u'restrictedTimePeriods': {u'level1': {u'unitOfTime': u'seconds', u'period': 60}, u'level2': {u'unitOfTime': u'minutes', u'period': 15}, u'level3': {u'unitOfTime': u'hours', u'period': 1}, u'level4': {u'unitOfTime': u'days', u'period': 1}, u'timeout': {u'unitOfTime': u'hours', u'period': 1}}, u'errorLog': {u'logPath': u'/var/log/dbgovernor-error-my.log', u'level': u'DEBUG'}, u'slowQueries': {u'logPath': u'/var/log/dbgovernor-kill.log', u'kill': True, u'timeout': 30}, u'restrictType': {u'mode': u'limit', u'unlimit': {u'unitOfTime': u'seconds', u'period': 60}} } Any key in dictionary can absent, appropriate MySQL Governor parameter will not changed :return: None. Throws DBGovernorException if error Nz['modeOfOperation']ro���rp���z['scriptPath']r|���r}���z['gatherDataForDetailedStats']rz���r���z['userMaxConnections']r~���z['logRestrictedUsersQueries']r{���z['restrictLog']['logPath']r����z['restrictLog']['format']r#���z['errorLog']['logPath']r����z['errorLog']['level']z['slowQueries']['logPath']r����z['slowQueries']['kill']r����z['restrictType']['mode']r�����parameters_dict))z%['restrictType']['unlimit']['period']z)['restrictType']['unlimit']['unitOfTime']r����r���)z-['restrictedTimePeriods']['level1']['period']z1['restrictedTimePeriods']['level1']['unitOfTime']r|���r���)z-['restrictedTimePeriods']['level2']['period']z1['restrictedTimePeriods']['level2']['unitOfTime']r|���r����)z-['restrictedTimePeriods']['level3']['period']z1['restrictedTimePeriods']['level3']['unitOfTime']r|���r����)z-['restrictedTimePeriods']['level4']['period']z1['restrictedTimePeriods']['level4']['unitOfTime']r|���r����)z.['restrictedTimePeriods']['timeout']['period']z2['restrictedTimePeriods']['timeout']['unitOfTime']r|���r ���r,���r ����wbs���<?xml version="1.0" ?> %s z%(dbgov_cfg)s error: � dbgov_cfg)�message�contextz//sbin/service db_governor restart &>/dev/null &Tz /bin/bashF)�shell� executable�check)rq���r?���rr���ri���r3���r���rs���rt����closer7���r����evalrf����KeyErrorr���ra����tostringr1����writer����r����r����r����r����r ���� subprocessr����)r����rw���r;����control_data_list�control_data_item�input_dict_keys�xml_tag_name�xml_attribute_name�func_converter�val�control_data_pairs_list�period_indexes�period_unit_of_time_indexes� period_val�period_unit_of_time�slow_queries_timeout�s_xmlrl���s��� r����set_db_gov_configr�������s������.LR��w�~�~�k�*�*�� ��F��+�����K��N�N�"�"�$�$�� ��� � � ��#�E�5�#�6� �z�8�S�9� -�{�F�DU�V� %�z�3I�3�O� ,�l�E�CT�U� )�:�u�c�B� (�*�h��D� &��v�s�;� $�e�V�S�9� )�>�5�#�F� &���?P�Q� '��%��E� ���"3�� �� �� �Te�Q���/A�>��>�_�>�>�?�?����<�1C�^�^�TW�EX�EX�Y�Y�Y�Y���� �� �� ��� ���� # �� # �� # ���"9�� �� ��\m�Y�N�7��GY� ��"�"D�N�"D�"D�E�E� �&9�$�?n�Ql�?n�?n�:o�:o�&p�&p�#���<�1C� �Ei�Tg�Ei�Ei�j�j�j�j���� �� �� ��� ���� �#2�=�#A�)�#L� �$�Q�(<�=�=�=�=���� �� �� ��D� �������q�!�!�� �+�t� $� $�� =�� �G�G�3�e�;�<�<�<� =�� =�� =�� =�� =�� =�� =�� =�� =�� =�� =����� =�� =�� =�� =����W�e�2�E�4M�u�Oc�d��R��R��R�!�.E��A���.N�/:�K�.H�#J��#J��K��K�PQ� R�����R������N�D��+�U�D��D��D��D��D��Ds�����$H,��CH,��54D*�)H,��* D7�4H,��6D7�7H,�� AF�H,�� F�H,��F�H,��#G��H,�� G�H,��G�,H,��;H �H,�� H$�$H,��'H$�(H,��,2J �*J�J c������������������������t������������������������}�|������������������������������������\��}}|������������������������������������|t����������|������������d�S�)z� Get db_governor status and version info :return: dict( 'dbGovVersion': <version>, 'dbGovStatus': enabled|error|disabled, 'dbGovError': error details ) )�dbGovVersion�dbGovStatus� dbGovError)r����get_governor_status�get_governor_versionr7���)�db_gov�status�errors��� r���r����r����l��sL��������_�_�F��.�.�0�0�M�F�E��3�3�5�5���%�j�j�����r���)N)rq���r�����typingr����lxmlr����clcommon.clexceptionr����clcommon.lib.mysql_governor_libr����clconfig_utilsr���r ���r ���r���r ���ru���ri���r3���rA���rO���rR���ra���rf���rm���rx���r����r����r����r���r���r����<module>r�������s����� � � � ����������������������������������3��3��3��3��3��3��9��9��9��9��9��9������������������������ �� �� �� �� �,�� �� �� � ��"&��!&�������� ������������� ������)��� �4�2��-��-��-��������"�����*�����1��1��1�8#��#��#�*�����"P��P��P��P�"3Q��3Q��3Q�liD��iD��iD�X��������r���