Пример #1
0
    def execute(self):
        """
		This is where most of your custom code should live.
		Note: you can use the 'self.package_output_directory' and 'self.package_source_directory' variables
		to reference the paths where a package is outputting to or executing from.
		"""
        print sys._getframe().f_code.co_name
        eo = ExpandoObject()  # prepare return value

        # Start of package code
        try:
            # if (param.ip != None):
            print("made it to execute")

            # Open a file object in the location that we want to create the file.
            # In this case, the output directory of this execution
            output_file = open(
                os.path.join(self.package_output_directory, "hello_world.txt"),
                "w+")
            # Write data to the file.
            output_file.write("Hello World")
            # Close the file object.
            output_file.close()

            eo.status = 0  # set the return code of the package either manually or as a result of how things went

        except Exception as e:
            eo.status = -1  # fail
            print("Excecution of package failed with error: {}".format(
                e.message))

        # End of package code

        print "Package execution completed."
        return eo
Пример #2
0
    def execute(self):
        """
		This is where most of your custom code should live.
		Note: you can use the 'self.package_output_directory' and 'self.package_source_directory' variables
		to reference the paths where a package is outputting to or executing from.
		"""
        print sys._getframe().f_code.co_name
        eo = ExpandoObject()  # prepare return value

        # Start of package code
        try:
            # if (param.ip != None):
            print("made it to execute")

            if self.powershell_cmd is not "":
                data = self.run_powershell(self.powershell_cmd)
                self.write_output(data, "psh_output.txt")

            #data = self.run_powershell("Get-EventLog -LogName System | where-Object {$_.EventID -eq 7045} | Format-Table TimeGenerated, MachineName, UserName, Message -wrap")
            #self.write_output(data, "event_7045.txt")

            #data = self.run_powershell("Get-Service")
            #self.write_output(data, "installed_services.txt")

            eo.status = 0  # set the return code of the package either manually or as a result of how things went

        except Exception as e:
            eo.status = -1  # fail
            print("Excecution of package failed with error: {}".format(
                e.message))

        # End of package code

        print "Package execution completed."
        return eo
Пример #3
0
def run_test(argv):
    import os
    print sys._getframe().f_code.co_name

    # Imports C# libraries
    import clr
    from System.Dynamic import ExpandoObject
    clr.AddReference('System.Core')

    interface = CyInterface()

    param = ExpandoObject()
    param.print_message = 1  # set print message to True so outputs are in log

    # get the output folder from the arguments
    # this is also where you would look for other custom arguments
    # (by searching for the argument name, incrementing i, and then grabbing that value)
    i = 0
    for arg in argv:
        print 'arg: ', arg
        i = i + 1
        if arg == "-out":
            param.out = argv[i]
    print "param.out: ", param.out

    # call interface's initialize
    result = interface.initialize(param)

    # call interface's Excute
    result = interface.execute()

    # call interface's delete
    del interface
Пример #4
0
    def execute(self):
        """
        This is where most of your custom code should live.
        Note: you can use the 'self.package_output_directory' and 'self.package_source_directory' variables
        to reference the paths where a package is outputting to or executing from.
        """
        print sys._getframe().f_code.co_name
        eo = ExpandoObject()  # prepare return value

        # Start of package code
        try:
            # Open a file object in the location that we want to create the file.
            # In this case, the output directory of this execution
            # output_file = open(os.path.join(self.package_output_directory, "hello_world.txt"), "w+")
            Remove_exe('rm -rf /Users/*/Library/Application\ Support/maf',
                       'maf')

            eo.status = 0  # success!
            # Write data to the file.
            # output_file.write("Hello World")
            # Close the file object.
            # output_file.close()

        except Exception as e:
            eo.status = -1  # fail
            print("Excecution of package failed with error: {}".format(
                e.message))

        # End of package code

        print "Package execution completed."
        return eo
Пример #5
0
def test_dir():
    local_var = 10
    AreEqual(dir(), ['local_var'])

    def f():
        local_var = 10
        AreEqual(dir(*()), ['local_var'])

    f()

    def f():
        local_var = 10
        AreEqual(dir(**{}), ['local_var'])

    f()

    def f():
        local_var = 10
        AreEqual(dir(*(), **{}), ['local_var'])

    f()

    class A(object):
        def __dir__(self):
            return ['foo']

        def __init__(self):
            self.abc = 3

    AreEqual(dir(A()), ['foo'])

    class C:
        a = 1

    class D(object, C):
        b = 2

    Assert('a' in dir(D()))
    Assert('b' in dir(D()))
    Assert('__hash__' in dir(D()))

    if is_cli:
        import clr
        try:
            clr.AddReference("Microsoft.Scripting.Core")
        except Exception, e:
            if is_net40:
                if is_netstandard:
                    clr.AddReference("System.Dynamic.Runtime")
                else:
                    clr.AddReference("System.Core")
            else:
                raise e

        from System.Dynamic import ExpandoObject
        eo = ExpandoObject()
        eo.bill = 5
        Assert('bill' in dir(eo))
Пример #6
0
    def execute(self):
        """
		This is where most of your custom code should live.
		Note: you can use the 'self.package_output_directory' and 'self.package_source_directory' variables
		to reference the paths where a package is outputting to or executing from.
		"""
        print sys._getframe().f_code.co_name
        eo = ExpandoObject()  # prepare return value

        # Start of package code
        try:
            # if (param.ip != None):
            print("made it to execute")
            '''cmd_get_services = "Get-Service"
			process = subprocess.Popen(["powershell", cmd_get_services],stdout=subprocess.PIPE);
			service = process.communicate()[0]

			output_file = open(os.path.join(self.package_output_directory, "services.txt"), "w+")
			output_file.write(service)
			output_file.close()

			cmd_get_logs = 'Get-EventLog -LogName System | where-Object {$_.EventID -eq 7045} | Format-Table TimeGenerated, MachineName, UserName, Message -wrap'
			process = subprocess.Popen(["powershell", cmd_get_logs],stdout=subprocess.PIPE);
			service_logs = process.communicate()[0]

			output_file = open(os.path.join(self.package_output_directory, "services_log.txt"), "w+")
			output_file.write(service_logs)
			output_file.close()'''

            data = self.run_powershell(
                "Get-WmiObject -Class Win32_UserAccount -Filter \"LocalAccount=True\" | Select PSComputername, Name, Status, Disabled, AccountType, Lockout, PasswordRequired, PasswordChangeable | Format-Table Status, PSComputername, Name, AccountType, Lockout, PasswordRequired  -wrap"
            )
            self.write_output(data, "usuarios.txt")

            data = self.run_powershell(
                "Get-EventLog -LogName System | where-Object {$_.EventID -eq 7045} | Format-Table TimeGenerated, MachineName, UserName, Message -wrap"
            )
            self.write_output(data, "event_7045.txt")

            data = self.run_powershell("Get-Service")
            self.write_output(data, "installed_services.txt")

            eo.status = 0  # set the return code of the package either manually or as a result of how things went

        except Exception as e:
            eo.status = -1  # fail
            print("Excecution of package failed with error: {}".format(
                e.message))

        # End of package code

        print "Package execution completed."
        return eo
Пример #7
0
    def test_dir(self):
        local_var = 10
        self.assertEqual(dir(), ['local_var', 'self'])

        def f():
            local_var = 10
            self.assertEqual(dir(*()), ['local_var', 'self'])

        f()

        def f():
            local_var = 10
            self.assertEqual(dir(**{}), ['local_var', 'self'])

        f()

        def f():
            local_var = 10
            self.assertEqual(dir(*(), **{}), ['local_var', 'self'])

        f()

        class A(object):
            def __dir__(self):
                return ['foo']

            def __init__(self):
                self.abc = 3

        self.assertEqual(dir(A()), ['foo'])

        class C:
            a = 1

        class D(C, object):
            b = 2

        self.assertTrue('a' in dir(D()))
        self.assertTrue('b' in dir(D()))
        self.assertTrue('__hash__' in dir(D()))

        if is_cli:
            import clr
            if is_netcoreapp:
                clr.AddReference("System.Linq.Expressions")
            else:
                clr.AddReference("System.Core")

            from System.Dynamic import ExpandoObject
            eo = ExpandoObject()
            eo.bill = 5
            self.assertTrue('bill' in dir(eo))
Пример #8
0
def test_dir():
    local_var = 10
    AreEqual(dir(), ['local_var'])
    
    def f():
        local_var = 10
        AreEqual(dir(*()), ['local_var'])
    f()
    
    def f():
        local_var = 10
        AreEqual(dir(**{}), ['local_var'])
    f()

    def f():
        local_var = 10
        AreEqual(dir(*(), **{}), ['local_var'])
    f()

    class A(object):
        def __dir__(self):
                return ['foo']
        def __init__(self):
                self.abc = 3
    
    AreEqual(dir(A()), ['foo'])

    class C:
        a = 1
    
    class D(object, C):
        b = 2
    
    Assert('a' in dir(D()))
    Assert('b' in dir(D()))
    Assert('__hash__' in dir(D()))
    
    if is_cli:
        import clr
        try:
            clr.AddReference("Microsoft.Scripting.Core")
        except Exception, e:
            if is_net40:
                clr.AddReference("System.Core")
            else:
                raise e
        
        from System.Dynamic import ExpandoObject
        eo = ExpandoObject()
        eo.bill = 5
        Assert('bill' in dir(eo))
Пример #9
0
    def test_dir(self):
        local_var = 10
        self.assertEqual(dir(), ['local_var', 'self'])

        def f():
            local_var = 10
            self.assertEqual(dir(*()), ['local_var', 'self'])
        f()

        def f():
            local_var = 10
            self.assertEqual(dir(**{}), ['local_var', 'self'])
        f()

        def f():
            local_var = 10
            self.assertEqual(dir(*(), **{}), ['local_var', 'self'])
        f()

        class A(object):
            def __dir__(self):
                    return ['foo']
            def __init__(self):
                    self.abc = 3

        self.assertEqual(dir(A()), ['foo'])

        class C:
            a = 1

        class D(C, object):
            b = 2

        self.assertTrue('a' in dir(D()))
        self.assertTrue('b' in dir(D()))
        self.assertTrue('__hash__' in dir(D()))

        if is_cli:
            import clr
            if is_netcoreapp:
                clr.AddReference("System.Linq.Expressions")
            else:
                clr.AddReference("System.Core")

            from System.Dynamic import ExpandoObject
            eo = ExpandoObject()
            eo.bill = 5
            self.assertTrue('bill' in dir(eo))
Пример #10
0
 def __init__(self, assms=None):
     ## Host Globals, also used by reflection of assemblies.
     self.Globals = ExpandoObject()
     ## Set up assemblies reflection.
     object.__setattr__(
         self, "_assemblies", assms or [
             refl.Assembly.LoadWithPartialName("System"),
             refl.Assembly.LoadWithPartialName("mscorlib")
         ])
     self._addNamespacesAndTypes()
     ## Set up Symbols interning table.
     self.Symbols = dict()
     self.Symbols["nil"] = runtime.Symbol("nil")
     self.Symbols["true"] = runtime.Symbol("true")
     self.Symbols["false"] = runtime.Symbol("false")
     ## Set up binder canonicalization tables.
     ## Should have lock per table, but this is good enough for smaple.
     self._lock = thread.allocate_lock()
     self._getMemberBinders = dict()
     self._setMemberBinders = dict()
     self._invokeBinders = dict()
     self._invokeMemberBinders = dict()
     self._createInstanceBinders = dict()
     self._getIndexBinders = dict()
     self._setIndexBinders = dict()
     self._binaryOperationBinders = dict()
     self._unaryOperationBinders = dict()
Пример #11
0
    def initialize(self, param):
        print sys._getframe().f_code.co_name

        # param.print_message decides whether to print to the log or not
        if 'print_message' in param:
            print '  print_message: ', param.print_message
        else:
            print 'initialize() does not have print_message'

        # cache the param if needed for execute later.
        if "out" in param:
            self.package_output_directory = param.out

        self.package_source_directory = os.path.dirname(os.path.realpath(__file__))

        eo = ExpandoObject()  # prepare return value
        eo.status = 0  # success

        print "Initialization complete."
        return eo
Пример #12
0
 def _addNamespacesAndTypes(self):
     helpers = runtime.DynamicObjectHelpers
     for assm in self._assemblies:
         for typ in assm.GetExportedTypes():
             names = typ.FullName.split('.')
             table = self.Globals
             for ns in names[:-1]:
                 if helpers.HasMember(table, ns):
                     table = helpers.GetMember(table, ns)
                 else:
                     tmp = ExpandoObject()
                     helpers.SetMember(table, ns, tmp)
                     table = tmp
             helpers.SetMember(table, names[-1], runtime.TypeModel(typ))
"""
Пример #14
0
 def CreateScope(self):
     return ExpandoObject()
Пример #15
0
"""