Copyright and debug
This commit is contained in:
commit
ac0086cab6
@ -24,6 +24,7 @@ sub load {
|
|||||||
my $host = $config->{node}->{host};
|
my $host = $config->{node}->{host};
|
||||||
my @echoareas = split /,/, $config->{node}->{echoareas};
|
my @echoareas = split /,/, $config->{node}->{echoareas};
|
||||||
my $name = $config->{node}->{name};
|
my $name = $config->{node}->{name};
|
||||||
|
my $notify = $config->{notify}->{enabled};
|
||||||
|
|
||||||
$c = {
|
$c = {
|
||||||
nick => $nick,
|
nick => $nick,
|
||||||
@ -31,6 +32,7 @@ sub load {
|
|||||||
host => $host,
|
host => $host,
|
||||||
echoareas => [@echoareas],
|
echoareas => [@echoareas],
|
||||||
name => $name,
|
name => $name,
|
||||||
|
notify => $notify,
|
||||||
};
|
};
|
||||||
|
|
||||||
return $c;
|
return $c;
|
||||||
@ -40,7 +42,7 @@ sub load {
|
|||||||
sub reload {
|
sub reload {
|
||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
|
|
||||||
my $c = II::Config->new();
|
my $c = II::Config->new();
|
||||||
my $config = $c->load();
|
my $config = $c->load();
|
||||||
|
|
||||||
return $config;
|
return $config;
|
||||||
|
36
II/DB.pm
36
II/DB.pm
@ -2,6 +2,7 @@ package II::DB;
|
|||||||
|
|
||||||
use SQL::Abstract;
|
use SQL::Abstract;
|
||||||
use DBI;
|
use DBI;
|
||||||
|
use utf8;
|
||||||
|
|
||||||
use Data::Dumper;
|
use Data::Dumper;
|
||||||
|
|
||||||
@ -20,6 +21,7 @@ sub new {
|
|||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Check message hash
|
||||||
sub check_hash {
|
sub check_hash {
|
||||||
my ( $self, $hash, $echo ) = @_;
|
my ( $self, $hash, $echo ) = @_;
|
||||||
my $dbh = $self->{_dbh};
|
my $dbh = $self->{_dbh};
|
||||||
@ -39,6 +41,7 @@ sub check_hash {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Begin transaction
|
||||||
sub begin {
|
sub begin {
|
||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
my $dbh = $self->{_dbh};
|
my $dbh = $self->{_dbh};
|
||||||
@ -47,6 +50,7 @@ sub begin {
|
|||||||
$dbh->do('BEGIN');
|
$dbh->do('BEGIN');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Commit transaction
|
||||||
sub commit {
|
sub commit {
|
||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
my $dbh = $self->{_dbh};
|
my $dbh = $self->{_dbh};
|
||||||
@ -330,4 +334,36 @@ sub select_new {
|
|||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Search
|
||||||
|
sub do_search {
|
||||||
|
my ( $self, $query ) = @_;
|
||||||
|
my $dbh = $self->{_dbh};
|
||||||
|
|
||||||
|
my $q = "select from_user, to_user, subg, time, echo, post, hash
|
||||||
|
from messages where subg
|
||||||
|
like '\%$query\%' COLLATE NOCASE
|
||||||
|
order by time";
|
||||||
|
|
||||||
|
print "SQL: " . $q . "\n";
|
||||||
|
my $sth = $dbh->prepare($q);
|
||||||
|
$sth->execute();
|
||||||
|
|
||||||
|
my @posts;
|
||||||
|
while ( my @hash = $sth->fetchrow_array() ) {
|
||||||
|
my ( $from, $to, $subg, $time, $echo, $post, $h ) = @hash;
|
||||||
|
my $data = {
|
||||||
|
from => "$from",
|
||||||
|
to => "$to",
|
||||||
|
subg => "$subg",
|
||||||
|
time => $time,
|
||||||
|
echo => "$echo",
|
||||||
|
post => "$post",
|
||||||
|
hash => "$h",
|
||||||
|
};
|
||||||
|
push( @posts, $data );
|
||||||
|
}
|
||||||
|
|
||||||
|
return @posts;
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
@ -148,7 +148,9 @@ sub get_echo {
|
|||||||
|
|
||||||
# Notify
|
# Notify
|
||||||
my @notify_cmd = ('notify-send', 'Сеть ii', 'Есть новые сообщения');
|
my @notify_cmd = ('notify-send', 'Сеть ii', 'Есть новые сообщения');
|
||||||
system(@notify_cmd) == 0 or warn "Cannot send notify: $!\n";
|
if ($notify == 1) {
|
||||||
|
system(@notify_cmd) == 0 or warn "Cannot send notify: $!\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $msgs;
|
return $msgs;
|
||||||
}
|
}
|
||||||
|
22
II/Render.pm
22
II/Render.pm
@ -263,4 +263,26 @@ sub new_mes {
|
|||||||
return $render;
|
return $render;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Search results
|
||||||
|
sub search {
|
||||||
|
my ( $self, @post ) = @_;
|
||||||
|
my $t = $self->{_template};
|
||||||
|
|
||||||
|
# Render header
|
||||||
|
my $render
|
||||||
|
= $t->head(
|
||||||
|
"ii " . $config->{name} . " :: Результаты поиска" );
|
||||||
|
|
||||||
|
my $count = 0;
|
||||||
|
while ( $count < @post ) {
|
||||||
|
|
||||||
|
# Render post
|
||||||
|
$render .= $t->post( @post[$count] );
|
||||||
|
$count++;
|
||||||
|
}
|
||||||
|
$render .= $t->foot();
|
||||||
|
|
||||||
|
return $render;
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
3
II/T.pm
3
II/T.pm
@ -193,6 +193,9 @@ sub pre {
|
|||||||
$post =~ s/ii:\/\/(\w+(\.)?\w+\.\d{2,4})/<a href="\/e?echo=$1&view=thread">$1<\/a>/g;
|
$post =~ s/ii:\/\/(\w+(\.)?\w+\.\d{2,4})/<a href="\/e?echo=$1&view=thread">$1<\/a>/g;
|
||||||
$post =~ s/ii:\/\/(\w{20})/<a href="\/send?hash=$1">$1<\/a>/g;
|
$post =~ s/ii:\/\/(\w{20})/<a href="\/send?hash=$1">$1<\/a>/g;
|
||||||
|
|
||||||
|
# Users
|
||||||
|
$post =~ s/.+? \@(\w+)(.?.+)/<a href="\/u?user=$1">$1<\/a>$2/g;
|
||||||
|
|
||||||
# Not are regexp parsing
|
# Not are regexp parsing
|
||||||
my $pre = 0;
|
my $pre = 0;
|
||||||
my $txt;
|
my $txt;
|
||||||
|
2
crontab
2
crontab
@ -1,2 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
echo "1 * * * * `whoami` wget -O /dev/null http://127.0.0.1/get" >> /etc/crontab
|
|
42
iiplc.app
Normal file → Executable file
42
iiplc.app
Normal file → Executable file
@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/perl
|
#!/usr/bin/perl
|
||||||
# Copyright © 2014 Difrex <difrex.punk@gmail.com>
|
# Copyright © 2014-2015 Difrex <difrex.punk@gmail.com>
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
@ -30,9 +30,6 @@ use II::Render;
|
|||||||
use II::DB;
|
use II::DB;
|
||||||
use II::Enc;
|
use II::Enc;
|
||||||
|
|
||||||
# Debug
|
|
||||||
use Data::Dumper;
|
|
||||||
|
|
||||||
my $c = II::Config->new();
|
my $c = II::Config->new();
|
||||||
my $config = $c->load();
|
my $config = $c->load();
|
||||||
|
|
||||||
@ -64,10 +61,22 @@ my $thread = sub {
|
|||||||
return [ 200, [ 'Content-type' => 'text/html' ], ["$thread"], ];
|
return [ 200, [ 'Content-type' => 'text/html' ], ["$thread"], ];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# Get new messages
|
||||||
my $get = sub {
|
my $get = sub {
|
||||||
$config = $c->reload();
|
$config = $c->reload();
|
||||||
my $GET = II::Get->new($config);
|
my $msgs;
|
||||||
my $msgs = $GET->get_echo();
|
if ( $config->{host} =~ m/.+\,.+/ ) {
|
||||||
|
my @hosts = split( /,/, $config->{host} );
|
||||||
|
foreach my $host (@hosts) {
|
||||||
|
$config->{host} = $host;
|
||||||
|
my $GET = II::Get->new($config);
|
||||||
|
$msgs .= $GET->get_echo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
my $GET = II::Get->new($config);
|
||||||
|
$msgs .= $GET->get_echo();
|
||||||
|
}
|
||||||
my $new_mes = $render->new_mes($msgs);
|
my $new_mes = $render->new_mes($msgs);
|
||||||
return [ 200, [ 'Content-type' => 'text/html' ], ["$new_mes"], ];
|
return [ 200, [ 'Content-type' => 'text/html' ], ["$new_mes"], ];
|
||||||
};
|
};
|
||||||
@ -157,6 +166,10 @@ my $push = sub {
|
|||||||
my $hash = $req->param('hash');
|
my $hash = $req->param('hash');
|
||||||
|
|
||||||
$config = $c->reload();
|
$config = $c->reload();
|
||||||
|
if ( $config->{host} =~ m/.+\,.+/ ) {
|
||||||
|
my @hosts = split( /,/, $config->{host} );
|
||||||
|
$config->{host} = $hosts[0];
|
||||||
|
}
|
||||||
my $s = II::Send->new( $config, $echo, $base64 );
|
my $s = II::Send->new( $config, $echo, $base64 );
|
||||||
$s->send($hash);
|
$s->send($hash);
|
||||||
|
|
||||||
@ -177,9 +190,26 @@ my $user = sub {
|
|||||||
return [ 200, [ 'Content-type' => 'text/html' ], [$mes_from], ];
|
return [ 200, [ 'Content-type' => 'text/html' ], [$mes_from], ];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# Search
|
||||||
|
########
|
||||||
|
my $search = sub {
|
||||||
|
my $env = shift;
|
||||||
|
|
||||||
|
my $req = Plack::Request->new($env);
|
||||||
|
my $query = $req->param('q');
|
||||||
|
|
||||||
|
my $db = II::DB->new();
|
||||||
|
my @post = $db->do_search($query);
|
||||||
|
|
||||||
|
my $result = $render->search(@post);
|
||||||
|
|
||||||
|
return [ 200, [ 'Content-type' => 'text/html' ], [$result], ];
|
||||||
|
};
|
||||||
|
|
||||||
# Mountpoints
|
# Mountpoints
|
||||||
builder {
|
builder {
|
||||||
mount "/static" => Plack::App::File->new( root => './s/' )->to_app;
|
mount "/static" => Plack::App::File->new( root => './s/' )->to_app;
|
||||||
|
mount "/search" => $search;
|
||||||
mount '/' => $root;
|
mount '/' => $root;
|
||||||
mount '/e' => $echo;
|
mount '/e' => $echo;
|
||||||
mount '/s' => $thread;
|
mount '/s' => $thread;
|
||||||
|
@ -175,3 +175,17 @@ margin-bottom: 0%;
|
|||||||
margin-left: 45%;
|
margin-left: 45%;
|
||||||
margin-right: 55%;
|
margin-right: 55%;
|
||||||
}
|
}
|
||||||
|
/* Search */
|
||||||
|
.search {
|
||||||
|
position: fixed;
|
||||||
|
top: 2em;
|
||||||
|
left: 0.5em;
|
||||||
|
opacity: 0.4;
|
||||||
|
transition-duration: 0.5s;
|
||||||
|
-webkit-transition-duration: 0.5s;
|
||||||
|
}
|
||||||
|
.search:hover {
|
||||||
|
opacity: 1;
|
||||||
|
transition-duration: 0.5s;
|
||||||
|
-webkit-transition-duration: 0.5s;
|
||||||
|
}
|
@ -15,4 +15,10 @@
|
|||||||
<b>[</b> <a href="/out">неотправленные сообщения</a> <b>]</b> 
|
<b>[</b> <a href="/out">неотправленные сообщения</a> <b>]</b> 
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
<div class='search'>
|
||||||
|
<form action='/search' method='POST'>
|
||||||
|
<input type='text' name='q'><br>
|
||||||
|
<input type='submit' value='Искать'>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
<!-- <hr> -->
|
<!-- <hr> -->
|
||||||
|
Loading…
Reference in New Issue
Block a user