logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Coding & Scripting Corner View previous topic :: View next topic
Reply to topic   Topic: protected directory authentication
Author
sailor



Joined: 17 Apr 2015
Posts: 77
Location: US

PostPosted: Thu 26 Sep '19 19:35    Post subject: protected directory authentication Reply with quote

I have a status web page on the backbone network that I access such as file://myserver/d$/status/index.htm. In the source of that, I have an image that lives on an Apache server:

src="https://mywebserver.com/svrstats/webapache_Status.png"

The directory svrstats is protected by basic user and password. You used to be able to put user and password in the url. Is there a way to embed user and password in the html so I don't have to right mouse click on the image and then fill in user and password (which then makes it appears on the file://...index.htm file ok)?
Back to top
glsmith
Moderator


Joined: 16 Oct 2007
Posts: 2268
Location: Sun Diego, USA

PostPosted: Fri 27 Sep '19 1:11    Post subject: Reply with quote

Sure your remembering correctly? Hasn't changed in decades.

https://username:password@mysite.com/webserver_status.png

It work's for me. I do get a warning in Firefox and clones telling me what I'm doing.


I do not get any warning in chrome on my Linux laptop.
It DOES NOT WORK AT ALL in MickeyMouseSoft Edge on Windoze 10, it asks for username and password .... the stoopid thing.
Could this be your problem?
Back to top
sailor



Joined: 17 Apr 2015
Posts: 77
Location: US

PostPosted: Thu 03 Oct '19 12:22    Post subject: Reply with quote

I'm using Chrome and they thought it was insecure, so it was disabled a year or more ago.

I can't seem to get my file://servername/d$/html/servers.html to load in Firefox.
There's a lot on the page, so maybe it's getting hung on something. Maybe fiddler would help, haven't had time to look.

I found a stackoverflow reference using javascript, but not sure if it would work since I don't have a web server https://stackoverflow.com/questions/3079031/login-form-for-http-basic-auth

There was another one using ajax, but would that work if I am using file://?

I thought about trying to set a cookie, but it can't be done https://stackoverflow.com/questions/49311410/saving-authentication-in-cookie

php could do it, but I'm not running this on a web server.
Back to top
sailor



Joined: 17 Apr 2015
Posts: 77
Location: US

PostPosted: Thu 03 Oct '19 15:06    Post subject: Reply with quote

Further down, https://stackoverflow.com/questions/3079031/login-form-for-http-basic-auth Ajax can be used, but I really don't know how to put it all together.

This has another example

https://www.quora.com/How-can-we-add-Ajax-in-HTML-code

Further down, Raj mentions you have to get a jquery plugin. I'm not sure how to put this all together.
Back to top
sailor



Joined: 17 Apr 2015
Posts: 77
Location: US

PostPosted: Thu 03 Oct '19 16:36    Post subject: Reply with quote

From this https://stackoverflow.com/questions/5507234/use-basic-authentication-with-jquery-and-ajax

This is what I have cooked up:

Code:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<script>
Function SendInfo() {
var uName="user";
var passwrd="password";

$.ajax({
    type: '{GET/POST}',
    url: '{https://myserver.com/server-status}',
    headers: {
        "Authorization": "Basic " + btoa(uName+":"+passwrd);
    },
    success : function(data) {
      //Success block 
    },
   error: function (xhr,ajaxOptions,throwError){
    //Error block
  },
});
}
</script>
<form action="" target="_self">
<input type="submit" onclick="SendInfo()" value="Submit" method="post">
</form>


In chrome debug, on Function line I get "uncaught syntax error: unexpected identifier" and the { is highlighted.

It looks like I have all the right number of braces.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7288
Location: Germany, Next to Hamburg

PostPosted: Fri 04 Oct '19 23:10    Post subject: Reply with quote

type and url are not correct:

Code:

type: 'post',
    url: 'https://myserver.com/server-status',


the error and the success functions

Code:

success: function (textStatus, status) {
                    console.log(textStatus);
                    console.log(status);
                   },
            error: function(xhr, textStatus, error) {
                    console.log(xhr.responseText);
                    console.log(xhr.statusText);
                    console.log(textStatus);
                    console.log(error);

                  }


So you can see your mistakes ;)
Back to top
sailor



Joined: 17 Apr 2015
Posts: 77
Location: US

PostPosted: Mon 07 Oct '19 19:52    Post subject: Reply with quote

Thanks, so I have this now, but still get the unexpected identifier. I would think the functions should be standalone or outside of this, but don't know how this jax works:
Code:

<script>
Function SendInfo() {
var uName="user";
var passwrd="password";

$.ajax({
    type: 'post',
    url: 'https://myserver.com/server-status',
    headers: {
        "Authorization": "Basic " + btoa(uName+":"+passwrd);
    },
success: function (textStatus, status) {
                    console.log(textStatus);
                    console.log(status);
                   },
            error: function(xhr, textStatus, error) {
                    console.log(xhr.responseText);
                    console.log(xhr.statusText);
                    console.log(textStatus);
                    console.log(error);

                  },
});
}
</script>
<form action="" target="_self">
<input type="submit" onclick="SendInfo()" value="Submit" method="post">
</form>

Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7288
Location: Germany, Next to Hamburg

PostPosted: Tue 08 Oct '19 9:56    Post subject: Reply with quote

The documentation is not that bad see https://api.jquery.com/jquery.ajax/
Back to top


Reply to topic   Topic: protected directory authentication View previous topic :: View next topic
Post new topic   Forum Index -> Coding & Scripting Corner