Sneaky way to post to a socket

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bill Tschumy

    Sneaky way to post to a socket

    First let me state upfront that I'm a Java programmer, not a web developer.
    Consequently I may be flying a bit wild here...

    I have scoured the web and usenet for solutions on how to communicate with a
    stand-a-alone Java application from a web page. Sounds like there is no
    really good browser independent way other than with applets.

    Here is what I am trying to do...

    I want to load a document with two frames. The top frame basically just has
    a button that says something like "Analyze". The bottom frame is initially
    loaded up with some web page. The user may browse around via links in the
    bottom frame and go to arbitrary web pages which will be loaded in the bottom
    frame.

    When the user clicks the "Analyze" button, I want to send the URL in the
    bottom frame to my Java application for analysis. Both the application and
    the web browser are on the same machine. The analysis is really displayed in
    the application, so no real results need be displayed in the browser.

    I was thinking about using a form post to post to my application (listening
    on a special port). I would use a "hidden" form element to send the url for
    analysis. This seems to be pretty much working for me. Here is the form
    code:

    <form action="http://127.0.0.1:7333/results.html" method="post">
    <input type="submit" name="foo" value="Analyze Page">
    <input type="hidden" name="url_to_pa rse" value="someurl" >
    </form>

    So I'm posting to the loopback address on port 7333 where my Java app is
    listening. The Java app does get data on the port and reads it and generates
    some returned text that does get displayed.

    My questions:
    1. Is there anything fundamentally wrong with doing this this way?

    2. Ideally I'd like the post to not change the web browser display, but if I
    don't return something the browser says "The page contained no data". Any
    way around this?

    3. I seem to need to have the form action post to a (bogus) .html file.
    Otherwise the browser thinks it needs to download the result as a file. Is
    there a better way to handle this?

    4. Eventually, I need to build the page that has the forms and I need to
    on-the-fly replace the "someurl" with the url loaded in the bottom frame. I
    assume I need javascript to do this. Anyone want to post a code snippet to
    do what I need (I really know very little about javascript).

    Thanks so much for any help or suggestions.



    --
    Bill Tschumy
    Otherwise -- Austin, TX
    Otherwise, Galaxy, Galactic Atlas, Galactic Map, Astronomy, Telescope, Deep Sky


  • Jim Ley

    #2
    Re: Sneaky way to post to a socket

    On Thu, 29 Apr 2004 17:15:04 GMT, Bill Tschumy
    <bill@otherwise DELETE.com> wrote:[color=blue]
    >My questions:
    >1. Is there anything fundamentally wrong with doing this this way?[/color]

    Nope, security makes it difficult.
    [color=blue]
    >2. Ideally I'd like the post to not change the web browser display, but if I
    >don't return something the browser says "The page contained no data". Any
    >way around this?[/color]

    return a 204 No Content from your Java App.
    [color=blue]
    >4. Eventually, I need to build the page that has the forms and I need to
    >on-the-fly replace the "someurl" with the url loaded in the bottom frame. I
    >assume I need javascript to do this. Anyone want to post a code snippet to
    >do what I need (I really know very little about javascript).[/color]

    Securirty will stuff you.

    onclick="this.f orm.elements['url']=parent.frames[1].location" in the
    submit button, but unless you get some security modifications to the
    browser to allow that cross domain scripting it isn't going to work.

    Jim.
    --
    comp.lang.javas cript FAQ - http://jibbering.com/faq/

    Comment

    • Dag Sunde

      #3
      Re: Sneaky way to post to a socket

      "Bill Tschumy" <bill@otherwise DELETE.com> wrote in message
      news:sKakc.2306 5$SA7.13586@new ssvr22.news.pro digy.com...[color=blue]
      > First let me state upfront that I'm a Java programmer, not a web[/color]
      developer.[color=blue]
      > Consequently I may be flying a bit wild here...
      >
      > I have scoured the web and usenet for solutions on how to communicate with[/color]
      a[color=blue]
      > stand-a-alone Java application from a web page. Sounds like there is no
      > really good browser independent way other than with applets.
      >
      > Here is what I am trying to do...
      >[/color]

      I really think a hidden applet in your top frame is the way to go.

      The Applet must have allowscripting = true, and a public method that
      accepts a string.

      Then from your analyze button, you call the applets public method with
      the bottom frames URL as a parameter from JavaScript.

      As you are primarely a java programmer, you already know how to send
      your data from the applet to your java-application on your server.

      [color=blue]
      > I want to load a document with two frames. The top frame basically just[/color]
      has[color=blue]
      > a button that says something like "Analyze". The bottom frame is[/color]
      initially[color=blue]
      > loaded up with some web page. The user may browse around via links in the
      > bottom frame and go to arbitrary web pages which will be loaded in the[/color]
      bottom[color=blue]
      > frame.
      >
      > When the user clicks the "Analyze" button, I want to send the URL in the
      > bottom frame to my Java application for analysis. Both the application and
      > the web browser are on the same machine. The analysis is really displayed[/color]
      in[color=blue]
      > the application, so no real results need be displayed in the browser.
      >
      > I was thinking about using a form post to post to my application[/color]
      (listening[color=blue]
      > on a special port). I would use a "hidden" form element to send the url[/color]
      for[color=blue]
      > analysis. This seems to be pretty much working for me. Here is the form[/color]

      <snipped />

      /Dag.


      Comment

      • Bill Tschumy

        #4
        Re: Sneaky way to post to a socket

        On Thu, 29 Apr 2004 15:23:14 -0500, Dag Sunde wrote (in article
        <Sudkc.81121$BD 3.9736221@julie tt.dax.net>):
        [color=blue]
        > "Bill Tschumy" <bill@otherwise DELETE.com> wrote in message
        > news:sKakc.2306 5$SA7.13586@new ssvr22.news.pro digy.com...[color=green]
        >> First let me state upfront that I'm a Java programmer, not a web[/color]
        > developer.[color=green]
        >> Consequently I may be flying a bit wild here...
        >>
        >> I have scoured the web and usenet for solutions on how to communicate with[/color]
        > a[color=green]
        >> stand-a-alone Java application from a web page. Sounds like there is no
        >> really good browser independent way other than with applets.
        >>
        >> Here is what I am trying to do...
        >>[/color]
        >
        > I really think a hidden applet in your top frame is the way to go.[/color]

        How do you hid the applet. Does it just have zero width and height?
        [color=blue]
        >
        > The Applet must have allowscripting = true, and a public method that
        > accepts a string.[/color]

        I'm not familiar with any allowscripting property. Is this something in the
        applet tag?
        [color=blue]
        >
        > Then from your analyze button, you call the applets public method with the
        > bottom frames URL as a parameter from JavaScript.[/color]

        Can you give me an example of how to do this? I'm really not a javascript
        person.
        [color=blue]
        >
        > As you are primarely a java programmer, you already know how to send your
        > data from the applet to your java-application on your server.[/color]

        Yes, I can handle this part.

        Thanks for your help.
        [color=blue]
        >
        >[color=green]
        >> I want to load a document with two frames. The top frame basically just[/color]
        > has[color=green]
        >> a button that says something like "Analyze". The bottom frame is[/color]
        > initially[color=green]
        >> loaded up with some web page. The user may browse around via links in the
        >> bottom frame and go to arbitrary web pages which will be loaded in the[/color]
        > bottom[color=green]
        >> frame.
        >>
        >> When the user clicks the "Analyze" button, I want to send the URL in the
        >> bottom frame to my Java application for analysis. Both the application and
        >> the web browser are on the same machine. The analysis is really displayed[/color]
        > in[color=green]
        >> the application, so no real results need be displayed in the browser.
        >>
        >> I was thinking about using a form post to post to my application[/color]
        > (listening[color=green]
        >> on a special port). I would use a "hidden" form element to send the url[/color]
        > for[color=green]
        >> analysis. This seems to be pretty much working for me. Here is the form[/color]
        >
        > <snipped />
        >
        > /Dag.
        >
        >[/color]



        --
        Bill Tschumy
        Otherwise -- Austin, TX
        Otherwise, Galaxy, Galactic Atlas, Galactic Map, Astronomy, Telescope, Deep Sky


        Comment

        • Bill Tschumy

          #5
          Re: Sneaky way to post to a socket

          On Thu, 29 Apr 2004 14:45:02 -0500, Jim Ley wrote
          (in article <40915abd.33903 5747@news.indiv idual.net>):
          [color=blue]
          > On Thu, 29 Apr 2004 17:15:04 GMT, Bill Tschumy
          > <bill@otherwise DELETE.com> wrote:[color=green]
          >> My questions:
          >> 1. Is there anything fundamentally wrong with doing this this way?[/color]
          >
          > Nope, security makes it difficult.
          >[color=green]
          >> 2. Ideally I'd like the post to not change the web browser display, but if
          >> I
          >> don't return something the browser says "The page contained no data". Any
          >> way around this?[/color]
          >
          > return a 204 No Content from your Java App.
          >[color=green]
          >> 4. Eventually, I need to build the page that has the forms and I need to
          >> on-the-fly replace the "someurl" with the url loaded in the bottom frame.
          >> I
          >> assume I need javascript to do this. Anyone want to post a code snippet
          >> to
          >> do what I need (I really know very little about javascript).[/color]
          >
          > Securirty will stuff you.
          >
          > onclick="this.f orm.elements['url']=parent.frames[1].location" in the
          > submit button, but unless you get some security modifications to the
          > browser to allow that cross domain scripting it isn't going to work.[/color]

          I feel I am really close on getting this to work. How is this cross domain?
          Everything is happening on the local machine. Is this the same as:

          onclick="this.m yform.url.value =parent.main.lo cation.href"

          if the form is defined as:

          <form name=myform action="http://127.0.0.1:7333/results.html" method="post">
          <input type="submit" name="foo" value="Download source on page" >
          <input type="hidden" name="url" value="ffff">
          </form>

          Does the onclick go in the submit button's input tag?
          [color=blue]
          >
          > Jim.
          >[/color]



          --
          Bill Tschumy
          Otherwise -- Austin, TX
          Otherwise, Galaxy, Galactic Atlas, Galactic Map, Astronomy, Telescope, Deep Sky


          Comment

          • Dag Sunde

            #6
            Re: Sneaky way to post to a socket


            "Bill Tschumy" <bill@otherwise DELETE.com> wrote in message
            news:Vyekc.2313 2$Uz3.20795@new ssvr22.news.pro digy.com...[color=blue]
            > On Thu, 29 Apr 2004 15:23:14 -0500, Dag Sunde wrote (in article
            > <Sudkc.81121$BD 3.9736221@julie tt.dax.net>):
            >[color=green]
            > > "Bill Tschumy" <bill@otherwise DELETE.com> wrote in message
            > > news:sKakc.2306 5$SA7.13586@new ssvr22.news.pro digy.com...[color=darkred]
            > >> First let me state upfront that I'm a Java programmer, not a web
            > >> developer. Consequently I may be flying a bit wild here...[/color][/color][/color]
            ....[color=blue][color=green]
            > > I really think a hidden applet in your top frame is the way to go.[/color]
            >
            > How do you hid the applet. Does it just have zero width and height?
            >[/color]

            Yes
            [color=blue][color=green]
            > >
            > > The Applet must have allowscripting = true, and a public method that
            > > accepts a string.[/color]
            >
            > I'm not familiar with any allowscripting property. Is this something in[/color]
            the[color=blue]
            > applet tag?[/color]

            Yes, it's in the applet tag, and its proper name is "mayscript='tru e'".
            [color=blue]
            >[color=green]
            > >
            > > Then from your analyze button, you call the applets public method with[/color][/color]
            the[color=blue][color=green]
            > > bottom frames URL as a parameter from JavaScript.[/color]
            >
            > Can you give me an example of how to do this? I'm really not a javascript
            > person.[/color]

            <script type="text/javascript">

            function invokeDispatche r()
            {
            var javaApplet;
            if (typeof document.getEle mentById('Dispa tcherApplet').a nalyzeUrl !=
            'undefined')
            javaApplet = document.getEle mentById('Dispa tcherApplet');
            else
            return false;

            var url = window.top.fram es['mainFrame'].location.href;
            javaApplet.anal yzeUrl(url);
            return true;
            }

            </script>
            ....
            <applet
            codebase = "."
            code = "com.dagsunde.d ispatcher.Dispa tcher.class"
            id = "DispatcherAppl et"
            name = "DispatcherAppl et"
            width = "5"
            height = "5"
            hspace = "0"
            vspace = "0"
            align = "left"
            mayscript="true "[color=blue]
            >[/color]
            </applet>
            <input id="analyzeButt on"
            type="button"
            value="Analyze"
            onClick="invoke Dispatcher();" />
            [color=blue]
            >[color=green]
            > >
            > > As you are primarely a java programmer, you already know how to send[/color][/color]
            your[color=blue][color=green]
            > > data from the applet to your java-application on your server.[/color]
            >
            > Yes, I can handle this part.[/color]

            BUT! Jim Ley is of course right. JS security stops you when the content in
            the frame you're trying to analyze origins from a different domain than the
            frame with the script is in.

            the line:
            var url = window.top.fram es['mainFrame'].location.href;

            from the script above works fine as long as "mainFrame" contains a document
            from
            the same server, but gives a "Permission denied" if it is ie. from
            google.com

            You *might* be able to work around this by digitally signing your script
            with a
            code signing certificate from Thawte or Verisign... (Costs US$400.- a year)

            I'll try it later, and inform you...

            --
            Dag.



            Comment

            • Razzbar

              #7
              Re: Sneaky way to post to a socket

              Bill Tschumy <bill@otherwise DELETE.com> wrote in message news:<9Fekc.231 37$Uz3.2725@new ssvr22.news.pro digy.com>...
              [color=blue]
              > I feel I am really close on getting this to work. How is this cross domain?
              > Everything is happening on the local machine. Is this the same as:[/color]

              Doing it across domains will slam you into the "same origination
              policy" I was writing an app that would let people surf in one
              window, and bookmark pages in another. But could not even read
              the URL of a page that came from a different domain.

              Sorry to rain on your parade. The obvious workaround is to have
              the user copy and paste the url... but if the page is in a
              different frame... you can't always see the url. But you could
              use two windows... One where the page to be analyzed is, and
              the other where your app is. Copy and paste from one window
              to the other. I hated having to do it that way, but got over
              it when the app started taking shape.


              [color=blue]
              > onclick="this.m yform.url.value =parent.main.lo cation.href"
              >
              > if the form is defined as:
              >
              > <form name=myform action="http://127.0.0.1:7333/results.html" method="post">
              > <input type="submit" name="foo" value="Download source on page" >
              > <input type="hidden" name="url" value="ffff">
              > </form>
              >
              > Does the onclick go in the submit button's input tag?[/color]

              I'd not use a type=submit, but rather a type=button, and in
              that tag, do "onclick=myfunc tion()". The myfunction() function
              would validate and submit the form. But that's just my style,
              because when you hit 'enter' in any field on a form, it
              immediately fires the submit button. So I use a button type
              button, then validate, then submit the form.

              Comment

              • Bill Tschumy

                #8
                Re: Sneaky way to post to a socket

                On Thu, 29 Apr 2004 20:48:43 -0500, Razzbar wrote
                (in article <c48470fc.04042 91748.d753634@p osting.google.c om>):
                [color=blue]
                > Bill Tschumy <bill@otherwise DELETE.com> wrote in message
                > news:<9Fekc.231 37$Uz3.2725@new ssvr22.news.pro digy.com>...
                >[color=green]
                >> I feel I am really close on getting this to work. How is this cross
                >> domain?
                >> Everything is happening on the local machine. Is this the same as:[/color]
                >
                > Doing it across domains will slam you into the "same origination
                > policy" I was writing an app that would let people surf in one
                > window, and bookmark pages in another. But could not even read
                > the URL of a page that came from a different domain.
                >
                > Sorry to rain on your parade. The obvious workaround is to have
                > the user copy and paste the url... but if the page is in a
                > different frame... you can't always see the url. But you could
                > use two windows... One where the page to be analyzed is, and
                > the other where your app is. Copy and paste from one window
                > to the other. I hated having to do it that way, but got over
                > it when the app started taking shape.[/color]

                I appreciate everyone taking time to explain the issues to me. I think I'll
                adopt a totally different approach to this.



                --
                Bill Tschumy
                Otherwise -- Austin, TX
                Otherwise, Galaxy, Galactic Atlas, Galactic Map, Astronomy, Telescope, Deep Sky


                Comment

                • Guest's Avatar

                  #9
                  Re: Sneaky way to post to a socket

                  "Razzbar" <glakk@potatora dio.f2s.com> wrote in message
                  news:c48470fc.0 404291748.d7536 34@posting.goog le.com...[color=blue]
                  > Bill Tschumy <bill@otherwise DELETE.com> wrote in message
                  > news:<9Fekc.231 37$Uz3.2725@new ssvr22.news.pro digy.com>...
                  >[color=green]
                  >> I feel I am really close on getting this to work. How is this cross
                  >> domain?
                  >> Everything is happening on the local machine. Is this the same as:[/color]
                  >
                  > Doing it across domains will slam you into the "same origination
                  > policy" I was writing an app that would let people surf in one
                  > window, and bookmark pages in another. But could not even read
                  > the URL of a page that came from a different domain.
                  >
                  > Sorry to rain on your parade. The obvious workaround is to have
                  > the user copy and paste the url... but if the page is in a
                  > different frame... you can't always see the url. But you could
                  > use two windows... One where the page to be analyzed is, and
                  > the other where your app is. Copy and paste from one window
                  > to the other. I hated having to do it that way, but got over
                  > it when the app started taking shape.
                  >
                  >
                  >[color=green]
                  >> onclick="this.m yform.url.value =parent.main.lo cation.href"
                  >>
                  >> if the form is defined as:
                  >>
                  >> <form name=myform action="http://127.0.0.1:7333/results.html"
                  >> method="post">
                  >> <input type="submit" name="foo" value="Download source on page" >
                  >> <input type="hidden" name="url" value="ffff">
                  >> </form>
                  >>
                  >> Does the onclick go in the submit button's input tag?[/color]
                  >
                  > I'd not use a type=submit, but rather a type=button, and in
                  > that tag, do "onclick=myfunc tion()". The myfunction() function
                  > would validate and submit the form. But that's just my style,
                  > because when you hit 'enter' in any field on a form, it
                  > immediately fires the submit button. So I use a button type
                  > button, then validate, then submit the form.[/color]

                  couldn't you write a short php script to get the requested info from the
                  domain instead...then it would be comming from your domain right?


                  Comment

                  Working...