|
Lines 39-45
Defines the basic class for an UMC server.
Link Here
|
| 39 |
import fcntl |
39 |
import fcntl |
| 40 |
import gzip |
40 |
import gzip |
| 41 |
import os |
41 |
import os |
| 42 |
import pwd |
|
|
| 43 |
import re |
42 |
import re |
| 44 |
import socket |
43 |
import socket |
| 45 |
|
44 |
|
|
Lines 65-71
from .definitions import (
Link Here
|
| 65 |
from ..resources import moduleManager, categoryManager |
64 |
from ..resources import moduleManager, categoryManager |
| 66 |
from ..log import CORE, CRYPT, RESOURCES |
65 |
from ..log import CORE, CRYPT, RESOURCES |
| 67 |
from ..config import ucr, SERVER_MAX_CONNECTIONS |
66 |
from ..config import ucr, SERVER_MAX_CONNECTIONS |
| 68 |
from ..statistics import statistics |
|
|
| 69 |
|
67 |
|
| 70 |
|
68 |
|
| 71 |
class MagicBucket(object): |
69 |
class MagicBucket(object): |
|
Lines 93-99
class MagicBucket(object):
Link Here
|
| 93 |
state.signal_connect('authenticated', self._authenticated) |
91 |
state.signal_connect('authenticated', self._authenticated) |
| 94 |
self.__states[socket] = state |
92 |
self.__states[socket] = state |
| 95 |
notifier.socket_add(socket, self._receive) |
93 |
notifier.socket_add(socket, self._receive) |
| 96 |
statistics.connections.new() |
|
|
| 97 |
|
94 |
|
| 98 |
def exit(self): |
95 |
def exit(self): |
| 99 |
'''Closes all open connections.''' |
96 |
'''Closes all open connections.''' |
|
Lines 103-109
class MagicBucket(object):
Link Here
|
| 103 |
if state.processor is not None: |
100 |
if state.processor is not None: |
| 104 |
state.processor.shutdown() |
101 |
state.processor.shutdown() |
| 105 |
notifier.socket_remove(sock) |
102 |
notifier.socket_remove(sock) |
| 106 |
statistics.connections.inactive() |
|
|
| 107 |
# delete states |
103 |
# delete states |
| 108 |
for state in self.__states.values(): |
104 |
for state in self.__states.values(): |
| 109 |
del state |
105 |
del state |
|
Lines 119-126
class MagicBucket(object):
Link Here
|
| 119 |
state.authResponse.status = result.status |
115 |
state.authResponse.status = result.status |
| 120 |
if result.message: |
116 |
if result.message: |
| 121 |
state.authResponse.message = result.message |
117 |
state.authResponse.message = result.message |
| 122 |
if result: |
|
|
| 123 |
statistics.users.add(state.username) |
| 124 |
state.authenticated = bool(result) |
118 |
state.authenticated = bool(result) |
| 125 |
self._response(state.authResponse, state) |
119 |
self._response(state.authResponse, state) |
| 126 |
state.authResponse = None |
120 |
state.authResponse = None |
|
Lines 198-204
class MagicBucket(object):
Link Here
|
| 198 |
All other valid commands are redirected to the processor. |
192 |
All other valid commands are redirected to the processor. |
| 199 |
""" |
193 |
""" |
| 200 |
state.requests[msg.id] = msg |
194 |
state.requests[msg.id] = msg |
| 201 |
statistics.requests.new() |
|
|
| 202 |
CORE.info('Incoming request of type %s' % msg.command) |
195 |
CORE.info('Incoming request of type %s' % msg.command) |
| 203 |
if not state.authenticated and msg.command != 'AUTH': |
196 |
if not state.authenticated and msg.command != 'AUTH': |
| 204 |
res = Response(msg) |
197 |
res = Response(msg) |
|
Lines 255-273
class MagicBucket(object):
Link Here
|
| 255 |
pass |
248 |
pass |
| 256 |
|
249 |
|
| 257 |
self._response(response, state) |
250 |
self._response(response, state) |
| 258 |
elif msg.command == 'STATISTICS': |
|
|
| 259 |
response = Response(msg) |
| 260 |
try: |
| 261 |
pwent = pwd.getpwnam(state.username) |
| 262 |
if not pwent.pw_uid in (0, ): |
| 263 |
raise KeyError |
| 264 |
CORE.info('Sending statistic data to client') |
| 265 |
response.status = SUCCESS |
| 266 |
response.result = statistics.json() |
| 267 |
except KeyError: |
| 268 |
CORE.info('User not allowed to retrieve statistics') |
| 269 |
response.status = BAD_REQUEST_FORBIDDEN |
| 270 |
self._response(response, state) |
| 271 |
else: |
251 |
else: |
| 272 |
# inform processor |
252 |
# inform processor |
| 273 |
if not state.processor: |
253 |
if not state.processor: |
|
Lines 307-313
class MagicBucket(object):
Link Here
|
| 307 |
return |
287 |
return |
| 308 |
|
288 |
|
| 309 |
try: |
289 |
try: |
| 310 |
statistics.requests.inactive() |
|
|
| 311 |
data = str(msg) |
290 |
data = str(msg) |
| 312 |
# there is no data from another request in the send queue |
291 |
# there is no data from another request in the send queue |
| 313 |
if not state.resend_queue: |
292 |
if not state.resend_queue: |
|
Lines 338-347
class MagicBucket(object):
Link Here
|
| 338 |
if socket not in self.__states: |
317 |
if socket not in self.__states: |
| 339 |
return |
318 |
return |
| 340 |
|
319 |
|
| 341 |
statistics.connections.inactive() |
|
|
| 342 |
if self.__states[socket].username in statistics.users: |
| 343 |
statistics.users.remove(self.__states[socket].username) |
| 344 |
|
| 345 |
if self.__states[socket].processor is not None: |
320 |
if self.__states[socket].processor is not None: |
| 346 |
self.__states[socket].processor.shutdown() |
321 |
self.__states[socket].processor.shutdown() |
| 347 |
|
322 |
|