Change file owner on php uploaded file

16 posts / 0 new
Last post
#1 Thu, 11/06/2008 - 12:48
AbitatSupport

Change file owner on php uploaded file

Not sure if this has anything to do with Virtualmin...

I have a PHP application that is encrypted, so I cannot modify the code.

It is running in a virtual server, as user www1. When this php app uploads a file, it is given the ownership of www1.

Is there a way in virtualmin to tell the virtual server what owner it should be running as so I can change the ownership of these uploaded files?

Thanks,

And sorry if this does not pertain to VirtualMin, I have been looking at other options and wonder if this is one of them.

Thu, 11/06/2008 - 14:07
ronald
ronald's picture

your php application should change permissions.
However you can try using webmins filemanager and select the upload directory. then set your permissions for it (under info) and click "files inherit values" or however it's called exactly..this might do the trick as well.

you might want to set ownership on that folder first, if not preferred then create a folder in it and set ownership on that one.

Fri, 11/07/2008 - 07:27 (Reply to #2)
ronald
ronald's picture

that sounds like a browser problem
per haps you can try firefox, it has a plugin for java.
Or other different modern browsers like opera, or chrome.

Also make sure it is activated in the properties of your browser

Fri, 11/07/2008 - 11:45 (Reply to #3)
ronald
ronald's picture

I once had the permissions changed by setting this through the filemanager, described above. It is odd that it didn't work for you on your server.
I needed that for a specific folder used by dolphin software which uploaded mediafiles.

Mon, 11/10/2008 - 08:26 (Reply to #4)
AbitatSupport

On Joes comment,

Any idea on configuring the php.ini file? I am googling because that seems the corect route,

However, I worry my tmp folder might get in the way before transferring to the actual upload folder...

Still googling. :)

Mon, 11/10/2008 - 09:08 (Reply to #5)
Joe
Joe's picture

Hmmm...I'm not seeing anything about it at the moment. Looks like maybe your application needs to handle setting the file mode, as there doesn't seem to be a mask setting in php.ini.

--

Check out the forum guidelines!

Mon, 11/10/2008 - 12:49 (Reply to #6)
ronald
ronald's picture

can you not create a php file and run that as a cron job every 5 minutes?

[code:1]
<?php
// Everything for owner, read and execute for owner's group
chmod("/somedir/somefile", 0750);
?>
[/code:1]

chmod would be preferred over umask, yes?

Fri, 11/07/2008 - 06:56
AbitatSupport

Thanks for the idea that sounds close to what I need, however,

When I go to Webmin -> Other -> File Manager, it says:

This module requires java to function, but your browser does not support java

And I have java installed and I use it on other sites, so I wonder why it is not detecting that properly now.

Fri, 11/07/2008 - 07:39 (Reply to #8)
Joe
Joe's picture

<div class='quote'>And I have java installed and I use it on other sites, so I wonder why it is not detecting that properly now.</div>

Are you sure? ;-)

In Firefox, you can check to see whether you have it by looking in the plugins page. Type &quot;about:plugins&quot; into the URL bar, and hit enter. I don't know how to do this in any other browser.

But, it seems to work with pretty much any of the official Sun Java plugins I've tried over the past several years. (It tries to work with the GNU Java plugin, but fails to actually run--the page just goes gray. But, so few of our users use that Java plugin version, it hasn't been a priority.)

--

Check out the forum guidelines!

Fri, 11/07/2008 - 08:03
AbitatSupport

Don't mind me, it is friday I guess :P

I had to reinstall it because I think I disabled it at some point.

Anyhoo, I found &quot;Files Inherit Group&quot; but that had no effect. I don't know if this really is a virtualmin thing so much as a linux/apache/php thing, but was hoping virtualmin could make it easy for me.

I just have no clue how to make this one php app upload as a different user.

To reitterate, I do not have access to the php code to modify the owner because the source is encrypted, so I have to do this some other way...

Anyone? :) Thanks for the help.

Fri, 11/07/2008 - 08:12 (Reply to #10)
andreychek

Well, suexec is a tool that has Apache execute code for a given Virtual Server as a given user.

Generally, said user is the Virtual Server owner.

What you might be able to do is create a Virtual Server for this particular application, and simply make sure that the suexec user for Virtual Server is the user you want it uploading files as.

That'd be easiest if that user were the Virtual Server owner, but you can also edit the Apache config and manually add the UID/GID you want it to switch to (but of course, you'll need to make sure the dir and files associated with it are the same).
-Eric

Fri, 11/07/2008 - 09:16
AbitatSupport

Sorry I am confusing things.

I actually need the app to upload a file with different permissions, not a different user.

Anyway, thanks for your guys' input.

Fri, 11/07/2008 - 09:29 (Reply to #12)
andreychek

Ahh, perhaps setting a umask will do what you're after. It allows you to change the default permissions for a directory and all directories under it for when files are created.

Some details are here:

http://www.cyberciti.biz/tips/understanding-linux-unix-umask-value-usage...
http://linux.die.net/man/1/umask

Fri, 11/07/2008 - 10:22
AbitatSupport

Ahhh good idea I'm learning lots!

I tried it but the uploaded files seem to ignore the umask. :(

Logged in as root and touching a new file listens to the umask, but still not the php app.

Fri, 11/07/2008 - 11:03 (Reply to #14)
andreychek

Hrm.

Yeah.

You may need to set the umask in Apache's init script.

It doesn't matter where in the init script, just somewhere near the top, and before Apache itself is launched. Then restart Apache and try it again.
-Eric

Fri, 11/07/2008 - 11:13 (Reply to #15)
Joe
Joe's picture

PHP doesn't respect the shell umask, I believe. I think you'll need to set it explicitly in the php.ini.

--

Check out the forum guidelines!

Topic locked