View Full Version : CGI for MY FILE MANAGER
YUPAPA
July 11th, 2001, 19:03
Hey NeedCGISpace or anyone,
do you know how to display the permission of the file?
for example, to display the permission of index.htm (-rw-r-r-), what the the code in Perl?
My File manager is here: http://www.yupapa.com/cgi-bin/manager.cgi
YUPAPA
July 11th, 2001, 19:06
My First thread and post in this forum
This is my second post!
lucifer
July 11th, 2001, 19:12
use stat function
YUPAPA
July 11th, 2001, 19:14
PLease tell me the code... I am just a beginner
lucifer
July 11th, 2001, 19:16
$mode = (stat($filename))[2];
printf "Permissions are %04o\n", $mode & 07777;
not in the format you want but you could sort it I'm sure
YUPAPA
July 11th, 2001, 19:30
Does it work for directory?
Howcome I get "16895" instead of "drwxrwxrwx" for my "cgi-bin" directory?
niv
July 11th, 2001, 19:39
Originally posted by lucifer
$mode = (stat($filename))[2];
printf "Permissions are %04o\n", $mode & 07777;
not in the format you want but you could sort it I'm sure
shouldn't it be
printf "Permissions are %04o\n", $mode & 0777;
?
niv
July 11th, 2001, 19:41
that and:
$owner_permissions = ($mode & 0777) / 100 % 10
$group_permissions = ($mode & 0777) / 10 % 10
$other_permissions = ($mode & 0777) % 10
(that should give you the permissions individually)
then use a system a if else system or something like it.
YUPAPA
July 11th, 2001, 19:45
so far example. for test.htm
the code is this:
$mode = (stat(test.htm))[2];
printf "Permissions are %04o\n", $mode & 0777;
$owner_permissions = ($mode & 0777) / 100 % 10
$group_permissions = ($mode & 0777) / 10 % 10
$other_permissions = ($mode & 0777) % 10
print "$owner_permissions $group_permissions $other_permissions ";
Right?
coolguy23
July 11th, 2001, 19:45
yo YUPAPA how does this file manager, do i just assign it to a directory or does it need password protected directories?
would you mind if i used it?
YUPAPA
July 11th, 2001, 19:47
You can test it out if you want
I am going to upgrade it by myself... I will make members login page, etc
niv
July 11th, 2001, 19:50
actually, that's pointless. here:
create a column for permissions btw,
$mode = (stat($filename))[2];
$owner_permissions = ($mode & 0777) / 100 % 10;
$group_permissions = ($mode & 0777) / 10 % 10;
$other_permissions = ($mode & 0777) % 10;
switch ($owner_permissions){
case 7: print "drwx"; break;
case 6: print "-rwx"; break;
case 5: print "-r-x"; break;
case 4: print "--wx"; break;
case 3: print "-r--"; break;
case 2: print "--w-"; break;
case 1: print "---x"; break;
default: print "----"; break;
}
switch ($group_permissions){
case 7: print "rwx"; break;
case 6: print "rwx"; break;
case 5: print "r-x"; break;
case 4: print "-wx"; break;
case 3: print "r--"; break;
case 2: print "-w-"; break;
case 1: print "--x"; break;
default: print "---"; break;
}
switch ($other_permissions){
case 7: print "rwx"; break;
case 6: print "rwx"; break;
case 5: print "r-x"; break;
case 4: print "-wx"; break;
case 3: print "r--"; break;
case 2: print "-w-"; break;
case 1: print "--x"; break;
default: print "---"; break;
}
the numbers in each of the cases correspond to the permissions for owner/group/other (default is 0). i might be wrong about these values (the verbal version of the permissions,) check with something before you enter that.
YUPAPA
July 11th, 2001, 19:57
Howcome I got internal serve error when I enter either
one of these?
switch ($owner_permissions){
case 7: print "drwx"; break;
case 6: print "-rwx"; break;
case 5: print "-r-x"; break;
case 4: print "--wx"; break;
case 3: print "-r--"; break;
case 2: print "--w-"; break;
case 1: print "---x"; break;
default: print "----"; break;
}
switch ($group_permissions){
case 7: print "rwx"; break;
case 6: print "rwx"; break;
case 5: print "r-x"; break;
case 4: print "-wx"; break;
case 3: print "r--"; break;
case 2: print "-w-"; break;
case 1: print "--x"; break;
default: print "---"; break;
}
switch ($other_permissions){
case 7: print "rwx"; break;
case 6: print "rwx"; break;
case 5: print "r-x"; break;
case 4: print "-wx"; break;
case 3: print "r--"; break;
case 2: print "-w-"; break;
case 1: print "--x"; break;
default: print "---"; break;
}
niv
July 11th, 2001, 20:11
aw crap...right that doesn't exist in perl, try this:
if ($owner_permissions==7) print "drwx";
else if ($owner_permissions==6) print "-rw-";
else if ($owner_permissions==5) print "-r-x";
else if ($owner_permissions==4) print "--wx";
else if ($owner_permissions==3) print "-r--";
else if ($owner_permissions==2) print "--w-";
else if ($owner_permissions==1) print "---x";
else print "----";
}
if ($group_permissions==7) print "rwx";
else if ($group_permissions==6) print "rw-";
else if ($group_permissions==5) print "r-x";
else if ($group_permissions==4) print "-wx";
else if ($group_permissions==3) print "r--";
else if ($group_permissions==2) print "-w-";
else if ($group_permissions==1) print "--x";
else print "---";
}
if ($other_permissions==7) print "rwx";
else if ($other_permissions==6) print "rw-";
else if ($other_permissions==5) print "r-x";
else if ($other_permissions==4) print "-wx";
else if ($other_permissions==3) print "r--";
else if ($other_permissions==2) print "-w-";
else if ($other_permissions==1) print "--x";
else print "---";
}
YUPAPA
July 11th, 2001, 20:16
I think you forgot the brackets
YUPAPA
July 11th, 2001, 20:26
still get an error :(
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 "---"; }
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 "---"; }
niv
July 11th, 2001, 20:26
those brackets are extraneous, get rid of them :p
niv
July 11th, 2001, 20:27
and it's else if, not elsif
YUPAPA
July 11th, 2001, 20:30
I still get the error
Premature end of script
niv
July 11th, 2001, 20:35
PM me that entire section that you've put in and i'll take a brief look at it :p
fury
July 11th, 2001, 20:37
Originally posted by needcgispace
and it's else if, not elsif
isn't it elsif in perl?
YUPAPA
July 11th, 2001, 20:37
The whole script?
Is about 500 lines
niv
July 11th, 2001, 20:42
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.
YUPAPA
July 11th, 2001, 20:57
?
OK now!
I sent you the thing!
niv
July 11th, 2001, 21:00
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.
atlas
July 11th, 2001, 21:14
You need the curly braces in perl... :)
Example:
if ($owner_permissions==7) { print "drwx"; }
-mk
atlascgi.com
YUPAPA
July 11th, 2001, 21:16
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 "---";
}
niv
July 11th, 2001, 21:48
*shrug* i have no idea why...
YUPAPA
July 11th, 2001, 22:06
OKOK... No problem..
I go ask Frank
LastActionHero
July 12th, 2001, 00:38
Originally posted by YUPAPA
OKOK... No problem..
I go ask Frank
Who's Frank? And Yupapa did you inform donhost about the security problem?
lucifer
July 12th, 2001, 07:02
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 :)
LastActionHero
July 12th, 2001, 07:38
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?
lucifer
July 12th, 2001, 08:00
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).
YUPAPA
July 12th, 2001, 09:00
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";
YUPAPA
July 12th, 2001, 09:01
You can check the file manager here:
http://www.yupapa.com/cgi-bin/manager.cgi
Just press the 'login' button to login, you do not have to type in anything for the password.
lucifer
July 12th, 2001, 10:03
this should do it
$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
";
YUPAPA
July 12th, 2001, 10:16
THANK YOU SO MUCH!
THANK YOU THANK YOU!
YUPAPA!!!!!
LastActionHero
July 12th, 2001, 10:19
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.
lucifer
July 12th, 2001, 10:20
just remember they are in oct (base 8) which is always a bit confussing to me i find hex so much easier
Hellbound
July 12th, 2001, 17:18
Very nice. It actually works with my browser (Planetweb 2.6 on Dreamcast). There's not many that do.
:) :) :)
YUPAPA
July 12th, 2001, 17:22
:)
gyrbo
July 13th, 2001, 06:45
Nice filemanager. Did you wrote it all by your self, or did you used an other script as base?
niv
July 13th, 2001, 07:13
actually, there's one thing messed up.
drwx-r-x-r-x and -rw---wx--wx
YUPAPA
July 13th, 2001, 12:09
Thanks!
Please check again... I think I corrected it~
Powered by vBulletin® Version 4.1.7 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.