Announcement

Collapse
No announcement yet.

Nerdy tips: Starting VNC/RDP from a hyperlink

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Nerdy tips: Starting VNC/RDP from a hyperlink

    This is something that I've looked into and sorted recently, and I feel like sharing today

    If you manage a network, and have a web-based ticket or computer management system, it could be very handy to be able to start an RDP or VNC session using a hyperlink.

    There are 2 approaches that I have found:

    1) Create a new protocol handler for rdp:// or vnc://
    2) Create .rdp and .vnc files on the fly

    I've opted to go with solution 2, as #1 requires software installation on local computers to work, whereas #2 only requires a webserver with php set up (and it wouldn't be too difficult to translate to ASP/perl/or any other CGI language.

    rdp.php:
    PHP Code:
    <?php
    $file 
    'rdpconnect.txt';

    if(!
    file_exists($file))
    {
       
    // File doesn't exist, output error
       
    die('file not found');
    }
    else
    {
       if(isset(
    $_GET) && array_key_exists("srv"$_GET) && preg_match("/^[A-Za-z0-9\.-][A-Za-z0-9\.-][A-Za-z0-9\.-]+$/i",$_GET["srv"]))
       {
          
    $rdp_file file_get_contents($file);
          
    // Set headers
          
    header("Cache-Control: public");
          
    header("Content-Description: File Transfer");
          
    header("Content-Disposition: attachment; filename=" $_GET["srv"] . ".rdp");
          
    header("Content-Type: text/plain");
          
    header("Content-Transfer-Encoding: 8bit");

          echo 
    str_ireplace("{SERVER_ADDRESS}"$_GET["srv"], $rdp_file);
       }
       else
          die(
    "You must specify a valid server name");
    }
    ?>
    rdpconnect.txt:
    Code:
    screen mode id:i:2
    desktopwidth:i:1280
    desktopheight:i:1024
    session bpp:i:16
    winposstr:s:0,1,305,203,1105,803
    compression:i:1
    keyboardhook:i:2
    displayconnectionbar:i:1
    disable wallpaper:i:0
    disable full window drag:i:0
    allow desktop composition:i:1
    allow font smoothing:i:1
    disable menu anims:i:0
    disable themes:i:0
    disable cursor setting:i:0
    bitmapcachepersistenable:i:1
    full address:s:{SERVER_ADDRESS}
    audiomode:i:0
    redirectprinters:i:1
    redirectcomports:i:0
    redirectsmartcards:i:1
    redirectclipboard:i:1
    redirectposdevices:i:0
    autoreconnection enabled:i:1
    authentication level:i:0
    prompt for credentials:i:0
    negotiate security layer:i:1
    remoteapplicationmode:i:0
    alternate shell:s:
    shell working directory:s:
    gatewayhostname:s:
    gatewayusagemethod:i:4
    gatewaycredentialssource:i:4
    gatewayprofileusagemethod:i:0
    promptcredentialonce:i:1
    devicestoredirect:s:*
    drivestoredirect:s:*
    vnc.php:
    PHP Code:
    <?php
    $file 
    'vncconnect.txt';

    if(!
    file_exists($file))
    {
       
    // File doesn't exist, output error
       
    die('file not found');
    }
    else
    {
       if(isset(
    $_GET) && array_key_exists("srv"$_GET) && preg_match("/^[A-Za-z0-9\.-][A-Za-z0-9\.-][A-Za-z0-9\.-]+$/i",$_GET["srv"]))
       {
          
    $rdp_file file_get_contents($file);
          
    // Set headers
          
    header("Cache-Control: public");
          
    header("Content-Description: File Transfer");
          
    header("Content-Disposition: attachment; filename=" $_GET["srv"] . ".vnc");
          
    header("Content-Type: text/plain");
          
    header("Content-Transfer-Encoding: 8bit");

          echo 
    str_ireplace("{SERVER_ADDRESS}"$_GET["srv"], $rdp_file);
       }
       else
          die(
    "You must specify a valid server name");
    }
    ?>
    vncconnect.txt
    Code:
    [connection]
    host={SERVER_ADDRESS}
    port=5900
    [options]
    use_encoding_0=1
    use_encoding_1=1
    use_encoding_2=1
    use_encoding_3=0
    use_encoding_4=1
    use_encoding_5=1
    use_encoding_6=0
    use_encoding_7=0
    use_encoding_8=0
    use_encoding_9=0
    use_encoding_10=0
    use_encoding_11=0
    use_encoding_12=0
    use_encoding_13=0
    use_encoding_14=0
    use_encoding_15=0
    use_encoding_16=1
    preferred_encoding=5
    restricted=0
    viewonly=0
    fullscreen=0
    autoDetect=1
    8bit=0
    shared=1
    swapmouse=0
    belldeiconify=0
    emulate3=1
    emulate3timeout=100
    emulate3fuzz=4
    disableclipboard=0
    localcursor=1
    scale_num=1
    scale_den=1
    To call, simply link to rdp.php?srv=<computer name> or vnc.php?srv=<computer name>.

    Examples:
    HTML Code:
    <a href="http://webserver/rdp.php?srv=webserver">RDP to webserver</a>
    <a href="http://webserver/vnc.php?srv=webserver">VNC to webserver</a>
    The scripts will initiate a download of a .rdp or .vnc file. Simply click "Open/Run" to open the connection.
    '====
    //`
    -Magilla
    They observe my perambulations upon my gyroscopically-balanced personal transportation device, and I perceive at my core that they have thus concluded that I am Caucasian, and, while intelligent, I am also somewhat socially inept. - Peculiar Alfred
    Eligible to shadow R & R-E NOW

  • #2
    Wow, nice one Hoss. I've got a use for that.
    Work Buy Consume Die

    Comment


    • #3
      No worries. People in network management usually have a use for this kind of thing
      '====
      //`
      -Magilla
      They observe my perambulations upon my gyroscopically-balanced personal transportation device, and I perceive at my core that they have thus concluded that I am Caucasian, and, while intelligent, I am also somewhat socially inept. - Peculiar Alfred
      Eligible to shadow R & R-E NOW

      Comment


      • #4
        I can set up hyperlinks to stuff so dweebs don't keep asking "how to I connect to the server again?"
        Work Buy Consume Die

        Comment


        • #5
          Nice.

          I created a web-based system for managing customised logs, software and hardware audit information with AD browsing - I use these RDP/VNC scripts so that when you are viewing the logs from a computer, remote connection to follow up on an issue is only one click away.

          I'm not good at pretty, but I'm effin' awesome at functional.
          Last edited by Magilla; 12-09-2011, 06:35 AM.
          '====
          //`
          -Magilla
          They observe my perambulations upon my gyroscopically-balanced personal transportation device, and I perceive at my core that they have thus concluded that I am Caucasian, and, while intelligent, I am also somewhat socially inept. - Peculiar Alfred
          Eligible to shadow R & R-E NOW

          Comment


          • #6
            Hey, Magilla I was playing with your php script and noticed that in firefox when trying to run the VNC file that it would not open properly. some vnc error, but i figured out what the problem was. First I did my usual troubleshooting, trying different browsers. I tried it in IE and it worked perfectly for some reason. Then I started to look at the code and figured out where it says "header("Content-Type: text/plain");". In firefox this tells it to save as a .txt. so i changed it to read "header("Content-Type: application/vnc");" and now the script works flawlessly on firefox. Thanks for this great script, it will help me greatly.

            Comment


            • #7
              Glad it helped you, mate.
              '====
              //`
              -Magilla
              They observe my perambulations upon my gyroscopically-balanced personal transportation device, and I perceive at my core that they have thus concluded that I am Caucasian, and, while intelligent, I am also somewhat socially inept. - Peculiar Alfred
              Eligible to shadow R & R-E NOW

              Comment


              • #8
                Excellent method!

                But, how do I use it?

                I'm not familar with these languages. I jsut want to add a hyperlink on my web site to start the RDP. To be specific, a sharepoint web site, I don't even know which language it used, php or ASP or some others?

                Where should I put these code so it will work?

                It would be very appreciate if any one could help me out.

                Thanks in advance.

                Comment


                • #9
                  How do you know if it's an excellent method if you can't make it work?



                  I have no idea how SharePoint works, so that can be your little project to find out

                  Is it only one computer that you need to get people to, or lots?
                  '====
                  //`
                  -Magilla
                  They observe my perambulations upon my gyroscopically-balanced personal transportation device, and I perceive at my core that they have thus concluded that I am Caucasian, and, while intelligent, I am also somewhat socially inept. - Peculiar Alfred
                  Eligible to shadow R & R-E NOW

                  Comment


                  • #10
                    oh no... :pinch:
                    Still not know how to use your code...

                    To answer your question, I need to allow many computers to visit the SharePoint site and click the RDP link. And that's why I need it...

                    On my test environment, I upload the .rdp file to the SharePoint site, and create a link to the file. It almostly worked as expected. [That means: it will allow me to download the .rdp file, and then open/run it, so I can start the Remote Desktop through 2 click, which is still acceptable.]

                    The bad news is, on my working place, I did the same thing, but it will not allow me to download the file, it directly open the file with IE, and it opened as text content. So I couldn't start the Remote Desktop at all. Since the SharePoint site in my working place are host by the other guy, there might be some settings differ with mine I need to find out.

                    Comment


                    • #11
                      Originally posted by Max Meng View Post
                      oh no... :pinch:
                      Still not know how to use your code...

                      To answer your question, I need to allow many computers to visit the SharePoint site and click the RDP link. And that's why I need it...

                      On my test environment, I upload the .rdp file to the SharePoint site, and create a link to the file. It almostly worked as expected. [That means: it will allow me to download the .rdp file, and then open/run it, so I can start the Remote Desktop through 2 click, which is still acceptable.]

                      The bad news is, on my working place, I did the same thing, but it will not allow me to download the file, it directly open the file with IE, and it opened as text content. So I couldn't start the Remote Desktop at all. Since the SharePoint site in my working place are host by the other guy, there might be some settings differ with mine I need to find out.
                      I don't think you've really picked up what magillas php code is actually doing. If you just want to provide people with a link on a webpage hosted by sharepoint to an .rdp file that they click open on, and it establishes a remote desktop session to a server, you don't need to worry about php or asp or anything like that. You can just upload the .rdp files somewhere within the wwwroot folder, make sure they all have read permissions for everyone, and link the file on your web page. Magilla has created a server run piece of code that generates files for many many different "servers". It doesn't sound like in your environment you need that, and I'm sorry to make assumptions, but it doesn't sound like you have the skills at present to emulate what magilla is doing.

                      I did however forget about this thread, and also have uses for the code you've published. I'll be looking into what I can do with it very soon :o

                      Comment


                      • #12
                        Originally posted by Max Meng View Post
                        oh no... :pinch:
                        Still not know how to use your code...

                        To answer your question, I need to allow many computers to visit the SharePoint site and click the RDP link. And that's why I need it...
                        You have, in fact, not answered my question at all. I asked how many servers people will be connecting to, not how many clients need to connect.

                        Originally posted by Max Meng View Post
                        On my test environment, I upload the .rdp file to the SharePoint site, and create a link to the file. It almostly worked as expected. [That means: it will allow me to download the .rdp file, and then open/run it, so I can start the Remote Desktop through 2 click, which is still acceptable.]

                        The bad news is, on my working place, I did the same thing, but it will not allow me to download the file, it directly open the file with IE, and it opened as text content. So I couldn't start the Remote Desktop at all. Since the SharePoint site in my working place are host by the other guy, there might be some settings differ with mine I need to find out.
                        I have no idea why it does that. I don't use sharepoint.

                        Lee: awesome.
                        '====
                        //`
                        -Magilla
                        They observe my perambulations upon my gyroscopically-balanced personal transportation device, and I perceive at my core that they have thus concluded that I am Caucasian, and, while intelligent, I am also somewhat socially inept. - Peculiar Alfred
                        Eligible to shadow R & R-E NOW

                        Comment


                        • #13
                          Can I have ur code for your little asset management system you have there?

                          No seriously, curious how you do a few things. How are you grabbing which software is installed on the machines? And the logs and all of that jimmy-jam? What mechanism are you using I mean, snmp?

                          Comment


                          • #14
                            Ha. I can't give you that code because I don't have it. That was work I did for a school a couple of years back.

                            It's a MySQL backend, php frontend, and a mixture of batch files, registry files and VBScripts that grab the info and put it into a database. Extensive use of psexec occurs here. The logs are logs of the scripts that run on the machine, not machine logs, although these are also fairly easy to get to. Software versions were done with a mixture of grabbing exe file metadata and grabbing info from the registry. No clients required on the machines, just RPC access through the firewalls. I had scripts for virus detection and removal, software installs/upgrades/removals, and information-gathering.

                            I'm happy to help you work the bits and pieces you need out.

                            Edit: also, that's not live AD data - I had to periodically run a script to update it. There was a lot I was going to do, and could have done (including that) but never got time.
                            '====
                            //`
                            -Magilla
                            They observe my perambulations upon my gyroscopically-balanced personal transportation device, and I perceive at my core that they have thus concluded that I am Caucasian, and, while intelligent, I am also somewhat socially inept. - Peculiar Alfred
                            Eligible to shadow R & R-E NOW

                            Comment

                            Working...
                            X