]> bicyclesonthemoon.info Git - ott/bsta/blobdiff - chat.1.pl
input validation; goto form; show version; 2 words password
[ott/bsta] / chat.1.pl
index 1fd807361bac9c4281b462fbba1560fba1c4f277..90ea637323a58d57d762aa154bc5db3e71bdadc0 100644 (file)
--- a/chat.1.pl
+++ b/chat.1.pl
@@ -29,7 +29,6 @@ use Encode ('encode', 'decode');
 ###PERL_LIB: use lib /botm/lib/bsta
 use botm_common (
        'HTTP_STATUS',
-       'read_data_file', 'write_data_file',
        'read_header_env',
        'url_query_decode', 'url_query_encode',
        'merge_url',
@@ -44,7 +43,9 @@ use bsta_lib (
        'print_html_start', 'print_html_end',
        'print_html_head_start', 'print_html_head_end',
        'print_html_body_start', 'print_html_body_end',
-       'merge_settings'
+       'merge_settings',
+       'read_chat', 'write_chat',
+       'read_coincidence', 'read_settings', 'read_state'
 );
 use  File::Copy;
 
@@ -52,9 +53,6 @@ use  File::Copy;
 ###PERL_CGI_COIN_PATH:      CGI_COIN_PATH      = /bsta/coin
 
 ###PERL_DATA_CHAT_PATH:     DATA_CHAT_PATH     = /botm/data/bsta/chat
-###PERL_DATA_COIN_PATH:     DATA_COIN_PATH     = /botm/data/bsta/coincidence
-###PERL_DATA_SETTINGS_PATH: DATA_SETTINGS_PATH = /botm/data/bsta/settings
-###PERL_DATA_STATE_PATH:    DATA_STATE_PATH    = /botm/data/bsta/state
 
 ###PERL_WEBSITE_NAME:       WEBSITE_NAME       = Bicycles on the Moon
 
@@ -118,9 +116,9 @@ $IP       = get_remote_addr();
 $page     = get_id(\%cgi, -1);
 $password = get_password(\%cgi);
 
-%coin      = read_data_file(DATA_COIN_PATH());
-%settings  = read_data_file(DATA_SETTINGS_PATH());
-%state     = read_data_file(DATA_STATE_PATH());
+%coin      = read_coincidence();
+%settings  = read_settings();
+%state     = read_state();
 
 $password_ok = ($password eq $settings{'password'});
 
@@ -141,7 +139,7 @@ foreach my $action_id ('join', 'leave', 'nopost', 'file') {
 if ($page < 0) {
        if (open_encoded($fh, "+<", DATA_CHAT_PATH())) {
                if (flock($fh, 2)) {
-                       %chat = read_data_file($fh);
+                       %chat = read_chat($fh);
                        
                        $chat_state = int($chat{'state'});
                        $chat_id    = int($chat{'id'});
@@ -167,7 +165,7 @@ if ($page < 0) {
                                                                $chat_state = CHAT_STATE->{'active'};
                                                                $chat{'state'} = $chat_state;
                                                        }
-                                                       write_data_file($fh, \%chat);
+                                                       write_chat($fh, \%chat);
                                                }
                                                else {
                                                        $status = HTTP_STATUS->{'bad_request'};
@@ -193,7 +191,7 @@ if ($page < 0) {
                                                                $chat_state = CHAT_STATE->{'ready'};
                                                                $chat{'state'} = $chat_state;
                                                        }
-                                                       write_data_file($fh, \%chat);
+                                                       write_chat($fh, \%chat);
                                                }
                                                elsif ($words eq '') {
                                                        $status = HTTP_STATUS->{'bad_request'};
@@ -223,12 +221,12 @@ if ($page < 0) {
                                        if ($username =~ /^[A-Za-z]*$/) {
                                                $chat{'content'} .= 'leave@'.$username.': '.$words."\n";
                                                if ($username ne '') {
-                                                       write_data_file($fh, \%chat);
+                                                       write_chat($fh, \%chat);
                                                }
                                                else {
                                                        my %new_chat;
                                                        if ($chat_state > 1) {
-                                                               write_data_file(DATA_CHAT_PATH.$chat_id, \%chat);
+                                                               write_chat($chat_id, \%chat);
                                                                $new_chat{'id'} = $chat_id+1;
                                                        }
                                                        else {
@@ -236,7 +234,7 @@ if ($page < 0) {
                                                        }
                                                        $new_chat{'state'} = CHAT_STATE->{'disconnected'};
                                                        $new_chat{'content'} = '';
-                                                       write_data_file($fh, \%new_chat);
+                                                       write_chat($fh, \%new_chat);
                                                }
                                        }
                                        else {
@@ -259,7 +257,7 @@ if ($page < 0) {
                                                        $chat_state = CHAT_STATE->{'active'};
                                                        $chat{'state'} = $chat_state;
                                                }
-                                               write_data_file($fh, \%chat);
+                                               write_chat($fh, \%chat);
                                        }
                                        else {
                                                $status = HTTP_STATUS->{'bad_request'};
@@ -291,10 +289,10 @@ if ($page < 0) {
 # old chat archive
 else {
        $chat_id = $page;
-       %chat = read_data_file(DATA_CHAT_PATH());
+       %chat = read_chat();
        $last_id = int($chat{'id'});
        if ($chat_id < $last_id) {
-               %chat = read_data_file(DATA_CHAT_PATH.$page);
+               %chat = read_chat($page);
                $chat_state = int($chat{'state'});
                @chat_lines = split(/\r?\n/, $chat{'content'});
        }
@@ -337,11 +335,11 @@ if ($password_ok) {
        $newer_url  = merge_url($newer_url , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
 }
 
+my $_password = $password_ok ? html_entity_encode_dec($settings{'password'}, 1): '';
 my $abbr = abbr_name($username);
 my $_website_name = html_entity_encode_dec(WEBSITE_NAME() , 1);
 my $_server       = html_entity_encode_dec($coin    {'server'}  , 1);
 my $_key          = html_entity_encode_dec($coin    {'key'}     , 1);
-my $_password     = html_entity_encode_dec($settings{'password'}, 1);
 my $_cgi_username = html_entity_encode_dec($cgi     {'username'}, 1);
 my $_username     = html_entity_encode_dec($username  , 1);
 my $_abbr         = html_entity_encode_dec($abbr      , 1);