Skip to content

Commit 02ae4dc

Browse files
committed
fill out app
database config deploy schema cli proof of dhcpd
1 parent 46e56da commit 02ae4dc

12 files changed

Lines changed: 187 additions & 2 deletions

File tree

bin/pa

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env perl
2+
3+
use lib './lib';
4+
use PeopleAPI::App::CLI;
5+
PeopleAPI::App::CLI->run;

dhcpd.pl

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env perl
2+
use strict;
3+
use POE;
4+
use POE::Component::DHCP::Monitor;
5+
use Net::DHCP::Packet;
6+
7+
$|=1;
8+
9+
POE::Session->create(
10+
inline_states => {
11+
_start => \&_start,
12+
dhcp_monitor_packet => \&dhcp_monitor_packet,
13+
_default => \&_default,
14+
},
15+
);
16+
17+
$poe_kernel->run();
18+
exit 0;
19+
20+
sub _start {
21+
my ($kernel,$heap) = @_[KERNEL,HEAP];
22+
$heap->{monitor} =
23+
POE::Component::DHCP::Monitor->spawn(
24+
alias => 'monitor', # optional
25+
port1 => 67, # default shown
26+
port2 => 68, # default shown
27+
#address => '192.168.1.1', # default is INADDR_ANY
28+
);
29+
return;
30+
}
31+
32+
sub dhcp_monitor_packet {
33+
my ($kernel,$heap,$packet) = @_[KERNEL,HEAP,ARG0];
34+
print STDOUT $packet->toString();
35+
print STDOUT "=============================================================================\n";
36+
return;
37+
}
38+
39+
sub _default {
40+
my ($event, $args) = @_[ARG0 .. $#_];
41+
my @output = ( "$event: " );
42+
43+
for my $arg (@$args) {
44+
if ( ref $arg eq 'ARRAY' ) {
45+
push( @output, '[' . join(', ', @$arg ) . ']' );
46+
}
47+
else {
48+
push ( @output, "'$arg'" );
49+
}
50+
}
51+
print join ' ', @output, "\n";
52+
return;
53+
}

etc/conf/peopleapi_purge.conf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<Model::Database>
2+
<connect_info>
3+
dsn dbi:SQLite:dbname=share/db/peopleapi
4+
</connect_info>
5+
</Model::Database>

lib/PeopleAPI/App/CLI.pm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package PeopleAPI::App::CLI;
2+
use App::Cmd::Setup -app => {
3+
plugins => [ qw(Prompt) ],
4+
};
5+
1;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package PeopleAPI::App::CLI::Command::Deploy;
2+
use PeopleAPI::App::CLI -command;
3+
use Try::Tiny;
4+
use PeopleAPI::Database::Script;
5+
6+
sub validate_args {
7+
my ($self, $opt, $args) = @_;
8+
$self->usage_error("no args expected") if @$args;
9+
}
10+
11+
sub execute {
12+
my ($self, $opt, $args) = @_;
13+
14+
my $script = PeopleAPI::Database::Script->new;
15+
my $schema = $script->schema->clone;
16+
17+
$schema->deploy({ add_drop_table => 1 });
18+
$self->populate_data($schema);
19+
}
20+
21+
sub populate_data {
22+
my ($self,$schema) = @_;
23+
24+
}
25+
26+
1;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package PeopleAPI;
1+
package PeopleAPI::App::Web;
22

33
use v5.14.0;
44
use Web::Simple;
@@ -16,7 +16,7 @@ sub dispatch_request {
1616
}
1717
}
1818

19-
sub get_hosts {
19+
sub get_hosts_arp {
2020
my @alive;
2121
for my $cd (2..254) {
2222
my $p = Net::Ping->new('syn');

lib/PeopleAPI/Database/Candy.pm

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package PeopleAPI::Database::Candy;
2+
3+
use base 'DBIx::Class::Candy';
4+
5+
sub base { $_[1] || 'PeopleAPI::Database::Schema::Result' }
6+
sub perl_version { 12 }
7+
sub autotable { 1 }
8+
9+
1;

lib/PeopleAPI/Database/Schema.pm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package PeopleAPI::Database::Schema;
2+
use base qw/DBIx::Class::Schema/;
3+
4+
__PACKAGE__->load_namespaces();
5+
6+
1;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package PeopleAPI::Database::Schema::Result;
2+
3+
use parent 'DBIx::Class::Core';
4+
5+
__PACKAGE__->load_components(qw/Helper::Row::RelationshipDWIM/);
6+
sub default_result_namespace { 'PeopleAPI::Database::Schema::Result' }
7+
1;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package PeopleAPI::Database::Schema::Result::Seen;
2+
3+
use PeopleAPI::Database::Candy
4+
-components => [qw/ EncodedColumn UUIDColumns
5+
InflateColumn::DateTime TimeStamp/];
6+
7+
column 'email' => {
8+
data_type => 'varchar',
9+
size => 100,
10+
is_nullable => 1,
11+
};
12+
13+
column 'mac' => {
14+
data_type => 'varchar',
15+
size => 100
16+
};
17+
18+
column 'ip' => {
19+
data_type => 'varchar',
20+
size => 100
21+
};
22+
23+
column 'last_seen' => {
24+
'data_type' => 'datetime',
25+
'set_on_create' => 0,
26+
'set_on_update' => 1,
27+
};

0 commit comments

Comments
 (0)