Exemplo n.º 1
0
def main():
    if len(sys.argv) > 1:
        print "Usage grevalstat"
        sys.exit(1)
    try:
        dbase = grinsdb.Database()
        allids = dbase.search(None, None)
        ddict = {}
        for id in allids:
            obj = dbase.open(id)
            if not obj.has_key('eval-license-req'):
                continue
            dates = obj['eval-license-req']
            date = string.strip(string.split(dates, ',')[-1])
            pdate = parsedate(date)
            if ddict.has_key(pdate):
                ddict[pdate] = ddict[pdate] + 1
            else:
                ddict[pdate] = 1
        pdates = ddict.keys()
        pdates.sort()
        pdates.reverse()
        for pdate in pdates:
            print pdate[3], ddict[pdate]
    finally:
        dbase.close()
Exemplo n.º 2
0
def genevaluationlicense(version=None, valid=14, platform=None):
    features = PRODUCT_TO_FEATURE[version]
    features = features + [PLATFORM_TO_PLATFORM[platform]]
    features = encodefeatures(features)
    dbase = grinsdb.Database()
    newid = grinsdb.uniqueid()
    date = getdate("+%d"%valid)
    name = None
    license = codelicense(newid, date, features, name)
    grinsdb.loglicense(license)
    dbase.close()
    return license
Exemplo n.º 3
0
def register(file, filename):
    dbase = grinsdb.Database()
    msg = rfc822.Message(file)
    obj = dbase.new(msg)

    if not obj.has_key('email'):
        print "Message is not a registration form"
        dbase.close()
        raise Error

    user = obj['email']
    if ':' in user or ' ' in user or not '@' in user:
        print "Invalid email:", user
        dbase.close()
        raise Error
    prevtime, oldobj = find_duplicate(dbase, obj)
    if prevtime:
        print "Duplicate not added.", filename
        dbase.close()
        if oldobj:
            print "But password sent."
            user = oldobj['email']
            clear = oldobj['password']
            try:
                lic = oldobj['eval-license']
            except:
                lic = ""
            mail(user, clear, lic, dup=1)
        raise Error

    grpasswd.addpasswd(obj)
    if obj.has_key("want-editor") and obj["want-editor"] == "yes":
        now = time.localtime(time.time())
        elr = time.strftime("%d-%h-%Y", now)
        obj['Eval-License-Req'] = elr
        license = open(LICENSE).read()
        try:
            obj['Eval-License'] = string.split(license)[1]
        except:
            pass
    else:
        license = ""

    dbase.save(obj)
    dbase.close()

    clear = obj['password']
    crypted = crypt_passwd(clear)
    ##     add_passwd(PASSWD, user, crypted)
    mail(user, clear, license)
    print "%s: added (%s)" % (user, filename)
Exemplo n.º 4
0
def main():
    if len(sys.argv) not in (3,4):
        print "Usage: graddfield user field [value]"
        sys.exit(1)
    user = sys.argv[1]
    field = sys.argv[2]
    dbase = grinsdb.Database()
    if len(sys.argv) <= 3:
        value = getfield(dbase, user, field)
        print "%s: %s = %s"%(user, field, value)
    else:
        value = sys.argv[3]
        addfield(dbase, user, field, value, override=1)
    dbase.close()
Exemplo n.º 5
0
def main():
    if len(sys.argv) > 1:
        print "Usage checkdb"
        sys.exit(1)
    dbase = grinsdb.Database(indexed=0)
    index = grinsdb.Index(keys=KEYS)
    try:
        allids = dbase.search(None, None)
        emaildict = {}
        badids = []
        print 'Checking email addresses and creating index',
        count = 0
        for id in allids:
            count = count + 1
            if count % 100 == 0:
                sys.stdout.write('.')
                sys.stdout.flush()
            obj = dbase.open(id)
            index.update(id, obj)
            if not obj.has_key('email'):
                badids.append(id)
                continue
            email = obj['email']
            if emaildict.has_key(email):
                emaildict[email].append(id)
            else:
                emaildict[email] = [id]
        sys.stdout.write('\n')
        index.close()
        del index
        if badids:
            print 'Bad messages:',
            for id in badids:
                print id,
                obj = dbase.open(id, 'w')
                dbase.remove(obj)
            print
        for email in emaildict.keys():
            if len(emaildict[email]) > 1:
                print 'Multiple:', email,
                for i in emaildict[email]:
                    print i,
                print

        genfiles(dbase)
    finally:
        dbase.close()
Exemplo n.º 6
0
def lostkey(file, filename):
    dbase = grinsdb.Database()
    msg = rfc822.Message(file)
    fullname, email = msg.getaddr('from')
    if msg.has_key('x-generated-message'):
        return
    list = dbase.search('email', email)
    if not list:
        dbase.close()
        mailnotok(email)
    else:
        obj = dbase.open(list[0])
        passwd = obj['password']
        dbase.close()
        mailok(email, passwd)
    while file.read(10000):
        pass
Exemplo n.º 7
0
def main():
    try:
        opts, args = getopt.getopt(sys.argv[1:], 'k:vlf')
    except getopt.error:
        print 'Usage: grfind [-k keyname] [-v] value ...'
        sys.exit(0)
    key = 'email'
    verbose = 0
    long = 0
    fullname = 0
    for o, a in opts:
        if o == '-k':
            key = a
        if o == '-v':
            verbose = 1
        if o == '-l':
            long = 1
        if o == '-f':
            fullname = 1
    dbase = grinsdb.Database()
    allids = []
    for value in args:
        ids = dbase.search(key, value)
        for id in ids:
            if not id in allids:
                allids.append(id)
        if verbose and not ids:
            print '** Not found:', value
    for id in allids:
        if long:
            print "(Record %s)" % id
            fp = dbase.openfp(id)
            sys.stdout.write(fp.read())
        elif verbose:
            obj = dbase.open(id)
            print '%s\t%s' % (id, obj['email'])
        elif fullname:
            print dbase.filename(id)
        else:
            print id
    dbase.close()
    if not allids:
        sys.exit(1)
Exemplo n.º 8
0
def main():
    if len(sys.argv) not in (2, 3):
        print "Usage: grpasswd user [passwd]"
        sys.exit(1)
    user = sys.argv[1]
    passwd = None
    if len(sys.argv) > 2:
        passwd = sys.argv[2]
    dbase = grinsdb.Database()
    if not passwd:
        passwd = getfield(dbase, user, 'Password')
        if passwd:
            print 'User: %s' % user
            print 'Password: %s' % passwd
        else:
            print 'User %s has no password' % user
    else:
        if passwd == '-':
            passwd = invent_passwd()
        addfield(dbase, user, 'Password', passwd, override=1)
    dbase.close()
Exemplo n.º 9
0
def evallicense(file, filename):
    license = open(LICENSE).read()
    msg = rfc822.Message(file)
    fullname, email = msg.getaddr('from')
    if msg.has_key('x-generated-message'):
        return
    if DISABLED:
        mailnomore(email)
        return
    dbase = grinsdb.Database()
    list = dbase.search('email', email)
    try:
        if not list:
            mailnotok(email)
        else:
            obj = dbase.open(list[0], 'w')
            obj['Want-editor'] = 'yes'
            if obj.has_key('Eval-License-Req'):
                elr = obj['Eval-License-Req'] + ', '
            else:
                elr = ''
            now = time.localtime(time.time())
            elr = elr + time.strftime("%d-%h-%Y", now)
            obj['Eval-License-Req'] = elr
            if not SEND_NEW_LICENSE and obj.has_key('Eval-License'):
                # send previously sent license
                license = obj['Eval-License']
            else:
                # send current license (and record it)
                try:
                    obj['Eval-License'] = string.split(license)[1]
                except:
                    pass
            dbase.save(obj)
            mailok(email, license)
    finally:
        dbase.close()
    while file.read(10000):
        pass
Exemplo n.º 10
0
def gencommerciallicense(version=None, platform=None,
                         user=None, organization=None,
                         preregistered=0):
    features = PRODUCT_TO_FEATURE[version]
    features = features + [PLATFORM_TO_PLATFORM[platform]]
    if preregistered:
        features = features + ["preregistered"]
    features = encodefeatures(features)
    dbase = grinsdb.Database()
    newid = grinsdb.uniqueid()
    date = None
    if user and organization:
        name = user + ',' + organization
    elif user:
        name = user + ','
    elif organization:
        name = organization
    else:
        name = None
    license = codelicense(newid, date, features, name)
    grinsdb.loglicense(license)
    dbase.close()
    return license
Exemplo n.º 11
0
     print "Error: exactly one of -D, -c, -r or -l should be specified"
     usage()
     sys.exit(1)
 if decode:
     info = decodelicense(decode)
     print info
     sys.exit(0)
 if (list or remove) and (newid or date or features or name):
     print "Error: -l and -r exclusive with all other options"
     usage()
     sys.exit(1)
 if (newid or name) and len(args) > 1:
     print "Error: Cannot specify same name or id for multiple licenses"
     usage()
     sys.exit(1)
 dbase = grinsdb.Database()
 if outfile:
     sys.stdout = open(outfile+".NEW", "w")
 if eval:
     if not features:
         features = getdefaultfeatures()
     if not newid:
         newid = grinsdb.uniqueid()
     license = codelicense(newid, date, features, name)
     grinsdb.loglicense(license)
     print "Evaluation-License:", license
     print "Expires: %d/%d/%d"%date
 elif list:
     for email in args:
         license = getfield(dbase, email, 'License')
         if license: