prompt
large_stringlengths
72
9.34k
completion
large_stringlengths
0
7.61k
<|file_name|>admin.py<|end_file_name|><|fim▁begin|>from django.contrib import admin from django.utils.translation import ugettext, ugettext_lazy as _ from ella.positions.models import Position from ella.utils import timezone class PositionOptions(admin.ModelAdmin): def show_title(self, obj): if not obj.target: return '-- %s --' % ugettext('empty position') else: <|fim_middle|> show_title.short_description = _('Title') def is_filled(self, obj): if obj.target: return True else: return False is_filled.short_description = _('Filled') is_filled.boolean = True def is_active(self, obj): if obj.disabled: return False now = timezone.now() active_from = not obj.active_from or obj.active_from <= now active_till = not obj.active_till or obj.active_till > now return active_from and active_till is_active.short_description = _('Active') is_active.boolean = True list_display = ('name', 'category', 'box_type', 'is_active', 'is_filled', 'show_title', 'disabled',) list_filter = ('category', 'name', 'disabled', 'active_from', 'active_till',) search_fields = ('box_type', 'text',) # suggest_fields = {'category': ('tree_path', 'title', 'slug',),} admin.site.register(Position, PositionOptions) <|fim▁end|>
return u'%s [%s]' % (obj.target.title, ugettext(obj.target_ct.name),)
<|file_name|>admin.py<|end_file_name|><|fim▁begin|>from django.contrib import admin from django.utils.translation import ugettext, ugettext_lazy as _ from ella.positions.models import Position from ella.utils import timezone class PositionOptions(admin.ModelAdmin): def show_title(self, obj): if not obj.target: return '-- %s --' % ugettext('empty position') else: return u'%s [%s]' % (obj.target.title, ugettext(obj.target_ct.name),) show_title.short_description = _('Title') def is_filled(self, obj): if obj.target: <|fim_middle|> else: return False is_filled.short_description = _('Filled') is_filled.boolean = True def is_active(self, obj): if obj.disabled: return False now = timezone.now() active_from = not obj.active_from or obj.active_from <= now active_till = not obj.active_till or obj.active_till > now return active_from and active_till is_active.short_description = _('Active') is_active.boolean = True list_display = ('name', 'category', 'box_type', 'is_active', 'is_filled', 'show_title', 'disabled',) list_filter = ('category', 'name', 'disabled', 'active_from', 'active_till',) search_fields = ('box_type', 'text',) # suggest_fields = {'category': ('tree_path', 'title', 'slug',),} admin.site.register(Position, PositionOptions) <|fim▁end|>
return True
<|file_name|>admin.py<|end_file_name|><|fim▁begin|>from django.contrib import admin from django.utils.translation import ugettext, ugettext_lazy as _ from ella.positions.models import Position from ella.utils import timezone class PositionOptions(admin.ModelAdmin): def show_title(self, obj): if not obj.target: return '-- %s --' % ugettext('empty position') else: return u'%s [%s]' % (obj.target.title, ugettext(obj.target_ct.name),) show_title.short_description = _('Title') def is_filled(self, obj): if obj.target: return True else: <|fim_middle|> is_filled.short_description = _('Filled') is_filled.boolean = True def is_active(self, obj): if obj.disabled: return False now = timezone.now() active_from = not obj.active_from or obj.active_from <= now active_till = not obj.active_till or obj.active_till > now return active_from and active_till is_active.short_description = _('Active') is_active.boolean = True list_display = ('name', 'category', 'box_type', 'is_active', 'is_filled', 'show_title', 'disabled',) list_filter = ('category', 'name', 'disabled', 'active_from', 'active_till',) search_fields = ('box_type', 'text',) # suggest_fields = {'category': ('tree_path', 'title', 'slug',),} admin.site.register(Position, PositionOptions) <|fim▁end|>
return False
<|file_name|>admin.py<|end_file_name|><|fim▁begin|>from django.contrib import admin from django.utils.translation import ugettext, ugettext_lazy as _ from ella.positions.models import Position from ella.utils import timezone class PositionOptions(admin.ModelAdmin): def show_title(self, obj): if not obj.target: return '-- %s --' % ugettext('empty position') else: return u'%s [%s]' % (obj.target.title, ugettext(obj.target_ct.name),) show_title.short_description = _('Title') def is_filled(self, obj): if obj.target: return True else: return False is_filled.short_description = _('Filled') is_filled.boolean = True def is_active(self, obj): if obj.disabled: <|fim_middle|> now = timezone.now() active_from = not obj.active_from or obj.active_from <= now active_till = not obj.active_till or obj.active_till > now return active_from and active_till is_active.short_description = _('Active') is_active.boolean = True list_display = ('name', 'category', 'box_type', 'is_active', 'is_filled', 'show_title', 'disabled',) list_filter = ('category', 'name', 'disabled', 'active_from', 'active_till',) search_fields = ('box_type', 'text',) # suggest_fields = {'category': ('tree_path', 'title', 'slug',),} admin.site.register(Position, PositionOptions) <|fim▁end|>
return False
<|file_name|>admin.py<|end_file_name|><|fim▁begin|>from django.contrib import admin from django.utils.translation import ugettext, ugettext_lazy as _ from ella.positions.models import Position from ella.utils import timezone class PositionOptions(admin.ModelAdmin): def <|fim_middle|>(self, obj): if not obj.target: return '-- %s --' % ugettext('empty position') else: return u'%s [%s]' % (obj.target.title, ugettext(obj.target_ct.name),) show_title.short_description = _('Title') def is_filled(self, obj): if obj.target: return True else: return False is_filled.short_description = _('Filled') is_filled.boolean = True def is_active(self, obj): if obj.disabled: return False now = timezone.now() active_from = not obj.active_from or obj.active_from <= now active_till = not obj.active_till or obj.active_till > now return active_from and active_till is_active.short_description = _('Active') is_active.boolean = True list_display = ('name', 'category', 'box_type', 'is_active', 'is_filled', 'show_title', 'disabled',) list_filter = ('category', 'name', 'disabled', 'active_from', 'active_till',) search_fields = ('box_type', 'text',) # suggest_fields = {'category': ('tree_path', 'title', 'slug',),} admin.site.register(Position, PositionOptions) <|fim▁end|>
show_title
<|file_name|>admin.py<|end_file_name|><|fim▁begin|>from django.contrib import admin from django.utils.translation import ugettext, ugettext_lazy as _ from ella.positions.models import Position from ella.utils import timezone class PositionOptions(admin.ModelAdmin): def show_title(self, obj): if not obj.target: return '-- %s --' % ugettext('empty position') else: return u'%s [%s]' % (obj.target.title, ugettext(obj.target_ct.name),) show_title.short_description = _('Title') def <|fim_middle|>(self, obj): if obj.target: return True else: return False is_filled.short_description = _('Filled') is_filled.boolean = True def is_active(self, obj): if obj.disabled: return False now = timezone.now() active_from = not obj.active_from or obj.active_from <= now active_till = not obj.active_till or obj.active_till > now return active_from and active_till is_active.short_description = _('Active') is_active.boolean = True list_display = ('name', 'category', 'box_type', 'is_active', 'is_filled', 'show_title', 'disabled',) list_filter = ('category', 'name', 'disabled', 'active_from', 'active_till',) search_fields = ('box_type', 'text',) # suggest_fields = {'category': ('tree_path', 'title', 'slug',),} admin.site.register(Position, PositionOptions) <|fim▁end|>
is_filled
<|file_name|>admin.py<|end_file_name|><|fim▁begin|>from django.contrib import admin from django.utils.translation import ugettext, ugettext_lazy as _ from ella.positions.models import Position from ella.utils import timezone class PositionOptions(admin.ModelAdmin): def show_title(self, obj): if not obj.target: return '-- %s --' % ugettext('empty position') else: return u'%s [%s]' % (obj.target.title, ugettext(obj.target_ct.name),) show_title.short_description = _('Title') def is_filled(self, obj): if obj.target: return True else: return False is_filled.short_description = _('Filled') is_filled.boolean = True def <|fim_middle|>(self, obj): if obj.disabled: return False now = timezone.now() active_from = not obj.active_from or obj.active_from <= now active_till = not obj.active_till or obj.active_till > now return active_from and active_till is_active.short_description = _('Active') is_active.boolean = True list_display = ('name', 'category', 'box_type', 'is_active', 'is_filled', 'show_title', 'disabled',) list_filter = ('category', 'name', 'disabled', 'active_from', 'active_till',) search_fields = ('box_type', 'text',) # suggest_fields = {'category': ('tree_path', 'title', 'slug',),} admin.site.register(Position, PositionOptions) <|fim▁end|>
is_active
<|file_name|>0001_initial.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- # Generated by Django 1.11.5 on 2017-09-21 12:06 from __future__ import unicode_literals <|fim▁hole|>from django.conf import settings from django.db import migrations, models import django.db.models.deletion class Migration(migrations.Migration): initial = True dependencies = [ migrations.swappable_dependency(settings.AUTH_USER_MODEL), ] operations = [ migrations.CreateModel( name='Group', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('name', models.CharField(max_length=255, unique=True)), ('slug', models.SlugField(allow_unicode=True, unique=True)), ('description', models.TextField(blank=True, default='')), ('description_html', models.TextField(blank=True, default='', editable=False)), ], options={ 'ordering': ['name'], }, ), migrations.CreateModel( name='GroupMember', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('group', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='memberships', to='groups.Group')), ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='user_groups', to=settings.AUTH_USER_MODEL)), ], ), migrations.AddField( model_name='group', name='members', field=models.ManyToManyField(through='groups.GroupMember', to=settings.AUTH_USER_MODEL), ), migrations.AlterUniqueTogether( name='groupmember', unique_together=set([('group', 'user')]), ), ]<|fim▁end|>
<|file_name|>0001_initial.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- # Generated by Django 1.11.5 on 2017-09-21 12:06 from __future__ import unicode_literals from django.conf import settings from django.db import migrations, models import django.db.models.deletion class Migration(migrations.Migration): <|fim_middle|> <|fim▁end|>
initial = True dependencies = [ migrations.swappable_dependency(settings.AUTH_USER_MODEL), ] operations = [ migrations.CreateModel( name='Group', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('name', models.CharField(max_length=255, unique=True)), ('slug', models.SlugField(allow_unicode=True, unique=True)), ('description', models.TextField(blank=True, default='')), ('description_html', models.TextField(blank=True, default='', editable=False)), ], options={ 'ordering': ['name'], }, ), migrations.CreateModel( name='GroupMember', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('group', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='memberships', to='groups.Group')), ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='user_groups', to=settings.AUTH_USER_MODEL)), ], ), migrations.AddField( model_name='group', name='members', field=models.ManyToManyField(through='groups.GroupMember', to=settings.AUTH_USER_MODEL), ), migrations.AlterUniqueTogether( name='groupmember', unique_together=set([('group', 'user')]), ), ]
<|file_name|>ref.py<|end_file_name|><|fim▁begin|>energies = dict() energies[81] = -3.17 # Ammoniadimer.xyz energies[82] = -5.02 # Waterdimer.xyz energies[83] = -1.50 # BenzeneMethanecomplex.xyz energies[84] = -18.61 # Formicaciddimer.xyz energies[85] = -15.96 # Formamidedimer.xyz energies[86] = -20.65 # Uracildimerhbonded.xyz energies[87] = -16.71 # 2pyridoxine2aminopyridinecomplex.xyz energies[88] = -16.37 # AdeninethymineWatsonCrickcomplex.xyz energies[89] = -0.53 # Methanedimer.xyz energies[90] = -1.51 # Ethenedimer.xyz energies[91] = -2.73 # Benzenedimerparalleldisplaced.xyz energies[92] = -4.42 # Pyrazinedimer.xyz energies[93] = -10.12 # Uracildimerstack.xyz energies[94] = -5.22 # Indolebenzenecomplexstack.xyz energies[95] = -12.23 # Adeninethyminecomplexstack.xyz energies[96] = -1.53 # Etheneethynecomplex.xyz energies[97] = -3.28 # Benzenewatercomplex.xyz energies[98] = -2.35 # Benzeneammoniacomplex.xyz energies[99] = -4.46 # BenzeneHCNcomplex.xyz energies[100] = -2.74 # BenzenedimerTshaped.xyz energies[101] = -5.73 # IndolebenzeneTshapecomplex.xyz energies[102] = -7.05 # Phenoldimer.xyz names = dict() names[81] = "Ammoniadimer.xyz" names[82] = "Waterdimer.xyz" names[83] = "BenzeneMethanecomplex.xyz" names[84] = "Formicaciddimer.xyz"<|fim▁hole|>names[89] = "Methanedimer.xyz" names[90] = "Ethenedimer.xyz" names[91] = "Benzenedimerparalleldisplaced.xyz" names[92] = "Pyrazinedimer.xyz" names[93] = "Uracildimerstack.xyz" names[94] = "Indolebenzenecomplexstack.xyz" names[95] = "Adeninethyminecomplexstack.xyz" names[96] = "Etheneethynecomplex.xyz" names[97] = "Benzenewatercomplex.xyz" names[98] = "Benzeneammoniacomplex.xyz" names[99] = "BenzeneHCNcomplex.xyz" names[100] = "BenzenedimerTshaped.xyz" names[101] = "IndolebenzeneTshapecomplex.xyz" names[102] = "Phenoldimer.xyz"<|fim▁end|>
names[85] = "Formamidedimer.xyz" names[86] = "Uracildimerhbonded.xyz" names[87] = "2pyridoxine2aminopyridinecomplex.xyz" names[88] = "AdeninethymineWatsonCrickcomplex.xyz"
<|file_name|>McAfee_DXL.py<|end_file_name|><|fim▁begin|>from typing import Dict import tempfile from dxlclient.client_config import DxlClientConfig from dxlclient.client import DxlClient from dxlclient.broker import Broker from dxlclient.message import Event import demistomock as demisto from CommonServerPython import * from CommonServerUserPython import * INTEGRATION_NAME = "McAfee DXL" CONNECT_RETRIES = 1 RECONNECT_DELAY = 1 RECONNECT_DELAY_MAX = 10 class EventSender: TRUST_LEVEL = { 'NOT_SET': '0', 'KNOWN_MALICIOUS': '1', 'MOST_LIKELY_MALICIOUS': '15', 'MIGHT_BE_MALICIOUS': '30', 'UNKNOWN': '50', 'MIGHT_BE_TRUSTED': '70', 'MOST_LIKELY_TRUSTED': '85', 'KNOWN_TRUSTED': '99', 'KNOWN_TRUSTED_INSTALLER': '100' } broker_ca_bundle = tempfile.NamedTemporaryFile().name cert_file = tempfile.NamedTemporaryFile().name private_key = tempfile.NamedTemporaryFile().name def __init__(self, params: Dict): with open(self.broker_ca_bundle, "w") as text_file: text_file.write(params['broker_ca_bundle']) with open(self.cert_file, "w") as text_file: text_file.write(params['cert_file']) with open(self.private_key, "w") as text_file: text_file.write(params['private_key']) if 'broker_urls' in params: self.broker_urls = params['broker_urls'].split(',') self.push_ip_topic = params.get('push_ip_topic') self.push_url_topic = params.get('push_url_topic') self.push_domain_topic = params.get('push_domain_topic') self.push_hash_topic = params.get('push_hash_topic') self.client = DxlClient(self.get_client_config()) self.client.connect() def __del__(self): self.client.disconnect() def push_ip(self, ip, trust_level, topic): if not is_ip_valid(ip): raise ValueError(f'argument ip {ip} is not a valid IP') trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_ip_topic, f'ip:{ip};trust_level:{trust_level_key}') return f'Successfully pushed ip {ip} with trust level {trust_level}' def push_url(self, url, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_url_topic = topic self.send_event(self.push_url_topic, f'url:{url};trust_level:{trust_level_key}') return f'Successfully pushed url {url} with trust level {trust_level}' def push_domain(self, domain, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_domain_topic = topic self.send_event(self.push_domain_topic, f'domain:{domain};trust_level:{trust_level_key}') return f'Successfully pushed domain {domain} with trust level {trust_level}' def push_hash(self, hash_obj, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_hash_topic, f'hash:{hash_obj};trust_level:{trust_level_key}') return f'Successfully pushed hash {hash_obj} with trust level {trust_level}' def get_client_config(self): config = DxlClientConfig( broker_ca_bundle=self.broker_ca_bundle, cert_file=self.cert_file, private_key=self.private_key, brokers=[Broker.parse(url) for url in self.broker_urls] ) config.connect_retries = CONNECT_RETRIES config.reconnect_delay = RECONNECT_DELAY config.reconnect_delay_max = RECONNECT_DELAY_MAX return config def send_event(self, topic, payload): if not topic: raise Exception(f'Error in {demisto.command()} topic field is required') event = Event(topic) event.payload = str(payload).encode() self.client.send_event(event) def send_event_wrapper(self, topic, payload): self.send_event(topic, payload) return 'Successfully sent event' def validate_certificates_format(): if '-----BEGIN PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't start with -----BEGIN PRIVATE KEY-----") if '-----END PRIVATE KEY-----' not in demisto.params()['private_key']: return_error(<|fim▁hole|> "incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if '-----END CERTIFICATE-----' not in demisto.params()['cert_file']: return_error( "The client certificates content seem to be incorrect as it doesn't end with -----END CERTIFICATE-----") if not demisto.params()['broker_ca_bundle'].lstrip(" ").startswith('-----BEGIN CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if not demisto.params()['broker_ca_bundle'].rstrip(" ").endswith('-----END CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't end with '-----END CERTIFICATE-----'") def main(): args = demisto.args() command = demisto.command() try: event_sender = EventSender(demisto.params()) result = '' if command == 'test-module': event_sender.send_event('TEST', 'test') result = 'ok' elif command == 'dxl-send-event': result = event_sender.send_event_wrapper(args.get('topic'), args.get('payload')) elif command == 'dxl-push-ip': result = event_sender.push_ip(args.get('ip'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-url': result = event_sender.push_url(args.get('url'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-domain': result = event_sender.push_domain(args.get('domain'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-hash': result = event_sender.push_hash(args.get('hash'), args.get('trust_level'), args.get('topic')) else: raise Exception(f'{demisto.command()} is not a command') return_outputs(result) except Exception as error: validate_certificates_format() return_error(f'error in {INTEGRATION_NAME} {str(error)}.', error) if __name__ in ('__builtin__', 'builtins'): main()<|fim▁end|>
"The private key content seems to be incorrect as it doesn't end with -----END PRIVATE KEY-----") if '-----BEGIN CERTIFICATE-----' not in demisto.params()['cert_file']: return_error("The client certificates content seem to be "
<|file_name|>McAfee_DXL.py<|end_file_name|><|fim▁begin|>from typing import Dict import tempfile from dxlclient.client_config import DxlClientConfig from dxlclient.client import DxlClient from dxlclient.broker import Broker from dxlclient.message import Event import demistomock as demisto from CommonServerPython import * from CommonServerUserPython import * INTEGRATION_NAME = "McAfee DXL" CONNECT_RETRIES = 1 RECONNECT_DELAY = 1 RECONNECT_DELAY_MAX = 10 class EventSender: <|fim_middle|> def validate_certificates_format(): if '-----BEGIN PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't start with -----BEGIN PRIVATE KEY-----") if '-----END PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't end with -----END PRIVATE KEY-----") if '-----BEGIN CERTIFICATE-----' not in demisto.params()['cert_file']: return_error("The client certificates content seem to be " "incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if '-----END CERTIFICATE-----' not in demisto.params()['cert_file']: return_error( "The client certificates content seem to be incorrect as it doesn't end with -----END CERTIFICATE-----") if not demisto.params()['broker_ca_bundle'].lstrip(" ").startswith('-----BEGIN CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if not demisto.params()['broker_ca_bundle'].rstrip(" ").endswith('-----END CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't end with '-----END CERTIFICATE-----'") def main(): args = demisto.args() command = demisto.command() try: event_sender = EventSender(demisto.params()) result = '' if command == 'test-module': event_sender.send_event('TEST', 'test') result = 'ok' elif command == 'dxl-send-event': result = event_sender.send_event_wrapper(args.get('topic'), args.get('payload')) elif command == 'dxl-push-ip': result = event_sender.push_ip(args.get('ip'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-url': result = event_sender.push_url(args.get('url'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-domain': result = event_sender.push_domain(args.get('domain'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-hash': result = event_sender.push_hash(args.get('hash'), args.get('trust_level'), args.get('topic')) else: raise Exception(f'{demisto.command()} is not a command') return_outputs(result) except Exception as error: validate_certificates_format() return_error(f'error in {INTEGRATION_NAME} {str(error)}.', error) if __name__ in ('__builtin__', 'builtins'): main() <|fim▁end|>
TRUST_LEVEL = { 'NOT_SET': '0', 'KNOWN_MALICIOUS': '1', 'MOST_LIKELY_MALICIOUS': '15', 'MIGHT_BE_MALICIOUS': '30', 'UNKNOWN': '50', 'MIGHT_BE_TRUSTED': '70', 'MOST_LIKELY_TRUSTED': '85', 'KNOWN_TRUSTED': '99', 'KNOWN_TRUSTED_INSTALLER': '100' } broker_ca_bundle = tempfile.NamedTemporaryFile().name cert_file = tempfile.NamedTemporaryFile().name private_key = tempfile.NamedTemporaryFile().name def __init__(self, params: Dict): with open(self.broker_ca_bundle, "w") as text_file: text_file.write(params['broker_ca_bundle']) with open(self.cert_file, "w") as text_file: text_file.write(params['cert_file']) with open(self.private_key, "w") as text_file: text_file.write(params['private_key']) if 'broker_urls' in params: self.broker_urls = params['broker_urls'].split(',') self.push_ip_topic = params.get('push_ip_topic') self.push_url_topic = params.get('push_url_topic') self.push_domain_topic = params.get('push_domain_topic') self.push_hash_topic = params.get('push_hash_topic') self.client = DxlClient(self.get_client_config()) self.client.connect() def __del__(self): self.client.disconnect() def push_ip(self, ip, trust_level, topic): if not is_ip_valid(ip): raise ValueError(f'argument ip {ip} is not a valid IP') trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_ip_topic, f'ip:{ip};trust_level:{trust_level_key}') return f'Successfully pushed ip {ip} with trust level {trust_level}' def push_url(self, url, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_url_topic = topic self.send_event(self.push_url_topic, f'url:{url};trust_level:{trust_level_key}') return f'Successfully pushed url {url} with trust level {trust_level}' def push_domain(self, domain, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_domain_topic = topic self.send_event(self.push_domain_topic, f'domain:{domain};trust_level:{trust_level_key}') return f'Successfully pushed domain {domain} with trust level {trust_level}' def push_hash(self, hash_obj, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_hash_topic, f'hash:{hash_obj};trust_level:{trust_level_key}') return f'Successfully pushed hash {hash_obj} with trust level {trust_level}' def get_client_config(self): config = DxlClientConfig( broker_ca_bundle=self.broker_ca_bundle, cert_file=self.cert_file, private_key=self.private_key, brokers=[Broker.parse(url) for url in self.broker_urls] ) config.connect_retries = CONNECT_RETRIES config.reconnect_delay = RECONNECT_DELAY config.reconnect_delay_max = RECONNECT_DELAY_MAX return config def send_event(self, topic, payload): if not topic: raise Exception(f'Error in {demisto.command()} topic field is required') event = Event(topic) event.payload = str(payload).encode() self.client.send_event(event) def send_event_wrapper(self, topic, payload): self.send_event(topic, payload) return 'Successfully sent event'
<|file_name|>McAfee_DXL.py<|end_file_name|><|fim▁begin|>from typing import Dict import tempfile from dxlclient.client_config import DxlClientConfig from dxlclient.client import DxlClient from dxlclient.broker import Broker from dxlclient.message import Event import demistomock as demisto from CommonServerPython import * from CommonServerUserPython import * INTEGRATION_NAME = "McAfee DXL" CONNECT_RETRIES = 1 RECONNECT_DELAY = 1 RECONNECT_DELAY_MAX = 10 class EventSender: TRUST_LEVEL = { 'NOT_SET': '0', 'KNOWN_MALICIOUS': '1', 'MOST_LIKELY_MALICIOUS': '15', 'MIGHT_BE_MALICIOUS': '30', 'UNKNOWN': '50', 'MIGHT_BE_TRUSTED': '70', 'MOST_LIKELY_TRUSTED': '85', 'KNOWN_TRUSTED': '99', 'KNOWN_TRUSTED_INSTALLER': '100' } broker_ca_bundle = tempfile.NamedTemporaryFile().name cert_file = tempfile.NamedTemporaryFile().name private_key = tempfile.NamedTemporaryFile().name def __init__(self, params: Dict): <|fim_middle|> def __del__(self): self.client.disconnect() def push_ip(self, ip, trust_level, topic): if not is_ip_valid(ip): raise ValueError(f'argument ip {ip} is not a valid IP') trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_ip_topic, f'ip:{ip};trust_level:{trust_level_key}') return f'Successfully pushed ip {ip} with trust level {trust_level}' def push_url(self, url, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_url_topic = topic self.send_event(self.push_url_topic, f'url:{url};trust_level:{trust_level_key}') return f'Successfully pushed url {url} with trust level {trust_level}' def push_domain(self, domain, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_domain_topic = topic self.send_event(self.push_domain_topic, f'domain:{domain};trust_level:{trust_level_key}') return f'Successfully pushed domain {domain} with trust level {trust_level}' def push_hash(self, hash_obj, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_hash_topic, f'hash:{hash_obj};trust_level:{trust_level_key}') return f'Successfully pushed hash {hash_obj} with trust level {trust_level}' def get_client_config(self): config = DxlClientConfig( broker_ca_bundle=self.broker_ca_bundle, cert_file=self.cert_file, private_key=self.private_key, brokers=[Broker.parse(url) for url in self.broker_urls] ) config.connect_retries = CONNECT_RETRIES config.reconnect_delay = RECONNECT_DELAY config.reconnect_delay_max = RECONNECT_DELAY_MAX return config def send_event(self, topic, payload): if not topic: raise Exception(f'Error in {demisto.command()} topic field is required') event = Event(topic) event.payload = str(payload).encode() self.client.send_event(event) def send_event_wrapper(self, topic, payload): self.send_event(topic, payload) return 'Successfully sent event' def validate_certificates_format(): if '-----BEGIN PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't start with -----BEGIN PRIVATE KEY-----") if '-----END PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't end with -----END PRIVATE KEY-----") if '-----BEGIN CERTIFICATE-----' not in demisto.params()['cert_file']: return_error("The client certificates content seem to be " "incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if '-----END CERTIFICATE-----' not in demisto.params()['cert_file']: return_error( "The client certificates content seem to be incorrect as it doesn't end with -----END CERTIFICATE-----") if not demisto.params()['broker_ca_bundle'].lstrip(" ").startswith('-----BEGIN CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if not demisto.params()['broker_ca_bundle'].rstrip(" ").endswith('-----END CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't end with '-----END CERTIFICATE-----'") def main(): args = demisto.args() command = demisto.command() try: event_sender = EventSender(demisto.params()) result = '' if command == 'test-module': event_sender.send_event('TEST', 'test') result = 'ok' elif command == 'dxl-send-event': result = event_sender.send_event_wrapper(args.get('topic'), args.get('payload')) elif command == 'dxl-push-ip': result = event_sender.push_ip(args.get('ip'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-url': result = event_sender.push_url(args.get('url'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-domain': result = event_sender.push_domain(args.get('domain'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-hash': result = event_sender.push_hash(args.get('hash'), args.get('trust_level'), args.get('topic')) else: raise Exception(f'{demisto.command()} is not a command') return_outputs(result) except Exception as error: validate_certificates_format() return_error(f'error in {INTEGRATION_NAME} {str(error)}.', error) if __name__ in ('__builtin__', 'builtins'): main() <|fim▁end|>
with open(self.broker_ca_bundle, "w") as text_file: text_file.write(params['broker_ca_bundle']) with open(self.cert_file, "w") as text_file: text_file.write(params['cert_file']) with open(self.private_key, "w") as text_file: text_file.write(params['private_key']) if 'broker_urls' in params: self.broker_urls = params['broker_urls'].split(',') self.push_ip_topic = params.get('push_ip_topic') self.push_url_topic = params.get('push_url_topic') self.push_domain_topic = params.get('push_domain_topic') self.push_hash_topic = params.get('push_hash_topic') self.client = DxlClient(self.get_client_config()) self.client.connect()
<|file_name|>McAfee_DXL.py<|end_file_name|><|fim▁begin|>from typing import Dict import tempfile from dxlclient.client_config import DxlClientConfig from dxlclient.client import DxlClient from dxlclient.broker import Broker from dxlclient.message import Event import demistomock as demisto from CommonServerPython import * from CommonServerUserPython import * INTEGRATION_NAME = "McAfee DXL" CONNECT_RETRIES = 1 RECONNECT_DELAY = 1 RECONNECT_DELAY_MAX = 10 class EventSender: TRUST_LEVEL = { 'NOT_SET': '0', 'KNOWN_MALICIOUS': '1', 'MOST_LIKELY_MALICIOUS': '15', 'MIGHT_BE_MALICIOUS': '30', 'UNKNOWN': '50', 'MIGHT_BE_TRUSTED': '70', 'MOST_LIKELY_TRUSTED': '85', 'KNOWN_TRUSTED': '99', 'KNOWN_TRUSTED_INSTALLER': '100' } broker_ca_bundle = tempfile.NamedTemporaryFile().name cert_file = tempfile.NamedTemporaryFile().name private_key = tempfile.NamedTemporaryFile().name def __init__(self, params: Dict): with open(self.broker_ca_bundle, "w") as text_file: text_file.write(params['broker_ca_bundle']) with open(self.cert_file, "w") as text_file: text_file.write(params['cert_file']) with open(self.private_key, "w") as text_file: text_file.write(params['private_key']) if 'broker_urls' in params: self.broker_urls = params['broker_urls'].split(',') self.push_ip_topic = params.get('push_ip_topic') self.push_url_topic = params.get('push_url_topic') self.push_domain_topic = params.get('push_domain_topic') self.push_hash_topic = params.get('push_hash_topic') self.client = DxlClient(self.get_client_config()) self.client.connect() def __del__(self): <|fim_middle|> def push_ip(self, ip, trust_level, topic): if not is_ip_valid(ip): raise ValueError(f'argument ip {ip} is not a valid IP') trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_ip_topic, f'ip:{ip};trust_level:{trust_level_key}') return f'Successfully pushed ip {ip} with trust level {trust_level}' def push_url(self, url, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_url_topic = topic self.send_event(self.push_url_topic, f'url:{url};trust_level:{trust_level_key}') return f'Successfully pushed url {url} with trust level {trust_level}' def push_domain(self, domain, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_domain_topic = topic self.send_event(self.push_domain_topic, f'domain:{domain};trust_level:{trust_level_key}') return f'Successfully pushed domain {domain} with trust level {trust_level}' def push_hash(self, hash_obj, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_hash_topic, f'hash:{hash_obj};trust_level:{trust_level_key}') return f'Successfully pushed hash {hash_obj} with trust level {trust_level}' def get_client_config(self): config = DxlClientConfig( broker_ca_bundle=self.broker_ca_bundle, cert_file=self.cert_file, private_key=self.private_key, brokers=[Broker.parse(url) for url in self.broker_urls] ) config.connect_retries = CONNECT_RETRIES config.reconnect_delay = RECONNECT_DELAY config.reconnect_delay_max = RECONNECT_DELAY_MAX return config def send_event(self, topic, payload): if not topic: raise Exception(f'Error in {demisto.command()} topic field is required') event = Event(topic) event.payload = str(payload).encode() self.client.send_event(event) def send_event_wrapper(self, topic, payload): self.send_event(topic, payload) return 'Successfully sent event' def validate_certificates_format(): if '-----BEGIN PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't start with -----BEGIN PRIVATE KEY-----") if '-----END PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't end with -----END PRIVATE KEY-----") if '-----BEGIN CERTIFICATE-----' not in demisto.params()['cert_file']: return_error("The client certificates content seem to be " "incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if '-----END CERTIFICATE-----' not in demisto.params()['cert_file']: return_error( "The client certificates content seem to be incorrect as it doesn't end with -----END CERTIFICATE-----") if not demisto.params()['broker_ca_bundle'].lstrip(" ").startswith('-----BEGIN CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if not demisto.params()['broker_ca_bundle'].rstrip(" ").endswith('-----END CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't end with '-----END CERTIFICATE-----'") def main(): args = demisto.args() command = demisto.command() try: event_sender = EventSender(demisto.params()) result = '' if command == 'test-module': event_sender.send_event('TEST', 'test') result = 'ok' elif command == 'dxl-send-event': result = event_sender.send_event_wrapper(args.get('topic'), args.get('payload')) elif command == 'dxl-push-ip': result = event_sender.push_ip(args.get('ip'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-url': result = event_sender.push_url(args.get('url'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-domain': result = event_sender.push_domain(args.get('domain'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-hash': result = event_sender.push_hash(args.get('hash'), args.get('trust_level'), args.get('topic')) else: raise Exception(f'{demisto.command()} is not a command') return_outputs(result) except Exception as error: validate_certificates_format() return_error(f'error in {INTEGRATION_NAME} {str(error)}.', error) if __name__ in ('__builtin__', 'builtins'): main() <|fim▁end|>
self.client.disconnect()
<|file_name|>McAfee_DXL.py<|end_file_name|><|fim▁begin|>from typing import Dict import tempfile from dxlclient.client_config import DxlClientConfig from dxlclient.client import DxlClient from dxlclient.broker import Broker from dxlclient.message import Event import demistomock as demisto from CommonServerPython import * from CommonServerUserPython import * INTEGRATION_NAME = "McAfee DXL" CONNECT_RETRIES = 1 RECONNECT_DELAY = 1 RECONNECT_DELAY_MAX = 10 class EventSender: TRUST_LEVEL = { 'NOT_SET': '0', 'KNOWN_MALICIOUS': '1', 'MOST_LIKELY_MALICIOUS': '15', 'MIGHT_BE_MALICIOUS': '30', 'UNKNOWN': '50', 'MIGHT_BE_TRUSTED': '70', 'MOST_LIKELY_TRUSTED': '85', 'KNOWN_TRUSTED': '99', 'KNOWN_TRUSTED_INSTALLER': '100' } broker_ca_bundle = tempfile.NamedTemporaryFile().name cert_file = tempfile.NamedTemporaryFile().name private_key = tempfile.NamedTemporaryFile().name def __init__(self, params: Dict): with open(self.broker_ca_bundle, "w") as text_file: text_file.write(params['broker_ca_bundle']) with open(self.cert_file, "w") as text_file: text_file.write(params['cert_file']) with open(self.private_key, "w") as text_file: text_file.write(params['private_key']) if 'broker_urls' in params: self.broker_urls = params['broker_urls'].split(',') self.push_ip_topic = params.get('push_ip_topic') self.push_url_topic = params.get('push_url_topic') self.push_domain_topic = params.get('push_domain_topic') self.push_hash_topic = params.get('push_hash_topic') self.client = DxlClient(self.get_client_config()) self.client.connect() def __del__(self): self.client.disconnect() def push_ip(self, ip, trust_level, topic): <|fim_middle|> def push_url(self, url, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_url_topic = topic self.send_event(self.push_url_topic, f'url:{url};trust_level:{trust_level_key}') return f'Successfully pushed url {url} with trust level {trust_level}' def push_domain(self, domain, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_domain_topic = topic self.send_event(self.push_domain_topic, f'domain:{domain};trust_level:{trust_level_key}') return f'Successfully pushed domain {domain} with trust level {trust_level}' def push_hash(self, hash_obj, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_hash_topic, f'hash:{hash_obj};trust_level:{trust_level_key}') return f'Successfully pushed hash {hash_obj} with trust level {trust_level}' def get_client_config(self): config = DxlClientConfig( broker_ca_bundle=self.broker_ca_bundle, cert_file=self.cert_file, private_key=self.private_key, brokers=[Broker.parse(url) for url in self.broker_urls] ) config.connect_retries = CONNECT_RETRIES config.reconnect_delay = RECONNECT_DELAY config.reconnect_delay_max = RECONNECT_DELAY_MAX return config def send_event(self, topic, payload): if not topic: raise Exception(f'Error in {demisto.command()} topic field is required') event = Event(topic) event.payload = str(payload).encode() self.client.send_event(event) def send_event_wrapper(self, topic, payload): self.send_event(topic, payload) return 'Successfully sent event' def validate_certificates_format(): if '-----BEGIN PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't start with -----BEGIN PRIVATE KEY-----") if '-----END PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't end with -----END PRIVATE KEY-----") if '-----BEGIN CERTIFICATE-----' not in demisto.params()['cert_file']: return_error("The client certificates content seem to be " "incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if '-----END CERTIFICATE-----' not in demisto.params()['cert_file']: return_error( "The client certificates content seem to be incorrect as it doesn't end with -----END CERTIFICATE-----") if not demisto.params()['broker_ca_bundle'].lstrip(" ").startswith('-----BEGIN CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if not demisto.params()['broker_ca_bundle'].rstrip(" ").endswith('-----END CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't end with '-----END CERTIFICATE-----'") def main(): args = demisto.args() command = demisto.command() try: event_sender = EventSender(demisto.params()) result = '' if command == 'test-module': event_sender.send_event('TEST', 'test') result = 'ok' elif command == 'dxl-send-event': result = event_sender.send_event_wrapper(args.get('topic'), args.get('payload')) elif command == 'dxl-push-ip': result = event_sender.push_ip(args.get('ip'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-url': result = event_sender.push_url(args.get('url'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-domain': result = event_sender.push_domain(args.get('domain'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-hash': result = event_sender.push_hash(args.get('hash'), args.get('trust_level'), args.get('topic')) else: raise Exception(f'{demisto.command()} is not a command') return_outputs(result) except Exception as error: validate_certificates_format() return_error(f'error in {INTEGRATION_NAME} {str(error)}.', error) if __name__ in ('__builtin__', 'builtins'): main() <|fim▁end|>
if not is_ip_valid(ip): raise ValueError(f'argument ip {ip} is not a valid IP') trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_ip_topic, f'ip:{ip};trust_level:{trust_level_key}') return f'Successfully pushed ip {ip} with trust level {trust_level}'
<|file_name|>McAfee_DXL.py<|end_file_name|><|fim▁begin|>from typing import Dict import tempfile from dxlclient.client_config import DxlClientConfig from dxlclient.client import DxlClient from dxlclient.broker import Broker from dxlclient.message import Event import demistomock as demisto from CommonServerPython import * from CommonServerUserPython import * INTEGRATION_NAME = "McAfee DXL" CONNECT_RETRIES = 1 RECONNECT_DELAY = 1 RECONNECT_DELAY_MAX = 10 class EventSender: TRUST_LEVEL = { 'NOT_SET': '0', 'KNOWN_MALICIOUS': '1', 'MOST_LIKELY_MALICIOUS': '15', 'MIGHT_BE_MALICIOUS': '30', 'UNKNOWN': '50', 'MIGHT_BE_TRUSTED': '70', 'MOST_LIKELY_TRUSTED': '85', 'KNOWN_TRUSTED': '99', 'KNOWN_TRUSTED_INSTALLER': '100' } broker_ca_bundle = tempfile.NamedTemporaryFile().name cert_file = tempfile.NamedTemporaryFile().name private_key = tempfile.NamedTemporaryFile().name def __init__(self, params: Dict): with open(self.broker_ca_bundle, "w") as text_file: text_file.write(params['broker_ca_bundle']) with open(self.cert_file, "w") as text_file: text_file.write(params['cert_file']) with open(self.private_key, "w") as text_file: text_file.write(params['private_key']) if 'broker_urls' in params: self.broker_urls = params['broker_urls'].split(',') self.push_ip_topic = params.get('push_ip_topic') self.push_url_topic = params.get('push_url_topic') self.push_domain_topic = params.get('push_domain_topic') self.push_hash_topic = params.get('push_hash_topic') self.client = DxlClient(self.get_client_config()) self.client.connect() def __del__(self): self.client.disconnect() def push_ip(self, ip, trust_level, topic): if not is_ip_valid(ip): raise ValueError(f'argument ip {ip} is not a valid IP') trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_ip_topic, f'ip:{ip};trust_level:{trust_level_key}') return f'Successfully pushed ip {ip} with trust level {trust_level}' def push_url(self, url, trust_level, topic): <|fim_middle|> def push_domain(self, domain, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_domain_topic = topic self.send_event(self.push_domain_topic, f'domain:{domain};trust_level:{trust_level_key}') return f'Successfully pushed domain {domain} with trust level {trust_level}' def push_hash(self, hash_obj, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_hash_topic, f'hash:{hash_obj};trust_level:{trust_level_key}') return f'Successfully pushed hash {hash_obj} with trust level {trust_level}' def get_client_config(self): config = DxlClientConfig( broker_ca_bundle=self.broker_ca_bundle, cert_file=self.cert_file, private_key=self.private_key, brokers=[Broker.parse(url) for url in self.broker_urls] ) config.connect_retries = CONNECT_RETRIES config.reconnect_delay = RECONNECT_DELAY config.reconnect_delay_max = RECONNECT_DELAY_MAX return config def send_event(self, topic, payload): if not topic: raise Exception(f'Error in {demisto.command()} topic field is required') event = Event(topic) event.payload = str(payload).encode() self.client.send_event(event) def send_event_wrapper(self, topic, payload): self.send_event(topic, payload) return 'Successfully sent event' def validate_certificates_format(): if '-----BEGIN PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't start with -----BEGIN PRIVATE KEY-----") if '-----END PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't end with -----END PRIVATE KEY-----") if '-----BEGIN CERTIFICATE-----' not in demisto.params()['cert_file']: return_error("The client certificates content seem to be " "incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if '-----END CERTIFICATE-----' not in demisto.params()['cert_file']: return_error( "The client certificates content seem to be incorrect as it doesn't end with -----END CERTIFICATE-----") if not demisto.params()['broker_ca_bundle'].lstrip(" ").startswith('-----BEGIN CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if not demisto.params()['broker_ca_bundle'].rstrip(" ").endswith('-----END CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't end with '-----END CERTIFICATE-----'") def main(): args = demisto.args() command = demisto.command() try: event_sender = EventSender(demisto.params()) result = '' if command == 'test-module': event_sender.send_event('TEST', 'test') result = 'ok' elif command == 'dxl-send-event': result = event_sender.send_event_wrapper(args.get('topic'), args.get('payload')) elif command == 'dxl-push-ip': result = event_sender.push_ip(args.get('ip'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-url': result = event_sender.push_url(args.get('url'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-domain': result = event_sender.push_domain(args.get('domain'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-hash': result = event_sender.push_hash(args.get('hash'), args.get('trust_level'), args.get('topic')) else: raise Exception(f'{demisto.command()} is not a command') return_outputs(result) except Exception as error: validate_certificates_format() return_error(f'error in {INTEGRATION_NAME} {str(error)}.', error) if __name__ in ('__builtin__', 'builtins'): main() <|fim▁end|>
trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_url_topic = topic self.send_event(self.push_url_topic, f'url:{url};trust_level:{trust_level_key}') return f'Successfully pushed url {url} with trust level {trust_level}'
<|file_name|>McAfee_DXL.py<|end_file_name|><|fim▁begin|>from typing import Dict import tempfile from dxlclient.client_config import DxlClientConfig from dxlclient.client import DxlClient from dxlclient.broker import Broker from dxlclient.message import Event import demistomock as demisto from CommonServerPython import * from CommonServerUserPython import * INTEGRATION_NAME = "McAfee DXL" CONNECT_RETRIES = 1 RECONNECT_DELAY = 1 RECONNECT_DELAY_MAX = 10 class EventSender: TRUST_LEVEL = { 'NOT_SET': '0', 'KNOWN_MALICIOUS': '1', 'MOST_LIKELY_MALICIOUS': '15', 'MIGHT_BE_MALICIOUS': '30', 'UNKNOWN': '50', 'MIGHT_BE_TRUSTED': '70', 'MOST_LIKELY_TRUSTED': '85', 'KNOWN_TRUSTED': '99', 'KNOWN_TRUSTED_INSTALLER': '100' } broker_ca_bundle = tempfile.NamedTemporaryFile().name cert_file = tempfile.NamedTemporaryFile().name private_key = tempfile.NamedTemporaryFile().name def __init__(self, params: Dict): with open(self.broker_ca_bundle, "w") as text_file: text_file.write(params['broker_ca_bundle']) with open(self.cert_file, "w") as text_file: text_file.write(params['cert_file']) with open(self.private_key, "w") as text_file: text_file.write(params['private_key']) if 'broker_urls' in params: self.broker_urls = params['broker_urls'].split(',') self.push_ip_topic = params.get('push_ip_topic') self.push_url_topic = params.get('push_url_topic') self.push_domain_topic = params.get('push_domain_topic') self.push_hash_topic = params.get('push_hash_topic') self.client = DxlClient(self.get_client_config()) self.client.connect() def __del__(self): self.client.disconnect() def push_ip(self, ip, trust_level, topic): if not is_ip_valid(ip): raise ValueError(f'argument ip {ip} is not a valid IP') trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_ip_topic, f'ip:{ip};trust_level:{trust_level_key}') return f'Successfully pushed ip {ip} with trust level {trust_level}' def push_url(self, url, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_url_topic = topic self.send_event(self.push_url_topic, f'url:{url};trust_level:{trust_level_key}') return f'Successfully pushed url {url} with trust level {trust_level}' def push_domain(self, domain, trust_level, topic): <|fim_middle|> def push_hash(self, hash_obj, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_hash_topic, f'hash:{hash_obj};trust_level:{trust_level_key}') return f'Successfully pushed hash {hash_obj} with trust level {trust_level}' def get_client_config(self): config = DxlClientConfig( broker_ca_bundle=self.broker_ca_bundle, cert_file=self.cert_file, private_key=self.private_key, brokers=[Broker.parse(url) for url in self.broker_urls] ) config.connect_retries = CONNECT_RETRIES config.reconnect_delay = RECONNECT_DELAY config.reconnect_delay_max = RECONNECT_DELAY_MAX return config def send_event(self, topic, payload): if not topic: raise Exception(f'Error in {demisto.command()} topic field is required') event = Event(topic) event.payload = str(payload).encode() self.client.send_event(event) def send_event_wrapper(self, topic, payload): self.send_event(topic, payload) return 'Successfully sent event' def validate_certificates_format(): if '-----BEGIN PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't start with -----BEGIN PRIVATE KEY-----") if '-----END PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't end with -----END PRIVATE KEY-----") if '-----BEGIN CERTIFICATE-----' not in demisto.params()['cert_file']: return_error("The client certificates content seem to be " "incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if '-----END CERTIFICATE-----' not in demisto.params()['cert_file']: return_error( "The client certificates content seem to be incorrect as it doesn't end with -----END CERTIFICATE-----") if not demisto.params()['broker_ca_bundle'].lstrip(" ").startswith('-----BEGIN CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if not demisto.params()['broker_ca_bundle'].rstrip(" ").endswith('-----END CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't end with '-----END CERTIFICATE-----'") def main(): args = demisto.args() command = demisto.command() try: event_sender = EventSender(demisto.params()) result = '' if command == 'test-module': event_sender.send_event('TEST', 'test') result = 'ok' elif command == 'dxl-send-event': result = event_sender.send_event_wrapper(args.get('topic'), args.get('payload')) elif command == 'dxl-push-ip': result = event_sender.push_ip(args.get('ip'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-url': result = event_sender.push_url(args.get('url'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-domain': result = event_sender.push_domain(args.get('domain'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-hash': result = event_sender.push_hash(args.get('hash'), args.get('trust_level'), args.get('topic')) else: raise Exception(f'{demisto.command()} is not a command') return_outputs(result) except Exception as error: validate_certificates_format() return_error(f'error in {INTEGRATION_NAME} {str(error)}.', error) if __name__ in ('__builtin__', 'builtins'): main() <|fim▁end|>
trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_domain_topic = topic self.send_event(self.push_domain_topic, f'domain:{domain};trust_level:{trust_level_key}') return f'Successfully pushed domain {domain} with trust level {trust_level}'
<|file_name|>McAfee_DXL.py<|end_file_name|><|fim▁begin|>from typing import Dict import tempfile from dxlclient.client_config import DxlClientConfig from dxlclient.client import DxlClient from dxlclient.broker import Broker from dxlclient.message import Event import demistomock as demisto from CommonServerPython import * from CommonServerUserPython import * INTEGRATION_NAME = "McAfee DXL" CONNECT_RETRIES = 1 RECONNECT_DELAY = 1 RECONNECT_DELAY_MAX = 10 class EventSender: TRUST_LEVEL = { 'NOT_SET': '0', 'KNOWN_MALICIOUS': '1', 'MOST_LIKELY_MALICIOUS': '15', 'MIGHT_BE_MALICIOUS': '30', 'UNKNOWN': '50', 'MIGHT_BE_TRUSTED': '70', 'MOST_LIKELY_TRUSTED': '85', 'KNOWN_TRUSTED': '99', 'KNOWN_TRUSTED_INSTALLER': '100' } broker_ca_bundle = tempfile.NamedTemporaryFile().name cert_file = tempfile.NamedTemporaryFile().name private_key = tempfile.NamedTemporaryFile().name def __init__(self, params: Dict): with open(self.broker_ca_bundle, "w") as text_file: text_file.write(params['broker_ca_bundle']) with open(self.cert_file, "w") as text_file: text_file.write(params['cert_file']) with open(self.private_key, "w") as text_file: text_file.write(params['private_key']) if 'broker_urls' in params: self.broker_urls = params['broker_urls'].split(',') self.push_ip_topic = params.get('push_ip_topic') self.push_url_topic = params.get('push_url_topic') self.push_domain_topic = params.get('push_domain_topic') self.push_hash_topic = params.get('push_hash_topic') self.client = DxlClient(self.get_client_config()) self.client.connect() def __del__(self): self.client.disconnect() def push_ip(self, ip, trust_level, topic): if not is_ip_valid(ip): raise ValueError(f'argument ip {ip} is not a valid IP') trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_ip_topic, f'ip:{ip};trust_level:{trust_level_key}') return f'Successfully pushed ip {ip} with trust level {trust_level}' def push_url(self, url, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_url_topic = topic self.send_event(self.push_url_topic, f'url:{url};trust_level:{trust_level_key}') return f'Successfully pushed url {url} with trust level {trust_level}' def push_domain(self, domain, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_domain_topic = topic self.send_event(self.push_domain_topic, f'domain:{domain};trust_level:{trust_level_key}') return f'Successfully pushed domain {domain} with trust level {trust_level}' def push_hash(self, hash_obj, trust_level, topic): <|fim_middle|> def get_client_config(self): config = DxlClientConfig( broker_ca_bundle=self.broker_ca_bundle, cert_file=self.cert_file, private_key=self.private_key, brokers=[Broker.parse(url) for url in self.broker_urls] ) config.connect_retries = CONNECT_RETRIES config.reconnect_delay = RECONNECT_DELAY config.reconnect_delay_max = RECONNECT_DELAY_MAX return config def send_event(self, topic, payload): if not topic: raise Exception(f'Error in {demisto.command()} topic field is required') event = Event(topic) event.payload = str(payload).encode() self.client.send_event(event) def send_event_wrapper(self, topic, payload): self.send_event(topic, payload) return 'Successfully sent event' def validate_certificates_format(): if '-----BEGIN PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't start with -----BEGIN PRIVATE KEY-----") if '-----END PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't end with -----END PRIVATE KEY-----") if '-----BEGIN CERTIFICATE-----' not in demisto.params()['cert_file']: return_error("The client certificates content seem to be " "incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if '-----END CERTIFICATE-----' not in demisto.params()['cert_file']: return_error( "The client certificates content seem to be incorrect as it doesn't end with -----END CERTIFICATE-----") if not demisto.params()['broker_ca_bundle'].lstrip(" ").startswith('-----BEGIN CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if not demisto.params()['broker_ca_bundle'].rstrip(" ").endswith('-----END CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't end with '-----END CERTIFICATE-----'") def main(): args = demisto.args() command = demisto.command() try: event_sender = EventSender(demisto.params()) result = '' if command == 'test-module': event_sender.send_event('TEST', 'test') result = 'ok' elif command == 'dxl-send-event': result = event_sender.send_event_wrapper(args.get('topic'), args.get('payload')) elif command == 'dxl-push-ip': result = event_sender.push_ip(args.get('ip'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-url': result = event_sender.push_url(args.get('url'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-domain': result = event_sender.push_domain(args.get('domain'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-hash': result = event_sender.push_hash(args.get('hash'), args.get('trust_level'), args.get('topic')) else: raise Exception(f'{demisto.command()} is not a command') return_outputs(result) except Exception as error: validate_certificates_format() return_error(f'error in {INTEGRATION_NAME} {str(error)}.', error) if __name__ in ('__builtin__', 'builtins'): main() <|fim▁end|>
trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_hash_topic, f'hash:{hash_obj};trust_level:{trust_level_key}') return f'Successfully pushed hash {hash_obj} with trust level {trust_level}'
<|file_name|>McAfee_DXL.py<|end_file_name|><|fim▁begin|>from typing import Dict import tempfile from dxlclient.client_config import DxlClientConfig from dxlclient.client import DxlClient from dxlclient.broker import Broker from dxlclient.message import Event import demistomock as demisto from CommonServerPython import * from CommonServerUserPython import * INTEGRATION_NAME = "McAfee DXL" CONNECT_RETRIES = 1 RECONNECT_DELAY = 1 RECONNECT_DELAY_MAX = 10 class EventSender: TRUST_LEVEL = { 'NOT_SET': '0', 'KNOWN_MALICIOUS': '1', 'MOST_LIKELY_MALICIOUS': '15', 'MIGHT_BE_MALICIOUS': '30', 'UNKNOWN': '50', 'MIGHT_BE_TRUSTED': '70', 'MOST_LIKELY_TRUSTED': '85', 'KNOWN_TRUSTED': '99', 'KNOWN_TRUSTED_INSTALLER': '100' } broker_ca_bundle = tempfile.NamedTemporaryFile().name cert_file = tempfile.NamedTemporaryFile().name private_key = tempfile.NamedTemporaryFile().name def __init__(self, params: Dict): with open(self.broker_ca_bundle, "w") as text_file: text_file.write(params['broker_ca_bundle']) with open(self.cert_file, "w") as text_file: text_file.write(params['cert_file']) with open(self.private_key, "w") as text_file: text_file.write(params['private_key']) if 'broker_urls' in params: self.broker_urls = params['broker_urls'].split(',') self.push_ip_topic = params.get('push_ip_topic') self.push_url_topic = params.get('push_url_topic') self.push_domain_topic = params.get('push_domain_topic') self.push_hash_topic = params.get('push_hash_topic') self.client = DxlClient(self.get_client_config()) self.client.connect() def __del__(self): self.client.disconnect() def push_ip(self, ip, trust_level, topic): if not is_ip_valid(ip): raise ValueError(f'argument ip {ip} is not a valid IP') trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_ip_topic, f'ip:{ip};trust_level:{trust_level_key}') return f'Successfully pushed ip {ip} with trust level {trust_level}' def push_url(self, url, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_url_topic = topic self.send_event(self.push_url_topic, f'url:{url};trust_level:{trust_level_key}') return f'Successfully pushed url {url} with trust level {trust_level}' def push_domain(self, domain, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_domain_topic = topic self.send_event(self.push_domain_topic, f'domain:{domain};trust_level:{trust_level_key}') return f'Successfully pushed domain {domain} with trust level {trust_level}' def push_hash(self, hash_obj, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_hash_topic, f'hash:{hash_obj};trust_level:{trust_level_key}') return f'Successfully pushed hash {hash_obj} with trust level {trust_level}' def get_client_config(self): <|fim_middle|> def send_event(self, topic, payload): if not topic: raise Exception(f'Error in {demisto.command()} topic field is required') event = Event(topic) event.payload = str(payload).encode() self.client.send_event(event) def send_event_wrapper(self, topic, payload): self.send_event(topic, payload) return 'Successfully sent event' def validate_certificates_format(): if '-----BEGIN PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't start with -----BEGIN PRIVATE KEY-----") if '-----END PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't end with -----END PRIVATE KEY-----") if '-----BEGIN CERTIFICATE-----' not in demisto.params()['cert_file']: return_error("The client certificates content seem to be " "incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if '-----END CERTIFICATE-----' not in demisto.params()['cert_file']: return_error( "The client certificates content seem to be incorrect as it doesn't end with -----END CERTIFICATE-----") if not demisto.params()['broker_ca_bundle'].lstrip(" ").startswith('-----BEGIN CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if not demisto.params()['broker_ca_bundle'].rstrip(" ").endswith('-----END CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't end with '-----END CERTIFICATE-----'") def main(): args = demisto.args() command = demisto.command() try: event_sender = EventSender(demisto.params()) result = '' if command == 'test-module': event_sender.send_event('TEST', 'test') result = 'ok' elif command == 'dxl-send-event': result = event_sender.send_event_wrapper(args.get('topic'), args.get('payload')) elif command == 'dxl-push-ip': result = event_sender.push_ip(args.get('ip'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-url': result = event_sender.push_url(args.get('url'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-domain': result = event_sender.push_domain(args.get('domain'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-hash': result = event_sender.push_hash(args.get('hash'), args.get('trust_level'), args.get('topic')) else: raise Exception(f'{demisto.command()} is not a command') return_outputs(result) except Exception as error: validate_certificates_format() return_error(f'error in {INTEGRATION_NAME} {str(error)}.', error) if __name__ in ('__builtin__', 'builtins'): main() <|fim▁end|>
config = DxlClientConfig( broker_ca_bundle=self.broker_ca_bundle, cert_file=self.cert_file, private_key=self.private_key, brokers=[Broker.parse(url) for url in self.broker_urls] ) config.connect_retries = CONNECT_RETRIES config.reconnect_delay = RECONNECT_DELAY config.reconnect_delay_max = RECONNECT_DELAY_MAX return config
<|file_name|>McAfee_DXL.py<|end_file_name|><|fim▁begin|>from typing import Dict import tempfile from dxlclient.client_config import DxlClientConfig from dxlclient.client import DxlClient from dxlclient.broker import Broker from dxlclient.message import Event import demistomock as demisto from CommonServerPython import * from CommonServerUserPython import * INTEGRATION_NAME = "McAfee DXL" CONNECT_RETRIES = 1 RECONNECT_DELAY = 1 RECONNECT_DELAY_MAX = 10 class EventSender: TRUST_LEVEL = { 'NOT_SET': '0', 'KNOWN_MALICIOUS': '1', 'MOST_LIKELY_MALICIOUS': '15', 'MIGHT_BE_MALICIOUS': '30', 'UNKNOWN': '50', 'MIGHT_BE_TRUSTED': '70', 'MOST_LIKELY_TRUSTED': '85', 'KNOWN_TRUSTED': '99', 'KNOWN_TRUSTED_INSTALLER': '100' } broker_ca_bundle = tempfile.NamedTemporaryFile().name cert_file = tempfile.NamedTemporaryFile().name private_key = tempfile.NamedTemporaryFile().name def __init__(self, params: Dict): with open(self.broker_ca_bundle, "w") as text_file: text_file.write(params['broker_ca_bundle']) with open(self.cert_file, "w") as text_file: text_file.write(params['cert_file']) with open(self.private_key, "w") as text_file: text_file.write(params['private_key']) if 'broker_urls' in params: self.broker_urls = params['broker_urls'].split(',') self.push_ip_topic = params.get('push_ip_topic') self.push_url_topic = params.get('push_url_topic') self.push_domain_topic = params.get('push_domain_topic') self.push_hash_topic = params.get('push_hash_topic') self.client = DxlClient(self.get_client_config()) self.client.connect() def __del__(self): self.client.disconnect() def push_ip(self, ip, trust_level, topic): if not is_ip_valid(ip): raise ValueError(f'argument ip {ip} is not a valid IP') trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_ip_topic, f'ip:{ip};trust_level:{trust_level_key}') return f'Successfully pushed ip {ip} with trust level {trust_level}' def push_url(self, url, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_url_topic = topic self.send_event(self.push_url_topic, f'url:{url};trust_level:{trust_level_key}') return f'Successfully pushed url {url} with trust level {trust_level}' def push_domain(self, domain, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_domain_topic = topic self.send_event(self.push_domain_topic, f'domain:{domain};trust_level:{trust_level_key}') return f'Successfully pushed domain {domain} with trust level {trust_level}' def push_hash(self, hash_obj, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_hash_topic, f'hash:{hash_obj};trust_level:{trust_level_key}') return f'Successfully pushed hash {hash_obj} with trust level {trust_level}' def get_client_config(self): config = DxlClientConfig( broker_ca_bundle=self.broker_ca_bundle, cert_file=self.cert_file, private_key=self.private_key, brokers=[Broker.parse(url) for url in self.broker_urls] ) config.connect_retries = CONNECT_RETRIES config.reconnect_delay = RECONNECT_DELAY config.reconnect_delay_max = RECONNECT_DELAY_MAX return config def send_event(self, topic, payload): <|fim_middle|> def send_event_wrapper(self, topic, payload): self.send_event(topic, payload) return 'Successfully sent event' def validate_certificates_format(): if '-----BEGIN PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't start with -----BEGIN PRIVATE KEY-----") if '-----END PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't end with -----END PRIVATE KEY-----") if '-----BEGIN CERTIFICATE-----' not in demisto.params()['cert_file']: return_error("The client certificates content seem to be " "incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if '-----END CERTIFICATE-----' not in demisto.params()['cert_file']: return_error( "The client certificates content seem to be incorrect as it doesn't end with -----END CERTIFICATE-----") if not demisto.params()['broker_ca_bundle'].lstrip(" ").startswith('-----BEGIN CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if not demisto.params()['broker_ca_bundle'].rstrip(" ").endswith('-----END CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't end with '-----END CERTIFICATE-----'") def main(): args = demisto.args() command = demisto.command() try: event_sender = EventSender(demisto.params()) result = '' if command == 'test-module': event_sender.send_event('TEST', 'test') result = 'ok' elif command == 'dxl-send-event': result = event_sender.send_event_wrapper(args.get('topic'), args.get('payload')) elif command == 'dxl-push-ip': result = event_sender.push_ip(args.get('ip'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-url': result = event_sender.push_url(args.get('url'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-domain': result = event_sender.push_domain(args.get('domain'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-hash': result = event_sender.push_hash(args.get('hash'), args.get('trust_level'), args.get('topic')) else: raise Exception(f'{demisto.command()} is not a command') return_outputs(result) except Exception as error: validate_certificates_format() return_error(f'error in {INTEGRATION_NAME} {str(error)}.', error) if __name__ in ('__builtin__', 'builtins'): main() <|fim▁end|>
if not topic: raise Exception(f'Error in {demisto.command()} topic field is required') event = Event(topic) event.payload = str(payload).encode() self.client.send_event(event)
<|file_name|>McAfee_DXL.py<|end_file_name|><|fim▁begin|>from typing import Dict import tempfile from dxlclient.client_config import DxlClientConfig from dxlclient.client import DxlClient from dxlclient.broker import Broker from dxlclient.message import Event import demistomock as demisto from CommonServerPython import * from CommonServerUserPython import * INTEGRATION_NAME = "McAfee DXL" CONNECT_RETRIES = 1 RECONNECT_DELAY = 1 RECONNECT_DELAY_MAX = 10 class EventSender: TRUST_LEVEL = { 'NOT_SET': '0', 'KNOWN_MALICIOUS': '1', 'MOST_LIKELY_MALICIOUS': '15', 'MIGHT_BE_MALICIOUS': '30', 'UNKNOWN': '50', 'MIGHT_BE_TRUSTED': '70', 'MOST_LIKELY_TRUSTED': '85', 'KNOWN_TRUSTED': '99', 'KNOWN_TRUSTED_INSTALLER': '100' } broker_ca_bundle = tempfile.NamedTemporaryFile().name cert_file = tempfile.NamedTemporaryFile().name private_key = tempfile.NamedTemporaryFile().name def __init__(self, params: Dict): with open(self.broker_ca_bundle, "w") as text_file: text_file.write(params['broker_ca_bundle']) with open(self.cert_file, "w") as text_file: text_file.write(params['cert_file']) with open(self.private_key, "w") as text_file: text_file.write(params['private_key']) if 'broker_urls' in params: self.broker_urls = params['broker_urls'].split(',') self.push_ip_topic = params.get('push_ip_topic') self.push_url_topic = params.get('push_url_topic') self.push_domain_topic = params.get('push_domain_topic') self.push_hash_topic = params.get('push_hash_topic') self.client = DxlClient(self.get_client_config()) self.client.connect() def __del__(self): self.client.disconnect() def push_ip(self, ip, trust_level, topic): if not is_ip_valid(ip): raise ValueError(f'argument ip {ip} is not a valid IP') trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_ip_topic, f'ip:{ip};trust_level:{trust_level_key}') return f'Successfully pushed ip {ip} with trust level {trust_level}' def push_url(self, url, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_url_topic = topic self.send_event(self.push_url_topic, f'url:{url};trust_level:{trust_level_key}') return f'Successfully pushed url {url} with trust level {trust_level}' def push_domain(self, domain, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_domain_topic = topic self.send_event(self.push_domain_topic, f'domain:{domain};trust_level:{trust_level_key}') return f'Successfully pushed domain {domain} with trust level {trust_level}' def push_hash(self, hash_obj, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_hash_topic, f'hash:{hash_obj};trust_level:{trust_level_key}') return f'Successfully pushed hash {hash_obj} with trust level {trust_level}' def get_client_config(self): config = DxlClientConfig( broker_ca_bundle=self.broker_ca_bundle, cert_file=self.cert_file, private_key=self.private_key, brokers=[Broker.parse(url) for url in self.broker_urls] ) config.connect_retries = CONNECT_RETRIES config.reconnect_delay = RECONNECT_DELAY config.reconnect_delay_max = RECONNECT_DELAY_MAX return config def send_event(self, topic, payload): if not topic: raise Exception(f'Error in {demisto.command()} topic field is required') event = Event(topic) event.payload = str(payload).encode() self.client.send_event(event) def send_event_wrapper(self, topic, payload): <|fim_middle|> def validate_certificates_format(): if '-----BEGIN PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't start with -----BEGIN PRIVATE KEY-----") if '-----END PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't end with -----END PRIVATE KEY-----") if '-----BEGIN CERTIFICATE-----' not in demisto.params()['cert_file']: return_error("The client certificates content seem to be " "incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if '-----END CERTIFICATE-----' not in demisto.params()['cert_file']: return_error( "The client certificates content seem to be incorrect as it doesn't end with -----END CERTIFICATE-----") if not demisto.params()['broker_ca_bundle'].lstrip(" ").startswith('-----BEGIN CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if not demisto.params()['broker_ca_bundle'].rstrip(" ").endswith('-----END CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't end with '-----END CERTIFICATE-----'") def main(): args = demisto.args() command = demisto.command() try: event_sender = EventSender(demisto.params()) result = '' if command == 'test-module': event_sender.send_event('TEST', 'test') result = 'ok' elif command == 'dxl-send-event': result = event_sender.send_event_wrapper(args.get('topic'), args.get('payload')) elif command == 'dxl-push-ip': result = event_sender.push_ip(args.get('ip'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-url': result = event_sender.push_url(args.get('url'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-domain': result = event_sender.push_domain(args.get('domain'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-hash': result = event_sender.push_hash(args.get('hash'), args.get('trust_level'), args.get('topic')) else: raise Exception(f'{demisto.command()} is not a command') return_outputs(result) except Exception as error: validate_certificates_format() return_error(f'error in {INTEGRATION_NAME} {str(error)}.', error) if __name__ in ('__builtin__', 'builtins'): main() <|fim▁end|>
self.send_event(topic, payload) return 'Successfully sent event'
<|file_name|>McAfee_DXL.py<|end_file_name|><|fim▁begin|>from typing import Dict import tempfile from dxlclient.client_config import DxlClientConfig from dxlclient.client import DxlClient from dxlclient.broker import Broker from dxlclient.message import Event import demistomock as demisto from CommonServerPython import * from CommonServerUserPython import * INTEGRATION_NAME = "McAfee DXL" CONNECT_RETRIES = 1 RECONNECT_DELAY = 1 RECONNECT_DELAY_MAX = 10 class EventSender: TRUST_LEVEL = { 'NOT_SET': '0', 'KNOWN_MALICIOUS': '1', 'MOST_LIKELY_MALICIOUS': '15', 'MIGHT_BE_MALICIOUS': '30', 'UNKNOWN': '50', 'MIGHT_BE_TRUSTED': '70', 'MOST_LIKELY_TRUSTED': '85', 'KNOWN_TRUSTED': '99', 'KNOWN_TRUSTED_INSTALLER': '100' } broker_ca_bundle = tempfile.NamedTemporaryFile().name cert_file = tempfile.NamedTemporaryFile().name private_key = tempfile.NamedTemporaryFile().name def __init__(self, params: Dict): with open(self.broker_ca_bundle, "w") as text_file: text_file.write(params['broker_ca_bundle']) with open(self.cert_file, "w") as text_file: text_file.write(params['cert_file']) with open(self.private_key, "w") as text_file: text_file.write(params['private_key']) if 'broker_urls' in params: self.broker_urls = params['broker_urls'].split(',') self.push_ip_topic = params.get('push_ip_topic') self.push_url_topic = params.get('push_url_topic') self.push_domain_topic = params.get('push_domain_topic') self.push_hash_topic = params.get('push_hash_topic') self.client = DxlClient(self.get_client_config()) self.client.connect() def __del__(self): self.client.disconnect() def push_ip(self, ip, trust_level, topic): if not is_ip_valid(ip): raise ValueError(f'argument ip {ip} is not a valid IP') trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_ip_topic, f'ip:{ip};trust_level:{trust_level_key}') return f'Successfully pushed ip {ip} with trust level {trust_level}' def push_url(self, url, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_url_topic = topic self.send_event(self.push_url_topic, f'url:{url};trust_level:{trust_level_key}') return f'Successfully pushed url {url} with trust level {trust_level}' def push_domain(self, domain, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_domain_topic = topic self.send_event(self.push_domain_topic, f'domain:{domain};trust_level:{trust_level_key}') return f'Successfully pushed domain {domain} with trust level {trust_level}' def push_hash(self, hash_obj, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_hash_topic, f'hash:{hash_obj};trust_level:{trust_level_key}') return f'Successfully pushed hash {hash_obj} with trust level {trust_level}' def get_client_config(self): config = DxlClientConfig( broker_ca_bundle=self.broker_ca_bundle, cert_file=self.cert_file, private_key=self.private_key, brokers=[Broker.parse(url) for url in self.broker_urls] ) config.connect_retries = CONNECT_RETRIES config.reconnect_delay = RECONNECT_DELAY config.reconnect_delay_max = RECONNECT_DELAY_MAX return config def send_event(self, topic, payload): if not topic: raise Exception(f'Error in {demisto.command()} topic field is required') event = Event(topic) event.payload = str(payload).encode() self.client.send_event(event) def send_event_wrapper(self, topic, payload): self.send_event(topic, payload) return 'Successfully sent event' def validate_certificates_format(): <|fim_middle|> def main(): args = demisto.args() command = demisto.command() try: event_sender = EventSender(demisto.params()) result = '' if command == 'test-module': event_sender.send_event('TEST', 'test') result = 'ok' elif command == 'dxl-send-event': result = event_sender.send_event_wrapper(args.get('topic'), args.get('payload')) elif command == 'dxl-push-ip': result = event_sender.push_ip(args.get('ip'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-url': result = event_sender.push_url(args.get('url'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-domain': result = event_sender.push_domain(args.get('domain'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-hash': result = event_sender.push_hash(args.get('hash'), args.get('trust_level'), args.get('topic')) else: raise Exception(f'{demisto.command()} is not a command') return_outputs(result) except Exception as error: validate_certificates_format() return_error(f'error in {INTEGRATION_NAME} {str(error)}.', error) if __name__ in ('__builtin__', 'builtins'): main() <|fim▁end|>
if '-----BEGIN PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't start with -----BEGIN PRIVATE KEY-----") if '-----END PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't end with -----END PRIVATE KEY-----") if '-----BEGIN CERTIFICATE-----' not in demisto.params()['cert_file']: return_error("The client certificates content seem to be " "incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if '-----END CERTIFICATE-----' not in demisto.params()['cert_file']: return_error( "The client certificates content seem to be incorrect as it doesn't end with -----END CERTIFICATE-----") if not demisto.params()['broker_ca_bundle'].lstrip(" ").startswith('-----BEGIN CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if not demisto.params()['broker_ca_bundle'].rstrip(" ").endswith('-----END CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't end with '-----END CERTIFICATE-----'")
<|file_name|>McAfee_DXL.py<|end_file_name|><|fim▁begin|>from typing import Dict import tempfile from dxlclient.client_config import DxlClientConfig from dxlclient.client import DxlClient from dxlclient.broker import Broker from dxlclient.message import Event import demistomock as demisto from CommonServerPython import * from CommonServerUserPython import * INTEGRATION_NAME = "McAfee DXL" CONNECT_RETRIES = 1 RECONNECT_DELAY = 1 RECONNECT_DELAY_MAX = 10 class EventSender: TRUST_LEVEL = { 'NOT_SET': '0', 'KNOWN_MALICIOUS': '1', 'MOST_LIKELY_MALICIOUS': '15', 'MIGHT_BE_MALICIOUS': '30', 'UNKNOWN': '50', 'MIGHT_BE_TRUSTED': '70', 'MOST_LIKELY_TRUSTED': '85', 'KNOWN_TRUSTED': '99', 'KNOWN_TRUSTED_INSTALLER': '100' } broker_ca_bundle = tempfile.NamedTemporaryFile().name cert_file = tempfile.NamedTemporaryFile().name private_key = tempfile.NamedTemporaryFile().name def __init__(self, params: Dict): with open(self.broker_ca_bundle, "w") as text_file: text_file.write(params['broker_ca_bundle']) with open(self.cert_file, "w") as text_file: text_file.write(params['cert_file']) with open(self.private_key, "w") as text_file: text_file.write(params['private_key']) if 'broker_urls' in params: self.broker_urls = params['broker_urls'].split(',') self.push_ip_topic = params.get('push_ip_topic') self.push_url_topic = params.get('push_url_topic') self.push_domain_topic = params.get('push_domain_topic') self.push_hash_topic = params.get('push_hash_topic') self.client = DxlClient(self.get_client_config()) self.client.connect() def __del__(self): self.client.disconnect() def push_ip(self, ip, trust_level, topic): if not is_ip_valid(ip): raise ValueError(f'argument ip {ip} is not a valid IP') trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_ip_topic, f'ip:{ip};trust_level:{trust_level_key}') return f'Successfully pushed ip {ip} with trust level {trust_level}' def push_url(self, url, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_url_topic = topic self.send_event(self.push_url_topic, f'url:{url};trust_level:{trust_level_key}') return f'Successfully pushed url {url} with trust level {trust_level}' def push_domain(self, domain, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_domain_topic = topic self.send_event(self.push_domain_topic, f'domain:{domain};trust_level:{trust_level_key}') return f'Successfully pushed domain {domain} with trust level {trust_level}' def push_hash(self, hash_obj, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_hash_topic, f'hash:{hash_obj};trust_level:{trust_level_key}') return f'Successfully pushed hash {hash_obj} with trust level {trust_level}' def get_client_config(self): config = DxlClientConfig( broker_ca_bundle=self.broker_ca_bundle, cert_file=self.cert_file, private_key=self.private_key, brokers=[Broker.parse(url) for url in self.broker_urls] ) config.connect_retries = CONNECT_RETRIES config.reconnect_delay = RECONNECT_DELAY config.reconnect_delay_max = RECONNECT_DELAY_MAX return config def send_event(self, topic, payload): if not topic: raise Exception(f'Error in {demisto.command()} topic field is required') event = Event(topic) event.payload = str(payload).encode() self.client.send_event(event) def send_event_wrapper(self, topic, payload): self.send_event(topic, payload) return 'Successfully sent event' def validate_certificates_format(): if '-----BEGIN PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't start with -----BEGIN PRIVATE KEY-----") if '-----END PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't end with -----END PRIVATE KEY-----") if '-----BEGIN CERTIFICATE-----' not in demisto.params()['cert_file']: return_error("The client certificates content seem to be " "incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if '-----END CERTIFICATE-----' not in demisto.params()['cert_file']: return_error( "The client certificates content seem to be incorrect as it doesn't end with -----END CERTIFICATE-----") if not demisto.params()['broker_ca_bundle'].lstrip(" ").startswith('-----BEGIN CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if not demisto.params()['broker_ca_bundle'].rstrip(" ").endswith('-----END CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't end with '-----END CERTIFICATE-----'") def main(): <|fim_middle|> if __name__ in ('__builtin__', 'builtins'): main() <|fim▁end|>
args = demisto.args() command = demisto.command() try: event_sender = EventSender(demisto.params()) result = '' if command == 'test-module': event_sender.send_event('TEST', 'test') result = 'ok' elif command == 'dxl-send-event': result = event_sender.send_event_wrapper(args.get('topic'), args.get('payload')) elif command == 'dxl-push-ip': result = event_sender.push_ip(args.get('ip'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-url': result = event_sender.push_url(args.get('url'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-domain': result = event_sender.push_domain(args.get('domain'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-hash': result = event_sender.push_hash(args.get('hash'), args.get('trust_level'), args.get('topic')) else: raise Exception(f'{demisto.command()} is not a command') return_outputs(result) except Exception as error: validate_certificates_format() return_error(f'error in {INTEGRATION_NAME} {str(error)}.', error)
<|file_name|>McAfee_DXL.py<|end_file_name|><|fim▁begin|>from typing import Dict import tempfile from dxlclient.client_config import DxlClientConfig from dxlclient.client import DxlClient from dxlclient.broker import Broker from dxlclient.message import Event import demistomock as demisto from CommonServerPython import * from CommonServerUserPython import * INTEGRATION_NAME = "McAfee DXL" CONNECT_RETRIES = 1 RECONNECT_DELAY = 1 RECONNECT_DELAY_MAX = 10 class EventSender: TRUST_LEVEL = { 'NOT_SET': '0', 'KNOWN_MALICIOUS': '1', 'MOST_LIKELY_MALICIOUS': '15', 'MIGHT_BE_MALICIOUS': '30', 'UNKNOWN': '50', 'MIGHT_BE_TRUSTED': '70', 'MOST_LIKELY_TRUSTED': '85', 'KNOWN_TRUSTED': '99', 'KNOWN_TRUSTED_INSTALLER': '100' } broker_ca_bundle = tempfile.NamedTemporaryFile().name cert_file = tempfile.NamedTemporaryFile().name private_key = tempfile.NamedTemporaryFile().name def __init__(self, params: Dict): with open(self.broker_ca_bundle, "w") as text_file: text_file.write(params['broker_ca_bundle']) with open(self.cert_file, "w") as text_file: text_file.write(params['cert_file']) with open(self.private_key, "w") as text_file: text_file.write(params['private_key']) if 'broker_urls' in params: <|fim_middle|> self.push_ip_topic = params.get('push_ip_topic') self.push_url_topic = params.get('push_url_topic') self.push_domain_topic = params.get('push_domain_topic') self.push_hash_topic = params.get('push_hash_topic') self.client = DxlClient(self.get_client_config()) self.client.connect() def __del__(self): self.client.disconnect() def push_ip(self, ip, trust_level, topic): if not is_ip_valid(ip): raise ValueError(f'argument ip {ip} is not a valid IP') trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_ip_topic, f'ip:{ip};trust_level:{trust_level_key}') return f'Successfully pushed ip {ip} with trust level {trust_level}' def push_url(self, url, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_url_topic = topic self.send_event(self.push_url_topic, f'url:{url};trust_level:{trust_level_key}') return f'Successfully pushed url {url} with trust level {trust_level}' def push_domain(self, domain, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_domain_topic = topic self.send_event(self.push_domain_topic, f'domain:{domain};trust_level:{trust_level_key}') return f'Successfully pushed domain {domain} with trust level {trust_level}' def push_hash(self, hash_obj, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_hash_topic, f'hash:{hash_obj};trust_level:{trust_level_key}') return f'Successfully pushed hash {hash_obj} with trust level {trust_level}' def get_client_config(self): config = DxlClientConfig( broker_ca_bundle=self.broker_ca_bundle, cert_file=self.cert_file, private_key=self.private_key, brokers=[Broker.parse(url) for url in self.broker_urls] ) config.connect_retries = CONNECT_RETRIES config.reconnect_delay = RECONNECT_DELAY config.reconnect_delay_max = RECONNECT_DELAY_MAX return config def send_event(self, topic, payload): if not topic: raise Exception(f'Error in {demisto.command()} topic field is required') event = Event(topic) event.payload = str(payload).encode() self.client.send_event(event) def send_event_wrapper(self, topic, payload): self.send_event(topic, payload) return 'Successfully sent event' def validate_certificates_format(): if '-----BEGIN PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't start with -----BEGIN PRIVATE KEY-----") if '-----END PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't end with -----END PRIVATE KEY-----") if '-----BEGIN CERTIFICATE-----' not in demisto.params()['cert_file']: return_error("The client certificates content seem to be " "incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if '-----END CERTIFICATE-----' not in demisto.params()['cert_file']: return_error( "The client certificates content seem to be incorrect as it doesn't end with -----END CERTIFICATE-----") if not demisto.params()['broker_ca_bundle'].lstrip(" ").startswith('-----BEGIN CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if not demisto.params()['broker_ca_bundle'].rstrip(" ").endswith('-----END CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't end with '-----END CERTIFICATE-----'") def main(): args = demisto.args() command = demisto.command() try: event_sender = EventSender(demisto.params()) result = '' if command == 'test-module': event_sender.send_event('TEST', 'test') result = 'ok' elif command == 'dxl-send-event': result = event_sender.send_event_wrapper(args.get('topic'), args.get('payload')) elif command == 'dxl-push-ip': result = event_sender.push_ip(args.get('ip'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-url': result = event_sender.push_url(args.get('url'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-domain': result = event_sender.push_domain(args.get('domain'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-hash': result = event_sender.push_hash(args.get('hash'), args.get('trust_level'), args.get('topic')) else: raise Exception(f'{demisto.command()} is not a command') return_outputs(result) except Exception as error: validate_certificates_format() return_error(f'error in {INTEGRATION_NAME} {str(error)}.', error) if __name__ in ('__builtin__', 'builtins'): main() <|fim▁end|>
self.broker_urls = params['broker_urls'].split(',')
<|file_name|>McAfee_DXL.py<|end_file_name|><|fim▁begin|>from typing import Dict import tempfile from dxlclient.client_config import DxlClientConfig from dxlclient.client import DxlClient from dxlclient.broker import Broker from dxlclient.message import Event import demistomock as demisto from CommonServerPython import * from CommonServerUserPython import * INTEGRATION_NAME = "McAfee DXL" CONNECT_RETRIES = 1 RECONNECT_DELAY = 1 RECONNECT_DELAY_MAX = 10 class EventSender: TRUST_LEVEL = { 'NOT_SET': '0', 'KNOWN_MALICIOUS': '1', 'MOST_LIKELY_MALICIOUS': '15', 'MIGHT_BE_MALICIOUS': '30', 'UNKNOWN': '50', 'MIGHT_BE_TRUSTED': '70', 'MOST_LIKELY_TRUSTED': '85', 'KNOWN_TRUSTED': '99', 'KNOWN_TRUSTED_INSTALLER': '100' } broker_ca_bundle = tempfile.NamedTemporaryFile().name cert_file = tempfile.NamedTemporaryFile().name private_key = tempfile.NamedTemporaryFile().name def __init__(self, params: Dict): with open(self.broker_ca_bundle, "w") as text_file: text_file.write(params['broker_ca_bundle']) with open(self.cert_file, "w") as text_file: text_file.write(params['cert_file']) with open(self.private_key, "w") as text_file: text_file.write(params['private_key']) if 'broker_urls' in params: self.broker_urls = params['broker_urls'].split(',') self.push_ip_topic = params.get('push_ip_topic') self.push_url_topic = params.get('push_url_topic') self.push_domain_topic = params.get('push_domain_topic') self.push_hash_topic = params.get('push_hash_topic') self.client = DxlClient(self.get_client_config()) self.client.connect() def __del__(self): self.client.disconnect() def push_ip(self, ip, trust_level, topic): if not is_ip_valid(ip): <|fim_middle|> trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_ip_topic, f'ip:{ip};trust_level:{trust_level_key}') return f'Successfully pushed ip {ip} with trust level {trust_level}' def push_url(self, url, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_url_topic = topic self.send_event(self.push_url_topic, f'url:{url};trust_level:{trust_level_key}') return f'Successfully pushed url {url} with trust level {trust_level}' def push_domain(self, domain, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_domain_topic = topic self.send_event(self.push_domain_topic, f'domain:{domain};trust_level:{trust_level_key}') return f'Successfully pushed domain {domain} with trust level {trust_level}' def push_hash(self, hash_obj, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_hash_topic, f'hash:{hash_obj};trust_level:{trust_level_key}') return f'Successfully pushed hash {hash_obj} with trust level {trust_level}' def get_client_config(self): config = DxlClientConfig( broker_ca_bundle=self.broker_ca_bundle, cert_file=self.cert_file, private_key=self.private_key, brokers=[Broker.parse(url) for url in self.broker_urls] ) config.connect_retries = CONNECT_RETRIES config.reconnect_delay = RECONNECT_DELAY config.reconnect_delay_max = RECONNECT_DELAY_MAX return config def send_event(self, topic, payload): if not topic: raise Exception(f'Error in {demisto.command()} topic field is required') event = Event(topic) event.payload = str(payload).encode() self.client.send_event(event) def send_event_wrapper(self, topic, payload): self.send_event(topic, payload) return 'Successfully sent event' def validate_certificates_format(): if '-----BEGIN PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't start with -----BEGIN PRIVATE KEY-----") if '-----END PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't end with -----END PRIVATE KEY-----") if '-----BEGIN CERTIFICATE-----' not in demisto.params()['cert_file']: return_error("The client certificates content seem to be " "incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if '-----END CERTIFICATE-----' not in demisto.params()['cert_file']: return_error( "The client certificates content seem to be incorrect as it doesn't end with -----END CERTIFICATE-----") if not demisto.params()['broker_ca_bundle'].lstrip(" ").startswith('-----BEGIN CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if not demisto.params()['broker_ca_bundle'].rstrip(" ").endswith('-----END CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't end with '-----END CERTIFICATE-----'") def main(): args = demisto.args() command = demisto.command() try: event_sender = EventSender(demisto.params()) result = '' if command == 'test-module': event_sender.send_event('TEST', 'test') result = 'ok' elif command == 'dxl-send-event': result = event_sender.send_event_wrapper(args.get('topic'), args.get('payload')) elif command == 'dxl-push-ip': result = event_sender.push_ip(args.get('ip'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-url': result = event_sender.push_url(args.get('url'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-domain': result = event_sender.push_domain(args.get('domain'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-hash': result = event_sender.push_hash(args.get('hash'), args.get('trust_level'), args.get('topic')) else: raise Exception(f'{demisto.command()} is not a command') return_outputs(result) except Exception as error: validate_certificates_format() return_error(f'error in {INTEGRATION_NAME} {str(error)}.', error) if __name__ in ('__builtin__', 'builtins'): main() <|fim▁end|>
raise ValueError(f'argument ip {ip} is not a valid IP')
<|file_name|>McAfee_DXL.py<|end_file_name|><|fim▁begin|>from typing import Dict import tempfile from dxlclient.client_config import DxlClientConfig from dxlclient.client import DxlClient from dxlclient.broker import Broker from dxlclient.message import Event import demistomock as demisto from CommonServerPython import * from CommonServerUserPython import * INTEGRATION_NAME = "McAfee DXL" CONNECT_RETRIES = 1 RECONNECT_DELAY = 1 RECONNECT_DELAY_MAX = 10 class EventSender: TRUST_LEVEL = { 'NOT_SET': '0', 'KNOWN_MALICIOUS': '1', 'MOST_LIKELY_MALICIOUS': '15', 'MIGHT_BE_MALICIOUS': '30', 'UNKNOWN': '50', 'MIGHT_BE_TRUSTED': '70', 'MOST_LIKELY_TRUSTED': '85', 'KNOWN_TRUSTED': '99', 'KNOWN_TRUSTED_INSTALLER': '100' } broker_ca_bundle = tempfile.NamedTemporaryFile().name cert_file = tempfile.NamedTemporaryFile().name private_key = tempfile.NamedTemporaryFile().name def __init__(self, params: Dict): with open(self.broker_ca_bundle, "w") as text_file: text_file.write(params['broker_ca_bundle']) with open(self.cert_file, "w") as text_file: text_file.write(params['cert_file']) with open(self.private_key, "w") as text_file: text_file.write(params['private_key']) if 'broker_urls' in params: self.broker_urls = params['broker_urls'].split(',') self.push_ip_topic = params.get('push_ip_topic') self.push_url_topic = params.get('push_url_topic') self.push_domain_topic = params.get('push_domain_topic') self.push_hash_topic = params.get('push_hash_topic') self.client = DxlClient(self.get_client_config()) self.client.connect() def __del__(self): self.client.disconnect() def push_ip(self, ip, trust_level, topic): if not is_ip_valid(ip): raise ValueError(f'argument ip {ip} is not a valid IP') trust_level_key = self.TRUST_LEVEL[trust_level] if topic: <|fim_middle|> self.send_event(self.push_ip_topic, f'ip:{ip};trust_level:{trust_level_key}') return f'Successfully pushed ip {ip} with trust level {trust_level}' def push_url(self, url, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_url_topic = topic self.send_event(self.push_url_topic, f'url:{url};trust_level:{trust_level_key}') return f'Successfully pushed url {url} with trust level {trust_level}' def push_domain(self, domain, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_domain_topic = topic self.send_event(self.push_domain_topic, f'domain:{domain};trust_level:{trust_level_key}') return f'Successfully pushed domain {domain} with trust level {trust_level}' def push_hash(self, hash_obj, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_hash_topic, f'hash:{hash_obj};trust_level:{trust_level_key}') return f'Successfully pushed hash {hash_obj} with trust level {trust_level}' def get_client_config(self): config = DxlClientConfig( broker_ca_bundle=self.broker_ca_bundle, cert_file=self.cert_file, private_key=self.private_key, brokers=[Broker.parse(url) for url in self.broker_urls] ) config.connect_retries = CONNECT_RETRIES config.reconnect_delay = RECONNECT_DELAY config.reconnect_delay_max = RECONNECT_DELAY_MAX return config def send_event(self, topic, payload): if not topic: raise Exception(f'Error in {demisto.command()} topic field is required') event = Event(topic) event.payload = str(payload).encode() self.client.send_event(event) def send_event_wrapper(self, topic, payload): self.send_event(topic, payload) return 'Successfully sent event' def validate_certificates_format(): if '-----BEGIN PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't start with -----BEGIN PRIVATE KEY-----") if '-----END PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't end with -----END PRIVATE KEY-----") if '-----BEGIN CERTIFICATE-----' not in demisto.params()['cert_file']: return_error("The client certificates content seem to be " "incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if '-----END CERTIFICATE-----' not in demisto.params()['cert_file']: return_error( "The client certificates content seem to be incorrect as it doesn't end with -----END CERTIFICATE-----") if not demisto.params()['broker_ca_bundle'].lstrip(" ").startswith('-----BEGIN CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if not demisto.params()['broker_ca_bundle'].rstrip(" ").endswith('-----END CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't end with '-----END CERTIFICATE-----'") def main(): args = demisto.args() command = demisto.command() try: event_sender = EventSender(demisto.params()) result = '' if command == 'test-module': event_sender.send_event('TEST', 'test') result = 'ok' elif command == 'dxl-send-event': result = event_sender.send_event_wrapper(args.get('topic'), args.get('payload')) elif command == 'dxl-push-ip': result = event_sender.push_ip(args.get('ip'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-url': result = event_sender.push_url(args.get('url'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-domain': result = event_sender.push_domain(args.get('domain'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-hash': result = event_sender.push_hash(args.get('hash'), args.get('trust_level'), args.get('topic')) else: raise Exception(f'{demisto.command()} is not a command') return_outputs(result) except Exception as error: validate_certificates_format() return_error(f'error in {INTEGRATION_NAME} {str(error)}.', error) if __name__ in ('__builtin__', 'builtins'): main() <|fim▁end|>
self.push_ip_topic = topic
<|file_name|>McAfee_DXL.py<|end_file_name|><|fim▁begin|>from typing import Dict import tempfile from dxlclient.client_config import DxlClientConfig from dxlclient.client import DxlClient from dxlclient.broker import Broker from dxlclient.message import Event import demistomock as demisto from CommonServerPython import * from CommonServerUserPython import * INTEGRATION_NAME = "McAfee DXL" CONNECT_RETRIES = 1 RECONNECT_DELAY = 1 RECONNECT_DELAY_MAX = 10 class EventSender: TRUST_LEVEL = { 'NOT_SET': '0', 'KNOWN_MALICIOUS': '1', 'MOST_LIKELY_MALICIOUS': '15', 'MIGHT_BE_MALICIOUS': '30', 'UNKNOWN': '50', 'MIGHT_BE_TRUSTED': '70', 'MOST_LIKELY_TRUSTED': '85', 'KNOWN_TRUSTED': '99', 'KNOWN_TRUSTED_INSTALLER': '100' } broker_ca_bundle = tempfile.NamedTemporaryFile().name cert_file = tempfile.NamedTemporaryFile().name private_key = tempfile.NamedTemporaryFile().name def __init__(self, params: Dict): with open(self.broker_ca_bundle, "w") as text_file: text_file.write(params['broker_ca_bundle']) with open(self.cert_file, "w") as text_file: text_file.write(params['cert_file']) with open(self.private_key, "w") as text_file: text_file.write(params['private_key']) if 'broker_urls' in params: self.broker_urls = params['broker_urls'].split(',') self.push_ip_topic = params.get('push_ip_topic') self.push_url_topic = params.get('push_url_topic') self.push_domain_topic = params.get('push_domain_topic') self.push_hash_topic = params.get('push_hash_topic') self.client = DxlClient(self.get_client_config()) self.client.connect() def __del__(self): self.client.disconnect() def push_ip(self, ip, trust_level, topic): if not is_ip_valid(ip): raise ValueError(f'argument ip {ip} is not a valid IP') trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_ip_topic, f'ip:{ip};trust_level:{trust_level_key}') return f'Successfully pushed ip {ip} with trust level {trust_level}' def push_url(self, url, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: <|fim_middle|> self.send_event(self.push_url_topic, f'url:{url};trust_level:{trust_level_key}') return f'Successfully pushed url {url} with trust level {trust_level}' def push_domain(self, domain, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_domain_topic = topic self.send_event(self.push_domain_topic, f'domain:{domain};trust_level:{trust_level_key}') return f'Successfully pushed domain {domain} with trust level {trust_level}' def push_hash(self, hash_obj, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_hash_topic, f'hash:{hash_obj};trust_level:{trust_level_key}') return f'Successfully pushed hash {hash_obj} with trust level {trust_level}' def get_client_config(self): config = DxlClientConfig( broker_ca_bundle=self.broker_ca_bundle, cert_file=self.cert_file, private_key=self.private_key, brokers=[Broker.parse(url) for url in self.broker_urls] ) config.connect_retries = CONNECT_RETRIES config.reconnect_delay = RECONNECT_DELAY config.reconnect_delay_max = RECONNECT_DELAY_MAX return config def send_event(self, topic, payload): if not topic: raise Exception(f'Error in {demisto.command()} topic field is required') event = Event(topic) event.payload = str(payload).encode() self.client.send_event(event) def send_event_wrapper(self, topic, payload): self.send_event(topic, payload) return 'Successfully sent event' def validate_certificates_format(): if '-----BEGIN PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't start with -----BEGIN PRIVATE KEY-----") if '-----END PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't end with -----END PRIVATE KEY-----") if '-----BEGIN CERTIFICATE-----' not in demisto.params()['cert_file']: return_error("The client certificates content seem to be " "incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if '-----END CERTIFICATE-----' not in demisto.params()['cert_file']: return_error( "The client certificates content seem to be incorrect as it doesn't end with -----END CERTIFICATE-----") if not demisto.params()['broker_ca_bundle'].lstrip(" ").startswith('-----BEGIN CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if not demisto.params()['broker_ca_bundle'].rstrip(" ").endswith('-----END CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't end with '-----END CERTIFICATE-----'") def main(): args = demisto.args() command = demisto.command() try: event_sender = EventSender(demisto.params()) result = '' if command == 'test-module': event_sender.send_event('TEST', 'test') result = 'ok' elif command == 'dxl-send-event': result = event_sender.send_event_wrapper(args.get('topic'), args.get('payload')) elif command == 'dxl-push-ip': result = event_sender.push_ip(args.get('ip'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-url': result = event_sender.push_url(args.get('url'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-domain': result = event_sender.push_domain(args.get('domain'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-hash': result = event_sender.push_hash(args.get('hash'), args.get('trust_level'), args.get('topic')) else: raise Exception(f'{demisto.command()} is not a command') return_outputs(result) except Exception as error: validate_certificates_format() return_error(f'error in {INTEGRATION_NAME} {str(error)}.', error) if __name__ in ('__builtin__', 'builtins'): main() <|fim▁end|>
self.push_url_topic = topic
<|file_name|>McAfee_DXL.py<|end_file_name|><|fim▁begin|>from typing import Dict import tempfile from dxlclient.client_config import DxlClientConfig from dxlclient.client import DxlClient from dxlclient.broker import Broker from dxlclient.message import Event import demistomock as demisto from CommonServerPython import * from CommonServerUserPython import * INTEGRATION_NAME = "McAfee DXL" CONNECT_RETRIES = 1 RECONNECT_DELAY = 1 RECONNECT_DELAY_MAX = 10 class EventSender: TRUST_LEVEL = { 'NOT_SET': '0', 'KNOWN_MALICIOUS': '1', 'MOST_LIKELY_MALICIOUS': '15', 'MIGHT_BE_MALICIOUS': '30', 'UNKNOWN': '50', 'MIGHT_BE_TRUSTED': '70', 'MOST_LIKELY_TRUSTED': '85', 'KNOWN_TRUSTED': '99', 'KNOWN_TRUSTED_INSTALLER': '100' } broker_ca_bundle = tempfile.NamedTemporaryFile().name cert_file = tempfile.NamedTemporaryFile().name private_key = tempfile.NamedTemporaryFile().name def __init__(self, params: Dict): with open(self.broker_ca_bundle, "w") as text_file: text_file.write(params['broker_ca_bundle']) with open(self.cert_file, "w") as text_file: text_file.write(params['cert_file']) with open(self.private_key, "w") as text_file: text_file.write(params['private_key']) if 'broker_urls' in params: self.broker_urls = params['broker_urls'].split(',') self.push_ip_topic = params.get('push_ip_topic') self.push_url_topic = params.get('push_url_topic') self.push_domain_topic = params.get('push_domain_topic') self.push_hash_topic = params.get('push_hash_topic') self.client = DxlClient(self.get_client_config()) self.client.connect() def __del__(self): self.client.disconnect() def push_ip(self, ip, trust_level, topic): if not is_ip_valid(ip): raise ValueError(f'argument ip {ip} is not a valid IP') trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_ip_topic, f'ip:{ip};trust_level:{trust_level_key}') return f'Successfully pushed ip {ip} with trust level {trust_level}' def push_url(self, url, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_url_topic = topic self.send_event(self.push_url_topic, f'url:{url};trust_level:{trust_level_key}') return f'Successfully pushed url {url} with trust level {trust_level}' def push_domain(self, domain, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: <|fim_middle|> self.send_event(self.push_domain_topic, f'domain:{domain};trust_level:{trust_level_key}') return f'Successfully pushed domain {domain} with trust level {trust_level}' def push_hash(self, hash_obj, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_hash_topic, f'hash:{hash_obj};trust_level:{trust_level_key}') return f'Successfully pushed hash {hash_obj} with trust level {trust_level}' def get_client_config(self): config = DxlClientConfig( broker_ca_bundle=self.broker_ca_bundle, cert_file=self.cert_file, private_key=self.private_key, brokers=[Broker.parse(url) for url in self.broker_urls] ) config.connect_retries = CONNECT_RETRIES config.reconnect_delay = RECONNECT_DELAY config.reconnect_delay_max = RECONNECT_DELAY_MAX return config def send_event(self, topic, payload): if not topic: raise Exception(f'Error in {demisto.command()} topic field is required') event = Event(topic) event.payload = str(payload).encode() self.client.send_event(event) def send_event_wrapper(self, topic, payload): self.send_event(topic, payload) return 'Successfully sent event' def validate_certificates_format(): if '-----BEGIN PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't start with -----BEGIN PRIVATE KEY-----") if '-----END PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't end with -----END PRIVATE KEY-----") if '-----BEGIN CERTIFICATE-----' not in demisto.params()['cert_file']: return_error("The client certificates content seem to be " "incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if '-----END CERTIFICATE-----' not in demisto.params()['cert_file']: return_error( "The client certificates content seem to be incorrect as it doesn't end with -----END CERTIFICATE-----") if not demisto.params()['broker_ca_bundle'].lstrip(" ").startswith('-----BEGIN CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if not demisto.params()['broker_ca_bundle'].rstrip(" ").endswith('-----END CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't end with '-----END CERTIFICATE-----'") def main(): args = demisto.args() command = demisto.command() try: event_sender = EventSender(demisto.params()) result = '' if command == 'test-module': event_sender.send_event('TEST', 'test') result = 'ok' elif command == 'dxl-send-event': result = event_sender.send_event_wrapper(args.get('topic'), args.get('payload')) elif command == 'dxl-push-ip': result = event_sender.push_ip(args.get('ip'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-url': result = event_sender.push_url(args.get('url'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-domain': result = event_sender.push_domain(args.get('domain'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-hash': result = event_sender.push_hash(args.get('hash'), args.get('trust_level'), args.get('topic')) else: raise Exception(f'{demisto.command()} is not a command') return_outputs(result) except Exception as error: validate_certificates_format() return_error(f'error in {INTEGRATION_NAME} {str(error)}.', error) if __name__ in ('__builtin__', 'builtins'): main() <|fim▁end|>
self.push_domain_topic = topic
<|file_name|>McAfee_DXL.py<|end_file_name|><|fim▁begin|>from typing import Dict import tempfile from dxlclient.client_config import DxlClientConfig from dxlclient.client import DxlClient from dxlclient.broker import Broker from dxlclient.message import Event import demistomock as demisto from CommonServerPython import * from CommonServerUserPython import * INTEGRATION_NAME = "McAfee DXL" CONNECT_RETRIES = 1 RECONNECT_DELAY = 1 RECONNECT_DELAY_MAX = 10 class EventSender: TRUST_LEVEL = { 'NOT_SET': '0', 'KNOWN_MALICIOUS': '1', 'MOST_LIKELY_MALICIOUS': '15', 'MIGHT_BE_MALICIOUS': '30', 'UNKNOWN': '50', 'MIGHT_BE_TRUSTED': '70', 'MOST_LIKELY_TRUSTED': '85', 'KNOWN_TRUSTED': '99', 'KNOWN_TRUSTED_INSTALLER': '100' } broker_ca_bundle = tempfile.NamedTemporaryFile().name cert_file = tempfile.NamedTemporaryFile().name private_key = tempfile.NamedTemporaryFile().name def __init__(self, params: Dict): with open(self.broker_ca_bundle, "w") as text_file: text_file.write(params['broker_ca_bundle']) with open(self.cert_file, "w") as text_file: text_file.write(params['cert_file']) with open(self.private_key, "w") as text_file: text_file.write(params['private_key']) if 'broker_urls' in params: self.broker_urls = params['broker_urls'].split(',') self.push_ip_topic = params.get('push_ip_topic') self.push_url_topic = params.get('push_url_topic') self.push_domain_topic = params.get('push_domain_topic') self.push_hash_topic = params.get('push_hash_topic') self.client = DxlClient(self.get_client_config()) self.client.connect() def __del__(self): self.client.disconnect() def push_ip(self, ip, trust_level, topic): if not is_ip_valid(ip): raise ValueError(f'argument ip {ip} is not a valid IP') trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_ip_topic, f'ip:{ip};trust_level:{trust_level_key}') return f'Successfully pushed ip {ip} with trust level {trust_level}' def push_url(self, url, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_url_topic = topic self.send_event(self.push_url_topic, f'url:{url};trust_level:{trust_level_key}') return f'Successfully pushed url {url} with trust level {trust_level}' def push_domain(self, domain, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_domain_topic = topic self.send_event(self.push_domain_topic, f'domain:{domain};trust_level:{trust_level_key}') return f'Successfully pushed domain {domain} with trust level {trust_level}' def push_hash(self, hash_obj, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: <|fim_middle|> self.send_event(self.push_hash_topic, f'hash:{hash_obj};trust_level:{trust_level_key}') return f'Successfully pushed hash {hash_obj} with trust level {trust_level}' def get_client_config(self): config = DxlClientConfig( broker_ca_bundle=self.broker_ca_bundle, cert_file=self.cert_file, private_key=self.private_key, brokers=[Broker.parse(url) for url in self.broker_urls] ) config.connect_retries = CONNECT_RETRIES config.reconnect_delay = RECONNECT_DELAY config.reconnect_delay_max = RECONNECT_DELAY_MAX return config def send_event(self, topic, payload): if not topic: raise Exception(f'Error in {demisto.command()} topic field is required') event = Event(topic) event.payload = str(payload).encode() self.client.send_event(event) def send_event_wrapper(self, topic, payload): self.send_event(topic, payload) return 'Successfully sent event' def validate_certificates_format(): if '-----BEGIN PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't start with -----BEGIN PRIVATE KEY-----") if '-----END PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't end with -----END PRIVATE KEY-----") if '-----BEGIN CERTIFICATE-----' not in demisto.params()['cert_file']: return_error("The client certificates content seem to be " "incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if '-----END CERTIFICATE-----' not in demisto.params()['cert_file']: return_error( "The client certificates content seem to be incorrect as it doesn't end with -----END CERTIFICATE-----") if not demisto.params()['broker_ca_bundle'].lstrip(" ").startswith('-----BEGIN CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if not demisto.params()['broker_ca_bundle'].rstrip(" ").endswith('-----END CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't end with '-----END CERTIFICATE-----'") def main(): args = demisto.args() command = demisto.command() try: event_sender = EventSender(demisto.params()) result = '' if command == 'test-module': event_sender.send_event('TEST', 'test') result = 'ok' elif command == 'dxl-send-event': result = event_sender.send_event_wrapper(args.get('topic'), args.get('payload')) elif command == 'dxl-push-ip': result = event_sender.push_ip(args.get('ip'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-url': result = event_sender.push_url(args.get('url'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-domain': result = event_sender.push_domain(args.get('domain'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-hash': result = event_sender.push_hash(args.get('hash'), args.get('trust_level'), args.get('topic')) else: raise Exception(f'{demisto.command()} is not a command') return_outputs(result) except Exception as error: validate_certificates_format() return_error(f'error in {INTEGRATION_NAME} {str(error)}.', error) if __name__ in ('__builtin__', 'builtins'): main() <|fim▁end|>
self.push_ip_topic = topic
<|file_name|>McAfee_DXL.py<|end_file_name|><|fim▁begin|>from typing import Dict import tempfile from dxlclient.client_config import DxlClientConfig from dxlclient.client import DxlClient from dxlclient.broker import Broker from dxlclient.message import Event import demistomock as demisto from CommonServerPython import * from CommonServerUserPython import * INTEGRATION_NAME = "McAfee DXL" CONNECT_RETRIES = 1 RECONNECT_DELAY = 1 RECONNECT_DELAY_MAX = 10 class EventSender: TRUST_LEVEL = { 'NOT_SET': '0', 'KNOWN_MALICIOUS': '1', 'MOST_LIKELY_MALICIOUS': '15', 'MIGHT_BE_MALICIOUS': '30', 'UNKNOWN': '50', 'MIGHT_BE_TRUSTED': '70', 'MOST_LIKELY_TRUSTED': '85', 'KNOWN_TRUSTED': '99', 'KNOWN_TRUSTED_INSTALLER': '100' } broker_ca_bundle = tempfile.NamedTemporaryFile().name cert_file = tempfile.NamedTemporaryFile().name private_key = tempfile.NamedTemporaryFile().name def __init__(self, params: Dict): with open(self.broker_ca_bundle, "w") as text_file: text_file.write(params['broker_ca_bundle']) with open(self.cert_file, "w") as text_file: text_file.write(params['cert_file']) with open(self.private_key, "w") as text_file: text_file.write(params['private_key']) if 'broker_urls' in params: self.broker_urls = params['broker_urls'].split(',') self.push_ip_topic = params.get('push_ip_topic') self.push_url_topic = params.get('push_url_topic') self.push_domain_topic = params.get('push_domain_topic') self.push_hash_topic = params.get('push_hash_topic') self.client = DxlClient(self.get_client_config()) self.client.connect() def __del__(self): self.client.disconnect() def push_ip(self, ip, trust_level, topic): if not is_ip_valid(ip): raise ValueError(f'argument ip {ip} is not a valid IP') trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_ip_topic, f'ip:{ip};trust_level:{trust_level_key}') return f'Successfully pushed ip {ip} with trust level {trust_level}' def push_url(self, url, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_url_topic = topic self.send_event(self.push_url_topic, f'url:{url};trust_level:{trust_level_key}') return f'Successfully pushed url {url} with trust level {trust_level}' def push_domain(self, domain, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_domain_topic = topic self.send_event(self.push_domain_topic, f'domain:{domain};trust_level:{trust_level_key}') return f'Successfully pushed domain {domain} with trust level {trust_level}' def push_hash(self, hash_obj, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_hash_topic, f'hash:{hash_obj};trust_level:{trust_level_key}') return f'Successfully pushed hash {hash_obj} with trust level {trust_level}' def get_client_config(self): config = DxlClientConfig( broker_ca_bundle=self.broker_ca_bundle, cert_file=self.cert_file, private_key=self.private_key, brokers=[Broker.parse(url) for url in self.broker_urls] ) config.connect_retries = CONNECT_RETRIES config.reconnect_delay = RECONNECT_DELAY config.reconnect_delay_max = RECONNECT_DELAY_MAX return config def send_event(self, topic, payload): if not topic: <|fim_middle|> event = Event(topic) event.payload = str(payload).encode() self.client.send_event(event) def send_event_wrapper(self, topic, payload): self.send_event(topic, payload) return 'Successfully sent event' def validate_certificates_format(): if '-----BEGIN PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't start with -----BEGIN PRIVATE KEY-----") if '-----END PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't end with -----END PRIVATE KEY-----") if '-----BEGIN CERTIFICATE-----' not in demisto.params()['cert_file']: return_error("The client certificates content seem to be " "incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if '-----END CERTIFICATE-----' not in demisto.params()['cert_file']: return_error( "The client certificates content seem to be incorrect as it doesn't end with -----END CERTIFICATE-----") if not demisto.params()['broker_ca_bundle'].lstrip(" ").startswith('-----BEGIN CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if not demisto.params()['broker_ca_bundle'].rstrip(" ").endswith('-----END CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't end with '-----END CERTIFICATE-----'") def main(): args = demisto.args() command = demisto.command() try: event_sender = EventSender(demisto.params()) result = '' if command == 'test-module': event_sender.send_event('TEST', 'test') result = 'ok' elif command == 'dxl-send-event': result = event_sender.send_event_wrapper(args.get('topic'), args.get('payload')) elif command == 'dxl-push-ip': result = event_sender.push_ip(args.get('ip'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-url': result = event_sender.push_url(args.get('url'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-domain': result = event_sender.push_domain(args.get('domain'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-hash': result = event_sender.push_hash(args.get('hash'), args.get('trust_level'), args.get('topic')) else: raise Exception(f'{demisto.command()} is not a command') return_outputs(result) except Exception as error: validate_certificates_format() return_error(f'error in {INTEGRATION_NAME} {str(error)}.', error) if __name__ in ('__builtin__', 'builtins'): main() <|fim▁end|>
raise Exception(f'Error in {demisto.command()} topic field is required')
<|file_name|>McAfee_DXL.py<|end_file_name|><|fim▁begin|>from typing import Dict import tempfile from dxlclient.client_config import DxlClientConfig from dxlclient.client import DxlClient from dxlclient.broker import Broker from dxlclient.message import Event import demistomock as demisto from CommonServerPython import * from CommonServerUserPython import * INTEGRATION_NAME = "McAfee DXL" CONNECT_RETRIES = 1 RECONNECT_DELAY = 1 RECONNECT_DELAY_MAX = 10 class EventSender: TRUST_LEVEL = { 'NOT_SET': '0', 'KNOWN_MALICIOUS': '1', 'MOST_LIKELY_MALICIOUS': '15', 'MIGHT_BE_MALICIOUS': '30', 'UNKNOWN': '50', 'MIGHT_BE_TRUSTED': '70', 'MOST_LIKELY_TRUSTED': '85', 'KNOWN_TRUSTED': '99', 'KNOWN_TRUSTED_INSTALLER': '100' } broker_ca_bundle = tempfile.NamedTemporaryFile().name cert_file = tempfile.NamedTemporaryFile().name private_key = tempfile.NamedTemporaryFile().name def __init__(self, params: Dict): with open(self.broker_ca_bundle, "w") as text_file: text_file.write(params['broker_ca_bundle']) with open(self.cert_file, "w") as text_file: text_file.write(params['cert_file']) with open(self.private_key, "w") as text_file: text_file.write(params['private_key']) if 'broker_urls' in params: self.broker_urls = params['broker_urls'].split(',') self.push_ip_topic = params.get('push_ip_topic') self.push_url_topic = params.get('push_url_topic') self.push_domain_topic = params.get('push_domain_topic') self.push_hash_topic = params.get('push_hash_topic') self.client = DxlClient(self.get_client_config()) self.client.connect() def __del__(self): self.client.disconnect() def push_ip(self, ip, trust_level, topic): if not is_ip_valid(ip): raise ValueError(f'argument ip {ip} is not a valid IP') trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_ip_topic, f'ip:{ip};trust_level:{trust_level_key}') return f'Successfully pushed ip {ip} with trust level {trust_level}' def push_url(self, url, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_url_topic = topic self.send_event(self.push_url_topic, f'url:{url};trust_level:{trust_level_key}') return f'Successfully pushed url {url} with trust level {trust_level}' def push_domain(self, domain, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_domain_topic = topic self.send_event(self.push_domain_topic, f'domain:{domain};trust_level:{trust_level_key}') return f'Successfully pushed domain {domain} with trust level {trust_level}' def push_hash(self, hash_obj, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_hash_topic, f'hash:{hash_obj};trust_level:{trust_level_key}') return f'Successfully pushed hash {hash_obj} with trust level {trust_level}' def get_client_config(self): config = DxlClientConfig( broker_ca_bundle=self.broker_ca_bundle, cert_file=self.cert_file, private_key=self.private_key, brokers=[Broker.parse(url) for url in self.broker_urls] ) config.connect_retries = CONNECT_RETRIES config.reconnect_delay = RECONNECT_DELAY config.reconnect_delay_max = RECONNECT_DELAY_MAX return config def send_event(self, topic, payload): if not topic: raise Exception(f'Error in {demisto.command()} topic field is required') event = Event(topic) event.payload = str(payload).encode() self.client.send_event(event) def send_event_wrapper(self, topic, payload): self.send_event(topic, payload) return 'Successfully sent event' def validate_certificates_format(): if '-----BEGIN PRIVATE KEY-----' not in demisto.params()['private_key']: <|fim_middle|> if '-----END PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't end with -----END PRIVATE KEY-----") if '-----BEGIN CERTIFICATE-----' not in demisto.params()['cert_file']: return_error("The client certificates content seem to be " "incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if '-----END CERTIFICATE-----' not in demisto.params()['cert_file']: return_error( "The client certificates content seem to be incorrect as it doesn't end with -----END CERTIFICATE-----") if not demisto.params()['broker_ca_bundle'].lstrip(" ").startswith('-----BEGIN CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if not demisto.params()['broker_ca_bundle'].rstrip(" ").endswith('-----END CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't end with '-----END CERTIFICATE-----'") def main(): args = demisto.args() command = demisto.command() try: event_sender = EventSender(demisto.params()) result = '' if command == 'test-module': event_sender.send_event('TEST', 'test') result = 'ok' elif command == 'dxl-send-event': result = event_sender.send_event_wrapper(args.get('topic'), args.get('payload')) elif command == 'dxl-push-ip': result = event_sender.push_ip(args.get('ip'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-url': result = event_sender.push_url(args.get('url'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-domain': result = event_sender.push_domain(args.get('domain'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-hash': result = event_sender.push_hash(args.get('hash'), args.get('trust_level'), args.get('topic')) else: raise Exception(f'{demisto.command()} is not a command') return_outputs(result) except Exception as error: validate_certificates_format() return_error(f'error in {INTEGRATION_NAME} {str(error)}.', error) if __name__ in ('__builtin__', 'builtins'): main() <|fim▁end|>
return_error( "The private key content seems to be incorrect as it doesn't start with -----BEGIN PRIVATE KEY-----")
<|file_name|>McAfee_DXL.py<|end_file_name|><|fim▁begin|>from typing import Dict import tempfile from dxlclient.client_config import DxlClientConfig from dxlclient.client import DxlClient from dxlclient.broker import Broker from dxlclient.message import Event import demistomock as demisto from CommonServerPython import * from CommonServerUserPython import * INTEGRATION_NAME = "McAfee DXL" CONNECT_RETRIES = 1 RECONNECT_DELAY = 1 RECONNECT_DELAY_MAX = 10 class EventSender: TRUST_LEVEL = { 'NOT_SET': '0', 'KNOWN_MALICIOUS': '1', 'MOST_LIKELY_MALICIOUS': '15', 'MIGHT_BE_MALICIOUS': '30', 'UNKNOWN': '50', 'MIGHT_BE_TRUSTED': '70', 'MOST_LIKELY_TRUSTED': '85', 'KNOWN_TRUSTED': '99', 'KNOWN_TRUSTED_INSTALLER': '100' } broker_ca_bundle = tempfile.NamedTemporaryFile().name cert_file = tempfile.NamedTemporaryFile().name private_key = tempfile.NamedTemporaryFile().name def __init__(self, params: Dict): with open(self.broker_ca_bundle, "w") as text_file: text_file.write(params['broker_ca_bundle']) with open(self.cert_file, "w") as text_file: text_file.write(params['cert_file']) with open(self.private_key, "w") as text_file: text_file.write(params['private_key']) if 'broker_urls' in params: self.broker_urls = params['broker_urls'].split(',') self.push_ip_topic = params.get('push_ip_topic') self.push_url_topic = params.get('push_url_topic') self.push_domain_topic = params.get('push_domain_topic') self.push_hash_topic = params.get('push_hash_topic') self.client = DxlClient(self.get_client_config()) self.client.connect() def __del__(self): self.client.disconnect() def push_ip(self, ip, trust_level, topic): if not is_ip_valid(ip): raise ValueError(f'argument ip {ip} is not a valid IP') trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_ip_topic, f'ip:{ip};trust_level:{trust_level_key}') return f'Successfully pushed ip {ip} with trust level {trust_level}' def push_url(self, url, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_url_topic = topic self.send_event(self.push_url_topic, f'url:{url};trust_level:{trust_level_key}') return f'Successfully pushed url {url} with trust level {trust_level}' def push_domain(self, domain, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_domain_topic = topic self.send_event(self.push_domain_topic, f'domain:{domain};trust_level:{trust_level_key}') return f'Successfully pushed domain {domain} with trust level {trust_level}' def push_hash(self, hash_obj, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_hash_topic, f'hash:{hash_obj};trust_level:{trust_level_key}') return f'Successfully pushed hash {hash_obj} with trust level {trust_level}' def get_client_config(self): config = DxlClientConfig( broker_ca_bundle=self.broker_ca_bundle, cert_file=self.cert_file, private_key=self.private_key, brokers=[Broker.parse(url) for url in self.broker_urls] ) config.connect_retries = CONNECT_RETRIES config.reconnect_delay = RECONNECT_DELAY config.reconnect_delay_max = RECONNECT_DELAY_MAX return config def send_event(self, topic, payload): if not topic: raise Exception(f'Error in {demisto.command()} topic field is required') event = Event(topic) event.payload = str(payload).encode() self.client.send_event(event) def send_event_wrapper(self, topic, payload): self.send_event(topic, payload) return 'Successfully sent event' def validate_certificates_format(): if '-----BEGIN PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't start with -----BEGIN PRIVATE KEY-----") if '-----END PRIVATE KEY-----' not in demisto.params()['private_key']: <|fim_middle|> if '-----BEGIN CERTIFICATE-----' not in demisto.params()['cert_file']: return_error("The client certificates content seem to be " "incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if '-----END CERTIFICATE-----' not in demisto.params()['cert_file']: return_error( "The client certificates content seem to be incorrect as it doesn't end with -----END CERTIFICATE-----") if not demisto.params()['broker_ca_bundle'].lstrip(" ").startswith('-----BEGIN CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if not demisto.params()['broker_ca_bundle'].rstrip(" ").endswith('-----END CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't end with '-----END CERTIFICATE-----'") def main(): args = demisto.args() command = demisto.command() try: event_sender = EventSender(demisto.params()) result = '' if command == 'test-module': event_sender.send_event('TEST', 'test') result = 'ok' elif command == 'dxl-send-event': result = event_sender.send_event_wrapper(args.get('topic'), args.get('payload')) elif command == 'dxl-push-ip': result = event_sender.push_ip(args.get('ip'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-url': result = event_sender.push_url(args.get('url'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-domain': result = event_sender.push_domain(args.get('domain'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-hash': result = event_sender.push_hash(args.get('hash'), args.get('trust_level'), args.get('topic')) else: raise Exception(f'{demisto.command()} is not a command') return_outputs(result) except Exception as error: validate_certificates_format() return_error(f'error in {INTEGRATION_NAME} {str(error)}.', error) if __name__ in ('__builtin__', 'builtins'): main() <|fim▁end|>
return_error( "The private key content seems to be incorrect as it doesn't end with -----END PRIVATE KEY-----")
<|file_name|>McAfee_DXL.py<|end_file_name|><|fim▁begin|>from typing import Dict import tempfile from dxlclient.client_config import DxlClientConfig from dxlclient.client import DxlClient from dxlclient.broker import Broker from dxlclient.message import Event import demistomock as demisto from CommonServerPython import * from CommonServerUserPython import * INTEGRATION_NAME = "McAfee DXL" CONNECT_RETRIES = 1 RECONNECT_DELAY = 1 RECONNECT_DELAY_MAX = 10 class EventSender: TRUST_LEVEL = { 'NOT_SET': '0', 'KNOWN_MALICIOUS': '1', 'MOST_LIKELY_MALICIOUS': '15', 'MIGHT_BE_MALICIOUS': '30', 'UNKNOWN': '50', 'MIGHT_BE_TRUSTED': '70', 'MOST_LIKELY_TRUSTED': '85', 'KNOWN_TRUSTED': '99', 'KNOWN_TRUSTED_INSTALLER': '100' } broker_ca_bundle = tempfile.NamedTemporaryFile().name cert_file = tempfile.NamedTemporaryFile().name private_key = tempfile.NamedTemporaryFile().name def __init__(self, params: Dict): with open(self.broker_ca_bundle, "w") as text_file: text_file.write(params['broker_ca_bundle']) with open(self.cert_file, "w") as text_file: text_file.write(params['cert_file']) with open(self.private_key, "w") as text_file: text_file.write(params['private_key']) if 'broker_urls' in params: self.broker_urls = params['broker_urls'].split(',') self.push_ip_topic = params.get('push_ip_topic') self.push_url_topic = params.get('push_url_topic') self.push_domain_topic = params.get('push_domain_topic') self.push_hash_topic = params.get('push_hash_topic') self.client = DxlClient(self.get_client_config()) self.client.connect() def __del__(self): self.client.disconnect() def push_ip(self, ip, trust_level, topic): if not is_ip_valid(ip): raise ValueError(f'argument ip {ip} is not a valid IP') trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_ip_topic, f'ip:{ip};trust_level:{trust_level_key}') return f'Successfully pushed ip {ip} with trust level {trust_level}' def push_url(self, url, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_url_topic = topic self.send_event(self.push_url_topic, f'url:{url};trust_level:{trust_level_key}') return f'Successfully pushed url {url} with trust level {trust_level}' def push_domain(self, domain, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_domain_topic = topic self.send_event(self.push_domain_topic, f'domain:{domain};trust_level:{trust_level_key}') return f'Successfully pushed domain {domain} with trust level {trust_level}' def push_hash(self, hash_obj, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_hash_topic, f'hash:{hash_obj};trust_level:{trust_level_key}') return f'Successfully pushed hash {hash_obj} with trust level {trust_level}' def get_client_config(self): config = DxlClientConfig( broker_ca_bundle=self.broker_ca_bundle, cert_file=self.cert_file, private_key=self.private_key, brokers=[Broker.parse(url) for url in self.broker_urls] ) config.connect_retries = CONNECT_RETRIES config.reconnect_delay = RECONNECT_DELAY config.reconnect_delay_max = RECONNECT_DELAY_MAX return config def send_event(self, topic, payload): if not topic: raise Exception(f'Error in {demisto.command()} topic field is required') event = Event(topic) event.payload = str(payload).encode() self.client.send_event(event) def send_event_wrapper(self, topic, payload): self.send_event(topic, payload) return 'Successfully sent event' def validate_certificates_format(): if '-----BEGIN PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't start with -----BEGIN PRIVATE KEY-----") if '-----END PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't end with -----END PRIVATE KEY-----") if '-----BEGIN CERTIFICATE-----' not in demisto.params()['cert_file']: <|fim_middle|> if '-----END CERTIFICATE-----' not in demisto.params()['cert_file']: return_error( "The client certificates content seem to be incorrect as it doesn't end with -----END CERTIFICATE-----") if not demisto.params()['broker_ca_bundle'].lstrip(" ").startswith('-----BEGIN CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if not demisto.params()['broker_ca_bundle'].rstrip(" ").endswith('-----END CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't end with '-----END CERTIFICATE-----'") def main(): args = demisto.args() command = demisto.command() try: event_sender = EventSender(demisto.params()) result = '' if command == 'test-module': event_sender.send_event('TEST', 'test') result = 'ok' elif command == 'dxl-send-event': result = event_sender.send_event_wrapper(args.get('topic'), args.get('payload')) elif command == 'dxl-push-ip': result = event_sender.push_ip(args.get('ip'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-url': result = event_sender.push_url(args.get('url'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-domain': result = event_sender.push_domain(args.get('domain'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-hash': result = event_sender.push_hash(args.get('hash'), args.get('trust_level'), args.get('topic')) else: raise Exception(f'{demisto.command()} is not a command') return_outputs(result) except Exception as error: validate_certificates_format() return_error(f'error in {INTEGRATION_NAME} {str(error)}.', error) if __name__ in ('__builtin__', 'builtins'): main() <|fim▁end|>
return_error("The client certificates content seem to be " "incorrect as they don't start with '-----BEGIN CERTIFICATE-----'")
<|file_name|>McAfee_DXL.py<|end_file_name|><|fim▁begin|>from typing import Dict import tempfile from dxlclient.client_config import DxlClientConfig from dxlclient.client import DxlClient from dxlclient.broker import Broker from dxlclient.message import Event import demistomock as demisto from CommonServerPython import * from CommonServerUserPython import * INTEGRATION_NAME = "McAfee DXL" CONNECT_RETRIES = 1 RECONNECT_DELAY = 1 RECONNECT_DELAY_MAX = 10 class EventSender: TRUST_LEVEL = { 'NOT_SET': '0', 'KNOWN_MALICIOUS': '1', 'MOST_LIKELY_MALICIOUS': '15', 'MIGHT_BE_MALICIOUS': '30', 'UNKNOWN': '50', 'MIGHT_BE_TRUSTED': '70', 'MOST_LIKELY_TRUSTED': '85', 'KNOWN_TRUSTED': '99', 'KNOWN_TRUSTED_INSTALLER': '100' } broker_ca_bundle = tempfile.NamedTemporaryFile().name cert_file = tempfile.NamedTemporaryFile().name private_key = tempfile.NamedTemporaryFile().name def __init__(self, params: Dict): with open(self.broker_ca_bundle, "w") as text_file: text_file.write(params['broker_ca_bundle']) with open(self.cert_file, "w") as text_file: text_file.write(params['cert_file']) with open(self.private_key, "w") as text_file: text_file.write(params['private_key']) if 'broker_urls' in params: self.broker_urls = params['broker_urls'].split(',') self.push_ip_topic = params.get('push_ip_topic') self.push_url_topic = params.get('push_url_topic') self.push_domain_topic = params.get('push_domain_topic') self.push_hash_topic = params.get('push_hash_topic') self.client = DxlClient(self.get_client_config()) self.client.connect() def __del__(self): self.client.disconnect() def push_ip(self, ip, trust_level, topic): if not is_ip_valid(ip): raise ValueError(f'argument ip {ip} is not a valid IP') trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_ip_topic, f'ip:{ip};trust_level:{trust_level_key}') return f'Successfully pushed ip {ip} with trust level {trust_level}' def push_url(self, url, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_url_topic = topic self.send_event(self.push_url_topic, f'url:{url};trust_level:{trust_level_key}') return f'Successfully pushed url {url} with trust level {trust_level}' def push_domain(self, domain, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_domain_topic = topic self.send_event(self.push_domain_topic, f'domain:{domain};trust_level:{trust_level_key}') return f'Successfully pushed domain {domain} with trust level {trust_level}' def push_hash(self, hash_obj, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_hash_topic, f'hash:{hash_obj};trust_level:{trust_level_key}') return f'Successfully pushed hash {hash_obj} with trust level {trust_level}' def get_client_config(self): config = DxlClientConfig( broker_ca_bundle=self.broker_ca_bundle, cert_file=self.cert_file, private_key=self.private_key, brokers=[Broker.parse(url) for url in self.broker_urls] ) config.connect_retries = CONNECT_RETRIES config.reconnect_delay = RECONNECT_DELAY config.reconnect_delay_max = RECONNECT_DELAY_MAX return config def send_event(self, topic, payload): if not topic: raise Exception(f'Error in {demisto.command()} topic field is required') event = Event(topic) event.payload = str(payload).encode() self.client.send_event(event) def send_event_wrapper(self, topic, payload): self.send_event(topic, payload) return 'Successfully sent event' def validate_certificates_format(): if '-----BEGIN PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't start with -----BEGIN PRIVATE KEY-----") if '-----END PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't end with -----END PRIVATE KEY-----") if '-----BEGIN CERTIFICATE-----' not in demisto.params()['cert_file']: return_error("The client certificates content seem to be " "incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if '-----END CERTIFICATE-----' not in demisto.params()['cert_file']: <|fim_middle|> if not demisto.params()['broker_ca_bundle'].lstrip(" ").startswith('-----BEGIN CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if not demisto.params()['broker_ca_bundle'].rstrip(" ").endswith('-----END CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't end with '-----END CERTIFICATE-----'") def main(): args = demisto.args() command = demisto.command() try: event_sender = EventSender(demisto.params()) result = '' if command == 'test-module': event_sender.send_event('TEST', 'test') result = 'ok' elif command == 'dxl-send-event': result = event_sender.send_event_wrapper(args.get('topic'), args.get('payload')) elif command == 'dxl-push-ip': result = event_sender.push_ip(args.get('ip'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-url': result = event_sender.push_url(args.get('url'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-domain': result = event_sender.push_domain(args.get('domain'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-hash': result = event_sender.push_hash(args.get('hash'), args.get('trust_level'), args.get('topic')) else: raise Exception(f'{demisto.command()} is not a command') return_outputs(result) except Exception as error: validate_certificates_format() return_error(f'error in {INTEGRATION_NAME} {str(error)}.', error) if __name__ in ('__builtin__', 'builtins'): main() <|fim▁end|>
return_error( "The client certificates content seem to be incorrect as it doesn't end with -----END CERTIFICATE-----")
<|file_name|>McAfee_DXL.py<|end_file_name|><|fim▁begin|>from typing import Dict import tempfile from dxlclient.client_config import DxlClientConfig from dxlclient.client import DxlClient from dxlclient.broker import Broker from dxlclient.message import Event import demistomock as demisto from CommonServerPython import * from CommonServerUserPython import * INTEGRATION_NAME = "McAfee DXL" CONNECT_RETRIES = 1 RECONNECT_DELAY = 1 RECONNECT_DELAY_MAX = 10 class EventSender: TRUST_LEVEL = { 'NOT_SET': '0', 'KNOWN_MALICIOUS': '1', 'MOST_LIKELY_MALICIOUS': '15', 'MIGHT_BE_MALICIOUS': '30', 'UNKNOWN': '50', 'MIGHT_BE_TRUSTED': '70', 'MOST_LIKELY_TRUSTED': '85', 'KNOWN_TRUSTED': '99', 'KNOWN_TRUSTED_INSTALLER': '100' } broker_ca_bundle = tempfile.NamedTemporaryFile().name cert_file = tempfile.NamedTemporaryFile().name private_key = tempfile.NamedTemporaryFile().name def __init__(self, params: Dict): with open(self.broker_ca_bundle, "w") as text_file: text_file.write(params['broker_ca_bundle']) with open(self.cert_file, "w") as text_file: text_file.write(params['cert_file']) with open(self.private_key, "w") as text_file: text_file.write(params['private_key']) if 'broker_urls' in params: self.broker_urls = params['broker_urls'].split(',') self.push_ip_topic = params.get('push_ip_topic') self.push_url_topic = params.get('push_url_topic') self.push_domain_topic = params.get('push_domain_topic') self.push_hash_topic = params.get('push_hash_topic') self.client = DxlClient(self.get_client_config()) self.client.connect() def __del__(self): self.client.disconnect() def push_ip(self, ip, trust_level, topic): if not is_ip_valid(ip): raise ValueError(f'argument ip {ip} is not a valid IP') trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_ip_topic, f'ip:{ip};trust_level:{trust_level_key}') return f'Successfully pushed ip {ip} with trust level {trust_level}' def push_url(self, url, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_url_topic = topic self.send_event(self.push_url_topic, f'url:{url};trust_level:{trust_level_key}') return f'Successfully pushed url {url} with trust level {trust_level}' def push_domain(self, domain, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_domain_topic = topic self.send_event(self.push_domain_topic, f'domain:{domain};trust_level:{trust_level_key}') return f'Successfully pushed domain {domain} with trust level {trust_level}' def push_hash(self, hash_obj, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_hash_topic, f'hash:{hash_obj};trust_level:{trust_level_key}') return f'Successfully pushed hash {hash_obj} with trust level {trust_level}' def get_client_config(self): config = DxlClientConfig( broker_ca_bundle=self.broker_ca_bundle, cert_file=self.cert_file, private_key=self.private_key, brokers=[Broker.parse(url) for url in self.broker_urls] ) config.connect_retries = CONNECT_RETRIES config.reconnect_delay = RECONNECT_DELAY config.reconnect_delay_max = RECONNECT_DELAY_MAX return config def send_event(self, topic, payload): if not topic: raise Exception(f'Error in {demisto.command()} topic field is required') event = Event(topic) event.payload = str(payload).encode() self.client.send_event(event) def send_event_wrapper(self, topic, payload): self.send_event(topic, payload) return 'Successfully sent event' def validate_certificates_format(): if '-----BEGIN PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't start with -----BEGIN PRIVATE KEY-----") if '-----END PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't end with -----END PRIVATE KEY-----") if '-----BEGIN CERTIFICATE-----' not in demisto.params()['cert_file']: return_error("The client certificates content seem to be " "incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if '-----END CERTIFICATE-----' not in demisto.params()['cert_file']: return_error( "The client certificates content seem to be incorrect as it doesn't end with -----END CERTIFICATE-----") if not demisto.params()['broker_ca_bundle'].lstrip(" ").startswith('-----BEGIN CERTIFICATE-----'): <|fim_middle|> if not demisto.params()['broker_ca_bundle'].rstrip(" ").endswith('-----END CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't end with '-----END CERTIFICATE-----'") def main(): args = demisto.args() command = demisto.command() try: event_sender = EventSender(demisto.params()) result = '' if command == 'test-module': event_sender.send_event('TEST', 'test') result = 'ok' elif command == 'dxl-send-event': result = event_sender.send_event_wrapper(args.get('topic'), args.get('payload')) elif command == 'dxl-push-ip': result = event_sender.push_ip(args.get('ip'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-url': result = event_sender.push_url(args.get('url'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-domain': result = event_sender.push_domain(args.get('domain'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-hash': result = event_sender.push_hash(args.get('hash'), args.get('trust_level'), args.get('topic')) else: raise Exception(f'{demisto.command()} is not a command') return_outputs(result) except Exception as error: validate_certificates_format() return_error(f'error in {INTEGRATION_NAME} {str(error)}.', error) if __name__ in ('__builtin__', 'builtins'): main() <|fim▁end|>
return_error( "The broker certificate seem to be incorrect as they don't start with '-----BEGIN CERTIFICATE-----'")
<|file_name|>McAfee_DXL.py<|end_file_name|><|fim▁begin|>from typing import Dict import tempfile from dxlclient.client_config import DxlClientConfig from dxlclient.client import DxlClient from dxlclient.broker import Broker from dxlclient.message import Event import demistomock as demisto from CommonServerPython import * from CommonServerUserPython import * INTEGRATION_NAME = "McAfee DXL" CONNECT_RETRIES = 1 RECONNECT_DELAY = 1 RECONNECT_DELAY_MAX = 10 class EventSender: TRUST_LEVEL = { 'NOT_SET': '0', 'KNOWN_MALICIOUS': '1', 'MOST_LIKELY_MALICIOUS': '15', 'MIGHT_BE_MALICIOUS': '30', 'UNKNOWN': '50', 'MIGHT_BE_TRUSTED': '70', 'MOST_LIKELY_TRUSTED': '85', 'KNOWN_TRUSTED': '99', 'KNOWN_TRUSTED_INSTALLER': '100' } broker_ca_bundle = tempfile.NamedTemporaryFile().name cert_file = tempfile.NamedTemporaryFile().name private_key = tempfile.NamedTemporaryFile().name def __init__(self, params: Dict): with open(self.broker_ca_bundle, "w") as text_file: text_file.write(params['broker_ca_bundle']) with open(self.cert_file, "w") as text_file: text_file.write(params['cert_file']) with open(self.private_key, "w") as text_file: text_file.write(params['private_key']) if 'broker_urls' in params: self.broker_urls = params['broker_urls'].split(',') self.push_ip_topic = params.get('push_ip_topic') self.push_url_topic = params.get('push_url_topic') self.push_domain_topic = params.get('push_domain_topic') self.push_hash_topic = params.get('push_hash_topic') self.client = DxlClient(self.get_client_config()) self.client.connect() def __del__(self): self.client.disconnect() def push_ip(self, ip, trust_level, topic): if not is_ip_valid(ip): raise ValueError(f'argument ip {ip} is not a valid IP') trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_ip_topic, f'ip:{ip};trust_level:{trust_level_key}') return f'Successfully pushed ip {ip} with trust level {trust_level}' def push_url(self, url, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_url_topic = topic self.send_event(self.push_url_topic, f'url:{url};trust_level:{trust_level_key}') return f'Successfully pushed url {url} with trust level {trust_level}' def push_domain(self, domain, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_domain_topic = topic self.send_event(self.push_domain_topic, f'domain:{domain};trust_level:{trust_level_key}') return f'Successfully pushed domain {domain} with trust level {trust_level}' def push_hash(self, hash_obj, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_hash_topic, f'hash:{hash_obj};trust_level:{trust_level_key}') return f'Successfully pushed hash {hash_obj} with trust level {trust_level}' def get_client_config(self): config = DxlClientConfig( broker_ca_bundle=self.broker_ca_bundle, cert_file=self.cert_file, private_key=self.private_key, brokers=[Broker.parse(url) for url in self.broker_urls] ) config.connect_retries = CONNECT_RETRIES config.reconnect_delay = RECONNECT_DELAY config.reconnect_delay_max = RECONNECT_DELAY_MAX return config def send_event(self, topic, payload): if not topic: raise Exception(f'Error in {demisto.command()} topic field is required') event = Event(topic) event.payload = str(payload).encode() self.client.send_event(event) def send_event_wrapper(self, topic, payload): self.send_event(topic, payload) return 'Successfully sent event' def validate_certificates_format(): if '-----BEGIN PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't start with -----BEGIN PRIVATE KEY-----") if '-----END PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't end with -----END PRIVATE KEY-----") if '-----BEGIN CERTIFICATE-----' not in demisto.params()['cert_file']: return_error("The client certificates content seem to be " "incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if '-----END CERTIFICATE-----' not in demisto.params()['cert_file']: return_error( "The client certificates content seem to be incorrect as it doesn't end with -----END CERTIFICATE-----") if not demisto.params()['broker_ca_bundle'].lstrip(" ").startswith('-----BEGIN CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if not demisto.params()['broker_ca_bundle'].rstrip(" ").endswith('-----END CERTIFICATE-----'): <|fim_middle|> def main(): args = demisto.args() command = demisto.command() try: event_sender = EventSender(demisto.params()) result = '' if command == 'test-module': event_sender.send_event('TEST', 'test') result = 'ok' elif command == 'dxl-send-event': result = event_sender.send_event_wrapper(args.get('topic'), args.get('payload')) elif command == 'dxl-push-ip': result = event_sender.push_ip(args.get('ip'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-url': result = event_sender.push_url(args.get('url'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-domain': result = event_sender.push_domain(args.get('domain'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-hash': result = event_sender.push_hash(args.get('hash'), args.get('trust_level'), args.get('topic')) else: raise Exception(f'{demisto.command()} is not a command') return_outputs(result) except Exception as error: validate_certificates_format() return_error(f'error in {INTEGRATION_NAME} {str(error)}.', error) if __name__ in ('__builtin__', 'builtins'): main() <|fim▁end|>
return_error( "The broker certificate seem to be incorrect as they don't end with '-----END CERTIFICATE-----'")
<|file_name|>McAfee_DXL.py<|end_file_name|><|fim▁begin|>from typing import Dict import tempfile from dxlclient.client_config import DxlClientConfig from dxlclient.client import DxlClient from dxlclient.broker import Broker from dxlclient.message import Event import demistomock as demisto from CommonServerPython import * from CommonServerUserPython import * INTEGRATION_NAME = "McAfee DXL" CONNECT_RETRIES = 1 RECONNECT_DELAY = 1 RECONNECT_DELAY_MAX = 10 class EventSender: TRUST_LEVEL = { 'NOT_SET': '0', 'KNOWN_MALICIOUS': '1', 'MOST_LIKELY_MALICIOUS': '15', 'MIGHT_BE_MALICIOUS': '30', 'UNKNOWN': '50', 'MIGHT_BE_TRUSTED': '70', 'MOST_LIKELY_TRUSTED': '85', 'KNOWN_TRUSTED': '99', 'KNOWN_TRUSTED_INSTALLER': '100' } broker_ca_bundle = tempfile.NamedTemporaryFile().name cert_file = tempfile.NamedTemporaryFile().name private_key = tempfile.NamedTemporaryFile().name def __init__(self, params: Dict): with open(self.broker_ca_bundle, "w") as text_file: text_file.write(params['broker_ca_bundle']) with open(self.cert_file, "w") as text_file: text_file.write(params['cert_file']) with open(self.private_key, "w") as text_file: text_file.write(params['private_key']) if 'broker_urls' in params: self.broker_urls = params['broker_urls'].split(',') self.push_ip_topic = params.get('push_ip_topic') self.push_url_topic = params.get('push_url_topic') self.push_domain_topic = params.get('push_domain_topic') self.push_hash_topic = params.get('push_hash_topic') self.client = DxlClient(self.get_client_config()) self.client.connect() def __del__(self): self.client.disconnect() def push_ip(self, ip, trust_level, topic): if not is_ip_valid(ip): raise ValueError(f'argument ip {ip} is not a valid IP') trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_ip_topic, f'ip:{ip};trust_level:{trust_level_key}') return f'Successfully pushed ip {ip} with trust level {trust_level}' def push_url(self, url, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_url_topic = topic self.send_event(self.push_url_topic, f'url:{url};trust_level:{trust_level_key}') return f'Successfully pushed url {url} with trust level {trust_level}' def push_domain(self, domain, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_domain_topic = topic self.send_event(self.push_domain_topic, f'domain:{domain};trust_level:{trust_level_key}') return f'Successfully pushed domain {domain} with trust level {trust_level}' def push_hash(self, hash_obj, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_hash_topic, f'hash:{hash_obj};trust_level:{trust_level_key}') return f'Successfully pushed hash {hash_obj} with trust level {trust_level}' def get_client_config(self): config = DxlClientConfig( broker_ca_bundle=self.broker_ca_bundle, cert_file=self.cert_file, private_key=self.private_key, brokers=[Broker.parse(url) for url in self.broker_urls] ) config.connect_retries = CONNECT_RETRIES config.reconnect_delay = RECONNECT_DELAY config.reconnect_delay_max = RECONNECT_DELAY_MAX return config def send_event(self, topic, payload): if not topic: raise Exception(f'Error in {demisto.command()} topic field is required') event = Event(topic) event.payload = str(payload).encode() self.client.send_event(event) def send_event_wrapper(self, topic, payload): self.send_event(topic, payload) return 'Successfully sent event' def validate_certificates_format(): if '-----BEGIN PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't start with -----BEGIN PRIVATE KEY-----") if '-----END PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't end with -----END PRIVATE KEY-----") if '-----BEGIN CERTIFICATE-----' not in demisto.params()['cert_file']: return_error("The client certificates content seem to be " "incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if '-----END CERTIFICATE-----' not in demisto.params()['cert_file']: return_error( "The client certificates content seem to be incorrect as it doesn't end with -----END CERTIFICATE-----") if not demisto.params()['broker_ca_bundle'].lstrip(" ").startswith('-----BEGIN CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if not demisto.params()['broker_ca_bundle'].rstrip(" ").endswith('-----END CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't end with '-----END CERTIFICATE-----'") def main(): args = demisto.args() command = demisto.command() try: event_sender = EventSender(demisto.params()) result = '' if command == 'test-module': <|fim_middle|> elif command == 'dxl-send-event': result = event_sender.send_event_wrapper(args.get('topic'), args.get('payload')) elif command == 'dxl-push-ip': result = event_sender.push_ip(args.get('ip'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-url': result = event_sender.push_url(args.get('url'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-domain': result = event_sender.push_domain(args.get('domain'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-hash': result = event_sender.push_hash(args.get('hash'), args.get('trust_level'), args.get('topic')) else: raise Exception(f'{demisto.command()} is not a command') return_outputs(result) except Exception as error: validate_certificates_format() return_error(f'error in {INTEGRATION_NAME} {str(error)}.', error) if __name__ in ('__builtin__', 'builtins'): main() <|fim▁end|>
event_sender.send_event('TEST', 'test') result = 'ok'
<|file_name|>McAfee_DXL.py<|end_file_name|><|fim▁begin|>from typing import Dict import tempfile from dxlclient.client_config import DxlClientConfig from dxlclient.client import DxlClient from dxlclient.broker import Broker from dxlclient.message import Event import demistomock as demisto from CommonServerPython import * from CommonServerUserPython import * INTEGRATION_NAME = "McAfee DXL" CONNECT_RETRIES = 1 RECONNECT_DELAY = 1 RECONNECT_DELAY_MAX = 10 class EventSender: TRUST_LEVEL = { 'NOT_SET': '0', 'KNOWN_MALICIOUS': '1', 'MOST_LIKELY_MALICIOUS': '15', 'MIGHT_BE_MALICIOUS': '30', 'UNKNOWN': '50', 'MIGHT_BE_TRUSTED': '70', 'MOST_LIKELY_TRUSTED': '85', 'KNOWN_TRUSTED': '99', 'KNOWN_TRUSTED_INSTALLER': '100' } broker_ca_bundle = tempfile.NamedTemporaryFile().name cert_file = tempfile.NamedTemporaryFile().name private_key = tempfile.NamedTemporaryFile().name def __init__(self, params: Dict): with open(self.broker_ca_bundle, "w") as text_file: text_file.write(params['broker_ca_bundle']) with open(self.cert_file, "w") as text_file: text_file.write(params['cert_file']) with open(self.private_key, "w") as text_file: text_file.write(params['private_key']) if 'broker_urls' in params: self.broker_urls = params['broker_urls'].split(',') self.push_ip_topic = params.get('push_ip_topic') self.push_url_topic = params.get('push_url_topic') self.push_domain_topic = params.get('push_domain_topic') self.push_hash_topic = params.get('push_hash_topic') self.client = DxlClient(self.get_client_config()) self.client.connect() def __del__(self): self.client.disconnect() def push_ip(self, ip, trust_level, topic): if not is_ip_valid(ip): raise ValueError(f'argument ip {ip} is not a valid IP') trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_ip_topic, f'ip:{ip};trust_level:{trust_level_key}') return f'Successfully pushed ip {ip} with trust level {trust_level}' def push_url(self, url, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_url_topic = topic self.send_event(self.push_url_topic, f'url:{url};trust_level:{trust_level_key}') return f'Successfully pushed url {url} with trust level {trust_level}' def push_domain(self, domain, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_domain_topic = topic self.send_event(self.push_domain_topic, f'domain:{domain};trust_level:{trust_level_key}') return f'Successfully pushed domain {domain} with trust level {trust_level}' def push_hash(self, hash_obj, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_hash_topic, f'hash:{hash_obj};trust_level:{trust_level_key}') return f'Successfully pushed hash {hash_obj} with trust level {trust_level}' def get_client_config(self): config = DxlClientConfig( broker_ca_bundle=self.broker_ca_bundle, cert_file=self.cert_file, private_key=self.private_key, brokers=[Broker.parse(url) for url in self.broker_urls] ) config.connect_retries = CONNECT_RETRIES config.reconnect_delay = RECONNECT_DELAY config.reconnect_delay_max = RECONNECT_DELAY_MAX return config def send_event(self, topic, payload): if not topic: raise Exception(f'Error in {demisto.command()} topic field is required') event = Event(topic) event.payload = str(payload).encode() self.client.send_event(event) def send_event_wrapper(self, topic, payload): self.send_event(topic, payload) return 'Successfully sent event' def validate_certificates_format(): if '-----BEGIN PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't start with -----BEGIN PRIVATE KEY-----") if '-----END PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't end with -----END PRIVATE KEY-----") if '-----BEGIN CERTIFICATE-----' not in demisto.params()['cert_file']: return_error("The client certificates content seem to be " "incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if '-----END CERTIFICATE-----' not in demisto.params()['cert_file']: return_error( "The client certificates content seem to be incorrect as it doesn't end with -----END CERTIFICATE-----") if not demisto.params()['broker_ca_bundle'].lstrip(" ").startswith('-----BEGIN CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if not demisto.params()['broker_ca_bundle'].rstrip(" ").endswith('-----END CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't end with '-----END CERTIFICATE-----'") def main(): args = demisto.args() command = demisto.command() try: event_sender = EventSender(demisto.params()) result = '' if command == 'test-module': event_sender.send_event('TEST', 'test') result = 'ok' elif command == 'dxl-send-event': <|fim_middle|> elif command == 'dxl-push-ip': result = event_sender.push_ip(args.get('ip'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-url': result = event_sender.push_url(args.get('url'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-domain': result = event_sender.push_domain(args.get('domain'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-hash': result = event_sender.push_hash(args.get('hash'), args.get('trust_level'), args.get('topic')) else: raise Exception(f'{demisto.command()} is not a command') return_outputs(result) except Exception as error: validate_certificates_format() return_error(f'error in {INTEGRATION_NAME} {str(error)}.', error) if __name__ in ('__builtin__', 'builtins'): main() <|fim▁end|>
result = event_sender.send_event_wrapper(args.get('topic'), args.get('payload'))
<|file_name|>McAfee_DXL.py<|end_file_name|><|fim▁begin|>from typing import Dict import tempfile from dxlclient.client_config import DxlClientConfig from dxlclient.client import DxlClient from dxlclient.broker import Broker from dxlclient.message import Event import demistomock as demisto from CommonServerPython import * from CommonServerUserPython import * INTEGRATION_NAME = "McAfee DXL" CONNECT_RETRIES = 1 RECONNECT_DELAY = 1 RECONNECT_DELAY_MAX = 10 class EventSender: TRUST_LEVEL = { 'NOT_SET': '0', 'KNOWN_MALICIOUS': '1', 'MOST_LIKELY_MALICIOUS': '15', 'MIGHT_BE_MALICIOUS': '30', 'UNKNOWN': '50', 'MIGHT_BE_TRUSTED': '70', 'MOST_LIKELY_TRUSTED': '85', 'KNOWN_TRUSTED': '99', 'KNOWN_TRUSTED_INSTALLER': '100' } broker_ca_bundle = tempfile.NamedTemporaryFile().name cert_file = tempfile.NamedTemporaryFile().name private_key = tempfile.NamedTemporaryFile().name def __init__(self, params: Dict): with open(self.broker_ca_bundle, "w") as text_file: text_file.write(params['broker_ca_bundle']) with open(self.cert_file, "w") as text_file: text_file.write(params['cert_file']) with open(self.private_key, "w") as text_file: text_file.write(params['private_key']) if 'broker_urls' in params: self.broker_urls = params['broker_urls'].split(',') self.push_ip_topic = params.get('push_ip_topic') self.push_url_topic = params.get('push_url_topic') self.push_domain_topic = params.get('push_domain_topic') self.push_hash_topic = params.get('push_hash_topic') self.client = DxlClient(self.get_client_config()) self.client.connect() def __del__(self): self.client.disconnect() def push_ip(self, ip, trust_level, topic): if not is_ip_valid(ip): raise ValueError(f'argument ip {ip} is not a valid IP') trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_ip_topic, f'ip:{ip};trust_level:{trust_level_key}') return f'Successfully pushed ip {ip} with trust level {trust_level}' def push_url(self, url, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_url_topic = topic self.send_event(self.push_url_topic, f'url:{url};trust_level:{trust_level_key}') return f'Successfully pushed url {url} with trust level {trust_level}' def push_domain(self, domain, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_domain_topic = topic self.send_event(self.push_domain_topic, f'domain:{domain};trust_level:{trust_level_key}') return f'Successfully pushed domain {domain} with trust level {trust_level}' def push_hash(self, hash_obj, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_hash_topic, f'hash:{hash_obj};trust_level:{trust_level_key}') return f'Successfully pushed hash {hash_obj} with trust level {trust_level}' def get_client_config(self): config = DxlClientConfig( broker_ca_bundle=self.broker_ca_bundle, cert_file=self.cert_file, private_key=self.private_key, brokers=[Broker.parse(url) for url in self.broker_urls] ) config.connect_retries = CONNECT_RETRIES config.reconnect_delay = RECONNECT_DELAY config.reconnect_delay_max = RECONNECT_DELAY_MAX return config def send_event(self, topic, payload): if not topic: raise Exception(f'Error in {demisto.command()} topic field is required') event = Event(topic) event.payload = str(payload).encode() self.client.send_event(event) def send_event_wrapper(self, topic, payload): self.send_event(topic, payload) return 'Successfully sent event' def validate_certificates_format(): if '-----BEGIN PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't start with -----BEGIN PRIVATE KEY-----") if '-----END PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't end with -----END PRIVATE KEY-----") if '-----BEGIN CERTIFICATE-----' not in demisto.params()['cert_file']: return_error("The client certificates content seem to be " "incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if '-----END CERTIFICATE-----' not in demisto.params()['cert_file']: return_error( "The client certificates content seem to be incorrect as it doesn't end with -----END CERTIFICATE-----") if not demisto.params()['broker_ca_bundle'].lstrip(" ").startswith('-----BEGIN CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if not demisto.params()['broker_ca_bundle'].rstrip(" ").endswith('-----END CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't end with '-----END CERTIFICATE-----'") def main(): args = demisto.args() command = demisto.command() try: event_sender = EventSender(demisto.params()) result = '' if command == 'test-module': event_sender.send_event('TEST', 'test') result = 'ok' elif command == 'dxl-send-event': result = event_sender.send_event_wrapper(args.get('topic'), args.get('payload')) elif command == 'dxl-push-ip': <|fim_middle|> elif command == 'dxl-push-url': result = event_sender.push_url(args.get('url'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-domain': result = event_sender.push_domain(args.get('domain'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-hash': result = event_sender.push_hash(args.get('hash'), args.get('trust_level'), args.get('topic')) else: raise Exception(f'{demisto.command()} is not a command') return_outputs(result) except Exception as error: validate_certificates_format() return_error(f'error in {INTEGRATION_NAME} {str(error)}.', error) if __name__ in ('__builtin__', 'builtins'): main() <|fim▁end|>
result = event_sender.push_ip(args.get('ip'), args.get('trust_level'), args.get('topic'))
<|file_name|>McAfee_DXL.py<|end_file_name|><|fim▁begin|>from typing import Dict import tempfile from dxlclient.client_config import DxlClientConfig from dxlclient.client import DxlClient from dxlclient.broker import Broker from dxlclient.message import Event import demistomock as demisto from CommonServerPython import * from CommonServerUserPython import * INTEGRATION_NAME = "McAfee DXL" CONNECT_RETRIES = 1 RECONNECT_DELAY = 1 RECONNECT_DELAY_MAX = 10 class EventSender: TRUST_LEVEL = { 'NOT_SET': '0', 'KNOWN_MALICIOUS': '1', 'MOST_LIKELY_MALICIOUS': '15', 'MIGHT_BE_MALICIOUS': '30', 'UNKNOWN': '50', 'MIGHT_BE_TRUSTED': '70', 'MOST_LIKELY_TRUSTED': '85', 'KNOWN_TRUSTED': '99', 'KNOWN_TRUSTED_INSTALLER': '100' } broker_ca_bundle = tempfile.NamedTemporaryFile().name cert_file = tempfile.NamedTemporaryFile().name private_key = tempfile.NamedTemporaryFile().name def __init__(self, params: Dict): with open(self.broker_ca_bundle, "w") as text_file: text_file.write(params['broker_ca_bundle']) with open(self.cert_file, "w") as text_file: text_file.write(params['cert_file']) with open(self.private_key, "w") as text_file: text_file.write(params['private_key']) if 'broker_urls' in params: self.broker_urls = params['broker_urls'].split(',') self.push_ip_topic = params.get('push_ip_topic') self.push_url_topic = params.get('push_url_topic') self.push_domain_topic = params.get('push_domain_topic') self.push_hash_topic = params.get('push_hash_topic') self.client = DxlClient(self.get_client_config()) self.client.connect() def __del__(self): self.client.disconnect() def push_ip(self, ip, trust_level, topic): if not is_ip_valid(ip): raise ValueError(f'argument ip {ip} is not a valid IP') trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_ip_topic, f'ip:{ip};trust_level:{trust_level_key}') return f'Successfully pushed ip {ip} with trust level {trust_level}' def push_url(self, url, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_url_topic = topic self.send_event(self.push_url_topic, f'url:{url};trust_level:{trust_level_key}') return f'Successfully pushed url {url} with trust level {trust_level}' def push_domain(self, domain, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_domain_topic = topic self.send_event(self.push_domain_topic, f'domain:{domain};trust_level:{trust_level_key}') return f'Successfully pushed domain {domain} with trust level {trust_level}' def push_hash(self, hash_obj, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_hash_topic, f'hash:{hash_obj};trust_level:{trust_level_key}') return f'Successfully pushed hash {hash_obj} with trust level {trust_level}' def get_client_config(self): config = DxlClientConfig( broker_ca_bundle=self.broker_ca_bundle, cert_file=self.cert_file, private_key=self.private_key, brokers=[Broker.parse(url) for url in self.broker_urls] ) config.connect_retries = CONNECT_RETRIES config.reconnect_delay = RECONNECT_DELAY config.reconnect_delay_max = RECONNECT_DELAY_MAX return config def send_event(self, topic, payload): if not topic: raise Exception(f'Error in {demisto.command()} topic field is required') event = Event(topic) event.payload = str(payload).encode() self.client.send_event(event) def send_event_wrapper(self, topic, payload): self.send_event(topic, payload) return 'Successfully sent event' def validate_certificates_format(): if '-----BEGIN PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't start with -----BEGIN PRIVATE KEY-----") if '-----END PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't end with -----END PRIVATE KEY-----") if '-----BEGIN CERTIFICATE-----' not in demisto.params()['cert_file']: return_error("The client certificates content seem to be " "incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if '-----END CERTIFICATE-----' not in demisto.params()['cert_file']: return_error( "The client certificates content seem to be incorrect as it doesn't end with -----END CERTIFICATE-----") if not demisto.params()['broker_ca_bundle'].lstrip(" ").startswith('-----BEGIN CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if not demisto.params()['broker_ca_bundle'].rstrip(" ").endswith('-----END CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't end with '-----END CERTIFICATE-----'") def main(): args = demisto.args() command = demisto.command() try: event_sender = EventSender(demisto.params()) result = '' if command == 'test-module': event_sender.send_event('TEST', 'test') result = 'ok' elif command == 'dxl-send-event': result = event_sender.send_event_wrapper(args.get('topic'), args.get('payload')) elif command == 'dxl-push-ip': result = event_sender.push_ip(args.get('ip'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-url': <|fim_middle|> elif command == 'dxl-push-domain': result = event_sender.push_domain(args.get('domain'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-hash': result = event_sender.push_hash(args.get('hash'), args.get('trust_level'), args.get('topic')) else: raise Exception(f'{demisto.command()} is not a command') return_outputs(result) except Exception as error: validate_certificates_format() return_error(f'error in {INTEGRATION_NAME} {str(error)}.', error) if __name__ in ('__builtin__', 'builtins'): main() <|fim▁end|>
result = event_sender.push_url(args.get('url'), args.get('trust_level'), args.get('topic'))
<|file_name|>McAfee_DXL.py<|end_file_name|><|fim▁begin|>from typing import Dict import tempfile from dxlclient.client_config import DxlClientConfig from dxlclient.client import DxlClient from dxlclient.broker import Broker from dxlclient.message import Event import demistomock as demisto from CommonServerPython import * from CommonServerUserPython import * INTEGRATION_NAME = "McAfee DXL" CONNECT_RETRIES = 1 RECONNECT_DELAY = 1 RECONNECT_DELAY_MAX = 10 class EventSender: TRUST_LEVEL = { 'NOT_SET': '0', 'KNOWN_MALICIOUS': '1', 'MOST_LIKELY_MALICIOUS': '15', 'MIGHT_BE_MALICIOUS': '30', 'UNKNOWN': '50', 'MIGHT_BE_TRUSTED': '70', 'MOST_LIKELY_TRUSTED': '85', 'KNOWN_TRUSTED': '99', 'KNOWN_TRUSTED_INSTALLER': '100' } broker_ca_bundle = tempfile.NamedTemporaryFile().name cert_file = tempfile.NamedTemporaryFile().name private_key = tempfile.NamedTemporaryFile().name def __init__(self, params: Dict): with open(self.broker_ca_bundle, "w") as text_file: text_file.write(params['broker_ca_bundle']) with open(self.cert_file, "w") as text_file: text_file.write(params['cert_file']) with open(self.private_key, "w") as text_file: text_file.write(params['private_key']) if 'broker_urls' in params: self.broker_urls = params['broker_urls'].split(',') self.push_ip_topic = params.get('push_ip_topic') self.push_url_topic = params.get('push_url_topic') self.push_domain_topic = params.get('push_domain_topic') self.push_hash_topic = params.get('push_hash_topic') self.client = DxlClient(self.get_client_config()) self.client.connect() def __del__(self): self.client.disconnect() def push_ip(self, ip, trust_level, topic): if not is_ip_valid(ip): raise ValueError(f'argument ip {ip} is not a valid IP') trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_ip_topic, f'ip:{ip};trust_level:{trust_level_key}') return f'Successfully pushed ip {ip} with trust level {trust_level}' def push_url(self, url, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_url_topic = topic self.send_event(self.push_url_topic, f'url:{url};trust_level:{trust_level_key}') return f'Successfully pushed url {url} with trust level {trust_level}' def push_domain(self, domain, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_domain_topic = topic self.send_event(self.push_domain_topic, f'domain:{domain};trust_level:{trust_level_key}') return f'Successfully pushed domain {domain} with trust level {trust_level}' def push_hash(self, hash_obj, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_hash_topic, f'hash:{hash_obj};trust_level:{trust_level_key}') return f'Successfully pushed hash {hash_obj} with trust level {trust_level}' def get_client_config(self): config = DxlClientConfig( broker_ca_bundle=self.broker_ca_bundle, cert_file=self.cert_file, private_key=self.private_key, brokers=[Broker.parse(url) for url in self.broker_urls] ) config.connect_retries = CONNECT_RETRIES config.reconnect_delay = RECONNECT_DELAY config.reconnect_delay_max = RECONNECT_DELAY_MAX return config def send_event(self, topic, payload): if not topic: raise Exception(f'Error in {demisto.command()} topic field is required') event = Event(topic) event.payload = str(payload).encode() self.client.send_event(event) def send_event_wrapper(self, topic, payload): self.send_event(topic, payload) return 'Successfully sent event' def validate_certificates_format(): if '-----BEGIN PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't start with -----BEGIN PRIVATE KEY-----") if '-----END PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't end with -----END PRIVATE KEY-----") if '-----BEGIN CERTIFICATE-----' not in demisto.params()['cert_file']: return_error("The client certificates content seem to be " "incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if '-----END CERTIFICATE-----' not in demisto.params()['cert_file']: return_error( "The client certificates content seem to be incorrect as it doesn't end with -----END CERTIFICATE-----") if not demisto.params()['broker_ca_bundle'].lstrip(" ").startswith('-----BEGIN CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if not demisto.params()['broker_ca_bundle'].rstrip(" ").endswith('-----END CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't end with '-----END CERTIFICATE-----'") def main(): args = demisto.args() command = demisto.command() try: event_sender = EventSender(demisto.params()) result = '' if command == 'test-module': event_sender.send_event('TEST', 'test') result = 'ok' elif command == 'dxl-send-event': result = event_sender.send_event_wrapper(args.get('topic'), args.get('payload')) elif command == 'dxl-push-ip': result = event_sender.push_ip(args.get('ip'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-url': result = event_sender.push_url(args.get('url'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-domain': <|fim_middle|> elif command == 'dxl-push-hash': result = event_sender.push_hash(args.get('hash'), args.get('trust_level'), args.get('topic')) else: raise Exception(f'{demisto.command()} is not a command') return_outputs(result) except Exception as error: validate_certificates_format() return_error(f'error in {INTEGRATION_NAME} {str(error)}.', error) if __name__ in ('__builtin__', 'builtins'): main() <|fim▁end|>
result = event_sender.push_domain(args.get('domain'), args.get('trust_level'), args.get('topic'))
<|file_name|>McAfee_DXL.py<|end_file_name|><|fim▁begin|>from typing import Dict import tempfile from dxlclient.client_config import DxlClientConfig from dxlclient.client import DxlClient from dxlclient.broker import Broker from dxlclient.message import Event import demistomock as demisto from CommonServerPython import * from CommonServerUserPython import * INTEGRATION_NAME = "McAfee DXL" CONNECT_RETRIES = 1 RECONNECT_DELAY = 1 RECONNECT_DELAY_MAX = 10 class EventSender: TRUST_LEVEL = { 'NOT_SET': '0', 'KNOWN_MALICIOUS': '1', 'MOST_LIKELY_MALICIOUS': '15', 'MIGHT_BE_MALICIOUS': '30', 'UNKNOWN': '50', 'MIGHT_BE_TRUSTED': '70', 'MOST_LIKELY_TRUSTED': '85', 'KNOWN_TRUSTED': '99', 'KNOWN_TRUSTED_INSTALLER': '100' } broker_ca_bundle = tempfile.NamedTemporaryFile().name cert_file = tempfile.NamedTemporaryFile().name private_key = tempfile.NamedTemporaryFile().name def __init__(self, params: Dict): with open(self.broker_ca_bundle, "w") as text_file: text_file.write(params['broker_ca_bundle']) with open(self.cert_file, "w") as text_file: text_file.write(params['cert_file']) with open(self.private_key, "w") as text_file: text_file.write(params['private_key']) if 'broker_urls' in params: self.broker_urls = params['broker_urls'].split(',') self.push_ip_topic = params.get('push_ip_topic') self.push_url_topic = params.get('push_url_topic') self.push_domain_topic = params.get('push_domain_topic') self.push_hash_topic = params.get('push_hash_topic') self.client = DxlClient(self.get_client_config()) self.client.connect() def __del__(self): self.client.disconnect() def push_ip(self, ip, trust_level, topic): if not is_ip_valid(ip): raise ValueError(f'argument ip {ip} is not a valid IP') trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_ip_topic, f'ip:{ip};trust_level:{trust_level_key}') return f'Successfully pushed ip {ip} with trust level {trust_level}' def push_url(self, url, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_url_topic = topic self.send_event(self.push_url_topic, f'url:{url};trust_level:{trust_level_key}') return f'Successfully pushed url {url} with trust level {trust_level}' def push_domain(self, domain, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_domain_topic = topic self.send_event(self.push_domain_topic, f'domain:{domain};trust_level:{trust_level_key}') return f'Successfully pushed domain {domain} with trust level {trust_level}' def push_hash(self, hash_obj, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_hash_topic, f'hash:{hash_obj};trust_level:{trust_level_key}') return f'Successfully pushed hash {hash_obj} with trust level {trust_level}' def get_client_config(self): config = DxlClientConfig( broker_ca_bundle=self.broker_ca_bundle, cert_file=self.cert_file, private_key=self.private_key, brokers=[Broker.parse(url) for url in self.broker_urls] ) config.connect_retries = CONNECT_RETRIES config.reconnect_delay = RECONNECT_DELAY config.reconnect_delay_max = RECONNECT_DELAY_MAX return config def send_event(self, topic, payload): if not topic: raise Exception(f'Error in {demisto.command()} topic field is required') event = Event(topic) event.payload = str(payload).encode() self.client.send_event(event) def send_event_wrapper(self, topic, payload): self.send_event(topic, payload) return 'Successfully sent event' def validate_certificates_format(): if '-----BEGIN PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't start with -----BEGIN PRIVATE KEY-----") if '-----END PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't end with -----END PRIVATE KEY-----") if '-----BEGIN CERTIFICATE-----' not in demisto.params()['cert_file']: return_error("The client certificates content seem to be " "incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if '-----END CERTIFICATE-----' not in demisto.params()['cert_file']: return_error( "The client certificates content seem to be incorrect as it doesn't end with -----END CERTIFICATE-----") if not demisto.params()['broker_ca_bundle'].lstrip(" ").startswith('-----BEGIN CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if not demisto.params()['broker_ca_bundle'].rstrip(" ").endswith('-----END CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't end with '-----END CERTIFICATE-----'") def main(): args = demisto.args() command = demisto.command() try: event_sender = EventSender(demisto.params()) result = '' if command == 'test-module': event_sender.send_event('TEST', 'test') result = 'ok' elif command == 'dxl-send-event': result = event_sender.send_event_wrapper(args.get('topic'), args.get('payload')) elif command == 'dxl-push-ip': result = event_sender.push_ip(args.get('ip'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-url': result = event_sender.push_url(args.get('url'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-domain': result = event_sender.push_domain(args.get('domain'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-hash': <|fim_middle|> else: raise Exception(f'{demisto.command()} is not a command') return_outputs(result) except Exception as error: validate_certificates_format() return_error(f'error in {INTEGRATION_NAME} {str(error)}.', error) if __name__ in ('__builtin__', 'builtins'): main() <|fim▁end|>
result = event_sender.push_hash(args.get('hash'), args.get('trust_level'), args.get('topic'))
<|file_name|>McAfee_DXL.py<|end_file_name|><|fim▁begin|>from typing import Dict import tempfile from dxlclient.client_config import DxlClientConfig from dxlclient.client import DxlClient from dxlclient.broker import Broker from dxlclient.message import Event import demistomock as demisto from CommonServerPython import * from CommonServerUserPython import * INTEGRATION_NAME = "McAfee DXL" CONNECT_RETRIES = 1 RECONNECT_DELAY = 1 RECONNECT_DELAY_MAX = 10 class EventSender: TRUST_LEVEL = { 'NOT_SET': '0', 'KNOWN_MALICIOUS': '1', 'MOST_LIKELY_MALICIOUS': '15', 'MIGHT_BE_MALICIOUS': '30', 'UNKNOWN': '50', 'MIGHT_BE_TRUSTED': '70', 'MOST_LIKELY_TRUSTED': '85', 'KNOWN_TRUSTED': '99', 'KNOWN_TRUSTED_INSTALLER': '100' } broker_ca_bundle = tempfile.NamedTemporaryFile().name cert_file = tempfile.NamedTemporaryFile().name private_key = tempfile.NamedTemporaryFile().name def __init__(self, params: Dict): with open(self.broker_ca_bundle, "w") as text_file: text_file.write(params['broker_ca_bundle']) with open(self.cert_file, "w") as text_file: text_file.write(params['cert_file']) with open(self.private_key, "w") as text_file: text_file.write(params['private_key']) if 'broker_urls' in params: self.broker_urls = params['broker_urls'].split(',') self.push_ip_topic = params.get('push_ip_topic') self.push_url_topic = params.get('push_url_topic') self.push_domain_topic = params.get('push_domain_topic') self.push_hash_topic = params.get('push_hash_topic') self.client = DxlClient(self.get_client_config()) self.client.connect() def __del__(self): self.client.disconnect() def push_ip(self, ip, trust_level, topic): if not is_ip_valid(ip): raise ValueError(f'argument ip {ip} is not a valid IP') trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_ip_topic, f'ip:{ip};trust_level:{trust_level_key}') return f'Successfully pushed ip {ip} with trust level {trust_level}' def push_url(self, url, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_url_topic = topic self.send_event(self.push_url_topic, f'url:{url};trust_level:{trust_level_key}') return f'Successfully pushed url {url} with trust level {trust_level}' def push_domain(self, domain, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_domain_topic = topic self.send_event(self.push_domain_topic, f'domain:{domain};trust_level:{trust_level_key}') return f'Successfully pushed domain {domain} with trust level {trust_level}' def push_hash(self, hash_obj, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_hash_topic, f'hash:{hash_obj};trust_level:{trust_level_key}') return f'Successfully pushed hash {hash_obj} with trust level {trust_level}' def get_client_config(self): config = DxlClientConfig( broker_ca_bundle=self.broker_ca_bundle, cert_file=self.cert_file, private_key=self.private_key, brokers=[Broker.parse(url) for url in self.broker_urls] ) config.connect_retries = CONNECT_RETRIES config.reconnect_delay = RECONNECT_DELAY config.reconnect_delay_max = RECONNECT_DELAY_MAX return config def send_event(self, topic, payload): if not topic: raise Exception(f'Error in {demisto.command()} topic field is required') event = Event(topic) event.payload = str(payload).encode() self.client.send_event(event) def send_event_wrapper(self, topic, payload): self.send_event(topic, payload) return 'Successfully sent event' def validate_certificates_format(): if '-----BEGIN PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't start with -----BEGIN PRIVATE KEY-----") if '-----END PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't end with -----END PRIVATE KEY-----") if '-----BEGIN CERTIFICATE-----' not in demisto.params()['cert_file']: return_error("The client certificates content seem to be " "incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if '-----END CERTIFICATE-----' not in demisto.params()['cert_file']: return_error( "The client certificates content seem to be incorrect as it doesn't end with -----END CERTIFICATE-----") if not demisto.params()['broker_ca_bundle'].lstrip(" ").startswith('-----BEGIN CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if not demisto.params()['broker_ca_bundle'].rstrip(" ").endswith('-----END CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't end with '-----END CERTIFICATE-----'") def main(): args = demisto.args() command = demisto.command() try: event_sender = EventSender(demisto.params()) result = '' if command == 'test-module': event_sender.send_event('TEST', 'test') result = 'ok' elif command == 'dxl-send-event': result = event_sender.send_event_wrapper(args.get('topic'), args.get('payload')) elif command == 'dxl-push-ip': result = event_sender.push_ip(args.get('ip'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-url': result = event_sender.push_url(args.get('url'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-domain': result = event_sender.push_domain(args.get('domain'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-hash': result = event_sender.push_hash(args.get('hash'), args.get('trust_level'), args.get('topic')) else: <|fim_middle|> return_outputs(result) except Exception as error: validate_certificates_format() return_error(f'error in {INTEGRATION_NAME} {str(error)}.', error) if __name__ in ('__builtin__', 'builtins'): main() <|fim▁end|>
raise Exception(f'{demisto.command()} is not a command')
<|file_name|>McAfee_DXL.py<|end_file_name|><|fim▁begin|>from typing import Dict import tempfile from dxlclient.client_config import DxlClientConfig from dxlclient.client import DxlClient from dxlclient.broker import Broker from dxlclient.message import Event import demistomock as demisto from CommonServerPython import * from CommonServerUserPython import * INTEGRATION_NAME = "McAfee DXL" CONNECT_RETRIES = 1 RECONNECT_DELAY = 1 RECONNECT_DELAY_MAX = 10 class EventSender: TRUST_LEVEL = { 'NOT_SET': '0', 'KNOWN_MALICIOUS': '1', 'MOST_LIKELY_MALICIOUS': '15', 'MIGHT_BE_MALICIOUS': '30', 'UNKNOWN': '50', 'MIGHT_BE_TRUSTED': '70', 'MOST_LIKELY_TRUSTED': '85', 'KNOWN_TRUSTED': '99', 'KNOWN_TRUSTED_INSTALLER': '100' } broker_ca_bundle = tempfile.NamedTemporaryFile().name cert_file = tempfile.NamedTemporaryFile().name private_key = tempfile.NamedTemporaryFile().name def __init__(self, params: Dict): with open(self.broker_ca_bundle, "w") as text_file: text_file.write(params['broker_ca_bundle']) with open(self.cert_file, "w") as text_file: text_file.write(params['cert_file']) with open(self.private_key, "w") as text_file: text_file.write(params['private_key']) if 'broker_urls' in params: self.broker_urls = params['broker_urls'].split(',') self.push_ip_topic = params.get('push_ip_topic') self.push_url_topic = params.get('push_url_topic') self.push_domain_topic = params.get('push_domain_topic') self.push_hash_topic = params.get('push_hash_topic') self.client = DxlClient(self.get_client_config()) self.client.connect() def __del__(self): self.client.disconnect() def push_ip(self, ip, trust_level, topic): if not is_ip_valid(ip): raise ValueError(f'argument ip {ip} is not a valid IP') trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_ip_topic, f'ip:{ip};trust_level:{trust_level_key}') return f'Successfully pushed ip {ip} with trust level {trust_level}' def push_url(self, url, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_url_topic = topic self.send_event(self.push_url_topic, f'url:{url};trust_level:{trust_level_key}') return f'Successfully pushed url {url} with trust level {trust_level}' def push_domain(self, domain, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_domain_topic = topic self.send_event(self.push_domain_topic, f'domain:{domain};trust_level:{trust_level_key}') return f'Successfully pushed domain {domain} with trust level {trust_level}' def push_hash(self, hash_obj, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_hash_topic, f'hash:{hash_obj};trust_level:{trust_level_key}') return f'Successfully pushed hash {hash_obj} with trust level {trust_level}' def get_client_config(self): config = DxlClientConfig( broker_ca_bundle=self.broker_ca_bundle, cert_file=self.cert_file, private_key=self.private_key, brokers=[Broker.parse(url) for url in self.broker_urls] ) config.connect_retries = CONNECT_RETRIES config.reconnect_delay = RECONNECT_DELAY config.reconnect_delay_max = RECONNECT_DELAY_MAX return config def send_event(self, topic, payload): if not topic: raise Exception(f'Error in {demisto.command()} topic field is required') event = Event(topic) event.payload = str(payload).encode() self.client.send_event(event) def send_event_wrapper(self, topic, payload): self.send_event(topic, payload) return 'Successfully sent event' def validate_certificates_format(): if '-----BEGIN PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't start with -----BEGIN PRIVATE KEY-----") if '-----END PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't end with -----END PRIVATE KEY-----") if '-----BEGIN CERTIFICATE-----' not in demisto.params()['cert_file']: return_error("The client certificates content seem to be " "incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if '-----END CERTIFICATE-----' not in demisto.params()['cert_file']: return_error( "The client certificates content seem to be incorrect as it doesn't end with -----END CERTIFICATE-----") if not demisto.params()['broker_ca_bundle'].lstrip(" ").startswith('-----BEGIN CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if not demisto.params()['broker_ca_bundle'].rstrip(" ").endswith('-----END CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't end with '-----END CERTIFICATE-----'") def main(): args = demisto.args() command = demisto.command() try: event_sender = EventSender(demisto.params()) result = '' if command == 'test-module': event_sender.send_event('TEST', 'test') result = 'ok' elif command == 'dxl-send-event': result = event_sender.send_event_wrapper(args.get('topic'), args.get('payload')) elif command == 'dxl-push-ip': result = event_sender.push_ip(args.get('ip'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-url': result = event_sender.push_url(args.get('url'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-domain': result = event_sender.push_domain(args.get('domain'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-hash': result = event_sender.push_hash(args.get('hash'), args.get('trust_level'), args.get('topic')) else: raise Exception(f'{demisto.command()} is not a command') return_outputs(result) except Exception as error: validate_certificates_format() return_error(f'error in {INTEGRATION_NAME} {str(error)}.', error) if __name__ in ('__builtin__', 'builtins'): <|fim_middle|> <|fim▁end|>
main()
<|file_name|>McAfee_DXL.py<|end_file_name|><|fim▁begin|>from typing import Dict import tempfile from dxlclient.client_config import DxlClientConfig from dxlclient.client import DxlClient from dxlclient.broker import Broker from dxlclient.message import Event import demistomock as demisto from CommonServerPython import * from CommonServerUserPython import * INTEGRATION_NAME = "McAfee DXL" CONNECT_RETRIES = 1 RECONNECT_DELAY = 1 RECONNECT_DELAY_MAX = 10 class EventSender: TRUST_LEVEL = { 'NOT_SET': '0', 'KNOWN_MALICIOUS': '1', 'MOST_LIKELY_MALICIOUS': '15', 'MIGHT_BE_MALICIOUS': '30', 'UNKNOWN': '50', 'MIGHT_BE_TRUSTED': '70', 'MOST_LIKELY_TRUSTED': '85', 'KNOWN_TRUSTED': '99', 'KNOWN_TRUSTED_INSTALLER': '100' } broker_ca_bundle = tempfile.NamedTemporaryFile().name cert_file = tempfile.NamedTemporaryFile().name private_key = tempfile.NamedTemporaryFile().name def <|fim_middle|>(self, params: Dict): with open(self.broker_ca_bundle, "w") as text_file: text_file.write(params['broker_ca_bundle']) with open(self.cert_file, "w") as text_file: text_file.write(params['cert_file']) with open(self.private_key, "w") as text_file: text_file.write(params['private_key']) if 'broker_urls' in params: self.broker_urls = params['broker_urls'].split(',') self.push_ip_topic = params.get('push_ip_topic') self.push_url_topic = params.get('push_url_topic') self.push_domain_topic = params.get('push_domain_topic') self.push_hash_topic = params.get('push_hash_topic') self.client = DxlClient(self.get_client_config()) self.client.connect() def __del__(self): self.client.disconnect() def push_ip(self, ip, trust_level, topic): if not is_ip_valid(ip): raise ValueError(f'argument ip {ip} is not a valid IP') trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_ip_topic, f'ip:{ip};trust_level:{trust_level_key}') return f'Successfully pushed ip {ip} with trust level {trust_level}' def push_url(self, url, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_url_topic = topic self.send_event(self.push_url_topic, f'url:{url};trust_level:{trust_level_key}') return f'Successfully pushed url {url} with trust level {trust_level}' def push_domain(self, domain, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_domain_topic = topic self.send_event(self.push_domain_topic, f'domain:{domain};trust_level:{trust_level_key}') return f'Successfully pushed domain {domain} with trust level {trust_level}' def push_hash(self, hash_obj, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_hash_topic, f'hash:{hash_obj};trust_level:{trust_level_key}') return f'Successfully pushed hash {hash_obj} with trust level {trust_level}' def get_client_config(self): config = DxlClientConfig( broker_ca_bundle=self.broker_ca_bundle, cert_file=self.cert_file, private_key=self.private_key, brokers=[Broker.parse(url) for url in self.broker_urls] ) config.connect_retries = CONNECT_RETRIES config.reconnect_delay = RECONNECT_DELAY config.reconnect_delay_max = RECONNECT_DELAY_MAX return config def send_event(self, topic, payload): if not topic: raise Exception(f'Error in {demisto.command()} topic field is required') event = Event(topic) event.payload = str(payload).encode() self.client.send_event(event) def send_event_wrapper(self, topic, payload): self.send_event(topic, payload) return 'Successfully sent event' def validate_certificates_format(): if '-----BEGIN PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't start with -----BEGIN PRIVATE KEY-----") if '-----END PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't end with -----END PRIVATE KEY-----") if '-----BEGIN CERTIFICATE-----' not in demisto.params()['cert_file']: return_error("The client certificates content seem to be " "incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if '-----END CERTIFICATE-----' not in demisto.params()['cert_file']: return_error( "The client certificates content seem to be incorrect as it doesn't end with -----END CERTIFICATE-----") if not demisto.params()['broker_ca_bundle'].lstrip(" ").startswith('-----BEGIN CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if not demisto.params()['broker_ca_bundle'].rstrip(" ").endswith('-----END CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't end with '-----END CERTIFICATE-----'") def main(): args = demisto.args() command = demisto.command() try: event_sender = EventSender(demisto.params()) result = '' if command == 'test-module': event_sender.send_event('TEST', 'test') result = 'ok' elif command == 'dxl-send-event': result = event_sender.send_event_wrapper(args.get('topic'), args.get('payload')) elif command == 'dxl-push-ip': result = event_sender.push_ip(args.get('ip'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-url': result = event_sender.push_url(args.get('url'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-domain': result = event_sender.push_domain(args.get('domain'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-hash': result = event_sender.push_hash(args.get('hash'), args.get('trust_level'), args.get('topic')) else: raise Exception(f'{demisto.command()} is not a command') return_outputs(result) except Exception as error: validate_certificates_format() return_error(f'error in {INTEGRATION_NAME} {str(error)}.', error) if __name__ in ('__builtin__', 'builtins'): main() <|fim▁end|>
__init__
<|file_name|>McAfee_DXL.py<|end_file_name|><|fim▁begin|>from typing import Dict import tempfile from dxlclient.client_config import DxlClientConfig from dxlclient.client import DxlClient from dxlclient.broker import Broker from dxlclient.message import Event import demistomock as demisto from CommonServerPython import * from CommonServerUserPython import * INTEGRATION_NAME = "McAfee DXL" CONNECT_RETRIES = 1 RECONNECT_DELAY = 1 RECONNECT_DELAY_MAX = 10 class EventSender: TRUST_LEVEL = { 'NOT_SET': '0', 'KNOWN_MALICIOUS': '1', 'MOST_LIKELY_MALICIOUS': '15', 'MIGHT_BE_MALICIOUS': '30', 'UNKNOWN': '50', 'MIGHT_BE_TRUSTED': '70', 'MOST_LIKELY_TRUSTED': '85', 'KNOWN_TRUSTED': '99', 'KNOWN_TRUSTED_INSTALLER': '100' } broker_ca_bundle = tempfile.NamedTemporaryFile().name cert_file = tempfile.NamedTemporaryFile().name private_key = tempfile.NamedTemporaryFile().name def __init__(self, params: Dict): with open(self.broker_ca_bundle, "w") as text_file: text_file.write(params['broker_ca_bundle']) with open(self.cert_file, "w") as text_file: text_file.write(params['cert_file']) with open(self.private_key, "w") as text_file: text_file.write(params['private_key']) if 'broker_urls' in params: self.broker_urls = params['broker_urls'].split(',') self.push_ip_topic = params.get('push_ip_topic') self.push_url_topic = params.get('push_url_topic') self.push_domain_topic = params.get('push_domain_topic') self.push_hash_topic = params.get('push_hash_topic') self.client = DxlClient(self.get_client_config()) self.client.connect() def <|fim_middle|>(self): self.client.disconnect() def push_ip(self, ip, trust_level, topic): if not is_ip_valid(ip): raise ValueError(f'argument ip {ip} is not a valid IP') trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_ip_topic, f'ip:{ip};trust_level:{trust_level_key}') return f'Successfully pushed ip {ip} with trust level {trust_level}' def push_url(self, url, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_url_topic = topic self.send_event(self.push_url_topic, f'url:{url};trust_level:{trust_level_key}') return f'Successfully pushed url {url} with trust level {trust_level}' def push_domain(self, domain, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_domain_topic = topic self.send_event(self.push_domain_topic, f'domain:{domain};trust_level:{trust_level_key}') return f'Successfully pushed domain {domain} with trust level {trust_level}' def push_hash(self, hash_obj, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_hash_topic, f'hash:{hash_obj};trust_level:{trust_level_key}') return f'Successfully pushed hash {hash_obj} with trust level {trust_level}' def get_client_config(self): config = DxlClientConfig( broker_ca_bundle=self.broker_ca_bundle, cert_file=self.cert_file, private_key=self.private_key, brokers=[Broker.parse(url) for url in self.broker_urls] ) config.connect_retries = CONNECT_RETRIES config.reconnect_delay = RECONNECT_DELAY config.reconnect_delay_max = RECONNECT_DELAY_MAX return config def send_event(self, topic, payload): if not topic: raise Exception(f'Error in {demisto.command()} topic field is required') event = Event(topic) event.payload = str(payload).encode() self.client.send_event(event) def send_event_wrapper(self, topic, payload): self.send_event(topic, payload) return 'Successfully sent event' def validate_certificates_format(): if '-----BEGIN PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't start with -----BEGIN PRIVATE KEY-----") if '-----END PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't end with -----END PRIVATE KEY-----") if '-----BEGIN CERTIFICATE-----' not in demisto.params()['cert_file']: return_error("The client certificates content seem to be " "incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if '-----END CERTIFICATE-----' not in demisto.params()['cert_file']: return_error( "The client certificates content seem to be incorrect as it doesn't end with -----END CERTIFICATE-----") if not demisto.params()['broker_ca_bundle'].lstrip(" ").startswith('-----BEGIN CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if not demisto.params()['broker_ca_bundle'].rstrip(" ").endswith('-----END CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't end with '-----END CERTIFICATE-----'") def main(): args = demisto.args() command = demisto.command() try: event_sender = EventSender(demisto.params()) result = '' if command == 'test-module': event_sender.send_event('TEST', 'test') result = 'ok' elif command == 'dxl-send-event': result = event_sender.send_event_wrapper(args.get('topic'), args.get('payload')) elif command == 'dxl-push-ip': result = event_sender.push_ip(args.get('ip'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-url': result = event_sender.push_url(args.get('url'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-domain': result = event_sender.push_domain(args.get('domain'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-hash': result = event_sender.push_hash(args.get('hash'), args.get('trust_level'), args.get('topic')) else: raise Exception(f'{demisto.command()} is not a command') return_outputs(result) except Exception as error: validate_certificates_format() return_error(f'error in {INTEGRATION_NAME} {str(error)}.', error) if __name__ in ('__builtin__', 'builtins'): main() <|fim▁end|>
__del__
<|file_name|>McAfee_DXL.py<|end_file_name|><|fim▁begin|>from typing import Dict import tempfile from dxlclient.client_config import DxlClientConfig from dxlclient.client import DxlClient from dxlclient.broker import Broker from dxlclient.message import Event import demistomock as demisto from CommonServerPython import * from CommonServerUserPython import * INTEGRATION_NAME = "McAfee DXL" CONNECT_RETRIES = 1 RECONNECT_DELAY = 1 RECONNECT_DELAY_MAX = 10 class EventSender: TRUST_LEVEL = { 'NOT_SET': '0', 'KNOWN_MALICIOUS': '1', 'MOST_LIKELY_MALICIOUS': '15', 'MIGHT_BE_MALICIOUS': '30', 'UNKNOWN': '50', 'MIGHT_BE_TRUSTED': '70', 'MOST_LIKELY_TRUSTED': '85', 'KNOWN_TRUSTED': '99', 'KNOWN_TRUSTED_INSTALLER': '100' } broker_ca_bundle = tempfile.NamedTemporaryFile().name cert_file = tempfile.NamedTemporaryFile().name private_key = tempfile.NamedTemporaryFile().name def __init__(self, params: Dict): with open(self.broker_ca_bundle, "w") as text_file: text_file.write(params['broker_ca_bundle']) with open(self.cert_file, "w") as text_file: text_file.write(params['cert_file']) with open(self.private_key, "w") as text_file: text_file.write(params['private_key']) if 'broker_urls' in params: self.broker_urls = params['broker_urls'].split(',') self.push_ip_topic = params.get('push_ip_topic') self.push_url_topic = params.get('push_url_topic') self.push_domain_topic = params.get('push_domain_topic') self.push_hash_topic = params.get('push_hash_topic') self.client = DxlClient(self.get_client_config()) self.client.connect() def __del__(self): self.client.disconnect() def <|fim_middle|>(self, ip, trust_level, topic): if not is_ip_valid(ip): raise ValueError(f'argument ip {ip} is not a valid IP') trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_ip_topic, f'ip:{ip};trust_level:{trust_level_key}') return f'Successfully pushed ip {ip} with trust level {trust_level}' def push_url(self, url, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_url_topic = topic self.send_event(self.push_url_topic, f'url:{url};trust_level:{trust_level_key}') return f'Successfully pushed url {url} with trust level {trust_level}' def push_domain(self, domain, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_domain_topic = topic self.send_event(self.push_domain_topic, f'domain:{domain};trust_level:{trust_level_key}') return f'Successfully pushed domain {domain} with trust level {trust_level}' def push_hash(self, hash_obj, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_hash_topic, f'hash:{hash_obj};trust_level:{trust_level_key}') return f'Successfully pushed hash {hash_obj} with trust level {trust_level}' def get_client_config(self): config = DxlClientConfig( broker_ca_bundle=self.broker_ca_bundle, cert_file=self.cert_file, private_key=self.private_key, brokers=[Broker.parse(url) for url in self.broker_urls] ) config.connect_retries = CONNECT_RETRIES config.reconnect_delay = RECONNECT_DELAY config.reconnect_delay_max = RECONNECT_DELAY_MAX return config def send_event(self, topic, payload): if not topic: raise Exception(f'Error in {demisto.command()} topic field is required') event = Event(topic) event.payload = str(payload).encode() self.client.send_event(event) def send_event_wrapper(self, topic, payload): self.send_event(topic, payload) return 'Successfully sent event' def validate_certificates_format(): if '-----BEGIN PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't start with -----BEGIN PRIVATE KEY-----") if '-----END PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't end with -----END PRIVATE KEY-----") if '-----BEGIN CERTIFICATE-----' not in demisto.params()['cert_file']: return_error("The client certificates content seem to be " "incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if '-----END CERTIFICATE-----' not in demisto.params()['cert_file']: return_error( "The client certificates content seem to be incorrect as it doesn't end with -----END CERTIFICATE-----") if not demisto.params()['broker_ca_bundle'].lstrip(" ").startswith('-----BEGIN CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if not demisto.params()['broker_ca_bundle'].rstrip(" ").endswith('-----END CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't end with '-----END CERTIFICATE-----'") def main(): args = demisto.args() command = demisto.command() try: event_sender = EventSender(demisto.params()) result = '' if command == 'test-module': event_sender.send_event('TEST', 'test') result = 'ok' elif command == 'dxl-send-event': result = event_sender.send_event_wrapper(args.get('topic'), args.get('payload')) elif command == 'dxl-push-ip': result = event_sender.push_ip(args.get('ip'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-url': result = event_sender.push_url(args.get('url'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-domain': result = event_sender.push_domain(args.get('domain'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-hash': result = event_sender.push_hash(args.get('hash'), args.get('trust_level'), args.get('topic')) else: raise Exception(f'{demisto.command()} is not a command') return_outputs(result) except Exception as error: validate_certificates_format() return_error(f'error in {INTEGRATION_NAME} {str(error)}.', error) if __name__ in ('__builtin__', 'builtins'): main() <|fim▁end|>
push_ip
<|file_name|>McAfee_DXL.py<|end_file_name|><|fim▁begin|>from typing import Dict import tempfile from dxlclient.client_config import DxlClientConfig from dxlclient.client import DxlClient from dxlclient.broker import Broker from dxlclient.message import Event import demistomock as demisto from CommonServerPython import * from CommonServerUserPython import * INTEGRATION_NAME = "McAfee DXL" CONNECT_RETRIES = 1 RECONNECT_DELAY = 1 RECONNECT_DELAY_MAX = 10 class EventSender: TRUST_LEVEL = { 'NOT_SET': '0', 'KNOWN_MALICIOUS': '1', 'MOST_LIKELY_MALICIOUS': '15', 'MIGHT_BE_MALICIOUS': '30', 'UNKNOWN': '50', 'MIGHT_BE_TRUSTED': '70', 'MOST_LIKELY_TRUSTED': '85', 'KNOWN_TRUSTED': '99', 'KNOWN_TRUSTED_INSTALLER': '100' } broker_ca_bundle = tempfile.NamedTemporaryFile().name cert_file = tempfile.NamedTemporaryFile().name private_key = tempfile.NamedTemporaryFile().name def __init__(self, params: Dict): with open(self.broker_ca_bundle, "w") as text_file: text_file.write(params['broker_ca_bundle']) with open(self.cert_file, "w") as text_file: text_file.write(params['cert_file']) with open(self.private_key, "w") as text_file: text_file.write(params['private_key']) if 'broker_urls' in params: self.broker_urls = params['broker_urls'].split(',') self.push_ip_topic = params.get('push_ip_topic') self.push_url_topic = params.get('push_url_topic') self.push_domain_topic = params.get('push_domain_topic') self.push_hash_topic = params.get('push_hash_topic') self.client = DxlClient(self.get_client_config()) self.client.connect() def __del__(self): self.client.disconnect() def push_ip(self, ip, trust_level, topic): if not is_ip_valid(ip): raise ValueError(f'argument ip {ip} is not a valid IP') trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_ip_topic, f'ip:{ip};trust_level:{trust_level_key}') return f'Successfully pushed ip {ip} with trust level {trust_level}' def <|fim_middle|>(self, url, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_url_topic = topic self.send_event(self.push_url_topic, f'url:{url};trust_level:{trust_level_key}') return f'Successfully pushed url {url} with trust level {trust_level}' def push_domain(self, domain, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_domain_topic = topic self.send_event(self.push_domain_topic, f'domain:{domain};trust_level:{trust_level_key}') return f'Successfully pushed domain {domain} with trust level {trust_level}' def push_hash(self, hash_obj, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_hash_topic, f'hash:{hash_obj};trust_level:{trust_level_key}') return f'Successfully pushed hash {hash_obj} with trust level {trust_level}' def get_client_config(self): config = DxlClientConfig( broker_ca_bundle=self.broker_ca_bundle, cert_file=self.cert_file, private_key=self.private_key, brokers=[Broker.parse(url) for url in self.broker_urls] ) config.connect_retries = CONNECT_RETRIES config.reconnect_delay = RECONNECT_DELAY config.reconnect_delay_max = RECONNECT_DELAY_MAX return config def send_event(self, topic, payload): if not topic: raise Exception(f'Error in {demisto.command()} topic field is required') event = Event(topic) event.payload = str(payload).encode() self.client.send_event(event) def send_event_wrapper(self, topic, payload): self.send_event(topic, payload) return 'Successfully sent event' def validate_certificates_format(): if '-----BEGIN PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't start with -----BEGIN PRIVATE KEY-----") if '-----END PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't end with -----END PRIVATE KEY-----") if '-----BEGIN CERTIFICATE-----' not in demisto.params()['cert_file']: return_error("The client certificates content seem to be " "incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if '-----END CERTIFICATE-----' not in demisto.params()['cert_file']: return_error( "The client certificates content seem to be incorrect as it doesn't end with -----END CERTIFICATE-----") if not demisto.params()['broker_ca_bundle'].lstrip(" ").startswith('-----BEGIN CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if not demisto.params()['broker_ca_bundle'].rstrip(" ").endswith('-----END CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't end with '-----END CERTIFICATE-----'") def main(): args = demisto.args() command = demisto.command() try: event_sender = EventSender(demisto.params()) result = '' if command == 'test-module': event_sender.send_event('TEST', 'test') result = 'ok' elif command == 'dxl-send-event': result = event_sender.send_event_wrapper(args.get('topic'), args.get('payload')) elif command == 'dxl-push-ip': result = event_sender.push_ip(args.get('ip'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-url': result = event_sender.push_url(args.get('url'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-domain': result = event_sender.push_domain(args.get('domain'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-hash': result = event_sender.push_hash(args.get('hash'), args.get('trust_level'), args.get('topic')) else: raise Exception(f'{demisto.command()} is not a command') return_outputs(result) except Exception as error: validate_certificates_format() return_error(f'error in {INTEGRATION_NAME} {str(error)}.', error) if __name__ in ('__builtin__', 'builtins'): main() <|fim▁end|>
push_url
<|file_name|>McAfee_DXL.py<|end_file_name|><|fim▁begin|>from typing import Dict import tempfile from dxlclient.client_config import DxlClientConfig from dxlclient.client import DxlClient from dxlclient.broker import Broker from dxlclient.message import Event import demistomock as demisto from CommonServerPython import * from CommonServerUserPython import * INTEGRATION_NAME = "McAfee DXL" CONNECT_RETRIES = 1 RECONNECT_DELAY = 1 RECONNECT_DELAY_MAX = 10 class EventSender: TRUST_LEVEL = { 'NOT_SET': '0', 'KNOWN_MALICIOUS': '1', 'MOST_LIKELY_MALICIOUS': '15', 'MIGHT_BE_MALICIOUS': '30', 'UNKNOWN': '50', 'MIGHT_BE_TRUSTED': '70', 'MOST_LIKELY_TRUSTED': '85', 'KNOWN_TRUSTED': '99', 'KNOWN_TRUSTED_INSTALLER': '100' } broker_ca_bundle = tempfile.NamedTemporaryFile().name cert_file = tempfile.NamedTemporaryFile().name private_key = tempfile.NamedTemporaryFile().name def __init__(self, params: Dict): with open(self.broker_ca_bundle, "w") as text_file: text_file.write(params['broker_ca_bundle']) with open(self.cert_file, "w") as text_file: text_file.write(params['cert_file']) with open(self.private_key, "w") as text_file: text_file.write(params['private_key']) if 'broker_urls' in params: self.broker_urls = params['broker_urls'].split(',') self.push_ip_topic = params.get('push_ip_topic') self.push_url_topic = params.get('push_url_topic') self.push_domain_topic = params.get('push_domain_topic') self.push_hash_topic = params.get('push_hash_topic') self.client = DxlClient(self.get_client_config()) self.client.connect() def __del__(self): self.client.disconnect() def push_ip(self, ip, trust_level, topic): if not is_ip_valid(ip): raise ValueError(f'argument ip {ip} is not a valid IP') trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_ip_topic, f'ip:{ip};trust_level:{trust_level_key}') return f'Successfully pushed ip {ip} with trust level {trust_level}' def push_url(self, url, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_url_topic = topic self.send_event(self.push_url_topic, f'url:{url};trust_level:{trust_level_key}') return f'Successfully pushed url {url} with trust level {trust_level}' def <|fim_middle|>(self, domain, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_domain_topic = topic self.send_event(self.push_domain_topic, f'domain:{domain};trust_level:{trust_level_key}') return f'Successfully pushed domain {domain} with trust level {trust_level}' def push_hash(self, hash_obj, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_hash_topic, f'hash:{hash_obj};trust_level:{trust_level_key}') return f'Successfully pushed hash {hash_obj} with trust level {trust_level}' def get_client_config(self): config = DxlClientConfig( broker_ca_bundle=self.broker_ca_bundle, cert_file=self.cert_file, private_key=self.private_key, brokers=[Broker.parse(url) for url in self.broker_urls] ) config.connect_retries = CONNECT_RETRIES config.reconnect_delay = RECONNECT_DELAY config.reconnect_delay_max = RECONNECT_DELAY_MAX return config def send_event(self, topic, payload): if not topic: raise Exception(f'Error in {demisto.command()} topic field is required') event = Event(topic) event.payload = str(payload).encode() self.client.send_event(event) def send_event_wrapper(self, topic, payload): self.send_event(topic, payload) return 'Successfully sent event' def validate_certificates_format(): if '-----BEGIN PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't start with -----BEGIN PRIVATE KEY-----") if '-----END PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't end with -----END PRIVATE KEY-----") if '-----BEGIN CERTIFICATE-----' not in demisto.params()['cert_file']: return_error("The client certificates content seem to be " "incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if '-----END CERTIFICATE-----' not in demisto.params()['cert_file']: return_error( "The client certificates content seem to be incorrect as it doesn't end with -----END CERTIFICATE-----") if not demisto.params()['broker_ca_bundle'].lstrip(" ").startswith('-----BEGIN CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if not demisto.params()['broker_ca_bundle'].rstrip(" ").endswith('-----END CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't end with '-----END CERTIFICATE-----'") def main(): args = demisto.args() command = demisto.command() try: event_sender = EventSender(demisto.params()) result = '' if command == 'test-module': event_sender.send_event('TEST', 'test') result = 'ok' elif command == 'dxl-send-event': result = event_sender.send_event_wrapper(args.get('topic'), args.get('payload')) elif command == 'dxl-push-ip': result = event_sender.push_ip(args.get('ip'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-url': result = event_sender.push_url(args.get('url'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-domain': result = event_sender.push_domain(args.get('domain'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-hash': result = event_sender.push_hash(args.get('hash'), args.get('trust_level'), args.get('topic')) else: raise Exception(f'{demisto.command()} is not a command') return_outputs(result) except Exception as error: validate_certificates_format() return_error(f'error in {INTEGRATION_NAME} {str(error)}.', error) if __name__ in ('__builtin__', 'builtins'): main() <|fim▁end|>
push_domain
<|file_name|>McAfee_DXL.py<|end_file_name|><|fim▁begin|>from typing import Dict import tempfile from dxlclient.client_config import DxlClientConfig from dxlclient.client import DxlClient from dxlclient.broker import Broker from dxlclient.message import Event import demistomock as demisto from CommonServerPython import * from CommonServerUserPython import * INTEGRATION_NAME = "McAfee DXL" CONNECT_RETRIES = 1 RECONNECT_DELAY = 1 RECONNECT_DELAY_MAX = 10 class EventSender: TRUST_LEVEL = { 'NOT_SET': '0', 'KNOWN_MALICIOUS': '1', 'MOST_LIKELY_MALICIOUS': '15', 'MIGHT_BE_MALICIOUS': '30', 'UNKNOWN': '50', 'MIGHT_BE_TRUSTED': '70', 'MOST_LIKELY_TRUSTED': '85', 'KNOWN_TRUSTED': '99', 'KNOWN_TRUSTED_INSTALLER': '100' } broker_ca_bundle = tempfile.NamedTemporaryFile().name cert_file = tempfile.NamedTemporaryFile().name private_key = tempfile.NamedTemporaryFile().name def __init__(self, params: Dict): with open(self.broker_ca_bundle, "w") as text_file: text_file.write(params['broker_ca_bundle']) with open(self.cert_file, "w") as text_file: text_file.write(params['cert_file']) with open(self.private_key, "w") as text_file: text_file.write(params['private_key']) if 'broker_urls' in params: self.broker_urls = params['broker_urls'].split(',') self.push_ip_topic = params.get('push_ip_topic') self.push_url_topic = params.get('push_url_topic') self.push_domain_topic = params.get('push_domain_topic') self.push_hash_topic = params.get('push_hash_topic') self.client = DxlClient(self.get_client_config()) self.client.connect() def __del__(self): self.client.disconnect() def push_ip(self, ip, trust_level, topic): if not is_ip_valid(ip): raise ValueError(f'argument ip {ip} is not a valid IP') trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_ip_topic, f'ip:{ip};trust_level:{trust_level_key}') return f'Successfully pushed ip {ip} with trust level {trust_level}' def push_url(self, url, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_url_topic = topic self.send_event(self.push_url_topic, f'url:{url};trust_level:{trust_level_key}') return f'Successfully pushed url {url} with trust level {trust_level}' def push_domain(self, domain, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_domain_topic = topic self.send_event(self.push_domain_topic, f'domain:{domain};trust_level:{trust_level_key}') return f'Successfully pushed domain {domain} with trust level {trust_level}' def <|fim_middle|>(self, hash_obj, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_hash_topic, f'hash:{hash_obj};trust_level:{trust_level_key}') return f'Successfully pushed hash {hash_obj} with trust level {trust_level}' def get_client_config(self): config = DxlClientConfig( broker_ca_bundle=self.broker_ca_bundle, cert_file=self.cert_file, private_key=self.private_key, brokers=[Broker.parse(url) for url in self.broker_urls] ) config.connect_retries = CONNECT_RETRIES config.reconnect_delay = RECONNECT_DELAY config.reconnect_delay_max = RECONNECT_DELAY_MAX return config def send_event(self, topic, payload): if not topic: raise Exception(f'Error in {demisto.command()} topic field is required') event = Event(topic) event.payload = str(payload).encode() self.client.send_event(event) def send_event_wrapper(self, topic, payload): self.send_event(topic, payload) return 'Successfully sent event' def validate_certificates_format(): if '-----BEGIN PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't start with -----BEGIN PRIVATE KEY-----") if '-----END PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't end with -----END PRIVATE KEY-----") if '-----BEGIN CERTIFICATE-----' not in demisto.params()['cert_file']: return_error("The client certificates content seem to be " "incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if '-----END CERTIFICATE-----' not in demisto.params()['cert_file']: return_error( "The client certificates content seem to be incorrect as it doesn't end with -----END CERTIFICATE-----") if not demisto.params()['broker_ca_bundle'].lstrip(" ").startswith('-----BEGIN CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if not demisto.params()['broker_ca_bundle'].rstrip(" ").endswith('-----END CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't end with '-----END CERTIFICATE-----'") def main(): args = demisto.args() command = demisto.command() try: event_sender = EventSender(demisto.params()) result = '' if command == 'test-module': event_sender.send_event('TEST', 'test') result = 'ok' elif command == 'dxl-send-event': result = event_sender.send_event_wrapper(args.get('topic'), args.get('payload')) elif command == 'dxl-push-ip': result = event_sender.push_ip(args.get('ip'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-url': result = event_sender.push_url(args.get('url'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-domain': result = event_sender.push_domain(args.get('domain'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-hash': result = event_sender.push_hash(args.get('hash'), args.get('trust_level'), args.get('topic')) else: raise Exception(f'{demisto.command()} is not a command') return_outputs(result) except Exception as error: validate_certificates_format() return_error(f'error in {INTEGRATION_NAME} {str(error)}.', error) if __name__ in ('__builtin__', 'builtins'): main() <|fim▁end|>
push_hash
<|file_name|>McAfee_DXL.py<|end_file_name|><|fim▁begin|>from typing import Dict import tempfile from dxlclient.client_config import DxlClientConfig from dxlclient.client import DxlClient from dxlclient.broker import Broker from dxlclient.message import Event import demistomock as demisto from CommonServerPython import * from CommonServerUserPython import * INTEGRATION_NAME = "McAfee DXL" CONNECT_RETRIES = 1 RECONNECT_DELAY = 1 RECONNECT_DELAY_MAX = 10 class EventSender: TRUST_LEVEL = { 'NOT_SET': '0', 'KNOWN_MALICIOUS': '1', 'MOST_LIKELY_MALICIOUS': '15', 'MIGHT_BE_MALICIOUS': '30', 'UNKNOWN': '50', 'MIGHT_BE_TRUSTED': '70', 'MOST_LIKELY_TRUSTED': '85', 'KNOWN_TRUSTED': '99', 'KNOWN_TRUSTED_INSTALLER': '100' } broker_ca_bundle = tempfile.NamedTemporaryFile().name cert_file = tempfile.NamedTemporaryFile().name private_key = tempfile.NamedTemporaryFile().name def __init__(self, params: Dict): with open(self.broker_ca_bundle, "w") as text_file: text_file.write(params['broker_ca_bundle']) with open(self.cert_file, "w") as text_file: text_file.write(params['cert_file']) with open(self.private_key, "w") as text_file: text_file.write(params['private_key']) if 'broker_urls' in params: self.broker_urls = params['broker_urls'].split(',') self.push_ip_topic = params.get('push_ip_topic') self.push_url_topic = params.get('push_url_topic') self.push_domain_topic = params.get('push_domain_topic') self.push_hash_topic = params.get('push_hash_topic') self.client = DxlClient(self.get_client_config()) self.client.connect() def __del__(self): self.client.disconnect() def push_ip(self, ip, trust_level, topic): if not is_ip_valid(ip): raise ValueError(f'argument ip {ip} is not a valid IP') trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_ip_topic, f'ip:{ip};trust_level:{trust_level_key}') return f'Successfully pushed ip {ip} with trust level {trust_level}' def push_url(self, url, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_url_topic = topic self.send_event(self.push_url_topic, f'url:{url};trust_level:{trust_level_key}') return f'Successfully pushed url {url} with trust level {trust_level}' def push_domain(self, domain, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_domain_topic = topic self.send_event(self.push_domain_topic, f'domain:{domain};trust_level:{trust_level_key}') return f'Successfully pushed domain {domain} with trust level {trust_level}' def push_hash(self, hash_obj, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_hash_topic, f'hash:{hash_obj};trust_level:{trust_level_key}') return f'Successfully pushed hash {hash_obj} with trust level {trust_level}' def <|fim_middle|>(self): config = DxlClientConfig( broker_ca_bundle=self.broker_ca_bundle, cert_file=self.cert_file, private_key=self.private_key, brokers=[Broker.parse(url) for url in self.broker_urls] ) config.connect_retries = CONNECT_RETRIES config.reconnect_delay = RECONNECT_DELAY config.reconnect_delay_max = RECONNECT_DELAY_MAX return config def send_event(self, topic, payload): if not topic: raise Exception(f'Error in {demisto.command()} topic field is required') event = Event(topic) event.payload = str(payload).encode() self.client.send_event(event) def send_event_wrapper(self, topic, payload): self.send_event(topic, payload) return 'Successfully sent event' def validate_certificates_format(): if '-----BEGIN PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't start with -----BEGIN PRIVATE KEY-----") if '-----END PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't end with -----END PRIVATE KEY-----") if '-----BEGIN CERTIFICATE-----' not in demisto.params()['cert_file']: return_error("The client certificates content seem to be " "incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if '-----END CERTIFICATE-----' not in demisto.params()['cert_file']: return_error( "The client certificates content seem to be incorrect as it doesn't end with -----END CERTIFICATE-----") if not demisto.params()['broker_ca_bundle'].lstrip(" ").startswith('-----BEGIN CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if not demisto.params()['broker_ca_bundle'].rstrip(" ").endswith('-----END CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't end with '-----END CERTIFICATE-----'") def main(): args = demisto.args() command = demisto.command() try: event_sender = EventSender(demisto.params()) result = '' if command == 'test-module': event_sender.send_event('TEST', 'test') result = 'ok' elif command == 'dxl-send-event': result = event_sender.send_event_wrapper(args.get('topic'), args.get('payload')) elif command == 'dxl-push-ip': result = event_sender.push_ip(args.get('ip'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-url': result = event_sender.push_url(args.get('url'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-domain': result = event_sender.push_domain(args.get('domain'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-hash': result = event_sender.push_hash(args.get('hash'), args.get('trust_level'), args.get('topic')) else: raise Exception(f'{demisto.command()} is not a command') return_outputs(result) except Exception as error: validate_certificates_format() return_error(f'error in {INTEGRATION_NAME} {str(error)}.', error) if __name__ in ('__builtin__', 'builtins'): main() <|fim▁end|>
get_client_config
<|file_name|>McAfee_DXL.py<|end_file_name|><|fim▁begin|>from typing import Dict import tempfile from dxlclient.client_config import DxlClientConfig from dxlclient.client import DxlClient from dxlclient.broker import Broker from dxlclient.message import Event import demistomock as demisto from CommonServerPython import * from CommonServerUserPython import * INTEGRATION_NAME = "McAfee DXL" CONNECT_RETRIES = 1 RECONNECT_DELAY = 1 RECONNECT_DELAY_MAX = 10 class EventSender: TRUST_LEVEL = { 'NOT_SET': '0', 'KNOWN_MALICIOUS': '1', 'MOST_LIKELY_MALICIOUS': '15', 'MIGHT_BE_MALICIOUS': '30', 'UNKNOWN': '50', 'MIGHT_BE_TRUSTED': '70', 'MOST_LIKELY_TRUSTED': '85', 'KNOWN_TRUSTED': '99', 'KNOWN_TRUSTED_INSTALLER': '100' } broker_ca_bundle = tempfile.NamedTemporaryFile().name cert_file = tempfile.NamedTemporaryFile().name private_key = tempfile.NamedTemporaryFile().name def __init__(self, params: Dict): with open(self.broker_ca_bundle, "w") as text_file: text_file.write(params['broker_ca_bundle']) with open(self.cert_file, "w") as text_file: text_file.write(params['cert_file']) with open(self.private_key, "w") as text_file: text_file.write(params['private_key']) if 'broker_urls' in params: self.broker_urls = params['broker_urls'].split(',') self.push_ip_topic = params.get('push_ip_topic') self.push_url_topic = params.get('push_url_topic') self.push_domain_topic = params.get('push_domain_topic') self.push_hash_topic = params.get('push_hash_topic') self.client = DxlClient(self.get_client_config()) self.client.connect() def __del__(self): self.client.disconnect() def push_ip(self, ip, trust_level, topic): if not is_ip_valid(ip): raise ValueError(f'argument ip {ip} is not a valid IP') trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_ip_topic, f'ip:{ip};trust_level:{trust_level_key}') return f'Successfully pushed ip {ip} with trust level {trust_level}' def push_url(self, url, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_url_topic = topic self.send_event(self.push_url_topic, f'url:{url};trust_level:{trust_level_key}') return f'Successfully pushed url {url} with trust level {trust_level}' def push_domain(self, domain, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_domain_topic = topic self.send_event(self.push_domain_topic, f'domain:{domain};trust_level:{trust_level_key}') return f'Successfully pushed domain {domain} with trust level {trust_level}' def push_hash(self, hash_obj, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_hash_topic, f'hash:{hash_obj};trust_level:{trust_level_key}') return f'Successfully pushed hash {hash_obj} with trust level {trust_level}' def get_client_config(self): config = DxlClientConfig( broker_ca_bundle=self.broker_ca_bundle, cert_file=self.cert_file, private_key=self.private_key, brokers=[Broker.parse(url) for url in self.broker_urls] ) config.connect_retries = CONNECT_RETRIES config.reconnect_delay = RECONNECT_DELAY config.reconnect_delay_max = RECONNECT_DELAY_MAX return config def <|fim_middle|>(self, topic, payload): if not topic: raise Exception(f'Error in {demisto.command()} topic field is required') event = Event(topic) event.payload = str(payload).encode() self.client.send_event(event) def send_event_wrapper(self, topic, payload): self.send_event(topic, payload) return 'Successfully sent event' def validate_certificates_format(): if '-----BEGIN PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't start with -----BEGIN PRIVATE KEY-----") if '-----END PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't end with -----END PRIVATE KEY-----") if '-----BEGIN CERTIFICATE-----' not in demisto.params()['cert_file']: return_error("The client certificates content seem to be " "incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if '-----END CERTIFICATE-----' not in demisto.params()['cert_file']: return_error( "The client certificates content seem to be incorrect as it doesn't end with -----END CERTIFICATE-----") if not demisto.params()['broker_ca_bundle'].lstrip(" ").startswith('-----BEGIN CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if not demisto.params()['broker_ca_bundle'].rstrip(" ").endswith('-----END CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't end with '-----END CERTIFICATE-----'") def main(): args = demisto.args() command = demisto.command() try: event_sender = EventSender(demisto.params()) result = '' if command == 'test-module': event_sender.send_event('TEST', 'test') result = 'ok' elif command == 'dxl-send-event': result = event_sender.send_event_wrapper(args.get('topic'), args.get('payload')) elif command == 'dxl-push-ip': result = event_sender.push_ip(args.get('ip'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-url': result = event_sender.push_url(args.get('url'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-domain': result = event_sender.push_domain(args.get('domain'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-hash': result = event_sender.push_hash(args.get('hash'), args.get('trust_level'), args.get('topic')) else: raise Exception(f'{demisto.command()} is not a command') return_outputs(result) except Exception as error: validate_certificates_format() return_error(f'error in {INTEGRATION_NAME} {str(error)}.', error) if __name__ in ('__builtin__', 'builtins'): main() <|fim▁end|>
send_event
<|file_name|>McAfee_DXL.py<|end_file_name|><|fim▁begin|>from typing import Dict import tempfile from dxlclient.client_config import DxlClientConfig from dxlclient.client import DxlClient from dxlclient.broker import Broker from dxlclient.message import Event import demistomock as demisto from CommonServerPython import * from CommonServerUserPython import * INTEGRATION_NAME = "McAfee DXL" CONNECT_RETRIES = 1 RECONNECT_DELAY = 1 RECONNECT_DELAY_MAX = 10 class EventSender: TRUST_LEVEL = { 'NOT_SET': '0', 'KNOWN_MALICIOUS': '1', 'MOST_LIKELY_MALICIOUS': '15', 'MIGHT_BE_MALICIOUS': '30', 'UNKNOWN': '50', 'MIGHT_BE_TRUSTED': '70', 'MOST_LIKELY_TRUSTED': '85', 'KNOWN_TRUSTED': '99', 'KNOWN_TRUSTED_INSTALLER': '100' } broker_ca_bundle = tempfile.NamedTemporaryFile().name cert_file = tempfile.NamedTemporaryFile().name private_key = tempfile.NamedTemporaryFile().name def __init__(self, params: Dict): with open(self.broker_ca_bundle, "w") as text_file: text_file.write(params['broker_ca_bundle']) with open(self.cert_file, "w") as text_file: text_file.write(params['cert_file']) with open(self.private_key, "w") as text_file: text_file.write(params['private_key']) if 'broker_urls' in params: self.broker_urls = params['broker_urls'].split(',') self.push_ip_topic = params.get('push_ip_topic') self.push_url_topic = params.get('push_url_topic') self.push_domain_topic = params.get('push_domain_topic') self.push_hash_topic = params.get('push_hash_topic') self.client = DxlClient(self.get_client_config()) self.client.connect() def __del__(self): self.client.disconnect() def push_ip(self, ip, trust_level, topic): if not is_ip_valid(ip): raise ValueError(f'argument ip {ip} is not a valid IP') trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_ip_topic, f'ip:{ip};trust_level:{trust_level_key}') return f'Successfully pushed ip {ip} with trust level {trust_level}' def push_url(self, url, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_url_topic = topic self.send_event(self.push_url_topic, f'url:{url};trust_level:{trust_level_key}') return f'Successfully pushed url {url} with trust level {trust_level}' def push_domain(self, domain, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_domain_topic = topic self.send_event(self.push_domain_topic, f'domain:{domain};trust_level:{trust_level_key}') return f'Successfully pushed domain {domain} with trust level {trust_level}' def push_hash(self, hash_obj, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_hash_topic, f'hash:{hash_obj};trust_level:{trust_level_key}') return f'Successfully pushed hash {hash_obj} with trust level {trust_level}' def get_client_config(self): config = DxlClientConfig( broker_ca_bundle=self.broker_ca_bundle, cert_file=self.cert_file, private_key=self.private_key, brokers=[Broker.parse(url) for url in self.broker_urls] ) config.connect_retries = CONNECT_RETRIES config.reconnect_delay = RECONNECT_DELAY config.reconnect_delay_max = RECONNECT_DELAY_MAX return config def send_event(self, topic, payload): if not topic: raise Exception(f'Error in {demisto.command()} topic field is required') event = Event(topic) event.payload = str(payload).encode() self.client.send_event(event) def <|fim_middle|>(self, topic, payload): self.send_event(topic, payload) return 'Successfully sent event' def validate_certificates_format(): if '-----BEGIN PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't start with -----BEGIN PRIVATE KEY-----") if '-----END PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't end with -----END PRIVATE KEY-----") if '-----BEGIN CERTIFICATE-----' not in demisto.params()['cert_file']: return_error("The client certificates content seem to be " "incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if '-----END CERTIFICATE-----' not in demisto.params()['cert_file']: return_error( "The client certificates content seem to be incorrect as it doesn't end with -----END CERTIFICATE-----") if not demisto.params()['broker_ca_bundle'].lstrip(" ").startswith('-----BEGIN CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if not demisto.params()['broker_ca_bundle'].rstrip(" ").endswith('-----END CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't end with '-----END CERTIFICATE-----'") def main(): args = demisto.args() command = demisto.command() try: event_sender = EventSender(demisto.params()) result = '' if command == 'test-module': event_sender.send_event('TEST', 'test') result = 'ok' elif command == 'dxl-send-event': result = event_sender.send_event_wrapper(args.get('topic'), args.get('payload')) elif command == 'dxl-push-ip': result = event_sender.push_ip(args.get('ip'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-url': result = event_sender.push_url(args.get('url'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-domain': result = event_sender.push_domain(args.get('domain'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-hash': result = event_sender.push_hash(args.get('hash'), args.get('trust_level'), args.get('topic')) else: raise Exception(f'{demisto.command()} is not a command') return_outputs(result) except Exception as error: validate_certificates_format() return_error(f'error in {INTEGRATION_NAME} {str(error)}.', error) if __name__ in ('__builtin__', 'builtins'): main() <|fim▁end|>
send_event_wrapper
<|file_name|>McAfee_DXL.py<|end_file_name|><|fim▁begin|>from typing import Dict import tempfile from dxlclient.client_config import DxlClientConfig from dxlclient.client import DxlClient from dxlclient.broker import Broker from dxlclient.message import Event import demistomock as demisto from CommonServerPython import * from CommonServerUserPython import * INTEGRATION_NAME = "McAfee DXL" CONNECT_RETRIES = 1 RECONNECT_DELAY = 1 RECONNECT_DELAY_MAX = 10 class EventSender: TRUST_LEVEL = { 'NOT_SET': '0', 'KNOWN_MALICIOUS': '1', 'MOST_LIKELY_MALICIOUS': '15', 'MIGHT_BE_MALICIOUS': '30', 'UNKNOWN': '50', 'MIGHT_BE_TRUSTED': '70', 'MOST_LIKELY_TRUSTED': '85', 'KNOWN_TRUSTED': '99', 'KNOWN_TRUSTED_INSTALLER': '100' } broker_ca_bundle = tempfile.NamedTemporaryFile().name cert_file = tempfile.NamedTemporaryFile().name private_key = tempfile.NamedTemporaryFile().name def __init__(self, params: Dict): with open(self.broker_ca_bundle, "w") as text_file: text_file.write(params['broker_ca_bundle']) with open(self.cert_file, "w") as text_file: text_file.write(params['cert_file']) with open(self.private_key, "w") as text_file: text_file.write(params['private_key']) if 'broker_urls' in params: self.broker_urls = params['broker_urls'].split(',') self.push_ip_topic = params.get('push_ip_topic') self.push_url_topic = params.get('push_url_topic') self.push_domain_topic = params.get('push_domain_topic') self.push_hash_topic = params.get('push_hash_topic') self.client = DxlClient(self.get_client_config()) self.client.connect() def __del__(self): self.client.disconnect() def push_ip(self, ip, trust_level, topic): if not is_ip_valid(ip): raise ValueError(f'argument ip {ip} is not a valid IP') trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_ip_topic, f'ip:{ip};trust_level:{trust_level_key}') return f'Successfully pushed ip {ip} with trust level {trust_level}' def push_url(self, url, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_url_topic = topic self.send_event(self.push_url_topic, f'url:{url};trust_level:{trust_level_key}') return f'Successfully pushed url {url} with trust level {trust_level}' def push_domain(self, domain, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_domain_topic = topic self.send_event(self.push_domain_topic, f'domain:{domain};trust_level:{trust_level_key}') return f'Successfully pushed domain {domain} with trust level {trust_level}' def push_hash(self, hash_obj, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_hash_topic, f'hash:{hash_obj};trust_level:{trust_level_key}') return f'Successfully pushed hash {hash_obj} with trust level {trust_level}' def get_client_config(self): config = DxlClientConfig( broker_ca_bundle=self.broker_ca_bundle, cert_file=self.cert_file, private_key=self.private_key, brokers=[Broker.parse(url) for url in self.broker_urls] ) config.connect_retries = CONNECT_RETRIES config.reconnect_delay = RECONNECT_DELAY config.reconnect_delay_max = RECONNECT_DELAY_MAX return config def send_event(self, topic, payload): if not topic: raise Exception(f'Error in {demisto.command()} topic field is required') event = Event(topic) event.payload = str(payload).encode() self.client.send_event(event) def send_event_wrapper(self, topic, payload): self.send_event(topic, payload) return 'Successfully sent event' def <|fim_middle|>(): if '-----BEGIN PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't start with -----BEGIN PRIVATE KEY-----") if '-----END PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't end with -----END PRIVATE KEY-----") if '-----BEGIN CERTIFICATE-----' not in demisto.params()['cert_file']: return_error("The client certificates content seem to be " "incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if '-----END CERTIFICATE-----' not in demisto.params()['cert_file']: return_error( "The client certificates content seem to be incorrect as it doesn't end with -----END CERTIFICATE-----") if not demisto.params()['broker_ca_bundle'].lstrip(" ").startswith('-----BEGIN CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if not demisto.params()['broker_ca_bundle'].rstrip(" ").endswith('-----END CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't end with '-----END CERTIFICATE-----'") def main(): args = demisto.args() command = demisto.command() try: event_sender = EventSender(demisto.params()) result = '' if command == 'test-module': event_sender.send_event('TEST', 'test') result = 'ok' elif command == 'dxl-send-event': result = event_sender.send_event_wrapper(args.get('topic'), args.get('payload')) elif command == 'dxl-push-ip': result = event_sender.push_ip(args.get('ip'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-url': result = event_sender.push_url(args.get('url'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-domain': result = event_sender.push_domain(args.get('domain'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-hash': result = event_sender.push_hash(args.get('hash'), args.get('trust_level'), args.get('topic')) else: raise Exception(f'{demisto.command()} is not a command') return_outputs(result) except Exception as error: validate_certificates_format() return_error(f'error in {INTEGRATION_NAME} {str(error)}.', error) if __name__ in ('__builtin__', 'builtins'): main() <|fim▁end|>
validate_certificates_format
<|file_name|>McAfee_DXL.py<|end_file_name|><|fim▁begin|>from typing import Dict import tempfile from dxlclient.client_config import DxlClientConfig from dxlclient.client import DxlClient from dxlclient.broker import Broker from dxlclient.message import Event import demistomock as demisto from CommonServerPython import * from CommonServerUserPython import * INTEGRATION_NAME = "McAfee DXL" CONNECT_RETRIES = 1 RECONNECT_DELAY = 1 RECONNECT_DELAY_MAX = 10 class EventSender: TRUST_LEVEL = { 'NOT_SET': '0', 'KNOWN_MALICIOUS': '1', 'MOST_LIKELY_MALICIOUS': '15', 'MIGHT_BE_MALICIOUS': '30', 'UNKNOWN': '50', 'MIGHT_BE_TRUSTED': '70', 'MOST_LIKELY_TRUSTED': '85', 'KNOWN_TRUSTED': '99', 'KNOWN_TRUSTED_INSTALLER': '100' } broker_ca_bundle = tempfile.NamedTemporaryFile().name cert_file = tempfile.NamedTemporaryFile().name private_key = tempfile.NamedTemporaryFile().name def __init__(self, params: Dict): with open(self.broker_ca_bundle, "w") as text_file: text_file.write(params['broker_ca_bundle']) with open(self.cert_file, "w") as text_file: text_file.write(params['cert_file']) with open(self.private_key, "w") as text_file: text_file.write(params['private_key']) if 'broker_urls' in params: self.broker_urls = params['broker_urls'].split(',') self.push_ip_topic = params.get('push_ip_topic') self.push_url_topic = params.get('push_url_topic') self.push_domain_topic = params.get('push_domain_topic') self.push_hash_topic = params.get('push_hash_topic') self.client = DxlClient(self.get_client_config()) self.client.connect() def __del__(self): self.client.disconnect() def push_ip(self, ip, trust_level, topic): if not is_ip_valid(ip): raise ValueError(f'argument ip {ip} is not a valid IP') trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_ip_topic, f'ip:{ip};trust_level:{trust_level_key}') return f'Successfully pushed ip {ip} with trust level {trust_level}' def push_url(self, url, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_url_topic = topic self.send_event(self.push_url_topic, f'url:{url};trust_level:{trust_level_key}') return f'Successfully pushed url {url} with trust level {trust_level}' def push_domain(self, domain, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_domain_topic = topic self.send_event(self.push_domain_topic, f'domain:{domain};trust_level:{trust_level_key}') return f'Successfully pushed domain {domain} with trust level {trust_level}' def push_hash(self, hash_obj, trust_level, topic): trust_level_key = self.TRUST_LEVEL[trust_level] if topic: self.push_ip_topic = topic self.send_event(self.push_hash_topic, f'hash:{hash_obj};trust_level:{trust_level_key}') return f'Successfully pushed hash {hash_obj} with trust level {trust_level}' def get_client_config(self): config = DxlClientConfig( broker_ca_bundle=self.broker_ca_bundle, cert_file=self.cert_file, private_key=self.private_key, brokers=[Broker.parse(url) for url in self.broker_urls] ) config.connect_retries = CONNECT_RETRIES config.reconnect_delay = RECONNECT_DELAY config.reconnect_delay_max = RECONNECT_DELAY_MAX return config def send_event(self, topic, payload): if not topic: raise Exception(f'Error in {demisto.command()} topic field is required') event = Event(topic) event.payload = str(payload).encode() self.client.send_event(event) def send_event_wrapper(self, topic, payload): self.send_event(topic, payload) return 'Successfully sent event' def validate_certificates_format(): if '-----BEGIN PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't start with -----BEGIN PRIVATE KEY-----") if '-----END PRIVATE KEY-----' not in demisto.params()['private_key']: return_error( "The private key content seems to be incorrect as it doesn't end with -----END PRIVATE KEY-----") if '-----BEGIN CERTIFICATE-----' not in demisto.params()['cert_file']: return_error("The client certificates content seem to be " "incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if '-----END CERTIFICATE-----' not in demisto.params()['cert_file']: return_error( "The client certificates content seem to be incorrect as it doesn't end with -----END CERTIFICATE-----") if not demisto.params()['broker_ca_bundle'].lstrip(" ").startswith('-----BEGIN CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't start with '-----BEGIN CERTIFICATE-----'") if not demisto.params()['broker_ca_bundle'].rstrip(" ").endswith('-----END CERTIFICATE-----'): return_error( "The broker certificate seem to be incorrect as they don't end with '-----END CERTIFICATE-----'") def <|fim_middle|>(): args = demisto.args() command = demisto.command() try: event_sender = EventSender(demisto.params()) result = '' if command == 'test-module': event_sender.send_event('TEST', 'test') result = 'ok' elif command == 'dxl-send-event': result = event_sender.send_event_wrapper(args.get('topic'), args.get('payload')) elif command == 'dxl-push-ip': result = event_sender.push_ip(args.get('ip'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-url': result = event_sender.push_url(args.get('url'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-domain': result = event_sender.push_domain(args.get('domain'), args.get('trust_level'), args.get('topic')) elif command == 'dxl-push-hash': result = event_sender.push_hash(args.get('hash'), args.get('trust_level'), args.get('topic')) else: raise Exception(f'{demisto.command()} is not a command') return_outputs(result) except Exception as error: validate_certificates_format() return_error(f'error in {INTEGRATION_NAME} {str(error)}.', error) if __name__ in ('__builtin__', 'builtins'): main() <|fim▁end|>
main
<|file_name|>search_yt.py<|end_file_name|><|fim▁begin|>import urllib import urllib2 from bs4 import BeautifulSoup textToSearch = 'gorillaz' query = urllib.quote(textToSearch) url = "https://www.youtube.com/results?search_query=" + query response = urllib2.urlopen(url) html = response.read() soup = BeautifulSoup(html) for vid in soup.findAll(attrs={'class':'yt-uix-tile-link'}):<|fim▁hole|><|fim▁end|>
print 'https://www.youtube.com' + vid['href']
<|file_name|>kodi.py<|end_file_name|><|fim▁begin|>""" SALTS XBMC Addon Copyright (C) 2015 tknorris This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by<|fim▁hole|> the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import xbmcaddon import xbmcplugin import xbmcgui import xbmc import xbmcvfs import urllib import urlparse import sys import os import re addon = xbmcaddon.Addon() get_setting = addon.getSetting show_settings = addon.openSettings def get_path(): return addon.getAddonInfo('path').decode('utf-8') def get_profile(): return addon.getAddonInfo('profile').decode('utf-8') def translate_path(path): return xbmc.translatePath(path).decode('utf-8') def set_setting(id, value): if not isinstance(value, basestring): value = str(value) addon.setSetting(id, value) def get_version(): return addon.getAddonInfo('version') def get_id(): return addon.getAddonInfo('id') def get_name(): return addon.getAddonInfo('name') def get_plugin_url(queries): try: query = urllib.urlencode(queries) except UnicodeEncodeError: for k in queries: if isinstance(queries[k], unicode): queries[k] = queries[k].encode('utf-8') query = urllib.urlencode(queries) return sys.argv[0] + '?' + query def end_of_directory(cache_to_disc=True): xbmcplugin.endOfDirectory(int(sys.argv[1]), cacheToDisc=cache_to_disc) def set_content(content): xbmcplugin.setContent(int(sys.argv[1]), content) def create_item(queries, label, thumb='', fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): list_item = xbmcgui.ListItem(label, iconImage=thumb, thumbnailImage=thumb) add_item(queries, list_item, fanart, is_folder, is_playable, total_items, menu_items, replace_menu) def add_item(queries, list_item, fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): if menu_items is None: menu_items = [] if is_folder is None: is_folder = False if is_playable else True if is_playable is None: playable = 'false' if is_folder else 'true' else: playable = 'true' if is_playable else 'false' liz_url = get_plugin_url(queries) if fanart: list_item.setProperty('fanart_image', fanart) list_item.setInfo('video', {'title': list_item.getLabel()}) list_item.setProperty('isPlayable', playable) list_item.addContextMenuItems(menu_items, replaceItems=replace_menu) xbmcplugin.addDirectoryItem(int(sys.argv[1]), liz_url, list_item, isFolder=is_folder, totalItems=total_items) def parse_query(query): q = {'mode': 'main'} if query.startswith('?'): query = query[1:] queries = urlparse.parse_qs(query) for key in queries: if len(queries[key]) == 1: q[key] = queries[key][0] else: q[key] = queries[key] return q def notify(header=None, msg='', duration=2000, sound=None): if header is None: header = get_name() if sound is None: sound = get_setting('mute_notifications') == 'false' icon_path = os.path.join(get_path(), 'icon.png') try: xbmcgui.Dialog().notification(header, msg, icon_path, duration, sound) except: builtin = "XBMC.Notification(%s,%s, %s, %s)" % (header, msg, duration, icon_path) xbmc.executebuiltin(builtin) def get_current_view(): skinPath = translate_path('special://skin/') xml = os.path.join(skinPath, 'addon.xml') f = xbmcvfs.File(xml) read = f.read() f.close() try: src = re.search('defaultresolution="([^"]+)', read, re.DOTALL).group(1) except: src = re.search('<res.+?folder="([^"]+)', read, re.DOTALL).group(1) src = os.path.join(skinPath, src, 'MyVideoNav.xml') f = xbmcvfs.File(src) read = f.read() f.close() match = re.search('<views>([^<]+)', read, re.DOTALL) if match: views = match.group(1) for view in views.split(','): if xbmc.getInfoLabel('Control.GetLabel(%s)' % (view)): return view<|fim▁end|>
<|file_name|>kodi.py<|end_file_name|><|fim▁begin|>""" SALTS XBMC Addon Copyright (C) 2015 tknorris This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import xbmcaddon import xbmcplugin import xbmcgui import xbmc import xbmcvfs import urllib import urlparse import sys import os import re addon = xbmcaddon.Addon() get_setting = addon.getSetting show_settings = addon.openSettings def get_path(): <|fim_middle|> def get_profile(): return addon.getAddonInfo('profile').decode('utf-8') def translate_path(path): return xbmc.translatePath(path).decode('utf-8') def set_setting(id, value): if not isinstance(value, basestring): value = str(value) addon.setSetting(id, value) def get_version(): return addon.getAddonInfo('version') def get_id(): return addon.getAddonInfo('id') def get_name(): return addon.getAddonInfo('name') def get_plugin_url(queries): try: query = urllib.urlencode(queries) except UnicodeEncodeError: for k in queries: if isinstance(queries[k], unicode): queries[k] = queries[k].encode('utf-8') query = urllib.urlencode(queries) return sys.argv[0] + '?' + query def end_of_directory(cache_to_disc=True): xbmcplugin.endOfDirectory(int(sys.argv[1]), cacheToDisc=cache_to_disc) def set_content(content): xbmcplugin.setContent(int(sys.argv[1]), content) def create_item(queries, label, thumb='', fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): list_item = xbmcgui.ListItem(label, iconImage=thumb, thumbnailImage=thumb) add_item(queries, list_item, fanart, is_folder, is_playable, total_items, menu_items, replace_menu) def add_item(queries, list_item, fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): if menu_items is None: menu_items = [] if is_folder is None: is_folder = False if is_playable else True if is_playable is None: playable = 'false' if is_folder else 'true' else: playable = 'true' if is_playable else 'false' liz_url = get_plugin_url(queries) if fanart: list_item.setProperty('fanart_image', fanart) list_item.setInfo('video', {'title': list_item.getLabel()}) list_item.setProperty('isPlayable', playable) list_item.addContextMenuItems(menu_items, replaceItems=replace_menu) xbmcplugin.addDirectoryItem(int(sys.argv[1]), liz_url, list_item, isFolder=is_folder, totalItems=total_items) def parse_query(query): q = {'mode': 'main'} if query.startswith('?'): query = query[1:] queries = urlparse.parse_qs(query) for key in queries: if len(queries[key]) == 1: q[key] = queries[key][0] else: q[key] = queries[key] return q def notify(header=None, msg='', duration=2000, sound=None): if header is None: header = get_name() if sound is None: sound = get_setting('mute_notifications') == 'false' icon_path = os.path.join(get_path(), 'icon.png') try: xbmcgui.Dialog().notification(header, msg, icon_path, duration, sound) except: builtin = "XBMC.Notification(%s,%s, %s, %s)" % (header, msg, duration, icon_path) xbmc.executebuiltin(builtin) def get_current_view(): skinPath = translate_path('special://skin/') xml = os.path.join(skinPath, 'addon.xml') f = xbmcvfs.File(xml) read = f.read() f.close() try: src = re.search('defaultresolution="([^"]+)', read, re.DOTALL).group(1) except: src = re.search('<res.+?folder="([^"]+)', read, re.DOTALL).group(1) src = os.path.join(skinPath, src, 'MyVideoNav.xml') f = xbmcvfs.File(src) read = f.read() f.close() match = re.search('<views>([^<]+)', read, re.DOTALL) if match: views = match.group(1) for view in views.split(','): if xbmc.getInfoLabel('Control.GetLabel(%s)' % (view)): return view <|fim▁end|>
return addon.getAddonInfo('path').decode('utf-8')
<|file_name|>kodi.py<|end_file_name|><|fim▁begin|>""" SALTS XBMC Addon Copyright (C) 2015 tknorris This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import xbmcaddon import xbmcplugin import xbmcgui import xbmc import xbmcvfs import urllib import urlparse import sys import os import re addon = xbmcaddon.Addon() get_setting = addon.getSetting show_settings = addon.openSettings def get_path(): return addon.getAddonInfo('path').decode('utf-8') def get_profile(): <|fim_middle|> def translate_path(path): return xbmc.translatePath(path).decode('utf-8') def set_setting(id, value): if not isinstance(value, basestring): value = str(value) addon.setSetting(id, value) def get_version(): return addon.getAddonInfo('version') def get_id(): return addon.getAddonInfo('id') def get_name(): return addon.getAddonInfo('name') def get_plugin_url(queries): try: query = urllib.urlencode(queries) except UnicodeEncodeError: for k in queries: if isinstance(queries[k], unicode): queries[k] = queries[k].encode('utf-8') query = urllib.urlencode(queries) return sys.argv[0] + '?' + query def end_of_directory(cache_to_disc=True): xbmcplugin.endOfDirectory(int(sys.argv[1]), cacheToDisc=cache_to_disc) def set_content(content): xbmcplugin.setContent(int(sys.argv[1]), content) def create_item(queries, label, thumb='', fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): list_item = xbmcgui.ListItem(label, iconImage=thumb, thumbnailImage=thumb) add_item(queries, list_item, fanart, is_folder, is_playable, total_items, menu_items, replace_menu) def add_item(queries, list_item, fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): if menu_items is None: menu_items = [] if is_folder is None: is_folder = False if is_playable else True if is_playable is None: playable = 'false' if is_folder else 'true' else: playable = 'true' if is_playable else 'false' liz_url = get_plugin_url(queries) if fanart: list_item.setProperty('fanart_image', fanart) list_item.setInfo('video', {'title': list_item.getLabel()}) list_item.setProperty('isPlayable', playable) list_item.addContextMenuItems(menu_items, replaceItems=replace_menu) xbmcplugin.addDirectoryItem(int(sys.argv[1]), liz_url, list_item, isFolder=is_folder, totalItems=total_items) def parse_query(query): q = {'mode': 'main'} if query.startswith('?'): query = query[1:] queries = urlparse.parse_qs(query) for key in queries: if len(queries[key]) == 1: q[key] = queries[key][0] else: q[key] = queries[key] return q def notify(header=None, msg='', duration=2000, sound=None): if header is None: header = get_name() if sound is None: sound = get_setting('mute_notifications') == 'false' icon_path = os.path.join(get_path(), 'icon.png') try: xbmcgui.Dialog().notification(header, msg, icon_path, duration, sound) except: builtin = "XBMC.Notification(%s,%s, %s, %s)" % (header, msg, duration, icon_path) xbmc.executebuiltin(builtin) def get_current_view(): skinPath = translate_path('special://skin/') xml = os.path.join(skinPath, 'addon.xml') f = xbmcvfs.File(xml) read = f.read() f.close() try: src = re.search('defaultresolution="([^"]+)', read, re.DOTALL).group(1) except: src = re.search('<res.+?folder="([^"]+)', read, re.DOTALL).group(1) src = os.path.join(skinPath, src, 'MyVideoNav.xml') f = xbmcvfs.File(src) read = f.read() f.close() match = re.search('<views>([^<]+)', read, re.DOTALL) if match: views = match.group(1) for view in views.split(','): if xbmc.getInfoLabel('Control.GetLabel(%s)' % (view)): return view <|fim▁end|>
return addon.getAddonInfo('profile').decode('utf-8')
<|file_name|>kodi.py<|end_file_name|><|fim▁begin|>""" SALTS XBMC Addon Copyright (C) 2015 tknorris This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import xbmcaddon import xbmcplugin import xbmcgui import xbmc import xbmcvfs import urllib import urlparse import sys import os import re addon = xbmcaddon.Addon() get_setting = addon.getSetting show_settings = addon.openSettings def get_path(): return addon.getAddonInfo('path').decode('utf-8') def get_profile(): return addon.getAddonInfo('profile').decode('utf-8') def translate_path(path): <|fim_middle|> def set_setting(id, value): if not isinstance(value, basestring): value = str(value) addon.setSetting(id, value) def get_version(): return addon.getAddonInfo('version') def get_id(): return addon.getAddonInfo('id') def get_name(): return addon.getAddonInfo('name') def get_plugin_url(queries): try: query = urllib.urlencode(queries) except UnicodeEncodeError: for k in queries: if isinstance(queries[k], unicode): queries[k] = queries[k].encode('utf-8') query = urllib.urlencode(queries) return sys.argv[0] + '?' + query def end_of_directory(cache_to_disc=True): xbmcplugin.endOfDirectory(int(sys.argv[1]), cacheToDisc=cache_to_disc) def set_content(content): xbmcplugin.setContent(int(sys.argv[1]), content) def create_item(queries, label, thumb='', fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): list_item = xbmcgui.ListItem(label, iconImage=thumb, thumbnailImage=thumb) add_item(queries, list_item, fanart, is_folder, is_playable, total_items, menu_items, replace_menu) def add_item(queries, list_item, fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): if menu_items is None: menu_items = [] if is_folder is None: is_folder = False if is_playable else True if is_playable is None: playable = 'false' if is_folder else 'true' else: playable = 'true' if is_playable else 'false' liz_url = get_plugin_url(queries) if fanart: list_item.setProperty('fanart_image', fanart) list_item.setInfo('video', {'title': list_item.getLabel()}) list_item.setProperty('isPlayable', playable) list_item.addContextMenuItems(menu_items, replaceItems=replace_menu) xbmcplugin.addDirectoryItem(int(sys.argv[1]), liz_url, list_item, isFolder=is_folder, totalItems=total_items) def parse_query(query): q = {'mode': 'main'} if query.startswith('?'): query = query[1:] queries = urlparse.parse_qs(query) for key in queries: if len(queries[key]) == 1: q[key] = queries[key][0] else: q[key] = queries[key] return q def notify(header=None, msg='', duration=2000, sound=None): if header is None: header = get_name() if sound is None: sound = get_setting('mute_notifications') == 'false' icon_path = os.path.join(get_path(), 'icon.png') try: xbmcgui.Dialog().notification(header, msg, icon_path, duration, sound) except: builtin = "XBMC.Notification(%s,%s, %s, %s)" % (header, msg, duration, icon_path) xbmc.executebuiltin(builtin) def get_current_view(): skinPath = translate_path('special://skin/') xml = os.path.join(skinPath, 'addon.xml') f = xbmcvfs.File(xml) read = f.read() f.close() try: src = re.search('defaultresolution="([^"]+)', read, re.DOTALL).group(1) except: src = re.search('<res.+?folder="([^"]+)', read, re.DOTALL).group(1) src = os.path.join(skinPath, src, 'MyVideoNav.xml') f = xbmcvfs.File(src) read = f.read() f.close() match = re.search('<views>([^<]+)', read, re.DOTALL) if match: views = match.group(1) for view in views.split(','): if xbmc.getInfoLabel('Control.GetLabel(%s)' % (view)): return view <|fim▁end|>
return xbmc.translatePath(path).decode('utf-8')
<|file_name|>kodi.py<|end_file_name|><|fim▁begin|>""" SALTS XBMC Addon Copyright (C) 2015 tknorris This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import xbmcaddon import xbmcplugin import xbmcgui import xbmc import xbmcvfs import urllib import urlparse import sys import os import re addon = xbmcaddon.Addon() get_setting = addon.getSetting show_settings = addon.openSettings def get_path(): return addon.getAddonInfo('path').decode('utf-8') def get_profile(): return addon.getAddonInfo('profile').decode('utf-8') def translate_path(path): return xbmc.translatePath(path).decode('utf-8') def set_setting(id, value): <|fim_middle|> def get_version(): return addon.getAddonInfo('version') def get_id(): return addon.getAddonInfo('id') def get_name(): return addon.getAddonInfo('name') def get_plugin_url(queries): try: query = urllib.urlencode(queries) except UnicodeEncodeError: for k in queries: if isinstance(queries[k], unicode): queries[k] = queries[k].encode('utf-8') query = urllib.urlencode(queries) return sys.argv[0] + '?' + query def end_of_directory(cache_to_disc=True): xbmcplugin.endOfDirectory(int(sys.argv[1]), cacheToDisc=cache_to_disc) def set_content(content): xbmcplugin.setContent(int(sys.argv[1]), content) def create_item(queries, label, thumb='', fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): list_item = xbmcgui.ListItem(label, iconImage=thumb, thumbnailImage=thumb) add_item(queries, list_item, fanart, is_folder, is_playable, total_items, menu_items, replace_menu) def add_item(queries, list_item, fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): if menu_items is None: menu_items = [] if is_folder is None: is_folder = False if is_playable else True if is_playable is None: playable = 'false' if is_folder else 'true' else: playable = 'true' if is_playable else 'false' liz_url = get_plugin_url(queries) if fanart: list_item.setProperty('fanart_image', fanart) list_item.setInfo('video', {'title': list_item.getLabel()}) list_item.setProperty('isPlayable', playable) list_item.addContextMenuItems(menu_items, replaceItems=replace_menu) xbmcplugin.addDirectoryItem(int(sys.argv[1]), liz_url, list_item, isFolder=is_folder, totalItems=total_items) def parse_query(query): q = {'mode': 'main'} if query.startswith('?'): query = query[1:] queries = urlparse.parse_qs(query) for key in queries: if len(queries[key]) == 1: q[key] = queries[key][0] else: q[key] = queries[key] return q def notify(header=None, msg='', duration=2000, sound=None): if header is None: header = get_name() if sound is None: sound = get_setting('mute_notifications') == 'false' icon_path = os.path.join(get_path(), 'icon.png') try: xbmcgui.Dialog().notification(header, msg, icon_path, duration, sound) except: builtin = "XBMC.Notification(%s,%s, %s, %s)" % (header, msg, duration, icon_path) xbmc.executebuiltin(builtin) def get_current_view(): skinPath = translate_path('special://skin/') xml = os.path.join(skinPath, 'addon.xml') f = xbmcvfs.File(xml) read = f.read() f.close() try: src = re.search('defaultresolution="([^"]+)', read, re.DOTALL).group(1) except: src = re.search('<res.+?folder="([^"]+)', read, re.DOTALL).group(1) src = os.path.join(skinPath, src, 'MyVideoNav.xml') f = xbmcvfs.File(src) read = f.read() f.close() match = re.search('<views>([^<]+)', read, re.DOTALL) if match: views = match.group(1) for view in views.split(','): if xbmc.getInfoLabel('Control.GetLabel(%s)' % (view)): return view <|fim▁end|>
if not isinstance(value, basestring): value = str(value) addon.setSetting(id, value)
<|file_name|>kodi.py<|end_file_name|><|fim▁begin|>""" SALTS XBMC Addon Copyright (C) 2015 tknorris This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import xbmcaddon import xbmcplugin import xbmcgui import xbmc import xbmcvfs import urllib import urlparse import sys import os import re addon = xbmcaddon.Addon() get_setting = addon.getSetting show_settings = addon.openSettings def get_path(): return addon.getAddonInfo('path').decode('utf-8') def get_profile(): return addon.getAddonInfo('profile').decode('utf-8') def translate_path(path): return xbmc.translatePath(path).decode('utf-8') def set_setting(id, value): if not isinstance(value, basestring): value = str(value) addon.setSetting(id, value) def get_version(): <|fim_middle|> def get_id(): return addon.getAddonInfo('id') def get_name(): return addon.getAddonInfo('name') def get_plugin_url(queries): try: query = urllib.urlencode(queries) except UnicodeEncodeError: for k in queries: if isinstance(queries[k], unicode): queries[k] = queries[k].encode('utf-8') query = urllib.urlencode(queries) return sys.argv[0] + '?' + query def end_of_directory(cache_to_disc=True): xbmcplugin.endOfDirectory(int(sys.argv[1]), cacheToDisc=cache_to_disc) def set_content(content): xbmcplugin.setContent(int(sys.argv[1]), content) def create_item(queries, label, thumb='', fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): list_item = xbmcgui.ListItem(label, iconImage=thumb, thumbnailImage=thumb) add_item(queries, list_item, fanart, is_folder, is_playable, total_items, menu_items, replace_menu) def add_item(queries, list_item, fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): if menu_items is None: menu_items = [] if is_folder is None: is_folder = False if is_playable else True if is_playable is None: playable = 'false' if is_folder else 'true' else: playable = 'true' if is_playable else 'false' liz_url = get_plugin_url(queries) if fanart: list_item.setProperty('fanart_image', fanart) list_item.setInfo('video', {'title': list_item.getLabel()}) list_item.setProperty('isPlayable', playable) list_item.addContextMenuItems(menu_items, replaceItems=replace_menu) xbmcplugin.addDirectoryItem(int(sys.argv[1]), liz_url, list_item, isFolder=is_folder, totalItems=total_items) def parse_query(query): q = {'mode': 'main'} if query.startswith('?'): query = query[1:] queries = urlparse.parse_qs(query) for key in queries: if len(queries[key]) == 1: q[key] = queries[key][0] else: q[key] = queries[key] return q def notify(header=None, msg='', duration=2000, sound=None): if header is None: header = get_name() if sound is None: sound = get_setting('mute_notifications') == 'false' icon_path = os.path.join(get_path(), 'icon.png') try: xbmcgui.Dialog().notification(header, msg, icon_path, duration, sound) except: builtin = "XBMC.Notification(%s,%s, %s, %s)" % (header, msg, duration, icon_path) xbmc.executebuiltin(builtin) def get_current_view(): skinPath = translate_path('special://skin/') xml = os.path.join(skinPath, 'addon.xml') f = xbmcvfs.File(xml) read = f.read() f.close() try: src = re.search('defaultresolution="([^"]+)', read, re.DOTALL).group(1) except: src = re.search('<res.+?folder="([^"]+)', read, re.DOTALL).group(1) src = os.path.join(skinPath, src, 'MyVideoNav.xml') f = xbmcvfs.File(src) read = f.read() f.close() match = re.search('<views>([^<]+)', read, re.DOTALL) if match: views = match.group(1) for view in views.split(','): if xbmc.getInfoLabel('Control.GetLabel(%s)' % (view)): return view <|fim▁end|>
return addon.getAddonInfo('version')
<|file_name|>kodi.py<|end_file_name|><|fim▁begin|>""" SALTS XBMC Addon Copyright (C) 2015 tknorris This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import xbmcaddon import xbmcplugin import xbmcgui import xbmc import xbmcvfs import urllib import urlparse import sys import os import re addon = xbmcaddon.Addon() get_setting = addon.getSetting show_settings = addon.openSettings def get_path(): return addon.getAddonInfo('path').decode('utf-8') def get_profile(): return addon.getAddonInfo('profile').decode('utf-8') def translate_path(path): return xbmc.translatePath(path).decode('utf-8') def set_setting(id, value): if not isinstance(value, basestring): value = str(value) addon.setSetting(id, value) def get_version(): return addon.getAddonInfo('version') def get_id(): <|fim_middle|> def get_name(): return addon.getAddonInfo('name') def get_plugin_url(queries): try: query = urllib.urlencode(queries) except UnicodeEncodeError: for k in queries: if isinstance(queries[k], unicode): queries[k] = queries[k].encode('utf-8') query = urllib.urlencode(queries) return sys.argv[0] + '?' + query def end_of_directory(cache_to_disc=True): xbmcplugin.endOfDirectory(int(sys.argv[1]), cacheToDisc=cache_to_disc) def set_content(content): xbmcplugin.setContent(int(sys.argv[1]), content) def create_item(queries, label, thumb='', fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): list_item = xbmcgui.ListItem(label, iconImage=thumb, thumbnailImage=thumb) add_item(queries, list_item, fanart, is_folder, is_playable, total_items, menu_items, replace_menu) def add_item(queries, list_item, fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): if menu_items is None: menu_items = [] if is_folder is None: is_folder = False if is_playable else True if is_playable is None: playable = 'false' if is_folder else 'true' else: playable = 'true' if is_playable else 'false' liz_url = get_plugin_url(queries) if fanart: list_item.setProperty('fanart_image', fanart) list_item.setInfo('video', {'title': list_item.getLabel()}) list_item.setProperty('isPlayable', playable) list_item.addContextMenuItems(menu_items, replaceItems=replace_menu) xbmcplugin.addDirectoryItem(int(sys.argv[1]), liz_url, list_item, isFolder=is_folder, totalItems=total_items) def parse_query(query): q = {'mode': 'main'} if query.startswith('?'): query = query[1:] queries = urlparse.parse_qs(query) for key in queries: if len(queries[key]) == 1: q[key] = queries[key][0] else: q[key] = queries[key] return q def notify(header=None, msg='', duration=2000, sound=None): if header is None: header = get_name() if sound is None: sound = get_setting('mute_notifications') == 'false' icon_path = os.path.join(get_path(), 'icon.png') try: xbmcgui.Dialog().notification(header, msg, icon_path, duration, sound) except: builtin = "XBMC.Notification(%s,%s, %s, %s)" % (header, msg, duration, icon_path) xbmc.executebuiltin(builtin) def get_current_view(): skinPath = translate_path('special://skin/') xml = os.path.join(skinPath, 'addon.xml') f = xbmcvfs.File(xml) read = f.read() f.close() try: src = re.search('defaultresolution="([^"]+)', read, re.DOTALL).group(1) except: src = re.search('<res.+?folder="([^"]+)', read, re.DOTALL).group(1) src = os.path.join(skinPath, src, 'MyVideoNav.xml') f = xbmcvfs.File(src) read = f.read() f.close() match = re.search('<views>([^<]+)', read, re.DOTALL) if match: views = match.group(1) for view in views.split(','): if xbmc.getInfoLabel('Control.GetLabel(%s)' % (view)): return view <|fim▁end|>
return addon.getAddonInfo('id')
<|file_name|>kodi.py<|end_file_name|><|fim▁begin|>""" SALTS XBMC Addon Copyright (C) 2015 tknorris This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import xbmcaddon import xbmcplugin import xbmcgui import xbmc import xbmcvfs import urllib import urlparse import sys import os import re addon = xbmcaddon.Addon() get_setting = addon.getSetting show_settings = addon.openSettings def get_path(): return addon.getAddonInfo('path').decode('utf-8') def get_profile(): return addon.getAddonInfo('profile').decode('utf-8') def translate_path(path): return xbmc.translatePath(path).decode('utf-8') def set_setting(id, value): if not isinstance(value, basestring): value = str(value) addon.setSetting(id, value) def get_version(): return addon.getAddonInfo('version') def get_id(): return addon.getAddonInfo('id') def get_name(): <|fim_middle|> def get_plugin_url(queries): try: query = urllib.urlencode(queries) except UnicodeEncodeError: for k in queries: if isinstance(queries[k], unicode): queries[k] = queries[k].encode('utf-8') query = urllib.urlencode(queries) return sys.argv[0] + '?' + query def end_of_directory(cache_to_disc=True): xbmcplugin.endOfDirectory(int(sys.argv[1]), cacheToDisc=cache_to_disc) def set_content(content): xbmcplugin.setContent(int(sys.argv[1]), content) def create_item(queries, label, thumb='', fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): list_item = xbmcgui.ListItem(label, iconImage=thumb, thumbnailImage=thumb) add_item(queries, list_item, fanart, is_folder, is_playable, total_items, menu_items, replace_menu) def add_item(queries, list_item, fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): if menu_items is None: menu_items = [] if is_folder is None: is_folder = False if is_playable else True if is_playable is None: playable = 'false' if is_folder else 'true' else: playable = 'true' if is_playable else 'false' liz_url = get_plugin_url(queries) if fanart: list_item.setProperty('fanart_image', fanart) list_item.setInfo('video', {'title': list_item.getLabel()}) list_item.setProperty('isPlayable', playable) list_item.addContextMenuItems(menu_items, replaceItems=replace_menu) xbmcplugin.addDirectoryItem(int(sys.argv[1]), liz_url, list_item, isFolder=is_folder, totalItems=total_items) def parse_query(query): q = {'mode': 'main'} if query.startswith('?'): query = query[1:] queries = urlparse.parse_qs(query) for key in queries: if len(queries[key]) == 1: q[key] = queries[key][0] else: q[key] = queries[key] return q def notify(header=None, msg='', duration=2000, sound=None): if header is None: header = get_name() if sound is None: sound = get_setting('mute_notifications') == 'false' icon_path = os.path.join(get_path(), 'icon.png') try: xbmcgui.Dialog().notification(header, msg, icon_path, duration, sound) except: builtin = "XBMC.Notification(%s,%s, %s, %s)" % (header, msg, duration, icon_path) xbmc.executebuiltin(builtin) def get_current_view(): skinPath = translate_path('special://skin/') xml = os.path.join(skinPath, 'addon.xml') f = xbmcvfs.File(xml) read = f.read() f.close() try: src = re.search('defaultresolution="([^"]+)', read, re.DOTALL).group(1) except: src = re.search('<res.+?folder="([^"]+)', read, re.DOTALL).group(1) src = os.path.join(skinPath, src, 'MyVideoNav.xml') f = xbmcvfs.File(src) read = f.read() f.close() match = re.search('<views>([^<]+)', read, re.DOTALL) if match: views = match.group(1) for view in views.split(','): if xbmc.getInfoLabel('Control.GetLabel(%s)' % (view)): return view <|fim▁end|>
return addon.getAddonInfo('name')
<|file_name|>kodi.py<|end_file_name|><|fim▁begin|>""" SALTS XBMC Addon Copyright (C) 2015 tknorris This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import xbmcaddon import xbmcplugin import xbmcgui import xbmc import xbmcvfs import urllib import urlparse import sys import os import re addon = xbmcaddon.Addon() get_setting = addon.getSetting show_settings = addon.openSettings def get_path(): return addon.getAddonInfo('path').decode('utf-8') def get_profile(): return addon.getAddonInfo('profile').decode('utf-8') def translate_path(path): return xbmc.translatePath(path).decode('utf-8') def set_setting(id, value): if not isinstance(value, basestring): value = str(value) addon.setSetting(id, value) def get_version(): return addon.getAddonInfo('version') def get_id(): return addon.getAddonInfo('id') def get_name(): return addon.getAddonInfo('name') def get_plugin_url(queries): <|fim_middle|> def end_of_directory(cache_to_disc=True): xbmcplugin.endOfDirectory(int(sys.argv[1]), cacheToDisc=cache_to_disc) def set_content(content): xbmcplugin.setContent(int(sys.argv[1]), content) def create_item(queries, label, thumb='', fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): list_item = xbmcgui.ListItem(label, iconImage=thumb, thumbnailImage=thumb) add_item(queries, list_item, fanart, is_folder, is_playable, total_items, menu_items, replace_menu) def add_item(queries, list_item, fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): if menu_items is None: menu_items = [] if is_folder is None: is_folder = False if is_playable else True if is_playable is None: playable = 'false' if is_folder else 'true' else: playable = 'true' if is_playable else 'false' liz_url = get_plugin_url(queries) if fanart: list_item.setProperty('fanart_image', fanart) list_item.setInfo('video', {'title': list_item.getLabel()}) list_item.setProperty('isPlayable', playable) list_item.addContextMenuItems(menu_items, replaceItems=replace_menu) xbmcplugin.addDirectoryItem(int(sys.argv[1]), liz_url, list_item, isFolder=is_folder, totalItems=total_items) def parse_query(query): q = {'mode': 'main'} if query.startswith('?'): query = query[1:] queries = urlparse.parse_qs(query) for key in queries: if len(queries[key]) == 1: q[key] = queries[key][0] else: q[key] = queries[key] return q def notify(header=None, msg='', duration=2000, sound=None): if header is None: header = get_name() if sound is None: sound = get_setting('mute_notifications') == 'false' icon_path = os.path.join(get_path(), 'icon.png') try: xbmcgui.Dialog().notification(header, msg, icon_path, duration, sound) except: builtin = "XBMC.Notification(%s,%s, %s, %s)" % (header, msg, duration, icon_path) xbmc.executebuiltin(builtin) def get_current_view(): skinPath = translate_path('special://skin/') xml = os.path.join(skinPath, 'addon.xml') f = xbmcvfs.File(xml) read = f.read() f.close() try: src = re.search('defaultresolution="([^"]+)', read, re.DOTALL).group(1) except: src = re.search('<res.+?folder="([^"]+)', read, re.DOTALL).group(1) src = os.path.join(skinPath, src, 'MyVideoNav.xml') f = xbmcvfs.File(src) read = f.read() f.close() match = re.search('<views>([^<]+)', read, re.DOTALL) if match: views = match.group(1) for view in views.split(','): if xbmc.getInfoLabel('Control.GetLabel(%s)' % (view)): return view <|fim▁end|>
try: query = urllib.urlencode(queries) except UnicodeEncodeError: for k in queries: if isinstance(queries[k], unicode): queries[k] = queries[k].encode('utf-8') query = urllib.urlencode(queries) return sys.argv[0] + '?' + query
<|file_name|>kodi.py<|end_file_name|><|fim▁begin|>""" SALTS XBMC Addon Copyright (C) 2015 tknorris This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import xbmcaddon import xbmcplugin import xbmcgui import xbmc import xbmcvfs import urllib import urlparse import sys import os import re addon = xbmcaddon.Addon() get_setting = addon.getSetting show_settings = addon.openSettings def get_path(): return addon.getAddonInfo('path').decode('utf-8') def get_profile(): return addon.getAddonInfo('profile').decode('utf-8') def translate_path(path): return xbmc.translatePath(path).decode('utf-8') def set_setting(id, value): if not isinstance(value, basestring): value = str(value) addon.setSetting(id, value) def get_version(): return addon.getAddonInfo('version') def get_id(): return addon.getAddonInfo('id') def get_name(): return addon.getAddonInfo('name') def get_plugin_url(queries): try: query = urllib.urlencode(queries) except UnicodeEncodeError: for k in queries: if isinstance(queries[k], unicode): queries[k] = queries[k].encode('utf-8') query = urllib.urlencode(queries) return sys.argv[0] + '?' + query def end_of_directory(cache_to_disc=True): <|fim_middle|> def set_content(content): xbmcplugin.setContent(int(sys.argv[1]), content) def create_item(queries, label, thumb='', fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): list_item = xbmcgui.ListItem(label, iconImage=thumb, thumbnailImage=thumb) add_item(queries, list_item, fanart, is_folder, is_playable, total_items, menu_items, replace_menu) def add_item(queries, list_item, fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): if menu_items is None: menu_items = [] if is_folder is None: is_folder = False if is_playable else True if is_playable is None: playable = 'false' if is_folder else 'true' else: playable = 'true' if is_playable else 'false' liz_url = get_plugin_url(queries) if fanart: list_item.setProperty('fanart_image', fanart) list_item.setInfo('video', {'title': list_item.getLabel()}) list_item.setProperty('isPlayable', playable) list_item.addContextMenuItems(menu_items, replaceItems=replace_menu) xbmcplugin.addDirectoryItem(int(sys.argv[1]), liz_url, list_item, isFolder=is_folder, totalItems=total_items) def parse_query(query): q = {'mode': 'main'} if query.startswith('?'): query = query[1:] queries = urlparse.parse_qs(query) for key in queries: if len(queries[key]) == 1: q[key] = queries[key][0] else: q[key] = queries[key] return q def notify(header=None, msg='', duration=2000, sound=None): if header is None: header = get_name() if sound is None: sound = get_setting('mute_notifications') == 'false' icon_path = os.path.join(get_path(), 'icon.png') try: xbmcgui.Dialog().notification(header, msg, icon_path, duration, sound) except: builtin = "XBMC.Notification(%s,%s, %s, %s)" % (header, msg, duration, icon_path) xbmc.executebuiltin(builtin) def get_current_view(): skinPath = translate_path('special://skin/') xml = os.path.join(skinPath, 'addon.xml') f = xbmcvfs.File(xml) read = f.read() f.close() try: src = re.search('defaultresolution="([^"]+)', read, re.DOTALL).group(1) except: src = re.search('<res.+?folder="([^"]+)', read, re.DOTALL).group(1) src = os.path.join(skinPath, src, 'MyVideoNav.xml') f = xbmcvfs.File(src) read = f.read() f.close() match = re.search('<views>([^<]+)', read, re.DOTALL) if match: views = match.group(1) for view in views.split(','): if xbmc.getInfoLabel('Control.GetLabel(%s)' % (view)): return view <|fim▁end|>
xbmcplugin.endOfDirectory(int(sys.argv[1]), cacheToDisc=cache_to_disc)
<|file_name|>kodi.py<|end_file_name|><|fim▁begin|>""" SALTS XBMC Addon Copyright (C) 2015 tknorris This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import xbmcaddon import xbmcplugin import xbmcgui import xbmc import xbmcvfs import urllib import urlparse import sys import os import re addon = xbmcaddon.Addon() get_setting = addon.getSetting show_settings = addon.openSettings def get_path(): return addon.getAddonInfo('path').decode('utf-8') def get_profile(): return addon.getAddonInfo('profile').decode('utf-8') def translate_path(path): return xbmc.translatePath(path).decode('utf-8') def set_setting(id, value): if not isinstance(value, basestring): value = str(value) addon.setSetting(id, value) def get_version(): return addon.getAddonInfo('version') def get_id(): return addon.getAddonInfo('id') def get_name(): return addon.getAddonInfo('name') def get_plugin_url(queries): try: query = urllib.urlencode(queries) except UnicodeEncodeError: for k in queries: if isinstance(queries[k], unicode): queries[k] = queries[k].encode('utf-8') query = urllib.urlencode(queries) return sys.argv[0] + '?' + query def end_of_directory(cache_to_disc=True): xbmcplugin.endOfDirectory(int(sys.argv[1]), cacheToDisc=cache_to_disc) def set_content(content): <|fim_middle|> def create_item(queries, label, thumb='', fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): list_item = xbmcgui.ListItem(label, iconImage=thumb, thumbnailImage=thumb) add_item(queries, list_item, fanart, is_folder, is_playable, total_items, menu_items, replace_menu) def add_item(queries, list_item, fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): if menu_items is None: menu_items = [] if is_folder is None: is_folder = False if is_playable else True if is_playable is None: playable = 'false' if is_folder else 'true' else: playable = 'true' if is_playable else 'false' liz_url = get_plugin_url(queries) if fanart: list_item.setProperty('fanart_image', fanart) list_item.setInfo('video', {'title': list_item.getLabel()}) list_item.setProperty('isPlayable', playable) list_item.addContextMenuItems(menu_items, replaceItems=replace_menu) xbmcplugin.addDirectoryItem(int(sys.argv[1]), liz_url, list_item, isFolder=is_folder, totalItems=total_items) def parse_query(query): q = {'mode': 'main'} if query.startswith('?'): query = query[1:] queries = urlparse.parse_qs(query) for key in queries: if len(queries[key]) == 1: q[key] = queries[key][0] else: q[key] = queries[key] return q def notify(header=None, msg='', duration=2000, sound=None): if header is None: header = get_name() if sound is None: sound = get_setting('mute_notifications') == 'false' icon_path = os.path.join(get_path(), 'icon.png') try: xbmcgui.Dialog().notification(header, msg, icon_path, duration, sound) except: builtin = "XBMC.Notification(%s,%s, %s, %s)" % (header, msg, duration, icon_path) xbmc.executebuiltin(builtin) def get_current_view(): skinPath = translate_path('special://skin/') xml = os.path.join(skinPath, 'addon.xml') f = xbmcvfs.File(xml) read = f.read() f.close() try: src = re.search('defaultresolution="([^"]+)', read, re.DOTALL).group(1) except: src = re.search('<res.+?folder="([^"]+)', read, re.DOTALL).group(1) src = os.path.join(skinPath, src, 'MyVideoNav.xml') f = xbmcvfs.File(src) read = f.read() f.close() match = re.search('<views>([^<]+)', read, re.DOTALL) if match: views = match.group(1) for view in views.split(','): if xbmc.getInfoLabel('Control.GetLabel(%s)' % (view)): return view <|fim▁end|>
xbmcplugin.setContent(int(sys.argv[1]), content)
<|file_name|>kodi.py<|end_file_name|><|fim▁begin|>""" SALTS XBMC Addon Copyright (C) 2015 tknorris This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import xbmcaddon import xbmcplugin import xbmcgui import xbmc import xbmcvfs import urllib import urlparse import sys import os import re addon = xbmcaddon.Addon() get_setting = addon.getSetting show_settings = addon.openSettings def get_path(): return addon.getAddonInfo('path').decode('utf-8') def get_profile(): return addon.getAddonInfo('profile').decode('utf-8') def translate_path(path): return xbmc.translatePath(path).decode('utf-8') def set_setting(id, value): if not isinstance(value, basestring): value = str(value) addon.setSetting(id, value) def get_version(): return addon.getAddonInfo('version') def get_id(): return addon.getAddonInfo('id') def get_name(): return addon.getAddonInfo('name') def get_plugin_url(queries): try: query = urllib.urlencode(queries) except UnicodeEncodeError: for k in queries: if isinstance(queries[k], unicode): queries[k] = queries[k].encode('utf-8') query = urllib.urlencode(queries) return sys.argv[0] + '?' + query def end_of_directory(cache_to_disc=True): xbmcplugin.endOfDirectory(int(sys.argv[1]), cacheToDisc=cache_to_disc) def set_content(content): xbmcplugin.setContent(int(sys.argv[1]), content) def create_item(queries, label, thumb='', fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): <|fim_middle|> def add_item(queries, list_item, fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): if menu_items is None: menu_items = [] if is_folder is None: is_folder = False if is_playable else True if is_playable is None: playable = 'false' if is_folder else 'true' else: playable = 'true' if is_playable else 'false' liz_url = get_plugin_url(queries) if fanart: list_item.setProperty('fanart_image', fanart) list_item.setInfo('video', {'title': list_item.getLabel()}) list_item.setProperty('isPlayable', playable) list_item.addContextMenuItems(menu_items, replaceItems=replace_menu) xbmcplugin.addDirectoryItem(int(sys.argv[1]), liz_url, list_item, isFolder=is_folder, totalItems=total_items) def parse_query(query): q = {'mode': 'main'} if query.startswith('?'): query = query[1:] queries = urlparse.parse_qs(query) for key in queries: if len(queries[key]) == 1: q[key] = queries[key][0] else: q[key] = queries[key] return q def notify(header=None, msg='', duration=2000, sound=None): if header is None: header = get_name() if sound is None: sound = get_setting('mute_notifications') == 'false' icon_path = os.path.join(get_path(), 'icon.png') try: xbmcgui.Dialog().notification(header, msg, icon_path, duration, sound) except: builtin = "XBMC.Notification(%s,%s, %s, %s)" % (header, msg, duration, icon_path) xbmc.executebuiltin(builtin) def get_current_view(): skinPath = translate_path('special://skin/') xml = os.path.join(skinPath, 'addon.xml') f = xbmcvfs.File(xml) read = f.read() f.close() try: src = re.search('defaultresolution="([^"]+)', read, re.DOTALL).group(1) except: src = re.search('<res.+?folder="([^"]+)', read, re.DOTALL).group(1) src = os.path.join(skinPath, src, 'MyVideoNav.xml') f = xbmcvfs.File(src) read = f.read() f.close() match = re.search('<views>([^<]+)', read, re.DOTALL) if match: views = match.group(1) for view in views.split(','): if xbmc.getInfoLabel('Control.GetLabel(%s)' % (view)): return view <|fim▁end|>
list_item = xbmcgui.ListItem(label, iconImage=thumb, thumbnailImage=thumb) add_item(queries, list_item, fanart, is_folder, is_playable, total_items, menu_items, replace_menu)
<|file_name|>kodi.py<|end_file_name|><|fim▁begin|>""" SALTS XBMC Addon Copyright (C) 2015 tknorris This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import xbmcaddon import xbmcplugin import xbmcgui import xbmc import xbmcvfs import urllib import urlparse import sys import os import re addon = xbmcaddon.Addon() get_setting = addon.getSetting show_settings = addon.openSettings def get_path(): return addon.getAddonInfo('path').decode('utf-8') def get_profile(): return addon.getAddonInfo('profile').decode('utf-8') def translate_path(path): return xbmc.translatePath(path).decode('utf-8') def set_setting(id, value): if not isinstance(value, basestring): value = str(value) addon.setSetting(id, value) def get_version(): return addon.getAddonInfo('version') def get_id(): return addon.getAddonInfo('id') def get_name(): return addon.getAddonInfo('name') def get_plugin_url(queries): try: query = urllib.urlencode(queries) except UnicodeEncodeError: for k in queries: if isinstance(queries[k], unicode): queries[k] = queries[k].encode('utf-8') query = urllib.urlencode(queries) return sys.argv[0] + '?' + query def end_of_directory(cache_to_disc=True): xbmcplugin.endOfDirectory(int(sys.argv[1]), cacheToDisc=cache_to_disc) def set_content(content): xbmcplugin.setContent(int(sys.argv[1]), content) def create_item(queries, label, thumb='', fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): list_item = xbmcgui.ListItem(label, iconImage=thumb, thumbnailImage=thumb) add_item(queries, list_item, fanart, is_folder, is_playable, total_items, menu_items, replace_menu) def add_item(queries, list_item, fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): <|fim_middle|> def parse_query(query): q = {'mode': 'main'} if query.startswith('?'): query = query[1:] queries = urlparse.parse_qs(query) for key in queries: if len(queries[key]) == 1: q[key] = queries[key][0] else: q[key] = queries[key] return q def notify(header=None, msg='', duration=2000, sound=None): if header is None: header = get_name() if sound is None: sound = get_setting('mute_notifications') == 'false' icon_path = os.path.join(get_path(), 'icon.png') try: xbmcgui.Dialog().notification(header, msg, icon_path, duration, sound) except: builtin = "XBMC.Notification(%s,%s, %s, %s)" % (header, msg, duration, icon_path) xbmc.executebuiltin(builtin) def get_current_view(): skinPath = translate_path('special://skin/') xml = os.path.join(skinPath, 'addon.xml') f = xbmcvfs.File(xml) read = f.read() f.close() try: src = re.search('defaultresolution="([^"]+)', read, re.DOTALL).group(1) except: src = re.search('<res.+?folder="([^"]+)', read, re.DOTALL).group(1) src = os.path.join(skinPath, src, 'MyVideoNav.xml') f = xbmcvfs.File(src) read = f.read() f.close() match = re.search('<views>([^<]+)', read, re.DOTALL) if match: views = match.group(1) for view in views.split(','): if xbmc.getInfoLabel('Control.GetLabel(%s)' % (view)): return view <|fim▁end|>
if menu_items is None: menu_items = [] if is_folder is None: is_folder = False if is_playable else True if is_playable is None: playable = 'false' if is_folder else 'true' else: playable = 'true' if is_playable else 'false' liz_url = get_plugin_url(queries) if fanart: list_item.setProperty('fanart_image', fanart) list_item.setInfo('video', {'title': list_item.getLabel()}) list_item.setProperty('isPlayable', playable) list_item.addContextMenuItems(menu_items, replaceItems=replace_menu) xbmcplugin.addDirectoryItem(int(sys.argv[1]), liz_url, list_item, isFolder=is_folder, totalItems=total_items)
<|file_name|>kodi.py<|end_file_name|><|fim▁begin|>""" SALTS XBMC Addon Copyright (C) 2015 tknorris This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import xbmcaddon import xbmcplugin import xbmcgui import xbmc import xbmcvfs import urllib import urlparse import sys import os import re addon = xbmcaddon.Addon() get_setting = addon.getSetting show_settings = addon.openSettings def get_path(): return addon.getAddonInfo('path').decode('utf-8') def get_profile(): return addon.getAddonInfo('profile').decode('utf-8') def translate_path(path): return xbmc.translatePath(path).decode('utf-8') def set_setting(id, value): if not isinstance(value, basestring): value = str(value) addon.setSetting(id, value) def get_version(): return addon.getAddonInfo('version') def get_id(): return addon.getAddonInfo('id') def get_name(): return addon.getAddonInfo('name') def get_plugin_url(queries): try: query = urllib.urlencode(queries) except UnicodeEncodeError: for k in queries: if isinstance(queries[k], unicode): queries[k] = queries[k].encode('utf-8') query = urllib.urlencode(queries) return sys.argv[0] + '?' + query def end_of_directory(cache_to_disc=True): xbmcplugin.endOfDirectory(int(sys.argv[1]), cacheToDisc=cache_to_disc) def set_content(content): xbmcplugin.setContent(int(sys.argv[1]), content) def create_item(queries, label, thumb='', fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): list_item = xbmcgui.ListItem(label, iconImage=thumb, thumbnailImage=thumb) add_item(queries, list_item, fanart, is_folder, is_playable, total_items, menu_items, replace_menu) def add_item(queries, list_item, fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): if menu_items is None: menu_items = [] if is_folder is None: is_folder = False if is_playable else True if is_playable is None: playable = 'false' if is_folder else 'true' else: playable = 'true' if is_playable else 'false' liz_url = get_plugin_url(queries) if fanart: list_item.setProperty('fanart_image', fanart) list_item.setInfo('video', {'title': list_item.getLabel()}) list_item.setProperty('isPlayable', playable) list_item.addContextMenuItems(menu_items, replaceItems=replace_menu) xbmcplugin.addDirectoryItem(int(sys.argv[1]), liz_url, list_item, isFolder=is_folder, totalItems=total_items) def parse_query(query): <|fim_middle|> def notify(header=None, msg='', duration=2000, sound=None): if header is None: header = get_name() if sound is None: sound = get_setting('mute_notifications') == 'false' icon_path = os.path.join(get_path(), 'icon.png') try: xbmcgui.Dialog().notification(header, msg, icon_path, duration, sound) except: builtin = "XBMC.Notification(%s,%s, %s, %s)" % (header, msg, duration, icon_path) xbmc.executebuiltin(builtin) def get_current_view(): skinPath = translate_path('special://skin/') xml = os.path.join(skinPath, 'addon.xml') f = xbmcvfs.File(xml) read = f.read() f.close() try: src = re.search('defaultresolution="([^"]+)', read, re.DOTALL).group(1) except: src = re.search('<res.+?folder="([^"]+)', read, re.DOTALL).group(1) src = os.path.join(skinPath, src, 'MyVideoNav.xml') f = xbmcvfs.File(src) read = f.read() f.close() match = re.search('<views>([^<]+)', read, re.DOTALL) if match: views = match.group(1) for view in views.split(','): if xbmc.getInfoLabel('Control.GetLabel(%s)' % (view)): return view <|fim▁end|>
q = {'mode': 'main'} if query.startswith('?'): query = query[1:] queries = urlparse.parse_qs(query) for key in queries: if len(queries[key]) == 1: q[key] = queries[key][0] else: q[key] = queries[key] return q
<|file_name|>kodi.py<|end_file_name|><|fim▁begin|>""" SALTS XBMC Addon Copyright (C) 2015 tknorris This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import xbmcaddon import xbmcplugin import xbmcgui import xbmc import xbmcvfs import urllib import urlparse import sys import os import re addon = xbmcaddon.Addon() get_setting = addon.getSetting show_settings = addon.openSettings def get_path(): return addon.getAddonInfo('path').decode('utf-8') def get_profile(): return addon.getAddonInfo('profile').decode('utf-8') def translate_path(path): return xbmc.translatePath(path).decode('utf-8') def set_setting(id, value): if not isinstance(value, basestring): value = str(value) addon.setSetting(id, value) def get_version(): return addon.getAddonInfo('version') def get_id(): return addon.getAddonInfo('id') def get_name(): return addon.getAddonInfo('name') def get_plugin_url(queries): try: query = urllib.urlencode(queries) except UnicodeEncodeError: for k in queries: if isinstance(queries[k], unicode): queries[k] = queries[k].encode('utf-8') query = urllib.urlencode(queries) return sys.argv[0] + '?' + query def end_of_directory(cache_to_disc=True): xbmcplugin.endOfDirectory(int(sys.argv[1]), cacheToDisc=cache_to_disc) def set_content(content): xbmcplugin.setContent(int(sys.argv[1]), content) def create_item(queries, label, thumb='', fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): list_item = xbmcgui.ListItem(label, iconImage=thumb, thumbnailImage=thumb) add_item(queries, list_item, fanart, is_folder, is_playable, total_items, menu_items, replace_menu) def add_item(queries, list_item, fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): if menu_items is None: menu_items = [] if is_folder is None: is_folder = False if is_playable else True if is_playable is None: playable = 'false' if is_folder else 'true' else: playable = 'true' if is_playable else 'false' liz_url = get_plugin_url(queries) if fanart: list_item.setProperty('fanart_image', fanart) list_item.setInfo('video', {'title': list_item.getLabel()}) list_item.setProperty('isPlayable', playable) list_item.addContextMenuItems(menu_items, replaceItems=replace_menu) xbmcplugin.addDirectoryItem(int(sys.argv[1]), liz_url, list_item, isFolder=is_folder, totalItems=total_items) def parse_query(query): q = {'mode': 'main'} if query.startswith('?'): query = query[1:] queries = urlparse.parse_qs(query) for key in queries: if len(queries[key]) == 1: q[key] = queries[key][0] else: q[key] = queries[key] return q def notify(header=None, msg='', duration=2000, sound=None): <|fim_middle|> def get_current_view(): skinPath = translate_path('special://skin/') xml = os.path.join(skinPath, 'addon.xml') f = xbmcvfs.File(xml) read = f.read() f.close() try: src = re.search('defaultresolution="([^"]+)', read, re.DOTALL).group(1) except: src = re.search('<res.+?folder="([^"]+)', read, re.DOTALL).group(1) src = os.path.join(skinPath, src, 'MyVideoNav.xml') f = xbmcvfs.File(src) read = f.read() f.close() match = re.search('<views>([^<]+)', read, re.DOTALL) if match: views = match.group(1) for view in views.split(','): if xbmc.getInfoLabel('Control.GetLabel(%s)' % (view)): return view <|fim▁end|>
if header is None: header = get_name() if sound is None: sound = get_setting('mute_notifications') == 'false' icon_path = os.path.join(get_path(), 'icon.png') try: xbmcgui.Dialog().notification(header, msg, icon_path, duration, sound) except: builtin = "XBMC.Notification(%s,%s, %s, %s)" % (header, msg, duration, icon_path) xbmc.executebuiltin(builtin)
<|file_name|>kodi.py<|end_file_name|><|fim▁begin|>""" SALTS XBMC Addon Copyright (C) 2015 tknorris This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import xbmcaddon import xbmcplugin import xbmcgui import xbmc import xbmcvfs import urllib import urlparse import sys import os import re addon = xbmcaddon.Addon() get_setting = addon.getSetting show_settings = addon.openSettings def get_path(): return addon.getAddonInfo('path').decode('utf-8') def get_profile(): return addon.getAddonInfo('profile').decode('utf-8') def translate_path(path): return xbmc.translatePath(path).decode('utf-8') def set_setting(id, value): if not isinstance(value, basestring): value = str(value) addon.setSetting(id, value) def get_version(): return addon.getAddonInfo('version') def get_id(): return addon.getAddonInfo('id') def get_name(): return addon.getAddonInfo('name') def get_plugin_url(queries): try: query = urllib.urlencode(queries) except UnicodeEncodeError: for k in queries: if isinstance(queries[k], unicode): queries[k] = queries[k].encode('utf-8') query = urllib.urlencode(queries) return sys.argv[0] + '?' + query def end_of_directory(cache_to_disc=True): xbmcplugin.endOfDirectory(int(sys.argv[1]), cacheToDisc=cache_to_disc) def set_content(content): xbmcplugin.setContent(int(sys.argv[1]), content) def create_item(queries, label, thumb='', fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): list_item = xbmcgui.ListItem(label, iconImage=thumb, thumbnailImage=thumb) add_item(queries, list_item, fanart, is_folder, is_playable, total_items, menu_items, replace_menu) def add_item(queries, list_item, fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): if menu_items is None: menu_items = [] if is_folder is None: is_folder = False if is_playable else True if is_playable is None: playable = 'false' if is_folder else 'true' else: playable = 'true' if is_playable else 'false' liz_url = get_plugin_url(queries) if fanart: list_item.setProperty('fanart_image', fanart) list_item.setInfo('video', {'title': list_item.getLabel()}) list_item.setProperty('isPlayable', playable) list_item.addContextMenuItems(menu_items, replaceItems=replace_menu) xbmcplugin.addDirectoryItem(int(sys.argv[1]), liz_url, list_item, isFolder=is_folder, totalItems=total_items) def parse_query(query): q = {'mode': 'main'} if query.startswith('?'): query = query[1:] queries = urlparse.parse_qs(query) for key in queries: if len(queries[key]) == 1: q[key] = queries[key][0] else: q[key] = queries[key] return q def notify(header=None, msg='', duration=2000, sound=None): if header is None: header = get_name() if sound is None: sound = get_setting('mute_notifications') == 'false' icon_path = os.path.join(get_path(), 'icon.png') try: xbmcgui.Dialog().notification(header, msg, icon_path, duration, sound) except: builtin = "XBMC.Notification(%s,%s, %s, %s)" % (header, msg, duration, icon_path) xbmc.executebuiltin(builtin) def get_current_view(): <|fim_middle|> <|fim▁end|>
skinPath = translate_path('special://skin/') xml = os.path.join(skinPath, 'addon.xml') f = xbmcvfs.File(xml) read = f.read() f.close() try: src = re.search('defaultresolution="([^"]+)', read, re.DOTALL).group(1) except: src = re.search('<res.+?folder="([^"]+)', read, re.DOTALL).group(1) src = os.path.join(skinPath, src, 'MyVideoNav.xml') f = xbmcvfs.File(src) read = f.read() f.close() match = re.search('<views>([^<]+)', read, re.DOTALL) if match: views = match.group(1) for view in views.split(','): if xbmc.getInfoLabel('Control.GetLabel(%s)' % (view)): return view
<|file_name|>kodi.py<|end_file_name|><|fim▁begin|>""" SALTS XBMC Addon Copyright (C) 2015 tknorris This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import xbmcaddon import xbmcplugin import xbmcgui import xbmc import xbmcvfs import urllib import urlparse import sys import os import re addon = xbmcaddon.Addon() get_setting = addon.getSetting show_settings = addon.openSettings def get_path(): return addon.getAddonInfo('path').decode('utf-8') def get_profile(): return addon.getAddonInfo('profile').decode('utf-8') def translate_path(path): return xbmc.translatePath(path).decode('utf-8') def set_setting(id, value): if not isinstance(value, basestring): <|fim_middle|> addon.setSetting(id, value) def get_version(): return addon.getAddonInfo('version') def get_id(): return addon.getAddonInfo('id') def get_name(): return addon.getAddonInfo('name') def get_plugin_url(queries): try: query = urllib.urlencode(queries) except UnicodeEncodeError: for k in queries: if isinstance(queries[k], unicode): queries[k] = queries[k].encode('utf-8') query = urllib.urlencode(queries) return sys.argv[0] + '?' + query def end_of_directory(cache_to_disc=True): xbmcplugin.endOfDirectory(int(sys.argv[1]), cacheToDisc=cache_to_disc) def set_content(content): xbmcplugin.setContent(int(sys.argv[1]), content) def create_item(queries, label, thumb='', fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): list_item = xbmcgui.ListItem(label, iconImage=thumb, thumbnailImage=thumb) add_item(queries, list_item, fanart, is_folder, is_playable, total_items, menu_items, replace_menu) def add_item(queries, list_item, fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): if menu_items is None: menu_items = [] if is_folder is None: is_folder = False if is_playable else True if is_playable is None: playable = 'false' if is_folder else 'true' else: playable = 'true' if is_playable else 'false' liz_url = get_plugin_url(queries) if fanart: list_item.setProperty('fanart_image', fanart) list_item.setInfo('video', {'title': list_item.getLabel()}) list_item.setProperty('isPlayable', playable) list_item.addContextMenuItems(menu_items, replaceItems=replace_menu) xbmcplugin.addDirectoryItem(int(sys.argv[1]), liz_url, list_item, isFolder=is_folder, totalItems=total_items) def parse_query(query): q = {'mode': 'main'} if query.startswith('?'): query = query[1:] queries = urlparse.parse_qs(query) for key in queries: if len(queries[key]) == 1: q[key] = queries[key][0] else: q[key] = queries[key] return q def notify(header=None, msg='', duration=2000, sound=None): if header is None: header = get_name() if sound is None: sound = get_setting('mute_notifications') == 'false' icon_path = os.path.join(get_path(), 'icon.png') try: xbmcgui.Dialog().notification(header, msg, icon_path, duration, sound) except: builtin = "XBMC.Notification(%s,%s, %s, %s)" % (header, msg, duration, icon_path) xbmc.executebuiltin(builtin) def get_current_view(): skinPath = translate_path('special://skin/') xml = os.path.join(skinPath, 'addon.xml') f = xbmcvfs.File(xml) read = f.read() f.close() try: src = re.search('defaultresolution="([^"]+)', read, re.DOTALL).group(1) except: src = re.search('<res.+?folder="([^"]+)', read, re.DOTALL).group(1) src = os.path.join(skinPath, src, 'MyVideoNav.xml') f = xbmcvfs.File(src) read = f.read() f.close() match = re.search('<views>([^<]+)', read, re.DOTALL) if match: views = match.group(1) for view in views.split(','): if xbmc.getInfoLabel('Control.GetLabel(%s)' % (view)): return view <|fim▁end|>
value = str(value)
<|file_name|>kodi.py<|end_file_name|><|fim▁begin|>""" SALTS XBMC Addon Copyright (C) 2015 tknorris This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import xbmcaddon import xbmcplugin import xbmcgui import xbmc import xbmcvfs import urllib import urlparse import sys import os import re addon = xbmcaddon.Addon() get_setting = addon.getSetting show_settings = addon.openSettings def get_path(): return addon.getAddonInfo('path').decode('utf-8') def get_profile(): return addon.getAddonInfo('profile').decode('utf-8') def translate_path(path): return xbmc.translatePath(path).decode('utf-8') def set_setting(id, value): if not isinstance(value, basestring): value = str(value) addon.setSetting(id, value) def get_version(): return addon.getAddonInfo('version') def get_id(): return addon.getAddonInfo('id') def get_name(): return addon.getAddonInfo('name') def get_plugin_url(queries): try: query = urllib.urlencode(queries) except UnicodeEncodeError: for k in queries: if isinstance(queries[k], unicode): <|fim_middle|> query = urllib.urlencode(queries) return sys.argv[0] + '?' + query def end_of_directory(cache_to_disc=True): xbmcplugin.endOfDirectory(int(sys.argv[1]), cacheToDisc=cache_to_disc) def set_content(content): xbmcplugin.setContent(int(sys.argv[1]), content) def create_item(queries, label, thumb='', fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): list_item = xbmcgui.ListItem(label, iconImage=thumb, thumbnailImage=thumb) add_item(queries, list_item, fanart, is_folder, is_playable, total_items, menu_items, replace_menu) def add_item(queries, list_item, fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): if menu_items is None: menu_items = [] if is_folder is None: is_folder = False if is_playable else True if is_playable is None: playable = 'false' if is_folder else 'true' else: playable = 'true' if is_playable else 'false' liz_url = get_plugin_url(queries) if fanart: list_item.setProperty('fanart_image', fanart) list_item.setInfo('video', {'title': list_item.getLabel()}) list_item.setProperty('isPlayable', playable) list_item.addContextMenuItems(menu_items, replaceItems=replace_menu) xbmcplugin.addDirectoryItem(int(sys.argv[1]), liz_url, list_item, isFolder=is_folder, totalItems=total_items) def parse_query(query): q = {'mode': 'main'} if query.startswith('?'): query = query[1:] queries = urlparse.parse_qs(query) for key in queries: if len(queries[key]) == 1: q[key] = queries[key][0] else: q[key] = queries[key] return q def notify(header=None, msg='', duration=2000, sound=None): if header is None: header = get_name() if sound is None: sound = get_setting('mute_notifications') == 'false' icon_path = os.path.join(get_path(), 'icon.png') try: xbmcgui.Dialog().notification(header, msg, icon_path, duration, sound) except: builtin = "XBMC.Notification(%s,%s, %s, %s)" % (header, msg, duration, icon_path) xbmc.executebuiltin(builtin) def get_current_view(): skinPath = translate_path('special://skin/') xml = os.path.join(skinPath, 'addon.xml') f = xbmcvfs.File(xml) read = f.read() f.close() try: src = re.search('defaultresolution="([^"]+)', read, re.DOTALL).group(1) except: src = re.search('<res.+?folder="([^"]+)', read, re.DOTALL).group(1) src = os.path.join(skinPath, src, 'MyVideoNav.xml') f = xbmcvfs.File(src) read = f.read() f.close() match = re.search('<views>([^<]+)', read, re.DOTALL) if match: views = match.group(1) for view in views.split(','): if xbmc.getInfoLabel('Control.GetLabel(%s)' % (view)): return view <|fim▁end|>
queries[k] = queries[k].encode('utf-8')
<|file_name|>kodi.py<|end_file_name|><|fim▁begin|>""" SALTS XBMC Addon Copyright (C) 2015 tknorris This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import xbmcaddon import xbmcplugin import xbmcgui import xbmc import xbmcvfs import urllib import urlparse import sys import os import re addon = xbmcaddon.Addon() get_setting = addon.getSetting show_settings = addon.openSettings def get_path(): return addon.getAddonInfo('path').decode('utf-8') def get_profile(): return addon.getAddonInfo('profile').decode('utf-8') def translate_path(path): return xbmc.translatePath(path).decode('utf-8') def set_setting(id, value): if not isinstance(value, basestring): value = str(value) addon.setSetting(id, value) def get_version(): return addon.getAddonInfo('version') def get_id(): return addon.getAddonInfo('id') def get_name(): return addon.getAddonInfo('name') def get_plugin_url(queries): try: query = urllib.urlencode(queries) except UnicodeEncodeError: for k in queries: if isinstance(queries[k], unicode): queries[k] = queries[k].encode('utf-8') query = urllib.urlencode(queries) return sys.argv[0] + '?' + query def end_of_directory(cache_to_disc=True): xbmcplugin.endOfDirectory(int(sys.argv[1]), cacheToDisc=cache_to_disc) def set_content(content): xbmcplugin.setContent(int(sys.argv[1]), content) def create_item(queries, label, thumb='', fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): list_item = xbmcgui.ListItem(label, iconImage=thumb, thumbnailImage=thumb) add_item(queries, list_item, fanart, is_folder, is_playable, total_items, menu_items, replace_menu) def add_item(queries, list_item, fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): if menu_items is None: <|fim_middle|> if is_folder is None: is_folder = False if is_playable else True if is_playable is None: playable = 'false' if is_folder else 'true' else: playable = 'true' if is_playable else 'false' liz_url = get_plugin_url(queries) if fanart: list_item.setProperty('fanart_image', fanart) list_item.setInfo('video', {'title': list_item.getLabel()}) list_item.setProperty('isPlayable', playable) list_item.addContextMenuItems(menu_items, replaceItems=replace_menu) xbmcplugin.addDirectoryItem(int(sys.argv[1]), liz_url, list_item, isFolder=is_folder, totalItems=total_items) def parse_query(query): q = {'mode': 'main'} if query.startswith('?'): query = query[1:] queries = urlparse.parse_qs(query) for key in queries: if len(queries[key]) == 1: q[key] = queries[key][0] else: q[key] = queries[key] return q def notify(header=None, msg='', duration=2000, sound=None): if header is None: header = get_name() if sound is None: sound = get_setting('mute_notifications') == 'false' icon_path = os.path.join(get_path(), 'icon.png') try: xbmcgui.Dialog().notification(header, msg, icon_path, duration, sound) except: builtin = "XBMC.Notification(%s,%s, %s, %s)" % (header, msg, duration, icon_path) xbmc.executebuiltin(builtin) def get_current_view(): skinPath = translate_path('special://skin/') xml = os.path.join(skinPath, 'addon.xml') f = xbmcvfs.File(xml) read = f.read() f.close() try: src = re.search('defaultresolution="([^"]+)', read, re.DOTALL).group(1) except: src = re.search('<res.+?folder="([^"]+)', read, re.DOTALL).group(1) src = os.path.join(skinPath, src, 'MyVideoNav.xml') f = xbmcvfs.File(src) read = f.read() f.close() match = re.search('<views>([^<]+)', read, re.DOTALL) if match: views = match.group(1) for view in views.split(','): if xbmc.getInfoLabel('Control.GetLabel(%s)' % (view)): return view <|fim▁end|>
menu_items = []
<|file_name|>kodi.py<|end_file_name|><|fim▁begin|>""" SALTS XBMC Addon Copyright (C) 2015 tknorris This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import xbmcaddon import xbmcplugin import xbmcgui import xbmc import xbmcvfs import urllib import urlparse import sys import os import re addon = xbmcaddon.Addon() get_setting = addon.getSetting show_settings = addon.openSettings def get_path(): return addon.getAddonInfo('path').decode('utf-8') def get_profile(): return addon.getAddonInfo('profile').decode('utf-8') def translate_path(path): return xbmc.translatePath(path).decode('utf-8') def set_setting(id, value): if not isinstance(value, basestring): value = str(value) addon.setSetting(id, value) def get_version(): return addon.getAddonInfo('version') def get_id(): return addon.getAddonInfo('id') def get_name(): return addon.getAddonInfo('name') def get_plugin_url(queries): try: query = urllib.urlencode(queries) except UnicodeEncodeError: for k in queries: if isinstance(queries[k], unicode): queries[k] = queries[k].encode('utf-8') query = urllib.urlencode(queries) return sys.argv[0] + '?' + query def end_of_directory(cache_to_disc=True): xbmcplugin.endOfDirectory(int(sys.argv[1]), cacheToDisc=cache_to_disc) def set_content(content): xbmcplugin.setContent(int(sys.argv[1]), content) def create_item(queries, label, thumb='', fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): list_item = xbmcgui.ListItem(label, iconImage=thumb, thumbnailImage=thumb) add_item(queries, list_item, fanart, is_folder, is_playable, total_items, menu_items, replace_menu) def add_item(queries, list_item, fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): if menu_items is None: menu_items = [] if is_folder is None: <|fim_middle|> if is_playable is None: playable = 'false' if is_folder else 'true' else: playable = 'true' if is_playable else 'false' liz_url = get_plugin_url(queries) if fanart: list_item.setProperty('fanart_image', fanart) list_item.setInfo('video', {'title': list_item.getLabel()}) list_item.setProperty('isPlayable', playable) list_item.addContextMenuItems(menu_items, replaceItems=replace_menu) xbmcplugin.addDirectoryItem(int(sys.argv[1]), liz_url, list_item, isFolder=is_folder, totalItems=total_items) def parse_query(query): q = {'mode': 'main'} if query.startswith('?'): query = query[1:] queries = urlparse.parse_qs(query) for key in queries: if len(queries[key]) == 1: q[key] = queries[key][0] else: q[key] = queries[key] return q def notify(header=None, msg='', duration=2000, sound=None): if header is None: header = get_name() if sound is None: sound = get_setting('mute_notifications') == 'false' icon_path = os.path.join(get_path(), 'icon.png') try: xbmcgui.Dialog().notification(header, msg, icon_path, duration, sound) except: builtin = "XBMC.Notification(%s,%s, %s, %s)" % (header, msg, duration, icon_path) xbmc.executebuiltin(builtin) def get_current_view(): skinPath = translate_path('special://skin/') xml = os.path.join(skinPath, 'addon.xml') f = xbmcvfs.File(xml) read = f.read() f.close() try: src = re.search('defaultresolution="([^"]+)', read, re.DOTALL).group(1) except: src = re.search('<res.+?folder="([^"]+)', read, re.DOTALL).group(1) src = os.path.join(skinPath, src, 'MyVideoNav.xml') f = xbmcvfs.File(src) read = f.read() f.close() match = re.search('<views>([^<]+)', read, re.DOTALL) if match: views = match.group(1) for view in views.split(','): if xbmc.getInfoLabel('Control.GetLabel(%s)' % (view)): return view <|fim▁end|>
is_folder = False if is_playable else True
<|file_name|>kodi.py<|end_file_name|><|fim▁begin|>""" SALTS XBMC Addon Copyright (C) 2015 tknorris This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import xbmcaddon import xbmcplugin import xbmcgui import xbmc import xbmcvfs import urllib import urlparse import sys import os import re addon = xbmcaddon.Addon() get_setting = addon.getSetting show_settings = addon.openSettings def get_path(): return addon.getAddonInfo('path').decode('utf-8') def get_profile(): return addon.getAddonInfo('profile').decode('utf-8') def translate_path(path): return xbmc.translatePath(path).decode('utf-8') def set_setting(id, value): if not isinstance(value, basestring): value = str(value) addon.setSetting(id, value) def get_version(): return addon.getAddonInfo('version') def get_id(): return addon.getAddonInfo('id') def get_name(): return addon.getAddonInfo('name') def get_plugin_url(queries): try: query = urllib.urlencode(queries) except UnicodeEncodeError: for k in queries: if isinstance(queries[k], unicode): queries[k] = queries[k].encode('utf-8') query = urllib.urlencode(queries) return sys.argv[0] + '?' + query def end_of_directory(cache_to_disc=True): xbmcplugin.endOfDirectory(int(sys.argv[1]), cacheToDisc=cache_to_disc) def set_content(content): xbmcplugin.setContent(int(sys.argv[1]), content) def create_item(queries, label, thumb='', fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): list_item = xbmcgui.ListItem(label, iconImage=thumb, thumbnailImage=thumb) add_item(queries, list_item, fanart, is_folder, is_playable, total_items, menu_items, replace_menu) def add_item(queries, list_item, fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): if menu_items is None: menu_items = [] if is_folder is None: is_folder = False if is_playable else True if is_playable is None: <|fim_middle|> else: playable = 'true' if is_playable else 'false' liz_url = get_plugin_url(queries) if fanart: list_item.setProperty('fanart_image', fanart) list_item.setInfo('video', {'title': list_item.getLabel()}) list_item.setProperty('isPlayable', playable) list_item.addContextMenuItems(menu_items, replaceItems=replace_menu) xbmcplugin.addDirectoryItem(int(sys.argv[1]), liz_url, list_item, isFolder=is_folder, totalItems=total_items) def parse_query(query): q = {'mode': 'main'} if query.startswith('?'): query = query[1:] queries = urlparse.parse_qs(query) for key in queries: if len(queries[key]) == 1: q[key] = queries[key][0] else: q[key] = queries[key] return q def notify(header=None, msg='', duration=2000, sound=None): if header is None: header = get_name() if sound is None: sound = get_setting('mute_notifications') == 'false' icon_path = os.path.join(get_path(), 'icon.png') try: xbmcgui.Dialog().notification(header, msg, icon_path, duration, sound) except: builtin = "XBMC.Notification(%s,%s, %s, %s)" % (header, msg, duration, icon_path) xbmc.executebuiltin(builtin) def get_current_view(): skinPath = translate_path('special://skin/') xml = os.path.join(skinPath, 'addon.xml') f = xbmcvfs.File(xml) read = f.read() f.close() try: src = re.search('defaultresolution="([^"]+)', read, re.DOTALL).group(1) except: src = re.search('<res.+?folder="([^"]+)', read, re.DOTALL).group(1) src = os.path.join(skinPath, src, 'MyVideoNav.xml') f = xbmcvfs.File(src) read = f.read() f.close() match = re.search('<views>([^<]+)', read, re.DOTALL) if match: views = match.group(1) for view in views.split(','): if xbmc.getInfoLabel('Control.GetLabel(%s)' % (view)): return view <|fim▁end|>
playable = 'false' if is_folder else 'true'
<|file_name|>kodi.py<|end_file_name|><|fim▁begin|>""" SALTS XBMC Addon Copyright (C) 2015 tknorris This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import xbmcaddon import xbmcplugin import xbmcgui import xbmc import xbmcvfs import urllib import urlparse import sys import os import re addon = xbmcaddon.Addon() get_setting = addon.getSetting show_settings = addon.openSettings def get_path(): return addon.getAddonInfo('path').decode('utf-8') def get_profile(): return addon.getAddonInfo('profile').decode('utf-8') def translate_path(path): return xbmc.translatePath(path).decode('utf-8') def set_setting(id, value): if not isinstance(value, basestring): value = str(value) addon.setSetting(id, value) def get_version(): return addon.getAddonInfo('version') def get_id(): return addon.getAddonInfo('id') def get_name(): return addon.getAddonInfo('name') def get_plugin_url(queries): try: query = urllib.urlencode(queries) except UnicodeEncodeError: for k in queries: if isinstance(queries[k], unicode): queries[k] = queries[k].encode('utf-8') query = urllib.urlencode(queries) return sys.argv[0] + '?' + query def end_of_directory(cache_to_disc=True): xbmcplugin.endOfDirectory(int(sys.argv[1]), cacheToDisc=cache_to_disc) def set_content(content): xbmcplugin.setContent(int(sys.argv[1]), content) def create_item(queries, label, thumb='', fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): list_item = xbmcgui.ListItem(label, iconImage=thumb, thumbnailImage=thumb) add_item(queries, list_item, fanart, is_folder, is_playable, total_items, menu_items, replace_menu) def add_item(queries, list_item, fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): if menu_items is None: menu_items = [] if is_folder is None: is_folder = False if is_playable else True if is_playable is None: playable = 'false' if is_folder else 'true' else: <|fim_middle|> liz_url = get_plugin_url(queries) if fanart: list_item.setProperty('fanart_image', fanart) list_item.setInfo('video', {'title': list_item.getLabel()}) list_item.setProperty('isPlayable', playable) list_item.addContextMenuItems(menu_items, replaceItems=replace_menu) xbmcplugin.addDirectoryItem(int(sys.argv[1]), liz_url, list_item, isFolder=is_folder, totalItems=total_items) def parse_query(query): q = {'mode': 'main'} if query.startswith('?'): query = query[1:] queries = urlparse.parse_qs(query) for key in queries: if len(queries[key]) == 1: q[key] = queries[key][0] else: q[key] = queries[key] return q def notify(header=None, msg='', duration=2000, sound=None): if header is None: header = get_name() if sound is None: sound = get_setting('mute_notifications') == 'false' icon_path = os.path.join(get_path(), 'icon.png') try: xbmcgui.Dialog().notification(header, msg, icon_path, duration, sound) except: builtin = "XBMC.Notification(%s,%s, %s, %s)" % (header, msg, duration, icon_path) xbmc.executebuiltin(builtin) def get_current_view(): skinPath = translate_path('special://skin/') xml = os.path.join(skinPath, 'addon.xml') f = xbmcvfs.File(xml) read = f.read() f.close() try: src = re.search('defaultresolution="([^"]+)', read, re.DOTALL).group(1) except: src = re.search('<res.+?folder="([^"]+)', read, re.DOTALL).group(1) src = os.path.join(skinPath, src, 'MyVideoNav.xml') f = xbmcvfs.File(src) read = f.read() f.close() match = re.search('<views>([^<]+)', read, re.DOTALL) if match: views = match.group(1) for view in views.split(','): if xbmc.getInfoLabel('Control.GetLabel(%s)' % (view)): return view <|fim▁end|>
playable = 'true' if is_playable else 'false'
<|file_name|>kodi.py<|end_file_name|><|fim▁begin|>""" SALTS XBMC Addon Copyright (C) 2015 tknorris This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import xbmcaddon import xbmcplugin import xbmcgui import xbmc import xbmcvfs import urllib import urlparse import sys import os import re addon = xbmcaddon.Addon() get_setting = addon.getSetting show_settings = addon.openSettings def get_path(): return addon.getAddonInfo('path').decode('utf-8') def get_profile(): return addon.getAddonInfo('profile').decode('utf-8') def translate_path(path): return xbmc.translatePath(path).decode('utf-8') def set_setting(id, value): if not isinstance(value, basestring): value = str(value) addon.setSetting(id, value) def get_version(): return addon.getAddonInfo('version') def get_id(): return addon.getAddonInfo('id') def get_name(): return addon.getAddonInfo('name') def get_plugin_url(queries): try: query = urllib.urlencode(queries) except UnicodeEncodeError: for k in queries: if isinstance(queries[k], unicode): queries[k] = queries[k].encode('utf-8') query = urllib.urlencode(queries) return sys.argv[0] + '?' + query def end_of_directory(cache_to_disc=True): xbmcplugin.endOfDirectory(int(sys.argv[1]), cacheToDisc=cache_to_disc) def set_content(content): xbmcplugin.setContent(int(sys.argv[1]), content) def create_item(queries, label, thumb='', fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): list_item = xbmcgui.ListItem(label, iconImage=thumb, thumbnailImage=thumb) add_item(queries, list_item, fanart, is_folder, is_playable, total_items, menu_items, replace_menu) def add_item(queries, list_item, fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): if menu_items is None: menu_items = [] if is_folder is None: is_folder = False if is_playable else True if is_playable is None: playable = 'false' if is_folder else 'true' else: playable = 'true' if is_playable else 'false' liz_url = get_plugin_url(queries) if fanart: <|fim_middle|> list_item.setInfo('video', {'title': list_item.getLabel()}) list_item.setProperty('isPlayable', playable) list_item.addContextMenuItems(menu_items, replaceItems=replace_menu) xbmcplugin.addDirectoryItem(int(sys.argv[1]), liz_url, list_item, isFolder=is_folder, totalItems=total_items) def parse_query(query): q = {'mode': 'main'} if query.startswith('?'): query = query[1:] queries = urlparse.parse_qs(query) for key in queries: if len(queries[key]) == 1: q[key] = queries[key][0] else: q[key] = queries[key] return q def notify(header=None, msg='', duration=2000, sound=None): if header is None: header = get_name() if sound is None: sound = get_setting('mute_notifications') == 'false' icon_path = os.path.join(get_path(), 'icon.png') try: xbmcgui.Dialog().notification(header, msg, icon_path, duration, sound) except: builtin = "XBMC.Notification(%s,%s, %s, %s)" % (header, msg, duration, icon_path) xbmc.executebuiltin(builtin) def get_current_view(): skinPath = translate_path('special://skin/') xml = os.path.join(skinPath, 'addon.xml') f = xbmcvfs.File(xml) read = f.read() f.close() try: src = re.search('defaultresolution="([^"]+)', read, re.DOTALL).group(1) except: src = re.search('<res.+?folder="([^"]+)', read, re.DOTALL).group(1) src = os.path.join(skinPath, src, 'MyVideoNav.xml') f = xbmcvfs.File(src) read = f.read() f.close() match = re.search('<views>([^<]+)', read, re.DOTALL) if match: views = match.group(1) for view in views.split(','): if xbmc.getInfoLabel('Control.GetLabel(%s)' % (view)): return view <|fim▁end|>
list_item.setProperty('fanart_image', fanart)
<|file_name|>kodi.py<|end_file_name|><|fim▁begin|>""" SALTS XBMC Addon Copyright (C) 2015 tknorris This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import xbmcaddon import xbmcplugin import xbmcgui import xbmc import xbmcvfs import urllib import urlparse import sys import os import re addon = xbmcaddon.Addon() get_setting = addon.getSetting show_settings = addon.openSettings def get_path(): return addon.getAddonInfo('path').decode('utf-8') def get_profile(): return addon.getAddonInfo('profile').decode('utf-8') def translate_path(path): return xbmc.translatePath(path).decode('utf-8') def set_setting(id, value): if not isinstance(value, basestring): value = str(value) addon.setSetting(id, value) def get_version(): return addon.getAddonInfo('version') def get_id(): return addon.getAddonInfo('id') def get_name(): return addon.getAddonInfo('name') def get_plugin_url(queries): try: query = urllib.urlencode(queries) except UnicodeEncodeError: for k in queries: if isinstance(queries[k], unicode): queries[k] = queries[k].encode('utf-8') query = urllib.urlencode(queries) return sys.argv[0] + '?' + query def end_of_directory(cache_to_disc=True): xbmcplugin.endOfDirectory(int(sys.argv[1]), cacheToDisc=cache_to_disc) def set_content(content): xbmcplugin.setContent(int(sys.argv[1]), content) def create_item(queries, label, thumb='', fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): list_item = xbmcgui.ListItem(label, iconImage=thumb, thumbnailImage=thumb) add_item(queries, list_item, fanart, is_folder, is_playable, total_items, menu_items, replace_menu) def add_item(queries, list_item, fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): if menu_items is None: menu_items = [] if is_folder is None: is_folder = False if is_playable else True if is_playable is None: playable = 'false' if is_folder else 'true' else: playable = 'true' if is_playable else 'false' liz_url = get_plugin_url(queries) if fanart: list_item.setProperty('fanart_image', fanart) list_item.setInfo('video', {'title': list_item.getLabel()}) list_item.setProperty('isPlayable', playable) list_item.addContextMenuItems(menu_items, replaceItems=replace_menu) xbmcplugin.addDirectoryItem(int(sys.argv[1]), liz_url, list_item, isFolder=is_folder, totalItems=total_items) def parse_query(query): q = {'mode': 'main'} if query.startswith('?'): <|fim_middle|> queries = urlparse.parse_qs(query) for key in queries: if len(queries[key]) == 1: q[key] = queries[key][0] else: q[key] = queries[key] return q def notify(header=None, msg='', duration=2000, sound=None): if header is None: header = get_name() if sound is None: sound = get_setting('mute_notifications') == 'false' icon_path = os.path.join(get_path(), 'icon.png') try: xbmcgui.Dialog().notification(header, msg, icon_path, duration, sound) except: builtin = "XBMC.Notification(%s,%s, %s, %s)" % (header, msg, duration, icon_path) xbmc.executebuiltin(builtin) def get_current_view(): skinPath = translate_path('special://skin/') xml = os.path.join(skinPath, 'addon.xml') f = xbmcvfs.File(xml) read = f.read() f.close() try: src = re.search('defaultresolution="([^"]+)', read, re.DOTALL).group(1) except: src = re.search('<res.+?folder="([^"]+)', read, re.DOTALL).group(1) src = os.path.join(skinPath, src, 'MyVideoNav.xml') f = xbmcvfs.File(src) read = f.read() f.close() match = re.search('<views>([^<]+)', read, re.DOTALL) if match: views = match.group(1) for view in views.split(','): if xbmc.getInfoLabel('Control.GetLabel(%s)' % (view)): return view <|fim▁end|>
query = query[1:]
<|file_name|>kodi.py<|end_file_name|><|fim▁begin|>""" SALTS XBMC Addon Copyright (C) 2015 tknorris This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import xbmcaddon import xbmcplugin import xbmcgui import xbmc import xbmcvfs import urllib import urlparse import sys import os import re addon = xbmcaddon.Addon() get_setting = addon.getSetting show_settings = addon.openSettings def get_path(): return addon.getAddonInfo('path').decode('utf-8') def get_profile(): return addon.getAddonInfo('profile').decode('utf-8') def translate_path(path): return xbmc.translatePath(path).decode('utf-8') def set_setting(id, value): if not isinstance(value, basestring): value = str(value) addon.setSetting(id, value) def get_version(): return addon.getAddonInfo('version') def get_id(): return addon.getAddonInfo('id') def get_name(): return addon.getAddonInfo('name') def get_plugin_url(queries): try: query = urllib.urlencode(queries) except UnicodeEncodeError: for k in queries: if isinstance(queries[k], unicode): queries[k] = queries[k].encode('utf-8') query = urllib.urlencode(queries) return sys.argv[0] + '?' + query def end_of_directory(cache_to_disc=True): xbmcplugin.endOfDirectory(int(sys.argv[1]), cacheToDisc=cache_to_disc) def set_content(content): xbmcplugin.setContent(int(sys.argv[1]), content) def create_item(queries, label, thumb='', fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): list_item = xbmcgui.ListItem(label, iconImage=thumb, thumbnailImage=thumb) add_item(queries, list_item, fanart, is_folder, is_playable, total_items, menu_items, replace_menu) def add_item(queries, list_item, fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): if menu_items is None: menu_items = [] if is_folder is None: is_folder = False if is_playable else True if is_playable is None: playable = 'false' if is_folder else 'true' else: playable = 'true' if is_playable else 'false' liz_url = get_plugin_url(queries) if fanart: list_item.setProperty('fanart_image', fanart) list_item.setInfo('video', {'title': list_item.getLabel()}) list_item.setProperty('isPlayable', playable) list_item.addContextMenuItems(menu_items, replaceItems=replace_menu) xbmcplugin.addDirectoryItem(int(sys.argv[1]), liz_url, list_item, isFolder=is_folder, totalItems=total_items) def parse_query(query): q = {'mode': 'main'} if query.startswith('?'): query = query[1:] queries = urlparse.parse_qs(query) for key in queries: if len(queries[key]) == 1: <|fim_middle|> else: q[key] = queries[key] return q def notify(header=None, msg='', duration=2000, sound=None): if header is None: header = get_name() if sound is None: sound = get_setting('mute_notifications') == 'false' icon_path = os.path.join(get_path(), 'icon.png') try: xbmcgui.Dialog().notification(header, msg, icon_path, duration, sound) except: builtin = "XBMC.Notification(%s,%s, %s, %s)" % (header, msg, duration, icon_path) xbmc.executebuiltin(builtin) def get_current_view(): skinPath = translate_path('special://skin/') xml = os.path.join(skinPath, 'addon.xml') f = xbmcvfs.File(xml) read = f.read() f.close() try: src = re.search('defaultresolution="([^"]+)', read, re.DOTALL).group(1) except: src = re.search('<res.+?folder="([^"]+)', read, re.DOTALL).group(1) src = os.path.join(skinPath, src, 'MyVideoNav.xml') f = xbmcvfs.File(src) read = f.read() f.close() match = re.search('<views>([^<]+)', read, re.DOTALL) if match: views = match.group(1) for view in views.split(','): if xbmc.getInfoLabel('Control.GetLabel(%s)' % (view)): return view <|fim▁end|>
q[key] = queries[key][0]
<|file_name|>kodi.py<|end_file_name|><|fim▁begin|>""" SALTS XBMC Addon Copyright (C) 2015 tknorris This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import xbmcaddon import xbmcplugin import xbmcgui import xbmc import xbmcvfs import urllib import urlparse import sys import os import re addon = xbmcaddon.Addon() get_setting = addon.getSetting show_settings = addon.openSettings def get_path(): return addon.getAddonInfo('path').decode('utf-8') def get_profile(): return addon.getAddonInfo('profile').decode('utf-8') def translate_path(path): return xbmc.translatePath(path).decode('utf-8') def set_setting(id, value): if not isinstance(value, basestring): value = str(value) addon.setSetting(id, value) def get_version(): return addon.getAddonInfo('version') def get_id(): return addon.getAddonInfo('id') def get_name(): return addon.getAddonInfo('name') def get_plugin_url(queries): try: query = urllib.urlencode(queries) except UnicodeEncodeError: for k in queries: if isinstance(queries[k], unicode): queries[k] = queries[k].encode('utf-8') query = urllib.urlencode(queries) return sys.argv[0] + '?' + query def end_of_directory(cache_to_disc=True): xbmcplugin.endOfDirectory(int(sys.argv[1]), cacheToDisc=cache_to_disc) def set_content(content): xbmcplugin.setContent(int(sys.argv[1]), content) def create_item(queries, label, thumb='', fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): list_item = xbmcgui.ListItem(label, iconImage=thumb, thumbnailImage=thumb) add_item(queries, list_item, fanart, is_folder, is_playable, total_items, menu_items, replace_menu) def add_item(queries, list_item, fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): if menu_items is None: menu_items = [] if is_folder is None: is_folder = False if is_playable else True if is_playable is None: playable = 'false' if is_folder else 'true' else: playable = 'true' if is_playable else 'false' liz_url = get_plugin_url(queries) if fanart: list_item.setProperty('fanart_image', fanart) list_item.setInfo('video', {'title': list_item.getLabel()}) list_item.setProperty('isPlayable', playable) list_item.addContextMenuItems(menu_items, replaceItems=replace_menu) xbmcplugin.addDirectoryItem(int(sys.argv[1]), liz_url, list_item, isFolder=is_folder, totalItems=total_items) def parse_query(query): q = {'mode': 'main'} if query.startswith('?'): query = query[1:] queries = urlparse.parse_qs(query) for key in queries: if len(queries[key]) == 1: q[key] = queries[key][0] else: <|fim_middle|> return q def notify(header=None, msg='', duration=2000, sound=None): if header is None: header = get_name() if sound is None: sound = get_setting('mute_notifications') == 'false' icon_path = os.path.join(get_path(), 'icon.png') try: xbmcgui.Dialog().notification(header, msg, icon_path, duration, sound) except: builtin = "XBMC.Notification(%s,%s, %s, %s)" % (header, msg, duration, icon_path) xbmc.executebuiltin(builtin) def get_current_view(): skinPath = translate_path('special://skin/') xml = os.path.join(skinPath, 'addon.xml') f = xbmcvfs.File(xml) read = f.read() f.close() try: src = re.search('defaultresolution="([^"]+)', read, re.DOTALL).group(1) except: src = re.search('<res.+?folder="([^"]+)', read, re.DOTALL).group(1) src = os.path.join(skinPath, src, 'MyVideoNav.xml') f = xbmcvfs.File(src) read = f.read() f.close() match = re.search('<views>([^<]+)', read, re.DOTALL) if match: views = match.group(1) for view in views.split(','): if xbmc.getInfoLabel('Control.GetLabel(%s)' % (view)): return view <|fim▁end|>
q[key] = queries[key]
<|file_name|>kodi.py<|end_file_name|><|fim▁begin|>""" SALTS XBMC Addon Copyright (C) 2015 tknorris This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import xbmcaddon import xbmcplugin import xbmcgui import xbmc import xbmcvfs import urllib import urlparse import sys import os import re addon = xbmcaddon.Addon() get_setting = addon.getSetting show_settings = addon.openSettings def get_path(): return addon.getAddonInfo('path').decode('utf-8') def get_profile(): return addon.getAddonInfo('profile').decode('utf-8') def translate_path(path): return xbmc.translatePath(path).decode('utf-8') def set_setting(id, value): if not isinstance(value, basestring): value = str(value) addon.setSetting(id, value) def get_version(): return addon.getAddonInfo('version') def get_id(): return addon.getAddonInfo('id') def get_name(): return addon.getAddonInfo('name') def get_plugin_url(queries): try: query = urllib.urlencode(queries) except UnicodeEncodeError: for k in queries: if isinstance(queries[k], unicode): queries[k] = queries[k].encode('utf-8') query = urllib.urlencode(queries) return sys.argv[0] + '?' + query def end_of_directory(cache_to_disc=True): xbmcplugin.endOfDirectory(int(sys.argv[1]), cacheToDisc=cache_to_disc) def set_content(content): xbmcplugin.setContent(int(sys.argv[1]), content) def create_item(queries, label, thumb='', fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): list_item = xbmcgui.ListItem(label, iconImage=thumb, thumbnailImage=thumb) add_item(queries, list_item, fanart, is_folder, is_playable, total_items, menu_items, replace_menu) def add_item(queries, list_item, fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): if menu_items is None: menu_items = [] if is_folder is None: is_folder = False if is_playable else True if is_playable is None: playable = 'false' if is_folder else 'true' else: playable = 'true' if is_playable else 'false' liz_url = get_plugin_url(queries) if fanart: list_item.setProperty('fanart_image', fanart) list_item.setInfo('video', {'title': list_item.getLabel()}) list_item.setProperty('isPlayable', playable) list_item.addContextMenuItems(menu_items, replaceItems=replace_menu) xbmcplugin.addDirectoryItem(int(sys.argv[1]), liz_url, list_item, isFolder=is_folder, totalItems=total_items) def parse_query(query): q = {'mode': 'main'} if query.startswith('?'): query = query[1:] queries = urlparse.parse_qs(query) for key in queries: if len(queries[key]) == 1: q[key] = queries[key][0] else: q[key] = queries[key] return q def notify(header=None, msg='', duration=2000, sound=None): if header is None: <|fim_middle|> if sound is None: sound = get_setting('mute_notifications') == 'false' icon_path = os.path.join(get_path(), 'icon.png') try: xbmcgui.Dialog().notification(header, msg, icon_path, duration, sound) except: builtin = "XBMC.Notification(%s,%s, %s, %s)" % (header, msg, duration, icon_path) xbmc.executebuiltin(builtin) def get_current_view(): skinPath = translate_path('special://skin/') xml = os.path.join(skinPath, 'addon.xml') f = xbmcvfs.File(xml) read = f.read() f.close() try: src = re.search('defaultresolution="([^"]+)', read, re.DOTALL).group(1) except: src = re.search('<res.+?folder="([^"]+)', read, re.DOTALL).group(1) src = os.path.join(skinPath, src, 'MyVideoNav.xml') f = xbmcvfs.File(src) read = f.read() f.close() match = re.search('<views>([^<]+)', read, re.DOTALL) if match: views = match.group(1) for view in views.split(','): if xbmc.getInfoLabel('Control.GetLabel(%s)' % (view)): return view <|fim▁end|>
header = get_name()
<|file_name|>kodi.py<|end_file_name|><|fim▁begin|>""" SALTS XBMC Addon Copyright (C) 2015 tknorris This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import xbmcaddon import xbmcplugin import xbmcgui import xbmc import xbmcvfs import urllib import urlparse import sys import os import re addon = xbmcaddon.Addon() get_setting = addon.getSetting show_settings = addon.openSettings def get_path(): return addon.getAddonInfo('path').decode('utf-8') def get_profile(): return addon.getAddonInfo('profile').decode('utf-8') def translate_path(path): return xbmc.translatePath(path).decode('utf-8') def set_setting(id, value): if not isinstance(value, basestring): value = str(value) addon.setSetting(id, value) def get_version(): return addon.getAddonInfo('version') def get_id(): return addon.getAddonInfo('id') def get_name(): return addon.getAddonInfo('name') def get_plugin_url(queries): try: query = urllib.urlencode(queries) except UnicodeEncodeError: for k in queries: if isinstance(queries[k], unicode): queries[k] = queries[k].encode('utf-8') query = urllib.urlencode(queries) return sys.argv[0] + '?' + query def end_of_directory(cache_to_disc=True): xbmcplugin.endOfDirectory(int(sys.argv[1]), cacheToDisc=cache_to_disc) def set_content(content): xbmcplugin.setContent(int(sys.argv[1]), content) def create_item(queries, label, thumb='', fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): list_item = xbmcgui.ListItem(label, iconImage=thumb, thumbnailImage=thumb) add_item(queries, list_item, fanart, is_folder, is_playable, total_items, menu_items, replace_menu) def add_item(queries, list_item, fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): if menu_items is None: menu_items = [] if is_folder is None: is_folder = False if is_playable else True if is_playable is None: playable = 'false' if is_folder else 'true' else: playable = 'true' if is_playable else 'false' liz_url = get_plugin_url(queries) if fanart: list_item.setProperty('fanart_image', fanart) list_item.setInfo('video', {'title': list_item.getLabel()}) list_item.setProperty('isPlayable', playable) list_item.addContextMenuItems(menu_items, replaceItems=replace_menu) xbmcplugin.addDirectoryItem(int(sys.argv[1]), liz_url, list_item, isFolder=is_folder, totalItems=total_items) def parse_query(query): q = {'mode': 'main'} if query.startswith('?'): query = query[1:] queries = urlparse.parse_qs(query) for key in queries: if len(queries[key]) == 1: q[key] = queries[key][0] else: q[key] = queries[key] return q def notify(header=None, msg='', duration=2000, sound=None): if header is None: header = get_name() if sound is None: <|fim_middle|> icon_path = os.path.join(get_path(), 'icon.png') try: xbmcgui.Dialog().notification(header, msg, icon_path, duration, sound) except: builtin = "XBMC.Notification(%s,%s, %s, %s)" % (header, msg, duration, icon_path) xbmc.executebuiltin(builtin) def get_current_view(): skinPath = translate_path('special://skin/') xml = os.path.join(skinPath, 'addon.xml') f = xbmcvfs.File(xml) read = f.read() f.close() try: src = re.search('defaultresolution="([^"]+)', read, re.DOTALL).group(1) except: src = re.search('<res.+?folder="([^"]+)', read, re.DOTALL).group(1) src = os.path.join(skinPath, src, 'MyVideoNav.xml') f = xbmcvfs.File(src) read = f.read() f.close() match = re.search('<views>([^<]+)', read, re.DOTALL) if match: views = match.group(1) for view in views.split(','): if xbmc.getInfoLabel('Control.GetLabel(%s)' % (view)): return view <|fim▁end|>
sound = get_setting('mute_notifications') == 'false'
<|file_name|>kodi.py<|end_file_name|><|fim▁begin|>""" SALTS XBMC Addon Copyright (C) 2015 tknorris This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import xbmcaddon import xbmcplugin import xbmcgui import xbmc import xbmcvfs import urllib import urlparse import sys import os import re addon = xbmcaddon.Addon() get_setting = addon.getSetting show_settings = addon.openSettings def get_path(): return addon.getAddonInfo('path').decode('utf-8') def get_profile(): return addon.getAddonInfo('profile').decode('utf-8') def translate_path(path): return xbmc.translatePath(path).decode('utf-8') def set_setting(id, value): if not isinstance(value, basestring): value = str(value) addon.setSetting(id, value) def get_version(): return addon.getAddonInfo('version') def get_id(): return addon.getAddonInfo('id') def get_name(): return addon.getAddonInfo('name') def get_plugin_url(queries): try: query = urllib.urlencode(queries) except UnicodeEncodeError: for k in queries: if isinstance(queries[k], unicode): queries[k] = queries[k].encode('utf-8') query = urllib.urlencode(queries) return sys.argv[0] + '?' + query def end_of_directory(cache_to_disc=True): xbmcplugin.endOfDirectory(int(sys.argv[1]), cacheToDisc=cache_to_disc) def set_content(content): xbmcplugin.setContent(int(sys.argv[1]), content) def create_item(queries, label, thumb='', fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): list_item = xbmcgui.ListItem(label, iconImage=thumb, thumbnailImage=thumb) add_item(queries, list_item, fanart, is_folder, is_playable, total_items, menu_items, replace_menu) def add_item(queries, list_item, fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): if menu_items is None: menu_items = [] if is_folder is None: is_folder = False if is_playable else True if is_playable is None: playable = 'false' if is_folder else 'true' else: playable = 'true' if is_playable else 'false' liz_url = get_plugin_url(queries) if fanart: list_item.setProperty('fanart_image', fanart) list_item.setInfo('video', {'title': list_item.getLabel()}) list_item.setProperty('isPlayable', playable) list_item.addContextMenuItems(menu_items, replaceItems=replace_menu) xbmcplugin.addDirectoryItem(int(sys.argv[1]), liz_url, list_item, isFolder=is_folder, totalItems=total_items) def parse_query(query): q = {'mode': 'main'} if query.startswith('?'): query = query[1:] queries = urlparse.parse_qs(query) for key in queries: if len(queries[key]) == 1: q[key] = queries[key][0] else: q[key] = queries[key] return q def notify(header=None, msg='', duration=2000, sound=None): if header is None: header = get_name() if sound is None: sound = get_setting('mute_notifications') == 'false' icon_path = os.path.join(get_path(), 'icon.png') try: xbmcgui.Dialog().notification(header, msg, icon_path, duration, sound) except: builtin = "XBMC.Notification(%s,%s, %s, %s)" % (header, msg, duration, icon_path) xbmc.executebuiltin(builtin) def get_current_view(): skinPath = translate_path('special://skin/') xml = os.path.join(skinPath, 'addon.xml') f = xbmcvfs.File(xml) read = f.read() f.close() try: src = re.search('defaultresolution="([^"]+)', read, re.DOTALL).group(1) except: src = re.search('<res.+?folder="([^"]+)', read, re.DOTALL).group(1) src = os.path.join(skinPath, src, 'MyVideoNav.xml') f = xbmcvfs.File(src) read = f.read() f.close() match = re.search('<views>([^<]+)', read, re.DOTALL) if match: <|fim_middle|> <|fim▁end|>
views = match.group(1) for view in views.split(','): if xbmc.getInfoLabel('Control.GetLabel(%s)' % (view)): return view
<|file_name|>kodi.py<|end_file_name|><|fim▁begin|>""" SALTS XBMC Addon Copyright (C) 2015 tknorris This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import xbmcaddon import xbmcplugin import xbmcgui import xbmc import xbmcvfs import urllib import urlparse import sys import os import re addon = xbmcaddon.Addon() get_setting = addon.getSetting show_settings = addon.openSettings def get_path(): return addon.getAddonInfo('path').decode('utf-8') def get_profile(): return addon.getAddonInfo('profile').decode('utf-8') def translate_path(path): return xbmc.translatePath(path).decode('utf-8') def set_setting(id, value): if not isinstance(value, basestring): value = str(value) addon.setSetting(id, value) def get_version(): return addon.getAddonInfo('version') def get_id(): return addon.getAddonInfo('id') def get_name(): return addon.getAddonInfo('name') def get_plugin_url(queries): try: query = urllib.urlencode(queries) except UnicodeEncodeError: for k in queries: if isinstance(queries[k], unicode): queries[k] = queries[k].encode('utf-8') query = urllib.urlencode(queries) return sys.argv[0] + '?' + query def end_of_directory(cache_to_disc=True): xbmcplugin.endOfDirectory(int(sys.argv[1]), cacheToDisc=cache_to_disc) def set_content(content): xbmcplugin.setContent(int(sys.argv[1]), content) def create_item(queries, label, thumb='', fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): list_item = xbmcgui.ListItem(label, iconImage=thumb, thumbnailImage=thumb) add_item(queries, list_item, fanart, is_folder, is_playable, total_items, menu_items, replace_menu) def add_item(queries, list_item, fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): if menu_items is None: menu_items = [] if is_folder is None: is_folder = False if is_playable else True if is_playable is None: playable = 'false' if is_folder else 'true' else: playable = 'true' if is_playable else 'false' liz_url = get_plugin_url(queries) if fanart: list_item.setProperty('fanart_image', fanart) list_item.setInfo('video', {'title': list_item.getLabel()}) list_item.setProperty('isPlayable', playable) list_item.addContextMenuItems(menu_items, replaceItems=replace_menu) xbmcplugin.addDirectoryItem(int(sys.argv[1]), liz_url, list_item, isFolder=is_folder, totalItems=total_items) def parse_query(query): q = {'mode': 'main'} if query.startswith('?'): query = query[1:] queries = urlparse.parse_qs(query) for key in queries: if len(queries[key]) == 1: q[key] = queries[key][0] else: q[key] = queries[key] return q def notify(header=None, msg='', duration=2000, sound=None): if header is None: header = get_name() if sound is None: sound = get_setting('mute_notifications') == 'false' icon_path = os.path.join(get_path(), 'icon.png') try: xbmcgui.Dialog().notification(header, msg, icon_path, duration, sound) except: builtin = "XBMC.Notification(%s,%s, %s, %s)" % (header, msg, duration, icon_path) xbmc.executebuiltin(builtin) def get_current_view(): skinPath = translate_path('special://skin/') xml = os.path.join(skinPath, 'addon.xml') f = xbmcvfs.File(xml) read = f.read() f.close() try: src = re.search('defaultresolution="([^"]+)', read, re.DOTALL).group(1) except: src = re.search('<res.+?folder="([^"]+)', read, re.DOTALL).group(1) src = os.path.join(skinPath, src, 'MyVideoNav.xml') f = xbmcvfs.File(src) read = f.read() f.close() match = re.search('<views>([^<]+)', read, re.DOTALL) if match: views = match.group(1) for view in views.split(','): if xbmc.getInfoLabel('Control.GetLabel(%s)' % (view)): <|fim_middle|> <|fim▁end|>
return view
<|file_name|>kodi.py<|end_file_name|><|fim▁begin|>""" SALTS XBMC Addon Copyright (C) 2015 tknorris This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import xbmcaddon import xbmcplugin import xbmcgui import xbmc import xbmcvfs import urllib import urlparse import sys import os import re addon = xbmcaddon.Addon() get_setting = addon.getSetting show_settings = addon.openSettings def <|fim_middle|>(): return addon.getAddonInfo('path').decode('utf-8') def get_profile(): return addon.getAddonInfo('profile').decode('utf-8') def translate_path(path): return xbmc.translatePath(path).decode('utf-8') def set_setting(id, value): if not isinstance(value, basestring): value = str(value) addon.setSetting(id, value) def get_version(): return addon.getAddonInfo('version') def get_id(): return addon.getAddonInfo('id') def get_name(): return addon.getAddonInfo('name') def get_plugin_url(queries): try: query = urllib.urlencode(queries) except UnicodeEncodeError: for k in queries: if isinstance(queries[k], unicode): queries[k] = queries[k].encode('utf-8') query = urllib.urlencode(queries) return sys.argv[0] + '?' + query def end_of_directory(cache_to_disc=True): xbmcplugin.endOfDirectory(int(sys.argv[1]), cacheToDisc=cache_to_disc) def set_content(content): xbmcplugin.setContent(int(sys.argv[1]), content) def create_item(queries, label, thumb='', fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): list_item = xbmcgui.ListItem(label, iconImage=thumb, thumbnailImage=thumb) add_item(queries, list_item, fanart, is_folder, is_playable, total_items, menu_items, replace_menu) def add_item(queries, list_item, fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): if menu_items is None: menu_items = [] if is_folder is None: is_folder = False if is_playable else True if is_playable is None: playable = 'false' if is_folder else 'true' else: playable = 'true' if is_playable else 'false' liz_url = get_plugin_url(queries) if fanart: list_item.setProperty('fanart_image', fanart) list_item.setInfo('video', {'title': list_item.getLabel()}) list_item.setProperty('isPlayable', playable) list_item.addContextMenuItems(menu_items, replaceItems=replace_menu) xbmcplugin.addDirectoryItem(int(sys.argv[1]), liz_url, list_item, isFolder=is_folder, totalItems=total_items) def parse_query(query): q = {'mode': 'main'} if query.startswith('?'): query = query[1:] queries = urlparse.parse_qs(query) for key in queries: if len(queries[key]) == 1: q[key] = queries[key][0] else: q[key] = queries[key] return q def notify(header=None, msg='', duration=2000, sound=None): if header is None: header = get_name() if sound is None: sound = get_setting('mute_notifications') == 'false' icon_path = os.path.join(get_path(), 'icon.png') try: xbmcgui.Dialog().notification(header, msg, icon_path, duration, sound) except: builtin = "XBMC.Notification(%s,%s, %s, %s)" % (header, msg, duration, icon_path) xbmc.executebuiltin(builtin) def get_current_view(): skinPath = translate_path('special://skin/') xml = os.path.join(skinPath, 'addon.xml') f = xbmcvfs.File(xml) read = f.read() f.close() try: src = re.search('defaultresolution="([^"]+)', read, re.DOTALL).group(1) except: src = re.search('<res.+?folder="([^"]+)', read, re.DOTALL).group(1) src = os.path.join(skinPath, src, 'MyVideoNav.xml') f = xbmcvfs.File(src) read = f.read() f.close() match = re.search('<views>([^<]+)', read, re.DOTALL) if match: views = match.group(1) for view in views.split(','): if xbmc.getInfoLabel('Control.GetLabel(%s)' % (view)): return view <|fim▁end|>
get_path
<|file_name|>kodi.py<|end_file_name|><|fim▁begin|>""" SALTS XBMC Addon Copyright (C) 2015 tknorris This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import xbmcaddon import xbmcplugin import xbmcgui import xbmc import xbmcvfs import urllib import urlparse import sys import os import re addon = xbmcaddon.Addon() get_setting = addon.getSetting show_settings = addon.openSettings def get_path(): return addon.getAddonInfo('path').decode('utf-8') def <|fim_middle|>(): return addon.getAddonInfo('profile').decode('utf-8') def translate_path(path): return xbmc.translatePath(path).decode('utf-8') def set_setting(id, value): if not isinstance(value, basestring): value = str(value) addon.setSetting(id, value) def get_version(): return addon.getAddonInfo('version') def get_id(): return addon.getAddonInfo('id') def get_name(): return addon.getAddonInfo('name') def get_plugin_url(queries): try: query = urllib.urlencode(queries) except UnicodeEncodeError: for k in queries: if isinstance(queries[k], unicode): queries[k] = queries[k].encode('utf-8') query = urllib.urlencode(queries) return sys.argv[0] + '?' + query def end_of_directory(cache_to_disc=True): xbmcplugin.endOfDirectory(int(sys.argv[1]), cacheToDisc=cache_to_disc) def set_content(content): xbmcplugin.setContent(int(sys.argv[1]), content) def create_item(queries, label, thumb='', fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): list_item = xbmcgui.ListItem(label, iconImage=thumb, thumbnailImage=thumb) add_item(queries, list_item, fanart, is_folder, is_playable, total_items, menu_items, replace_menu) def add_item(queries, list_item, fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): if menu_items is None: menu_items = [] if is_folder is None: is_folder = False if is_playable else True if is_playable is None: playable = 'false' if is_folder else 'true' else: playable = 'true' if is_playable else 'false' liz_url = get_plugin_url(queries) if fanart: list_item.setProperty('fanart_image', fanart) list_item.setInfo('video', {'title': list_item.getLabel()}) list_item.setProperty('isPlayable', playable) list_item.addContextMenuItems(menu_items, replaceItems=replace_menu) xbmcplugin.addDirectoryItem(int(sys.argv[1]), liz_url, list_item, isFolder=is_folder, totalItems=total_items) def parse_query(query): q = {'mode': 'main'} if query.startswith('?'): query = query[1:] queries = urlparse.parse_qs(query) for key in queries: if len(queries[key]) == 1: q[key] = queries[key][0] else: q[key] = queries[key] return q def notify(header=None, msg='', duration=2000, sound=None): if header is None: header = get_name() if sound is None: sound = get_setting('mute_notifications') == 'false' icon_path = os.path.join(get_path(), 'icon.png') try: xbmcgui.Dialog().notification(header, msg, icon_path, duration, sound) except: builtin = "XBMC.Notification(%s,%s, %s, %s)" % (header, msg, duration, icon_path) xbmc.executebuiltin(builtin) def get_current_view(): skinPath = translate_path('special://skin/') xml = os.path.join(skinPath, 'addon.xml') f = xbmcvfs.File(xml) read = f.read() f.close() try: src = re.search('defaultresolution="([^"]+)', read, re.DOTALL).group(1) except: src = re.search('<res.+?folder="([^"]+)', read, re.DOTALL).group(1) src = os.path.join(skinPath, src, 'MyVideoNav.xml') f = xbmcvfs.File(src) read = f.read() f.close() match = re.search('<views>([^<]+)', read, re.DOTALL) if match: views = match.group(1) for view in views.split(','): if xbmc.getInfoLabel('Control.GetLabel(%s)' % (view)): return view <|fim▁end|>
get_profile
<|file_name|>kodi.py<|end_file_name|><|fim▁begin|>""" SALTS XBMC Addon Copyright (C) 2015 tknorris This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import xbmcaddon import xbmcplugin import xbmcgui import xbmc import xbmcvfs import urllib import urlparse import sys import os import re addon = xbmcaddon.Addon() get_setting = addon.getSetting show_settings = addon.openSettings def get_path(): return addon.getAddonInfo('path').decode('utf-8') def get_profile(): return addon.getAddonInfo('profile').decode('utf-8') def <|fim_middle|>(path): return xbmc.translatePath(path).decode('utf-8') def set_setting(id, value): if not isinstance(value, basestring): value = str(value) addon.setSetting(id, value) def get_version(): return addon.getAddonInfo('version') def get_id(): return addon.getAddonInfo('id') def get_name(): return addon.getAddonInfo('name') def get_plugin_url(queries): try: query = urllib.urlencode(queries) except UnicodeEncodeError: for k in queries: if isinstance(queries[k], unicode): queries[k] = queries[k].encode('utf-8') query = urllib.urlencode(queries) return sys.argv[0] + '?' + query def end_of_directory(cache_to_disc=True): xbmcplugin.endOfDirectory(int(sys.argv[1]), cacheToDisc=cache_to_disc) def set_content(content): xbmcplugin.setContent(int(sys.argv[1]), content) def create_item(queries, label, thumb='', fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): list_item = xbmcgui.ListItem(label, iconImage=thumb, thumbnailImage=thumb) add_item(queries, list_item, fanart, is_folder, is_playable, total_items, menu_items, replace_menu) def add_item(queries, list_item, fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): if menu_items is None: menu_items = [] if is_folder is None: is_folder = False if is_playable else True if is_playable is None: playable = 'false' if is_folder else 'true' else: playable = 'true' if is_playable else 'false' liz_url = get_plugin_url(queries) if fanart: list_item.setProperty('fanart_image', fanart) list_item.setInfo('video', {'title': list_item.getLabel()}) list_item.setProperty('isPlayable', playable) list_item.addContextMenuItems(menu_items, replaceItems=replace_menu) xbmcplugin.addDirectoryItem(int(sys.argv[1]), liz_url, list_item, isFolder=is_folder, totalItems=total_items) def parse_query(query): q = {'mode': 'main'} if query.startswith('?'): query = query[1:] queries = urlparse.parse_qs(query) for key in queries: if len(queries[key]) == 1: q[key] = queries[key][0] else: q[key] = queries[key] return q def notify(header=None, msg='', duration=2000, sound=None): if header is None: header = get_name() if sound is None: sound = get_setting('mute_notifications') == 'false' icon_path = os.path.join(get_path(), 'icon.png') try: xbmcgui.Dialog().notification(header, msg, icon_path, duration, sound) except: builtin = "XBMC.Notification(%s,%s, %s, %s)" % (header, msg, duration, icon_path) xbmc.executebuiltin(builtin) def get_current_view(): skinPath = translate_path('special://skin/') xml = os.path.join(skinPath, 'addon.xml') f = xbmcvfs.File(xml) read = f.read() f.close() try: src = re.search('defaultresolution="([^"]+)', read, re.DOTALL).group(1) except: src = re.search('<res.+?folder="([^"]+)', read, re.DOTALL).group(1) src = os.path.join(skinPath, src, 'MyVideoNav.xml') f = xbmcvfs.File(src) read = f.read() f.close() match = re.search('<views>([^<]+)', read, re.DOTALL) if match: views = match.group(1) for view in views.split(','): if xbmc.getInfoLabel('Control.GetLabel(%s)' % (view)): return view <|fim▁end|>
translate_path
<|file_name|>kodi.py<|end_file_name|><|fim▁begin|>""" SALTS XBMC Addon Copyright (C) 2015 tknorris This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import xbmcaddon import xbmcplugin import xbmcgui import xbmc import xbmcvfs import urllib import urlparse import sys import os import re addon = xbmcaddon.Addon() get_setting = addon.getSetting show_settings = addon.openSettings def get_path(): return addon.getAddonInfo('path').decode('utf-8') def get_profile(): return addon.getAddonInfo('profile').decode('utf-8') def translate_path(path): return xbmc.translatePath(path).decode('utf-8') def <|fim_middle|>(id, value): if not isinstance(value, basestring): value = str(value) addon.setSetting(id, value) def get_version(): return addon.getAddonInfo('version') def get_id(): return addon.getAddonInfo('id') def get_name(): return addon.getAddonInfo('name') def get_plugin_url(queries): try: query = urllib.urlencode(queries) except UnicodeEncodeError: for k in queries: if isinstance(queries[k], unicode): queries[k] = queries[k].encode('utf-8') query = urllib.urlencode(queries) return sys.argv[0] + '?' + query def end_of_directory(cache_to_disc=True): xbmcplugin.endOfDirectory(int(sys.argv[1]), cacheToDisc=cache_to_disc) def set_content(content): xbmcplugin.setContent(int(sys.argv[1]), content) def create_item(queries, label, thumb='', fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): list_item = xbmcgui.ListItem(label, iconImage=thumb, thumbnailImage=thumb) add_item(queries, list_item, fanart, is_folder, is_playable, total_items, menu_items, replace_menu) def add_item(queries, list_item, fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): if menu_items is None: menu_items = [] if is_folder is None: is_folder = False if is_playable else True if is_playable is None: playable = 'false' if is_folder else 'true' else: playable = 'true' if is_playable else 'false' liz_url = get_plugin_url(queries) if fanart: list_item.setProperty('fanart_image', fanart) list_item.setInfo('video', {'title': list_item.getLabel()}) list_item.setProperty('isPlayable', playable) list_item.addContextMenuItems(menu_items, replaceItems=replace_menu) xbmcplugin.addDirectoryItem(int(sys.argv[1]), liz_url, list_item, isFolder=is_folder, totalItems=total_items) def parse_query(query): q = {'mode': 'main'} if query.startswith('?'): query = query[1:] queries = urlparse.parse_qs(query) for key in queries: if len(queries[key]) == 1: q[key] = queries[key][0] else: q[key] = queries[key] return q def notify(header=None, msg='', duration=2000, sound=None): if header is None: header = get_name() if sound is None: sound = get_setting('mute_notifications') == 'false' icon_path = os.path.join(get_path(), 'icon.png') try: xbmcgui.Dialog().notification(header, msg, icon_path, duration, sound) except: builtin = "XBMC.Notification(%s,%s, %s, %s)" % (header, msg, duration, icon_path) xbmc.executebuiltin(builtin) def get_current_view(): skinPath = translate_path('special://skin/') xml = os.path.join(skinPath, 'addon.xml') f = xbmcvfs.File(xml) read = f.read() f.close() try: src = re.search('defaultresolution="([^"]+)', read, re.DOTALL).group(1) except: src = re.search('<res.+?folder="([^"]+)', read, re.DOTALL).group(1) src = os.path.join(skinPath, src, 'MyVideoNav.xml') f = xbmcvfs.File(src) read = f.read() f.close() match = re.search('<views>([^<]+)', read, re.DOTALL) if match: views = match.group(1) for view in views.split(','): if xbmc.getInfoLabel('Control.GetLabel(%s)' % (view)): return view <|fim▁end|>
set_setting
<|file_name|>kodi.py<|end_file_name|><|fim▁begin|>""" SALTS XBMC Addon Copyright (C) 2015 tknorris This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import xbmcaddon import xbmcplugin import xbmcgui import xbmc import xbmcvfs import urllib import urlparse import sys import os import re addon = xbmcaddon.Addon() get_setting = addon.getSetting show_settings = addon.openSettings def get_path(): return addon.getAddonInfo('path').decode('utf-8') def get_profile(): return addon.getAddonInfo('profile').decode('utf-8') def translate_path(path): return xbmc.translatePath(path).decode('utf-8') def set_setting(id, value): if not isinstance(value, basestring): value = str(value) addon.setSetting(id, value) def <|fim_middle|>(): return addon.getAddonInfo('version') def get_id(): return addon.getAddonInfo('id') def get_name(): return addon.getAddonInfo('name') def get_plugin_url(queries): try: query = urllib.urlencode(queries) except UnicodeEncodeError: for k in queries: if isinstance(queries[k], unicode): queries[k] = queries[k].encode('utf-8') query = urllib.urlencode(queries) return sys.argv[0] + '?' + query def end_of_directory(cache_to_disc=True): xbmcplugin.endOfDirectory(int(sys.argv[1]), cacheToDisc=cache_to_disc) def set_content(content): xbmcplugin.setContent(int(sys.argv[1]), content) def create_item(queries, label, thumb='', fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): list_item = xbmcgui.ListItem(label, iconImage=thumb, thumbnailImage=thumb) add_item(queries, list_item, fanart, is_folder, is_playable, total_items, menu_items, replace_menu) def add_item(queries, list_item, fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): if menu_items is None: menu_items = [] if is_folder is None: is_folder = False if is_playable else True if is_playable is None: playable = 'false' if is_folder else 'true' else: playable = 'true' if is_playable else 'false' liz_url = get_plugin_url(queries) if fanart: list_item.setProperty('fanart_image', fanart) list_item.setInfo('video', {'title': list_item.getLabel()}) list_item.setProperty('isPlayable', playable) list_item.addContextMenuItems(menu_items, replaceItems=replace_menu) xbmcplugin.addDirectoryItem(int(sys.argv[1]), liz_url, list_item, isFolder=is_folder, totalItems=total_items) def parse_query(query): q = {'mode': 'main'} if query.startswith('?'): query = query[1:] queries = urlparse.parse_qs(query) for key in queries: if len(queries[key]) == 1: q[key] = queries[key][0] else: q[key] = queries[key] return q def notify(header=None, msg='', duration=2000, sound=None): if header is None: header = get_name() if sound is None: sound = get_setting('mute_notifications') == 'false' icon_path = os.path.join(get_path(), 'icon.png') try: xbmcgui.Dialog().notification(header, msg, icon_path, duration, sound) except: builtin = "XBMC.Notification(%s,%s, %s, %s)" % (header, msg, duration, icon_path) xbmc.executebuiltin(builtin) def get_current_view(): skinPath = translate_path('special://skin/') xml = os.path.join(skinPath, 'addon.xml') f = xbmcvfs.File(xml) read = f.read() f.close() try: src = re.search('defaultresolution="([^"]+)', read, re.DOTALL).group(1) except: src = re.search('<res.+?folder="([^"]+)', read, re.DOTALL).group(1) src = os.path.join(skinPath, src, 'MyVideoNav.xml') f = xbmcvfs.File(src) read = f.read() f.close() match = re.search('<views>([^<]+)', read, re.DOTALL) if match: views = match.group(1) for view in views.split(','): if xbmc.getInfoLabel('Control.GetLabel(%s)' % (view)): return view <|fim▁end|>
get_version
<|file_name|>kodi.py<|end_file_name|><|fim▁begin|>""" SALTS XBMC Addon Copyright (C) 2015 tknorris This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import xbmcaddon import xbmcplugin import xbmcgui import xbmc import xbmcvfs import urllib import urlparse import sys import os import re addon = xbmcaddon.Addon() get_setting = addon.getSetting show_settings = addon.openSettings def get_path(): return addon.getAddonInfo('path').decode('utf-8') def get_profile(): return addon.getAddonInfo('profile').decode('utf-8') def translate_path(path): return xbmc.translatePath(path).decode('utf-8') def set_setting(id, value): if not isinstance(value, basestring): value = str(value) addon.setSetting(id, value) def get_version(): return addon.getAddonInfo('version') def <|fim_middle|>(): return addon.getAddonInfo('id') def get_name(): return addon.getAddonInfo('name') def get_plugin_url(queries): try: query = urllib.urlencode(queries) except UnicodeEncodeError: for k in queries: if isinstance(queries[k], unicode): queries[k] = queries[k].encode('utf-8') query = urllib.urlencode(queries) return sys.argv[0] + '?' + query def end_of_directory(cache_to_disc=True): xbmcplugin.endOfDirectory(int(sys.argv[1]), cacheToDisc=cache_to_disc) def set_content(content): xbmcplugin.setContent(int(sys.argv[1]), content) def create_item(queries, label, thumb='', fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): list_item = xbmcgui.ListItem(label, iconImage=thumb, thumbnailImage=thumb) add_item(queries, list_item, fanart, is_folder, is_playable, total_items, menu_items, replace_menu) def add_item(queries, list_item, fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): if menu_items is None: menu_items = [] if is_folder is None: is_folder = False if is_playable else True if is_playable is None: playable = 'false' if is_folder else 'true' else: playable = 'true' if is_playable else 'false' liz_url = get_plugin_url(queries) if fanart: list_item.setProperty('fanart_image', fanart) list_item.setInfo('video', {'title': list_item.getLabel()}) list_item.setProperty('isPlayable', playable) list_item.addContextMenuItems(menu_items, replaceItems=replace_menu) xbmcplugin.addDirectoryItem(int(sys.argv[1]), liz_url, list_item, isFolder=is_folder, totalItems=total_items) def parse_query(query): q = {'mode': 'main'} if query.startswith('?'): query = query[1:] queries = urlparse.parse_qs(query) for key in queries: if len(queries[key]) == 1: q[key] = queries[key][0] else: q[key] = queries[key] return q def notify(header=None, msg='', duration=2000, sound=None): if header is None: header = get_name() if sound is None: sound = get_setting('mute_notifications') == 'false' icon_path = os.path.join(get_path(), 'icon.png') try: xbmcgui.Dialog().notification(header, msg, icon_path, duration, sound) except: builtin = "XBMC.Notification(%s,%s, %s, %s)" % (header, msg, duration, icon_path) xbmc.executebuiltin(builtin) def get_current_view(): skinPath = translate_path('special://skin/') xml = os.path.join(skinPath, 'addon.xml') f = xbmcvfs.File(xml) read = f.read() f.close() try: src = re.search('defaultresolution="([^"]+)', read, re.DOTALL).group(1) except: src = re.search('<res.+?folder="([^"]+)', read, re.DOTALL).group(1) src = os.path.join(skinPath, src, 'MyVideoNav.xml') f = xbmcvfs.File(src) read = f.read() f.close() match = re.search('<views>([^<]+)', read, re.DOTALL) if match: views = match.group(1) for view in views.split(','): if xbmc.getInfoLabel('Control.GetLabel(%s)' % (view)): return view <|fim▁end|>
get_id
<|file_name|>kodi.py<|end_file_name|><|fim▁begin|>""" SALTS XBMC Addon Copyright (C) 2015 tknorris This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import xbmcaddon import xbmcplugin import xbmcgui import xbmc import xbmcvfs import urllib import urlparse import sys import os import re addon = xbmcaddon.Addon() get_setting = addon.getSetting show_settings = addon.openSettings def get_path(): return addon.getAddonInfo('path').decode('utf-8') def get_profile(): return addon.getAddonInfo('profile').decode('utf-8') def translate_path(path): return xbmc.translatePath(path).decode('utf-8') def set_setting(id, value): if not isinstance(value, basestring): value = str(value) addon.setSetting(id, value) def get_version(): return addon.getAddonInfo('version') def get_id(): return addon.getAddonInfo('id') def <|fim_middle|>(): return addon.getAddonInfo('name') def get_plugin_url(queries): try: query = urllib.urlencode(queries) except UnicodeEncodeError: for k in queries: if isinstance(queries[k], unicode): queries[k] = queries[k].encode('utf-8') query = urllib.urlencode(queries) return sys.argv[0] + '?' + query def end_of_directory(cache_to_disc=True): xbmcplugin.endOfDirectory(int(sys.argv[1]), cacheToDisc=cache_to_disc) def set_content(content): xbmcplugin.setContent(int(sys.argv[1]), content) def create_item(queries, label, thumb='', fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): list_item = xbmcgui.ListItem(label, iconImage=thumb, thumbnailImage=thumb) add_item(queries, list_item, fanart, is_folder, is_playable, total_items, menu_items, replace_menu) def add_item(queries, list_item, fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): if menu_items is None: menu_items = [] if is_folder is None: is_folder = False if is_playable else True if is_playable is None: playable = 'false' if is_folder else 'true' else: playable = 'true' if is_playable else 'false' liz_url = get_plugin_url(queries) if fanart: list_item.setProperty('fanart_image', fanart) list_item.setInfo('video', {'title': list_item.getLabel()}) list_item.setProperty('isPlayable', playable) list_item.addContextMenuItems(menu_items, replaceItems=replace_menu) xbmcplugin.addDirectoryItem(int(sys.argv[1]), liz_url, list_item, isFolder=is_folder, totalItems=total_items) def parse_query(query): q = {'mode': 'main'} if query.startswith('?'): query = query[1:] queries = urlparse.parse_qs(query) for key in queries: if len(queries[key]) == 1: q[key] = queries[key][0] else: q[key] = queries[key] return q def notify(header=None, msg='', duration=2000, sound=None): if header is None: header = get_name() if sound is None: sound = get_setting('mute_notifications') == 'false' icon_path = os.path.join(get_path(), 'icon.png') try: xbmcgui.Dialog().notification(header, msg, icon_path, duration, sound) except: builtin = "XBMC.Notification(%s,%s, %s, %s)" % (header, msg, duration, icon_path) xbmc.executebuiltin(builtin) def get_current_view(): skinPath = translate_path('special://skin/') xml = os.path.join(skinPath, 'addon.xml') f = xbmcvfs.File(xml) read = f.read() f.close() try: src = re.search('defaultresolution="([^"]+)', read, re.DOTALL).group(1) except: src = re.search('<res.+?folder="([^"]+)', read, re.DOTALL).group(1) src = os.path.join(skinPath, src, 'MyVideoNav.xml') f = xbmcvfs.File(src) read = f.read() f.close() match = re.search('<views>([^<]+)', read, re.DOTALL) if match: views = match.group(1) for view in views.split(','): if xbmc.getInfoLabel('Control.GetLabel(%s)' % (view)): return view <|fim▁end|>
get_name
<|file_name|>kodi.py<|end_file_name|><|fim▁begin|>""" SALTS XBMC Addon Copyright (C) 2015 tknorris This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import xbmcaddon import xbmcplugin import xbmcgui import xbmc import xbmcvfs import urllib import urlparse import sys import os import re addon = xbmcaddon.Addon() get_setting = addon.getSetting show_settings = addon.openSettings def get_path(): return addon.getAddonInfo('path').decode('utf-8') def get_profile(): return addon.getAddonInfo('profile').decode('utf-8') def translate_path(path): return xbmc.translatePath(path).decode('utf-8') def set_setting(id, value): if not isinstance(value, basestring): value = str(value) addon.setSetting(id, value) def get_version(): return addon.getAddonInfo('version') def get_id(): return addon.getAddonInfo('id') def get_name(): return addon.getAddonInfo('name') def <|fim_middle|>(queries): try: query = urllib.urlencode(queries) except UnicodeEncodeError: for k in queries: if isinstance(queries[k], unicode): queries[k] = queries[k].encode('utf-8') query = urllib.urlencode(queries) return sys.argv[0] + '?' + query def end_of_directory(cache_to_disc=True): xbmcplugin.endOfDirectory(int(sys.argv[1]), cacheToDisc=cache_to_disc) def set_content(content): xbmcplugin.setContent(int(sys.argv[1]), content) def create_item(queries, label, thumb='', fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): list_item = xbmcgui.ListItem(label, iconImage=thumb, thumbnailImage=thumb) add_item(queries, list_item, fanart, is_folder, is_playable, total_items, menu_items, replace_menu) def add_item(queries, list_item, fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): if menu_items is None: menu_items = [] if is_folder is None: is_folder = False if is_playable else True if is_playable is None: playable = 'false' if is_folder else 'true' else: playable = 'true' if is_playable else 'false' liz_url = get_plugin_url(queries) if fanart: list_item.setProperty('fanart_image', fanart) list_item.setInfo('video', {'title': list_item.getLabel()}) list_item.setProperty('isPlayable', playable) list_item.addContextMenuItems(menu_items, replaceItems=replace_menu) xbmcplugin.addDirectoryItem(int(sys.argv[1]), liz_url, list_item, isFolder=is_folder, totalItems=total_items) def parse_query(query): q = {'mode': 'main'} if query.startswith('?'): query = query[1:] queries = urlparse.parse_qs(query) for key in queries: if len(queries[key]) == 1: q[key] = queries[key][0] else: q[key] = queries[key] return q def notify(header=None, msg='', duration=2000, sound=None): if header is None: header = get_name() if sound is None: sound = get_setting('mute_notifications') == 'false' icon_path = os.path.join(get_path(), 'icon.png') try: xbmcgui.Dialog().notification(header, msg, icon_path, duration, sound) except: builtin = "XBMC.Notification(%s,%s, %s, %s)" % (header, msg, duration, icon_path) xbmc.executebuiltin(builtin) def get_current_view(): skinPath = translate_path('special://skin/') xml = os.path.join(skinPath, 'addon.xml') f = xbmcvfs.File(xml) read = f.read() f.close() try: src = re.search('defaultresolution="([^"]+)', read, re.DOTALL).group(1) except: src = re.search('<res.+?folder="([^"]+)', read, re.DOTALL).group(1) src = os.path.join(skinPath, src, 'MyVideoNav.xml') f = xbmcvfs.File(src) read = f.read() f.close() match = re.search('<views>([^<]+)', read, re.DOTALL) if match: views = match.group(1) for view in views.split(','): if xbmc.getInfoLabel('Control.GetLabel(%s)' % (view)): return view <|fim▁end|>
get_plugin_url
<|file_name|>kodi.py<|end_file_name|><|fim▁begin|>""" SALTS XBMC Addon Copyright (C) 2015 tknorris This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import xbmcaddon import xbmcplugin import xbmcgui import xbmc import xbmcvfs import urllib import urlparse import sys import os import re addon = xbmcaddon.Addon() get_setting = addon.getSetting show_settings = addon.openSettings def get_path(): return addon.getAddonInfo('path').decode('utf-8') def get_profile(): return addon.getAddonInfo('profile').decode('utf-8') def translate_path(path): return xbmc.translatePath(path).decode('utf-8') def set_setting(id, value): if not isinstance(value, basestring): value = str(value) addon.setSetting(id, value) def get_version(): return addon.getAddonInfo('version') def get_id(): return addon.getAddonInfo('id') def get_name(): return addon.getAddonInfo('name') def get_plugin_url(queries): try: query = urllib.urlencode(queries) except UnicodeEncodeError: for k in queries: if isinstance(queries[k], unicode): queries[k] = queries[k].encode('utf-8') query = urllib.urlencode(queries) return sys.argv[0] + '?' + query def <|fim_middle|>(cache_to_disc=True): xbmcplugin.endOfDirectory(int(sys.argv[1]), cacheToDisc=cache_to_disc) def set_content(content): xbmcplugin.setContent(int(sys.argv[1]), content) def create_item(queries, label, thumb='', fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): list_item = xbmcgui.ListItem(label, iconImage=thumb, thumbnailImage=thumb) add_item(queries, list_item, fanart, is_folder, is_playable, total_items, menu_items, replace_menu) def add_item(queries, list_item, fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): if menu_items is None: menu_items = [] if is_folder is None: is_folder = False if is_playable else True if is_playable is None: playable = 'false' if is_folder else 'true' else: playable = 'true' if is_playable else 'false' liz_url = get_plugin_url(queries) if fanart: list_item.setProperty('fanart_image', fanart) list_item.setInfo('video', {'title': list_item.getLabel()}) list_item.setProperty('isPlayable', playable) list_item.addContextMenuItems(menu_items, replaceItems=replace_menu) xbmcplugin.addDirectoryItem(int(sys.argv[1]), liz_url, list_item, isFolder=is_folder, totalItems=total_items) def parse_query(query): q = {'mode': 'main'} if query.startswith('?'): query = query[1:] queries = urlparse.parse_qs(query) for key in queries: if len(queries[key]) == 1: q[key] = queries[key][0] else: q[key] = queries[key] return q def notify(header=None, msg='', duration=2000, sound=None): if header is None: header = get_name() if sound is None: sound = get_setting('mute_notifications') == 'false' icon_path = os.path.join(get_path(), 'icon.png') try: xbmcgui.Dialog().notification(header, msg, icon_path, duration, sound) except: builtin = "XBMC.Notification(%s,%s, %s, %s)" % (header, msg, duration, icon_path) xbmc.executebuiltin(builtin) def get_current_view(): skinPath = translate_path('special://skin/') xml = os.path.join(skinPath, 'addon.xml') f = xbmcvfs.File(xml) read = f.read() f.close() try: src = re.search('defaultresolution="([^"]+)', read, re.DOTALL).group(1) except: src = re.search('<res.+?folder="([^"]+)', read, re.DOTALL).group(1) src = os.path.join(skinPath, src, 'MyVideoNav.xml') f = xbmcvfs.File(src) read = f.read() f.close() match = re.search('<views>([^<]+)', read, re.DOTALL) if match: views = match.group(1) for view in views.split(','): if xbmc.getInfoLabel('Control.GetLabel(%s)' % (view)): return view <|fim▁end|>
end_of_directory
<|file_name|>kodi.py<|end_file_name|><|fim▁begin|>""" SALTS XBMC Addon Copyright (C) 2015 tknorris This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import xbmcaddon import xbmcplugin import xbmcgui import xbmc import xbmcvfs import urllib import urlparse import sys import os import re addon = xbmcaddon.Addon() get_setting = addon.getSetting show_settings = addon.openSettings def get_path(): return addon.getAddonInfo('path').decode('utf-8') def get_profile(): return addon.getAddonInfo('profile').decode('utf-8') def translate_path(path): return xbmc.translatePath(path).decode('utf-8') def set_setting(id, value): if not isinstance(value, basestring): value = str(value) addon.setSetting(id, value) def get_version(): return addon.getAddonInfo('version') def get_id(): return addon.getAddonInfo('id') def get_name(): return addon.getAddonInfo('name') def get_plugin_url(queries): try: query = urllib.urlencode(queries) except UnicodeEncodeError: for k in queries: if isinstance(queries[k], unicode): queries[k] = queries[k].encode('utf-8') query = urllib.urlencode(queries) return sys.argv[0] + '?' + query def end_of_directory(cache_to_disc=True): xbmcplugin.endOfDirectory(int(sys.argv[1]), cacheToDisc=cache_to_disc) def <|fim_middle|>(content): xbmcplugin.setContent(int(sys.argv[1]), content) def create_item(queries, label, thumb='', fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): list_item = xbmcgui.ListItem(label, iconImage=thumb, thumbnailImage=thumb) add_item(queries, list_item, fanart, is_folder, is_playable, total_items, menu_items, replace_menu) def add_item(queries, list_item, fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): if menu_items is None: menu_items = [] if is_folder is None: is_folder = False if is_playable else True if is_playable is None: playable = 'false' if is_folder else 'true' else: playable = 'true' if is_playable else 'false' liz_url = get_plugin_url(queries) if fanart: list_item.setProperty('fanart_image', fanart) list_item.setInfo('video', {'title': list_item.getLabel()}) list_item.setProperty('isPlayable', playable) list_item.addContextMenuItems(menu_items, replaceItems=replace_menu) xbmcplugin.addDirectoryItem(int(sys.argv[1]), liz_url, list_item, isFolder=is_folder, totalItems=total_items) def parse_query(query): q = {'mode': 'main'} if query.startswith('?'): query = query[1:] queries = urlparse.parse_qs(query) for key in queries: if len(queries[key]) == 1: q[key] = queries[key][0] else: q[key] = queries[key] return q def notify(header=None, msg='', duration=2000, sound=None): if header is None: header = get_name() if sound is None: sound = get_setting('mute_notifications') == 'false' icon_path = os.path.join(get_path(), 'icon.png') try: xbmcgui.Dialog().notification(header, msg, icon_path, duration, sound) except: builtin = "XBMC.Notification(%s,%s, %s, %s)" % (header, msg, duration, icon_path) xbmc.executebuiltin(builtin) def get_current_view(): skinPath = translate_path('special://skin/') xml = os.path.join(skinPath, 'addon.xml') f = xbmcvfs.File(xml) read = f.read() f.close() try: src = re.search('defaultresolution="([^"]+)', read, re.DOTALL).group(1) except: src = re.search('<res.+?folder="([^"]+)', read, re.DOTALL).group(1) src = os.path.join(skinPath, src, 'MyVideoNav.xml') f = xbmcvfs.File(src) read = f.read() f.close() match = re.search('<views>([^<]+)', read, re.DOTALL) if match: views = match.group(1) for view in views.split(','): if xbmc.getInfoLabel('Control.GetLabel(%s)' % (view)): return view <|fim▁end|>
set_content
<|file_name|>kodi.py<|end_file_name|><|fim▁begin|>""" SALTS XBMC Addon Copyright (C) 2015 tknorris This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import xbmcaddon import xbmcplugin import xbmcgui import xbmc import xbmcvfs import urllib import urlparse import sys import os import re addon = xbmcaddon.Addon() get_setting = addon.getSetting show_settings = addon.openSettings def get_path(): return addon.getAddonInfo('path').decode('utf-8') def get_profile(): return addon.getAddonInfo('profile').decode('utf-8') def translate_path(path): return xbmc.translatePath(path).decode('utf-8') def set_setting(id, value): if not isinstance(value, basestring): value = str(value) addon.setSetting(id, value) def get_version(): return addon.getAddonInfo('version') def get_id(): return addon.getAddonInfo('id') def get_name(): return addon.getAddonInfo('name') def get_plugin_url(queries): try: query = urllib.urlencode(queries) except UnicodeEncodeError: for k in queries: if isinstance(queries[k], unicode): queries[k] = queries[k].encode('utf-8') query = urllib.urlencode(queries) return sys.argv[0] + '?' + query def end_of_directory(cache_to_disc=True): xbmcplugin.endOfDirectory(int(sys.argv[1]), cacheToDisc=cache_to_disc) def set_content(content): xbmcplugin.setContent(int(sys.argv[1]), content) def <|fim_middle|>(queries, label, thumb='', fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): list_item = xbmcgui.ListItem(label, iconImage=thumb, thumbnailImage=thumb) add_item(queries, list_item, fanart, is_folder, is_playable, total_items, menu_items, replace_menu) def add_item(queries, list_item, fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): if menu_items is None: menu_items = [] if is_folder is None: is_folder = False if is_playable else True if is_playable is None: playable = 'false' if is_folder else 'true' else: playable = 'true' if is_playable else 'false' liz_url = get_plugin_url(queries) if fanart: list_item.setProperty('fanart_image', fanart) list_item.setInfo('video', {'title': list_item.getLabel()}) list_item.setProperty('isPlayable', playable) list_item.addContextMenuItems(menu_items, replaceItems=replace_menu) xbmcplugin.addDirectoryItem(int(sys.argv[1]), liz_url, list_item, isFolder=is_folder, totalItems=total_items) def parse_query(query): q = {'mode': 'main'} if query.startswith('?'): query = query[1:] queries = urlparse.parse_qs(query) for key in queries: if len(queries[key]) == 1: q[key] = queries[key][0] else: q[key] = queries[key] return q def notify(header=None, msg='', duration=2000, sound=None): if header is None: header = get_name() if sound is None: sound = get_setting('mute_notifications') == 'false' icon_path = os.path.join(get_path(), 'icon.png') try: xbmcgui.Dialog().notification(header, msg, icon_path, duration, sound) except: builtin = "XBMC.Notification(%s,%s, %s, %s)" % (header, msg, duration, icon_path) xbmc.executebuiltin(builtin) def get_current_view(): skinPath = translate_path('special://skin/') xml = os.path.join(skinPath, 'addon.xml') f = xbmcvfs.File(xml) read = f.read() f.close() try: src = re.search('defaultresolution="([^"]+)', read, re.DOTALL).group(1) except: src = re.search('<res.+?folder="([^"]+)', read, re.DOTALL).group(1) src = os.path.join(skinPath, src, 'MyVideoNav.xml') f = xbmcvfs.File(src) read = f.read() f.close() match = re.search('<views>([^<]+)', read, re.DOTALL) if match: views = match.group(1) for view in views.split(','): if xbmc.getInfoLabel('Control.GetLabel(%s)' % (view)): return view <|fim▁end|>
create_item
<|file_name|>kodi.py<|end_file_name|><|fim▁begin|>""" SALTS XBMC Addon Copyright (C) 2015 tknorris This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import xbmcaddon import xbmcplugin import xbmcgui import xbmc import xbmcvfs import urllib import urlparse import sys import os import re addon = xbmcaddon.Addon() get_setting = addon.getSetting show_settings = addon.openSettings def get_path(): return addon.getAddonInfo('path').decode('utf-8') def get_profile(): return addon.getAddonInfo('profile').decode('utf-8') def translate_path(path): return xbmc.translatePath(path).decode('utf-8') def set_setting(id, value): if not isinstance(value, basestring): value = str(value) addon.setSetting(id, value) def get_version(): return addon.getAddonInfo('version') def get_id(): return addon.getAddonInfo('id') def get_name(): return addon.getAddonInfo('name') def get_plugin_url(queries): try: query = urllib.urlencode(queries) except UnicodeEncodeError: for k in queries: if isinstance(queries[k], unicode): queries[k] = queries[k].encode('utf-8') query = urllib.urlencode(queries) return sys.argv[0] + '?' + query def end_of_directory(cache_to_disc=True): xbmcplugin.endOfDirectory(int(sys.argv[1]), cacheToDisc=cache_to_disc) def set_content(content): xbmcplugin.setContent(int(sys.argv[1]), content) def create_item(queries, label, thumb='', fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): list_item = xbmcgui.ListItem(label, iconImage=thumb, thumbnailImage=thumb) add_item(queries, list_item, fanart, is_folder, is_playable, total_items, menu_items, replace_menu) def <|fim_middle|>(queries, list_item, fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): if menu_items is None: menu_items = [] if is_folder is None: is_folder = False if is_playable else True if is_playable is None: playable = 'false' if is_folder else 'true' else: playable = 'true' if is_playable else 'false' liz_url = get_plugin_url(queries) if fanart: list_item.setProperty('fanart_image', fanart) list_item.setInfo('video', {'title': list_item.getLabel()}) list_item.setProperty('isPlayable', playable) list_item.addContextMenuItems(menu_items, replaceItems=replace_menu) xbmcplugin.addDirectoryItem(int(sys.argv[1]), liz_url, list_item, isFolder=is_folder, totalItems=total_items) def parse_query(query): q = {'mode': 'main'} if query.startswith('?'): query = query[1:] queries = urlparse.parse_qs(query) for key in queries: if len(queries[key]) == 1: q[key] = queries[key][0] else: q[key] = queries[key] return q def notify(header=None, msg='', duration=2000, sound=None): if header is None: header = get_name() if sound is None: sound = get_setting('mute_notifications') == 'false' icon_path = os.path.join(get_path(), 'icon.png') try: xbmcgui.Dialog().notification(header, msg, icon_path, duration, sound) except: builtin = "XBMC.Notification(%s,%s, %s, %s)" % (header, msg, duration, icon_path) xbmc.executebuiltin(builtin) def get_current_view(): skinPath = translate_path('special://skin/') xml = os.path.join(skinPath, 'addon.xml') f = xbmcvfs.File(xml) read = f.read() f.close() try: src = re.search('defaultresolution="([^"]+)', read, re.DOTALL).group(1) except: src = re.search('<res.+?folder="([^"]+)', read, re.DOTALL).group(1) src = os.path.join(skinPath, src, 'MyVideoNav.xml') f = xbmcvfs.File(src) read = f.read() f.close() match = re.search('<views>([^<]+)', read, re.DOTALL) if match: views = match.group(1) for view in views.split(','): if xbmc.getInfoLabel('Control.GetLabel(%s)' % (view)): return view <|fim▁end|>
add_item
<|file_name|>kodi.py<|end_file_name|><|fim▁begin|>""" SALTS XBMC Addon Copyright (C) 2015 tknorris This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import xbmcaddon import xbmcplugin import xbmcgui import xbmc import xbmcvfs import urllib import urlparse import sys import os import re addon = xbmcaddon.Addon() get_setting = addon.getSetting show_settings = addon.openSettings def get_path(): return addon.getAddonInfo('path').decode('utf-8') def get_profile(): return addon.getAddonInfo('profile').decode('utf-8') def translate_path(path): return xbmc.translatePath(path).decode('utf-8') def set_setting(id, value): if not isinstance(value, basestring): value = str(value) addon.setSetting(id, value) def get_version(): return addon.getAddonInfo('version') def get_id(): return addon.getAddonInfo('id') def get_name(): return addon.getAddonInfo('name') def get_plugin_url(queries): try: query = urllib.urlencode(queries) except UnicodeEncodeError: for k in queries: if isinstance(queries[k], unicode): queries[k] = queries[k].encode('utf-8') query = urllib.urlencode(queries) return sys.argv[0] + '?' + query def end_of_directory(cache_to_disc=True): xbmcplugin.endOfDirectory(int(sys.argv[1]), cacheToDisc=cache_to_disc) def set_content(content): xbmcplugin.setContent(int(sys.argv[1]), content) def create_item(queries, label, thumb='', fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): list_item = xbmcgui.ListItem(label, iconImage=thumb, thumbnailImage=thumb) add_item(queries, list_item, fanart, is_folder, is_playable, total_items, menu_items, replace_menu) def add_item(queries, list_item, fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): if menu_items is None: menu_items = [] if is_folder is None: is_folder = False if is_playable else True if is_playable is None: playable = 'false' if is_folder else 'true' else: playable = 'true' if is_playable else 'false' liz_url = get_plugin_url(queries) if fanart: list_item.setProperty('fanart_image', fanart) list_item.setInfo('video', {'title': list_item.getLabel()}) list_item.setProperty('isPlayable', playable) list_item.addContextMenuItems(menu_items, replaceItems=replace_menu) xbmcplugin.addDirectoryItem(int(sys.argv[1]), liz_url, list_item, isFolder=is_folder, totalItems=total_items) def <|fim_middle|>(query): q = {'mode': 'main'} if query.startswith('?'): query = query[1:] queries = urlparse.parse_qs(query) for key in queries: if len(queries[key]) == 1: q[key] = queries[key][0] else: q[key] = queries[key] return q def notify(header=None, msg='', duration=2000, sound=None): if header is None: header = get_name() if sound is None: sound = get_setting('mute_notifications') == 'false' icon_path = os.path.join(get_path(), 'icon.png') try: xbmcgui.Dialog().notification(header, msg, icon_path, duration, sound) except: builtin = "XBMC.Notification(%s,%s, %s, %s)" % (header, msg, duration, icon_path) xbmc.executebuiltin(builtin) def get_current_view(): skinPath = translate_path('special://skin/') xml = os.path.join(skinPath, 'addon.xml') f = xbmcvfs.File(xml) read = f.read() f.close() try: src = re.search('defaultresolution="([^"]+)', read, re.DOTALL).group(1) except: src = re.search('<res.+?folder="([^"]+)', read, re.DOTALL).group(1) src = os.path.join(skinPath, src, 'MyVideoNav.xml') f = xbmcvfs.File(src) read = f.read() f.close() match = re.search('<views>([^<]+)', read, re.DOTALL) if match: views = match.group(1) for view in views.split(','): if xbmc.getInfoLabel('Control.GetLabel(%s)' % (view)): return view <|fim▁end|>
parse_query
<|file_name|>kodi.py<|end_file_name|><|fim▁begin|>""" SALTS XBMC Addon Copyright (C) 2015 tknorris This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import xbmcaddon import xbmcplugin import xbmcgui import xbmc import xbmcvfs import urllib import urlparse import sys import os import re addon = xbmcaddon.Addon() get_setting = addon.getSetting show_settings = addon.openSettings def get_path(): return addon.getAddonInfo('path').decode('utf-8') def get_profile(): return addon.getAddonInfo('profile').decode('utf-8') def translate_path(path): return xbmc.translatePath(path).decode('utf-8') def set_setting(id, value): if not isinstance(value, basestring): value = str(value) addon.setSetting(id, value) def get_version(): return addon.getAddonInfo('version') def get_id(): return addon.getAddonInfo('id') def get_name(): return addon.getAddonInfo('name') def get_plugin_url(queries): try: query = urllib.urlencode(queries) except UnicodeEncodeError: for k in queries: if isinstance(queries[k], unicode): queries[k] = queries[k].encode('utf-8') query = urllib.urlencode(queries) return sys.argv[0] + '?' + query def end_of_directory(cache_to_disc=True): xbmcplugin.endOfDirectory(int(sys.argv[1]), cacheToDisc=cache_to_disc) def set_content(content): xbmcplugin.setContent(int(sys.argv[1]), content) def create_item(queries, label, thumb='', fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): list_item = xbmcgui.ListItem(label, iconImage=thumb, thumbnailImage=thumb) add_item(queries, list_item, fanart, is_folder, is_playable, total_items, menu_items, replace_menu) def add_item(queries, list_item, fanart='', is_folder=None, is_playable=None, total_items=0, menu_items=None, replace_menu=False): if menu_items is None: menu_items = [] if is_folder is None: is_folder = False if is_playable else True if is_playable is None: playable = 'false' if is_folder else 'true' else: playable = 'true' if is_playable else 'false' liz_url = get_plugin_url(queries) if fanart: list_item.setProperty('fanart_image', fanart) list_item.setInfo('video', {'title': list_item.getLabel()}) list_item.setProperty('isPlayable', playable) list_item.addContextMenuItems(menu_items, replaceItems=replace_menu) xbmcplugin.addDirectoryItem(int(sys.argv[1]), liz_url, list_item, isFolder=is_folder, totalItems=total_items) def parse_query(query): q = {'mode': 'main'} if query.startswith('?'): query = query[1:] queries = urlparse.parse_qs(query) for key in queries: if len(queries[key]) == 1: q[key] = queries[key][0] else: q[key] = queries[key] return q def <|fim_middle|>(header=None, msg='', duration=2000, sound=None): if header is None: header = get_name() if sound is None: sound = get_setting('mute_notifications') == 'false' icon_path = os.path.join(get_path(), 'icon.png') try: xbmcgui.Dialog().notification(header, msg, icon_path, duration, sound) except: builtin = "XBMC.Notification(%s,%s, %s, %s)" % (header, msg, duration, icon_path) xbmc.executebuiltin(builtin) def get_current_view(): skinPath = translate_path('special://skin/') xml = os.path.join(skinPath, 'addon.xml') f = xbmcvfs.File(xml) read = f.read() f.close() try: src = re.search('defaultresolution="([^"]+)', read, re.DOTALL).group(1) except: src = re.search('<res.+?folder="([^"]+)', read, re.DOTALL).group(1) src = os.path.join(skinPath, src, 'MyVideoNav.xml') f = xbmcvfs.File(src) read = f.read() f.close() match = re.search('<views>([^<]+)', read, re.DOTALL) if match: views = match.group(1) for view in views.split(','): if xbmc.getInfoLabel('Control.GetLabel(%s)' % (view)): return view <|fim▁end|>
notify