#!/usr/bin/env perl
# Copyright 2011-2017 Frank Breedijk
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ------------------------------------------------------------------------------
# This program creates users from the command line, usefull if you have not set
# up any users in the web gui, or if you are writing Seccubus and the GUI does
# not exist yet ;)
# ------------------------------------------------------------------------------

use strict;
use SeccubusV2;
use Seccubus::Helpers;
use Seccubus::Users;
use Getopt::Long;

my (
    $username,
    $name,
    $isadmin,
    $help,
);

$isadmin = 0;
$help = 0;

GetOptions(
    'username|u=s'  => \$username,
    'name|n=s'      => \$name,
    'isadmin!'      => \$isadmin,
    'help|h'        => \$help,
);

help() if $help;
if ( ! $username ) {
    print "You must specify a username";
    help();
} elsif ( ! $name ) {
    print "You must specify the users real name (or a string you can identify them by";
    help();
}

add_user($username, $name, $isadmin); # insert in the user table

exit();

sub help() {
    print "
Usage: add_user --username <name> --name <Real name> [--isadmin]

Arguments:
--username (-u) - the username
--name (-n)     - the real name of the user
--(no)isadmin   - makes the user a member of the administrators group
                  Option, default: --noisadmin
--help          - Print this message
                  Option
";
    exit(1);
}


