• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

CGI for MY FILE MANAGER

Originally posted by fury


isn't it elsif in perl?

i'm an idiot... half a year of PHP and no perl has gotten to me.. :mad:

yupapa, just PM me the section you added for the permissions.
 
it should be:

#var

$mode = (stat(test.htm))[2];
$owner_permissions = ($mode & 0777) / 100 % 10;
$group_permissions = ($mode & 0777) / 10 % 10;
$other_permissions = ($mode & 0777) % 10;

#owner
if ($owner_permissions==7) print "drwx";
elsif ($owner_permissions==6) print "-rw-";
elsif ($owner_permissions==5) print "-r-x";
elsif ($owner_permissions==4) print "--wx";
elsif ($owner_permissions==3) print "-r--";
elsif ($owner_permissions==2) print "--w-";
elsif ($owner_permissions==1) print "---x";
else print "---";

#group/other permissions
if ($group_permissions==7) print "rwx";
elsif ($group_permissions==6) print "rw-";
elsif ($group_permissions==5) print "r-x";
elsif ($group_permissions==4) print "-wx";
elsif ($group_permissions==3) print "r--";
elsif ($group_permissions==2) print "-w-";
elsif ($group_permissions==1) print "--x";
else print "---";

if ($other_permissions==7) print "rwx";
elsif ($other_permissions==6) print "rw-";
elsif ($other_permissions==5) print "r-x";
elsif ($other_permissions==4) print "-wx";
elsif ($other_permissions==3) print "r--";
elsif ($other_permissions==2) print "-w-";
elsif ($other_permissions==1) print "--x";
else print "---";



i guess that should be it :mad:, ask lucifer for anything else, i'm not to sure how to go about the directory thing. i'm not a perl person.
 
You need the curly braces in perl... :)

Example:
if ($owner_permissions==7) { print "drwx"; }

-mk
atlascgi.com
 
Ya!
But still doesn't work!!


$mode = (stat($dir))[2];
$owner_permissions = ($mode & 0777) / 100 % 10;
$group_permissions = ($mode & 0777) / 10 % 10;
$other_permissions = ($mode & 0777) % 10;

#owner
if ($owner_permissions==7) {
print "drwx";
} elsif {
($owner_permissions==6) print "-rw-";
} elsif { ($owner_permissions==5) print "-r-x";
} elsif { ($owner_permissions==4) print "--wx";
} elsif { ($owner_permissions==3) print "-r--";
} elsif { ($owner_permissions==2) print "--w-";
} elsif { ($owner_permissions==1) print "---x";
} else {
print "---";
}

#group/other permissions
if ($group_permissions==7) {
print "rwx";
} elsif {
($owner_permissions==6) print "-rw-";
} elsif { ($group_permissions==5) print "-r-x";
} elsif { ($group_permissions==4) print "--wx";
} elsif { ($group_permissions==3) print "-r--";
} elsif { ($group_permissions==2) print "--w-";
} elsif { ($group_permissions==1) print "---x";
} else {
print "---";
}

if ($other_permissions==7) print "rwx";
print "drwx";
} elsif {
($other_permissions==6) print "-rw-";
} elsif { ($other_permissions==5) print "-r-x";
} elsif { ($other_permissions==4) print "--wx";
} elsif { ($other_permissions==3) print "-r--";
} elsif { ($other_permissions==2) print "--w-";
} elsif { ($other_permissions==1) print "---x";
} else {
print "---";
}
 
Originally posted by YUPAPA
Ya!
But still doesn't work!!


#owner
if ($owner_permissions==7) {
print "drwx";
} elsif {
($owner_permissions==6) print "-rw-";
} elsif { ($owner_permissions==5) print "-r-x";
} elsif { ($owner_permissions==4) print "--wx";
} elsif { ($owner_permissions==3) print "-r--";
} elsif { ($owner_permissions==2) print "--w-";
} elsif { ($owner_permissions==1) print "---x";
} else {
print "---";
}


use
#owner
if ($owner_permissions==7) {print "drwx"; }
elsif ($owner_permissions==6) {print "-rw-"; }
elsif ($owner_permissions==5) {print "-r-x"; }
elsif ($owner_permissions==4) {print "--wx"; }
elsif ($owner_permissions==3) {print "-r--"; }
elsif ($owner_permissions==2) {print "--w-"; }
elsif ($owner_permissions==1) {print "---x"; }
else { print "---"; }

notice where the {} are

if (condition) {block}

Yupapa if you are new to this perl stuff be aware that you can make some big holes in your security if you do some silly things like `$something_from_a_form` so I'd advise getting it checked over by someone who knows about these things else you could have big problems. It's good that you are trying - keep working at it :)
 
Originally posted by lucifer

Yupapa if you are new to this perl stuff be aware that you can make some big holes in your security if you do some silly things like `$something_from_a_form` so I'd advise getting it checked over by someone who knows about these things else you could have big problems. at it

That is exactly he accidently discovered yesterday. So is perl so insercure that anyone can program a malicios script and use it to do anything he wants on the server?
 
it depends on the permissions the script has and who it runs as.

on linux etc if I write a script and it runs as apache then it can't do much as it can only read/delete files that have those permissions. If it runs as me then it can read/delete all my files. but I can't make my script run as root and kill the whole system.

on windows I'm not sure but I suspect you could probably format the c: drive as it's never struck me as that secure. not sure of win NT/2000

the main problem with scripts is people who write ones that use loads of resources. or open security holes. perl can be secure more so than php. but so much depends on how the server is set up. eg. I used to be able to travel all over my server using ftp and look at anyone else on the servers files. now I can't as I'm forced to live in my little area and can only look in my directories. because of this I can now have passwords in php files and others on the server can't just wander over and take a look (apart from sys admin).
 
Frank!!!
The permission is different. The CGI-BIN DIrectory has a permission 0777, but it shows a different permission on the file manager.

Here is my code:

### Some code here to read all the directories... now $dir is equal to 'cgi-bin' ###

$mode = (stat($dir))[2];
$owner_permissions = ($mode & 0777) / 100 % 10;
$group_permissions = ($mode & 0777) / 10 % 10;
$other_permissions = ($mode & 0777) % 10;

#owner
if ($owner_permissions==7) {$owner_value = "drwx"; }
elsif ($owner_permissions==6) {$owner_value = "-rw-"; }
elsif ($owner_permissions==5) {$owner_value = "-r-x"; }
elsif ($owner_permissions==4) {$owner_value = "--wx"; }
elsif ($owner_permissions==3) {$owner_value = "-r--"; }
elsif ($owner_permissions==2) {$owner_value = "--w-"; }
elsif ($owner_permissions==1) {$owner_value = "---x"; }
else { $owner_value = "---"; }

#group
if ($group_permissions==7) {$group_value = "drwx"; }
elsif ($group_permissions==6) {$group_value = "-rw-"; }
elsif ($group_permissions==5) {$group_value = "-r-x"; }
elsif ($group_permissions==4) {$group_value = "--wx"; }
elsif ($group_permissions==3) {$group_value = "-r--"; }
elsif ($group_permissions==2) {$group_value = "--w-"; }
elsif ($group_permissions==1) {$group_value = "---x"; }
else { $group_value = "---"; }

#other
if ($other_permissions==7) {$other_value = "drwx"; }
elsif ($other_permissions==6) {$other_value = "-rw-"; }
elsif ($other_permissions==5) {$other_value = "-r-x"; }
elsif ($other_permissions==4) {$other_value = "--wx"; }
elsif ($other_permissions==3) {$other_value = "-r--"; }
elsif ($other_permissions==2) {$other_value = "--w-"; }
elsif ($other_permissions==1) {$other_value = "---x"; }
else { $other_value = "---"; }

print "$owner_value$group_value$other_value";
 
this should do it

Code:
$mode = (stat($dir))[2]; 

$owner_permissions = ($mode & 0700)/64;
$group_permissions = ($mode & 070)/8;
$other_permissions = ($mode & 07);

print "owner $owner_permissions : group $group_permissions : others (public)  $other_permissions 
";
 
So Lucifer, you are Frank?

Anyways I always thought once an account it setup in linux it's so strict that you can't venture out of the directory you are assigned for eg /home/actionhero. Only you can see what directories are there but can't see any file. I thought that came with the default install.
 
just remember they are in oct (base 8) which is always a bit confussing to me i find hex so much easier
 
Nice file manager

Very nice. It actually works with my browser (Planetweb 2.6 on Dreamcast). There's not many that do.

:) :) :)
 
Back
Top