bye bye github

This commit is contained in:
mynah
2018-07-13 19:06:08 -05:00
commit ee47c30aca
241 changed files with 26451 additions and 0 deletions

48
lib/Dojo/Conf.pm.example Normal file
View File

@@ -0,0 +1,48 @@
package Dojo::Conf;
use strict;
use warnings;
#Paths
use constant {
MOD => "public", #location of modules
SERVER_NAME => "localhost:3000",
CHAT_SRV => "chat.vuelodegrulla.com",
};
# database access
use constant {
VUELODB => "dbname",
VUELODB_H => "localhost",
VUELODB_UW => "writtername",
VUELODB_UWP => "writterpass",
VUELODB_UR => "readername",
VUELODB_URP => "readerpass",
};
our $radio ={ #hash to configure icecast radio
server_name => SERVER_NAME,
radio_server =>"https://myradio.com",
channel => "/test",
listen_url =>"http://radio:8000/test",
};
our $chat={ #hash to configure chat (candy prodody) server
chat_addr => "https://".CHAT_SRV,
chat_srv => CHAT_SRV,
chat_channel => 'Users@radio.'.CHAT_SRV,
};
our %rtmp={ #hash ro configure rtpm video server
rtmp_server =>"rtmp://myserver.com/steam",
rtmp_channel =>"channel",
};
our %def=( #some other global configuration
modules => MOD,
# layout => "default"
);
1;
__END__

View File

@@ -0,0 +1,63 @@
package Dojo::Controller::Data;
use Mojo::Base 'Mojolicious::Controller';
use Dojo::Support qw{ dmph merge_hash load_module };
use Dojo::Conf;
use Net::Telnet;
my $server_name = $Dojo::Conf::chat->{chat_srv};
our $t; #telnet server object
sub simple{
my $c=shift;
my $n=$c->param("dreq")//"";
my $json = {status => "304"};
$json = \%Dojo::Conf::radio if $n =~m/^radio$/ ;
$json = candy() if $n =~m/^candy$/ ;
$c->render(json=>$json);
}
sub candy{
my $c=shift;
my $r="-1";
if (connectT()) {
if ($c->param("command") =~/^isOn$/){ $r = isOn(); }
elsif( $c->session("pmid") == 4 ){
$r = turnOn() if ($c->param("command") =~/^on$/);
$r = turnOff() if ($c->param("command") =~/^off$/);
}}
else {$r="connection error";};
$c->render(json => {a=>$r});
}
sub turnOff{
return 1 unless (isOn());
grep(/Result: true/,sendT("host:deactivate('$server_name')"))?1:0;
}
sub turnOn{
return 1 unless (!isOn());
grep(/Result: true/,sendT("host:activate('$server_name')"))?1:0;
}
sub isOn{ grep(/\s$server_name/,sendT("host:list()"))? 1:0; }
sub sendT{
commandT(shift);
my @r = $t->getlines(All=>0);
disconnectT();
return @r
}
sub connectT{
$t = new Net::Telnet ( Port=>5582, Timeout=>1, Errmode=>'return' );
# $t = new Net::Telnet ( Port=>5582, Timeout=>1, Errmode=>'die' );
return 1 if $t->open();
return 0;
}
sub commandT{
$t->getlines(All=>0);#empty buffer
$t->print(shift); #run istruction
}
sub disconnectT{ $t->close();}
1
__END__

View File

@@ -0,0 +1,12 @@
package Dojo::Controller::Example;
use Mojo::Base 'Mojolicious::Controller';
# This action will render a template
sub welcome {
my $self = shift;
# Render template "example/welcome.html.ep" with message
$self->render(msg => 'Welcome to the Mojolicious real-time web framework!');
}
1;

View File

@@ -0,0 +1,99 @@
package Dojo::Controller::Home;
use Mojo::Base 'Mojolicious::Controller';
use Dojo::Support qw{ dmph merge_hash load_module };
use Dojo::Conf;
sub tst{
my $c=shift;
my ($v,$w)= load_module($c);
# $c->stash($v);
$c->stash(d =>$v);
}
sub home {
my $c = shift;
$c->stash((load_module($c))[0]);
$c->stash( map{ $_->{nombre} => $_->{contenido}} @{$c->dbv->mod});
}
sub pang {
my $c = shift;
my ($v,$w)=load_module($c);
$c->stash($v);
$c->stash( $c->dbv->pang($w) );
}
sub cal {
my $c = shift;
$c->stash((load_module($c))[0]);
my ($data,$block)=$c->dbv->cal;
my %hdata;
map{ push @{ $hdata{$_->{bid}} },$_; }(@$data);
$c->stash( r=>\%hdata, b=>$block);
}
sub event{
my $c = shift;
$c->stash((load_module($c))[0]);
$c->stash(%{($c->dbv->event($c->param("id")))->[0]});
}
sub contact{
my $c = shift;
if ($c->param("mup")){
$c->flash(mname => $c->param("mname"));
$c->redirect_to('contact2');
}else{
my $dir= "/$c->{stash}{controller}/$c->{stash}{action}";
$c->stash( css=>["$dir/cssContact1.css"], js=>[]);
$c->stash( layout=>"default");
}
}
sub contact2{
my $c = shift;
$c->redirect_to("home") unless $c->flash('mname');
my $dir= "/$c->{stash}{controller}/contact";
$c->stash( css=>["$dir/cssContact2.css"], js=>[]);
$c->stash( layout=>"default");
$c->stash( mname=>$c->flash('mname'));
}
sub store{
my $c = shift;
$c->stash((load_module($c))[0]);
$c->stash( r=>$c->dbv->store);
}
sub tv{
my $c = shift;
$c->stash( merge_hash(
(load_module($c))[0],
(load_module($c,"home/tv/trans"))[0]
));
my ($series,$table)=$c->dbv->tv;
$c->stash( series=>$series, table=>$table);
}
sub podcast{
my $c = shift;
$c->stash((load_module($c))[0]);
my ($txt,$h)=$c->dbv->podcast;
$c->stash( t=>$txt, pod=>$h,);
}
sub radio{
my $c=shift;
$c->stash((load_module($c))[0]);
$c->stash(%{($c->dbv->radio)->[0]});
$c->stash($Dojo::Conf::radio);
$c->stash(nick=>$c->session("nick"));
}
#$c->render(text =>"$c->{match}->position");
#$c->render(text=>"$c->{stash}{controller}");
#$c->render(text=>"$c->{match}{stack}->[0]{controller}");
#$c->render(text=>"$h->{css}[0]");
1;

View File

@@ -0,0 +1,28 @@
package Dojo::Controller::Users;
use Mojo::Base 'Mojolicious::Controller';
use Dojo::Support qw{ merge_hash load_module };
sub login {
my $c = shift;
$c->stash((load_module($c))[0]);
my $user = $c->param('uname') // '';
my $pass = $c->param('pass') //'';
return $c->render unless my $pmid = $c->dbg->check($user, $pass);
$c->session(user => $user, pmid=>$pmid, nick=> $c->param('nick'));
$c->redirect_to('radio');
}
sub is_logged {
my $self = shift;
return 1 if $self->session('user');
$self->redirect_to('login');
}
sub logout {
my $self = shift;
$self->session(expires => 1);
$self->redirect_to('home');
}
1;

15
lib/Dojo/Model/Data.pm Normal file
View File

@@ -0,0 +1,15 @@
package Dojo::Model::Data;
use Dojo::Support qw{ dmph merge_hash load_module };
use Dojo::Conf;
sub new { bless {}, shift };
sub tst{
return {tst=>"this is my rifle"};
}
1;

38
lib/Dojo/Model/Users.pm Normal file
View File

@@ -0,0 +1,38 @@
package Dojo::Model::Users;
use strict;
use warnings;
use DBI;
use Mojo::Util 'secure_compare';
use Dojo::Conf;
sub new { bless {}, shift }
sub check {
my ($self, $user, $pass) = @_;
my $q="select permiso_id as pid from usuario where nombre = ? and pass=? ";
# | 0 | bloqueado |
# | 1 | invitado |
# | 2 | usuario |
# | 3 | pago |
# | 4 | master |
my $r= _read($q,$vuelo,$user,$pass)->[0];
return $r->{pid} // 0;
}
sub _read{
my ($q,$d,@bind)=@_;
my (@empty,$arr);
my $dbh = DBI->connect("DBI:mysql:".Dojo::Conf::GRULLADB.":".Dojo::Conf:: GRULLADB_H,Dojo::Conf::GRULLADB_UR,Dojo::Conf::GRULLADB_URP);
return \@empty unless($dbh);
#$dbh->do(qq{SET NAMES 'utf8'});
my $h=$dbh->selectall_arrayref($q,{ Slice => {} },@bind);
#((col1=>d1,col2=>d1),(col1=>d2,col2=>d2))
$dbh->disconnect();
return $h;
}
1;

79
lib/Dojo/Model/Vuelo.pm Normal file
View File

@@ -0,0 +1,79 @@
package Dojo::Model::Vuelo;
use Mojo::File 'path';
use Mojo::JSON qw(decode_json encode_json);
use Dojo::Support qw{ dmph merge_hash load_module };
use File::Basename;
use Text::Markdown qw{ markdown };
use Encode qw{ decode_utf8 };
use DBI;
use Dojo::Conf;
sub new { bless {}, shift };
sub mod{
my $q="select nombre,contenido from casa;";
return \@{_read($q,$vuelo)};
}
sub pang{
my ($c,$q)=@_;
return {map { basename($_,".md") => load_md("public/$_")}@{$q->{md}}};
}
sub cal {
my $block=_read (path("public/home/cal/q1Block.q")->slurp,$vuelo);
my $data=_read (path("public/home/cal/q3Event.q")->slurp,$vuelo);
return ($data,$block);
}
sub event{
my ($self,$id)=@_;
return _read (path("public/home/event/qEvent.q")->slurp,$vuelo,$id);
}
sub store{
return _read (path("public/home/store/qStore.q")->slurp,$vuelo);
}
sub tv{
my $series = _read (path("public/home/tv/qSeries.q")->slurp,$vuelo); #group,name
my $table = _read (path("public/home/tv/qTable.q")->slurp,$vuelo); #name,order,group
return ($series,$table);
}
sub podcast{
my $txt = path("public/home/podcast/text.txt")->slurp;
my $hash = decode_json path("public/home/podcast/jsonPod.json")->slurp;
return ($txt,$hash);
}
sub radio{
my $q="select contenido as rmod from casa where nombre='rmod';";
return _read($q,$vuelo);
}
sub _read{
my ($q,$d,@bind)=@_;
my (@empty,$arr);
my $dbh = DBI->connect("DBI:mysql:".Dojo::Conf::VUELODB.":".Dojo::Conf::VUELODB_H,Dojo::Conf::VUELODB_UR,Dojo::Conf::VUELODB_URP);
return \@empty unless($dbh);
#$dbh->do(qq{SET NAMES 'utf8'});
my $h=$dbh->selectall_arrayref($q,{ Slice => {} },@bind);
#((col1=>d1,col2=>d1),(col1=>d2,col2=>d2))
$dbh->disconnect();
return $h;
}
sub load_md{
return "" unless
my $text = path(shift)->slurp;
return markdown( decode_utf8($text) );
}
sub load_txt{
return "" unless
my $text = path(shift)->slurp;
return decode_utf8($text);
}

62
lib/Dojo/Support.pm Normal file
View File

@@ -0,0 +1,62 @@
package Dojo::Support;
use strict;
use warnings;
use Exporter 'import';
our @EXPORT = qw/ dmph merge_hash load_module /;
use Mojo::Base 'Mojolicious';
use File::Basename;
use Mojo::File 'path';
use Path::Class;
use Encode qw{ decode_utf8 };
use Hash::Merge;
use Dojo::Conf;
sub get_names{
my $dir = shift;
my @file_name;
opendir(DIR, $dir) or die "error opening dir: $dir \n$!";
while (my $file = readdir(DIR)) {
next unless ( $file =~m/^[\w\d]/);
next unless (-f "$dir/$file");
push(@file_name,$file);
}
closedir(DIR);
return sort @file_name;
};
sub merge_hash{
my ($v,$w)=@_;
my $merger = Hash::Merge->new('LEFT_PRECEDENT');
return $merger->merge( $v, $w );
}
sub load_module{
my $c=shift;
my $dir=shift //"$c->{stash}{controller}/$c->{stash}{action}";
my $lpath= Dojo::Conf::MOD."/$dir";
my $h; $h->{js}=[]; $h->{css}=[]; #no me gusta!!!
$h->{layout} = "default";
my $q;
my @s= get_names($lpath);
foreach (@s) {
push(@{$h->{$1}}, "/$dir/$_") if /.*\.(css|js)$/;
push(@{$q->{$1}}, "/$dir/$_") if /.*\.(q|json|txt|md)$/;
}
return ($h,$q);
};
sub dmph{
my $x = shift;
my $y=" ";
foreach (sort(keys %$x)) {
$y= "$y $_ = $x->{$_} \n";
}
return $y;
}
1;