keeping safe assets folder in codeigniter - codeigniter

Hi i have this assets folder which has the following folder inside of css, images, uploads, and js folder i put the assets folder outside application. Im wondering that how could i keep it safe so that when users tried to type in the url like for example http:/test.com/assets it will redirect to application folder or somewhat it will says page not found. Cause ive noticed that when i type in the url http://test.com/assets it will go to the assets folder and which is vulnerable and people could see all the folders in the assets folder. can someone help me figued this thing out? Any help is muchly appreciated.

if you want to secure you folder then do one this create html file like this
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<p>Directory access is forbidden.</p>
</body>
</html>
and save it as index.html and put it on your assets folder whenever some try to access your url http://test.com/assets then this index file will execute and its shows Directory access is forbidden.

Related

Codeigniter 4 assets PATH configuration for Modules

I m creating different directories for Role-based access in Codeigniter 4. I have created the Modules directory inside app/ i.e (app/modules/admin). I have assets for the admin. I want to load it in the header file of view. I have tried it with the base_url().'/app/modules/admin/assets/filename.xyz' but load the complete file in the link but doesn't show me the assets. How can, I load these assets in the same directory. Please see the below code
<link rel="stylesheet" href="<?php echo(base_url().'/app/modules/super/assets/'); ?>plugins/fontawesome-free/css/all.min.css">
All public files including assets should be placed inside your public folder and not your app folder. Your app folder shouldn't be visible to the public.
With this in mind what I would do would be create a simular structure in your public folder.
public/modules/admin/css
public/modules/admin/js
public/modules/admin/img
Then if you have an asset called styles that would be in:
public/modules/admin/css/styles.css
This asset should be called using the base_url function from the uri helper.
<link src="<?php echo base_url('modules/admin/css/styles.css'); ?>">

Image path issue when uploading Laravel 6 project to live server?

I uploaded my Laravel 6 blog to a live server. I put the content of the 'public' directory in the "public_html" folder and I created another directory outside the "public_html" where I uploaded the rest of the files and folders.
Everything seems to be working ok, except when I create a new category or post the images are not uploaded. I guess it's a path problem.
I think I need to modify the path in the controller, like here
$category = Image::make($image)->resize(1920,479)->stream();
Storage::disk('public')->put('category/' . $imagename, $category);
Since I no longer have a directory called "public", what should I put there? How do I change this path?
My css and js files were linked like this on localhost:
<link href="{{ asset('public/assets/frontend/css/bootstrap.css') }}" rel="stylesheet">
when I just left out "public/" they were working fine on the live, but if I leave out the "public" in the controller code, it's not working.

css file not found - asp.net core web application

I have created an asp.net core web application (I started with the Empty option) and I am building it step by step. It seems my css file is not being read or found though.
When I launch the application I can see that my html page does not look as it should be and when I use the developer tools in edge under the console there is an HTTP404: NOT FOUND - The server has not found anything matching the requested URI (Uniform Resource Identifier). GET - http://localhost:8888/css/site.css error which would indicate my css file is indeed not being read or found.
Now, my css file is under a folder called "css" which is in the root of the project. When I say root I mean that I have just created a folder called css and the path is the same of Program.cs or Startup.cs. There is no wwwroot in my project (seems that asp.net core 2.2 has removed it by default?) and the css folder is not there. As follows the code from my html page, I have tried to add the ~ before the "/css" but still nothing.
<head>
<link href="/css/site.css" rel="stylesheet" />
</head>
If you would like that static files to be served outside of the web root (for example in a folder named MyStaticFiles) and it has the structure like
-YourProject
--MyStaticFiles
---css
----site.css
--Program.cs
--Startup.cs
You could use app.UseStaticFiles, refer to Serve files outside of web root
public void Configure(IApplicationBuilder app)
{
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(
Path.Combine(Directory.GetCurrentDirectory(), "MyStaticFiles")),
RequestPath = "/StaticFiles"
});
}
Then you could get the css from http://localhost:8888/StaticFiles/css/site.css
or <link rel="stylesheet" href="~/StaticFiles/css/site.css" />
It is happening because environment webroot is different than the css folder is currently in. You have to change the webroot or move your css folder to current webroot.
Normally the wwwroot folder is set at environment webroot

Spring MVC resources not being mapped

my folder structure
enter image description here
And my code in the JSP page is
<script src='${pageContext.request.contextPath}/AppNameController.js'/>
I'm still getting 404 error
You have the prefix set to /WEB-INF/jsp but looking at your project structure your index.jsp is only within the /WEB-INF folder rather than inside the /WEB-INF/jsp folder.
Also change to:
${pageContext.request.contextPath}/resources/scripts/AppNameController.js

Including page layout to Laravel project

I was supplied with a custom layout for the login page of my Laravel project.
When I opened login.html file, which represents the layout for that specific page I saw such links
<!-- Base Css Files -->
<link href="assets/libs/jqueryui/ui-lightness/jquery-ui-1.10.4.custom.min.css" rel="stylesheet" />
<link href="assets/libs/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
<link href="assets/libs/font-awesome/css/font-awesome.min.css" rel="stylesheet" />
...
So I figured that I only need to copy the assets folder, which came with the template (there are all needed bootstraps, jqueries and whatnot) to my projects app\resources\assets directory
Now, when I copied the code from login.html into my login.blade.php view and copied the templates' assets folder to app\resources\assets it doesnt work. It only displays naked html code when I open the page.
What am I doing wrong in linking the assets folder?
The resources folder is (like the name says) for the resources.
If you don't want/need to build/compile/min your scripts, then just put them in the public folder, so you can access them from your template.
In your case
public/assets/libs...
In order to access assets, you have two ways to approach it. Either using Elixir/gulp or to use direct access.
Gulp is a node.js application that reads your assets files, whether JS, CSS, Coffee, etc...and combine them in single files. Gulp reads the files defined in the gulpfile.js, and you can access the output files in your blade file using elixir().
You can read more about Elixir here.
In your specific case, you can just place the files under the public/ directory. So Laravel treats public as the root directory, and if you want to read the file assets/css/foo.css just place the file in public/assets/css/foo.css

Resources