Пример #1
0
def main():
    parser = argparse.ArgumentParser(description="List users")
    parser.add_argument("-k", "--keep-going", action="store_true", dest="keep_going", help="keep going on errors")
    parser.add_argument("--hsprov", metavar="IP:PORT", action="store", help="IP address and port of homestead-prov")
    parser.add_argument("--full", action="store_true", help="displays full information for each user")
    parser.add_argument("--pace", action="store", type=int, help="sets the target number of users to list per second")
    parser.add_argument("-f", "--force", action="store_true", dest="force", help="forces specified pace")
    args = parser.parse_args()

    utils.setup_logging()
    settings.HOMESTEAD_URL = args.hsprov or settings.HOMESTEAD_URL
    default_pace = 5 if args.full else 500
    pace = args.pace or default_pace

    # Check the pace and get confirmation if it's too high
    if pace > default_pace and not args.force:
        if args.full:
            print("Pace %d greater than recommended value (%d) when --full specified" % (pace, default_pace))
        else:
            print("Pace %d greater than recommended value (%d)" % (pace, default_pace))
        print("This may impact call processing!  Are you sure? [y/N]")
        print("(... or specify --force to skip this check and force the specified pace)")
        if raw_input().lower() == "y":
            print("Continuing...")
        else:
            print("Aborting!")
            sys.exit(1)

    if not utils.check_connection():
        sys.exit(1)

    success = True
    try:
        for public_id in pace_wrapper(utils.list_users(keep_going=args.keep_going), pace=pace):
            if args.full:
                if not utils.display_user(public_id):
                    success = False
            else:
                print "%s" % (public_id,)
            sys.stdout.flush()

            if not success and not args.keep_going:
                break
    except HTTPError:
        success = False

    sys.exit(0 if success else 1)
Пример #2
0
def main():
    parser = argparse.ArgumentParser(description="Update user")
    parser.add_argument("-k", "--keep-going", action="store_true", dest="keep_going", help="keep going on errors")
    parser.add_argument("-q", "--quiet", action="store_true", dest="quiet", help="don't display the user")
    parser.add_argument("--hsprov", metavar="IP:PORT", action="store", help="IP address and port of homestead-prov")
    parser.add_argument("--plaintext", action="store_true", help="store password in plaintext")
    parser.add_argument("--ifc", metavar="iFC-FILE", action="store", dest="ifc_file", help="XML file containing the iFC (default: iFC unchanged)")
    parser.add_argument("--prefix", action="store", default="123", dest="twin_prefix", help="twin-prefix (default: 123)")
    parser.add_argument("--impi", action="store", default="", dest="impi", help="IMPI (default: derived from the IMPU)")
    parser.add_argument("dns", metavar="<directory-number>[..<directory-number>]")
    parser.add_argument("domain", metavar="<domain>")
    parser.add_argument("--password", help="new password (default: password unchanged)")
    args = parser.parse_args()

    utils.setup_logging()
    settings.HOMESTEAD_URL = args.hsprov or settings.HOMESTEAD_URL

    ifc = None
    if args.ifc_file:
        ifc = utils.build_ifc(args.ifc_file, args.domain, args.twin_prefix)
        if not ifc:
            sys.exit(1)

    if not utils.check_connection():
        sys.exit(1)

    success = True
    for dn in utils.parse_dn_ranges(args.dns):
        public_id = "sip:%s@%s" % (dn, args.domain)
        private_id = "%s@%s" % (dn, args.domain)

        if args.impi != "":
            private_id = args.impi

        if utils.update_user(private_id, public_id, args.domain, args.password, ifc, args.plaintext):
            if not args.quiet and not utils.display_user(public_id):
                success = False
        else:
            success = False

        if not success and not args.keep_going:
            break

    sys.exit(0 if success else 1)
Пример #3
0
def main():
    parser = argparse.ArgumentParser(description="Display user")
    parser.add_argument("-k",
                        "--keep-going",
                        action="store_true",
                        dest="keep_going",
                        help="keep going on errors")
    parser.add_argument("-q",
                        "--quiet",
                        action="store_true",
                        dest="quiet",
                        help="suppress non-critical errors")
    parser.add_argument("-s",
                        "--short",
                        action="store_true",
                        dest="short",
                        help="less verbose display")
    parser.add_argument("--hsprov",
                        metavar="IP:PORT",
                        action="store",
                        help="IP address and port of homestead-prov")
    parser.add_argument("dns",
                        metavar="<directory-number>[..<directory-number>]")
    parser.add_argument("domain", metavar="<domain>")
    args = parser.parse_args()

    utils.setup_logging(
        level=logging.CRITICAL if args.quiet else logging.ERROR)
    settings.HOMESTEAD_URL = args.hsprov or settings.HOMESTEAD_URL

    if not utils.check_connection():
        sys.exit(1)

    success = True
    for dn in utils.parse_dn_ranges(args.dns):
        public_id = "sip:%s@%s" % (dn, args.domain)

        if not utils.display_user(public_id, short=args.short):
            success = False

        if not success and not args.keep_going:
            break

    sys.exit(0 if success else 1)
Пример #4
0
def main():
    parser = argparse.ArgumentParser(description="Delete user")
    parser.add_argument("-f", "--force", action="store_true", dest="force", help="proceed with delete in the face of errors")
    parser.add_argument("-q", "--quiet", action="store_true", dest="quiet", help="silence 'forced' error messages")
    parser.add_argument("-y", "--yes", action="store_true", dest="no_prompt", help="auto-accept the prompt displayed before deleting the user(s)")
    parser.add_argument("--hsprov", metavar="IP:PORT", action="store", help="IP address and port of homestead-prov")
    parser.add_argument("--impi", action="store", default="", dest="impi", help="IMPI (default: derived from the IMPU)")
    parser.add_argument("dns", metavar="<directory-number>[..<directory-number>]")
    parser.add_argument("domain", metavar="<domain>")
    args = parser.parse_args()

    utils.setup_logging(level=logging.CRITICAL if args.quiet else logging.ERROR)
    settings.HOMESTEAD_URL = args.hsprov or settings.HOMESTEAD_URL

    if not utils.check_connection():
        sys.exit(1)

    if not args.no_prompt:
        print 'Are you sure you wish to delete the following users: {}? [y/n]'.format(args.dns)
        choice = raw_input().lower()

        if choice != 'y':
            if choice != 'n':
                print "Exiting due to invalid input: Expected 'y' or 'n'."
            else:
                print "Exiting on user request."
            exit(0)

    success = True
    for dn in utils.parse_dn_ranges(args.dns):
        public_id = "sip:%s@%s" % (dn, args.domain)
        private_id = "%s@%s" % (dn, args.domain)

        if args.impi != "":
            private_id = args.impi

        if not utils.delete_user(private_id, public_id, force=args.force):
            success = False

        if not success and not args.force:
            break

    sys.exit(0 if success else 1)
Пример #5
0
def main():
    parser = argparse.ArgumentParser(description="Update user")
    parser.add_argument("-k",
                        "--keep-going",
                        action="store_true",
                        dest="keep_going",
                        help="keep going on errors")
    parser.add_argument("-q",
                        "--quiet",
                        action="store_true",
                        dest="quiet",
                        help="don't display the user")
    parser.add_argument("--hsprov",
                        metavar="IP:PORT",
                        action="store",
                        help="IP address and port of homestead-prov")
    parser.add_argument("--plaintext",
                        action="store_true",
                        help="store password in plaintext")
    parser.add_argument(
        "--ifc",
        metavar="iFC-FILE",
        action="store",
        dest="ifc_file",
        help="XML file containing the iFC (default: iFC unchanged)")
    parser.add_argument("--prefix",
                        action="store",
                        default="123",
                        dest="twin_prefix",
                        help="twin-prefix (default: 123)")
    parser.add_argument("--impi",
                        action="store",
                        default="",
                        dest="impi",
                        help="IMPI (default: derived from the IMPU)")
    parser.add_argument("dns",
                        metavar="<directory-number>[..<directory-number>]")
    parser.add_argument("domain", metavar="<domain>")
    parser.add_argument("--password",
                        help="new password (default: password unchanged)")
    args = parser.parse_args()

    utils.setup_logging()
    settings.HOMESTEAD_URL = args.hsprov or settings.HOMESTEAD_URL

    ifc = None
    if args.ifc_file:
        ifc = utils.build_ifc(args.ifc_file, args.domain, args.twin_prefix)
        if not ifc:
            sys.exit(1)

    if not utils.check_connection():
        sys.exit(1)

    success = True
    for dn in utils.parse_dn_ranges(args.dns):
        public_id = "sip:%s@%s" % (dn, args.domain)
        private_id = "%s@%s" % (dn, args.domain)

        if args.impi != "":
            private_id = args.impi

        if utils.update_user(private_id, public_id, args.domain, args.password,
                             ifc, args.plaintext):
            if not args.quiet and not utils.display_user(public_id):
                success = False
        else:
            success = False

        if not success and not args.keep_going:
            break

    sys.exit(0 if success else 1)
Пример #6
0
def main():
    parser = argparse.ArgumentParser(description="Delete user")
    parser.add_argument("-f",
                        "--force",
                        action="store_true",
                        dest="force",
                        help="proceed with delete in the face of errors")
    parser.add_argument("-q",
                        "--quiet",
                        action="store_true",
                        dest="quiet",
                        help="silence 'forced' error messages")
    parser.add_argument(
        "-y",
        "--yes",
        action="store_true",
        dest="no_prompt",
        help="auto-accept the prompt displayed before deleting the user(s)")
    parser.add_argument("--hsprov",
                        metavar="IP:PORT",
                        action="store",
                        help="IP address and port of homestead-prov")
    parser.add_argument("--impi",
                        action="store",
                        default="",
                        dest="impi",
                        help="IMPI (default: derived from the IMPU)")
    parser.add_argument("dns",
                        metavar="<directory-number>[..<directory-number>]")
    parser.add_argument("domain", metavar="<domain>")
    args = parser.parse_args()

    utils.setup_logging(
        level=logging.CRITICAL if args.quiet else logging.ERROR)
    settings.HOMESTEAD_URL = args.hsprov or settings.HOMESTEAD_URL

    if not utils.check_connection():
        sys.exit(1)

    if not args.no_prompt:
        print 'Are you sure you wish to delete the following users: {}? [y/n]'.format(
            args.dns)
        choice = raw_input().lower()

        if choice != 'y':
            if choice != 'n':
                print "Exiting due to invalid input: Expected 'y' or 'n'."
            else:
                print "Exiting on user request."
            exit(0)

    success = True
    for dn in utils.parse_dn_ranges(args.dns):
        public_id = "sip:%s@%s" % (dn, args.domain)
        private_id = "%s@%s" % (dn, args.domain)

        if args.impi != "":
            private_id = args.impi

        if not utils.delete_user(private_id, public_id, force=args.force):
            success = False

        if not success and not args.force:
            break

    sys.exit(0 if success else 1)
Пример #7
0
def main():
    parser = argparse.ArgumentParser(description="Create user")
    parser.add_argument("-k", "--keep-going", action="store_true", dest="keep_going", help="keep going on errors")
    parser.add_argument("--hsprov", metavar="IP:PORT", action="store", help="IP address and port of homestead-prov")
    parser.add_argument("--plaintext", action="store_true", help="store password in plaintext")
    parser.add_argument("--ifc", metavar="iFC-FILE", action="store", dest="ifc_file", help="XML file containing the iFC")
    parser.add_argument("--prefix", action="store", default="123", dest="twin_prefix", help="twin-prefix (default: 123)")
    parser.add_argument("--impi", action="store", default="", dest="impi", help="IMPI (default: derived from the IMPU)")
    parser.add_argument("dns", metavar="<directory-number>[..<directory-number>]")
    parser.add_argument("domain", metavar="<domain>")
    parser.add_argument("password", metavar="<password>")
    args = parser.parse_args()

    utils.setup_logging()
    settings.HOMESTEAD_URL = args.hsprov or settings.HOMESTEAD_URL
    ifc = utils.build_ifc(args.ifc_file, args.domain, args.twin_prefix)
    if not ifc:
        sys.exit(1)

    if not utils.check_connection():
        sys.exit(1)

    # We use sys.stdout.write to print to stdout without a newline, so we can
    # indicate progress to the user
    sys.stdout.write("Creating users...")
    sys.stdout.flush()
    count = 0
    errors = 0
    for dn in utils.parse_dn_ranges(args.dns):
        success = True
        count += 1
        sys.stdout.write(".")
        sys.stdout.flush()
        public_id = "sip:%s@%s" % (dn, args.domain)
        private_id = "%s@%s" % (dn, args.domain)

        if args.impi != "":
            private_id = args.impi

        if utils.create_user(private_id, public_id, args.domain, args.password, ifc, plaintext=args.plaintext):
            if not utils.display_user(public_id, quiet=True):
                success = False
        else:
            success = False

        if not success:
            errors += 1
            utils.delete_user(private_id, public_id, force=True)
            print("Failed to create a subscriber - {}.".format(dn))

            if not args.keep_going:
                if dn != args.dns:
                    print("Failed to create any subscribers beyond {}".format(dn))

                break

        if count == 100:
            print("")
            print("Created up to user {}".format(dn))
            count = 0

    if errors == 0:
        if count == 1:
            print("Success. Subscriber {} has been created.".format(args.dns))
        else:
            print("Success. {} subscriber(s) have been created.".format(count))

        sys.exit(0)
    else:
        print("Finished, but failed to create all subscribers. See logs above for individual subscribers.")
        sys.exit(1)
Пример #8
0
def main():
    parser = argparse.ArgumentParser(description="List users")
    parser.add_argument("-k",
                        "--keep-going",
                        action="store_true",
                        dest="keep_going",
                        help="keep going on errors")
    parser.add_argument("--hsprov",
                        metavar="IP:PORT",
                        action="store",
                        help="IP address and port of homestead-prov")
    parser.add_argument("--full",
                        action="store_true",
                        help="displays full information for each user")
    parser.add_argument(
        "--pace",
        action="store",
        type=int,
        help="sets the target number of users to list per second")
    parser.add_argument("-f",
                        "--force",
                        action="store_true",
                        dest="force",
                        help="forces specified pace")
    args = parser.parse_args()

    utils.setup_logging()
    settings.HOMESTEAD_URL = args.hsprov or settings.HOMESTEAD_URL
    default_pace = 5 if args.full else 500
    pace = args.pace or default_pace

    # Check the pace and get confirmation if it's too high
    if pace > default_pace and not args.force:
        if args.full:
            print(
                "Pace %d greater than recommended value (%d) when --full specified"
                % (pace, default_pace))
        else:
            print("Pace %d greater than recommended value (%d)" %
                  (pace, default_pace))
        print("This may impact call processing!  Are you sure? [y/N]")
        print(
            "(... or specify --force to skip this check and force the specified pace)"
        )
        if raw_input().lower() == "y":
            print("Continuing...")
        else:
            print("Aborting!")
            sys.exit(1)

    if not utils.check_connection():
        sys.exit(1)

    success = True
    try:
        for public_id in pace_wrapper(
                utils.list_users(keep_going=args.keep_going), pace=pace):
            if args.full:
                if not utils.display_user(public_id):
                    success = False
            else:
                print "%s" % (public_id, )
            sys.stdout.flush()

            if not success and not args.keep_going:
                break
    except HTTPError:
        success = False

    sys.exit(0 if success else 1)