Skip to content

Commit 2d18453

Browse files
committed
Allow site endpoint to be run locally
1 parent 1dcfa7e commit 2d18453

File tree

2 files changed

+38
-27
lines changed

2 files changed

+38
-27
lines changed

lib/Brass/API.pm

+4-26
Original file line numberDiff line numberDiff line change
@@ -141,36 +141,14 @@ get 'api/site/' => sub {
141141
my $user = var 'api_user'
142142
or error __"Authentication required";
143143

144-
my $action = query_parameters->get('action')
145-
or error __"Need required action";
146-
147-
my $schema = schema;
148-
149-
my $config = $schema->resultset('Config')->next
150-
or error __x"Configuration information not defined. Please define in Brass in the Config => Site menu";
151-
152-
my $output;
153-
154-
if ($action eq 'smtp')
155-
{
156-
$output = [$config->smtp_relayhost];
157-
}
158-
elsif ($action eq 'internal_networks')
159-
{
160-
$output = [$config->internal_networks_all];
161-
}
162-
elsif ($action eq 'wazuh_manager')
163-
{
164-
$output = [$config->wazuh_manager];
165-
}
166-
else {
167-
error __x"Unknown action {action}", action => $action;
168-
}
144+
my $return = $cdb->run_site(
145+
action => query_parameters->get('action'),
146+
);
169147

170148
content_type 'application/json';
171149
encode_json({
172150
"is_error" => 0,
173-
"result" => encode_json($output),
151+
"result" => encode_json($return),
174152
});
175153
};
176154

lib/Brass/ConfigDB.pm

+34-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ sub _run_local
5353
my $type = delete $params{type}
5454
or error __"Please provide type of request with --type";
5555

56-
# XXX More types to be migrated
5756
if ($type eq 'pwd')
5857
{
5958
$self->run_pwd(%params);
@@ -66,6 +65,13 @@ sub _run_local
6665
{
6766
$self->run_server(%params);
6867
}
68+
elsif ($type eq 'site')
69+
{
70+
$self->run_site(%params);
71+
}
72+
else {
73+
error __x"Unknown type: {type}", type => $type;
74+
}
6975
}
7076

7177
sub _run_remote
@@ -486,6 +492,33 @@ sub run_server
486492
}
487493
}
488494

495+
sub run_site
496+
{ my ($self, %params) = @_;
497+
498+
my $schema = $self->schema;
499+
my $action = $params{action}
500+
or error __"Need required action";
501+
502+
my $config = $schema->resultset('Config')->next
503+
or error __x"Configuration information not defined. Please define in Brass in the Config => Site menu";
504+
505+
if ($action eq 'smtp')
506+
{
507+
return [$config->smtp_relayhost];
508+
}
509+
elsif ($action eq 'internal_networks')
510+
{
511+
return [$config->internal_networks_all];
512+
}
513+
elsif ($action eq 'wazuh_manager')
514+
{
515+
return [$config->wazuh_manager];
516+
}
517+
else {
518+
error __x"Unknown action {action}", action => $action;
519+
}
520+
}
521+
489522
sub randompw()
490523
{ my $pwgen = CtrlO::Crypt::XkcdPassword->new;
491524
$pwgen->xkcd( words => 3, digits => 2 );

0 commit comments

Comments
 (0)