NetTalk Central

Author Topic: NetTalkServer extra buttons  (Read 3307 times)

DonnEdwards

  • Jr. Member
  • **
  • Posts: 56
    • View Profile
    • Insights and Rants
    • Email
NetTalkServer extra buttons
« on: April 16, 2021, 07:44:27 AM »
I have created two useful buttons to help me set up the secure and insecure ports correctly. See attached image

These are the items to add near the end of the Webserver Window using the Window Structure Editor:

Code: [Select]
          BUTTON('Insecure Address'),AT(6,297),USE(?InsecureButton),TIP('Open the browser with' & |
            ' the insecure address and port')
          BUTTON('Secure Address'),AT(82,297),USE(?SecureButton),TIP('Open the browser with ' & |
            'the secure address and port')

In the Local data "Generated Declarations" embed point, add in:

Code: [Select]
! Secure and Insecure Address buttons
loc:Run           cstring(255)
loc:parameters    cstring (255)
loc:ret           long
st                StringTheory

For the "?InsecureButton" Accepted embed point add in:

Code: [Select]
  ! Open the insecure address
  IF len(clip(set:Domains)) > 4 THEN            ! Domains are listed
        st.SetValue(CLIP(set:Domains) & '<13,10>') ! Get the domains, add a CR LF to the end
        loc:Run = 'http://' & CLIP(st.Before('<13,10>')) & ':' & CLIP(set:InsecurePort) ! First listed domain
  ELSIF LEN(CLIP(set:BindToIpAddress)) > 4 THEN ! IP Address filled in
        loc:Run = 'http://' & CLIP(set:BindToIpAddress) & ':' & CLIP(set:InsecurePort)
  ELSE                                          ! IP Address missing
        loc:Run = 'http://127.0.0.1:' & CLIP(set:InsecurePort)
  END                                           ! IP Address
  loc:parameters = ''
  loc:ret = OS_ShellExecute(0{prop:clienthandle}, 0, address(loc:Run), address(loc:Parameters), 0, 1) ! Open the URL

Similarly for the "?SecureButton"

Code: [Select]
  ! Open the secure address
  IF set:SecurePort > 0 THEN                ! Secure port set
        IF len(clip(set:Domains)) > 4 THEN            ! Domains are listed
            st.SetValue(CLIP(set:Domains) & '<13,10>')  ! Get the domains, add a CR LF to the end
            loc:Run = 'https://' & CLIP(st.Before('<13,10>')) & ':' & CLIP(set:SecurePort) ! First listed domain
        ELSIF LEN(CLIP(set:BindToIpAddress)) > 4 THEN ! IP Address filled in
            loc:Run = 'https://' & CLIP(set:BindToIpAddress) & ':' & CLIP(set:SecurePort)

        ELSE                                ! IP Address missing
            loc:Run = 'https://127.0.0.1:' & CLIP(set:SecurePort)
        END                                 ! IP Address
        loc:parameters = ''
        loc:ret = OS_ShellExecute(0{prop:clienthandle}, 0, address(loc:Run), address(loc:Parameters), 0, 1)  ! Open the URL
  ELSE                                      ! Secure port is zero
        MESSAGE('Secure Port not set')
  END                                       ! Secure port

I'm not entirely sure I have got it right. Please could you guys have a look at my code and tell me how I can improve it further. I'm still very new at all of this.
Thanks in advance
Donn
If you're happy with your security, then so are the bad guys

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: NetTalkServer extra buttons
« Reply #1 on: April 19, 2021, 02:17:58 AM »
It is very common for the address, on the same computer, to be different to the address which will be used from outside the LAN.
So these buttons may be useful to you, but I suspect will not operate reliably in all (or even most) cases.

Because the settings (domains list) is typically the External address, which may, or may not, work, when connecting from the local computer.

Cheers
Bruce

DonnEdwards

  • Jr. Member
  • **
  • Posts: 56
    • View Profile
    • Insights and Rants
    • Email
Re: NetTalkServer extra buttons
« Reply #2 on: April 20, 2021, 05:03:19 AM »
Perhaps I didn't explain the use case too clearly. The exe runs on my development PC and then I copy it to the live server. Each box has different settings, but the same EXE.

See images side by side below. So when I click on the "Insecure Address" on my dev box, it opens http://192.10.200.98:88 because that's what the settings are. I click the same button on the live server and I get http://kgoffice.co.za:80 which is then immediately redirected to https://kgoffice.co.za as expected.

Or I can save time and click on the "Secure Address" button on the live server and get https://kgoffice.co.za:443 straight away.

The buttons allow me to check that I got the settings correct. For example I forgot to change port 88 to port 80 on the live server, so the "Insecure Address" button showed me something was wrong.
If you're happy with your security, then so are the bad guys