App-Phoebe

 view release on metacpan or  search on metacpan

lib/App/Phoebe/Chat.pm  view on Meta::CPAN

The I<Listen URL> is where you need to I<stream>: as people say things in the
room, these messages get streamed in one endless Gemini document. You might have
to set an appropriate timeout period for your connection for this to work. 1h,
perhaps?

The URL will look something like this:
C<gemini://localhost/do/chat/listen> or
C<gemini://localhost/space/do/chat/listen>

The I<Say URL> is where you post things you want to say: point your client at
the URL, it prompts your for something to say, and once you do, it redirects you
to the same URL again, so you can keep saying things.

The URL will look something like this: C<gemini://localhost/do/chat/say> or
C<gemini://localhost/space/do/chat/say>

Your chat nickname is the client certificate's common name. One way to create a
client certificate that's valid for five years with an appropriate common name:

    openssl req -new -x509 -newkey ec \
    -pkeyopt ec_paramgen_curve:prime256v1 \

script/gemini-chat  view on Meta::CPAN

First, you connect to the I<listen> URL using C<gemini>:

    gemini --cert_file=cert.pem --key_file=key.pem \
      gemini://localhost/do/chat/listen

Then you connect the chat client to the I<say> URL using C<gemini-chat>:

    gemini-chat --cert=cert.pem --key=key.pem \
      gemini://transjovian.org/do/chat/say

At the prompt, type your message. What effectively happens is that all you type
ends up being sent to the server via a Gemini request:
C<gemini://transjovian.org/do/chat/say?your%20text%20here>.

To generate your client certificate for 100 days and using “Alex” as your common
name:

    openssl req -new -x509 -newkey ec -subj "/CN=Alex" \
      -pkeyopt ec_paramgen_curve:prime256v1 -days 100 \
      -nodes -out cert.pem -keyout key.pem

script/gemini-chat  view on Meta::CPAN

my $host = domain_to_ascii(decode_utf8 $iri->host);
my $port = $iri->port || 1965;
my $unsafe = "^A-Za-z0-9\-\._~"; # the default
my $path = uri_escape_utf8($iri->path, $unsafe . "/"); # path separator are safe

$uri = $iri->scheme . '://' . $host . ':' . $port;
$uri .= $path if $path;

# start read loop for saying stuff
my $term = Term::ReadLine->new($uri);
my $prompt = "> ";
my $OUT = $term->OUT || \*STDOUT;
while (defined ($_ = $term->readline($prompt))) {
  exit if $_ eq "quit";
  # create client
  my $text = uri_escape_utf8($_);
  Mojo::IOLoop->client({
    address => $host,
    port => $port,
    tls => 1,
    tls_cert => $cert,
    tls_key => $key,
    tls_options => { SSL_verify_mode => 0x00 }} => sub {

script/ijirait  view on Meta::CPAN

  Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
}

sub play {
  say "Use 'quit' to leave the game. Use '\\' to send a newline.";

  my @queue = qw(look);

  # start read loop for saying stuff
  my $term = Term::ReadLine->new("Ijirait");
  my $prompt = "> ";
  my $OUT = $term->OUT || \*STDOUT;
  while (defined ($_ = shift(@queue) || $term->readline($prompt))) {
    exit if $_ eq "quit";
    # Handle <
    my $command = decode(locale => $_);
    if ($command =~ /^(.*?)\s*<\s*([^|<>]+?)\s*$/s) {
      if (-f $2) {
	$command = $1 . " " . decode_utf8(read_text($2));
      } else {
	say "Cannot read $2";
	next;
      }

script/phoebe  view on Meta::CPAN

    cpan App::Phoebe

The Perl files are stored in F</home/phoebe/perl5>.

=head1 QUICKSTART

Start Phoebe.

    phoebe

When you run it for the first time, Phoebe is going to prompt you for a hostname
and create certificates for you. If in doubt, answer C<localhost>. The
certificate and a private key are stored in the F<cert.pem> and F<key.pem>
files, using elliptic curves, valid for five years, without password protection.

    Do you want to create them right now?
    The certificate uses eliptic curves and is valid for five years.
    If so, please provide your hostname (e.g. localhost).
    If not, just press Enter.
    localhost
    openssl req -new -x509 -newkey ec -subj "/CN=localhost" -pkeyopt ec_paramgen_curve:prime256v1 -days 1825 -nodes -out cert.pem -keyout key.pem

script/phoebe  view on Meta::CPAN


sub generate_certificates {
  say "The default certificate (and key) files are missing.";
  say "Do you want to create them right now?";
  say "The certificate uses eliptic curves and is valid for five years.";
  say "If so, please provide your hostname (e.g. localhost).";
  say "If not, just press Enter.";
  local $SIG{'ALRM'} = sub {
    die "Timed out!\n";
  };
  alarm(30); # timeout for the following prompt
  my $hostname = <STDIN>;
  alarm(0);  # done, no more alarm
  chomp $hostname;
  die "The hostname may not contain any whitespace\n" if $hostname =~ /\s/;
  my $cmd = qq(openssl req -new -x509 -newkey ec -subj "/CN=$hostname" )
      . qq(-pkeyopt ec_paramgen_curve:prime256v1 -days 1825 -nodes -out cert.pem -keyout key.pem);
  if ($hostname) {
    say $cmd;
    system($cmd) == 0
      or die "openssl failed: $?";

t/Oracle.t  view on Meta::CPAN


$page = query_gemini("$base/oracle/question/$n", undef, 0);
unlike($page, qr/delete/, "Unidentified visitor does not get to delete the question");
unlike($page, qr/answer/, "Unidentified visitor does not get to answer the question");

$page = query_gemini("$base/oracle/question/$n", undef, 2);
unlike($page, qr/delete/, "Somebody else does not get to delete the question");
like($page, qr/^=> \/oracle\/question\/$n\/answer/m, "Somebody else may answer");

$page = query_gemini("$base/oracle/question/$n/answer", undef, 0);
like($page, qr/^60/, "Unidentified visitor does not get a prompt for an answer");
$page = query_gemini("$base/oracle/question/$n/answer");
like($page, qr/^40/, "Question asker does not get to answer");
$page = query_gemini("$base/oracle/question/$n/answer", undef, 2);
like($page, qr/^10/, "Prompt for an answer");
$page = query_gemini("$base/oracle/question/" . ($n+1) . "/answer", undef, 2);
like($page, qr/deleted/, "Attempt to answer an unknown question");

$page = query_gemini("$base/oracle/question/$n/answer?4%E2%80%BC", undef, 2);
like($page, qr/^30 $base\/oracle\/question\/$n\r$/m, "Answer given");

t/Wikipedia.t  view on Meta::CPAN


# make sure starting phoebe starts knows localhost is the proxy
our @config = (<<'EOT');
package App::Phoebe::Wikipedia;
our $host = "localhost";
EOT

require './t/test.pl';

like(query_gemini("$base/"),
     qr/^10.*language/, "Top level is a prompt");
like(query_gemini("$base/?en"),
     qr/^30.*\/en\r\n/, "Redirect for the language");
like(query_gemini("$base/en"),
     qr/^10.*term/, "Search term prompt");
like(query_gemini("$base/en?Project%20Gemini"),
     qr/^30.*\/search\/en\/Project%20Gemini\r\n/, "Redirect for the term");

 SKIP: {
   skip "Making requests to Wikipedia requires \$ENV{TEST_AUTHOR} > 2", 2
       unless $ENV{TEST_AUTHOR} and $ENV{TEST_AUTHOR} > 2;

   like(query_gemini("$base/search/en/Project%20Gemini"),
	qr/^20/, "List of terms");
   like(query_gemini("$base/text/en/Project%20Gemini"),



( run in 0.961 second using v1.01-cache-2.11-cpan-6aa56a78535 )