Re: [PHP] create file permission problem (solved)

2007-06-17 Thread Daniel Brown

On 6/15/07, tedd [EMAIL PROTECTED] wrote:

At 6:56 PM -0400 6/15/07, Daniel Brown wrote:


I don't think it's PAM-compliant to use a single-quote character
in your passwords, Tedd.  ;-P

--
Daniel P. Brown

Daniel:

Bzzzet, thanks for trying.

Let me explain again, maybe I did explain myself well.

In the show-code folder (link below) is a php file entitled a.php.
Inside that file are password and user ID variables. They don't mean
anything, nor do they do anything, but they are there.

Now, I did say that you have all the tools you need at the site to
discover what these values are. Can you do it?

Again, here's the link:

http://sperling.com/a/show-code/

Is this trivial or not?

Cheers,

tedd
--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com



   Tedd,

   You may not have noticed the fact that the joke I made was
directly-related to the content within the file.  I just didn't want
to post it to the list in case anyone else was trying.  It only took
about 90 seconds to get the data.  The password has a single-quote in
it (hence the non-PAM-compliant crack).  Also, is it necessary to have
the space before the $id tag?  Aren't $id fields usually placed prior
to the $password field?  And finally, shouldn't the phrase end with a
question mark, considering it's an inquiry and not a statement?

   That should suffice right?  ;-P

--
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] create file permission problem (solved)

2007-06-15 Thread tedd

At 1:06 PM -0400 6/14/07, Daniel Brown wrote:

   For the sake of people reading the archives now (and in years to
come), what was the cause of the problem, Tedd?



Daniel:

Ok, good point -- I would have liked to have this example to review.

I'm not sure of the problems I had, because they were a comedy of 
errors, but the following is my solution.


If anyone finds anything wrong, or if I have misstated something, 
please feel free to comment or correct me. Remember, this works for 
me, but perhaps not for others.


Cheers,

tedd

--- here's the code, please watch for line breaks ---


?php

/* Virtual Host -- how to create and/or write to file

To open a file for writing requires that you change its permissions to 0777.
If the file is not there, then to create one requires that you change 
its parent

directory to 0777 and then create the file.

The following code works for me.
*/

include('config.php'); // get your FTP password and user id
$server= 'ftp.yourdomain.com'; // your domain name
$path = 'httpdocs/read-write/test/'; // path to the folder test

$folder = 'test/';   // folder name
$filename = 'my.txt'; // file name
$tpath = $path . $filename; // total path for file

$contents = This is my text; // give the file some text

$connection = ftp_connect($server);  // connection
$result = ftp_login($connection, $user, $pass);  // login to ftp server

if ((!$connection) || (!$result))
{
echo ('pERROR/p');
}
else
{
//---
echo(Open connectionbr/);

echo(Change parent directory permission to 0777 for writingbr/);
	$str=CHMOD 0777 . $path;	 // change permission for 
directory to 0777

ftp_site($connection, $str);

echo(Checking to see if file existbr/);
if (is_file($folder . $filename))
{
echo(File found br/);
}
else
{
echo(File not foundbr/);
echo(Creating file -- $filenamebr/);
}
//---
echo(Opening and Writing file -- $filenamebr/);

$file = fopen( $folder . $filename, w ); // open file
fwrite( $file, $contents); // write file
fclose( $file ); // close file

echo(Change permission of file to 0644br/);
chmod($folder .  $filename, 0644);

	echo(Change permission for parent directory back to 0755br/); 
	$str=CHMOD 0755 . $path;	 // change permission for 
directory back to 755

ftp_site($connection, $str);

echo(Close connectionbr/br/);
ftp_close($connection); // close connection

//---
echo(hrbr/Reading file:br/);

$filesize = filesize($folder . $filename);
$file = fopen($folder .  $filename, r );
$text = fread( $file, $filesize );
fclose( $file );

echo( File name: $filenamebr/ );
echo( File size: $filesize bytesbr/ );
echo( File contents:br/$textbr/ );
}
?

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] create file permission problem (solved)

2007-06-15 Thread Daniel Brown

On 6/15/07, tedd [EMAIL PROTECTED] wrote:

At 1:06 PM -0400 6/14/07, Daniel Brown wrote:
For the sake of people reading the archives now (and in years to
come), what was the cause of the problem, Tedd?


Daniel:

Ok, good point -- I would have liked to have this example to review.

I'm not sure of the problems I had, because they were a comedy of
errors, but the following is my solution.

If anyone finds anything wrong, or if I have misstated something,
please feel free to comment or correct me. Remember, this works for
me, but perhaps not for others.

Cheers,

tedd

--- here's the code, please watch for line breaks ---


?php

/* Virtual Host -- how to create and/or write to file

To open a file for writing requires that you change its permissions to 0777.
If the file is not there, then to create one requires that you change
its parent
directory to 0777 and then create the file.

The following code works for me.
*/

include('config.php'); // get your FTP password and user id
$server= 'ftp.yourdomain.com'; // your domain name
$path = 'httpdocs/read-write/test/'; // path to the folder test

$folder = 'test/';   // folder name
$filename = 'my.txt'; // file name
$tpath = $path . $filename; // total path for file

$contents = This is my text;   // give the file some text

$connection = ftp_connect($server);  // connection
$result = ftp_login($connection, $user, $pass);  // login to ftp server

if ((!$connection) || (!$result))
{
echo ('pERROR/p');
}
else
{
//---
echo(Open connectionbr/);

echo(Change parent directory permission to 0777 for writingbr/);
$str=CHMOD 0777 . $path;   // change permission for
directory to 0777
ftp_site($connection, $str);

echo(Checking to see if file existbr/);
if (is_file($folder . $filename))
{
echo(File found br/);
}
else
{
echo(File not foundbr/);
echo(Creating file -- $filenamebr/);
}
//---
echo(Opening and Writing file -- $filenamebr/);

$file = fopen( $folder . $filename, w );   // open file
fwrite( $file, $contents); // write file
fclose( $file ); // close file

echo(Change permission of file to 0644br/);
chmod($folder .  $filename, 0644);

echo(Change permission for parent directory back to 0755br/);
$str=CHMOD 0755 . $path;   // change permission for
directory back to 755
ftp_site($connection, $str);

echo(Close connectionbr/br/);
ftp_close($connection); // close connection

//---
echo(hrbr/Reading file:br/);

$filesize = filesize($folder . $filename);
$file = fopen($folder .  $filename, r );
$text = fread( $file, $filesize );
fclose( $file );

echo( File name: $filenamebr/ );
echo( File size: $filesize bytesbr/ );
echo( File contents:br/$textbr/ );
}
?

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com



   Sounds like it was the decimal (three-bit, incorrect) versus octal
(four bit, correct) chmod(); value after all.  Boo-yaa and stuff.

   Thanks for posting it.  I don't know about ya'all, but I hate when
I search the web, find people with the exact problem I'm having, and
there's no solutions posted.  It seems to happen any time I search for
the resolution to a problem I just can't figure out.

--
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] create file permission problem (solved)

2007-06-15 Thread tedd

At 5:31 PM -0400 6/15/07, Daniel Brown wrote:


   Sounds like it was the decimal (three-bit, incorrect) versus octal
(four bit, correct) chmod(); value after all.  Boo-yaa and stuff.


Nope, that was one of the things I had right from the get-go.

The biggest problems I had were:

a) getting the file paths right.

b) understanding that if a file is not there, then you must to change 
the permissions of the parent folder/directory to be able to create a 
file.


c) understanding that working with files on a virtual host is quite 
different than what's normally posted as a read/write solution.


d) understanding that I must use the ftp_connect() to connect with my 
virtual host for these types of operations and that's different than 
what's normally posted as a read/write solution.


Oh, to see it run -- see here:

http://sperling.com/a/readwrite/

I had made it one of my show-code examples, like this:

http://sperling.com/a/show-code/

But, in doing so, I found that I had written code that would expose 
other php code in the folder if used cleverly. So I removed the 
offending code. But, it was an interesting experience.


If you want to try being clever, there is a file in the show-code 
folder entitled a.php -- tell me what it says. You have all the 
tools you need to review the php file..


Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] create file permission problem (solved)

2007-06-15 Thread Daniel Brown

On 6/15/07, tedd [EMAIL PROTECTED] wrote:

At 5:31 PM -0400 6/15/07, Daniel Brown wrote:

Sounds like it was the decimal (three-bit, incorrect) versus octal
(four bit, correct) chmod(); value after all.  Boo-yaa and stuff.

Nope, that was one of the things I had right from the get-go.

The biggest problems I had were:

a) getting the file paths right.

b) understanding that if a file is not there, then you must to change
the permissions of the parent folder/directory to be able to create a
file.

c) understanding that working with files on a virtual host is quite
different than what's normally posted as a read/write solution.

d) understanding that I must use the ftp_connect() to connect with my
virtual host for these types of operations and that's different than
what's normally posted as a read/write solution.

Oh, to see it run -- see here:

http://sperling.com/a/readwrite/

I had made it one of my show-code examples, like this:

http://sperling.com/a/show-code/

But, in doing so, I found that I had written code that would expose
other php code in the folder if used cleverly. So I removed the
offending code. But, it was an interesting experience.

If you want to try being clever, there is a file in the show-code
folder entitled a.php -- tell me what it says. You have all the
tools you need to review the php file..

Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




   I don't think it's PAM-compliant to use a single-quote character
in your passwords, Tedd.  ;-P

--
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] create file permission problem (solved)

2007-06-15 Thread tedd

At 6:56 PM -0400 6/15/07, Daniel Brown wrote:




   I don't think it's PAM-compliant to use a single-quote character
in your passwords, Tedd.  ;-P

--
Daniel P. Brown


Daniel:

Bzzzet, thanks for trying.

Let me explain again, maybe I did explain myself well.

In the show-code folder (link below) is a php file entitled a.php. 
Inside that file are password and user ID variables. They don't mean 
anything, nor do they do anything, but they are there.


Now, I did say that you have all the tools you need at the site to 
discover what these values are. Can you do it?


Again, here's the link:

http://sperling.com/a/show-code/

Is this trivial or not?

Cheers,

tedd
--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] create file permission problem

2007-06-14 Thread Daniel Brown

On 6/13/07, tedd [EMAIL PROTECTED] wrote:

At 1:37 PM -0400 6/13/07, Daniel Brown wrote:
On 6/13/07, tedd [EMAIL PROTECTED] wrote:
Hi Gang:

I'm sure this is obvious to most, but not to me.

I working on a virtual host.

If I want to save data in a file, I can ftpconnect(); change the
permissions of an existing file from 0755 to 0777; write to the file;
and change the permissions of the file back to 0755 -- no problem.

However, if a file is not there, then I can create one. However, the
permissions of the file will be automagically set to 0600 and as
such, I can't change them via ftpconnect(). In other words, I can't
FTP in to my site and change the permissions of a file I created. I
can delete the file, but that's all.

How do you guys create a file and set its permissions working on a
virtual host via php?

-snip-

Two quick questions

Is the PHP script running ftpconnect() using a valid FTP account
with privileges to own/share a file on the system?

How are you creating the file on the FTP server?

--
Daniel P. Brown


Daniel:

1. I'm not sure -- from within a script, I ftpconnect() with user and
password and can change permissions of directories with no problems
-- can I do that without a valid FTP account?

2. From within a script, I change the permission of the parent
directory and open a file. If it's there, then I can read from or
write to it. If it's not there, then the operation ( fopen( $folder .
$filename, w )) creates the file and I can write to it then read
from it.

I have now figured out how to get the created file to 644 permission
and that's sufficient. I'm still not able to get permissions to 755,
but really don't need to, just wondering how.

Thanks,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com



   When you're chmod()'ing your file, are you doing it correctly,
with the four-bit (octal) number as opposed to the common use of the
three-bit (decimal) number?

   Id est:
   chmod($somefile, 0755); // The correct way
   chmod($somefile, 755); // Should work, but is still
technically incorrect

--
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] create file permission problem (solved)

2007-06-14 Thread tedd

Daniel, Robert, Richard, and Al:

Thanks, all is better. I can create and change file and folder 
permission as I want now.


Cheers,

tedd
--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] create file permission problem (solved)

2007-06-14 Thread Daniel Brown

   For the sake of people reading the archives now (and in years to
come), what was the cause of the problem, Tedd?

On 6/14/07, tedd [EMAIL PROTECTED] wrote:

Daniel, Robert, Richard, and Al:

Thanks, all is better. I can create and change file and folder
permission as I want now.

Cheers,

tedd
--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





--
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] create file permission problem

2007-06-13 Thread tedd

Hi Gang:

I'm sure this is obvious to most, but not to me.

I working on a virtual host.

If I want to save data in a file, I can ftpconnect(); change the 
permissions of an existing file from 0755 to 0777; write to the file; 
and change the permissions of the file back to 0755 -- no problem.


However, if a file is not there, then I can create one. However, the 
permissions of the file will be automagically set to 0600 and as 
such, I can't change them via ftpconnect(). In other words, I can't 
FTP in to my site and change the permissions of a file I created. I 
can delete the file, but that's all.


How do you guys create a file and set its permissions working on a 
virtual host via php?


Cheers,

tedd

PS: If I remember correctly, it was pretty easy in perl. Just try to 
open/write a file and if it wasn't there, it created one for you. 
But, it's been years since I did any perl stuff -- could be wrong.


--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] create file permission problem

2007-06-13 Thread Daniel Brown

On 6/13/07, tedd [EMAIL PROTECTED] wrote:

Hi Gang:

I'm sure this is obvious to most, but not to me.

I working on a virtual host.

If I want to save data in a file, I can ftpconnect(); change the
permissions of an existing file from 0755 to 0777; write to the file;
and change the permissions of the file back to 0755 -- no problem.

However, if a file is not there, then I can create one. However, the
permissions of the file will be automagically set to 0600 and as
such, I can't change them via ftpconnect(). In other words, I can't
FTP in to my site and change the permissions of a file I created. I
can delete the file, but that's all.

How do you guys create a file and set its permissions working on a
virtual host via php?

Cheers,

tedd

PS: If I remember correctly, it was pretty easy in perl. Just try to
open/write a file and if it wasn't there, it created one for you.
But, it's been years since I did any perl stuff -- could be wrong.

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




   Two quick questions

   Is the PHP script running ftpconnect() using a valid FTP account
with privileges to own/share a file on the system?

   How are you creating the file on the FTP server?

--
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] create file permission problem

2007-06-13 Thread Robert Cummings
On Wed, 2007-06-13 at 13:13 -0400, tedd wrote:
 Hi Gang:
 
 I'm sure this is obvious to most, but not to me.
 
 I working on a virtual host.
 
 If I want to save data in a file, I can ftpconnect(); change the 
 permissions of an existing file from 0755 to 0777; write to the file; 
 and change the permissions of the file back to 0755 -- no problem.
 
 However, if a file is not there, then I can create one. However, the 
 permissions of the file will be automagically set to 0600 and as 
 such, I can't change them via ftpconnect(). In other words, I can't 
 FTP in to my site and change the permissions of a file I created. I 
 can delete the file, but that's all.
 
 How do you guys create a file and set its permissions working on a 
 virtual host via php?

See the following functions:

http://ca.php.net/manual/en/function.umask.php
http://ca.php.net/manual/en/function.chmod.php

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] create file permission problem

2007-06-13 Thread Richard Lynch
On Wed, June 13, 2007 12:13 pm, tedd wrote:
 I'm sure this is obvious to most, but not to me.

 I working on a virtual host.

 If I want to save data in a file, I can ftpconnect(); change the
 permissions of an existing file from 0755 to 0777; write to the file;
 and change the permissions of the file back to 0755 -- no problem.

 However, if a file is not there, then I can create one. However, the
 permissions of the file will be automagically set to 0600 and as
 such, I can't change them via ftpconnect(). In other words, I can't
 FTP in to my site and change the permissions of a file I created. I
 can delete the file, but that's all.

 How do you guys create a file and set its permissions working on a
 virtual host via php?

When your script creates the file, it creates it as itself, and not as
'you', which means that 'you' probably can't change it.

Fortunately, your php script owns the file, and it CAN change it.

In particular, before your script creates the file, it can use
http://php.net/umask to define what permissions the file should have,
or, after it's created, it can change the permissions with
http://php.net/chmod

 PS: If I remember correctly, it was pretty easy in perl. Just try to
 open/write a file and if it wasn't there, it created one for you.
 But, it's been years since I did any perl stuff -- could be wrong.

If Perl is running as 'you' then you'd have an easier time...

But if Perl was, say, mod_perl and running as the Apache user, you'd
be in the exact same boat as you are now.

PHP vs Perl is pretty irrelevant.

It's about who created the file with which permissions, and who's
trying to access it.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] create file permission problem

2007-06-13 Thread Daniel Brown

On Wed, June 13, 2007 12:13 pm, tedd wrote:
 If I want to save data in a file, I can ftpconnect(); change the
 permissions of an existing file from 0755 to 0777; write to the file;
 and change the permissions of the file back to 0755 -- no problem.


On 6/13/07, Richard Lynch [EMAIL PROTECTED] wrote:

When your script creates the file, it creates it as itself, and not as
'you', which means that 'you' probably can't change it.


   Rich,

   If he's doing it with ftpconnect();, it's a matter of the login
information supplied for the socket connection via the function, not
who the script is running as.  However, on a slightly different note,
you can (once again, referring to my post from the archives) `chmod
6755 scriptname.php` where scriptname.php is the name of the file
creating the file, if on the same (*nix-like) server as the files
being created.  If the server is set up properly, then chmod'ing it
like that sets the first permission bit to execute the script as the
user and group (with inherent permissions), as opposed to running as
`nobody`, `apache`, `httpd`, `daemon`, or *gulp!* `root`.

--
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] create file permission problem

2007-06-13 Thread tedd

At 1:37 PM -0400 6/13/07, Daniel Brown wrote:

On 6/13/07, tedd [EMAIL PROTECTED] wrote:

Hi Gang:

I'm sure this is obvious to most, but not to me.

I working on a virtual host.

If I want to save data in a file, I can ftpconnect(); change the
permissions of an existing file from 0755 to 0777; write to the file;
and change the permissions of the file back to 0755 -- no problem.

However, if a file is not there, then I can create one. However, the
permissions of the file will be automagically set to 0600 and as
such, I can't change them via ftpconnect(). In other words, I can't
FTP in to my site and change the permissions of a file I created. I
can delete the file, but that's all.

How do you guys create a file and set its permissions working on a
virtual host via php?

-snip-


   Two quick questions

   Is the PHP script running ftpconnect() using a valid FTP account
with privileges to own/share a file on the system?

   How are you creating the file on the FTP server?

--
Daniel P. Brown



Daniel:

1. I'm not sure -- from within a script, I ftpconnect() with user and 
password and can change permissions of directories with no problems 
-- can I do that without a valid FTP account?


2. From within a script, I change the permission of the parent 
directory and open a file. If it's there, then I can read from or 
write to it. If it's not there, then the operation ( fopen( $folder . 
$filename, w )) creates the file and I can write to it then read 
from it.


I have now figured out how to get the created file to 644 permission 
and that's sufficient. I'm still not able to get permissions to 755, 
but really don't need to, just wondering how.


Thanks,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php