IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Web Perl Discussion :

problème avec un fichier CGI perl


Sujet :

Web Perl

  1. #1
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Août 2009
    Messages
    44
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2009
    Messages : 44
    Points : 31
    Points
    31
    Par défaut problème avec un fichier CGI perl
    Bonjour,

    J'ai un petit soucis quand je veux accéder à mon fichier cgi à partir du navigateur. Le répertoir cgi-bin a bien été crée et j'y accède sans problème via mon navigateur qui affiche tous les fichier contenus dans cgi_bin mais dès que je clique sur le fichier cgi la page n'est pas trouvée?

    Je ne sais vraiment pas quoi faire. Je suis sous windows

    Merci.

  2. #2
    Membre actif
    Homme Profil pro
    Inscrit en
    Juillet 2009
    Messages
    164
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 79
    Localisation : France

    Informations forums :
    Inscription : Juillet 2009
    Messages : 164
    Points : 218
    Points
    218
    Par défaut
    Qu'affiche le navigateur ? error 404, ou le contenu du fichier cgi ? autre chose ?
    As-tu installé un serveur, Apache, par exemple, de plus le serveur doit être configuré pour interpréter les fichiers cgi
    nibroc


    Citation Envoyé par anassss Voir le message
    Bonjour,

    J'ai un petit soucis quand je veux accéder à mon fichier cgi à partir du navigateur. Le répertoir cgi-bin a bien été crée et j'y accède sans problème via mon navigateur qui affiche tous les fichier contenus dans cgi_bin mais dès que je clique sur le fichier cgi la page n'est pas trouvée?

    Je ne sais vraiment pas quoi faire. Je suis sous windows

    Merci.

  3. #3
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Août 2009
    Messages
    44
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2009
    Messages : 44
    Points : 31
    Points
    31
    Par défaut
    Citation Envoyé par nibroc Voir le message
    Qu'affiche le navigateur ? error 404, ou le contenu du fichier cgi ? autre chose ?
    As-tu installé un serveur, Apache, par exemple, de plus le serveur doit être configuré pour interpréter les fichiers cgi
    nibroc
    Oui j'ai un serveur IIS en local mais kan j'exécute le fichier cgi j'ai cette erreur :

    CGI Error
    The specified CGI application misbehaved by not returning a complete set of HTTP headers.

  4. #4
    Responsable Perl et Outils

    Avatar de djibril
    Homme Profil pro
    Inscrit en
    Avril 2004
    Messages
    19 820
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 19 820
    Points : 499 184
    Points
    499 184
    Par défaut
    Il faut nous montrer ton code.

  5. #5
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Août 2009
    Messages
    44
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2009
    Messages : 44
    Points : 31
    Points
    31
    Par défaut
    Citation Envoyé par djibril Voir le message
    Il faut nous montrer ton code.
    Le code ne marchera pas si vous le lancer car il requiert une authentification .mai voilà un bout de code :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    use strict;
    use warnings;
    use CGI ':standard';
    use JSON::XS 'decode_json', 'encode_json';
    use IO::All;
    use YAML::XS qw/DumpFile LoadFile/;
    use FindBin;
    use Socialtext::Resting::Getopt qw/get_rester/;
    use Weather::Underground;
    use Acme::LOLCAT ();
    use Finance::Quote;
    use Locale::Currency::Format;
    use URI::Escape;
    use DateTime;
    use DateTime::Duration;
    use utf8;
     
    # Use a local YAML file to store state. Make sure
    # this file exists and is writable.
    my $Conf_file = "$FindBin::Bin/sally.yaml";
    my $Config = load_config();
     
    # Use a config file to hold the Socialtext server
    # and username/password details.
    my $rester = get_rester( 'rester-config' => "$FindBin::Bin/.sally-rester");
     
    eval {
        print header('text/plain');
     
        if (my $js = param('json_payload')) {
            my $signals = decode_json($js);
            my $signal = $signals->[0]->{object};
            my $actor = $signals->[0]->{actor};
            my $at = $signals->[0]->{at};
     
            # Map the tags into a hash for ease
            $signal->{tags} = { map {$_ => 1} @{$signal->{tags}}};
     
            # The thread is where our Reply will be sent to.
            # Because we always reply to the incoming message, our replies will
            # be sent to the appropriate context - private or to the group or
            # account they came from.
            $signal->{thread} = $signal->{in_reply_to}{signal_id} || $signal->{id};
     
            my $resp;
            my @annotations;
            my $begin = "^(?:{user: $Config->{our_user_id}}\\s+)?#?";
            my $STOCK_SYMBOL = qr/\b([A-Z]{3,4})\b/;
     
            # Now look at the signal body for opportunities to interact.
     
            if ($signal->{body} =~ m/${begin}(tell|ask)\s+{user: (\d+)}\s+(.+)/i) {
                # Tell or Ask means we will store a message to deliver to a user
                # later.
                my ($verb, $user_id, $msg) = ($1, $2, $3);
                if ($user_id == $Config->{our_user_id}) {
                    $resp = "Uh, thanks {user: $actor->{id}} - I'll, uh, do that.";
                }
                else {
                    push @{ $Config->{tell}{$user_id} }, {
                        from => $actor->{id},
                        at => $at,
                        verb => $verb,
                        message => $msg,
                    };
                    save_config();
                    $resp = "I'll pass that on to {user: $user_id}";
                }
            }
            elsif ($actor->{id} == $Config->{our_user_id}) {
                # Ignore our own messages.
                return;
            }
            elsif ($signal->{body} =~ m/${begin}weather (.+)/i) {
                # Look up the weather and reply with what we found
                my $query = $1;
                ($resp, my $places) = handle_weather($query, \@annotations);
                if ($places) {
                    # Set up some interactions for our weather response.
                    push @annotations, {
                        interactor => { title => "More about \u$query..." }
                    };
                    for (@$places) {
                        my $place = $_->{place};
                        push @annotations, {
                            action => {
                                title => "Map for $place",
                                url => "http://maps.google.com/maps?f=q&z=15&output=embed&q=" . uri_escape($place),
                                target => "frame",
                                width => "100%",
                                height => "400"
                            },
                        };
                        push @annotations, {
                            action => {
                                title => "Search for $place",
                                url => "http://www.google.com/search?q=" . uri_escape($place),
                                target => "blank",
                            },
                        };
                    }
                }
            }
            elsif ($signal->{body} =~ m/${begin}lol:? (.+)/i) {
                # LOLbot repeats the signal using Acme::LOLCAT
                $resp = Acme::LOLCAT::translate($1);
            }
            elsif ($signal->{body} =~ m/${begin}exchange\s+.*?([\d.]*)\s*(\w{3}) (?:to )?(\w{3})/i) {
                # Currency Exchange
                $resp = handle_exchange($1, $2, $3);
            }
            elsif ($signal->{body} =~ m/\b(quote|stock)\b.+$STOCK_SYMBOL/) {
                $resp = '';
                while ($signal->{body} =~ m/$STOCK_SYMBOL/g) {
                    # Look up a stock quote
                    $resp .= handle_stock($1);
                }
            }
            elsif ($signal->{body} =~ m/${begin}math (.+)/i) {
                # Do some math
                $resp = handle_math($1);
            }
            elsif ($signal->{body} =~ m/${begin}seen {user: (\d+)}/i) {
                # Handle requests for the last signal a user sent.
                my $user_id = $1;
                if (my $last = $Config->{last_seen}{$user_id}) {
                    (my $at = $last->{at}) =~ s/(.+)\..+/$1/;
                    $resp = qq(I last saw {user: $user_id} saying '$last->{body}' at "$at"<) . $rester->server . qq($last->{uri}>);
                }
                else {
                    $resp = "Sorry, I haven't seen {user: $user_id}";
                }
            }
            elsif ($signal->{body} =~ m/${begin}poll(?:\s+(.+)|\s*$)/i) {
                # Start a poll
                my ($topic) = ($1);
                $topic ||= '';
     
                push @annotations, {
                    interactor => { title => "Start a poll..." }
                };
     
                # In this case, the poll itself is handled by the hal9000 script.
                push @annotations, {
                    action => {
                        title => "Set Answers",
                        url => "http://borax.socialtext.net/~audreyt/hal9000/poll.cgi/$signal->{signal_id}/start?q="
                             . uri_escape($topic) . ';user=' . $actor->{id}
                             . ';account_ids=' . join(',', @{$signal->{account_ids}||[]})
                             . ';group_ids=' . join(',', @{$signal->{group_ids}||[]})
                             . ';request_uri=' . $ENV{SCRIPT_URI},
                        target => "frame",
                        width => "100%",
                        height => "300"
                    },
                };
     
                $resp = "{user: $actor->{id}} Please click 'Start a poll...' to the right to set the answers."
            }
            elsif ($signal->{body} =~ m/^{user: $Config->{our_user_id}} (?:commands|help)$/) {
                # This is kind of a usage help.
                $resp = help_text();
                push @annotations, detailed_help_annotation();
            }
            elsif ($signal->{tags}{bug}) {
                # If someone mentions the #bug tag, send them the link to our bug
                # reporting form, but only once per thread.
                unless ($Config->{bug_report}{$signal->{thread}}) {
                    $Config->{bug_report}{$signal->{thread}} = 1;
                    $resp = qq{If you've found a bug, please use the "bug reporting form"<https://www2.socialtext.net/bug-report/index.cgi?internal_bug_report>};
                }
            }
            elsif ($signal->{body} =~ /roll ((\d+)d(\d+))/i) {
                my ($arg, $n, $die) = ($1,$2,$3);
                my @rolls;
                push @rolls, int(rand($die))+1 for (1..$n);
                my $sum = 0;
                $sum += $_ for @rolls;
                $resp = "rolled $arg got ".join(', ',@rolls)." for $sum\n";
            }
            elsif ($signal->{body} =~ m/selling days/i) {
                my $days = selling_days_left_in_the_quarter();
                $resp = "There are $days selling days left in the quarter.";
            }
            elsif ($signal->{body} =~ m/^{user: $Config->{our_user_id}} (.+)$/
                or (($signal->{recipient_id}||0) == $Config->{our_user_id})) {
                # For any other kind of mention
                $resp = help_text();
                push @annotations, detailed_help_annotation();
            }
     
            if ($resp) {
                send_signal(
                    $resp,
                    in_reply_to => { signal_id => $signal->{id} },
                    (@annotations ? (annotations => \@annotations) : ()),
                );
            }
     
            # Remember each user's last signal for the seen command.
            $Config->{last_seen}{$actor->{id}} = {
                body => $signal->{body},
                at => $at,
                uri => $signal->{uri},
            };
            save_config();
     
            # Check if there is any messages for the user that just signalled.
            if (my $msgs = $Config->{tell}{$actor->{id}}) {
                for my $msg (@$msgs) {
                    (my $at = $msg->{at}) =~ s/(.+)\..+/$1/;
                    my $verb = $msg->{verb} || 'tell';
                    my $message = "{user: $actor->{id}}: {user: $msg->{from}} said to $verb you $msg->{message} (at $at)";
                    send_signal($message);
                }
                delete $Config->{tell}{$actor->{id}};
                save_config();
            }
        }
        elsif (my $jsp = param('json_post')) {
            # This allows other scripts (like the hal9000 poll bot) to post http to
            # sally, and have sally send a signal.
            my $signal = decode_json($jsp);
            send_signal(delete $signal->{body}, %$signal);
        }
        elsif (param('detailed_help')) {
            print <<'EOT';
     
     
     
     
    You can interact with me in several ways:
     
    I can look up the weather in a given place. Examples:
    weather New York, NY
    weather 90210
    weather SFO
     
    I can exchange currencies:
    exchange USD to GBP
    exchange CAD to USD
    exchange $50 CAD to USD
     
    I will look up any thing that looks like a stock symbol:
    Price of GOOG?
    What is the price of GOOG, AAPL and RIM?
    I'm good at math:
    math 9 * 42
    math ((50000 * 20) * 0.87) - ((50000 * 20) * 0.75)
     
    I can help you poll your peers about some question:
    poll
    poll How far do you live from Florida?
     
    I can translate into LOLcat:
    lol Can I have a cheeseberger?
     
    I can tell you when I last saw a particular user send a signal:
    seen @SomeUser
     
    I can remind someone when they next return to signals:
    tell @SomeUser to read the memo and fill out their TPS reports.
     
    And for you keeners out there, my source code is available here:
    <a href="http://github.com/socialtext/st-clients/blob/master/rest/perl/sally/sally.cgi" target="_blank">http://github.com/socialtext/st-clie...ally/sally.cgi</a>
    EOT
            exit;
        }
    };
    if ($@) {
        # Dump any errors to a temp file.
        DumpFile('/tmp/sally-error', { error => $@ } );
    }
    print "KTHXBYE\n";
     
    exit;
     
     
    sub send_signal {
        my $text = shift;
        my %args = @_;
        $rester->post_signal($text, %args);
    }
     
    sub load_config {
        return LoadFile($Conf_file) if -e $Conf_file and -s _;
     
        # Determine our user_id
        my $me = $rester->get_user($rester->username);
        $Config = {
            our_user_id => $me->{user_id},
        };
        save_config();
        return $Config;
    }
     
    sub save_config {
        DumpFile($Conf_file, $Config);
    }
     
    sub handle_weather {
        my $place = shift;
        my $annos = shift;
        my $weather = Weather::Underground->new(place => $place) or
            die "Can't load weather for $place: $@\n";
        my $ref = $weather->get_weather();
        unless ($ref) {
            push @$annos, detailed_help_annotation();
            return "Sorry, I cannot look up the weather in $place. "
                . "Try: _city, state_ or _zip code_ or _airport_";
        }
     
        my $w = $ref->[0];
        return("In $w->{place} it is $w->{fahrenheit}°F ($w->{celsius}°C) and $w->{conditions}", $ref);
    }

  6. #6
    Membre actif
    Homme Profil pro
    Inscrit en
    Juillet 2009
    Messages
    164
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 79
    Localisation : France

    Informations forums :
    Inscription : Juillet 2009
    Messages : 164
    Points : 218
    Points
    218
    Par défaut
    Est-ce que ton script commence au moins par :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    #!/perl/bin/perl -wT
    print "Content-type: text/html\n\n";
    ou encore, si tu utilises le module CGI dans le style fonctionnel :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    #!/perl/bin/perl -wT
    use CGI qw(:standard);
    print header;
    .......
    ... j'ai cette erreur :
    CGI Error
    The specified CGI application misbehaved by not returning a complete set of HTTP headers.

  7. #7
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Août 2009
    Messages
    44
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2009
    Messages : 44
    Points : 31
    Points
    31
    Par défaut
    oui meme quand je met print header ça me sort la même erreur.

  8. #8
    Membre actif
    Homme Profil pro
    Inscrit en
    Juillet 2009
    Messages
    164
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 79
    Localisation : France

    Informations forums :
    Inscription : Juillet 2009
    Messages : 164
    Points : 218
    Points
    218
    Par défaut
    Essaie de mettre
    au lieu de
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    print header('text/plain');
    Cela dit ton code me paraît compliqué, je ne saisis pas la nécessité de placer le dans le block eval.


    Citation Envoyé par anassss Voir le message
    Le code ne marchera pas si vous le lancer car il requiert une authentification .mai voilà un bout de code :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    use strict;
    use warnings;
    use CGI ':standard';
    use JSON::XS 'decode_json', 'encode_json';
    use IO::All;
    use YAML::XS qw/DumpFile LoadFile/;
    use FindBin;
    use Socialtext::Resting::Getopt qw/get_rester/;
    use Weather::Underground;
    use Acme::LOLCAT ();
    use Finance::Quote;
    use Locale::Currency::Format;
    use URI::Escape;
    use DateTime;
    use DateTime::Duration;
    use utf8;
     
    # Use a local YAML file to store state. Make sure
    # this file exists and is writable.
    my $Conf_file = "$FindBin::Bin/sally.yaml";
    my $Config = load_config();
     
    # Use a config file to hold the Socialtext server
    # and username/password details.
    my $rester = get_rester( 'rester-config' => "$FindBin::Bin/.sally-rester");
     
    eval {
        print header('text/plain');
     
        if (my $js = param('json_payload')) {
            my $signals = decode_json($js);
            my $signal = $signals->[0]->{object};
            my $actor = $signals->[0]->{actor};
            my $at = $signals->[0]->{at};
     
            # Map the tags into a hash for ease
            $signal->{tags} = { map {$_ => 1} @{$signal->{tags}}};
     
            # The thread is where our Reply will be sent to.
            # Because we always reply to the incoming message, our replies will
            # be sent to the appropriate context - private or to the group or
            # account they came from.
            $signal->{thread} = $signal->{in_reply_to}{signal_id} || $signal->{id};
     
            my $resp;
            my @annotations;
            my $begin = "^(?:{user: $Config->{our_user_id}}\\s+)?#?";
            my $STOCK_SYMBOL = qr/\b([A-Z]{3,4})\b/;
     
            # Now look at the signal body for opportunities to interact.
     
            if ($signal->{body} =~ m/${begin}(tell|ask)\s+{user: (\d+)}\s+(.+)/i) {
                # Tell or Ask means we will store a message to deliver to a user
                # later.
                my ($verb, $user_id, $msg) = ($1, $2, $3);
                if ($user_id == $Config->{our_user_id}) {
                    $resp = "Uh, thanks {user: $actor->{id}} - I'll, uh, do that.";
                }
                else {
                    push @{ $Config->{tell}{$user_id} }, {
                        from => $actor->{id},
                        at => $at,
                        verb => $verb,
                        message => $msg,
                    };
                    save_config();
                    $resp = "I'll pass that on to {user: $user_id}";
                }
            }
            elsif ($actor->{id} == $Config->{our_user_id}) {
                # Ignore our own messages.
                return;
            }
            elsif ($signal->{body} =~ m/${begin}weather (.+)/i) {
                # Look up the weather and reply with what we found
                my $query = $1;
                ($resp, my $places) = handle_weather($query, \@annotations);
                if ($places) {
                    # Set up some interactions for our weather response.
                    push @annotations, {
                        interactor => { title => "More about \u$query..." }
                    };
                    for (@$places) {
                        my $place = $_->{place};
                        push @annotations, {
                            action => {
                                title => "Map for $place",
                                url => "http://maps.google.com/maps?f=q&z=15&output=embed&q=" . uri_escape($place),
                                target => "frame",
                                width => "100%",
                                height => "400"
                            },
                        };
                        push @annotations, {
                            action => {
                                title => "Search for $place",
                                url => "http://www.google.com/search?q=" . uri_escape($place),
                                target => "blank",
                            },
                        };
                    }
                }
            }
            elsif ($signal->{body} =~ m/${begin}lol:? (.+)/i) {
                # LOLbot repeats the signal using Acme::LOLCAT
                $resp = Acme::LOLCAT::translate($1);
            }
            elsif ($signal->{body} =~ m/${begin}exchange\s+.*?([\d.]*)\s*(\w{3}) (?:to )?(\w{3})/i) {
                # Currency Exchange
                $resp = handle_exchange($1, $2, $3);
            }
            elsif ($signal->{body} =~ m/\b(quote|stock)\b.+$STOCK_SYMBOL/) {
                $resp = '';
                while ($signal->{body} =~ m/$STOCK_SYMBOL/g) {
                    # Look up a stock quote
                    $resp .= handle_stock($1);
                }
            }
            elsif ($signal->{body} =~ m/${begin}math (.+)/i) {
                # Do some math
                $resp = handle_math($1);
            }
            elsif ($signal->{body} =~ m/${begin}seen {user: (\d+)}/i) {
                # Handle requests for the last signal a user sent.
                my $user_id = $1;
                if (my $last = $Config->{last_seen}{$user_id}) {
                    (my $at = $last->{at}) =~ s/(.+)\..+/$1/;
                    $resp = qq(I last saw {user: $user_id} saying '$last->{body}' at "$at"<) . $rester->server . qq($last->{uri}>);
                }
                else {
                    $resp = "Sorry, I haven't seen {user: $user_id}";
                }
            }
            elsif ($signal->{body} =~ m/${begin}poll(?:\s+(.+)|\s*$)/i) {
                # Start a poll
                my ($topic) = ($1);
                $topic ||= '';
     
                push @annotations, {
                    interactor => { title => "Start a poll..." }
                };
     
                # In this case, the poll itself is handled by the hal9000 script.
                push @annotations, {
                    action => {
                        title => "Set Answers",
                        url => "http://borax.socialtext.net/~audreyt/hal9000/poll.cgi/$signal->{signal_id}/start?q="
                             . uri_escape($topic) . ';user=' . $actor->{id}
                             . ';account_ids=' . join(',', @{$signal->{account_ids}||[]})
                             . ';group_ids=' . join(',', @{$signal->{group_ids}||[]})
                             . ';request_uri=' . $ENV{SCRIPT_URI},
                        target => "frame",
                        width => "100%",
                        height => "300"
                    },
                };
     
                $resp = "{user: $actor->{id}} Please click 'Start a poll...' to the right to set the answers."
            }
            elsif ($signal->{body} =~ m/^{user: $Config->{our_user_id}} (?:commands|help)$/) {
                # This is kind of a usage help.
                $resp = help_text();
                push @annotations, detailed_help_annotation();
            }
            elsif ($signal->{tags}{bug}) {
                # If someone mentions the #bug tag, send them the link to our bug
                # reporting form, but only once per thread.
                unless ($Config->{bug_report}{$signal->{thread}}) {
                    $Config->{bug_report}{$signal->{thread}} = 1;
                    $resp = qq{If you've found a bug, please use the "bug reporting form"<https://www2.socialtext.net/bug-report/index.cgi?internal_bug_report>};
                }
            }
            elsif ($signal->{body} =~ /roll ((\d+)d(\d+))/i) {
                my ($arg, $n, $die) = ($1,$2,$3);
                my @rolls;
                push @rolls, int(rand($die))+1 for (1..$n);
                my $sum = 0;
                $sum += $_ for @rolls;
                $resp = "rolled $arg got ".join(', ',@rolls)." for $sum\n";
            }
            elsif ($signal->{body} =~ m/selling days/i) {
                my $days = selling_days_left_in_the_quarter();
                $resp = "There are $days selling days left in the quarter.";
            }
            elsif ($signal->{body} =~ m/^{user: $Config->{our_user_id}} (.+)$/
                or (($signal->{recipient_id}||0) == $Config->{our_user_id})) {
                # For any other kind of mention
                $resp = help_text();
                push @annotations, detailed_help_annotation();
            }
     
            if ($resp) {
                send_signal(
                    $resp,
                    in_reply_to => { signal_id => $signal->{id} },
                    (@annotations ? (annotations => \@annotations) : ()),
                );
            }
     
            # Remember each user's last signal for the seen command.
            $Config->{last_seen}{$actor->{id}} = {
                body => $signal->{body},
                at => $at,
                uri => $signal->{uri},
            };
            save_config();
     
            # Check if there is any messages for the user that just signalled.
            if (my $msgs = $Config->{tell}{$actor->{id}}) {
                for my $msg (@$msgs) {
                    (my $at = $msg->{at}) =~ s/(.+)\..+/$1/;
                    my $verb = $msg->{verb} || 'tell';
                    my $message = "{user: $actor->{id}}: {user: $msg->{from}} said to $verb you $msg->{message} (at $at)";
                    send_signal($message);
                }
                delete $Config->{tell}{$actor->{id}};
                save_config();
            }
        }
        elsif (my $jsp = param('json_post')) {
            # This allows other scripts (like the hal9000 poll bot) to post http to
            # sally, and have sally send a signal.
            my $signal = decode_json($jsp);
            send_signal(delete $signal->{body}, %$signal);
        }
        elsif (param('detailed_help')) {
            print <<'EOT';
     
     
     
     
    You can interact with me in several ways:
     
    I can look up the weather in a given place. Examples:
    weather New York, NY
    weather 90210
    weather SFO
     
    I can exchange currencies:
    exchange USD to GBP
    exchange CAD to USD
    exchange $50 CAD to USD
     
    I will look up any thing that looks like a stock symbol:
    Price of GOOG?
    What is the price of GOOG, AAPL and RIM?
    I'm good at math:
    math 9 * 42
    math ((50000 * 20) * 0.87) - ((50000 * 20) * 0.75)
     
    I can help you poll your peers about some question:
    poll
    poll How far do you live from Florida?
     
    I can translate into LOLcat:
    lol Can I have a cheeseberger?
     
    I can tell you when I last saw a particular user send a signal:
    seen @SomeUser
     
    I can remind someone when they next return to signals:
    tell @SomeUser to read the memo and fill out their TPS reports.
     
    And for you keeners out there, my source code is available here:
    <a href="http://github.com/socialtext/st-clients/blob/master/rest/perl/sally/sally.cgi" target="_blank">http://github.com/socialtext/st-clie...ally/sally.cgi</a>
    EOT
            exit;
        }
    };
    if ($@) {
        # Dump any errors to a temp file.
        DumpFile('/tmp/sally-error', { error => $@ } );
    }
    print "KTHXBYE\n";
     
    exit;
     
     
    sub send_signal {
        my $text = shift;
        my %args = @_;
        $rester->post_signal($text, %args);
    }
     
    sub load_config {
        return LoadFile($Conf_file) if -e $Conf_file and -s _;
     
        # Determine our user_id
        my $me = $rester->get_user($rester->username);
        $Config = {
            our_user_id => $me->{user_id},
        };
        save_config();
        return $Config;
    }
     
    sub save_config {
        DumpFile($Conf_file, $Config);
    }
     
    sub handle_weather {
        my $place = shift;
        my $annos = shift;
        my $weather = Weather::Underground->new(place => $place) or
            die "Can't load weather for $place: $@\n";
        my $ref = $weather->get_weather();
        unless ($ref) {
            push @$annos, detailed_help_annotation();
            return "Sorry, I cannot look up the weather in $place. "
                . "Try: _city, state_ or _zip code_ or _airport_";
        }
     
        my $w = $ref->[0];
        return("In $w->{place} it is $w->{fahrenheit}°F ($w->{celsius}°C) and $w->{conditions}", $ref);
    }

  9. #9
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Août 2009
    Messages
    44
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2009
    Messages : 44
    Points : 31
    Points
    31
    Par défaut
    Meme quand je fais les modifications ça me sort la même erreur, le problème c'est que je suis sur que le code est correct car il m'a été fourni par une source fiable.

  10. #10
    Membre actif
    Homme Profil pro
    Inscrit en
    Juillet 2009
    Messages
    164
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 79
    Localisation : France

    Informations forums :
    Inscription : Juillet 2009
    Messages : 164
    Points : 218
    Points
    218
    Par défaut
    Essaie d'ajouter à ta liste de use la ligne :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    use CGI::Carp qw(warningsToBrowser fatalsToBrowser) ;
    peut-être avant tu obtiendras peut-être plus de précisions sur l'erreur rencontrée.

    Citation Envoyé par anassss Voir le message
    Meme quand je fais les modifications ça me sort la même erreur, le problème c'est que je suis sur que le code est correct car il m'a été fourni par une source fiable.

  11. #11
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Août 2009
    Messages
    44
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2009
    Messages : 44
    Points : 31
    Points
    31
    Par défaut
    effectivement ça me sort une erreur plus precise :

    Software error:

    Can't call method "username" on an undefined value at c:\Inetpub\cgi-bin\sally.cgi line 308.

    For help, please send mail to this site's webmaster, giving this error message and the time and date of the error.


    Voici le bout de code correcpondant

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     my $me = $rester->get_user($rester->username);
    Sachant que $rester a été défini par :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    my $rester = get_rester( 'rester-config' => "$FindBin::Bin/.sally-rester");

  12. #12
    Membre actif
    Homme Profil pro
    Inscrit en
    Juillet 2009
    Messages
    164
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 79
    Localisation : France

    Informations forums :
    Inscription : Juillet 2009
    Messages : 164
    Points : 218
    Points
    218
    Par défaut
    Là, j'avoue que je ne vois pas, username n'est pas défini ? Pourquoi ?
    Quelqu'un de plus calé que moi devrait prendre la relève.

    Citation Envoyé par anassss Voir le message
    effectivement ça me sort une erreur plus precise :

    Software error:

    Can't call method "username" on an undefined value at c:\Inetpub\cgi-bin\sally.cgi line 308.

    For help, please send mail to this site's webmaster, giving this error message and the time and date of the error.


    Voici le bout de code correcpondant

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     my $me = $rester->get_user($rester->username);
    Sachant que $rester a été défini par :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    my $rester = get_rester( 'rester-config' => "$FindBin::Bin/.sally-rester");

  13. #13
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Août 2009
    Messages
    44
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2009
    Messages : 44
    Points : 31
    Points
    31
    Par défaut
    Bonjour

    quelques idées???

  14. #14
    Membre émérite
    Profil pro
    Inscrit en
    Octobre 2008
    Messages
    1 874
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Octobre 2008
    Messages : 1 874
    Points : 2 890
    Points
    2 890
    Par défaut
    Apparemment get_rester() renvoie undef
    Est-ce que vraiment $FindBin::Bin est bien la méthode adaptée en environnement CGI pour trouver l'emplacement de ce fichier de config ".sally-rester"?

  15. #15
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Août 2009
    Messages
    44
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2009
    Messages : 44
    Points : 31
    Points
    31
    Par défaut
    Citation Envoyé par estofilo Voir le message
    Apparemment get_rester() renvoie undef
    Est-ce que vraiment $FindBin::Bin est bien la méthode adaptée en environnement CGI pour trouver l'emplacement de ce fichier de config ".sally-rester"?
    Ah d'accord, est ce qu'il pourrait y avoir une autre méthode dans ce cas ?

  16. #16
    Membre émérite
    Profil pro
    Inscrit en
    Octobre 2008
    Messages
    1 874
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Octobre 2008
    Messages : 1 874
    Points : 2 890
    Points
    2 890
    Par défaut
    Tu pourrais par exemple mettre en dur le chemin où se trouve ce fichier.

  17. #17
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Août 2009
    Messages
    44
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2009
    Messages : 44
    Points : 31
    Points
    31
    Par défaut
    Citation Envoyé par estofilo Voir le message
    Tu pourrais par exemple mettre en dur le chemin où se trouve ce fichier.
    j'ai essayé
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    my $rester = get_rester( 'rester-config' => ".sally-rester.conf");
    J'obtiens toujours la même erreur

  18. #18
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Août 2009
    Messages
    44
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2009
    Messages : 44
    Points : 31
    Points
    31
    Par défaut
    Bonjour c'est toujours moi, je bloque toujours...
    Des propositions de solution??

    Je vous remercie

Discussions similaires

  1. Problème avec un fichier .BAT
    Par jbidou88 dans le forum Autres Logiciels
    Réponses: 2
    Dernier message: 01/05/2006, 13h03
  2. Problème avec un fichier .BAT
    Par jbidou88 dans le forum Autres Logiciels
    Réponses: 2
    Dernier message: 26/04/2006, 14h55
  3. Problème avec des fichiers
    Par Stany dans le forum C++
    Réponses: 7
    Dernier message: 17/10/2005, 16h53
  4. Problème avec les boutons de perl Tk
    Par jkevin2 dans le forum Interfaces Graphiques
    Réponses: 4
    Dernier message: 02/09/2005, 17h18
  5. Problème avec les fichiers .JPG
    Par cprogil dans le forum Langage
    Réponses: 5
    Dernier message: 10/06/2003, 15h44

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo