Beispiel #1
0
 def cmdConnection():
   nonlocal db, servicing
   try:
     db = ftnconfig.connectdb()
     servicing = True
     s.send(b"201 Read-only server intact\r\n")
   except:
     log(str(a)+"\nexception\n"+traceback.format_exc())
     servicing = False
     s.send(b"400 Database is unavailable\r\n")
Beispiel #2
0
 def cmdConnection():
   nonlocal db, servicing
   if servicing:
     raise Exception("internal data mess: servicing is True before connection!")
   try:
     db = ftnconfig.connectdb()
     servicing = servicing or True
     s.send(b"201 Read-only server intact\r\n")
   except:
     log(str(a)+"\nexception\n"+traceback.format_exc())
     servicing = False
     s.send(b"400 Database is unavailable\r\n")
Beispiel #3
0
 def cmdConnection():
     nonlocal db, servicing
     if servicing:
         raise Exception("internal data mess: servicing is True before connection!")
     try:
         db = ftnconfig.connectdb()
         servicing = servicing or True
         s.send(b"201 Read-only server intact\r\n")
     except:
         log(str(a) + "\nexception\n" + traceback.format_exc())
         servicing = False
         s.send(b"400 Database is unavailable\r\n")
Beispiel #4
0
      continue
    except:
      pass

    l1=l.decode("utf-8", "replace")
    outp.append("Error on line %d"% l_pos)
    outp.append(l1.strip())
#    print(repr(l1))
    error_count +=1

    l_pos+=1


  u.close()

  outp.append("ASCII lines: %d"%ascii_count)
  outp.append("UTF-8 lines: %d"%utf8_count)
  outp.append("Error lines: %d"%error_count)


db = ftnconfig.connectdb()

with ftnimport.session(db) as sess:
  sess.send_message(("node", ftnconfig.ADDRESS), "Sergey Dorofeev", ("echo", "FLUID.REPORTS"), "All", None, "UTF-8 nodelist stats",
"""Привет All

%s

Вот так
"""%("\n".join(outp)))
Beispiel #5
0
#!/usr/local/bin/python3

#link='2:5020/1200'
domain = "echo"
purgelist = 'orphans'

import ftnconfig
import ftnimport
import ftnexport
import os

robot = ftnconfig.robotnames[domain]

db = ftnconfig.connectdb()

for area in open(purgelist):
    area = area.strip().upper()
    aid = ftnconfig.get_addr_id(db, db.FTN_domains[domain], area)

    # 1. verify that there is nothing there
    if domain == "fileecho":
        print(area, os.listdir("/tank/home/fido/fareas/" + area.lower()))
    elif domain == "echo":
        count = db.prepare(
            "select count(*) from messages where destination=$1").first(aid)
        print(area, count)
        if count:
            continue

    else:
        1 / 0
Beispiel #6
0
#!/usr/local/bin/python3 -bb

import ftnconfig
import sys

link_address = sys.argv[1]

print("pq://*****:*****@host/database")
db = ftnconfig.connectdb(
    input("enter connection string for admin connection: "))

addr_id = ftnconfig.get_addr_id(db, db.FTN_domains["node"], link_address)
link_id = ftnconfig.get_link_id(db, link_address)

print(addr_id, link_id)

print(
    db.prepare(
        "select t.domain, t.text from subscriptions s, addresses t where s.subscriber=$1 and t.id=s.target"
    )(addr_id))

assert (input("enter 'yes' to confirm: ") == "yes")

db.prepare("delete from subscriptions where subscriber=$1")(addr_id)
db.prepare("delete from links where id=$1")(link_id)
Beispiel #7
0
#!/usr/local/bin/python3 -bb

import re

""" Create vital netmail subscription (and remove unneeded) """

from ftnconfig import connectdb, ADDRESS, NETMAIL_peers, NETMAIL_peerhosts, NETMAIL_uplinks, format1files, format2files, get_link_password
from ftnimport import session
from ftn.ftn import FTNAlreadySubscribed, FTNNoAddressInBase
from ftn.addr import addr2str, str2addr, addr_expand
import ftnexport

# 1. Create subscription for myself and for all nodes that designate me as group (they get netmail directly)
# 1a. Also create the same subscriptions for peers

db = connectdb()

""" load routing inforation from N5020/R50 config files """

re_S=re.compile("\s+")

hubs = {}
links = set(NETMAIL_peers)
#print ("links=",links)
manualrouted = {}

for host, peer in NETMAIL_peerhosts:
    links.add(peer)
    hubs.setdefault(peer, set()).add(host)
    manualrouted[host] = peer
Beispiel #8
0
#!/usr/local/bin/python3 -bb

from ftnconfig import connectdb, get_link_password

db = connectdb()

fareas = {}

for a, b in db.prepare(
        "select t.text, sr.text from subscriptions s, addresses sr, addresses t "
        "where s.subscriber=sr.id and s.target=t.id and t.domain=3")():
    fareas.setdefault(a, set()).add(b)

fa = open("fareas.bbs", "w")
fa.write("*****\n")
for k, v in fareas.items():
    fa.write("/tank/home/fido/fareas/" + k.lower() + " " + k + " " +
             " ".join(v) + "\n")
fa.close()

pw = open("passwd", "w")

for a in db.prepare("select a.text from links l, addresses a "
                    "where l.address=a.id and a.domain=$1 order by a.text")(
                        db.FTN_domains["node"]):
    #print (a[0])

    linkpw = get_link_password(db, a[0])
    if linkpw is not None:
        pw.write("password %-23s %s\n" % (a[0], linkpw))
Beispiel #9
0
def session(log, s, a):
    def rununpack():
        global L_unpack

        log("rununpack aquiring lock")
        #  is_free = L_unpack.acquire(False)
        #  if not is_free:
        #    log("waiting another process")

        # always unpack as there is possibility that when other process started our data was not ready
        L_unpack.acquire()

        #  if is_free:
        log("start to unpack")
        #--os.spawn(os.P_WAIT, UNPACK1[0], UNPACK1)

        #  else:
        #    log("just unpacked by parallel process")

        L_unpack.release()

    try:
        db = connectdb()
        addresses = []
        password = None
        filename = None
        length = None
        s.send(b"hi " + str(a).encode("utf-8") + b"\n")
        while True:
            l = readline(s).decode("utf-8")
            while l[-1] in ("\n", "\r"):
                l = l[:-1]

            log(str(a) + " got %s" % repr(l))
            arg, val = l.split(" ", 1)
            #log(arg+" is "+val)
            if arg == "ADDRESS":
                if password:
                    raise Exception("password already established")
                #log(str(a)+" ADDRESS "+val)
                addresses.append(val)
            elif arg == "PASSWORD":
                if password:
                    raise Exception("password already established")
                if len(addresses) == 0:
                    raise Exception("password without address")
                #log("PASSWORD "+val)
                password = val
            elif arg == "FILENAME":
                if filename:
                    raise Exception("filename already established")
                if not address:
                    raise Exception("filename without address")
                #log("FILENAME "+val)
                filename = val
            elif arg == "BINARY":
                if not filename:
                    raise Exception("binary data without filename")
                length = int(val)
                log(
                    str(a) +
                    " receive %d bytes of file %s from address %s password %s"
                    % (length, filename, address[0], password))

                with file_import(db, address[0], password, filename,
                                 length) as sess:
                    for data in readdata(s, length):
                        sess.add_data(data)

                s.send(b"DONE\n")
                filename = None

            elif arg == "END":
                log(str(a) + " session end " + val)
                break

            elif arg == "GET":
                # if no password sent and link does not have password, export only direct netmail
                #  - arranged in ftnexport
                classesstr = val.lower().split(",")
                classes = set()
                allclasses = set(
                    ("netmail", "echomail", "fileecho", "filebox", "direct"))
                if ["all"] == classesstr:
                    classes = allclasses
                else:
                    for classstr in classesstr:
                        if classstr in allclasses:
                            classes.add(classstr)
                        else:
                            raise Excption("invalid mail class")

                rununpack()

                log(str(a) + " sending " + ", ".join(list(classes)))

                for address in addresses:
                    try:
                        log(str(a) + " export for address " + address)

                        for outbfile, committer in file_export(
                                db, address, password, classes):
                            if outbfile is not None:
                                log(
                                    str(a) + " outbound file " +
                                    outbfile.filename)
                                s.send(b"FILENAME " +
                                       outbfile.filename.encode("utf-8") +
                                       b"\n")
                                s.send(b"BINARY " +
                                       str(outbfile.length).encode("utf-8") +
                                       b"\n")

                                while True:
                                    d = outbfile.data.read(16384)
                                    if len(d) == 0:
                                        break
                                    log(str(a) + " %d" % s.send(d))

                                confirmstr = readline(s).rstrip(b"\r")
                                log(str(a) + " RECV: " + repr(confirmstr))
                                log(
                                    str(a) + " SHOULD: " +
                                    repr(b"DONE " +
                                         outbfile.filename.encode("utf-8")))
                                if confirmstr != b"DONE " + outbfile.filename.encode(
                                        "utf-8"):
                                    raise Exception(
                                        "did not get good confirmation string")

                                log(str(a) + " CONFIRMED")
                            else:
                                log(
                                    str(a) +
                                    " None file passed, just committing")

                            committer.commit()

                    except FTNWrongPassword:
                        log("address %s excluded due to wrong password" %
                            address)
                    except:
                        log(
                            str(a) + " exception on addess %s: %s" %
                            (address, traceback.format_exc()))

                # "QUEUE EMPTY" must be sent only after all addresses are processed
                log(str(a) + " that's all")
                s.send(b"QUEUE EMPTY\n")

            else:
                raise Exception("unknown keyword %s" % arg)

    except Exception:
        log(str(a) + "\nexception\n" + traceback.format_exc())

    finally:
        log(str(a) + " end")
        s.close()
Beispiel #10
0
  print (address, addr_id, "from:", msg_from, "to:", msg_to)

  if msg_from!=0 or msg_to!=0:
    print("messages exist")
    return
#  assert( input("enter 'yes' to confirm: ")=="yes" )

  with ftnimport.session(db) as sess:
    for (link_addr,subs_id) in db.prepare("select a.text, s.id from addresses a, subscriptions s where a.id=s.subscriber and s.target=$1")(addr_id):
      print ("unsubscribing",link_addr)
      link_id = ftnconfig.find_link(db, link_addr)
      my_id, pw=ftnaccess.link_password(db, link_id, forrobots=True)
      sess.send_message(ftnconfig.get_taddr(db, my_id), ftnconfig.SYSOP, ("node", link_addr), robot, None, pw, "-"+address[1], sendmode="direct")
      db.prepare("delete from subscriptions where id=$1")(subs_id)
    sess.send_message(("node", ftnconfig.ADDRESS), ftnconfig.SYSOP, ("echo", "FLUID.LOCAL"), "All", None, "removal", address[0]+" "+address[1]+" removed from node")
    db.prepare("delete from deletedvitalsubscriptionwatermarks where target=$1")(addr_id)
    db.prepare("delete from addresses where id=$1")(addr_id)



print ("pq://*****:*****@host/database")
db=ftnconfig.connectdb(input("enter connection string for admin connection: "))

if len(sys.argv)!=3:
  print ("specify address: domain text, for example fileecho xpicsysop")
  autoclean(db)
else:
  domain=sys.argv[1]
  area=sys.argv[2].upper()
  oblive(db, (domain, area))
Beispiel #11
0
def session(log, s, a):

  def rununpack():
    global L_unpack

    log("rununpack aquiring lock")
#  is_free = L_unpack.acquire(False)
#  if not is_free: 
#    log("waiting another process")

  # always unpack as there is possibility that when other process started our data was not ready
    L_unpack.acquire()

#  if is_free:
    log("start to unpack")
  #--os.spawn(os.P_WAIT, UNPACK1[0], UNPACK1)

#  else:
#    log("just unpacked by parallel process")

    L_unpack.release()



  try:
    db = connectdb()
    addresses = []
    password = None
    filename = None
    length = None
    s.send(b"hi "+str(a).encode("utf-8")+b"\n")
    while True:
      l=readline(s).decode("utf-8")
      while l[-1] in ("\n", "\r"):
        l = l[:-1]

      log(str(a)+" got %s"%repr(l))
      arg, val = l.split(" ", 1)
      #log(arg+" is "+val)
      if arg=="ADDRESS":
        if password:
          raise Exception("password already established")
        #log(str(a)+" ADDRESS "+val)
        addresses.append(val)
      elif arg=="PASSWORD":
        if password:
          raise Exception("password already established")
        if len(addresses) == 0:
          raise Exception("password without address")
        #log("PASSWORD "+val)
        password = val
      elif arg=="FILENAME":
        if filename:
          raise Exception("filename already established")
        if not address:
          raise Exception("filename without address")
        #log("FILENAME "+val)
        filename = val
      elif arg=="BINARY":
        if not filename:
          raise Exception("binary data without filename")
        length = int(val)
        log(str(a)+" receive %d bytes of file %s from address %s password %s"%(length, filename, address[0], password))

        with file_import(db, address[0], password, filename, length) as sess:
          for data in readdata(s, length):
            sess.add_data(data)

        s.send(b"DONE\n")
        filename = None

      elif arg=="END":
        log(str(a)+" session end "+val)
        break

      elif arg=="GET":
        # if no password sent and link does not have password, export only direct netmail
        #  - arranged in ftnexport
        classesstr = val.lower().split(",")
        classes = set()
        allclasses = set(("netmail", "echomail", "fileecho", "filebox", "direct"))
        if ["all"]==classesstr:
          classes = allclasses
        else:
          for classstr in classesstr:
            if classstr in allclasses:
              classes.add(classstr)
            else:
              raise Excption("invalid mail class")

        rununpack()

        log(str(a)+" sending "+", ".join(list(classes)))

        for address in addresses:
          try:
            log(str(a)+" export for address "+address)

            for outbfile, committer in file_export(db, address, password, classes):
              if outbfile is not None:
                log(str(a)+" outbound file "+outbfile.filename)
                s.send(b"FILENAME " + outbfile.filename.encode("utf-8") + b"\n")
                s.send(b"BINARY " + str(outbfile.length).encode("utf-8") + b"\n")

                while True:
                  d = outbfile.data.read(16384)
                  if len(d)==0:
                    break
                  log(str(a)+" %d"%s.send(d))

                confirmstr = readline(s).rstrip(b"\r")
                log(str(a)+" RECV: "+repr(confirmstr))
                log(str(a)+ " SHOULD: "+repr(b"DONE " + outbfile.filename.encode("utf-8")))
                if confirmstr != b"DONE " + outbfile.filename.encode("utf-8"):
                  raise Exception("did not get good confirmation string")

                log(str(a)+" CONFIRMED")
              else:
                log(str(a)+" None file passed, just committing")

              committer.commit()


          except FTNWrongPassword:
            log("address %s excluded due to wrong password"%address)
          except:
            log(str(a)+" exception on addess %s: %s"%(address, traceback.format_exc()))

        # "QUEUE EMPTY" must be sent only after all addresses are processed
        log(str(a)+" that's all")
        s.send(b"QUEUE EMPTY\n")

      else:
        raise Exception("unknown keyword %s"%arg)

  except Exception:
    log(str(a)+"\nexception\n"+traceback.format_exc())

  finally:
    log(str(a)+" end")
    s.close()
Beispiel #12
0
 def __init__(self):
   self.lasts = {} # subscription: lastsent
   self.db = connectdb()
Beispiel #13
0
 def __init__(self, newstatus=2):
   self.newstatus=newstatus
   self.msglist=set()
   self.msgarqlist=[]
   self.db = connectdb()
Beispiel #14
0
  pass

# --- **** ---

def count_messages_to(db, address):
    return int(db.prepare("select count(*) from messages where destination=$1")(address)[0][0])

def get_matching_targets(db, targetdomain, mask):
    mask = mask.replace("+", "++").replace("%", "+%").replace("_", "+_").replace("*", "%").replace("?", "_")
    return [x[0] for x in db.prepare("select t.text from addresses t where t.domain=$1 and t.text like $2 escape '+'")\
        (db.FTN_domains[targetdomain], mask)]

def get_subnodes(db, addr):
  return [x[0] for x in db.prepare("select s.text from addresses n, addresses s where s.group=n.id and n.text=$1 and n.domain=$2")(addr, db.FTN_domains["node"])]

def get_supernode(db, addr):
  r = db.prepare("select s.text from addresses n, addresses s where s.id=n.group and n.text=$1 and n.domain=$2")(addr, db.FTN_domains["node"])
  if len(r):
    return r[0][0]
  else:
    return None

if __name__ == "__main__":
    from ftnconfig import connectdb
#    for s in get_node_subscriptions(connectdb(), "2:5020/4441", "echo"):
#        if s.find("TEST")!=-1:
#            print (s)

    print (get_subnodes(connectdb(), '2:5020/733315'))