DEV Community

Cover image for ssh chat:@www.vitalipom.com πŸ”₯πŸ”₯πŸ”₯πŸ”₯πŸ”₯πŸ”₯πŸ”₯ (Now with usernames!)
Vitali Pomanitski
Vitali Pomanitski

Posted on

ssh chat:@www.vitalipom.com πŸ”₯πŸ”₯πŸ”₯πŸ”₯πŸ”₯πŸ”₯πŸ”₯ (Now with usernames!)

Hi,
I built an SSH chat for programmers using the Curses library.

Please, please, please, come to visit me. It's a server within my house, a real server computer which is connected to the Internet. I also implemented auto scrolling alone recently and I will share this source code too. Please come to visit, leave a message and drop a star on my repository.

Find the source code here:

https://github.com/VitaliPom/chatapp/blob/master/perl.pl
Enter fullscreen mode Exit fullscreen mode

And enter the chat with one line command from any CMD:

ssh chat:@www.vitalipom.com
Enter fullscreen mode Exit fullscreen mode

Many thanks,
Vitali Pomanitski

EDIT: ~~~~ Source CODE ~~~~

#! /home/linuxbrew/.linuxbrew/opt/perl@5.18/bin/perl -w

use strict;
use Curses;
use Curses::UI;
use Curses::UI::Common;


# create a new C::UI object
my $key_up = 0;

my $cui = Curses::UI->new( -clear_on_exit => 1,

                           );

my $win = $cui->add('window_id', 'Window');

my $height = `tput rows`;
$height-=1;

my $textentry = $win->add(
    'mytextentry', 'TextEntry',
    -y => $height,  
    -text => 'Username: '
    );

my $SERVER = "192.168.1.13/chat.php";

my $USERNAME = "";

my $text = `curl $SERVER`;
$text =~ s#""#"#g;
$text =~ s#``#`#g;
$text =~ s#''#'#g;


my $textviewer = $win->add( 
     'mytextviewer', 'TextViewer',
        -text => $text, 
    -vscrollbar => 1

                );


$textentry->focus();

#$text = $textentry->get();

#$textentry->set_routine('loose-focus',"\r");
#$cui->set_routine('none',KEY_UP);
#$cui->set_routine('none',KEY_DOWN);

$cui->set_binding( sub {
     $text = $textentry->get();
     $text =~ s#"#""#g;
     $text =~ s#`#``#g;  
     $text =~ s#'#''#g; 

     if(not defined $text or $text eq ""){
        return;
     }
     my $is_log = 0;
     if($USERNAME eq ""){
        my $tmp_username = $text;
        if($tmp_username =~ /Username:\s*/){ 
            $tmp_username =~ s#Username:\s*##; 
            if($tmp_username ne ""){
                $USERNAME = $tmp_username;
                $USERNAME =~ s#"##g;   
                $USERNAME =~ s#`##g;  
                $USERNAME =~ s#'##g; 

                $text = "$USERNAME has logged in!";
                $is_log = 1;
            }
        }
     }

     $USERNAME =~ s#"#""#g;   
     $USERNAME =~ s#`#``#g;  
     $USERNAME =~ s#'#''#g; 

     if($USERNAME ne ""){
         if(not $is_log){
             $text = $USERNAME . ": " . $text; 
         }
         my $new_text = $text;
         $USERNAME =~ s#"#""#g;    
         $USERNAME =~ s#`#``#g;  
         $USERNAME =~ s#'#''#g; 
         $new_text =~ s#$USERNAME: ##;
         $new_text =~ s#Username:\s*##;

         if($new_text eq ":q"){
             exit 0;   
         }
         `curl $SERVER -d "message=$text"`;
         $text = `curl $SERVER`;
         $text =~ s#""#"#g; 
             $text =~ s#``#`#g;
         $text =~ s#''#'#g;

         $textviewer->text($text);
         $textentry->text(""); 
     }else{
         $textentry->text("Username: "); 
     }

    }, KEY_ENTER()); 

#$cui->set_binding( sub {
#     $text = `curl $SERVER`;
#     $textviewer->text($text);
#
#                $cui->draw(1);
#     
##     $textviewer->{-yscrpos}++;
#     $textviewer->layout_content();
##     $textentry->focus();
#
#        }, "5" ); 

$cui->set_timer(
        'timer',
        sub {
                 $text = `curl $SERVER`;
                 $text =~ s#""#"#g;
                 $text =~ s#``#`#g;
                 $text =~ s#''#'#g;

                 $textviewer->text($text);
#                $textentry->focus();

                 if($key_up == 0){
                    for(my $i = 0; $i<2000; $i++){
                          $textviewer->cursor_down()
                     }
                 }

                $cui->draw(1);
                return;
        },
        1,
);
for(my $i =0; $i<2000; $i++){
    $textviewer->cursor_down(); 
}


$textviewer->set_binding( sub {
        $key_up--;
        $textviewer->cursor_up()

        }, KEY_UP() );

$textentry->set_binding( sub {
        $key_up--;
        $textviewer->focus();
        $textviewer->cursor_up();
        $textentry->focus();

        }, KEY_UP() );

$textentry->set_binding( sub {
        if($key_up < 0){
            $key_up++;
        }

        $textviewer->focus();
        $textviewer->cursor_down();
        $textentry->focus();

        }, KEY_DOWN() );


$textviewer->set_binding( sub {
        if($key_up < 0){
            $key_up++;
        }
        $textviewer->cursor_down()

        }, KEY_DOWN() );

$cui->set_binding( sub {exit 0;}, "\e" );

$cui->mainloop;


Enter fullscreen mode Exit fullscreen mode

Top comments (14)

Collapse
 
jachdich profile image
Jachdich • Edited

Hey, why does this vibrate my phone constantly and can you fix it?

Also ls -la would be a cool way to list people online.

Collapse
 
vitalipom profile image
Vitali Pomanitski

Regarding ls there is no way to list people who logged of yet.
As of constant vibrating capabilities - you can turn off the 'Bell' in your shell and it will stop. Or simply use Google Cloud Shell in your phone. Currently I don't know if it's fixable, and if Curses library awakes the bell. But generally it happens because the end of Buffer in Auto Scroll.

Collapse
 
vitalipom profile image
Vitali Pomanitski

Also if you want to keep on track of what people are saying, there is vitalipom.com/message.txt

Collapse
 
spyrosamvra profile image
Spyros Amvrakidis

Request password. Fix it or better leave one default pass for fix this.

One question, can I use the source for Penetration testing?

Of course it's really good idea and congrat but will be dangerous bc without Penetration and vulnerable testing will be really big backdoor on the network.

Collapse
 
vitalipom profile image
Vitali Pomanitski • Edited

Hi no password is needed, check you command line.
Regarding pen testing. You can check through code if you can see any backdoors and report as people did. Though it's a little bit outdated. Feel free to open tickets. I actually take care of them. BUT please don't use automated peneteration testing, as it spams as heck and your 3 minutes interest later on provides me with 3 hours of work!. So as long as it is not automated and not spams. It's important.
I'll drop the secured version of code later on. Feel free top file up bugs you'll find in the github repository meanwhile.
Many thanks,
vitalipom

Collapse
 
vitalipom profile image
Vitali Pomanitski

You know what, I'm sorry I apologies. I WILL try to create for you, security guys a node for pen testin. :)
Hope this will satisfy :) :) β™₯.

Collapse
 
spyrosamvra profile image
Spyros Amvrakidis

Automation tools can just create bigger problem πŸ˜‚.
Thanks you.
If I find any backdoor I send you massege in your pc πŸ˜‚πŸ˜‚πŸ˜‚ just joke I open ticker with the backdoor.

Collapse
 
victoor profile image
VΓ­ctor FalcΓ³n

Don't know why, but my screen flash a lot when the chat it's open.

It's a cool idea ;)

Collapse
 
vitalipom profile image
Vitali Pomanitski

Hi Victor, thanks for visitting! I implemented a refresh every second. Currently the buffer is very big, lots of messages. So it might take time before it loads all of them. Hence you'll see an empty screen every second on slower machine and/or weaker connection.
I will fix it up when I will be on the server :). Okay?
Meanwhile you can check the messages at vitalipom.com/message.txt
or implement your own sending node via curl vitalipom.com -d 'message=your message here' in any other scripting language.

Collapse
 
fultonbrowne profile image
Fulton Browne

this real cool, what other features are planned?

Collapse
 
vitalipom profile image
Vitali Pomanitski

Hi, tnx! Passwords are coming for usernames so that you won't steal the usernames of each other :)

Collapse
 
dustinshah profile image
dustinshah

Hi I tried sshing but it requires a password..

Collapse
 
vitalipom profile image
Vitali Pomanitski

Hi, I was working on the server. Try again now.

Collapse
 
dustinshah profile image
dustinshah • Edited

Got connected!