Exemplo n.º 1
0
Arquivo: slurp.py Projeto: thkrz/slurp
def fetch(segment, groups) -> None:
    host = flags['h']
    port = None
    if ':' in host:
        host, port = tuple(host.split(':', 1))
        port = int(port)
    try:
        if flags['ssl']:
            if not port:
                port = 563
            s = nntplib.NNTP_SSL(host, port)
        else:
            if not port:
                port = 119
            s = nntplib.NNTP(host, port)
        s.login(flags['u'], flags['p'])
        for group in groups:
            try:
                s.group(group)
                watchdog.put(segment)
                s.body('<{}>'.format(segment), file=segment)
            except nntplib.NNTPTemporaryError:
                continue
            break
        s.quit()
    except nntplib.NNTPPermanentError as e:
        log('slurp: nntp: ' + str(e))
Exemplo n.º 2
0
def get_co(host, port, ssl, user, password, timeout):
    try:
        if ssl:
            co = nntplib.NNTP_SSL(host, port, user, password, timeout=timeout)
        else:
            co = nntplib.NNTP(host, port, user, password, timeout=timeout)
    except Exception as err:
        raise ConnectionError('Could not connect to the server, please, check '
                              'your connection ({}).'.format(err))
    return co
Exemplo n.º 3
0
def con(host, port, ssl, username, password):
    '''Connect to UNS and return socket. Arguments:
	- host: valid UNS hostname (str)
	- port: valid UNS port (str)
	- ssl: (boolean)
	- username: UNS username (str)
	- password: UNS password (str)
	Returns:
	- UNS NNTP socket (object)'''
    if ssl == True:
        socket = nntplib.NNTP_SSL(host, port, username, password)
    else:
        socket = nntplib.NNTP(host, port, username, password)
    return socket
Exemplo n.º 4
0
 def open_connection(self):
     global FORWARD_NNTP
     if not settings.do_forwarding:
         return None
     sslcontext = ssl.SSLContext(ssl.PROTOCOL_TLS)
     if settings.forward_server_ssl:
         nntp_obj = nntplib.NNTP_SSL(settings.forward_server_url,
                                     user=settings.forward_server_user,
                                     password=settings.forward_server_pass,
                                     ssl_context=sslcontext,
                                     port=settings.forward_server_port,
                                     readermode=True,
                                     timeout=5)
     else:
         nntp_obj = nntplib.NNTP(settings.forward_server_url,
                                 user=settings.forward_server_user,
                                 password=settings.forward_server_pass,
                                 ssl_context=sslcontext,
                                 port=settings.forward_server_port,
                                 readermode=True,
                                 timeout=5)
     FORWARD_NNTP.append(nntp_obj)
     return nntp_obj
Exemplo n.º 5
0
def post_article(name, email, groups, subject, contents, father_news=None):
    for group in groups:
        settings = hosts[group.host.host]
        try:
            if settings['ssl']:
                co = nntplib.NNTP_SSL(settings['host'],
                                      settings['port'],
                                      settings['user'],
                                      settings['pass'],
                                      timeout=settings['timeout'])
            else:
                co = nntplib.NNTP(settings['host'],
                                  settings['port'],
                                  settings['user'],
                                  settings['pass'],
                                  timeout=settings['timeout'])
        except Exception:
            return False
        print(
            co.post(
                build_article(name, email, [group.name], subject, contents,
                              father_news, settings['encoding'])))
        return True
Exemplo n.º 6
0
 def open_connection(self, server_name0, conn_nr):
     result = None
     for idx, (sn, cn, rt, nobj) in enumerate(self.all_connections):
         if sn == server_name0 and cn == conn_nr:
             if nobj:
                 return nobj
             else:
                 context = ssl.SSLContext(ssl.PROTOCOL_TLS)
                 sc = self.get_single_server_config(server_name0)
                 if sc:
                     server_name, server_url, user, password, port, usessl, level, connections, retention, useserver\
                         = sc
                     if useserver:
                         try:
                             self.logger.debug(whoami() +
                                               "Opening connection # " +
                                               str(conn_nr) + "to server " +
                                               server_name)
                             if usessl:
                                 nntpobj = nntplib.NNTP_SSL(
                                     server_url,
                                     user=user,
                                     password=password,
                                     ssl_context=context,
                                     port=port,
                                     readermode=True)
                             else:
                                 # this is just for ginzicut preloading
                                 if user.lower(
                                 ) == "ginzicut" or password.lower(
                                 ) == "ginzicut":
                                     nntpobj = nntplib.NNTP(server_url,
                                                            port=port)
                                 else:
                                     nntpobj = nntplib.NNTP(
                                         server_url,
                                         user=user,
                                         password=password,
                                         readermode=True,
                                         port=port)
                             self.logger.debug(whoami() +
                                               "Opened Connection #" +
                                               str(conn_nr) +
                                               " on server " + server_name0)
                             result = nntpobj
                             self.all_connections[idx] = (sn, cn, rt,
                                                          nntpobj)
                             break
                         except Exception as e:
                             self.logger.error(whoami() + "Server " +
                                               server_name0 +
                                               " connect error: " + str(e))
                             self.all_connections[idx] = (sn, cn, rt, None)
                             break
                 else:
                     self.logger.error(
                         whoami() +
                         "Cannot get server config for server: " +
                         server_name0)
                     self.all_connections[idx] = (sn, cn, rt, None)
                     break
     return result
Exemplo n.º 7
0
bytespersec = bytesdownloaded / (time.time() - t0)
kbpersec = bytespersec / 1024
mbpersec = kbpersec / 1024
print("Mbit/sec:", int(mbpersec * 8))

for n in clientthreads:
        n.s.quit()

# print(info_ginzicut.lines[0:3])

sys.exit()

sslcontext = ssl.SSLContext(ssl.PROTOCOL_TLS)
nntp_obj = nntplib.NNTP_SSL(settings.forward_server_url, user=settings.forward_server_user,
                            password=settings.forward_server_pass, ssl_context=sslcontext,
                            port=settings.forward_server_port, readermode=True, timeout=5)
for a in artlist:
        print(a)
        resp, info = nntp_obj.body(a)
        print("-----------------", resp)
        info_eweka = info

# i0 = [i for i, j in zip(info_eweka, info_ginzicut) if i != j]

print("... read from eweka directly")
print(info_eweka.lines[-5:])
print("... read from ginzicut")
print(info_ginzicut.lines[-5:])

for n in clientthreads:
Exemplo n.º 8
0
 def __init__(self):
     self.connection = nntplib.NNTP_SSL(host=auth['server'],
                                        user=auth['user'],
                                        password=auth['password'])
Exemplo n.º 9
0
 def connect(self):
     conn = nntplib.NNTP_SSL(host=auth['server'], user=auth['user'], password=auth['password'])
     return conn