The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 19, 2019, 06:16:37 AM

Login with username, password and session length


Pages: [1] 2
  Print  
Author Topic: why cant i read /proc/loadavg  (Read 5945 times)
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« on: November 24, 2008, 08:12:31 PM »

so on all my hosts i can run this with no issue.
echo file_get_contents('/proc/loadavg');

but on my dedi, I cannot. any ideas? it's centOS running plesk.
if I go to the file and vi it, i can seen the content of it fine. so what gives?
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #1 on: November 24, 2008, 10:07:27 PM »

Check perms. if the file is 700 or 600 then you when SSHd in will have privs to see it, but the no-privilege Apache daemon would not.

Set error_reporting to E_ALL and see what happens when you try to open it.
Try fopen on it as well and see if the error is the same.

Are you certain about the path to the file? I've gotten poopshooted by thinking I was in one place, but Apache/PHP saw my directory different.
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #2 on: November 25, 2008, 02:46:23 PM »

i get no error. nothing, zippo, nada.

 Huh?
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #3 on: November 25, 2008, 04:01:52 PM »

try fopen on the file and see what the resource handle is that comes back. If you get a zero, then error_reporting(E_ALL) will have something for you. Try the different access methods here: http://us.php.net/manual/en/function.fopen.php ... I'd say to try with a passive/shared read only.
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #4 on: November 25, 2008, 05:15:30 PM »

thats the thing, it comes back with NOTHING
not even a zero or space or anything at all.

apparently the file doesnt exist from PHP's point of view otherwise file_exists would return false
so its obviously a path issue. like PHP can't navigate to the root directory?

soooo this brings me to chroot.
how do I see what directory a user is chrooted to?
that would be odd, but you never know?

Code:
error_reporting(E_ALL);
if (file_exists('/proc/loadavg'))
{
echo "exists<br>";
}
$aaa = fopen('/proc/loadavg','r');
echo fread($aaa, filesize('/proc/loadavg'));
echo $aaa;
echo 'end';
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #5 on: November 25, 2008, 06:04:44 PM »

start here, what do you get?

Code:
<?php

$handle 
fopen('thefile.txt''r');
echo (
$handle) ? 'have handle' 'no handle';

?>


Oh, and just for giggles, create a brand 3 new text files right beside it with 600, 660, 666 perms and try the same.
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #6 on: November 25, 2008, 07:10:47 PM »

i get
600 nohandle
660 nohandle
666 have handle
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #7 on: November 25, 2008, 07:18:43 PM »

... and set as 666, then file_get_contents you receive nothing? How about the files right beside it with the same perms? Create the file as simply as a text file with "Hello World" in it with no CRLFs or anything other than those characters.

The good news is that since you received a handle with 666 it means that you and PHP are perceiving the Dirs the same way. (BTW - really shitty day, now into my 3rd Guinness + Vanilla vodka and working hard on incoherence, so apologies if I'm not making sense) try fread($handle, 4096) and fgets($handle) and see if you get anything on the NEW (hello world) file with 666.
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #8 on: November 25, 2008, 07:40:58 PM »

doing file_get_contents I also only get back the contents of the 666 file.
which of course is what should be happening, and works for any other file within my web folders, since thats what I am doing with other code anyway.

i cannot seem to get out of my web folder.
so I think that apache might be chroot to something other than root because when I run:

echo dirname(__FILE__);

i get:

/var/www/vhosts/mydomain.com/httpdocs


so um, wtf? why the hell would the host set up a dedi this way?
can I just chroot apache to the actual root? and how do I do that without completely pooching the system?
or can I do a symbolic link to the root or at least the proc folder?
of course only if that IS the issue.
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #9 on: November 25, 2008, 07:53:29 PM »

Sorry, perk's intellect has left the building. He'll have to re-read your post in the maņana. j'pologise.
« Last Edit: November 25, 2008, 07:55:00 PM by perkiset » Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #10 on: November 25, 2008, 08:09:55 PM »

no problem, no rush.

guiness and vanilla vodka? my initial reaction was bleh, but now that I think about it, thats probably pretty damn good. gonna have to try that some day.
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #11 on: November 25, 2008, 08:17:54 PM »

It's damn fine. but I've jumped to JD neat. Dont do more than a shot of vanil per pull of guin. Otherwise it's "drink" rather rahter than "colored guinness." But ah deligthful. laters!
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #12 on: November 27, 2008, 10:43:34 AM »

echo dirname(__FILE__);

i get:

/var/www/vhosts/mydomain.com/httpdocs

um im retarded. duh, thats the path from root...
So... back to the question of why i can't access the proc directory from php?
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #13 on: November 27, 2008, 11:01:55 AM »

The proc directory is under <where the PHP script is running> yes?

Then access it without the leading slash, because you want the relative dir from (where you currently) are.
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #14 on: November 27, 2008, 07:34:49 PM »

no the proc is off root.

but I guess i can put a symlink to it from my apache root. (how do I do that by the way?? )
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
Pages: [1] 2
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!