How to give relative path in .js on linux platform? - javascript

I have Web UI developed in simple HTML and .js with lighttpd as web server and it is on linux based device.
I need to keep my main.html file in root directory and javascript files in js folder.
While running program it reads the javascript from js folder and the javascript accessing config files from other directories (/etc/config/myconfig). While accessing this file application giving error as 403 since I am using XMLHttpRequest, but it works when I keep myconfig file in root directory i.e with the main.html.
Please suggest is there any way to tell javascript to read file from /etc/config directory.

Error 403 :
403 Forbidden
The request was a valid request, but the server is refusing to respond to it.[2] Unlike a 401 Unauthorized response, authenticating will make no difference.[2] On servers where authentication is required, this commonly means that the provided credentials were successfully authenticated but that the credentials still do not grant the client permission to access the resource (e.g., a recognized user attempting to access restricted content).
You need give your script access to read from the directory(/etc/config).
Read about chmod/chown commands.

Related

Issue with json_rpc over https

Hello my site is powered by https. The config.js file is located in the root folder of the site, it specifies which address to access via the API. The address is specified https://127.0.0.1:10000/json_rpc, requests to this address do not work. If you specify http://127.0.0.1:10000/json_rpc, then everything works. How can I call the API over https and not over http? Or is there a workaround in the config.js itself?
If you make a request via curl https://127.0.0.1:10000/json_rpc, then curl error appears: (35) OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to 127.0.0.1:10000

For the ajax url shows 404 on the AWS tomcat log

I was using MVN install deploy my code on the AWS tomcat. I did this by directly open the AWSname:8080/manager/html and upload the WAR file(I am not sure if it is the correct way). The server can load the index.html successfully as my expectation and shows page on the front-end, but error went to call AJAX, which is in Javascript file, it always return 404. The servlet's url pattern will be like this
AJAX
Login Servlet
I tested everything fine on my localhost:8080, but in the AWS tomcat, the log showed like this.
Tomcat Log
I've never met such a case before, could somebody give me some useful suggestions on the possible solutions?
from your description it is not clear if you have multiple apps/war/containers/servers.
From your message you have a UI, which seems not to be bundled into your war file. To check in this case use these steps to check your setups
Add a index.html to your root in the war file and test if you can access it locally.
if this works, deploy on AWS and try to access the same path on AWS.
if the page is showing, your context is defined well on AWS. So you have an issue with your URL mappings
But if it does not show, you have a URL problem (wrong URL on AWS)

Downloading text file using curl in HTML

I am trying to download text file from server to local directory.
If I execute following curl command it copies myfile.txt from server and saves in same directory as newfile.txt.:
curl -o newfile.txt http://myserverip/myfile.txt
I want to automate this by running the command from javascript while loading the webpage.
For example if I open an html page (which runs a javascript) like http://myserverip/getnewfile.html in the browser the myfile.txt from the server should be copied to newfile.txt in the loacl directory.
Can anyone help me to write javascript to execute the curl command?
Please note that the server in local area network and router is configured to allow connections only from white-listed mac ids of local machines so there is no any authentication required to connect to server.
You can't run local command-line commands from JavaScript, because that would be a massive security vulnerability. The tool you want to use for this is either window.open (to open a tab with the file in order to cause the browser to download it) or the fetch API (to retrieve the file for use in JavaScript).

Why can't I load up a local JSON file with AngularJS $http?

I am trying to load up local file(todo.json) that is in the same folder as my webpage with the following line:
$http.get("todo.json").success( function( data ){ //Do Some logic});
But I get the following error message in the Javascript console:
Error: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'file:///C:/Users/quickCoder/Desktop/HTML5Apps/todo.json'.
...
As mentioned, the index.html file consisting of this code is in the same HTML5Apps folder as todo.json. Any suggestions ?
I think you need a running webserver that serves your files and the json file have to be in the folder of your server.
You can use a server like node-serve. It's easy to run once installed just type serve in your terminal.
[...] Now the protocol for a local file is not http:// but file://. Therefore, you cannot do a direct AJAX request from a local file. The same applies to many other APIs available through JavaScript, which can only request access through the HTTP protocol. This is because of the Web's security model, which we'll discuss in another article.
source of the quote mdn

Forbidden : You don't have permission to access /questions.php on this server

I am beginner in PHP and I got the Error for Developed My Project ERROR is Like:
This: Forbidden
You don't have permission to access /quiz.php on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Please give the suggestion for Solve this problem.
From interpreting the error, I believe that the problem doesn't lie in php but rather in the underlying operating system and filesystem. More specifically, file permissions.
If you are running Apache on Linux the webserver will only be able to serve pages that it can read. This has to do with local filesystem permissions.
I'm taking a leap here, but if your server is run by the user www-data then that user needs read permissions to the .php files in order to serve them as web pages. If these files are in a subdirectory, then that subdirectory and the .php files inside must also be accessible by www-data.
First, make sure that quiz.php is readable by the user www-data, as most likely you would have created this file using a different user account (root? yourself?).
The following command sets the owner of the file quiz.php to www-data
chown www-data quiz.php
This command needs to be issued in the directory where quiz.php is located and it needs to be entered with a user account that has sufficient privileges to change a file's attributes. Normally this is the root account, but it could be you if the server's administrator has given you those permissions.
You can read up on the chown command by typing
man chown
on most Linux systems.

Categories