コード例 #1
0
ファイル: views.py プロジェクト: staneyffer/spug
def do_task(request):
    form, error = JsonParser(
        Argument('host_ids',
                 type=list,
                 filter=lambda x: len(x),
                 help='请选择执行主机'), Argument('command', help='请输入执行命令内容'),
        Argument('engine_type', type=int, required=False),
        Argument('engine_id', type=int, required=False)).parse(request.body)
    if error is None:
        token = Channel.get_token()
        engine = None
        if form.engine_id:
            engine_obj = ExecEngine.objects.filter(pk=form.engine_id).first()
            if engine_obj:
                engine = ExecEngine.get_engine_dict(engine_obj)
        else:
            engine = ExecEngine.build_engine(form.engine_type)
        logger.info(f'{engine}')
        for host in Host.objects.filter(id__in=form.host_ids):
            Channel.send_ssh_executor(token=token,
                                      hostname=host.hostname,
                                      port=host.port,
                                      username=host.username,
                                      command=form.command,
                                      engine=engine)
        return json_response(token)
    return json_response(error=error)
コード例 #2
0
ファイル: models.py プロジェクト: jackerzz/spug
 def _make_notify(cls, source, type, title, content):
     tmp_str = f'{source},{type},{title},{content}'
     digest = hashlib.md5(tmp_str.encode()).hexdigest()
     unique_key = f'spug:notify:{digest}'
     if not cache.get(unique_key):   # 限制相同内容的发送频率
         cache.set(unique_key, 1, 3600)
         cls.objects.create(source=source, title=title, type=type, content=content)
     Channel.send_notify(title, content)
コード例 #3
0
ファイル: views.py プロジェクト: luckycyong/openspug
def do_task(request):
    form, error = JsonParser(
        Argument('host_ids',
                 type=list,
                 filter=lambda x: len(x),
                 help='请选择执行主机'),
        Argument('command', help='请输入执行命令内容')).parse(request.body)
    if error is None:
        token = Channel.get_token()
        for host in Host.objects.filter(id__in=form.host_ids):
            Channel.send_ssh_executor(token=token,
                                      hostname=host.hostname,
                                      port=host.port,
                                      username=host.username,
                                      command=form.command)
        return json_response(token)
    return json_response(error=error)
コード例 #4
0
def do_task(request):
    form, error = JsonParser(
        Argument('host_ids',
                 type=list,
                 filter=lambda x: len(x),
                 help='请选择执行主机'),
        Argument('command', help='请输入执行命令内容')).parse(
            request.body
        )  #判断host_ids和command是否存在,不存在则返回错误(help定义了返回类型,关联在libs目录下面parser.py)。
    if error is None:
        if not request.user.has_host_perm(form.host_ids):
            return json_response(error='无权访问主机,请联系管理员')
        token = Channel.get_token()
        for host in Host.objects.filter(id__in=form.host_ids):
            Channel.send_ssh_executor(token=token,
                                      hostname=host.hostname,
                                      port=host.port,
                                      username=host.username,
                                      command=form.command)
        return json_response(token)
    return json_response(error=error)
コード例 #5
0
ファイル: packet_chan.py プロジェクト: jfhs/Dota2AIFramework
    def __init__(self, stream, channels):
        """
        @type stream: BinaryStream
        """
        self.length = stream.readInt16()
        for index in range(self.length):
            channel = Channel()
            channel.id = stream.readInt32()
            channel.unknown1 = stream.readInt32()
            channel.unknown2 = stream.readInt32()
            channel.verbosity_default = stream.readInt32()
            channel.verbosity_current = stream.readInt32()

            R = stream.readByte()
            G = stream.readByte()
            B = stream.readByte()
            A = stream.readByte()

            channel.RGBA_Override = self.__bytes_to_hex(R + G + B)

            channel.name = stream.readBytesNullTerminated(34)
            channels.append(channel)
コード例 #6
0
    def __init__(self, stream, channels):
        """
        @type stream: BinaryStream
        """
        self.length = stream.readInt16()
        for index in range(self.length):
            channel = Channel()
            channel.id = stream.readInt32()
            channel.unknown1 = stream.readInt32()
            channel.unknown2 = stream.readInt32()
            channel.verbosity_default = stream.readInt32()
            channel.verbosity_current = stream.readInt32()

            R = stream.readByte()
            G = stream.readByte()
            B = stream.readByte()
            A = stream.readByte()

            channel.RGBA_Override = self.__bytes_to_hex(R+G+B)


            channel.name = stream.readBytesNullTerminated(34)
            channels.append(channel)
コード例 #7
0
import random
from libs.node import Node
from libs.node import Station
from libs.node import StationDcf
from libs.node import StationRl
from libs.channel import Channel
from tqdm import tqdm
from config import Config
#import matplotlib.pyplot as plt

cfg = Config()
global_time = 0
channel = Channel(global_time, [])


station_num = 5
data_rate = 6  # Mbps
# All the lengeth is a mutible of slot


# incule header
pkt_len = 1560
# us
slot_len = 10
sifs = 2
ack_len = 2 + sifs
difs = 4
timeout = ack_len

frame_len = pkt_len * 8 / slot_len / data_rate
stations_list = []
コード例 #8
0
ファイル: packet_chan.py プロジェクト: jfhs/Dota2AIFramework
from libs.channel import Channel

__author__ = 'DarkSupremo'

from libs.binary import BinaryStream

UNKNOWN = Channel()
UNKNOWN.id = -1
UNKNOWN.RGBA_Override = ''
UNKNOWN.name = 'UNKNOWN'


class PacketCHAN:
    def __bytes_to_hex(self, bytes):
        return "".join("{0:02x}".format(c) for c in bytes)

    def __init__(self, stream, channels):
        """
        @type stream: BinaryStream
        """
        self.length = stream.readInt16()
        for index in range(self.length):
            channel = Channel()
            channel.id = stream.readInt32()
            channel.unknown1 = stream.readInt32()
            channel.unknown2 = stream.readInt32()
            channel.verbosity_default = stream.readInt32()
            channel.verbosity_current = stream.readInt32()

            R = stream.readByte()
            G = stream.readByte()