How to find out the document root or find out actual path of a URL in cPanel server? - shell

First of all, I searched in Google to my level best to find the answer and not able to even get some clue on this.
I want to find out the actual path in the server for a given URL. I have root access.
For example, I want to write a script, It takes URL as a input and prints the actual path in the server.
Example Input: some.com/wp-includes/js/tinymce/plugins/media/js/file.php
abcd.com/wp-includes/js/tinymce/plugins/wpgallery/img/xml.php
The output should be
/home/some/public_html/wp-includes/js/tinymce/plugins/media/js/file.php
/home/abcd/public_html/wp-includes/js/tinymce/plugins/wpgallery/img/xml.php
The domain name can be add-on, or sub-domain , But it is hosted on the same server.
I want to write a shell script to achieve this. Please guide me.
I want this to be done using Linux shell script only and not using PHP.

There is a perl based cPanel API for getting this information. Without that, It is very tough to implement it or i have not seen any code on Internet. So I dropped this.

From any PHP code running in browser you can use:
# prints DocumentRoot path
echo $_SERVER["DOCUMENT_ROOT"];
# prints full filesystem path of the script
echo $_SERVER["SCRIPT_FILENAME"];

Related

classic asp create text file on webserver: error 800a0034 Bad_file_name_or_number

I have a classic asp page in VBS and I am trying to create a file on the web server with the following code.
Set fso = CreateObject("Scripting.FileSystemObject")
Set file1 = fso.CreateTextFile("\\localhost\inetpub\wwwroot\cs\batch\123456dirs.bat", true)
This returns the following error:
|666|800a0034|Bad_file_name_or_number
Line 666 is the CreateTextFile line.
According to the Microsoft docs, this means that I'm trying to create a file with an invalid filename. Then it explains the rules for filenames and mine appears to be perfectly valid.
Any suggestions or ideas on how I can further troubleshoot this?
first thing to check to make sure your users have access to the folder. Assuming you're not using windows authentication, make sure IUSR account has write access to the folder.
second, unless inetpub is set up as a share to folder, you're syntax won't work. if the root of your website is located in the CS folder, you can do something like:
Set file1 = fso.CreateTextFile(Server.MapPath( "/cs/batch/123456dirs.bat" ), true)
The createtextfile() function runs on the web server but in the context of the local server itself. Simply put, any path you give it must resolve as if you were logged on to a windows desktop on the server and tried to CD to that path.
The format \localhost... is a UNC path. See this question for a discussion about UNC paths and windows. Unless you know for sure that there is a UNC path mapped for \localhost then that is probably your issue. You may be making the assumption the \localhost will be a reasonable path to use, but as I said unless you know for sure it is available then this is an invalid choice.
Lastly, if you decide to set up a share for \localhost, you will be getting in to some interesting territory around the user context that the web server operates in. You see you will have to set up the share for the IIS user that is configured as the run-as identity for IIS, so you will need to know that and create the required config to give that user the share.
If it were me, I would switch to using a standard windows path, although even then you need to appreciate the run-as user context and security config, etc.

REST API URL with Directory and File name as Path Variables

I have a requirement to send the folder details in the URL for POST method, some thing like this
http:///{directory}/{filename}
I am using Spring API to create the service. Using #PathVariables to two variables in the URI.
Problem : Directory can have "/" slashes in it.
Now how can I create my API, please help me.
POST http://example.com/api/files/path/to/my/file/filename
Stick a controller on /api/files. Scrape the URL starting after /files. Use that to locate the file.
P.S. This has the potential to be a Very Bad Idea. Make sure you secure the controller to only expose those parts of your filesystem you don't mind random internet strangers to be able to operate on.

How to get a copy of all uploaded images from a Plone site

I am working on a plone site with version 4. I want to have a copy of all the uploaded images. What is the way to get it? I couldn't get appropriate documentation for it.
If you are comfortable with the Linux command line and want something quick and dirty to get ALL images locally, you can add a script (Python) via the zmi into the portal_skins/custom folder on the Plone site, with the following code:
from Products.CMFCore.utils import getToolByName
base = 'http://example.com/'
pc = getToolByName(context, 'portal_catalog')
query = {'portal_type': 'Image'}
brains = pc(query)
for brain in brains:
path = brain.getObject().absolute_url()[len(base):]
dire = '/'.join(path.split('/')[:-1])
print "mkdir -p '%s';wget %s%s -O '%s'" % (dire, base, path, path)
return printed
(Replace example.com with your site domain name)
Call the script 'image_links'.
Then go to to http://example.com/image_links
You should see a whole bunch of bash shell script commands on the web page. Copy and paste those into a terminal, and your machine should download the images.
Alternatively, put those commands into a shell script and download them all at once.
This produces a directory structure with all images on the site.
I used something similar a few weeks ago to download 3500 images from a client site. Took an hour or 2, but without involvement from me.
Keep in mind that this is quick and dirty: Images get the Plone object name, so might not have the correct extension, etc. YMMV.
A simple (but manual) way is to connect to your Plone site using a webdav client and authenticating using Plone credentials.
In this way you can move inside Plone folders and drag & drop images from remove site to your local machine.

Get a dropbox url from the command line

I'm a windows 7 user and I want to access an object from within my public dropbox folder using the command line. How do I do that (note my skills with the command line are weak so be gentle please. This is what I'm basing my information on: DROPBOX CITE LINK
Here's the path to my drop box and what I attempted:
#the path
C:/Users/trinker/Dropbox/Public/plot.png
#the attempt to retrieve the url of plot.png
CD C:/Users/trinker/Dropbox/Public/
C:/Users/trinker/Dropbox/bin/dropbox.py puburl C:/Users/trinker/Dropbox/Public/plot.png
Note my slashes are going the opposite way you'd normally see them on a windows machine as I'm using this within another program that requires the slashes be in this direction or doubled as in \\
The goal is to retrieve the url for the dropbox object.
There is a work around pointed out to me by my friend Dason. Go to your public folder and copy the link from a file. Here's one of mine:
https://dl.dropboxusercontent.com/u/61803503/%20wordcloud.pdf
The account number is always the same for your own drop box. So the following form will allow me to share documents:
file.path("https://dl.dropboxusercontent.com/u/61803503", DOCUMENT_NAME_HERE)
I don't know exactly what you are doing but if that is the url to your dropbox share, and you just wanted to access via command line have you tried just mapping a network drive to that URL to see if it works?

I'm told to down load a text file from another website and to put in the root directory of my website

I want to know how to down load a text file from another website and how to put it in the root directory of my website.Can you help me with problem please.THANK'S !!
As a program, or as a human action?
As a human, you should be able to take the link and download the file, upload to your website using for example FTP or (hopefully no one does this now) frontpage.
If you mean programattically, well its almost the same. Your script would need to open the file in the root directory, open the URL and read in the data sent and save it to the file, close the file. However, how to do so exactly depends on the lanugage you want, is this a repeated event or a once off?
This type of request usually happens when you are requesting a service that requires proof that you are the website owner. Being the owner of that website would also indicate that you should have at least ftp access over your site. If you are hosting the website yourself, this is an easy task you just copy the file into the root directory (windows default is c:\inetpub\wwwroot, ubuntu default is /var/www/). However if your website is hosted, you need to find your ftp username and password and utilize an ftp program like FileZilla. If you want to tell us what file host you use maybe someone can give you exact instructions. But beware of what file you host.
If you have the URL of the text file you can put it into your browser and then save the file to your disk. You then need to FTP it to your web server (or whatever method you normally use to get files onto the server)
In PHP:
<?php
$resource = curl_init('http://www.someserver.com/file.txt');
// important, otherwise curl_exec will output directly
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$data = curl_exec($resource);
curl_close($resource);
file_put_contents('/dir/localfile.txt', $data);
Or even better, with a bash script with a simple wget and cp.

Resources