コード例 #1
0
ファイル: activities.py プロジェクト: zzhsec/Osmedeus
    def put(self, workspace):
        ws_name = utils.get_workspace(workspace=workspace)
        activities_path = current_path + \
            '/storages/{0}/activities.json'.format(ws_name)
        if not self.get_activities(workspace=workspace):
            return {
                "error":
                "activities doesn't exist for {0} workspace".format(workspace)
            }
        module = request.args.get('module')

        raw_activities = self.activities
        for k, v in self.activities.items():
            if k == module:
                raw_activities[k] = []

                for item in v:
                    cmd_item = item
                    cmd_item['status'] = "Done"
                    raw_activities[k].append(cmd_item)

        # rewrite the activities again
        utils.just_write(activities_path, raw_activities, is_json=True)

        commands = [x for x in raw_activities[module]]
        return {'commands': commands}
コード例 #2
0
    def post(self):
        utils.make_directory('/tmp/osmedeus-tmp/')
        data = Save.parser.parse_args()
        raw_content = data['content']
        content = urllib.parse.unquote(raw_content)
        ts = str(int(time.time()))
        filepath = '/tmp/osmedeus-tmp/' + \
            hashlib.md5(ts.encode()).hexdigest()[:5]

        utils.just_write(filepath, content)
        return {"filepath": filepath}
コード例 #3
0
ファイル: activities.py プロジェクト: zcomtenten/Osmedeus
    def patch(self):
        data = Activities.parser.parse_args()
        raw_data = data['data']
        raw_data = unquote(data['data'])

        # print(raw_data)
        #because parser can't parse nested dict and use literal_eval to make sure we have a dict
        real_data = literal_eval(raw_data)
        module = real_data.get('module')
        content = real_data.get('content')

        activities = self.activities

        if activities.get(module) is not None:
            activities[module] += content

        utils.just_write(current_path + '/storages/activities.json', activities, is_json=True)
        return activities
コード例 #4
0
ファイル: activities.py プロジェクト: nacimuss/osmodeus
    def put(self):
        module = request.args.get('module')

        raw_activities = self.activities
        for k, v in self.activities.items():
            if k == module:
                raw_activities[k] = []

                for item in v:
                    cmd_item = item
                    cmd_item['status'] = "Done"
                    raw_activities[k].append(cmd_item)

        #rewrite the activities again
        utils.just_write(current_path + '/storages/activities.json',
                         raw_activities,
                         is_json=True)

        commands = [x for x in raw_activities[module]]
        return {'commands': commands}
コード例 #5
0
ファイル: configuration.py プロジェクト: wiwi936/Osmedeus
    def post(self):
        current_path = os.path.dirname(os.path.realpath(__file__))
        # global options
        data = Configurations.parser.parse_args()
        options = data['options']

        utils.just_write(current_path + '/storages/options.json',
                         options,
                         is_json=True)
        utils.print_info("Cleasning activities log")

        #Create skeleton activities
        commands = utils.reading_json(current_path + '/storages/commands.json')
        raw_activities = {}
        for k, v in commands.items():
            raw_activities[k] = []
        utils.just_write(current_path + '/storages/activities.json',
                         raw_activities,
                         is_json=True)

        return options
コード例 #6
0
    def post(self):
        current_path = os.path.dirname(os.path.realpath(__file__))
        # global options
        data = Configurations.parser.parse_args()
        options = data['options']

        utils.just_write(current_path + '/storages/options.json', options, is_json=True)

        if options.get('FORCE') == "False":
            old_log = options['WORKSPACE'] + '/log.json'
            if utils.not_empty_file(old_log) and utils.reading_json(old_log):
                utils.print_info(
                    "It's already done. use '-f' options to force rerun the module")

                raw_activities = utils.reading_json(
                    options['WORKSPACE'] + '/log.json')
                utils.just_write(current_path + '/storages/activities.json',
                                 raw_activities, is_json=True)

                return options

        
        utils.print_info("Cleasning activities log")
        #Create skeleton activities
        commands = utils.reading_json(current_path + '/storages/commands.json')
        raw_activities = {}
        for k,v in commands.items():
            raw_activities[k] = []
        utils.just_write(current_path + '/storages/activities.json',
                         raw_activities, is_json=True)

        return options
コード例 #7
0
ファイル: app.py プロジェクト: NejibNBM/Osmedeus
    def post(self):
        data = Cmd.parser.parse_args()
        cmd = data['cmd']
        std_path = data['std_path']
        output_path = data['output_path']
        module = data['module']

        activity = {
            'cmd': cmd,
            'std_path': std_path,
            'output_path': output_path,
            'status': 'Running'
        }

        # this
        if activities_log.get(module):
            activities_log[module].append(activity)
        else:
            activities_log[module] = [activity]

        utils.print_info("Execute: {0} ".format(cmd))
        stdout = execute.run(cmd)
        # just ignore for testing purpose
        # stdout = "<< stdoutput >> << {0} >>".format(cmd)
        if std_path != '':
            utils.just_write(std_path, stdout)
        utils.check_output(output_path)

        # change status of log
        # activity['status'] = 'Done'
        for item in activities_log[module]:
            if item['cmd'] == cmd:
                if stdout is None:
                    item['status'] = 'Error'
                item['status'] = 'Done'

        return jsonify(status="200", output_path=output_path)
コード例 #8
0
ファイル: configuration.py プロジェクト: zzhsec/Osmedeus
    def post(self):
        # global options
        data = Configurations.parser.parse_args()
        options = data['options']

        # @TODO add another authen level when settings things from remote
        # check if credentials is the same on the config file or not
        if not self.verify(options):
            return {"error": "Can't not verify to setup config"}

        # write each workspace seprated folder
        ws_name = utils.get_workspace(options)
        utils.make_directory(current_path + '/storages/{0}/'.format(ws_name))
        if not os.path.isdir(current_path + '/storages/{0}/'.format(ws_name)):
            return {
                "error":
                "Can not create workspace directory with name {0} ".format(
                    ws_name)
            }

        activities_path = current_path + '/storages/{0}/activities.json'.format(
            ws_name)
        options_path = current_path + '/storages/{0}/options.json'.format(
            ws_name)

        # consider this is settings db
        utils.just_write(options_path, options, is_json=True)

        if options.get('FORCE') == "False":
            old_log = options['WORKSPACE'] + '/log.json'
            if utils.not_empty_file(old_log) and utils.reading_json(old_log):
                utils.print_info(
                    "It's already done. use '-f' options to force rerun the module"
                )

                raw_activities = utils.reading_json(options['WORKSPACE'] +
                                                    '/log.json')

                utils.just_write(activities_path, raw_activities, is_json=True)

                return options

        utils.print_info("Cleaning activities log")

        # Create skeleton activities based on commands.json
        commands = utils.reading_json(current_path + '/storages/commands.json')

        raw_activities = {}
        for k, v in commands.items():
            raw_activities[k] = []
        utils.just_write(activities_path, raw_activities, is_json=True)

        return options
コード例 #9
0
ファイル: cmd.py プロジェクト: maheshnama098/sid
    def post(self, workspace):
        ws_name = utils.get_workspace(workspace=workspace)
        options_path = current_path + \
            '/storages/{0}/options.json'.format(ws_name)

        self.options = utils.reading_json(options_path)

        data = Cmd.parser.parse_args()
        cmd = data['cmd']
        std_path = data['std_path']
        output_path = data['output_path']
        module = data['module']
        nolog = data['nolog']

        activity = {
            'cmd': cmd,
            'std_path': std_path,
            'output_path': output_path,
            'status': 'Running'
        }

        if nolog == 'False':
            activities_path = current_path + '/storages/{0}/activities.json'.format(
                ws_name)

            # activities = utils.reading_json(activities_path)
            activities = utils.reading_json(activities_path)
            if activities.get(module):
                activities[module].append(activity)
            else:
                activities[module] = [activity]

            utils.just_write(activities_path, activities, is_json=True)

            slack.slack_noti('log',
                             self.options,
                             mess={
                                 'title':
                                 "{0} | {1} | Execute".format(
                                     self.options['TARGET'], module),
                                 'content':
                                 '```{0}```'.format(cmd),
                             })

        utils.print_info("Execute: {0} ".format(cmd))

        stdout = execute.run(cmd)
        utils.check_output(output_path)
        # just ignore for testing purpose
        # stdout = "<< stdoutput >> << {0} >>".format(cmd)

        if nolog == 'False':
            # change status of log
            activities = utils.reading_json(activities_path)
            for item in activities[module]:
                if item['cmd'] == cmd:
                    if stdout is None:
                        item['status'] = 'Error'
                    else:
                        item['status'] = 'Done'
                        try:
                            if std_path != '':
                                utils.just_write(std_path, stdout)
                                slack.slack_file(
                                    'std',
                                    self.options,
                                    mess={
                                        'title':
                                        "{0} | {1} | std".format(
                                            self.options['TARGET'], module),
                                        'filename':
                                        '{0}'.format(std_path),
                                    })
                            if output_path != '':
                                slack.slack_file(
                                    'verbose-report',
                                    self.options,
                                    mess={
                                        'channel':
                                        self.options['VERBOSE_REPORT_CHANNEL'],
                                        'filename':
                                        output_path
                                    })
                        except:
                            pass

            utils.just_write(activities_path, activities, is_json=True)

        return jsonify(status="200", output_path=output_path)
コード例 #10
0
ファイル: cmd.py プロジェクト: qsdj/Osmedeus
    def post(self):
        data = Cmd.parser.parse_args()
        cmd = data['cmd']
        std_path = data['std_path']
        output_path = data['output_path']
        module = data['module']
        nolog = data['nolog']

        activity = {
            'cmd': cmd,
            'std_path': std_path,
            'output_path': output_path,
            'status': 'Running'
        }

        if nolog == 'False':
            activities = utils.reading_json(current_path + '/storages/activities.json')
            if activities.get(module):
                activities[module].append(activity)
            else:
                activities[module] = [activity]
            
            utils.just_write(current_path + '/storages/activities.json',
                            activities, is_json=True)
            slack.slack_noti('log', self.options, mess={
                'title':  "{0} | {1} | Execute".format(self.options['TARGET'], module),
                'content': '```{0}```'.format(cmd),
            })

        utils.print_info("Execute: {0} ".format(cmd))


        stdout = execute.run(cmd)
        # just ignore for testing purpose
        # stdout = "<< stdoutput >> << {0} >>".format(cmd)
        utils.check_output(output_path)

        if nolog == 'False':
            # change status of log
            activities = utils.reading_json(current_path + '/storages/activities.json')
            for item in activities[module]:
                if item['cmd'] == cmd:
                    if stdout is None:
                        item['status'] = 'Error'
                    else:
                        item['status'] = 'Done'
                        try:
                            if std_path != '':
                                utils.just_write(std_path, stdout)
                                slack.slack_file('std', self.options, mess={
                                    'title':  "{0} | {1} | std".format(self.options['TARGET'], module),
                                    'filename': '{0}'.format(std_path),
                                })
                            if output_path != '':
                                slack.slack_file('verbose-report', self.options, mess={
                                    'channel': self.options['VERBOSE_REPORT_CHANNEL'],
                                    'filename': output_path
                                })
                        except:
                            pass

            utils.just_write(current_path + '/storages/activities.json', activities, is_json=True)

        return jsonify(status="200", output_path=output_path)