Аудит

Данные на 16 февраля 2024

Добавить сайт в список

29

Показатели сайта

0
0
0
Узнайте больше об этом сайте
ИКС сайта 160
SSL-сертификат Есть SSL-сертификат

Содержимое

Заголовок (тег title) Все о вооружении России и мира
Заголовок (тег h1) Отсутствует
Описание сайта (description) Отсутствует

Главная страница сайта

URL сайта https://gunsfriend.ru/
Локализация сайта Альтернативных страниц нет
Кодировка страниц UTF-8
Тексты 72
HTML теги 466
a99 article20 body1 button1 center1 comment5 div146 footer1 form1 h11 h221 h42 h51 head1 header1 html1 i6 img25 input1 li33 link15 meta14 nav2 noscript1 p3 picture3 script31 source6 span7 style6 title1 ul8 unknown1
Скрипты на сайте 32
Обнаружены скрипты:
Яндекс.Метрика
Google AdSense
Все скрипты:
data:text/javascript;base64,Ci8qIDwhW0NEQVRBWyAqLwp2YXIgam9oYW5uZXNfanNfc2V0dGluZ3MgPSB7InJ0bF9tb2RlIjoiIiwiaGVhZGVyX3N0aWNreSI6IiIsImhlYWRlcl9zdGlja3lfb2Zmc2V0IjoiMzAwIiwiaGVhZGVyX3N0aWNreV91cCI6IiIsInBvcHVwIjoiMSIsImdvX3RvX3RvcCI6IjEiLCJncmlkIjp7ImNvbHVtbiI6NTAsImd1dHRlciI6eyJ4cyI6MTUsInNtIjoxNSwibWQiOjMwLCJsZyI6MzAsInhsIjo0OH0sImJyZWFrcG9pbnQiOnsieHMiOjAsInNtIjozNzQsIm1kIjo2MDAsImxnIjo5MDAsInhsIjoxMTI4fX19OwovKiBdXT4gKi8K
data:text/javascript;base64,CiAgICAgICAgICAgICAgICBmdW5jdGlvbiBvbkVycm9yUGxhY2luZygpIHsKICAgICAgICAgICAgICAgICAgICBpZiAodHlwZW9mIGNhY2hlUGxhY2luZyAhPT0gJ3VuZGVmaW5lZCcgJiYgdHlwZW9mIGNhY2hlUGxhY2luZyA9PT0gJ2Z1bmN0aW9uJyAmJiB0eXBlb2Ygd2luZG93LmpzSW5wdXRlckxhdW5jaCAhPT0gJ3VuZGVmaW5lZCcgJiYgWzE1LCAxMF0uaW5jbHVkZXMod2luZG93LmpzSW5wdXRlckxhdW5jaCkpIHsKICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGVycm9ySW5mbyA9IFtdOwogICAgICAgICAgICAgICAgICAgICAgICBjYWNoZVBsYWNpbmcoJ2xvdycsZXJyb3JJbmZvKTsKICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICBzZXRUaW1lb3V0KGZ1bmN0aW9uICgpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG9uRXJyb3JQbGFjaW5nKCk7CiAgICAgICAgICAgICAgICAgICAgICAgIH0sIDEwMCkKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB2YXIgeGhyID0gbmV3IFhNTEh0dHBSZXF1ZXN0KCk7CiAgICAgICAgICAgICAgICB4aHIub3BlbignR0VUJywiLy9uZXdyb3RhdG9ybWFyY2gyMy5iaWQvMXl0YWguanNvbiIsdHJ1ZSk7CiAgICAgICAgICAgICAgICB4aHIuc2V0UmVxdWVzdEhlYWRlcigiQ29udGVudC10eXBlIiwgImFwcGxpY2F0aW9uL3gtd3d3LWZvcm0tdXJsZW5jb2RlZCIpOwogICAgICAgICAgICAgICAgeGhyLm9ucmVhZHlzdGF0ZWNoYW5nZSA9IGZ1bmN0aW9uKCkgewogICAgICAgICAgICAgICAgICAgIGlmICh4aHIuc3RhdHVzICE9IDIwMCkgewogICAgICAgICAgICAgICAgICAgICAgICBpZiAoeGhyLnN0YXR1c1RleHQgIT0gJ2Fib3J0JykgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgb25FcnJvclBsYWNpbmcoKTsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH07CiAgICAgICAgICAgICAgICB4aHIuc2VuZCgpOwogICAgICAgICAgICA=
data:text/javascript;base64,CiAgICAgICAgICAgICAgICBmdW5jdGlvbiBvbkVycm9yUGxhY2luZygpIHsKICAgICAgICAgICAgICAgICAgICBpZiAodHlwZW9mIGNhY2hlUGxhY2luZyAhPT0gJ3VuZGVmaW5lZCcgJiYgdHlwZW9mIGNhY2hlUGxhY2luZyA9PT0gJ2Z1bmN0aW9uJyAmJiB0eXBlb2Ygd2luZG93LmpzSW5wdXRlckxhdW5jaCAhPT0gJ3VuZGVmaW5lZCcgJiYgWzE1LCAxMF0uaW5jbHVkZXMod2luZG93LmpzSW5wdXRlckxhdW5jaCkpIHsKICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGVycm9ySW5mbyA9IFtdOwogICAgICAgICAgICAgICAgICAgICAgICBjYWNoZVBsYWNpbmcoJ2xvdycsZXJyb3JJbmZvKTsKICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICBzZXRUaW1lb3V0KGZ1bmN0aW9uICgpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG9uRXJyb3JQbGFjaW5nKCk7CiAgICAgICAgICAgICAgICAgICAgICAgIH0sIDEwMCkKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB2YXIgeGhyID0gbmV3IFhNTEh0dHBSZXF1ZXN0KCk7CiAgICAgICAgICAgICAgICB4aHIub3BlbignR0VUJywiLy9uZXdyb3RhdG9ybWFyY2gyMy5iaWQvMXl0YWgubWluLmpzIix0cnVlKTsKICAgICAgICAgICAgICAgIHhoci5zZXRSZXF1ZXN0SGVhZGVyKCJDb250ZW50LXR5cGUiLCAiYXBwbGljYXRpb24veC13d3ctZm9ybS11cmxlbmNvZGVkIik7CiAgICAgICAgICAgICAgICB4aHIub25yZWFkeXN0YXRlY2hhbmdlID0gZnVuY3Rpb24oKSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKHhoci5zdGF0dXMgIT0gMjAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmICh4aHIuc3RhdHVzVGV4dCAhPSAnYWJvcnQnKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvbkVycm9yUGxhY2luZygpOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgICAgIHhoci5zZW5kKCk7CiAgICAgICAgICAgIA==
data:text/javascript;base64,CmlmICh0eXBlb2YgcmJfYWpheHVybD09PSd1bmRlZmluZWQnKSB7dmFyIHJiX2FqYXh1cmwgPSAnaHR0cHM6Ly9ndW5zZnJpZW5kLnJ1L3dwLWFkbWluL2FkbWluLWFqYXgucGhwJzt9CmlmICh0eXBlb2YgY2FjaGVfZGV2aWNlcz09PSd1bmRlZmluZWQnKSB7dmFyIGNhY2hlX2RldmljZXMgPSBmYWxzZTt9CnZhciBuUmVhZHlCbG9jayA9IGZhbHNlOw0KdmFyIGZldGNoZWRDb3VudGVyID0gMDsNCg0KZnVuY3Rpb24gc2VuZFJlYWR5QmxvY2tzTmV3KGJsb2Nrcykgew0KICAgIGlmICghY2FjaGVfZGV2aWNlcykgew0KICAgICAgICBsZXQgeGh0dHAgPSBuZXcgWE1MSHR0cFJlcXVlc3QoKTsNCiAgICAgICAgbGV0IHNlbmREYXRhID0gJ2FjdGlvbj1zYXZlQWRCbG9ja3MmdHlwZT1ibG9ja3NHZXRoZXJpbmcmZGF0YT0nK2Jsb2NrczsNCiAgICAgICAgeGh0dHAub25yZWFkeXN0YXRlY2hhbmdlID0gZnVuY3Rpb24ocmVkYXRhKSB7DQogICAgICAgICAgICBpZiAodGhpcy5yZWFkeVN0YXRlID09IDQgJiYgdGhpcy5zdGF0dXMgPT0gMjAwKSB7DQogICAgICAgICAgICAgICAgY29uc29sZS5sb2coJ2NhY2hlIHN1Y2NlZWQnKTsNCiAgICAgICAgICAgIH0NCiAgICAgICAgfTsNCiAgICAgICAgeGh0dHAub3BlbigiUE9TVCIsIHJiX2FqYXh1cmwsIHRyd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0IG9rU3RhdGVzID0gWydkb25lJywncmVmcmVzaC13YWl0Jywnbm8tYmxvY2snLCdmZXRjaGVkJ107DQogICAgICAgIGxldCBjdXJTdGF0ZSA9ICcnOw0KDQogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgZ2F0aGVyZWRCbG9ja3MubGVuZ3RoOyBpKyspIHsNCiAgICAgICAgICAgIGlmICghZ2F0aGVyZWRCbG9ja3NbaV1bJ2RhdGFzZXQnXVsic3RhdGUiXSkgew0KICAgICAgICAgICAgICAgIG5SZWFkeUJsb2NrID0gdHJ1ZTsNCiAgICAgICAgICAgICAgICBicmVhazsNCiAgICAgICAgICAgIH0gZWxzZSB7DQogICAgICAgICAgICAgICAgY3VyU3RhdGUgPSBnYXRoZXJlZEJsb2Nrc1tpXVsnZGF0YXNldCddWyJzdGF0ZSJdLnRvTG93ZXJDYXNlKCk7DQogICAgICAgICAgICAgICAgaWYgKCFva1N0YXRlcy5pbmNsdWRlcyhjdXJTdGF0ZSkpIHsNCiAgICAgICAgICAgICAgICAgICAgblJlYWR5QmxvY2sgPSB0cnVlOw0KICAgICAgICAgICAgICAgICAgICBicmVhazsNCiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKGN1clN0YXRlPT0nZmV0Y2hlZCcmJmZldGNoZWRDb3VudGVyIDwgMykgew0KICAgICAgICAgICAgICAgICAgICBmZXRjaGVkQ291bnRlcisrOw0KICAgICAgICAgICAgICAgICAgICBuUmVhZHlCbG9jayA9IHRydWU7DQogICAgICAgICAgICAgICAgICAgIGJyZWFrOw0KICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgIH0NCiAgICAgICAgfQ0KICAgIH0NCiAgICBlbHNlIG5SZWFkeUJsb2NrID0gdHJ1ZTsNCg0KICAgIGlmIChuUmVhZHlCbG9jayA9PSB0cnVlKSB7DQogICAgICAgIG5SZWFkeUJsb2NrID0gZmFsc2U7DQogICAgICAgIHNldFRpbWVvdXQodGltZUJlZm9yZUdhdGhlcmluZywyM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LA0KICAgICAgICBkaXZDaWRFbGVtZW50ID0gJyc7DQoNCiAgICBpZiAodHlwZW9mIHNjQXJyYXkgIT09ICd1bmRlZmluZWQnKSB7DQogICAgICAgIGlmIChzY0FycmF5JiZzY0FycmF5Lmxlbmd0aCA+IDAmJmdhdGhlcmVkQmxvY2tzJiZnYXRoZXJlZEJsb2Nrcy5sZW5ndGggPiAwJiZ0eXBlb2Ygd2luZG93LnJ1bHZXNWdudGIgIT09ICd1bmRlZmluZWQnKSB7DQogICAgICAgICAgICBkYXRhQ2lkSWRlbnRpZmllciA9IHdpbmRvdy5ydWx2VzVnbnRiOw0KICAgICAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBnYXRoZXJlZEJsb2Nrcy5sZW5ndGg7IGkrKykgew0KICAgICAgICAgICAgICAgIGdhdGhlcmVkQmxvY2tDaGlsZCA9IGdhdGhlcmVkQmxvY2tzW2ldLmNoaWxkcmVuWzBdOw0KICAgICAgICAgICAgICAgIGlmICghZ2F0aGVyZWRCbG9ja0NoaWxkKSB7DQogICAgICAgICAgICAgICAgICAgIGNvbnRpbnVlOw0KICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgICAgICBzY0FkSWQgPSAtMzsNCiAgICAgICAgICAgICAgICBibG9ja1N0YXR1cyA9IG51bGw7DQogICAgICAgICAgICAgICAgc2NDb250YWluZXIgPSBudWxsOw0KICAgICAgICAgICAgICAgIGRhdGFGdWxsID0gLTE7DQogICAgICAgICAgICAgICAgc2t5c2NyYXBlclN0YXR1cyA9IGZhbHNlOw0KICAgICAgICAgICAgICAgIHNwbGl0ZWRTa3lzY3JhcGVyID0gW107DQogICAgICAgICAgICAgICAgZ2F0aGVyZWRCbG9ja0NoaWxkU2t5UGFydHMgPSBbXTsNCiAgICAgICAgICAgICAgICBzdGlja3lTdGF0dXMgPSBmYWxzZTsNCiAgICAgICAgICAgICAgICBzdGlja3lDaGVjayA9IFtdOw0KICAgICAgICAgICAgICAgIHN0aWNreUZpeGVkU3RhdHVzID0gZmFsc2U7DQogICAgICAgICAgICAgICAgc3RpY2t5Rml4ZWRDaGVjayA9IFtdOw0KICAgICAgICAgICAgICAgIHJlcGVhdGFibGVJZGVudGlmaWVyID0gIiI7DQogICAgICAgICAgICAgICAgZGl2Q2lkRWxlbWVudCA9IG51bGw7DQoNCiAgICAgICAgICAgICAgICBzY0FkSWQgPSBnYXRoZXJlZEJsb2NrQ2hpbGQuZ2V0QXR0cmlidXRlKCdkYXRhLWFpZCcpOw0KICAgICAgICAgICAgICAgIHNjQmxvY2tJZCA9IGdhdGhlcmVkQmxvY2tDaGlsZC5nZXRBdHRyaWJ1dGUoJ2RhdGEtaWQnKTsNCiAgICAgICAgICAgICAgICBibG9ja1N0YXR1cyA9IGdhdGhlcmVkQmxvY2tDaGlsZC5nZXRBdHRyaWJ1dGUoJ2RhdGEtc3RhdGUnKTsNCiAgICAgICAgICAgICAgICBkYXRhRnVsbCA9IGdhdGhlcmVkQmxvY2tDaGlsZC5nZXRBdHRyaWJ1dGUoJ2RhdGEtZnVsbCcpOw0KDQogICAgICAgICAgICAgICAgaWYgKHNjQmxvY2tJZCYmc2NBZElkID4gMCkgew0KICAgICAgICAgICAgICAgICAgICBzY2kgPSAtMTsNCiAgICAgICAgICAgICAgICAgICAgZm9yIChpMSA9IDA7IGkxIDwgc2NBcnJheS5sZW5ndGg7IGkxKyspIHsNCiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzY0Jsb2NrSWQgPT0gc2NBcnJheVtpMV1bJ2Jsb2NrSWQnXSYmc2NBZElkID09IHNjQXJyYXlbaTFdWydhZElkJ10pIHsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzY2kgPSBpMTsNCiAgICAgICAgICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgICAgICAgICAgfQ0KDQogICAgICAgICAgICAgICAgICAgIGlmIChzY2kgPiAtMSkgew0KICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGJsb2NrU3RhdHVzJiZva1N0YXRlcy5pbmNsdWRlcyhibG9ja1N0YXR1cykpIHsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoYmxvY2tTdGF0dXM9PSduby1ibG9jaycpIHsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZ2F0aGVyZWRCbG9ja0NoaWxkLmlubmVySFRNTCA9ICcnOw0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoKGJsb2NrU3RhdHVzPT0nZmV0Y2hlZCcmJmRhdGFGdWxsPT0xKXx8IVsnbm8tYmxvY2snLCdmZXRjaGVkJ10uaW5jbHVkZXMoYmxvY2tTdGF0dXMpKSB7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZvciAobGV0IGNsMSA9IDA7IGNsMSA8IGdhdGhlcmVkQmxvY2tzW2ldLmNsYXNzTGlzdC5sZW5ndGg7IGNsMSsrKSB7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoZ2F0aGVyZWRCbG9ja3NbaV0uY2xhc3NMaXN0W2NsMV0uaW5jbHVkZXMoInJlcGVhdGFibGUtbWFyayIpKSB7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcmVwZWF0YWJsZUlkZW50aWZpZXIgPSBnYXRoZXJlZEJsb2Nrc1tpXS5jbGFzc0xpc3RbY2wxXTsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQ0KDQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChyZXBlYXRhYmxlSWRlbnRpZmllcikgew0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZGl2Q2lkRWxlbWVudCA9IGRvY3VtZW50LnF1ZXJ5U2VsZWN0b3JBbGwoIi5wZXJjZW50UG9pbnRlckNsYXNzLnNjTWFyay4iK3JlcGVhdGFibGVJZGVudGlmaWVyKycgZGl2W2RhdGEtY2lkPSInK2RhdGFDaWRJZGVudGlmaWVyKyciXScpOw0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2Ugew0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZGl2Q2lkRWxlbWVudCA9IGdhdGhlcmVkQmxvY2tDaGlsZC5xdWVyeVNlbGVjdG9yQWxsKCdkaXZbZGF0YS1jaWQ9IicrZGF0YUNpZElkZW50aWZpZXIrJyJdJyk7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0NCg0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB2YXIgdGV4dCA9IHNjQXJyYXlbc2NpXVsndGV4dCddOw0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoZGl2Q2lkRWxlbWVudCYmZGl2Q2lkRWxlbWVudC5sZW5ndGggPiAwKSB7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmb3IgKGxldCBpMiA9IDA7IGkyIDwgZGl2Q2lkRWxlbWVudC5sZW5ndGg7IGkyKyspIHsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBqUXVlcnkoZGl2Q2lkRWxlbWVudFtpMl0pLmh0bWwodGV4dCk7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBqUXVlcnkoZ2F0aGVyZWRCbG9ja0NoaWxkKS5odG1sKHRleHQpOw0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxhdW5jaFVwZGF0ZVJiRGlzcGxheXMoKTsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGJsb2NrU3RhdHVzIT0nZmV0Y2hlZCd8fChibG9ja1N0YXR1cz09J2ZldGNoZWQnJiZkYXRhRnVsbD09MSkpIHsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZm9yIChpMSA9IDA7IGkxIDwgc2NBcnJheS5sZW5ndGg7IGkxKyspIHsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzY0Jsb2NrSWQgPT0gc2NBcnJheVtpMV1bJ2Jsb2NrSWQnXSkgew0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHNjQXJyYXkuc3BsaWNlKGkxLCAxKTsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpMS0tOw0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQ0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGdhdGhlcmVkQmxvY2tzW2ldLmNsYXNzTGlzdC5yZW1vdmUoJ3NjTWFyaycpOw0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgICAgICAgICAgfQ0KICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoc2NCbG9ja0lkJiZzY0FkSWQgPCAxJiZbJ25vLWJsb2NrJywnZmV0Y2hlZCddLmluY2x1ZGVzKGJsb2NrU3RhdHVzKSkgew0KICAgICAgICAgICAgICAgICAgICBmb3IgKGkxID0gMDsgaTEgPCBzY0FycmF5Lmxlbmd0aDsgaTErKykgew0KICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHNjQmxvY2tJZCA9PSBzY0FycmF5W2kxXVsnYmxvY2tJZCddKSB7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgc2NBcnJheS5zcGxpY2UoaTEsIDEpOw0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIGkxLS07DQogICAgICAgICAgICAgICAgICAgICAgICB9DQogICAg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ibExvY2FsID0gYmxUeXBlOw0KICAgIGxldCBjdXJyZW50QmxvY2s7DQogICAgbGV0IGN1cnJlbnRCbG9ja0lkOw0KICAgIGxldCBjdXJyZW50QmxvY2tQb3NpdGlvbjsNCiAgICBsZXQgY3VycmVudENvbnRhaW5lcjsNCiAgICBsZXQgaSA9IDA7DQogICAgbGV0IGogPSAwOw0KICAgIGxldCBibG9ja1N0ckpzID0gJyAucGVyY2VudFBvaW50ZXJDbGFzcy5tYXJrZWQnOw0KICAgIGxldCBibG9ja1N0clBocCA9ICcgLnBlcmNlbnRQb2ludGVyQ2xhc3M6bm90KC5tYXJrZWQpJzsNCiAgICBsZXQgYmxvY2tTdHIgPSAnIC5wZXJjZW50UG9pbnRlckNsYXNzJzsNCiAgICBsZXQgY2hlY2tQb2ludGVyID0gbnVsbDsNCiAgICBsZXQgYmxvY2tSZXBlYXRFbmQgPSBmYWxzZTsNCg0KICAgIGlmIChzZWFyY2hUeXBlKSB7DQogICAgICAgIGlmIChzZWFyY2hUeXBlID09ICdtYXJrZWQnKSB7DQogICAgICAgICAgICB3aGlsZSAoIWJsb2NrUmVwZWF0RW5kKSB7DQogICAgICAgICAgICAgICAgYmxMb2NhbCA9IGJsTG9jYWwucGFyZW50RWxlbWVudDsNCiAgICAgICAgICAgICAgICBpZiAoYmxMb2NhbCkgew0KICAgICAgICAgICAgICAgICAgICBjaGVja1BvaW50ZXIgPSBibExvY2FsLnF1ZXJ5U2VsZWN0b3IoIiNjb250ZW50X3BvaW50ZXJfaWQiKTsNCiAgICAgICAgICAgICAgICAgICAgaWYgKCFjaGVja1BvaW50ZXIpIHsNCiAgICAgICAgICAgICAgICAgICAgICAgIGJsb2Nrc0luQ29udGFpbmVyID0galF1ZXJ5KGJsTG9jYWwpLnBhcmVudChjb250YWluZXJTdHJpbmcpOw0KICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGJsb2Nrc0luQ29udGFpbmVyICYmIGJsb2Nrc0luQ29udGFpbmVyLmxlbmd0aCA+IDApIHsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAvKiBjaGVja1BvaW50ZXIgPSBibG9ja3NJbkNvbnRhaW5lci5xdWVyeVNlbGVjdG9yKCIjY29udGVudF9wb2ludGVyX2lkIik7ICovDQogICAgICAgICAgICAgICAgICAgICAgICAgICAgY2hlY2tQb2ludGVyID0galF1ZXJ5KGJsb2Nrc0luQ29udGFpbmVyKS5maW5kKCIjY29udGVudF9wb2ludGVyX2lkIik7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGNoZWNrUG9pbnRlciAmJiBjaGVja1BvaW50ZXIubGVuZ3RoID4gMCkgew0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBibG9ja3NJbkNvbnRhaW5lciA9IG51bGw7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQ0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIGJsb2NrUmVwZWF0RW5kID0gdHJ1ZTsNCiAgICAgICAgICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsNCiAgICAgICAgICAgICAgICAgICAgICAgIGJsb2NrUmVwZWF0RW5kID0gdHJ1ZQ0KICAgICAgICAgICAgICAgICAgICB9DQogICAgICAgICAgICAgICAgfSBlbHNlIHsNCiAgICAgICAgICAgICAgICAgICAgYmxvY2tSZXBlYXRFbmQgPSB0cnVlDQogICAgICAgICAgICAgICAgfQ0KICAgICAgICAgICAgfQ0KICAgICAgICAgICAgLyogYmxvY2tzSW5Db250YWluZXIgPSBqUXVlcnkoYmxUeXBlKS5wYXJlbnQoY29udGFpbmVyU3RyaW5nKTsgKi8NCiAgICAgICAgICAgIGlmIChibG9ja3NJbkNvbnRhaW5lciYmYmxvY2tzSW5Db250YWluZXIubGVuZ3RoID4gMCkgew0KICAgICAgICAgICAgICAgIC8qIGJsb2Nrc0luQ29udGFpbmVyLnBhcmVudE5vZGUuaW5zZXJ0QmVmb3JlKHJiX3RlbXBFbGVtZW50LCBibG9ja3NJbkNvbnRhaW5lcik7ICovDQogICAgICAgICAgICAgICAgYmxvY2tzSW5Db250YWluZXJbMF0ucGFyZW50Tm9kZS5pbnNlcnRCZWZvcmUocmJfdGVtcEVsZW1lbnQsIGJsb2Nrc0luQ29udGFpbmVyWzBdKTsNCg0KICAgICAgICAgICAgICAgIHNhbWVFbGVtZW50QWZ0ZXJFeGNDbGFzc0lkID0gZmFsc2U7DQogICAgICAgICAgICAgICAgcmV0dXJuIGJsb2Nrc0luQ29udGFpbmVyWzBdOw0KICAgICAgICAgICAgfQ0KICAgICAgICAgICAgcmV0dXJuIGJsVHlwZTsNCiAgICAgICAgfSBlbHNlIGlmIChzZWFyY2hUeXBlID09ICdub24tbWFya2VkJykgew0KICAgICAgICAgICAgYmxvY2tzSW5Db250YWluZXIgPSBkb2N1bWVudC5xdWVyeVNlbGVjdG9yQWxsKGJsVHlwZSArIGNvbnRhaW5lclN0cmluZyArIGJsb2NrU3RyUGhwKTsNCiAgICAgICAgICAgIGlmIChibG9ja3NJbkNvbnRhaW5lciAmJiBibG9ja3NJbkNvbnRhaW5lci5sZW5ndGggPiAwICYmIHVzZWRCbG9ja1NldHRpbmdBcnJheSAmJiB1c2VkQmxvY2tTZXR0aW5nQXJyYXkubGVuZ3RoID4gMCkgew0KICAgICAgICAgICAgICAgIGZvciAoaSA9IDA7IGkgPCBibG9ja3NJbkNvbnRhaW5lci5sZW5ndGg7IGkrKykgew0KICAgICAgICAgICAgICAgICAgICBjdXJyZW50QmxvY2sgPSBibG9ja3NJbkNvbnRhaW5lcltpXTsNCiAgICAgICAgICAgICAgICAgICAgY3VycmVudEJsb2NrSWQgPSBjdXJyZW50QmxvY2sucXVlcnlTZWxlY3RvcignLicgKyBibG9ja19jbGFzc2VzLmpvaW4oJywgLicpKS5nZXRBdHRyaWJ1dGUoJ2RhdGEtaWQnKTsNCiAgICAgICAgICAgICAgICAgICAgY3VycmVudENvbnRhaW5lciA9IG51bGw7DQogICAgICAgICAgICAgICAgICAgIGZvciAoaiA9IDA7IGogPCB1c2VkQmxvY2tTZXR0aW5nQXJyYXkubGVuZ3RoOyBpKyspIHsNCiAgICAgICAgICAgICAgICAgICAgICAgIGlmICh1c2VkQmxvY2tTZXR0aW5nQXJyYXlbaV1bJ2lkJ10gPT0gY3VycmVudEJsb2NrSWQpIHsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBjdXJyZW50QmxvY2tQb3NpdGlvbiA9IHVzZWRCbG9ja1NldHRpbmdBcnJheVtpXVsnZWxlbWVudFBvc2l0aW9uJ107DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgY3VycmVudENvbnRhaW5lciA9IGN1cnJlbnRCbG9jay5jbG9zZXN0KGJsVHlwZSArIGNvbnRhaW5lclN0cmluZyk7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGN1cnJlbnRCbG9ja1Bvc2l0aW9uID09IDApIHsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY3VycmVudENvbnRhaW5lci5wYXJlbnROb2RlLmluc2VydEJlZm9yZShjdXJyZW50QmxvY2ssIGN1cnJlbnRDb250YWluZXIpOw0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGN1cnJlbnRDb250YWluZXIucGFyZW50Tm9kZS5pbnNlcnRCZWZvcmUoY3VycmVudEJsb2NrLCBjdXJyZW50Q29udGFpbmVyLm5leHRTaWJsaW5nKTsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7DQogICAgICAgICAgICAgICAgICAgICAgICB9DQogICAgICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgICAgICB9DQogICAgICAgICAgICB9DQogICAgICAgIH0NCiAgICB9DQogICAgcmV0dXJuIGZhbHNlOw0KfQ0KDQpmdW5jdGlvbiBjcmVhdGVTdHlsZUVsZW1lbnQoYmxvY2tOdW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gICAgICAgICBlbXB0eVZhbHVlcyA9IGZhbHNlOw0KICAgICAgICAgICAgbWFyZ2luU3RyaW5nID0gJzAgMCAwIGF1dG8nOw0KICAgICAgICAgICAgdGV4dEFsaWduU3RyaW5nID0gJ3JpZ2h0JzsNCiAgICAgICAgICAgIGJyZWFrOw0KICAgICAgICBjYXNlICdjZW50ZXInOg0KICAgICAgICAgICAgZW1wdHlWYWx1ZXMgPSBmYWxzZTsNCiAgICAgICAgICAgIG1hcmdpblN0cmluZyA9ICcwIGF1dG8nOw0KICAgICAgICAgICAgdGV4dEFsaWduU3RyaW5nID0gJ2NlbnRlcic7DQogICAgICAgICAgICBicmVhazsNCiAgICAgICAgY2FzZSAnZGVmYXVsdCc6DQogICAgICAgICAgICBlbXB0eVZhbHVlcyA9IHRydWU7DQogICAgICAgICAgICBtYXJnaW5TdHJpbmcgPSAnZGVmYXVsdCc7DQogICAgICAgICAgICB0ZXh0QWxpZ25TdHJpbmcgPSAnZGVmYXVsdCc7DQogICAgICAgICAgICAvKiogaGVyZSB3aWxsIGJlIGNzcyAqLw0KICAgICAgICAgICAgYnJlYWs7DQogICAgfQ0KICAgIGlmICghZW1wdHlWYWx1ZXMpIHsNCiAgICAgICAgaHRtbFRvQWRkID0gJy5wZXJjZW50UG9pbnRlckNsYXNzICA+ICpbZGF0YS1pZD0iJytibG9ja051bWJlcisnIl0ge1xuJyArDQogICAgICAgICAgICAnICAgIG1hcmdpbjogJyttYXJnaW5TdHJpbmcrJztcbicgKw0KICAgICAgICAgICAgJ31cbic7DQogICAgfQ0KDQogICAgZWxlbWVudFRvQWRkU3R5bGVMb2NhbC5pbm5lckhUTUwgKz0gaHRtbFRvQWRkOw0KICAgIHJldHVybiB0ZXh0QWxpZ25TdHJpbmc7DQp9DQoNCmZ1bmN0aW9uIGluaXRUYXJnZXRUb0luc2VydChwb3NpdGlvbiwgdHlwZSwgY3VycmVudEVsZW1lbnQpIHsNCiAgICBsZXQgcG9zQ3VycmVudEVsZW1lbnQ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GVkID0gdHJ1ZTsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdGVzdEltYWdlQ29tcFdpZHRoID0gZ2V0Q29tcHV0ZWRTdHlsZShmaWd1cmVDaGlsZHNbZmNDb3VdKTsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdGVzdEltYWdlQ29tcFdpZHRoID0gcGFyc2VJbnQodGVzdEltYWdlQ29tcFdpZHRoLndpZHRoKTsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coJ2ltZ19mX3c6JytmaWd1cmVDb21XaWR0aCsnOyBpbWdfdzonK3Rlc3RJbWFnZUNvbXBXaWR0aCsnOycpOw0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBmY0NvdSsrOw0KICAgICAgICAgICAgICAgICAgICAgICAgfQ0KICAgICAgICAgICAgICAgICAgICB9DQogICAgICAgICAgICAgICAgfQ0KICAgICAgICAgICAgICAgIGlmICh0ZXN0SW1nIGluc3RhbmNlb2YgSFRNTEltYWdlRWxlbWVudCkgew0KICAgICAgICAgICAgICAgICAgICB0ZXN0SW1nRGV0ZWN0ZWQgPSB0cnVlOw0KICAgICAgICAgICAgICAgICAgICB0ZXN0SW1hZ2VDb21wV2lkdGggPSBnZXRDb21wdXRlZFN0eWxlKHRlc3RJbWcpOw0KICAgICAgICAgICAgICAgICAgICB0ZXN0SW1hZ2VDb21wV2lkdGggPSBwYXJzZUludCh0ZXN0SW1hZ2VDb21wV2lkdGgud2lkdGgpOw0KICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZygnaW1nX3c6Jyt0ZXN0SW1hZ2VDb21wV2lkdGgrJzsnKTsNCiAgICAgICAgICAgICAgICB9DQogICAgICAgICAgICAgICAgaWYgKCF0ZXN0SW1nLnByZXZpb3VzU2libGluZykgew0KICAgICAgICAgICAgICAgICAgICBicmVhazsNCiAgICAgICAgICAgICAgICB9DQogICA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ICAgICAgICAgICAgICAgaWYgKGN1cnJFeGNTdHIubGVuZ3RoID4gMSkgew0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIGN1cnJFeGNTdHIgPSBjdXJyRXhjU3RyLnN1YnN0cmluZygxKTsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBleGNBcnJbJ2lkJ10ucHVzaChjdXJyRXhjU3RyKTsNCiAgICAgICAgICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOw0KICAgICAgICAgICAgICAgICAgICBjYXNlICcuJzoNCiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChjdXJyRXhjU3RyLmxlbmd0aCA+IDEpIHsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBjdXJyRXhjU3RyID0gY3VyckV4Y1N0ci5zdWJzdHJpbmcoMSk7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgZXhjQXJyWydjbGFzcyddLnB1c2goY3VyckV4Y1N0cik7DQogICAgICAgICAgICAgICAgICAgICAgICB9DQogICAgICAgICAgICAgICAgICAgICAgICBicmVhazsNCiAgICAgICAgICAgICAgICAgICAgZGVmYXVsdDoNCiAgICAgICAgICAgICAgICAgICAgICAgIGV4Y0FyclsndGFnJ10ucHVzaChjdXJyRXhjU3RyKTsNCiAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOw0KICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgICAgICBjb3UrKzsNCiAgICAgICAgICAgIH0NCiAgICAgICAgfQ0KICAgIH0NCiAgICByZXR1cm4gZXhjQXJyOw0KfQ0KDQpmdW5jdGlvbiBhc3luY0Jsb2Nrc0luc2VydGluZ0Z1bmN0aW9uKGJsb2NrU2V0dGluZ0FycmF5KSB7DQogICAgdHJ5IHsNCiAgICAgICAgdmFyIGNvbnRlbnRfcG9pbnRlciA9IGRvY3VtZW50LnF1ZXJ5U2VsZWN0b3IoIiNjb250ZW50X3BvaW50ZXJfaWQiKTsgLyogb3JpZyAqLw0KICAgICAgICB2YXIgcGFyZW50X3dpdGhfY29udGVudCA9IGNvbnRlbnRfcG9pbnRlci5wYXJlbnRFbGVtZW50Ow0KICAgICAgICB2YXIgbG9yZE9mRWxlbWVudHMgPSBwYXJlbnRfd2l0aF9jb250ZW50Ow0KICAgICAgICBwYXJlbnRfd2l0aF9jb250ZW50ID0gcGFyZW50X3dpdGhfY29udGVudC5wYXJlbnRFbGVtZW50Ow0KICAgICAgICB2YXIgbmV3RWxlbWVudCA9IGRvY3VtZW50LmNyZWF0ZUVsZW1lbnQoImRpdiIpOw0KICAgICAgICB2YXIgZWxlbWVudFRvQWRkOw0KICAgICAgICB2YXIgZWxlbWVudFRvQWRkU3R5bGU7DQogICAgICAgIHZhciBwb29sYmFja0kgPSAwOw0KICAgICAgICB2YXIgY291bnRlciA9IDA7DQogICAgICAgIHZhciBjdXJyZW50RWxlbWVudDsNCiAgICAgICAgdmFyIHJlcGVhdGFibGVDdXJyZW50RWxlbWVudDsNCiAgICAgICAgdmFyIHJlcGVhdGFibGVTdWNjZXNzOw0KICAgICAgICB2YXIgcmVDb3U7DQogICAgICAgIHZhciBjdXJGaXJzdFBsYWNlOw0KICAgICAgICB2YXIgY3VyRWxlbWVudENvdW50Ow0KICAgICAgICB2YXIgY3VyRWxlbWVudFN0ZXA7DQogICAgICAgIHZhciBiYWNrRWxlbWVudCA9IDA7DQogICAgICAgIHZhciBzdW1SZXN1bHQgPSAwOw0KICAgICAgICB2YXIgY3VyU3VtUmVzdWx0ID0gMDsNCiAgICAgICAgdmFyIHJlcGVhdCA9IGZhbHNlOw0KICAgICAgICB2YXIgY3VycmVudEVsZW1lbnRDaGVja2VyID0gZmFsc2U7DQogICAgICAgIGxldCBjb250YWluZXJGb3I2dGggPSBbXTsNCiAgICAgICAgbGV0IGNvbnRhaW5lckZvcjd0aCA9IFtdOw0KICAgICAgICB2YXIgcG9zQ3VycmVudEVsZW1lbnQ7DQogICAgICAgIHZhciBibG9ja19udW1iZXI7D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ICAgICAgIGxldCBFeGNTdHJDb3UgPSAxOw0KICAgICAgICBsZXQgZGV0YWlsZWRRdWVyeVN0cmluZzsNCiAgICAgICAgbGV0IHVzZWRFbGVtZW50Ow0KICAgICAgICBsZXQgdGFnTGlzdCA9IFtdOw0KICAgICAgICBsZXQgbG9jYWxTdW1SZXN1bHQ7DQogICAgICAgIGxldCBiaW5kZXJOYW1lOw0KDQogICAgICAgIHZhciByZW1vdmVDbGVhcmluZzsNCiAgICAgICAgdmFyIHJlcGVhdGFibGVCbG9ja0lkZW50aWZpZXIgPSAwOw0KDQogICAgICAgIHZhciBpOw0KDQogICAgICAgIGlmIChjb250ZW50TGVuZ3RoIDwgMSkgew0KICAgICAgICAgICAgY29udGVudExlbmd0aCA9IHBhcmVudF93aXRoX2NvbnRlbnQuaW5uZXJUZXh0Lmxlbmd0aA0KICAgICAgICB9DQoNCiAgICAgICAgcmJfdGVtcEVsZW1lbnQgPSBkb2N1bWVudC5xdWVyeVNlbGVjdG9yKCcjcmJfdGVtcEVsZW1lbnQnKTsNCiAgICAgICAgaWYgKCFyYl90ZW1wRWxlbWVudCkgew0KICAgICAgICAgICAgcmJfdGVtcEVsZW1lbnQgPSBkb2N1bWVudC5jcmVhdGVFbGVtZW50KCdzcGFuJyk7DQogICAgICAgICAgICByYl90ZW1wRWxlbWVudC5zZXRBdHRyaWJ1dGUoJ2lkJywgJ3JiX3RlbXBFbGVtZW50Jyk7DQogICAgICAgIH0NCg0KICAgICAgICBmdW5jdGlvbiBnZXRGcm9tQ29uc3RydWN0aW9ucyhjdXJyZW50RWxlbWVudCkgew0KICAgICAgICAgICAgaWYgKGN1cnJlbnRFbGVtZW50LnBhcmVudEVsZW1lbnQudGFnTmFtZS50b0xvd2VyQ2FzZSgpID09ICJibG9ja3F1b3RlIikgew0KICAgICAgICAgICAgICAgIGN1cnJlbnRFbGVtZW50ID0gY3VycmVudEVsZW1lbnQucGFyZW50RWxlbWVudDsNCiAgICAgICAgICAgICAgICAvKiBpbml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0cnVjdGlvbj1mYWxzZTsNCiAgICAgICAgICAgIH0NCiAgICAgICAgICAgIHJldHVybiBjdXJyZW50RWxlbWVudDsNCiAgICAgICAgfQ0KDQogICAgICAgIGZ1bmN0aW9uIGRpcmVjdENsYXNzRWxlbWVudERldGVjdGluZyhibG9ja1NldHRpbmdBcnJheSwgZGlyZWN0RWxlbWVudCkgew0KICAgICAgICAgICAgbGV0IGZpbmRRdWVyeSA9IDA7DQogICAgICAgICAgICBsZXQgZGlyZWN0Q2xhc3NFbGVtZW50UmVzdWx0ID0gW107DQoNCiAgICAgICAgICAgIGN1cnJlbnRFbGVtZW50ID0gZG9jdW1lbnQucXVlcnlTZWxlY3RvckFsbChkaXJlY3RFbGVtZW50KTsNCiAgICAgICAgICAgIGlmIChjdXJyZW50RWxlbWVudC5sZW5ndGggPiAwKSB7DQogICAgICAgICAgICAgICAgaWYgKGJsb2NrU2V0dGluZ0FycmF5W2ldWydlbGVtZW50UGxhY2UnXSA+IDEpIHsNCiAgICAgICAgICAgICAgICAgICAgaWYgKGN1cnJlbnRFbGVtZW50Lmxlbmd0aCA+PSBibG9ja1NldHRpbmdBcnJheVtpXVsnZWxlbWVudFBsYWNlJ10pIHsNCiAgICAgICAgICAgICAgICAgICAgICAgIGN1cnJlbnRFbGVtZW50ID0gY3VycmVudEVsZW1lbnRbYmxvY2tTZXR0aW5nQXJyYXlbaV1bJ2VsZW1lbnRQbGFjZSddLTFdOw0KICAgICAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKGN1cnJlbnRFbGVtZW50Lmxlbmd0aCA8IGJsb2NrU2V0dGluZ0FycmF5W2ldWydlbGVtZW50UGxhY2UnXSkgew0KICAgICAgICAgICAgICAgICAgICAgICAgY3VycmVudEVsZW1lbnQgPSBjdXJyZW50RWxlbWVudFtjdXJyZW50RWxlbWVudC5sZW5ndGggLSAxXTsNCiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsNCiAgICAgICAgICAgICAgICAgICAgICAgIGZpbmRRdWVyeSA9IDE7DQogICAgICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKGJsb2NrU2V0dGluZ0FycmF5W2ldWydlbGVtZW50UGxhY2UnXSA8IDApIHsNCiAgICAgICAgICAgICAgICAgICAgaWYgKChjdXJyZW50RWxlbWVudC5sZW5ndGggKyBibG9ja1NldHRpbmdBcnJheVtpXVsnZWxlbWVudFBsYWNlJ10gKyAxKSA+IDApIHsNCiAgICAgICAgICAgICAgICAgICAgICAgIGN1cnJlbnRFbGVtZW50ID0gY3VycmVudEVsZW1lbnRbY3VycmVudEVsZW1lbnQubGVuZ3RoICsgYmxvY2tTZXR0aW5nQXJyYXlbaV1bJ2VsZW1lbnRQbGFjZSddXTsNCiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsNCiAgICAgICAgICAgICAgICAgICAgICAgIGZpbmRRdWVyeSA9IDE7DQogICAgICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgICAgICB9IGVsc2Ugew0KICAgICAgICAgICAgICAgICAgICBmaW5kUXVlcnkgPSAxOw0KICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgIH0gZWxzZSB7DQogICAgICAgICAgICAgICAgZmluZFF1ZXJ5ID0gMTsNCiAgICAgICAgICAgIH0NCg0KICAgICAgICAgICAgZGlyZWN0Q2xhc3NFbGVtZW50UmVzdWx0WydmaW5kUXVlcnknXSA9IGZpbmRRdWVyeTsNCiAgICAgICAgICAgIGRpcmVjdENsYXNzRWxlbWVudFJlc3VsdFsnY3VycmVudEVsZW1lbnQnXSA9IGN1cnJlbnRFbGVtZW50Ow0KDQogICAgICAgICAgICByZXR1cm4gZGlyZWN0Q2xhc3NFbGVtZW50UmVzdWx0Ow0KICAgICAgICB9DQoNCiAgICAgICAgZnVuY3Rpb24gcGxhY2luZ1RvSDEodXNlZEVsZW1lbnQsIGVsZW1lbnRUYWdUb0ZpbmQpIHsNCiAgICAgICAgICAgIGxldCB1c2VsZXNzTGV0Ow0KICAgICAgICAgICAgY3VycmVudEVsZW1lbnQgPSB1c2VkRWxlbWVudC5xdWVyeVNlbGVjdG9yQWxsKGVsZW1lbnRUYWdUb0ZpbmQpOw0KDQogICAgICAgICAgICBpZiAoY3VycmVudEVsZW1lbnQubGVuZ3RoIDwgMSkgew0KICAgICAgICAgICAgICAgIGlmICh1c2VkRWxlbWVudC5wYXJlbnRFbGVtZW50KSB7DQogICAgICAgICAgICAgICAgICAgIHVzZWxlc3NMZXQgPSBwbGFjaW5nVG9IMSh1c2VkRWxlbWVudC5wYXJlbnRFbGVtZW50LCBlbGVtZW50VGFnVG9GaW5kKTsNCiAgICAgICAgICAgICAgICB9DQogICAgICAgICAgICB9DQogICAgICAgICAgICByZXR1cm4gY3VycmVudEVsZW1lbnQ7DQogICAgICAgIH0NCg0KICAgICAgICBmdW5jdGlvbiBlbGVtZW50c0NsZWFuaW5nKGV4Y0FyciwgZWxMaXN0LCBwd2NMb2NhbCwgZ2F0aGVyU3RyaW5nKSB7DQogICAgICAgICAgICBsZXQgbWFya2VkQ2xhc3MgPSAncmJfbV9pbmMnOw0KICAgICAgICAgICAgbGV0IG1hcmtlZENsYXNzQmFkID0gJ3JiX21fZXhjJzsNCiAgICAgICAgICAgIGxldCBjb3UgPSAwOw0KICAgICAgICAgICAgbGV0IGNvdTEgPSAwOw0KICAgICAgICAgICAgbGV0IGZpbmFsQXJyID0gW107DQogICAgICAgICAgICBsZXQgZmluYWxBcnJDbGVhciA9IFtdOw0KICAgICAgICAgICAgbGV0IGNoZWNrTmVhcmVzdDsNCiAgICAgICAgICAgIGxldCBvdXRPZlJhbmdlQ2hlY2s7DQogICAgICAgICAgICBsZXQgZ2F0aGVyUmVqZWN0ZWQ7DQogICAgICAgICAgICBsZXQgYWxsb3dlcjsNCg0KICAgICAgICAgICAgdHJ5IHsNCiAgICAgICAgICAgICAgICB3aGlsZSAoZWxMaXN0W2NvdV0pIHsNCiAgICAgICAgICAgICAgICAgICAgYWxsb3dlciA9IHRydWU7DQogICAgICAgICAgICAgICAgICAgIGlmICghZWxMaXN0W2NvdV0uY2xhc3NMaXN0LmNvbnRhaW5zKG1hcmtlZENsYXNzQmFkKSkgew0KICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGV4Y0FyciYmZXhjQXJyLmxlbmd0aCA+IDApIHsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb3UxID0gMDsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICB3aGlsZSAoZXhjQXJyW2NvdTFdKSB7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNoZWNrTmVhcmVzdCA9IGVsTGlzdFtjb3VdLnBhcmVudEVsZW1lbnQuY2xvc2VzdChleGNBcnJbY291MV0pOw0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoY2hlY2tOZWFyZXN0KSB7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjaGVja05lYXJlc3QuY2xhc3NMaXN0LmFkZCgnY3VyckNsb3Nlc3QnKTsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dE9mUmFuZ2VDaGVjayA9IHB3Y0xvY2FsLnF1ZXJ5U2VsZWN0b3IoJy5jdXJyQ2xvc2VzdCcpOw0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKG91dE9mUmFuZ2VDaGVjaykgew0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGFsbG93ZXIgPSBmYWxzZTsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjaGVja05lYXJlc3QuY2xhc3NMaXN0LmFkZChtYXJrZWRDbGFzcyk7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZ2F0aGVyUmVqZWN0ZWQgPSBjaGVja05lYXJlc3QucXVlcnlTZWxlY3RvckFsbChnYXRoZXJTdHJpbmcpOw0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChnYXRoZXJSZWplY3RlZC5sZW5ndGggPiAwKSB7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZvciAobGV0IGkxID0gMDsgaTEgPCBnYXRoZXJSZWplY3RlZC5sZW5ndGg7IGkxKyspIHsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGdhdGhlclJlamVjdGVkW2kxXS5jbGFzc0xpc3QuYWRkKG1hcmtlZENsYXNzQmFkKTsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQ0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNoZWNrTmVhcmVzdC5jbGFzc0xpc3QucmVtb3ZlKCdjdXJyQ2xvc2VzdCcpOw0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvdTErKzsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9DQogICAgICAgICAgICAgICAgICAgICAgICB9DQogICAgICAgICAgICAgICAgICAgICAgICBpZiAoYWxsb3dlcj09PXRydWUpIHsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBlbExpc3RbY291XS5jbGFzc0xpc3QuYWRkKG1hcmtlZENsYXNzKTsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAvKiBmaW5hbEFyci5wdXNoKGVsTGlzdFtjb3VdKTsgKi8NCiAgICAgICAgICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgICAgICAgICAgfQ0KICAgICAgICAgICAgICAgICAgICBjb3UrKzsNCiAgICAgICAgICAgICAgICB9DQogICAgICAgICAgICAgICAgZmluYWxBcnIgPSBwd2NMb2NhbC5xdWVyeVNlbGVjdG9yQWxsKCcuJyttYXJrZWRDbGFzcysnOm5vdCgnK21hcmtlZENsYXNzQmFkKycpJyk7DQogICAgICAgICAgICAgICAgZmluYWxBcnJDbGVhciA9IHB3Y0xvY2FsLnF1ZXJ5U2VsZWN0b3JBbGwoJy4nK21hcmtlZENsYXNzKycsLicrbWFya2VkQ2xhc3NCYWQpOw0KICAgICAgICAgICAgICAgIGlmIChmaW5hbEFyckNsZWFyJiZmaW5hbEFyckNsZWFyLmxlbmd0aCA+IDApIHsNCiAgICAgICAgICAgICAgICAgICAgZm9yIChsZXQgaTEgPSAwOyBpMSA8IGZpbmFsQXJyQ2xlYXIubGVuZ3RoOyBpMSsrKSB7DQogICAgICAgICAgICAgICAgICAgICAgICBmaW5hbEFyckNsZWFyW2kxXS5jbGFzc0xpc3QucmVtb3ZlKG1hcmtlZENsYXNzLG1hcmtlZENsYXNzQmFkKTsNCiAgICAgICAgICAgICAgICAgICAgfQ0KICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgIH0gY2F0Y2ggKGVyKSB7DQogICAgICAgICAgICAgICAgY29uc29sZS5sb2coZXIubWVzc2FnZSk7DQogICAgICAgICAgICB9DQogICAgICAgICAgICByZXR1cm4gZmluYWxBcnI7DQogICAgICAgIH0NCg0KICAgICAgICBmdW5jdGlvbiBjdXJlZW50RWxlbWVudHNHYXRoZXIodXNlZEVsZW1lbnQsIGxvb3BMaW1pdCA9IDIsIGxvY2FsUHdjID0gcGFyZW50X3dpdGhfY29udGVudCkgew0KICAgICAgICAgICAgbGV0IGN1ckVsZW1lbnRTZWFyY2hSZXBlYXRlciA9IHRydWU7DQogICAgICAgICAgICBsZXQgY3VyRWxlbWVudFNlYXJjaENvdW50ZXIgPSAwOw0KICAgICAgICAgICAgbGV0IGN1cnJlbnRFbGVtZW50TG9jID0gbnVsbDsNCiAgICAgICAgICAgIGxldCBFeGNsdWRlZFN0cmluZ0JlZ2luID0gJyc7DQogICAgICAgICAgICBsZXQgRXhjbHVkZWRTdHJpbmcgPSAnJzsNCiAgICAgICAgICAgIGxldCBFeGNsdWRlZFN0cmluZ0VuZCA9ICcnOw0KICAgICAgICAgICAgbGV0IHRhZ0xpc3RTdHJpbmcgPSAnJzsNCiAgICAgICAgICAgIGxldCB0YWdMaXN0U3RyaW5nRXhjID0gJyc7DQogICAgICAgICAgICBsZXQgY291ID0gMDsNCiAgICAgICAgICAgIC8qIGxldCBleGNBcnIgPSBleGNJZENsVW5wYWNrZXIoKTsgKi8NCiAgICAgICAgICAgIGxldCB0YWdMaXN0Q291ID0gMDsNCg0KICAgICAgICAgICAgaWYgKHVzZWRFbGVtZW50PT0naDEnKSB7DQogICAgICAgICAgICAgICAgY3VycmVudEVsZW1lbnRMb2MgPSBwbGFjaW5nVG9IMShsb2NhbFB3YywgdXNlZEVsZW1lbnQpOw0KICAgICAgICAgICAgfSBlbHNlIHsNCiAgICAgICAgICAgICAgICBpZiAodXNlZEVsZW1lbnQ9PSdoMi00Jykge3RhZ0xpc3QgPSBbJ2gyJywnaDMnLCdoMyddO30NCiAgICAgICAgICAgICAgICBlbHNlICAgICAgICAgICAgICAgICAgICAge3RhZ0xpc3QgPSBbdXNlZEVsZW1lbnRdOyAgIH0NCiAgICAgICAgICAgICAgICB3aGlsZSAodGFnTGlzdFt0YWdMaXN0Q291XSkgew0KICAgICAgICAgICAgICAgICAgICB0YWdMaXN0U3RyaW5nICs9ICgoY291Kys+MCk/JywnOicnKSt0YWdMaXN0W3RhZ0xpc3RDb3VdOw0KICAgICAgICAgICAgICAgICAgICB0YWdMaXN0U3RyaW5nRXhjICs9ICc6bm90KCcrdGFnTGlzdFt0YWdMaXN0Q291XSsnKSc7DQogICAgICAgICAgICAgICAgICAgIHRhZ0xpc3RDb3UrKzsNCiAgICAgICAgICAgICAgICB9DQoNCiAgICAgICAgICAgICAgICBFeGNsdWRlZFN0cmluZyA9ICcnOw0KICAgICAgICAgICAgICAgIGlmIChleGNJZENsYXNzJiZleGNJZENsYXNzLmxlbmd0aCA+IDApIHsNCiAgICAgICAgICAgICAgICAgICAgZm9yIChsZXQgaTIgPSAwOyBpMiA8IGV4Y0lkQ2xhc3MubGVuZ3RoOyBpMisrKSB7DQogICAgICAgICAgICAgICAgICAgICAgICBpZiAoZXhjSWRDbGFzc1tpMl0ubGVuZ3RoID4gMCkgew0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIEV4Y2x1ZGVkU3RyaW5nICs9IChpMj4wPycsJzonJykrZXhjSWRDbGFzc1tpMl0rdGFnTGlzdFN0cmluZ0V4YzsNCiAgICAgICAgICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgICAgICAgICAgfQ0KICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgICAgICBkZXRhaWxlZFF1ZXJ5U3RyaW5nICs9IHRhZ0xpc3RTdHJpbmcrJywnK0V4Y2x1ZGVkU3RyaW5nOw0KDQogICAgICAgICAgICAgICAgLyogY29uc29sZS5sb2coZGV0YWlsZWRRdWVyeVN0cmluZyk7ICovDQogICAgICAgICAgICAgICAgd2hpbGUgKGN1ckVsZW1lbnRTZWFyY2hSZXBlYXRlciYmY3VyRWxlbWVudFNlYXJjaENvdW50ZXIgPCBsb29wTGltaXQpIHsNCiAgICAgICAgICAgICAgICAgICAgdHJ5IHsNCiAgICAgICAgICAgICAgICAgICAgICAgIGN1cnJlbnRFbGVtZW50TG9jID0gbG9jYWxQd2MucXVlcnlTZWxlY3RvckFsbCh0YWdMaXN0U3RyaW5nKTsNCiAgICAgICAgICAgICAgICAgICAgfSBjYXRjaCAoZTEpIHtjb25zb2xlLmxvZyhlMS5tZXNzYWdlKTt9DQogICAgICAgICAgICAgICAgICAgIGlmICghY3VycmVudEVsZW1lbnRMb2MpIHsNCiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChsb2NhbFB3Yy5wYXJlbnRFbGVtZW50KSB7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgbG9jYWxQd2MgPSBsb2NhbFB3Yy5wYXJlbnRFbGVtZW50Ow0KICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBicmVhazsNCiAgICAgICAgICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsNCiAgICAgICAgICAgICAgICAgICAgICAgIGN1cnJlbnRFbGVtZW50TG9jID0gZWxlbWVudHNDbGVhbmluZyhleGNJZENsYXNzLCBjdXJyZW50RWxlbWVudExvYywgbG9jYWxQd2MsIGRldGFpbGVkUXVlcnlTdHJpbmcpOw0KICAgICAgICAgICAgICAgICAgICAgICAgY3VyRWxlbWVudFNlYXJjaFJlcGVhdGVyID0gZmFsc2U7DQogICAgICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgICAgICAgICAgY3VyRWxlbWVudFNlYXJjaENvdW50ZXIrKzsNCiAgICAgICAgICAgICAgICB9DQogICAgICAgICAgICB9DQogICAgICAgICAgICByZXR1cm4gY3VycmVudEVsZW1lbnRMb2M7DQogICAgICAgIH0NCg0KICAgICAgICBmdW5jdGlvbiBjdXJyZW50RWxlbWVudFJlY2VpdmVyKHJldmVydCwgbG9jYWxDdXJFbCA9IGN1cnJlbnRFbGVtZW50KSB7DQogICAgICAgICAgICBsZXQgb3JpZ0N1ckVsID0gbG9jYWxDdXJFbDsNCiAgICAgICAgICAgIGN1clN1bVJlc3VsdCA9IHN1bVJlc3VsdDsNCiAgICAgICAgICAgIGRldGFpbGVkRWxlbWVudExpc3QgPSBsb2NhbEN1ckVsOw0KICAgICAgICAgICAgc2FtZUVsZW1lbnRBZnRlcldpZHRoID0gZmFsc2U7DQogICAgICAgICAgICBsZXQgdGVzdENvdSA9IDA7DQogICAgICAgICAgICB3aGlsZSAoZGV0YWlsZWRFbGVtZW50TGlzdFtjdXJTdW1SZXN1bHRdJiZzYW1lRWxlbWVudEFmdGVyV2lkdGg9PWZhbHNlJiZ0ZXN0Q291IDwgOCkgew0KICAgICAgICAgICAgICAgIGxvY2FsQ3VyRWwgPSBkZXRhaWxlZEVsZW1lbnRMaXN0W2N1clN1bVJlc3VsdF07DQogICAgICAgICAgICAgICAgdHJ5IHsNCiAgICAgICAgICAgICAgICAgICAgc2FtZUVsZW1lbnRBZnRlcldpZHRoPXRydWU7DQogICAgICAgICAgICAgICAgICAgIHNhbWVFbGVtZW50QWZ0ZXJXaWR0aCA9IGNoZWNrQWRzV2lkdGgoY29udGVudF9wb2ludGVyLCBibG9ja1NldHRpbmdBcnJheVtpXVsiZWxlbWVudFBvc2l0aW9uIl0sIGxvY2FsQ3VyRWwpOw0KICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGV4KSB7DQogICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGV4Lm1lc3NhZ2UpOw0KICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgICAgICByZXZlcnQ/IGN1clN1bVJlc3VsdC0tOiBjdXJTdW1SZXN1bHQrKzsNCiAgICAgICAgICAgICAgICB0ZXN0Q291Kys7DQogICAgICAgICAgICB9DQogICAgICAgICAgICBpZiAobG9jYWxDdXJFbCkgew0KICAgICAgICAgICAgICAgIGN1cnJlbnRFbGVtZW50Q2hlY2tlciA9IHRydWU7DQogICAgICAgICAgICB9DQogICAgICAgICAgICByZXR1cm4gbG9jYWxDdXJFbD9sb2NhbEN1ckVsOm9yaWdDdXJFbDsNCiAgICAgICAgfQ0KICAgICAgICANCiAgICAgICAgZnVuY3Rpb24gZW5kaW5nQWN0aW9ucyhibG9ja19udW1iZXIpIHsNCiAgICAgICAgICAgIHVzZWRCbG9ja1NldHRpbmdBcnJheUlkcy5wdXNoKGJsb2NrX251bWJlcik7DQogICAgICAgICAgICBibG9ja1NldHRpbmdBcnJheS5zcGxpY2UoaS0tLCAxKTsNCiAgICAgICAgICAgIHBvb2xiYWNrSSA9IDE7DQogICAgICAgIH0NCg0KICAgICAgICBmb3IgKGkgPSAwOyBpIDwgYmxvY2tTZXR0aW5nQXJyYXkubGVuZ3RoOyBpKyspIHsNCiAgICAgICAgICAgIGN1cnJlbnRFbGVtZW50ID0gbnVsbDsNCiAgICAgICAgICAgIGN1cnJlbnRFbGVtZW50Q2hlY2tlciA9IGZhbHNlOw0KICAgICAgICAgICAgc2FtZUVsZW1lbnRBZnRlcldpZHRoID0gZmFsc2U7DQogICAgICAgICAgICBzYW1lRWxlbWVudEFmdGVyRXhjQ2xhc3NJZCA9IGZhbHNlOw0KICAgICAgICAgICAgc2FtZUVsZW1lbnRBZnRlckZyb21Db25zdHJ1Y3Rpb24gPSBmYWxzZTsNCiAgICAgICAgICAgIHRhZ0xpc3RDb3UgPSAwOw0KICAgICAgICAgICAgcG9vbGJhY2tJID0gMDsNCiAgICAgICAgICAgIGRldGFpbGVkUXVlcnlTdHJpbmcgPSAnJzsNCiAgICAgICAgICAgIGJpbmRlck5hbWUgPSBlbGVtZW50QmluZGVyTmFtZUdlbmVyYXRvcigpOw0KDQogICAgICAgICAgICB0cnkgew0KICAgICAgICAgICAgICAgIGlmICghYmxvY2tTZXR0aW5nQXJyYXlbaV1bInRleHQiXQ0KICAgICAgICAgICAgICAgICAgICB8fChibG9ja1NldHRpbmdBcnJheVtpXVsidGV4dCJdJiZibG9ja1NldHRpbmdBcnJheVtpXVsidGV4dCJdLmxlbmd0aCA8IDEpDQogICAgICAgICAgICAgICAgICAgIHx8KHJlamVjdGVkQmxvY2tzJiZyZWplY3RlZEJsb2Nrcy5pbmNsdWRlcyhibG9ja1NldHRpbmdBcnJheVtpXVsiaWQiXSkpDQogICAgICAgICAgICAgICAgICAgIHx8KChibG9ja1NldHRpbmdBcnJheVtpXVsibWF4SGVhZGVycyJdID4gMCkmJihibG9ja1NldHRpbmdBcnJheVtpXVsibWF4SGVhZGVycyJdIDwgcGFyc2VJbnQodGVybW9yYXJpdHlfcGFyZW50X3dpdGhfY29udGVudF9sZW5ndGgpKSkNCiAgICAgICAgICAgICAgICAgICAgfHwoKGJsb2NrU2V0dGluZ0FycmF5W2ldWyJtYXhTeW1ib2xzIl0gPiAwKSYmKGJsb2NrU2V0dGluZ0FycmF5W2ldWyJtYXhTeW1ib2xzIl0gPCBwYXJzZUludChjb250ZW50TGVuZ3RoKSkpDQogICAgICAgICAgICAgICAgICAgIHx8KGNvbnRlbnRfcG9pbnRlci5jbGFzc0xpc3QuY29udGFpbnMoImhhcmQtY29udGVudCIpJiZibG9ja1NldHRpbmdBcnJheVtpXVsic2V0dGluZ190eXBlIl0hPTMpDQogICAgICAgICAgICAgICAgKSB7DQogICAgICAgICAgICAgICAgICAgIGJsb2NrU2V0dGluZ0FycmF5LnNwbGljZShpLS0sIDEpOw0KICAgICAgICAgICAgICAgICAgICBwb29sYmFja0kgPSAxOw0KICAgICAgICAgICAgICAgICAgICBjb250aW51ZTsNCiAgICAgICAgICAgICAgICB9DQoNCiAgICAgICAgICAgICAgICBibG9ja19udW1iZXIgPSAwOw0KDQogICAgICAgICAgICAgICAgZWxlbWVudFRvQWRkID0gZG9jdW1lbnQuY3JlYXRlRWxlbWVudCgiZGl2Iik7DQogICAgICAgICAgICAgICAgZWxlbWVudFRvQWRkLmNsYXNzTGlzdC5hZGQoInBlcmNlbnRQb2ludGVyQ2xhc3MiKTsNCiAgICAgICAgICAgICAgICBlbGVtZW50VG9BZGQuY2xhc3NMaXN0LmFkZCgibWFya2VkIik7DQogICAgICAgICAgICAgICAgaWYgKGJsb2NrU2V0dGluZ0FycmF5W2ldWyJzYyJdPT0xKSB7DQogICAgICAgICAgICAgICAgICAgIGVsZW1lbnRUb0FkZC5jbGFzc0xpc3QuYWRkKCJzY01hcmsiKTsNCiAgICAgICAgICAgICAgICB9DQogICAgICAgICAgICAgICAgZWxlbWVudFRvQWRkLmlubmVySFRNTCA9IGJsb2NrU2V0dGluZ0FycmF5W2ldWyJ0ZXh0Il07DQogICAgICAgICAgICAgICAgZWxlbWVudFRvQWRkLmRhdGFzZXQucmJpbmRlciA9IGJpbmRlck5hbWU7DQogICAgICAgICAgICAgICAgYmxvY2tfbnVtYmVyID0gZWxlbWVudFRvQWRkLmNoaWxkcmVuWzBdLmF0dHJpYnV0ZXNbJ2RhdGEtaWQnXS52YWx1ZTsNCg0KICAgICAgICAgICAgICAgIGlmIChibG9ja0R1cGxpY2F0ZSA9PSAnbm8nKSB7DQogICAgICAgICAgICAgICAgICAgIGlmICh1c2VkQmxvY2tTZXR0aW5nQXJyYXlJZHMubGVuZ3RoID4gMCkgew0KICAgICAgICAgICAgICAgICAgICAgICAgZm9yIChsZXQgaTEgPSAwOyBpMSA8IHVzZWRCbG9ja1NldHRpbmdBcnJheUlkcy5sZW5ndGg7IGkxKyspIHsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoYmxvY2tfbnVtYmVyPT11c2VkQmxvY2tTZXR0aW5nQXJyYXlJZHNbaTFdKSB7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGJsb2NrU2V0dGluZ0FycmF5LnNwbGljZShpLS0sIDEpOw0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwb29sYmFja0kgPSAxOw0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBicmVhazsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9DQogICAgICAgICAgICAgICAgICAgICAgICB9DQogICAgICAgICAgICAgICAgICAgICAgICBpZiAocG9vbGJhY2tJID09IDEpIHsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb250aW51ZTsNCiAgICAgICAgICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgICAgICAgICAgfQ0KICAgICAgICAgICAgICAgIH0NCg0KICAgICAgICAgICAgICAgIGVsZW1lbnRUb0FkZFN0eWxlID0gY3JlYXRlU3R5bGVFbGVtZW50KGJsb2NrX251bWJlciwgYmxvY2tTZXR0aW5nQXJyYXlbaV1bImVsZW1lbnRDc3MiXSk7DQoNCiAgICAgICAgICAgICAgICBpZiAoZWxlbWVudFRvQWRkU3R5bGUmJmVsZW1lbnRUb0FkZFN0eWxlIT0nZGVmYXVsdCcpIHsNCiAgICAgICAgIC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FbGVtZW50ID0gY3VycmVudEVsZW1lbnRSZWNlaXZlcih0cnVlKTsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9DQogICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2Ugew0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIHN1bVJlc3VsdCA9IGJsb2NrU2V0dGluZ0FycmF5W2ldWyJlbGVtZW50UGxhY2UiXSAtIDE7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHN1bVJlc3VsdCA8IGN1cnJlbnRFbGVtZW50Lmxlbmd0aCkgew0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjdXJyZW50RWxlbWVudCA9IGN1cnJlbnRFbGVtZW50UmVjZWl2ZXIoZmFsc2UpOw0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgICAgICAgICAgfQ0KICAgICAgICAgICAgICAgICAgICBpZiAoY3VycmVudEVsZW1lbnQgIT0gdW5kZWZpbmVkICYmIGN1cnJlbnRFbGVtZW50ICE9IG51bGwgJiYgY3VycmVudEVsZW1lbnRDaGVja2VyKSB7DQogICAgICAgICAgICAgICAgICAgICAgICBwb3NDdXJyZW50RWxlbWVudCA9IGluaXRUYXJnZXRUb0luc2VydChibG9ja1NldHRpbmdBcnJheVtpXVsiZWxlbWVudFBvc2l0aW9uIl0sICdlbGVtZW50JywgY3VycmVudEVsZW1lbnQpOw0KICAgICAgICAgICAgICAgICAgICAgICAgY3VycmVudEVsZW1lbnQucGFyZW50Tm9kZS5pbnNlcnRCZWZvcmUoZWxlbWVudFRvQWRkLCBwb3NDdXJyZW50RWxlbWVudCk7DQogICAgICAgICAgICAgICAgICAgICAgICBjdXJyZW50RWxlbWVudC5jbGFzc0xpc3QuYWRkKCdyYmluZGVyLScrYmluZGVyTmFtZSk7DQogICAgICAgICAgICAgICAgICAgICAgICBlbGVtZW50VG9BZGQuY2xhc3NMaXN0LnJlbW92ZSgnY292ZXJlZEFkJyk7DQogICAgICAgICAgICAgICAgICAgICAgICB1c2VkQmxvY2tTZXR0aW5nQXJyYXlJZHMucHVzaChibG9ja19udW1iZXIpOw0KICAgICAgICAgICAgICAgICAgICAgICAgYmxvY2tTZXR0aW5nQXJyYXkuc3BsaWNlKGktLSwgMSk7DQogICAgICAgICAgICAgICAgICAgICAgICBwb29sYmFja0kgPSAxOw0KICAgICAgICAgICAgICAgICAgICAgICAgcmJfdGVtcEVsZW1lbnRfY2hlY2sgPSBmYWxzZTsNCiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsNCiAgICAgICAgICAgICAgICAgICAgICAgIHJlcGVhdCA9IHRydWU7DQogICAgICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgICAgICB9DQogICAgICAgICAgICAgICAgZWxzZSBpZiAoYmxvY2tTZXR0aW5nQXJyYXlbaV1bInNldHRpbmdfdHlwZSJdID09IDIpIHsNCiAgICAgICAgICAgICAgICAgICAgaWYgKGJsb2NrRHVwbGljYXRlID09ICdubycpIHsNCiAgICAgICAgICAgICAgICAgICAgICAgIGJsb2NrU2V0dGluZ0FycmF5W2ldWyJlbGVtZW50Q291bnQiXSA9IDE7DQogICAgICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgICAgICAgICAgcmVwZWF0YWJsZUN1cnJlbnRFbGVtZW50ID0gW107DQogICAgICAgICAgICAgICAgICAgIHJlQ291ID0gMDsNCiAgICAgICAgICAgICAgICAgICAgY3VyRmlyc3RQbGFjZSA9IGJsb2NrU2V0dGluZ0FycmF5W2ldWyJmaXJzdFBsYWNlIl07DQogICAgICAgICAgICAgICAgICAgIGN1ckVsZW1lbnRDb3VudCA9IGJsb2NrU2V0dGluZ0FycmF5W2ldWyJlbGVtZW50Q291bnQiXTsNCiAgICAgICAgICAgICAgICAgICAgY3VyRWxlbWVudFN0ZXAgPSBibG9ja1NldHRpbmdBcnJheVtpXVsiZWxlbWVudFN0ZXAiXTsNCiAgICAgICAgICAgICAgICAgICAgcmVwZWF0YWJsZVN1Y2Nlc3MgPSBmYWxzZTsNCg0KICAgICAgICAgICAgICAgICAgICBlbGVtZW50VG9BZGRTdHlsZSA9IGNyZWF0ZVN0eWxlRWxlbWVudChibG9ja19udW1iZXIsIGJsb2NrU2V0dGluZ0FycmF5W2ldWyJlbGVtZW50Q3NzIl0pOw0KDQogICAgICAgICAgICAgICAgICAgIHJlcGVhdGFibGVDdXJyZW50RWxlbWVudCA9IGN1cmVlbnRFbGVtZW50c0dhdGhlcihibG9ja1NldHRpbmdBcnJheVtpXVsiZWxlbWVudCJdLnRvTG93ZXJDYXNlKCkpOw0KICAgICAgICAgICAgICAgICAgICBpZiAocmVwZWF0YWJsZUN1cnJlbnRFbGVtZW50KSB7DQogICAgICAgICAgICAgICAgICAgICAgICBmb3IgKGxldCBpMSA9IDA7IGkxIDwgYmxvY2tTZXR0aW5nQXJyYXlbaV1bImVsZW1lbnRDb3VudCJdOyBpMSsrKSB7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgY3VycmVudEVsZW1lbnRDaGVja2VyID0gZmFsc2U7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgbGV0IHJlcEVsZW1lbnRUb0FkZCA9IGRvY3VtZW50LmNyZWF0ZUVsZW1lbnQoImRpdiIpOw0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJlcEVsZW1lbnRUb0FkZC5jbGFzc0xpc3QuYWRkKCJwZXJjZW50UG9pbnRlckNsYXNzIik7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgcmVwRWxlbWVudFRvQWRkLmNsYXNzTGlzdC5hZGQoIm1hcmtlZCIpOw0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChibG9ja1NldHRpbmdBcnJheVtpXVsic2MiXT09MSkgew0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXBFbGVtZW50VG9BZGQuY2xhc3NMaXN0LmFkZCgic2NNYXJrIik7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQ0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJlcEVsZW1lbnRUb0FkZC5jbGFzc0xpc3QuYWRkKCJyZXBlYXRhYmxlLW1hcmstIityZXBlYXRhYmxlQmxvY2tJZGVudGlmaWVyKTsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXBFbGVtZW50VG9BZGQuaW5uZXJIVE1MID0gYmxvY2tTZXR0aW5nQXJyYXlbaV1bInRleHQiXTsNCg0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChlbGVtZW50VG9BZGRTdHlsZSYmZWxlbWVudFRvQWRkU3R5bGUhPSdkZWZhdWx0Jykgew0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXBFbGVtZW50VG9BZGQuc3R5bGUudGV4dEFsaWduID0gZWxlbWVudFRvQWRkU3R5bGU7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQ0KDQogICAgICAgICAgICAgICAgICAgICAgICAgICAgc3VtUmVzdWx0ID0gTWF0aC5yb3VuZChwYXJzZUludChibG9ja1NldHRpbmdBcnJheVtpXVsiZmlyc3RQbGFjZSJdKSArIChpMSpwYXJzZUludChibG9ja1NldHRpbmdBcnJheVtpXVsiZWxlbWVudFN0ZXAiXSkpIC0gMSk7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHN1bVJlc3VsdCA8IHJlcGVhdGFibGVDdXJyZW50RWxlbWVudC5sZW5ndGgpIHsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY3VycmVudEVsZW1lbnQgPSBjdXJyZW50RWxlbWVudFJlY2VpdmVyKGZhbHNlLCByZXBlYXRhYmxlQ3VycmVudEVsZW1lbnQpOw0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0NCg0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChjdXJyZW50RWxlbWVudCAhPSB1bmRlZmluZWQgJiYgY3VycmVudEVsZW1lbnQgIT0gbnVsbCAmJiBjdXJyZW50RWxlbWVudENoZWNrZXIpIHsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcG9zQ3VycmVudEVsZW1lbnQgPSBpbml0VGFyZ2V0VG9JbnNlcnQoYmxvY2tTZXR0aW5nQXJyYXlbaV1bImVsZW1lbnRQb3NpdGlvbiJdLCAnZWxlbWVudCcsIGN1cnJlbnRFbGVtZW50KTsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY3VycmVudEVsZW1lbnQucGFyZW50Tm9kZS5pbnNlcnRCZWZvcmUocmVwRWxlbWVudFRvQWRkLCBwb3NDdXJyZW50RWxlbWVudCk7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGN1cnJlbnRFbGVtZW50LmNsYXNzTGlzdC5hZGQoJ3JiaW5kZXItJytiaW5kZXJOYW1lKTsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcmVwRWxlbWVudFRvQWRkLmNsYXNzTGlzdC5yZW1vdmUoJ2NvdmVyZWRBZCcpOw0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjdXJGaXJzdFBsYWNlID0gc3VtUmVzdWx0ICsgcGFyc2VJbnQoYmxvY2tTZXR0aW5nQXJyYXlbaV1bImVsZW1lbnRTdGVwIl0pICsgMTsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY3VyRWxlbWVudENvdW50LS07DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJlcGVhdGFibGVTdWNjZXNzID0gdHJ1ZTsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2Ugew0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXBlYXRhYmxlU3VjY2VzcyA9IGZhbHNlOw0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBicmVhazsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9DQogICAgICAgICAgICAgICAgICAgICAgICB9DQogICAgICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgICAgICAgICAgaWYgKHJlcGVhdGFibGVTdWNjZXNzPT10cnVlKSB7DQogICAgICAgICAgICAgICAgICAgICAgICB1c2VkQmxvY2tTZXR0aW5nQXJyYXlJZHMucHVzaChibG9ja19udW1iZXIpOw0KICAgICAgICAgICAgICAgICAgICAgICAgYmxvY2tTZXR0aW5nQXJyYXkuc3BsaWNlKGktLSwgMSk7DQogICAgICAgICAgICAgICAgICAgICAgICBwb29sYmFja0kgPSAxOw0KICAgICAgICAgICAgICAgICAgICAgICAgcmVwZWF0YWJsZUJsb2NrSWRlbnRpZmllcisrOw0KICAgICAgICAgICAgICAgICAgICB9IGVsc2Ugew0KICAgICAgICAgICAgICAgICAgICAgICAgaWYgKCFibG9ja1NldHRpbmdBcnJheVtpXVsidW5zdWNjZXNzIl0pIHsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBibG9ja1NldHRpbmdBcnJheVtpXVsidW5zdWNjZXNzIl0gPSAxOw0KICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBibG9ja1NldHRpbmdBcnJheVtpXVsidW5zdWNjZXNzIl0gPSBNYXRoLnJvdW5kKGJsb2NrU2V0dGluZ0FycmF5W2ldWyJ1bnN1Y2Nlc3MiXSArIDEpOw0KICAgICAgICAgICAgICAgICAgICAgICAgfQ0KICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGJsb2NrU2V0dGluZ0FycmF5W2ldWyJ1bnN1Y2Nlc3MiXSA+IDEwKSB7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgdXNlZEJsb2NrU2V0dGluZ0FycmF5SWRzLnB1c2goYmxvY2tfbnVtYmVyKTsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBibG9ja1NldHRpbmdBcnJheS5zcGxpY2UoaS0tLCAxKTsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBwb29sYmFja0kgPSAxOw0KICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBibG9ja1NldHRpbmdBcnJheVtpXVsiZmlyc3RQbGFjZSJdID0gY3VyRmlyc3RQbGFjZTsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBibG9ja1NldHRpbmdBcnJheVtpXVsiZWxlbWVudENvdW50Il0gPSBjdXJFbGVtZW50Q291bnQ7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgYmxvY2tTZXR0aW5nQXJyYXlbaV1bImVsZW1lbnRTdGVwIl0gPSBjdXJFbGVtZW50U3RlcDsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXBlYXQgPSB0cnVlOw0KICAgICAgICAgICAgICAgICAgICAgICAgfQ0KICAgICAgICAgICAgICAgICAgICB9DQogICAgICAgICAgICAgICAgfQ0KICAgICAgICAgICAgICAgIGVsc2UgaWYgKGJsb2NrU2V0dGluZ0FycmF5W2ldWyJzZXR0aW5nX3R5cGUiXSA9PSAzKSB7DQogICAgICAgICAgICAgICAgICAgIGxldCBlbGVtZW50VHlwZVN5bWJvbCA9ICcnOw0KICAgICAgICAgICAgICAgICAgICBsZXQgZWxlbWVudFNwYWNlU3ltYm9sID0gJyc7DQogICAgICAgICAgICAgICAgICAgIGxldCBlbGVtZW50TmFtZSA9ICcnOw0KICAgICAgICAgICAgICAgICAgICBsZXQgZWxlbWVudFR5cGUgPSAnJzsNCiAgICAgICAgICAgICAgICAgICAgbGV0IGVsZW1lbnRUYWcgID0gJyc7DQogICAgICAgICAgICAgICAgICAgIGxldCBmaW5kUXVlcnkgPSAwOw0KICAgICAgICAgICAgICAgICAgICBsZXQgZGlyZWN0Q2xhc3NSZXN1bHQgPSBbXTsNCiAgICAgICAgICAgICAgICAgICAgbGV0IGRpcmVjdEVsZW1lbnQgPSBibG9ja1NldHRpbmdBcnJheVtpXVsiZGlyZWN0RWxlbWVudCJdLnRyaW0oKTsNCg0KICAgICAgICAgICAgICAgICAgICBpZiAoZGlyZWN0RWxlbWVudC5zZWFyY2goJyMnKSA+IC0xKSB7DQogICAgICAgICAgICAgICAgICAgICAgICBmaW5kUXVlcnkgPSAxOw0KICAgICAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKChkaXJlY3RFbGVtZW50LnNlYXJjaCgnIycpIDwgMCkmJihkaXJlY3RFbGVtZW50LnNlYXJjaCgnLicpID4gLTEpKSB7DQogICAgICAgICAgICAgICAgICAgICAgICBkaXJlY3RDbGFzc1Jlc3VsdCA9IGRpcmVjdENsYXNzRWxlbWVudERldGVjdGluZyhibG9ja1NldHRpbmdBcnJheSwgZGlyZWN0RWxlbWVudCk7DQogICAgICAgICAgICAgICAgICAgICAgICBmaW5kUXVlcnkgPSBkaXJlY3RDbGFzc1Jlc3VsdFsnZmluZFF1ZXJ5J107DQogICAgICAgICAgICAgICAgICAgICAgICBjdXJyZW50RWxlbWVudCA9IGRpcmVjdENsYXNzUmVzdWx0WydjdXJyZW50RWxlbWVudCddOw0KICAgICAgICAgICAgICAgICAgICB9DQogICAgICAgICAgICAgICAgICAgIGlmIChmaW5kUXVlcnkgPT0gMSkgew0KICAgICAgICAgICAgICAgICAgICAgICAgY3VycmVudEVsZW1lbnQgPSBkb2N1bWVudC5xdWVyeVNlbGVjdG9yKGRpcmVjdEVsZW1lbnQpOw0KICAgICAgICAgICAgICAgICAgICB9DQogICAgICAgICAgICAgICAgICAgIGlmIChjdXJyZW50RWxlbWVudCkgew0KICAgICAgICAgICAgICAgICAgICAgICAgY3VycmVudEVsZW1lbnRDaGVja2VyID0gdHJ1ZTsNCiAgICAgICAgICAgICAgICAgICAgfQ0KDQogICAgICAgICAgICAgICAgICAgIGlmIChjdXJyZW50RWxlbWVudCAhPSB1bmRlZmluZWQgJiYgY3VycmVudEVsZW1lbnQgIT0gbnVsbCAmJiBjdXJyZW50RWxlbWVudENoZWNrZXIpIHsNCiAgICAgICAgICAgICAgICAgICAgICAgIHBvc0N1cnJlbnRFbGVtZW50ID0gaW5pdFRhcmdldFRvSW5zZXJ0KGJsb2NrU2V0dGluZ0FycmF5W2ldWyJlbGVtZW50UG9zaXRpb24iXSwgJ2VsZW1lbnQnLCBjdXJyZW50RWxlbWVudCk7DQogICAgICAgICAgICAgICAgICAgICAgICBjdXJyZW50RWxlbWVudC5wYXJlbnROb2RlLmluc2VydEJlZm9yZShlbGVtZW50VG9BZGQsIHBvc0N1cnJlbnRFbGVtZW50KTsNCiAgICAgICAgICAgICAgICAgICAgICAgIGVsZW1lbnRUb0FkZC5jbGFzc0xpc3QucmVtb3ZlKCdjb3ZlcmVkQWQnKTsNCiAgICAgICAgICAgICAgICAgICAgICAgIGN1cnJlbnRFbGVtZW50LmNsYXNzTGlzdC5hZGQoJ3JiaW5kZXItJytiaW5kZXJOYW1lKTsNCiAgICAgICAgICAgICAgICAgICAgICAgIHVzZWRCbG9ja1NldHRpbmdBcnJheUlkcy5wdXNoKGJsb2NrX251bWJlcik7DQogICAgICAgICAgICAgICAgICAgICAgICBibG9ja1NldHRpbmdBcnJheS5zcGxpY2UoaS0tLCAxKTsNCiAgICAgICAgICAgICAgICAgICAgICAgIHBvb2xiYWNrSSA9IDE7DQogICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7DQogICAgICAgICAgICAgICAgICAgICAgICByZXBlYXQgPSB0cnVlOw0KICAgICAgICAgICAgICAgICAgICB9DQogICAgICAgICAgICAgICAgfQ0KICAgICAgICAgICAgICAgIGVsc2UgaWYgKGJsb2NrU2V0dGluZ0FycmF5W2ldWyJzZXR0aW5nX3R5cGUiXSA9PSA0KSB7DQogICAgICAgICAgICAgICAgICAgIGRvY3VtZW50LnF1ZXJ5U2VsZWN0b3IoIiNjb250ZW50X3BvaW50ZXJfaWQiKS5wYXJlbnRFbGVtZW50LmFwcGVuZChlbGVtZW50VG9BZGQpOw0KICAgICAgICAgICAgICAgICAgICB1c2VkQmxvY2tTZXR0aW5nQXJyYXlJZHMucHVzaChibG9ja19udW1iZXIpOw0KICAgICAgICAgICAgICAgICAgICBibG9ja1NldHRpbmdBcnJheS5zcGxpY2UoaS0tLCAxKTsNCiAgICAgICAgICAgICAgICAgICAgcG9vbGJhY2tJID0gMTsNCiAgICAgICAgICAgICAgICB9DQogICAgICAgICAgICAgICAgZWxzZSBpZiAoYmxvY2tTZXR0aW5nQXJyYXlbaV1bInNldHRpbmdfdHlwZSJdID09IDUpIHsNCiAgICAgICAgICAgICAgICAgICAgbGV0IGN1cnJlbnRFbGVtZW50TGlzdCA9IGN1cmVlbnRFbGVtZW50c0dhdGhlcigncCcsIDEsIGNvbnRlbnRfcG9pbnRlci5wYXJlbnRFbGVtZW50KTsNCiAgICAgICAgICAgICAgICAgICAgaWYgKGN1cnJlbnRFbGVtZW50TGlzdCYmY3VycmVudEVsZW1lbnRMaXN0Lmxlbmd0aCA+IDApIHsNCiAgICAgICAgICAgICAgICAgICAgICAgIGxldCBwQ291bnQgPSBjdXJyZW50RWxlbWVudExpc3QubGVuZ3RoOw0KICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGVsZW1lbnROdW1iZXIgPSBNYXRoLnJvdW5kKHBDb3VudC8yKTsNCiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChwQ291bnQgPiAxKSB7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgY3VycmVudEVsZW1lbnQgPSBjdXJyZW50RWxlbWVudExpc3RbZWxlbWVudE51bWJlcisxXTsNCiAgICAgICAgICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChjdXJyZW50RWxlbWVudCAhPSB1bmRlZmluZWQgJiYgY3VycmVudEVsZW1lbnQgIT0gbnVsbCkgew0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChwQ291bnQgPiAxKSB7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGN1cnJlbnRFbGVtZW50LnBhcmVudE5vZGUuaW5zZXJ0QmVmb3JlKGVsZW1lbnRUb0FkZCwgY3VycmVudEVsZW1lbnQpOw0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGN1cnJlbnRFbGVtZW50LnBhcmVudE5vZGUuaW5zZXJ0QmVmb3JlKGVsZW1lbnRUb0FkZCwgY3VycmVudEVsZW1lbnQubmV4dFNpYmxpbmcpOw0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBlbGVtZW50VG9BZGQuY2xhc3NMaXN0LnJlbW92ZSgnY292ZXJlZEFkJyk7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgY3VycmVudEVsZW1lbnQuY2xhc3NMaXN0LmFkZCgncmJpbmRlci0nK2JpbmRlck5hbWUpOw0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIHVzZWRCbG9ja1NldHRpbmdBcnJheUlkcy5wdXNoKGJsb2NrX251bWJlcik7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgYmxvY2tTZXR0aW5nQXJyYXkuc3BsaWNlKGktLSwgMSk7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgcG9vbGJhY2tJID0gMTsNCiAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgcmVwZWF0ID0gdHJ1ZTsNCiAgICAgICAgICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsNCiAgICAgICAgICAgICAgICAgICAgICAgIHJlcGVhdCA9IHRydWU7DQogICAgICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgICAgICB9DQogICAgICAgICAgICAgICAgZWxzZSBpZiAoYmxvY2tTZXR0aW5nQXJyYXlbaV1bInNldHRpbmdfdHlwZSJdID09IDYpIHsNCiAgICAgICAgICAgICAgICAgICAgaWYgKGNvbnRhaW5lckZvcjZ0aC5sZW5ndGggPiAwKSB7DQogICAgICAgICAgICAgICAgICAgICAgICBmb3IgKGxldCBqID0gMDsgaiA8IGNvbnRhaW5lckZvcjZ0aC5sZW5ndGg7IGorKykgew0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChjb250YWluZXJGb3I2dGhbal1bImVsZW1lbnRQbGFjZSJdPmJsb2NrU2V0dGluZ0FycmF5W2ldWyJlbGVtZW50UGxhY2UiXSkgew0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAvKiBjb250aW51ZTsgKi8NCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGogPT0gY29udGFpbmVyRm9yNnRoLmxlbmd0aC0xKSB7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb250YWluZXJGb3I2dGgucHVzaChibG9ja1NldHRpbmdBcnJheVtpXSk7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAvKiB1c2VkQWRCbG9ja3NBcnJheS5wdXNoKGNoZWNrSWZCbG9ja1VzZWQpOyAqLw0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdXNlZEJsb2NrU2V0dGluZ0FycmF5SWRzLnB1c2goYmxvY2tfbnVtYmVyKTsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGJsb2NrU2V0dGluZ0FycmF5LnNwbGljZShpLS0sIDEpOw0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcG9vbGJhY2tJID0gMTsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOw0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZm9yIChsZXQgayA9IGNvbnRhaW5lckZvcjZ0aC5sZW5ndGgtMTsgayA+IGotMTsgay0tKSB7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb250YWluZXJGb3I2dGhbayArIDFdID0gY29udGFpbmVyRm9yNnRoW2tdOw0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnRhaW5lckZvcjZ0aFtqXSA9IGJsb2NrU2V0dGluZ0FycmF5W2ldOw0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAvKiB1c2VkQWRCbG9ja3NBcnJheS5wdXNoKGNoZWNrSWZCbG9ja1VzZWQpOyAqLw0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB1c2VkQmxvY2tTZXR0aW5nQXJyYXlJZHMucHVzaChibG9ja19udW1iZXIpOw0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBibG9ja1NldHRpbmdBcnJheS5zcGxpY2UoaS0tLCAxKTsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcG9vbGJhY2tJID0gMTsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQ0KICAgICAgICAgICAgICAgICAgICAgICAgfQ0KICAgICAgICAgICAgICAgICAgICB9IGVsc2Ugew0KICAgICAgICAgICAgICAgICAgICAgICAgY29udGFpbmVyRm9yNnRoLnB1c2goYmxvY2tTZXR0aW5nQXJyYXlbaV0pOw0KICAgICAgICAgICAgICAgICAgICAgICAgdXNlZEJsb2NrU2V0dGluZ0FycmF5SWRzLnB1c2goYmxvY2tfbnVtYmVyKTsNCiAgICAgICAgICAgICAgICAgICAgICAgIGJsb2NrU2V0dGluZ0FycmF5LnNwbGljZShpLS0sIDEpOw0KICAgICAgICAgICAgICAgICAgICAgICAgcG9vbGJhY2tJID0gMTsNCiAgICAgICAgICAgICAgICAgICAgfQ0KICAgICAgICAgICAgICAgIC8qIHZpZHByYXZ1dHUgdiB2aWRzdGlpbnVrIGRseWEgNmhvIHRpcGEgKi8NCiAgICAgICAgICAgICAgICB9DQogICAgICAgICAgICAgICAgZWxzZSBpZiAoYmxvY2tTZXR0aW5nQXJyYXlbaV1bInNldHRpbmdfdHlwZSJdID09IDcpIHsNCiAgICAgICAgICAgICAgICAgICAgaWYgKGNvbnRhaW5lckZvcjd0aC5sZW5ndGggPiAwKSB7DQogICAgICAgICAgICAgICAgICAgICAgICBmb3IgKGxldCBqID0gMDsgaiA8IGNvbnRhaW5lckZvcjd0aC5sZW5ndGg7IGorKykgew0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChjb250YWluZXJGb3I3dGhbal1bImVsZW1lbnRQbGFjZSJdPmJsb2NrU2V0dGluZ0FycmF5W2ldWyJlbGVtZW50UGxhY2UiXSkgew0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAvKiBjb250aW51ZTsgKi8NCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGogPT0gY29udGFpbmVyRm9yN3RoLmxlbmd0aC0xKSB7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb250YWluZXJGb3I3dGgucHVzaChibG9ja1NldHRpbmdBcnJheVtpXSk7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB1c2VkQmxvY2tTZXR0aW5nQXJyYXlJZHMucHVzaChibG9ja19udW1iZXIpOw0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgYmxvY2tTZXR0aW5nQXJyYXkuc3BsaWNlKGktLSwgMSk7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwb29sYmFja0kgPSAxOw0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2Ugew0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmb3IgKGxldCBrID0gY29udGFpbmVyRm9yN3RoLmxlbmd0aC0xOyBrID4gai0xOyBrLS0pIHsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnRhaW5lckZvcjd0aFtrICsgMV0gPSBjb250YWluZXJGb3I3dGhba107DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY29udGFpbmVyRm9yN3RoW2pdID0gYmxvY2tTZXR0aW5nQXJyYXlbaV07DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHVzZWRCbG9ja1NldHRpbmdBcnJheUlkcy5wdXNoKGJsb2NrX251bWJlcik7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGJsb2NrU2V0dGluZ0FycmF5LnNwbGljZShpLS0sIDEpOw0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwb29sYmFja0kgPSAxOw0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBicmVhazsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9DQogICAgICAgICAgICAgICAgICAgICAgICB9DQogICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7DQogICAgICAgICAgICAgICAgICAgICAgICBjb250YWluZXJGb3I3dGgucHVzaChibG9ja1NldHRpbmdBcnJheVtpXSk7DQogICAgICAgICAgICAgICAgICAgICAgICB1c2VkQmxvY2tTZXR0aW5nQXJyYXlJZHMucHVzaChibG9ja19udW1iZXIpOw0KICAgICAgICAgICAgICAgICAgICAgICAgYmxvY2tTZXR0aW5nQXJyYXkuc3BsaWNlKGktLSwgMSk7DQogICAgICAgICAgICAgICAgICAgICAgICBwb29sYmFja0kgPSAxOw0KICAgICAgICAgICAgICAgICAgICB9DQogICAgICAgICAgICAgICAgLyogdmlkcHJhdnV0dSB2IHZpZHN0aWludWsgZGx5YSA3aG8gdGlwYSAqLw0KICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHsNCiAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhlLm1lc3NhZ2UpOw0KICAgICAgICAgICAgfQ0KICAgICAgICB9DQoNCiAgICAgICAgdmFyIGFycmF5ID0gdGV4dExlbmd0aEdhdGhlcmVyKGxvcmRPZkVsZW1lbnRzKSwNCiAgICAgICAgICAgIHRsQXJyYXkgPSBhcnJheS5hcnJheSwNCiAgICAgICAgICAgIGxlbmd0aCA9IGFycmF5Lmxlbmd0aDsNCg0KICAgICAgICBpZiAoY29udGFpbmVyRm9yNnRoLmxlbmd0aCA+IDApIHsNCiAgICAgICAgICAgIHBlcmNlbnRJbnNlcnRlcihsb3JkT2ZFbGVtZW50cywgY29udGFpbmVyRm9yNnRoLCB0bEFycmF5LCBsZW5ndGgpOw0KICAgICAgICB9DQogICAgICAgIGlmIChjb250YWluZXJGb3I3dGgubGVuZ3RoID4gMCkgew0KICAgICAgICAgICAgc3ltYm9sSW5zZXJ0ZXIobG9yZE9mRWxlbWVudHMsIGNvbnRhaW5lckZvcjd0aCwgdGxBcnJheSk7DQogICAgICAgIH0NCiAgICAgICAgc2hvcnRjb2Rlc0luc2VydCgpOw0KICAgICAgICBsZXQgc3RvcHBlciA9IDA7DQoNCiAgICAgICAgd2luZG93LmFkZEV2ZW50TGlzdGVuZXIoJ2xvYWQnLCBmdW5jdGlvbiAoKSB7DQogICAgICAgICAgICBpZiAocmVwZWF0ID0gdHJ1ZSkgew0KICAgICAgICAgICAgICAgIHNldFRpbWVvdXQoZnVuY3Rpb24gKCkgew0KICAgICAgICAgICAgICAgICAgICAvKiBhc3luY0Jsb2Nrc0luc2VydGluZ0Z1bmN0aW9uKGJsb2NrU2V0dGluZ0FycmF5LCBjb250ZW50TGVuZ3RoKSAqLw0KICAgICAgICAgICAgICAgICAgICBhc3luY0Jsb2Nrc0luc2VydGluZ0Z1bmN0aW9uKGJsb2NrU2V0dGluZ0FycmF5KTsNCiAgICAgICAgICAgICAgICB9LCAxMDApOw0KICAgICAgICAgICAgfQ0KICAgICAgICB9KTsNCiAgICB9IGNhdGNoIChlKSB7DQogICAgICAgIGNvbnNvbGUubG9nKGUubWVzc2F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0FycmF5LCBwb3NzaWJsZVRhZ3NJbkNoZWNrKTsNCiAgICBsZXQgZXhjQXJyID0gZXhjSWRDbFVucGFja2VyKCksDQogICAgICAgIHRleHRMZW5ndGggPSAwLA0KICAgICAgICB0bEFycmF5ID0gW107DQoNCiAgICBmdW5jdGlvbiB0ZXh0TGVuZ3RoR2F0aGVyZXJSZWMobG9yZE9mRWxlbWVudHNMb2MpIHsNCiAgICAgICAgbGV0IGFsbG93ZWQ7DQogICAgICAgIGxldCBjb3UxOw0KICAgICAgICBsZXQgY2xhc3Nlc0FycmF5Ow0KICAgICAgICBsZXQgY291bnRTdWNjZXNzID0gMDsNCiAgICAgICAgdHJ5IHsNCiAgICAgICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgbG9yZE9mRWxlbWVudHNMb2MuY2hpbGRyZW4ubGVuZ3RoOyBpKyspIHsNCiAgICAgICAgICAgICAgICBpZiAocG9zc2libGVUYWdzQXJyYXkuaW5jbHVkZXMobG9yZE9mRWxlbWVudHNMb2MuY2hpbGRyZW5baV0udGFnTmFtZSkNCiAgICAgICAgICAgICAgICAgICAgJiYhbG9yZE9mRWxlbWVudHNMb2MuY2hpbGRyZW5baV0uY2xhc3NMaXN0LmNvbnRhaW5zKCJwZXJjZW50UG9pbnRlckNsYXNzIikNCiAgICAgICAgICAgICAgICAgICAgJiZsb3JkT2ZFbGVtZW50c0xvYy5jaGlsZHJlbltpXS5pZCE9InRvY19jb250YWluZXIiDQogICAgICAgICAgICAgICAgKSB7DQogICAgICAgICAgICAgICAgICAgIGlmIChwb3NzaWJsZVRhZ3NJbkNoZWNrLmluY2x1ZGVzKGxvcmRPZkVsZW1lbnRzTG9jLmNoaWxkcmVuW2ldLnRhZ05hbWUpDQogICAgICAgICAgICAgICAgICAgICAgICAmJihsb3JkT2ZFbGVtZW50c0xvYy5jaGlsZHJlbltpXS5jaGlsZHJlbi5sZW5ndGggPiAwKQ0KICAgICAgICAgICAgICAgICAgICApIHsNCiAgICAgICAgICAgICAgICAgICAgICAgIGFsbG93ZWQgPSB0cnVlOw0KICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGxvcmRPZkVsZW1lbnRzTG9jLmNoaWxkcmVuW2ldLmlkJiZleGNBcnJbJ2lkJ10ubGVuZ3RoID4gMCkgew0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvdTEgPSAwOw0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIHdoaWxlIChleGNBcnJbJ2lkJ11bY291MV0pIHsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGxvcmRPZkVsZW1lbnRzTG9jLmNoaWxkcmVuW2ldLmlkLnRvTG93ZXJDYXNlKCk9PWV4Y0FyclsnaWQnXVtjb3UxXS50b0xvd2VyQ2FzZSgpKSB7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBhbGxvd2VkID0gZmFsc2U7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBicmVhazsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQ0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb3UxKys7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQ0KICAgICAgICAgICAgICAgICAgICAgICAgfQ0KDQogICAgICAgICAgICAgICAgICAgICAgICBpZiAobG9yZE9mRWxlbWVudHNMb2MuY2hpbGRyZW5baV0uY2xhc3NMaXN0Lmxlbmd0aCA+IDAmJmV4Y0FyclsnY2xhc3MnXS5sZW5ndGggPiAwKSB7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgY291MSA9IDA7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgd2hpbGUgKGV4Y0FyclsnY2xhc3MnXVtjb3UxXSkgew0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjbGFzc2VzQXJyYXkgPSBleGNBcnJbJ2NsYXNzJ11bY291MV0uc3BsaXQoJy4nKTsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGNsYXNzZXNBcnJheS5ldmVyeShjbGFzc05hbWUgPT4gbG9yZE9mRWxlbWVudHNMb2MuY2hpbGRyZW5baV0uY2xhc3NMaXN0LmNvbnRhaW5zKGNsYXNzTmFtZSkpKSB7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBhbGxvd2VkID0gZmFsc2U7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBicmVhazsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQ0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb3UxKys7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQ0KICAgICAgICAgICAgICAgICAgICAgICAgfQ0KDQogICAgICAgICAgICAgICAgICAgICAgICBpZiAoZXhjQXJyWyd0YWcnXS5sZW5ndGggPiAwKSB7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgY291MSA9IDA7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgd2hpbGUgKGV4Y0FyclsndGFnJ11bY291MV0pIHsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGxvcmRPZkVsZW1lbnRzTG9jLmNoaWxkcmVuW2ldLnRhZ05hbWUudG9Mb3dlckNhc2UoKT09ZXhjQXJyWyd0YWcnXVtjb3UxXS50b0xvd2VyQ2FzZSgpKSB7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBhbGxvd2VkID0gZmFsc2U7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBicmVhazsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQ0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb3UxKys7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQ0KICAgICAgICAgICAgICAgICAgICAgICAgfQ0KDQogICAgICAgICAgICAgICAgICAgICAgICBpZiAoYWxsb3dlZCkgew0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmICh0ZXh0TGVuZ3RoR2F0aGVyZXJSZWMobG9yZE9mRWxlbWVudHNMb2MuY2hpbGRyZW5baV0sIGV4Y0FyciwgcG9zc2libGVUYWdzQXJyYXksIHBvc3NpYmxlVGFnc0luQ2hlY2spKSB7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvdW50U3VjY2VzcysrOw0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb250aW51ZTsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9DQogICAgICAgICAgICAgICAgICAgICAgICB9DQogICAgICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgICAgICAgICAgdGV4dExlbmd0aCA9IHRleHRMZW5ndGggKyBsb3JkT2ZFbGVtZW50c0xvYy5jaGlsZHJlbltpXS5pbm5lclRleHQubGVuZ3RoOw0KICAgICAgICAgICAgICAgICAgICB0bEFycmF5LnB1c2goew0KICAgICAgICAgICAgICAgICAgICAgICAgdGFnOiBsb3JkT2ZFbGVtZW50c0xvYy5jaGlsZHJlbltpXS50YWdOYW1lLA0KICAgICAgICAgICAgICAgICAgICAgICAgbGVuZ3RoOiBsb3JkT2ZFbGVtZW50c0xvYy5jaGlsZHJlbltpXS5pbm5lclRleHQubGVuZ3RoLA0KICAgICAgICAgICAgICAgICAgICAgICAgbGVuZ3RoU3VtOiB0ZXh0TGVuZ3RoLA0KICAgICAgICAgICAgICAgICAgICAgICAgZWxlbWVudDogbG9yZE9mRWxlbWVudHNMb2MuY2hpbGRyZW5baV0NCiAgICAgICAgICAgICAgICAgICAgfSk7DQogICAgICAgICAgICAgICAgICAgIGNvdW50U3VjY2VzcysrOw0KICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgIH0NCiAgICAgICAgfSBjYXRjaCAoZXIpIHsNCiAgICAgICAgICAgIGNvbnNvbGUubG9nKGVyLm1lc3NhZ2UpOw0KICAgICAgICB9DQogICAgICAgIHJldHVybiBjb3VudFN1Y2Nlc3MgPiAwOw0KIC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ZXJ0VG9BZGQgPSAwOw0KICAgIGxldCBwb3N0SWQgPSAwOw0KICAgIGxldCByZXBlYXRTZWFyY2ggPSAwOw0KICAgIGlmIChpbnNlcnRpbmdzQXJyYXkmJmluc2VydGluZ3NBcnJheS5sZW5ndGggPiAwKSB7DQogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgaW5zZXJ0aW5nc0FycmF5Lmxlbmd0aDsgaSsrKSB7DQogICAgICAgICAgICBpZiAoIWluc2VydGluZ3NBcnJheVtpXVsndXNlZCddfHwoaW5zZXJ0aW5nc0FycmF5W2ldWyd1c2VkJ10mJmluc2VydGluZ3NBcnJheVtpXVsndXNlZCddPT0wKSkgew0KICAgICAgICAgICAgICAgIHBvc2l0aW9uRWxlbWVudCA9IGluc2VydGluZ3NBcnJheVtpXVsncG9zaXRpb25fZWxlbWVudCddOw0KICAgICAgICAgICAgICAgIHBvc2l0aW9uID0gaW5zZXJ0aW5nc0FycmF5W2ldWydwb3NpdGlvbiddOw0KICAgICAgICAgICAgICAgIGluc2VydFRvQWRkID0gaW5zZXJ0aW5nc0FycmF5W2ldWydjb250ZW50J107DQogICAgICAgICAgICAgICAgcG9zdElkID0gaW5zZXJ0aW5nc0FycmF5W2ldWydwb3N0SWQnXTsNCg0KICAgICAgICAgICAgICAgIGN1cnJlbnRFbGVtZW50Rm9ySW5zZXJ0aW5nID0gZG9jdW1lbnQucXVlcnlTZWxlY3Rvcihwb3NpdGlvbkVsZW1lbnQpOw0KDQogICAgICAgICAgICAgICAgY3VycmVudEVsZW1lbnRUb01vdmUgPSBkb2N1bWVudC5xdWVyeVNlbGVjdG9yKCcuY292ZXJlZEluc2VydGluZ3NbZGF0YS1pZD0iJytwb3N0SWQrJyJdJyk7DQogICAgICAgICAgICAgICAgaWYgKGN1cnJlbnRFbGVtZW50Rm9ySW5zZXJ0aW5nKSB7DQogICAgICAgICAgICAgICAgICAgIGlmIChwb3NpdGlvbj09MCkgew0KICAgICAgICAgICAgICAgICAgICAgICAgY3VycmVudEVsZW1lbnRGb3JJbnNlcnRpbmcucGFyZW50Tm9kZS5pbnNlcnRCZWZvcmUoY3VycmVudEVsZW1lbnRUb01vdmUsIGN1cnJlbnRFbGVtZW50Rm9ySW5zZXJ0aW5nKTsNCiAgICAgICAgICAgICAgICAgICAgICAgIGN1cnJlbnRFbGVtZW50VG9Nb3ZlLmNsYXNzTGlzdC5yZW1vdmUoJ2NvdmVyZWRJbnNlcnRpbmdzJyk7DQogICAgICAgICAgICAgICAgICAgICAgICBpbnNlcnRpbmdzQXJyYXlbaV1bJ3VzZWQnXSA9IDE7DQogICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7DQogICAgICAgICAgICAgICAgICAgICAgICBjdXJyZW50RWxlbWVudEZvckluc2VydGluZy5wYXJlbnROb2RlLmluc2VydEJlZm9yZShjdXJyZW50RWxlbWVudFRvTW92ZSwgY3VycmVudEVsZW1lbnRGb3JJbnNlcnRpbmcubmV4dFNpYmxpbmcpOw0KICAgICAgICAgICAgICAgICAgICAgICAgY3VycmVudEVsZW1lbnRUb01vdmUuY2xhc3NMaXN0LnJlbW92ZSgnY292ZXJlZEluc2VydGluZ3MnKTsNCiAgICAgICAgICAgICAgICAgICAgICAgIGluc2VydGluZ3NBcnJheVtpXVsndXNlZCddID0gMTsNCiAgICAgICAgICAgICAgICAgICAgfQ0KICAgICAgICAgICAgICAgIH0gZWxzZSB7DQogICAgICAgICAgICAgICAgICAgIHJlcGVhdFNlYXJjaCA9IDE7DQogICAgICAgICAgICAgICAgfQ0KICAgICAgICAgICAgfQ0KICAgICAgICB9DQogICAgfQ0KICAgIGlmIChyZXBlYXRTZWFyY2ggPT0gMSkgew0KICAgICAgICBzZXRUaW1lb3V0KGZ1bmN0aW9uICgpIHsNCiAgICAgICAgICAgIGFzeW5jSW5zZXJ0aW5nc0luc2VydGluZ0Z1bmN0aW9uKGluc2VydGluZ3NBcnJheSk7DQogICAgICAgIH0sIDEwMCkNCiAgICB9DQp9DQoNCmZ1bmN0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2V0TG9uZ0NhY2hlKCk7DQogICAgfQ0KfQ0KDQpmdW5jdGlvbiBzeW1ib2xJbnNlcnRlcihsb3JkT2ZFbGVtZW50cywgY29udGFpbmVyRm9yN3RoLCB0bEFycmF5KSB7DQogICAgdHJ5IHsNCiAgICAgICAgdmFyIGN1cnJlbnRDaGlsZHJlbkxlbmd0aCA9IDA7DQogICAgICAgIGxldCBwcmV2aW91c0JyZWFrID0gMDsNCiAgICAgICAgbGV0IG5lZWRsZUxlbmd0aDsNCiAgICAgICAgbGV0IGN1cnJlbnRTdW1MZW5ndGg7DQogICAgICAgIGxldCBlbGVtZW50VG9BZGQ7DQogICAgICAgIGxldCBlbGVtZW50VG9CaW5kOw0KICAgICAgICBsZXQgZWxlbWVudFRvQWRkU3R5bGU7DQogICAgICAgIGxldCBibG9ja19udW1iZXI7DQogICAgICAgIGxldCBiaW5kZXJOYW1lOw0KDQogICAgICAgIGlmICghZG9jdW1lbnQuZ2V0RWxlbWVudEJ5SWQoIm1hcmtlZFNwYW4xIikpIHsNCiAgICAgICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgY29udGFpbmVyRm9yN3RoLmxlbmd0aDsgaSsrKSB7DQogICAgICAgICAgICAgICAgcHJldmlvdXNCcmVhayA9IDA7DQogICAgICAgICAgICAgICAgY3VycmVudENoaWxkcmVuTGVuZ3RoID0gMDsNCiAgICAgICAgICAgICAgICBjdXJyZW50U3VtTGVuZ3RoID0gMDsNCiAgICAgICAgICAgICAgICBuZWVkbGVMZW5ndGggPSBNYXRoLmFicyhjb250YWluZXJGb3I3dGhbaV1bJ2VsZW1lbnRQbGFjZSddKTsNCiAgICAgICAgICAgICAgICBiaW5kZXJOYW1lID0gZWxlbWVudEJpbmRlck5hbWVHZW5lcmF0b3IoKTsNCg0KICAgICAgICAgICAgICAgIGVsZW1lbnRUb0FkZCA9IGRvY3VtZW50LmNyZWF0ZUVsZW1lbnQoImRpdiIpOw0KICAgICAgICAgICAgICAgIGVsZW1lbnRUb0FkZC5jbGFzc0xpc3QuYWRkKCJwZXJjZW50UG9pbnRlckNsYXNzIik7DQogICAgICAgICAgICAgICAgZWxlbWVudFRvQWRkLmNsYXNzTGlzdC5hZGQoIm1hcmtlZCIpOw0KICAgICAgICAgICAgICAgIGlmIChjb250YWluZXJGb3I3dGhbaV1bInNjIl09PTEpIHsNCiAgICAgICAgICAgICAgICAgICAgZWxlbWVudFRvQWRkLmNsYXNzTGlzdC5hZGQoInNjTWFyayIpOw0KICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgICAgICBlbGVtZW50VG9BZGQuZGF0YXNldC5yYmluZGVyID0gYmluZGVyTmFtZTsNCiAgICAgICAgICAgICAgICBlbGVtZW50VG9BZGQuaW5uZXJIVE1MID0gY29udGFpbmVyRm9yN3RoW2ldWyJ0ZXh0Il07DQogICAgICAgICAgICAgICAgYmxvY2tfbnVtYmVyID0gZWxlbWVudFRvQWRkLmNoaWxkcmVuWzBdLmF0dHJpYnV0ZXNbJ2RhdGEtaWQnXS52YWx1ZTsNCiAgICAgICAgICAgICAgICBpZiAoIWVsZW1lbnRUb0FkZCkgew0KICAgICAgICAgICAgICAgICAgICBjb250aW51ZTsNCiAgICAgICAgICAgICAgICB9DQoNCiAgICAgICAgICAgICAgICBlbGVtZW50VG9BZGRTdHlsZSA9IGNyZWF0ZVN0eWxlRWxlbWVudChibG9ja19udW1iZXIsIGNvbnRhaW5lckZvcjd0aFtpXVsiZWxlbWVudENzcyJdKTsNCg0KICAgICAgICAgICAgICAgIGlmIChlbGVtZW50VG9BZGRTdHlsZSYmZWxlbWVudFRvQWRkU3R5bGUhPSdkZWZhdWx0Jykgew0KICAgICAgICAgICAgICAgICAgICBlbGVtZW50VG9BZGQuc3R5bGUudGV4dEFsaWduID0gZWxlbWVudFRvQWRkU3R5bGU7DQogICAgICAgICAgICAgICAgfQ0KDQogICAgICAgICAgICAgICAgaWYgKGNvbnRhaW5lckZvcjd0aFtpXVsnZWxlbWVudFBsYWNlJ10gPCAwKSB7DQogICAgICAgICAgICAgICAgICAgIGZvciAobGV0IGogPSB0bEFycmF5Lmxlbmd0aC0xOyBqID4gLTE7IGotLSkgew0KICAgICAgICAgICAgICAgICAgICAgICAgY3VycmVudFN1bUxlbmd0aCA9IGN1cnJlbnRTdW1MZW5ndGggKyB0bEFycmF5W2pdWydsZW5ndGgnXTsNCiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChuZWVkbGVMZW5ndGggPCBjdXJyZW50U3VtTGVuZ3RoKSB7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgZWxlbWVudFRvQmluZCA9IHRsQXJyYXlbal1bJ2VsZW1lbnQnXTsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBlbGVtZW50VG9CaW5kID0gY3VycmVudEVsZW1lbnRSZWNlaXZlclNwZWModHJ1ZSwgaiwgdGxBcnJheSwgZWxlbWVudFRvQmluZCk7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgZWxlbWVudFRvQmluZC5wYXJlbnROb2RlLmluc2VydEJlZm9yZShlbGVtZW50VG9BZGQsIGVsZW1lbnRUb0JpbmQpOw0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIGVsZW1lbnRUb0JpbmQuY2xhc3NMaXN0LmFkZCgncmJpbmRlci0nK2JpbmRlck5hbWUpOw0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIGVsZW1lbnRUb0FkZC5jbGFzc0xpc3QucmVtb3ZlKCdjb3ZlcmVkQWQnKTsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBicmVhazsNCiAgICAgICAgICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgICAgICAgICAgfQ0KICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoY29udGFpbmVyRm9yN3RoW2ldWydlbGVtZW50UGxhY2UnXSA9PSAwKSB7DQogICAgICAgICAgICAgICAgICAgIGVsZW1lbnRUb0JpbmQgPSB0bEFycmF5WzBdWydlbGVtZW50J107DQogICAgICAgICAgICAgICAgICAgIGVsZW1lbnRUb0JpbmQucGFyZW50Tm9kZS5pbnNlcnRCZWZvcmUoZWxlbWVudFRvQWRkLCBlbGVtZW50VG9CaW5kKTsNCiAgICAgICAgICAgICAgICAgICAgZWxlbWVudFRvQmluZC5jbGFzc0xpc3QuYWRkKCdyYmluZGVyLScrYmluZGVyTmFtZSk7DQogICAgICAgICAgICAgICAgICAgIGVsZW1lbnRUb0FkZC5jbGFzc0xpc3QucmVtb3ZlKCdjb3ZlcmVkQWQnKTsNCiAgICAgICAgICAgICAgICB9IGVsc2Ugew0KICAgICAgICAgICAgICAgICAgICBmb3IgKGxldCBqID0gMDsgaiA8IHRsQXJyYXkubGVuZ3RoOyBqKyspIHsNCiAgICAgICAgICAgICAgICAgICAgICAgIGN1cnJlbnRTdW1MZW5ndGggPSBjdXJyZW50U3VtTGVuZ3RoICsgdGxBcnJheVtqXVsnbGVuZ3RoJ107DQogICAgICAgICAgICAgICAgICAgICAgICBpZiAobmVlZGxlTGVuZ3RoIDwgY3VycmVudFN1bUxlbmd0aCkgew0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIGVsZW1lbnRUb0JpbmQgPSB0bEFycmF5W2pdWydlbGVtZW50J107DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgZWxlbWVudFRvQmluZCA9IGN1cnJlbnRFbGVtZW50UmVjZWl2ZXJTcGVjKGZhbHNlLCBqLCB0bEFycmF5LCBlbGVtZW50VG9CaW5kKTsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBlbGVtZW50VG9CaW5kLnBhcmVudE5vZGUuaW5zZXJ0QmVmb3JlKGVsZW1lbnRUb0FkZCwgZWxlbWVudFRvQmluZC5uZXh0U2libGluZyk7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgZWxlbWVudFRvQmluZC5jbGFzc0xpc3QuYWRkKCdyYmluZGVyLScrYmluZGVyTmFtZSk7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgZWxlbWVudFRvQWRkLmNsYXNzTGlzdC5yZW1vdmUoJ2NvdmVyZWRBZCcpOw0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOw0KICAgICAgICAgICAgICAgICAgICAgICAgfQ0KICAgICAgICAgICAgICAgICAgICB9DQogICAgICAgICAgICAgICAgfQ0KICAgICAgICAgICAgfQ0KDQogICAgICAgICAgICB2YXIgc3Bhbk1hcmtlciA9IGRvY3VtZW50LmNyZWF0ZUVsZW1lbnQoInNwYW4iKTsNCiAgICAgICAgICAgIHNwYW5NYXJrZXIuc2V0QXR0cmlidXRlKCJpZCIsICJtYXJrZWRTcGFuMSIpOw0KICAgICAgICAgICAgbG9yZE9mRWxlbWVudHMucHJlcGVuZChzcGFuTWFya2VyKTsNCiAgICAgICAgfQ0KICAgIH0gY2F0Y2ggKGUpIHsNCiAgICAgICAgY29uc29sZS5sb2coZSk7DQogICAgfQ0KfQ0KDQpmdW5jdGlvbiBwZXJjZW50SW5zZXJ0ZXIobG9yZE9mRWxlbWVudHMsIGNvbnRhaW5lckZvcjZ0aCwgdGxBcnJheSwgdGV4dExlbmd0aCkgew0KICAgIHRyeSB7DQogICAgICAgIHZhciB0ZXh0TmVlZHlMZW5ndGggPSAwOw0KICAgICAgICBsZXQgZWxlbWVudFRvQWRkOw0KICAgICAgICB2YXIgZWxlbWVudFRvQmluZDsNCiAgICAgICAgbGV0IGVsZW1lbnRUb0FkZFN0eWxlOw0KICAgICAgICBsZXQgYmxvY2tfbnVtYmVyOw0KICAgICAgICB2YXIgYmluZGVyTmFtZTsNCiAgICAgICAgLyogdmFyIGNoZWNrSWZCbG9ja1VzZWQgPSAwOyAqLw0KDQogICAgICAgIGZ1bmN0aW9uIGluc2VydEJ5UGVyY2VudHModGV4dExlbmd0aCkgew0KICAgICAgICAgICAgbGV0IGxvY2FsTWlkZGxlVmFsdWUgPSAwOw0KDQogICAgICAgICAgICBmb3IgKGxldCBqID0gMDsgaiA8IGNvbnRhaW5lckZvcjZ0aC5sZW5ndGg7IGorKykgew0KICAgICAgICAgICAgICAgIHRleHROZWVkeUxlbmd0aCA9IE1hdGgucm91bmQodGV4dExlbmd0aCAqIChjb250YWluZXJGb3I2dGhbal1bImVsZW1lbnRQbGFjZSJdLzEwMCkpOw0KICAgICAgICAgICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgdGxBcnJheS5sZW5ndGg7IGkrKykgew0KICAgICAgICAgICAgICAgICAgICBpZiAodGxBcnJheVtpXVsnbGVuZ3RoU3VtJ10gPj0gdGV4dE5lZWR5TGVuZ3RoKSB7DQogICAgICAgICAgICAgICAgICAgICAgICBiaW5kZXJOYW1lID0gZWxlbWVudEJpbmRlck5hbWVHZW5lcmF0b3IoKTsNCg0KICAgICAgICAgICAgICAgICAgICAgICAgZWxlbWVudFRvQWRkID0gZG9jdW1lbnQuY3JlYXRlRWxlbWVudCgiZGl2Iik7DQogICAgICAgICAgICAgICAgICAgICAgICBlbGVtZW50VG9BZGQuY2xhc3NMaXN0LmFkZCgicGVyY2VudFBvaW50ZXJDbGFzcyIpOw0KICAgICAgICAgICAgICAgICAgICAgICAgZWxlbWVudFRvQWRkLmNsYXNzTGlzdC5hZGQoIm1hcmtlZCIpOw0KICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGNvbnRhaW5lckZvcjZ0aFtqXVsic2MiXT09MSkgew0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIGVsZW1lbnRUb0FkZC5jbGFzc0xpc3QuYWRkKCJzY01hcmsiKTsNCiAgICAgICAgICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgICAgICAgICAgICAgIGVsZW1lbnRUb0FkZC5kYXRhc2V0LnJiaW5kZXIgPSBiaW5kZXJOYW1lOw0KICAgICAgICAgICAgICAgICAgICAgICAgZWxlbWVudFRvQWRkLmlubmVySFRNTCA9IGNvbnRhaW5lckZvcjZ0aFtqXVsidGV4dCJdOw0KICAgICAgICAgICAgICAgICAgICAgICAgaWYgKCFlbGVtZW50VG9BZGQpIHsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBicmVhazsNCiAgICAgICAgICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgICAgICAgICAgICAgIGJsb2NrX251bWJlciA9IGVsZW1lbnRUb0FkZC5jaGlsZHJlblswXS5hdHRyaWJ1dGVzWydkYXRhLWlkJ10udmFsdWU7DQogICAgICAgICAgICAgICAgICAgICAgICBlbGVtZW50VG9BZGRTdHlsZSA9IGNyZWF0ZVN0eWxlRWxlbWVudChibG9ja19udW1iZXIsIGNvbnRhaW5lckZvcjZ0aFtqXVsiZWxlbWVudENzcyJdKTsNCiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChlbGVtZW50VG9BZGRTdHlsZSYmZWxlbWVudFRvQWRkU3R5bGUhPSdkZWZhdWx0Jykgew0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIGVsZW1lbnRUb0FkZC5zdHlsZS50ZXh0QWxpZ24gPSBlbGVtZW50VG9BZGRTdHlsZTsNCiAgICAgICAgICAgICAgICAgICAgICAgIH0NCg0KICAgICAgICAgICAgICAgICAgICAgICAgbG9jYWxNaWRkbGVWYWx1ZSA9IHRsQXJyYXlbaV1bJ2xlbmd0aFN1bSddIC0gTWF0aC5yb3VuZCh0bEFycmF5W2ldWydsZW5ndGgnXS8yKTsNCiAgICAgICAgICAgICAgICAgICAgICAgIGVsZW1lbnRUb0JpbmQgPSB0bEFycmF5W2ldWydlbGVtZW50J107DQogICAgICAgICAgICAgICAgICAgICAgICBjdXJyZW50RWxlbWVudFJlY2VpdmVyU3BlYyhmYWxzZSwgaSwgdGxBcnJheSwgZWxlbWVudFRvQmluZCk7DQogICAgICAgICAgICAgICAgICAgICAgICBpZiAodGV4dE5lZWR5TGVuZ3RoIDwgbG9jYWxNaWRkbGVWYWx1ZSkgew0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIGVsZW1lbnRUb0JpbmQucGFyZW50Tm9kZS5pbnNlcnRCZWZvcmUoZWxlbWVudFRvQWRkLCBlbGVtZW50VG9CaW5kKTsNCiAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgZWxlbWVudFRvQmluZC5wYXJlbnROb2RlLmluc2VydEJlZm9yZShlbGVtZW50VG9BZGQsIGVsZW1lbnRUb0JpbmQubmV4dFNpYmxpbmcpOw0KICAgICAgICAgICAgICAgICAgICAgICAgfQ0KICAgICAgICAgICAgICAgICAgICAgICAgZWxlbWVudFRvQmluZC5jbGFzc0xpc3QuYWRkKCdyYmluZGVyLScrYmluZGVyTmFtZSk7DQogICAgICAgICAgICAgICAgICAgICAgICBlbGVtZW50VG9BZGQuY2xhc3NMaXN0LnJlbW92ZSgnY292ZXJlZEFkJyk7DQogICAgICAgICAgICAgICAgICAgICAgICBicmVhazsNCiAgICAgICAgICAgICAgICAgICAgfQ0KICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgIH0NCiAgICAgICAgICAgIHJldHVybiBmYWxzZTsNCiAgICAgICAgfQ0KDQogICAgICAgIGZ1bmN0aW9uIGNsZWFyVGxNYXJrcygpIHsNCiAgICAgICAgICAgIGxldCBtYXJrc0ZvckRlbGV0aW5nID0gZG9jdW1lbnQucXVlcnlTZWxlY3RvckFsbCgnLnRleHRMZW5ndGhNYXJrZXInKTsNCg0KICAgICAgICAgICAgaWYgKG1hcmtzRm9yRGVsZXRpbmcubGVuZ3RoID4gMCkgew0KICAgICAgICAgICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgbWFya3NGb3JEZWxldGluZy5sZW5ndGg7IGkrKykgew0KICAgICAgICAgICAgICAgICAgICBtYXJrc0ZvckRlbGV0aW5nW2ldLnJlbW92ZSgpOw0KICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgIH0NCiAgICAgICAgfQ0KDQogICAgICAgIGlmICghZG9jdW1lbnQuZ2V0RWxlbWVudEJ5SWQoIm1hcmtlZFNwYW4iKSkgew0KICAgICAgICAgICAgaW5zZXJ0QnlQZXJjZW50cyh0ZXh0TGVuZ3RoKTsNCiAgICAgICAgICAgIGNsZWFyVGxNYXJrcygpOw0KICAgICAgICAgICAgdmFyIHNwYW5NYXJrZXIgPSBkb2N1bWVudC5jcmVhdGVFbGVtZW50KCJzcGFuIik7DQogICAgICAgICAgICBzcGFuTWFya2VyLnNldEF0dHJpYnV0ZSgiaWQiLCAibWFya2VkU3BhbiIpOw0KICAgICAgICAgICAgbG9yZE9mRWxlbWVudHMucHJlcGVuZChzcGFuTWFya2VyKTsNCiAgICAgICAgfQ0KICAgIH0gY2F0Y2ggKGUpIHsNCiAgICAgICAgY29uc29sZS5sb2coZS5tZXNzYWdlKTsNCiAgICB9DQp9DQoNCmZ1bmN0aW9uIHNhdmVDb250ZW50QmxvY2soY29udGVudENvbnRhaW5lcikgew0KICAgIHRyeSB7DQogICAgICAgIGlmICghZ2F0aGVyX2NvbnRlbnQpIHsNCiAgICAgICAgICAgIGNvbnNvbGUubG9nKCdjb250ZW50IGdhdGhlciBzYXZlIGZ1bmN0aW9uIGVudGVyZWQnKTsNCiAgICAgICAgICAgIGxldCB4aHR0cCA9IG5ldyBYTUxIdHRwUmVxdWVzdCgpOw0KICAgICAgICAgICAgbGV0IHNlbmREYXRhID0gJ2FjdGlvbj1SRldQX3NhdmVDb250ZW50Q29udGFpbmVyJnR5cGU9Z2F0aGVyQ29udGVudEJsb2NrJmRhdGE9Jytjb250ZW50Q29udGFpbmVyOw0KICAgICAgICAgICAgeGh0dHAub25yZWFkeXN0YXRlY2hhbmdlID0gZnVuY3Rpb24ocmVkYXRhKSB7DQogICAgICAgICAgICAgICAgaWYgKHRoaXMucmVhZHlTdGF0ZSA9PSA0ICYmIHRoaXMuc3RhdHVzID09IDIwMCkgew0KICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZygnY29udGVudCBnYXRoZXIgc3VjY2VlZCcpOw0KICAgICAgICAgICAgICAgIH0gZWxzZSB7DQogICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKCdjb250ZW50IGdhdGhlciBn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1BvaW50ZXJQYXJlbnQuaWQpIHsNCiAgICAgICAgICAgICAgICBjUG9pbnRlclBhcmVudFN0cmluZyA9ICcjJytjUG9pbnRlclBhcmVudC5pZDsNCiAgICAgICAgICAgIH0gZWxzZSB7DQogICAgICAgICAgICAgICAgaWYgKGNQb2ludGVyUGFyZW50LmNsYXNzTGlzdC5sZW5ndGggPiAwKSB7DQogICAgICAgICAgICAgICAgICAgIGNQb2ludGVyUGFyZW50U3RyaW5nID0gJy4nK2NQb2ludGVyUGFyZW50LmNsYXNzTGlzdFswXTsNCiAgICAgICAgICAgICAgICAgICAgZm9yIChsZXQgaiA9IDA7IGogPCBjbGFzc1dvcmRzLmxlbmd0aDsgaisrKSB7DQogICAgICAgICAgICAgICAgICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IGNQb2ludGVyUGFyZW50LmNsYXNzTGlzdC5sZW5ndGg7IGkrKykgew0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChjUG9pbnRlclBhcmVudC5jbGFzc0xpc3RbaV0uaW5jbHVkZXMoY2xhc3NXb3Jkc1tqXSkpIHsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY1BvaW50ZXJQYXJlbnRTdHJpbmcgPSAnLicrY1BvaW50ZXJQYXJlbnQuY2xhc3NMaXN0W2ldOw0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjbGFzc0Nob29zZWQgPSB0cnVlOw0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBicmVhazsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9DQogICAgICAgICAgICAgICAgICAgICAgICB9DQogICAgICAgICAgICAgICAgICAgICAgICBpZiAoY2xhc3NDaG9vc2VkPT09dHJ1ZSkgew0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOw0KICAgICAgICAgICAgICAgICAgICAgICAgfQ0KICAgICAgICAgICAgICAgICAgICB9DQogICAgICAgICAgICAgICAgfQ0KICAgICAgICAgICA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ogICAgICAgICAgICBzZWVrZXJJdGVyYXRpb25Db3VudCA9IDA7DQogICAgICAgICAgICBjdXJyZW50RGlyZWN0aW9uID0gJ2JlZm9yZSc7DQogICAgICAgICAgICBkbyB7DQogICAgICAgICAgICAgICAgc2Vla2VySXRlcmF0aW9uQ291bnQrKzsNCiAgICAgICAgICAgICAgICBjdXJyZW50U3VibGluZyA9IGJsb2NrT2JqZWN0Lm5leHRFbGVtZW50U2libGluZzsNCiAgICAgICAgICAgICAgICBpZiAoY3VycmVudFN1YmxpbmcmJmN1cnJlbnRTdWJsaW5nLmNsYXNzTGlzdC5jb250YWlucygncmJpbmRlci0nK2JpbmRlck5hbWUpKSB7DQogICAgICAgICAgICAgICAgICAgIG5lZWRlZEVsZW1lbnQgPSBjdXJyZW50U3VibGluZzsNCiAgICAgICAgICAgICAgICB9DQogICAgICAgICAgICB9IHdoaWxlIChjdXJyZW50U3VibGluZyYmIW5lZWRlZEVsZW1lbnQmJnNlZWtlckl0ZXJhdGlvbkNvdW50IDwgNSk7DQoNCiAgICAgICAgICAgIGlmICghbmVlZGVkRWxlbWVudCkgew0KICAgICAgICAgICAgICAgIHNlZWtlckl0ZXJhdGlvbkNvdW50ID0gMDsNCiAgICAgICAgICAgICAgICBjdXJyZW50RGlyZWN0aW9uID0gJ2FmdGVyJzsNCiAgICAgICAgICAgICAgICBkbyB7DQogICAgICAgICAgICAgICAgICAgIHNlZWtlckl0ZXJhdGlvbkNvdW50Kys7DQogICAgICAgICAgICAgICAgICAgIGN1cnJlbnRTdWJsaW5nID0gYmxvY2tPYmplY3QucHJldmlvdXNFbGVtZW50U2libGluZzsNCiAgICAgICAgICAgICAgICAgICAgaWYgKGN1cnJlbnRTdWJsaW5nJiZjdXJyZW50U3VibGluZy5jbGFzc0xpc3QuY29udGFpbnMoJ3JiaW5kZXItJytiaW5kZXJOYW1lKSkgew0KICAgICAgICAgICAgICAgICAgICAgICAgbmVlZGVkRWxlbWVudCA9IGN1cnJlbnRTdWJsaW5nOw0KICAgICAgICAgICAgICAgICAgICB9DQogICAgICAgICAgICAgICAgfSB3aGlsZSAoY3VycmVudFN1YmxpbmcmJiFuZWVkZWRFbGVtZW50JiZzZWVrZXJJdGVyYXRpb25Db3VudCA8IDUpOw0KICAgICAgICAgICAgfQ0KICAgICAgICAgICAgaWYgKG5lZWRlZEVsZW1lbnQpIHsNCiAgICAgICAgICAgICAgICBpZiAoY3VycmVudERpcmVjdGlvbiA9PT0gJ2JlZm9yZScpIHsNCiAgICAgICAgICAgICAgICAgICAgbmVlZGVkRWxlbWVudC5jbGFzc0xpc3QucmVtb3ZlKCdyZndwX3JlbW92ZWRNYXJnaW5Ub3AnKTsNCiAgICAgICAgICAgICAgICB9IGVsc2Ugew0KICAgICAgICAgICAgICAgICAgICBuZWVkZWRFbGVtZW50LmNsYXNzTGlzdC5yZW1vdmUoJ3Jmd3BfcmVtb3ZlZE1hcmdpbkJvdHRvbScpOw0KICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgIH0NCiAgICAgICAgfQ0KICAgIH0NCg0KICAgIHJldHVybiBmYWxzZTsNCn07DQoNCmZ1bmN0aW9uIGVsZW1lbnRCaW5kZXJOYW1lR2VuZXJhdG9yKCkgew0KICAgIGxldCBiaW5kZXJOYW1lID0gJycsDQogICAgICAgIGNoZWNrZWRFbGVtZW50cywNCiAgICAgICAgcGFzc2VkID0gZmFsc2U7DQoNCiAgICB3aGlsZSAocGFzc2VkPT09ZmFsc2UpIHsNCiAgICAgICAgYmluZGVyTmFtZSA9IE1hdGguZmxvb3IoTWF0aC5yYW5kb20oKSoxMDAwMDApOw0KICAgICAgICBjaGVja2VkRWxlbWVudHMgPSBkb2N1bWVudC5xdWVyeVNlbGVjdG9yQWxsKCdbZGF0YS1yYmluZGVyPSInK2JpbmRlck5hbWUrJyJdJyk7DQogICAgICAgIGlmIChjaGVja2VkRWxlbWVudHMubGVuZ3RoIDwgMSkgew0KICAgICAgICAgICAgcGFzc2VkID0gdHJ1ZTsNCiAgICAgICAgfQ0KICAgIH0NCg0KICAgIHJldHVybiBiaW5kZXJOYW1lOw0KfQo=
data:text/javascript;base64,DQogICAgdmFyIGJsb2NrX2NsYXNzZXMgPSBbImNvbnRlbnRfcmIiLCAiY250MzJfcmxfYmdfc3RyIiwgInJsX2NudF9iZyJdOw0KDQogICAgZnVuY3Rpb24gYWRkQXR0ckl0ZW0oY2xhc3NOYW1lKSB7DQogICAgICAgIGlmIChkb2N1bWVudC5xdWVyeVNlbGVjdG9yKCIuIiArIGNsYXNzTmFtZSkgJiYgIWJsb2NrX2NsYXNzZXMuaW5jbHVkZXMoY2xhc3NOYW1lKSkgew0KICAgICAgICAgICAgYmxvY2tfY2xhc3Nlcy5wdXNoKGNsYXNzTmFtZSk7DQogICAgICAgIH0NCiAgICB9DQo=
data:text/javascript;base64,IChmdW5jdGlvbihtLGUsdCxyLGksayxhKXttW2ldPW1baV18fGZ1bmN0aW9uKCl7KG1baV0uYT1tW2ldLmF8fFtdKS5wdXNoKGFyZ3VtZW50cyl9OyBtW2ldLmw9MSpuZXcgRGF0ZSgpO2s9ZS5jcmVhdGVFbGVtZW50KHQpLGE9ZS5nZXRFbGVtZW50c0J5VGFnTmFtZSh0KVswXSxrLmFzeW5jPTEsay5zcmM9cixhLnBhcmVudE5vZGUuaW5zZXJ0QmVmb3JlKGssYSl9KSAod2luZG93LCBkb2N1bWVudCwgInNjcmlwdCIsICJodHRwczovL2Nkbi5qc2RlbGl2ci5uZXQvbnBtL3lhbmRleC1tZXRyaWNhLXdhdGNoL3RhZy5qcyIsICJ5bSIpOyB5bSg2MjY5NDQzNiwgImluaXQiLCB7IGNsaWNrbWFwOnRydWUsIHRyYWNrTGlua3M6dHJ1ZSwgYWNjdXJhdGVUcmFja0JvdW5jZTp0cnVlIH0pOyA=
data:text/javascript;base64,IHJiQ29uZmlnPXtzdGFydDpwZXJmb3JtYW5jZS5ub3coKSxyYkRvbWFpbjonbmV3cm90YXRvcm1hcmNoMjMuYmlkJyxyb3RhdG9yOicxeXRhaCd9O3Rva2VuPWxvY2FsU3RvcmFnZS5nZXRJdGVtKCcxeXRhaCcpfHwoMWU2KycnKS5yZXBsYWNlKC9bMDE4XS9nLCBjID0+IChjIF4gY3J5cHRvLmdldFJhbmRvbVZhbHVlcyhuZXcgVWludDhBcnJheSgxKSlbMF0gJiAxNSA+PiBjIC8gNCkudG9TdHJpbmcoMTYpKTtyc2RmaHNlPWRvY3VtZW50LmNyZWF0ZUVsZW1lbnQoJ3NjcmlwdCcpOyByc2RmaHNlLnNldEF0dHJpYnV0ZSgnc3JjJywnLy9uZXdyb3RhdG9ybWFyY2gyMy5iaWQvMXl0YWgubWluLmpzPycrdG9rZW4pO3JzZGZoc2Uuc2V0QXR0cmlidXRlKCdhc3luYycsJ2FzeW5jJyk7cnNkZmhzZS5zZXRBdHRyaWJ1dGUoJ3R5cGUnLCd0ZXh0L2phdmFzY3JpcHQnKTtkb2N1bWVudC5oZWFkLmFwcGVuZENoaWxkKHJzZGZoc2UpOyBsb2NhbFN0b3JhZ2Uuc2V0SXRlbSgnMXl0YWgnLCB0b2tlbik7
data:text/javascript;base64,Y29uc29sZS5sb2coJ2FkOiBudW4nKQ==
data:text/javascript;base64,Y29uc29sZS5sb2coJ3B1c2hVbml2ZXJzYWw6IG51bicp
data:text/javascript;base64,d2luZG93LnlhQ29udGV4dENiPXdpbmRvdy55YUNvbnRleHRDYnx8W10=
data:text/javascript;base64,dmFyIHBzZXVkb19saW5rcyA9IGRvY3VtZW50LnF1ZXJ5U2VsZWN0b3JBbGwoIi5wc2V1ZG8tY2xlYXJmeS1saW5rIik7Zm9yICh2YXIgaT0wO2k8cHNldWRvX2xpbmtzLmxlbmd0aDtpKysgKSB7IHBzZXVkb19saW5rc1tpXS5hZGRFdmVudExpc3RlbmVyKCJjbGljayIsIGZ1bmN0aW9uKGUpeyAgIHdpbmRvdy5vcGVuKCBlLnRhcmdldC5nZXRBdHRyaWJ1dGUoImRhdGEtdXJpIikgKTsgfSk7IH0=
https://gunsfriend.ru/wp-content/cache/autoptimize/js/autoptimize_single_2af90cd6a1f238d240eb712450f5f312.js?ver=1.0.6
https://gunsfriend.ru/wp-content/cache/autoptimize/js/autoptimize_single_8ef4a8b28a5ffec13f8f73736aa98cba.js?ver=6.4.3
https://gunsfriend.ru/wp-content/cache/autoptimize/js/autoptimize_single_90db5b8fdd2839962541055eac95df77.js?ver=1.4.1
https://gunsfriend.ru/wp-content/cache/autoptimize/js/autoptimize_single_a91dcbb696a094d52a957e32f5220b05.js?ver=1.3
https://gunsfriend.ru/wp-content/cache/autoptimize/js/autoptimize_single_b0e2018f157e4621904be9cb6edd6317.js?ver=6.4.3
https://gunsfriend.ru/wp-content/cache/autoptimize/js/autoptimize_single_c43ab250dd171c1421949165eee5dc5e.js?ver=6.4.3
https://gunsfriend.ru/wp-includes/js/imagesloaded.min.js?ver=5.0.0
https://gunsfriend.ru/wp-includes/js/jquery/jquery-migrate.min.js?ver=3.4.1
https://gunsfriend.ru/wp-includes/js/jquery/jquery.masonry.min.js?ver=3.1.2b
https://gunsfriend.ru/wp-includes/js/jquery/jquery.min.js?ver=3.7.1
https://gunsfriend.ru/wp-includes/js/masonry.min.js?ver=4.2.2
https://mxkikf.com/d4kl17912/ivl/pm003yqh8678/quv/867ypkdkx.php
https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5778252166041275
https://qbhyczr5hw.ru/script.js
https://rbone.link/pjs/AnhvtTu1B.js
https://runoffree.bid/pjs/AnhvtTu1B.js
https://truenat.bid/nat/AnhvtTu1B.js
https://yandex.ru/ads/system/context.js
Внешние ссылки 0
Внутренние ссылки 99

meta-теги

viewportwidth=device-width, initial-scale=1
robotsindex, follow
googlebotindex, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1
bingbotindex, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1
twitter:cardsummary_large_image
msapplication-TileImagehttps://gunsfriend.ru/wp-content/uploads/2020/05/cropped-favicon-270x270.png
og:localeru_RU
og:typewebsite
og:titleВсе о вооружении России и мира
og:urlhttps://gunsfriend.ru/
og:site_nameВсе о вооружении России и мира
article:modified_time2019-11-30T17:10:00+00:00

Скриншот сайта

Скриншота нет

Сервер сайта

IP адрес сайта 77.246.146.46
Веб-сервер nginx/1.16.1
Версия HTTP HTTP 2
DNS сервера dns1.eplanet.host
dns3.eplanet.host
dns2.eplanet.host
DNS записи 8
A записи
1: ip: 77.246.146.46
NS записи
2: target: dns1.eplanet.host
3: target: dns3.eplanet.host
4: target: dns2.eplanet.host
SOA записи
5: mname: kartoska.ru
5: rname: root.kartoska.ru
5: serial: 2020051504
5: refresh: 3600
5: retry: 3600
5: expire: 604800
5: minimum-ttl: 86400
MX записи
6: pri: 10
6: target: mail.gunsfriend.ru
7: pri: 20
7: target: mail.gunsfriend.ru
TXT записи
8: txt: v=spf1 ip4:77.246.145.94 a mx ~all
8: entries: 0: v=spf1 ip4:77.246.145.94 a mx ~all

Ответ сервера

Группы заголовков: заголовки безопасности, заголовки кэширования.
status HTTP/1.1 200 OK
server nginx/1.16.1
date Fri, 16 Feb 2024 11:08:23 GMT
content-type text/html; charset=UTF-8
transfer-encoding chunked
connection keep-alive
x-powered-by PHP/7.4.29
set-cookie PHPSESSID=c8cca5d001d56485f3c5263fc5418f3a; path=/
expires Thu, 19 Nov 1981 08:52:00 GMT
cache-control no-store, no-cache, must-revalidate
pragma no-cache
x-rocket-nginx-bypass No
strict-transport-security max-age=31536000;
content-encoding gzip

Оцените сайт

Не ставьте оценку если отвечаете на другой отзыв или пишите комментарий:

Можно добавить текст отзыва, ответ на другой отзыв, или просто комментарий к сайту:
captcha