CGI / postprocess of values

Discussion in 'Perl Misc' started by cwpbl, Jan 8, 2013.

  1. cwpbl

    cwpbl Guest

    Hello,

    I have a very simple test.cgi program, using CGI.pm wich display a
    textfield.
    After the form has been submitted, I have a new url, saying :
    http://host/cgi-bin/test.cgi?my_textfield_content=azertyu

    OK.
    Now, I want the value of my_textfield_content appear as an encoded
    string, in the url, something like
    http://host/cgi-bin/test.cgi?my_textfield_content=VgHo98km==

    I have already written the (de)(en)coding function.
    But how can I call this encoding function to have value of
    my_text_field_content modified ?
    cwpbl, Jan 8, 2013
    #1
    1. Advertising

  2. cwpbl

    cwpbl Guest

    Le 08/01/2013 23:24, Ben Morrow a écrit :
    >
    > Quoth cwpbl <>:
    >>
    >> I have a very simple test.cgi program, using CGI.pm wich display a
    >> textfield.
    >> After the form has been submitted, I have a new url, saying :
    >> http://host/cgi-bin/test.cgi?my_textfield_content=azertyu
    >>
    >> OK.
    >> Now, I want the value of my_textfield_content appear as an encoded
    >> string, in the url, something like
    >> http://host/cgi-bin/test.cgi?my_textfield_content=VgHo98km==

    >
    > Why?
    >
    > (This is not a stupid question. What are you trying to do that makes you
    > think you need this?)


    1. I need a url which does not contains some characters (like |) because
    these url , entered in a wiki (dokuwiki), are not interpreted correctly.
    2. url are send to some users. I do not want they modify these url (easy
    to do if in clear).

    >
    >> I have already written the (de)(en)coding function.

    >
    > I hope you mean 'I have already found MIME::Base64, and I know how to
    > use it'.
    >

    I use 8bits -> 7bits + encode_base64.

    sub cps {
    my $bstr = unpack('B*', $_[0]);
    $bstr =~ s/.(.{7})/$1/g;
    return pack('B*', $bstr);
    }

    sub ec{
    return encode_base64(cps($_[0]),"");
    }

    The problem is : where call ec ?

    > Ben
    >
    cwpbl, Jan 9, 2013
    #2
    1. Advertising

  3. cwpbl

    Justin C Guest

    On 2013-01-09, cwpbl <> wrote:
    > Le 08/01/2013 23:24, Ben Morrow a écrit :
    >>
    >> Quoth cwpbl <>:
    >>>
    >>> I have a very simple test.cgi program, using CGI.pm wich display a
    >>> textfield.
    >>> After the form has been submitted, I have a new url, saying :
    >>> http://host/cgi-bin/test.cgi?my_textfield_content=azertyu
    >>>
    >>> OK.
    >>> Now, I want the value of my_textfield_content appear as an encoded
    >>> string, in the url, something like
    >>> http://host/cgi-bin/test.cgi?my_textfield_content=VgHo98km==

    >>
    >> Why?
    >>
    >> (This is not a stupid question. What are you trying to do that makes you
    >> think you need this?)

    >
    > 1. I need a url which does not contains some characters (like |) because
    > these url , entered in a wiki (dokuwiki), are not interpreted correctly.


    I think you have two options. You receive whatever characters the user
    wants to submit, and then you tidy the information how you want when
    you receive it, or you write some javascript that does the change when
    the user clicks submit, the script does the submit after doing the
    changes to the string - the problem with this is that any user with
    half a clue will see what your code does and, if they so desire will
    still find a way of submitting what they want.


    > 2. url are send to some users. I do not want they modify these url (easy
    > to do if in clear).


    Security through obscurity is no security at all.
    <URL:http://en.wikipedia.org/wiki/Security_through_obscurity>


    >>> I have already written the (de)(en)coding function.

    >>
    >> I hope you mean 'I have already found MIME::Base64, and I know how to
    >> use it'.
    >>

    > I use 8bits -> 7bits + encode_base64.
    >
    > sub cps {
    > my $bstr = unpack('B*', $_[0]);
    > $bstr =~ s/.(.{7})/$1/g;
    > return pack('B*', $bstr);
    > }
    >
    > sub ec{
    > return encode_base64(cps($_[0]),"");
    > }
    >
    > The problem is : where call ec ?


    Call it when you receive the form back from the user.


    Justin.

    --
    Justin C, by the sea.
    Justin C, Jan 9, 2013
    #3
  4. cwpbl

    cwpbl Guest

    Le 08/01/2013 22:40, Henry Law a écrit :
    > On 08/01/13 19:58, cwpbl wrote:
    >> After the form has been submitted, I have a new url, saying :
    >> http://host/cgi-bin/test.cgi?my_textfield_content=azertyu

    >
    > This is intrinsically what the "submit" function does; it sends to the
    > server program the value of the field in the form.
    >
    >> Now, I want the value of my_textfield_content appear as an encoded
    >> string, in the url, something like
    >> http://host/cgi-bin/test.cgi?my_textfield_content=VgHo98km==

    >
    > Unless you write some local code (javascript or whatever) to encode the
    > contents of "textfield" /before/ submission then it will be sent off
    > unencoded.
    >
    > I think I have understood your question. But it would be better if you
    > post test.cgi, so we can see what you're doing.
    >

    Thank you,
    here are the interesting parts of the script :

    use CGI;
    ....
    my $filter = $q->param('filter') || ".";
    ....
    sub cps {
    my $bstr = unpack('B*', $_[0]);
    $bstr =~ s/.(.{7})/$1/g;
    return pack('B*', $bstr);
    }

    sub ec{
    return encode_base64(cps($_[0]),"");
    }
    ....
    my $q = new CGI;
    print
    $q->header( "text/html" ),
    $q->start_html( ... );
    ....
    print
    $q->start_form(-action=>"", -method=>'GET', name=>'filter_form' ),
    $q->textfield(-name=>'filter',-default=>"", -size=>20),
    $q->submit(-name=> "filter_btn", -value=>"OK"),
    $q->end_form();
    [...]
    print
    $q->table( ... ),
    $q->end_html();


    I want to have the value of filter param modified ( with ec funtion) in
    the new url. How "insert" this processing in the script ?
    cwpbl, Jan 9, 2013
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jürgen Exner

    Re: CGI Perl "use CGI" statement fail

    Jürgen Exner, Jul 31, 2003, in forum: Perl
    Replies:
    0
    Views:
    1,275
    Jürgen Exner
    Jul 31, 2003
  2. Shailan
    Replies:
    2
    Views:
    917
    Shailan
    Dec 15, 2003
  3. John Smith
    Replies:
    0
    Views:
    3,029
    John Smith
    May 15, 2006
  4. LarsenMTL
    Replies:
    4
    Views:
    687
    Eric Walstad
    Nov 4, 2004
  5. praba kar

    Python-cgi or Perl-cgi script doubt

    praba kar, Jul 30, 2005, in forum: Python
    Replies:
    1
    Views:
    546
    Michael Sparks
    Jul 30, 2005
Loading...

Share This Page