samedi 24 février 2018

Why doesn't appache allow access to files outside the web root --from within index.html?

As the title states..

I have the following organization to my project but am unable to access the related css and javascript files from within my html code --unless I create symbolic links from the file to my web root. Is this normal behavior for apache or does the problem lie elsewhere?

If I remove the symbolic links and correct the path in my src attributes the content of those outside files becomes inaccessible

userName@hostName:/var/www/test$ tree
.
├── css
│   └── style.css
├── html
│   ├── code.js -> ../js/code.js
│   ├── index.html
│   ├── jquery-3.2.1.js -> ../libs/jquery-3.2.1.js
│   └── style.css -> ../css/style.css
├── js
│   └── code.js
└── libs
    └── jquery-3.2.1.js

4 directories, 7 files

userName@hostName:/var/www/test$ less html/index.html

<!doctype HTML>
<html>
   <head>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <link rel="stylesheet" type="text/css" href="./style.css">
      <title>Test</title>
   </head><!-- head -->
   <body>
     <h1>LOCAL TESTING SITE..</h1>
   </body><!-- body -->
    <script src="./code.js"></script>
</html><!-- html -->

html/index.html (END)

^ Works

userName@hostName:/var/www/test$ tree
.
├── css
│   └── style.css
├── html
│   ├── index.html
├── js
│   └── code.js
└── libs
    └── jquery-3.2.1.js

4 directories, 7 files

userName@hostName:/var/www/test$ less html/index.html

<!doctype HTML>
<html>
   <head>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <link rel="stylesheet" type="text/css" href="../css/style.css">
      <title>Test</title>
   </head><!-- head -->
   <body>
     <h1>LOCAL TESTING SITE..</h1>
   </body><!-- body -->
    <script src="../js/code.js"></script>
</html><!-- html -->

html/index.html (END)

^ Does NOT Work

userName@hostName:/var/www/test$ tree -p
.
├── [drwxrwxr-x]  css
│   └── [-rw-rw-r--]  style.css
├── [drwxrwxr-x]  html
│   ├── [lrwxrwxrwx]  code.js -> ../js/code.js
│   ├── [-rw-rw-r--]  index.html
│   ├── [lrwxrwxrwx]  jquery-3.2.1.js -> ../libs/jquery-3.2.1.js
│   └── [lrwxrwxrwx]  style.css -> ../css/style.css
├── [drwxrwxr-x]  js
│   └── [-rw-rw-r--]  code.js
└── [drwxrwxr-x]  libs
    └── [-rw-rw-r--]  jquery-3.2.1.js

4 directories, 7 files

^ Permissions on files

userName@hostName:/etc/apache2$ less sites-available/test.local.conf

<VirtualHost *:80>
        ServerAdmin myEmail@email.com
        DocumentRoot /var/www/test/html
        ServerName test.local
        ErrorLog ${APACHE_LOG_DIR}/test.local.error.log
        CustomLog ${APACHE_LOG_DIR}/test.local.access.log combined
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

sites-available/test.local.conf (END)

^ Virtual Host Configuration

userName@hostName:/var/www/test$ uname -v

#35~16.04.1-Ubuntu


userName@hostName:/var/www/test$ apache2 -v

Server version: Apache/2.4.18 (Ubuntu)

^ System Info




Using JQuery to replace tags within an array?

I am new to Javascript and JQuery and I am trying to replace all my tags with upon first click, and then replace with on the second click, and so forth.

Basically just cycling through them so on each click I have a 3d rendered box or sphere. I tried to run it with this code however it does not work.

When I checked the console, only the lines were getting logged, so it doesn't seem to be replacing them correctly. I need to keep the tags within each preserved as I work.

var counter = 0;
    var myArr = ["a-sphere", "a-box"];

    $("#targeted").click(function() {
        if(counter == myArr.length) counter = 0;
        $(myArr[counter]).replaceWith(function() {
            var myString = "<" + myArr[counter] + ">" + $(this).html() + "</" + myArr[counter] + ">";
            console.log(myString + counter);
            return myString;
        });
        counter++;
    });




How to call ...blade.php in different folder inside views folder in laravel

Excuse me, i would like to ask about how to call another page blade in different subfolder inside views. Example :

views
   --home(subfolder)
   --beranda(subfolder)
       --refresh.blade.php
   --layouts(subfolder)
       --master.blade.php

in master.blade.php implements template page, when i click one link in this folder may have to go in refresh.blade.php. Likely another web layout, they have a lot of link in header like 'Home', 'Paper', etc.

I'm still learned more about laravel as beginner practice. May you can help me, i'll appreciate that.

Regard, Aga.




How can i be a web developer?

Sir,Is It Possible To Be An Awesome full stack Web Developer Without Doing Competitive Programming / without problem solving in online judge?

Thanks in advance




PHP file upload error for large files

I am trying to upload files using php on my local server and save it in the current working directory.The code is working fine for any file type of size less than 2mb but above this size it gives error. I have also modified the upload and post size in php.ini file,but it was of no help.It gives 4 errors: 1-Undefined index: temp in C:\wamp64\www\project\upload.php on line 3. 2-file_get_contents(C:\wamp64\www\project\project): failed to open stream: No such file or directory in C:\wamp64\www\project\upload.php on line 5. 3-Undefined index: temp in C:\wamp64\www\project\upload.php on line 6. 4-Undefined index: temp in C:\wamp64\www\project\upload.php on line 18. I am saving the uploaded file in the same location where upload.php is located.

Upload.php:

<?php
$target_dir = getcwd();
$target_file = $target_dir .'\project'. basename($_FILES["temp"]["name"]);
$uploadOk = 1;
echo file_get_contents($target_file);
if ($_FILES["temp"]["size"] > 5000000000) 
{
    echo "Sorry, your file is too large.";
    $uploadOk = 0;
}

if ($uploadOk == 0) 
{
    echo "Sorry, your file was not uploaded.";
} 
else 
{
    if (move_uploaded_file($_FILES["temp"]["tmp_name"], $target_file)) 
    {
        echo "The file ". basename( $_FILES["temp"]["name"]). " has been 
uploaded.";
    } 
    else 
    {
        echo "Sorry, there was an error uploading your file.";
    }
}
?>




How to delete event listener without external function

Got the real dilemma. I have an init function which has lots of parameters inside which are depended on each other and can't be remove outside, an array of elements and added to each a click event listener. This event listener checks if the clicked element is a certain element then remove the click listener from all elements in the array. The promblem is I have to use an anonimus function in the event listener due to the internal parameters of the init function, but to delete an event listener I must pass the same function in removeEventListener so it must be named function and I can't get solution for this.

The approximate logic:

let init = () =>{

  //some internal parameters here and logic

  for (let i = 0; i < elArr.length; i++) {

    elArr[i].addEventListener('click', event => {
        if (event.target.style.background ===
            elArr[pickedElement].style.background) {

            //Not working (can't define the param as a separate function due 
            //to params of this function can't be passed to there)
            for (let i = 0; i < elArr.length; i++)
                elArr[i].removeEventListener("click", event);

        } else {
            event.target.style.background = bgColor;
        }
    });  
}




How to make calls by website authorized?

I have a website deployed on AWS. I also have an API written in python on the same server but on a different port. How do I restrict the calls being made to my API so that they can come only from my website and no other public source?