Frontend: Implement support for adding channels

This commit is contained in:
2023-09-15 21:01:26 +02:00
parent 3155946a67
commit fe114e749c
3 changed files with 102 additions and 52 deletions

View File

@@ -486,6 +486,25 @@ sub sendResponse {
}
}
sub createUser {
my $aName = $_[0];
my $aPassword = $_[1];
my $aPrivileges = $_[2];
my $aConnection = $_[3];
my $id = 0;
my $query = $aConnection->prepare(qq(select id from users order by rowid desc limit 1;));
$query->execute();
my @row = $query->fetchrow_array();
if(scalar(@row)>0) {
$id = $row[0]+1;
}
my $password = Digest::SHA::sha256_hex($aPassword);
$query = $aConnection->prepare(qq(insert into users values($id, ?, ?, ?);));
$query->execute($aName, $aPassword, $aPrivileges);
}
sub httpServerWorker {
my $db = DBI->connect("DBI:SQLite:dbname=$configuration::database", "", "", {RaiseError=>1});
my $query = $db->prepare(qq(select id from users;));
@@ -493,9 +512,7 @@ sub httpServerWorker {
my @row = $query->fetchrow_array();
if(scalar(@row)==0) {
# Create default user
my $password = Digest::SHA::sha256_hex("admin");
$query = $db->prepare(qq(insert into users values(0, "admin", "$password", 2);));
$query->execute();
createUser("admin", "admin", 2, $db);
}
my $server = new IO::Socket::INET(LocalHost=>"localhost", LocalPort=>$configuration::httpServerPort, Proto=>"tcp", Listen=>1, Reuse=>1);