Copyright and debug
This commit is contained in:
commit
ac0086cab6
@ -15,15 +15,16 @@ sub new {
|
||||
sub load {
|
||||
my ($self) = @_;
|
||||
my $file = $self->{_file};
|
||||
|
||||
|
||||
my $tiny = Config::Tiny->new();
|
||||
$config = $tiny->read($file);
|
||||
|
||||
|
||||
my $key = $config->{auth}->{key};
|
||||
my $nick = $config->{auth}->{nick};
|
||||
my $host = $config->{node}->{host};
|
||||
my @echoareas = split /,/, $config->{node}->{echoareas};
|
||||
my $name = $config->{node}->{name};
|
||||
my $notify = $config->{notify}->{enabled};
|
||||
|
||||
$c = {
|
||||
nick => $nick,
|
||||
@ -31,6 +32,7 @@ sub load {
|
||||
host => $host,
|
||||
echoareas => [@echoareas],
|
||||
name => $name,
|
||||
notify => $notify,
|
||||
};
|
||||
|
||||
return $c;
|
||||
@ -40,7 +42,7 @@ sub load {
|
||||
sub reload {
|
||||
my ($self) = @_;
|
||||
|
||||
my $c = II::Config->new();
|
||||
my $c = II::Config->new();
|
||||
my $config = $c->load();
|
||||
|
||||
return $config;
|
||||
|
36
II/DB.pm
36
II/DB.pm
@ -2,6 +2,7 @@ package II::DB;
|
||||
|
||||
use SQL::Abstract;
|
||||
use DBI;
|
||||
use utf8;
|
||||
|
||||
use Data::Dumper;
|
||||
|
||||
@ -20,6 +21,7 @@ sub new {
|
||||
return $self;
|
||||
}
|
||||
|
||||
# Check message hash
|
||||
sub check_hash {
|
||||
my ( $self, $hash, $echo ) = @_;
|
||||
my $dbh = $self->{_dbh};
|
||||
@ -39,6 +41,7 @@ sub check_hash {
|
||||
}
|
||||
}
|
||||
|
||||
# Begin transaction
|
||||
sub begin {
|
||||
my ($self) = @_;
|
||||
my $dbh = $self->{_dbh};
|
||||
@ -47,6 +50,7 @@ sub begin {
|
||||
$dbh->do('BEGIN');
|
||||
}
|
||||
|
||||
# Commit transaction
|
||||
sub commit {
|
||||
my ($self) = @_;
|
||||
my $dbh = $self->{_dbh};
|
||||
@ -330,4 +334,36 @@ sub select_new {
|
||||
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;
|
||||
|
@ -148,7 +148,9 @@ sub get_echo {
|
||||
|
||||
# Notify
|
||||
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;
|
||||
}
|
||||
|
22
II/Render.pm
22
II/Render.pm
@ -263,4 +263,26 @@ sub new_mes {
|
||||
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;
|
||||
|
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{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
|
||||
my $pre = 0;
|
||||
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
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
@ -30,9 +30,6 @@ use II::Render;
|
||||
use II::DB;
|
||||
use II::Enc;
|
||||
|
||||
# Debug
|
||||
use Data::Dumper;
|
||||
|
||||
my $c = II::Config->new();
|
||||
my $config = $c->load();
|
||||
|
||||
@ -64,10 +61,22 @@ my $thread = sub {
|
||||
return [ 200, [ 'Content-type' => 'text/html' ], ["$thread"], ];
|
||||
};
|
||||
|
||||
# Get new messages
|
||||
my $get = sub {
|
||||
$config = $c->reload();
|
||||
my $GET = II::Get->new($config);
|
||||
my $msgs = $GET->get_echo();
|
||||
my $msgs;
|
||||
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);
|
||||
return [ 200, [ 'Content-type' => 'text/html' ], ["$new_mes"], ];
|
||||
};
|
||||
@ -157,6 +166,10 @@ my $push = sub {
|
||||
my $hash = $req->param('hash');
|
||||
|
||||
$config = $c->reload();
|
||||
if ( $config->{host} =~ m/.+\,.+/ ) {
|
||||
my @hosts = split( /,/, $config->{host} );
|
||||
$config->{host} = $hosts[0];
|
||||
}
|
||||
my $s = II::Send->new( $config, $echo, $base64 );
|
||||
$s->send($hash);
|
||||
|
||||
@ -177,9 +190,26 @@ my $user = sub {
|
||||
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
|
||||
builder {
|
||||
mount "/static" => Plack::App::File->new( root => './s/' )->to_app;
|
||||
mount "/search" => $search;
|
||||
mount '/' => $root;
|
||||
mount '/e' => $echo;
|
||||
mount '/s' => $thread;
|
||||
|
@ -174,4 +174,18 @@ margin-bottom: 0%;
|
||||
padding: 0.2em;
|
||||
margin-left: 45%;
|
||||
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> 
|
||||
</p>
|
||||
</div>
|
||||
<div class='search'>
|
||||
<form action='/search' method='POST'>
|
||||
<input type='text' name='q'><br>
|
||||
<input type='submit' value='Искать'>
|
||||
</form>
|
||||
</div>
|
||||
<!-- <hr> -->
|
||||
|
Loading…
Reference in New Issue
Block a user