Windows network drive from PHP running on a linux environment - php

I have to check something if it works.
We have limited access to a Debian server via ssh. We have a PHP intranet solution running on this server, so we can run PHP scripts. We got the following scenario:
A windows network drive given: \\IP\folder$
We have to read this windows network drive from PHP under linux. I never did such thing.
We have no any rights to mount anything on the server. This drive may or may not accessable from the linux machine, I don't know. (I guess it's accessable, due to the scenario).
We didn't receive any user&pass for the drive, so I guess we don't need it.
The question is: is it possible to do this in this situation if everything was set up correctly on the customer side? If yes, how?
We can ask more information and configuration changes if we need it, but I'm wondering if we can do this now, because it's interesting.
Thanks in advance,
negra

You can use smbclient to access the share. You could consider it as a sort of 'ftp' client, but for accessing Windows shares instead. It can work without need for mounting, and you should be able to talk to it directly from PHP using popen() for bi-directional communication of commands/results.
However, this depends on the share actually being remotely accessible, and you having access rights to it (via a windows account or the share having 'everyone/read' permissions). If windows networking is firewalled and/or you don't have access permissions, then there's nothing you can do to access the files directly.

Related

Secure Linux Server Setup To Run Scripts via PHP exec()?

I'd like to run a script (phantomJS) via php exec() or shell_exec(). Everything is working fine on my development system.
I've installed phantomJS on my production server, and have run it successfully from the terminal after logging in via SSH.
But when I run it from PHP via exec() or shell_exec(), I get messages saying:
GLIBCXX_3.xx not found
GLIBC_2.xx not found
The support team at the web hosting provider is saying they don't know how to enable the server to access the script and still maintain security:
We're not familiar with the specifics of it, so we'll either have to
go through with disabling the chroot, but as our supervisor mentioned
this will allow all accounts on the server to account with each other
which is what the chroot prevents.
You can have your own system administrators look at the setup as you
do have root access, and see if they can devise a workaround, but on
our end this is the only thing we can suggest.
They are running CentOS, which is a 64-bit Linux OS.
I have very good experience with this web host up to this time, so I'm hoping there's a way to address this without changing hosts.
I have full root access to the account, so I can configure it in any way necessary.
Can anyone make some suggestions about how I might configure my production server to access phantomJS while maintaining a secure server?
UPDATE
Apparently my app is in a "chrooted environment" without full root access to GLIB on the server. The web host is saying there will be a lack of security if my php user is given full root access.
You have to remove your PhantomJS system call and create an API layer or a service that subscribes an MQ queue and then integrate it with PHP to avoid several problems, including the chroot limitation.

PHP - Transfer file from Server to Windows PC

I have tried a few SSH and SCP snippets to transfer files from a web server to a windows pc and I can't quite get it working. There are a combination of things I believe I need such as firewall permissions, php modules, etc.
What boggles my mind is, it is so easy to ssh to a linux machine because I know the username and password but for Windows, you don't REALLY have a username and sometimes don't even have a password.
That being said, here is what I need to do. I have a linux server online and need to send a XML file to a windows pc. Out of your experiences, what are the best php modules, snippets, and any tips that you followed to achieve this? I believe the IP I would use for my windows machine would be my public ip but what in the world would the password be.. I have no pw on my computer? Do I need extra software installed on my windows pc as well?
Any help is appreciated.
Without getting into your IP potentially being dynamic.
It sounds like you need a cron job on the web server. You could then set up a FTP/SSH server on your Windows PC to receive the file.
On the other hand if this file is in a website folder which has FTP access. You could FTP to the server from your Windows pc and get the file with an FTP client.
Programs such as FTPBox could sync this for you or Curl from the command line.
With a command line program like Curl on your Windows PC you could set up a cron job on your Windows pc to automate getting this file if you want to do this automatically.
There are a few other options like a virtual linux machine on your windows pc. Then you could SSH from there and set up shared folders etc.
But to put it as simply as my experience has taken me.
If you have a webserver use FTPS and use a FTP client on your PC.
or use a command line program like Curl to automate from windows pc
From the server you need a cron job to automate the process, but you need to setup some type of server to receive this reliably. You could have a PHP file call a script file with php exec() depending on your webservers permissions.
Your router and software firewall may need to be configured to allow the ports you use for the transfer.
Easiest option is FTP server on webserver and FTP client on windows machine.
There are a few options, so I hope this has helped somewhat, I haven't taken into account a few things like security, automation, permissions etc. So none of these could be your best option. :)
Hope this helps a bit
Edit: Just to add Windows doesn't come with SSH which might explain some of the username/password issues. When you set up a FTP server on your Windows pc you can set your credentials
Here is a guide for setting up FTP Server on Windows PC
https://www.howtogeek.com/140352/how-to-host-an-ftp-server-on-windows-with-filezilla/
Once you have a server setup on your pc, if you wish to go down the route of a creating a cron job on your webserver for automation, you will havve your credentials from your server setup.

Do I need to install PHP, MySQL, and something like XAMP, if I already have an IDE, a webhost, and FTP client?

It seems like there are two ways to go, and the determining factor is whether you want to host on your own computer, or through a webhost.
If I have an IDE, a webhost server I subscribe to, and an FTP client to transfer my files to the server, then I don't need to install PHP, MySQL, and XAMP, right?
I know XAMP allows me make my computer website server.
When I install PHP, am I installing the intepreter for my computer/server to parse the .php files? (and same for MySQL?)
If I pay for web hosting, then their servers already have PHP and MySQL parsers, and all I need to do is upload my text files, right?
Thanks in advance
U just cant simply put the files in server without developing them.and if you want to develop any website or any webapp then u need to make your system a local server where you can execute your server side languages like php.XAMP is a short form for mysql,apache and php for windows.and 'website server' is not the proper word.use LOCALHOST instead because only u will have access to your server unless you are connected via LAN or WAN.so i can summarize the above in few points keeping in mind that you want to develop your website.
step 1:install XAMP
step 2:develop and test your scripts.
Step 3:if everything works fine than host your site in the webserver for everybody to see it.

Programmatically access windows share in php via kerberos or ntlm

I have a few requirements here on which I am not sure if they're even possible the way they're requested. Sorry beforehand for not having code, but I feel stackoverflow fits the most for this question, and I can't write code on company time before the situation is clear.
Setup
A windows server with an IIS and PHP running via FCGI. There's an intranet (php/mysql) running on this machine. Users currently have anonymous access to it, since it is an open intranet. All users are in the same windows domain.
SSO and windows shares
As far as my research got, single sign on via NTLM is possible and should not be a biggie to implement into the current intranet. However, there's a plugin running which reads directories from defined windows shares, and spits out a file list. Those files are read by a specific user account having read access to this share.
Is it possible to authenticate the current user at the windows share to read files, via that data I receive from SSO (via ntlm or kerberos or ...)?
You need Kerberos, Credential Deleagtion and Impersonation. Forget NTLM.
Edit: On Windows, this is solved by SSPI, on Unix by GSS-API.

PHP shell_exec doesn't work in Windows Azure

We need to execute an .exe file in a remote Windows Azure Server.
We call it from PHP with shell_exec. The .exe should create new files in two different folders into the server and generate data entries in a data base and returns a string, but it doesn’t work.
We don’t have any problem executing it in our local server with windows 7 Enterprise and IIS 7. That’s why we thought it could be a permissions problem, and then we have created a .user.ini file with the following content:
safe_mode= off
safe_mode_exec_dir= off
Unfortunately it doesn’t work too.
Any suggestions?
Thanks in advance.
You are most probably working with Windows Azure Web Sites. This is a high-density shared hosting with tightened security. If you need things like shell_exec you shall move to Windows Azure Cloud Service (Web Role), where you have full control over the OS and web server / php settings.
Using Cloud Service you will be able to use shell_exec. However when you move to Cloud Service you have begin thinking of saving files in Azure Blob Storage, as the local storage for cloud service is:
Not persistent
not synchronized across role instances
If you want don't yet know what Role and Role Instance is, or are little confused, please go through this article.

Categories