Skip to content

Commit

Permalink
fixed handling of undefined values passed in through javascript
Browse files Browse the repository at this point in the history
  • Loading branch information
ewolf committed Oct 17, 2016
1 parent cc72537 commit 73c939c
Show file tree
Hide file tree
Showing 6 changed files with 195 additions and 2 deletions.
1 change: 1 addition & 0 deletions ServerYote/Build.PL
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ my $builder = Module::Build->new(
requires => {
'perl' => 'v5.12',
'Yote' => 1.31,
'JSON' => 0,
'IO::Socket::SSL' => 2.024,
'Lock::Server' => 1.73,
'Test::More' => 0,
Expand Down
6 changes: 5 additions & 1 deletion ServerYote/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
2016-09-01 eric wolf <coyocanid@gmail.com>
2016-09-01 eric wolf <coyocanid@gmail.com>
* Version 1.19 : Added Yote::Server::ModperlOperator
* This thing needs documentation *sigh*

2016-09-01 eric wolf <coyocanid@gmail.com>
* Version 1.18 : unicode support for input/output
* Version 1.17 : added a needs resync error case to send back to the client
* Version 1.16 : logins are case insensitive now
Expand Down
41 changes: 41 additions & 0 deletions ServerYote/cgi-bin/epuc/strip.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/perl

use strict;
use warnings;
no warnings 'uninitialized';

use lib '/opt/yote/lib';
use lib '/home/wolf/proj/Yote/ServerYote/lib';
use lib '/home/wolf/proj/Yote/LockServer/lib';
use lib '/home/wolf/proj/Yote/FixedRecordStore/lib';
use lib '/home/wolf/proj/Yote/YoteBase/lib';

use Yote;
use Yote::Server;
use EPUC::Util;

my( $server, $cgi ) = EPUC::Util::init;
# Käse essen
my $app = $server->fetch_app( 'EPUC::App' );

my $strip_id = $cgi->param('s');
my $strip_id = $cgi->param('s');

my $strip = $server->store->_fetch( $strip_id );

if( $strip ) {
# find the index of the strip and make sure it is ready
if( $strip->get__state eq 'complete' ) {
my $strips =
}
}

print $cgi->header(
-status => '200 OK',
-type => 'text/json'
);
_log("OUTY <$out_json>");
print $out_json;
$main::yote_server->{STORE}->stow_all;


6 changes: 6 additions & 0 deletions ServerYote/cgi-bin/yote_cgi.pl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
no warnings 'uninitialized';

use lib '/opt/yote/lib';
use lib '/home/wolf/proj/Yote/ServerYote/lib';
use lib '/home/wolf/proj/Yote/LockServer/lib';
use lib '/home/wolf/proj/Yote/FixedRecordStore/lib';
use lib '/home/wolf/proj/Yote/YoteBase/lib';

use Yote;
use Yote::Server;
Expand Down Expand Up @@ -80,7 +84,9 @@ sub _log {
-status => '200 OK',
-type => 'text/json; charset=utf-8'
);
print STDERR Data::Dumper->Dump([$out_json,"AFOR"]);
$out_json = Encode::decode('utf8',$out_json);
print STDERR Data::Dumper->Dump([$out_json,"AR"]);
_log( "CGI OUT <$out_json>" );
print $out_json;
$main::yote_server->{STORE}->stow_all;
Expand Down
2 changes: 1 addition & 1 deletion ServerYote/lib/Yote/Server.pm
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use UUID::Tiny;

use vars qw($VERSION);

$VERSION = '1.18';
$VERSION = '1.19';

our $DEBUG = 0;

Expand Down
141 changes: 141 additions & 0 deletions ServerYote/lib/Yote/Server/ModperlOperator.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
package Yote::Server::ModperlOperator;

use strict;
no strict 'refs';

use Apache2::Cookie;
use Apache2::Const qw(:common);
use Data::Dumper;
use Text::Xslate qw(mark_raw);

use Yote::Server;

sub new {
my( $pkg, $r, %options ) = @_;

my $jar = Apache2::Cookie::Jar->new($r);
my $token_cookie = $jar->cookies("token");
my $token = $token_cookie ? $token_cookie->value : 0;
my( @path ) = grep { $_ } split '/', $r->uri;

bless {
r => $r,
cookie_path => $options{cookie_path},
template_path => $options{template_path},
app_name => $options{app_name},
main_template => $options{main_template},
token => $token,
path => \@path,
}, $pkg;

} #new

sub req {
shift->{r}
}

sub load_app {
my( $self, $appname ) = @_;

eval('use Yote::ConfigData');
my $yote_root_dir = $@ ? '/opt/yote' : Yote::ConfigData->config( 'yote_root' );
unshift @INC, "$yote_root_dir/lib";

my $options = Yote::Server::load_options( $yote_root_dir );
my $server = new Yote::Server( $options );
my $store = $server->store;
my $root = $store->fetch_server_root;
my $session = $root->_fetch_session( $self->{token} );
$root->{SESSION} = $session;
unless( $session ) {
($root,my $token) = $root->init_root;
$self->{token} = $token;
my $token_cookie = Apache2::Cookie->new( $self->{r},
-name => "token",
-path => "/$self->{cookie_path}",
-value => $self->{token} );
$token_cookie->bake( $self->{r} );
}


$self->{root} = $root;
$self->{session} = $session;
$self->{store} = $store;

my( $app, $login ) = $root->fetch_app( $appname );
$app->{SESSION} = $session;
$self->{app} = $app;
$self->{login} = $login;
if( $login ) {
$login->{SESSION} = $session;
}
$app;
} #load_app

sub haslogin {
defined shift->{login};
}

sub err {
my( $self, $err ) = @_;
$err //= $@;
if( ref $err ) {
$self->{last_err} = $err->{err};
return $err->{err};
} elsif( $err ) {
die $err;
}
}

sub lasterr {
shift->{last_err};
}

sub login {
my $self = shift;
return $self->{login} if $self->{login};
my $r = $self->{r};
my( $un, $pw ) = ( $r->param('un'), $r->param('pw') );
my $login;
if( $un && $pw ) {
$login = $self->{app}->login( $un, $pw );
$login->{SESSION} = $self->{session};
$self->{login} = $login;
}
$login;
} #login

sub tmpl {
my( $self, $tname ) = @_;
"$self->{template_path}/$tname.tx";
}

sub make_page {
my $self = shift;

my $tx = new Text::Xslate;
$self->load_app($self->{app_name});
eval {
$self->login;
};
$self->err;
my( @path ) = @{$self->{path}};
$self->{r}->print( $tx->render( $self->tmpl($self->{main_template}), {
op => $self, } ) );

$self->{store}->stow_all;

return $self->{rv};
} #make_page

1;

__END__
=head1 NAME
Yote::Server::ModperlOperator - marry the yote server to xslate templates
=cut

0 comments on commit 73c939c

Please sign in to comment.