Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Modules
Author Message
California
Hangin' Around



Joined: Mar 24, 2005
Posts: 28

PostPosted: Thu Mar 24, 2005 12:30 am Reply with quote

I am working on limiting admin access to a module so only the super admin or content admin has access. I am using the following code but it is denying access to everyone.

Code:
}

$aid = trim($aid);
$result = sql_query("select radmincontent, radminsuper from ".$prefix."_authors where aid='$aid'", $dbi);
list($radmincontent, $radminsuper) = sql_fetch_row($result, $dbi);
if (($radmincontent==1) OR ($radminsuper==1)) {


The code works on other modules fine so I am wondering if someone can help me figure out why it is not working in this specific module. Here is some more of the module code including above:

Code:
if (!eregi("modules.php", $_SERVER['PHP_SELF'])) {

    die ("You can't access this file directly...");
 }
$aid = trim($aid);
$result = sql_query("select radmincontent, radminsuper from ".$prefix."_authors where aid='$aid'", $dbi);
list($radmincontent, $radminsuper) = sql_fetch_row($result, $dbi);
if (($radmincontent==1) OR ($radminsuper==1)) {

require_once("mainfile.php");
$module_name = basename(dirname(__FILE__));
get_lang($module_name);
$pagetitle = "- "._IPTRACKING."";
if(is_user($user)) {
    if($cookie[9]=="") $cookie[9]=$Default_Theme;
    if(!$file=@opendir("themes/$cookie[9]")) {
   $ThemeSel = $Default_Theme;
    } else {
   $ThemeSel = $cookie[9];
    }
} else {
    $ThemeSel = $Default_Theme;
}

$now = date("d-m-Y");
$dot = explode ("-",$now);
$nowdate = $dot[0];
$nowmonth = $dot[1];
$nowyear = $dot[2];


Last edited by California on Fri Mar 25, 2005 4:14 pm; edited 1 time in total 
View user's profile Send private message
sixonetonoffun
Spouse Contemplates Divorce



Joined: Jan 02, 2003
Posts: 2496

PostPosted: Thu Mar 24, 2005 7:49 am Reply with quote

If its in 7.6 the authors table had the modules removed. Look at the News module as an example of how to check the permissions.

_________________
[b][size=5]openSUSE 11.4-x86 | Linux 2.6.37.1-1.2desktop i686 | KDE: 4.6.41>=4.7 | XFCE 4.8 | AMD Athlon(tm) XP 3000+ | MSI K7N2 Delta-L | 3GB Black Diamond DDR
| GeForce 6200@433Mhz 512MB | Xorg 1.9.3 | NVIDIA 270.30[/size:2b8 
View user's profile Send private message
California







PostPosted: Thu Mar 24, 2005 12:46 pm Reply with quote

It is in 7.0

I took the above code in the first block from a stock module (content) that came with 7.0 and it works with some other modules but not with this module.

It seems to be having trouble looking up the author information as it denies access to everyone even super admins so there must be something conflicting or I made a mistake.

I do not understand some of the code below where it processes cookies and users so I am not sure if that is causing the trouble.

Any help would be appreciated. The author of the module is no where to be found, I already tried that.
 
Raven
Site Admin/Owner



Joined: Aug 27, 2002
Posts: 17088

PostPosted: Thu Mar 24, 2005 12:54 pm Reply with quote

Try placing this statement after the $aid = trim($aid); to see if $aid is resolving.
die('aid = '.$aid);

If it is, then change this
Code:
$result = sql_query("select radmincontent, radminsuper from ".$prefix."_authors where aid='$aid'", $dbi);
to
Code:
$result = mysql_query("select radmincontent, radminsuper from ".$prefix."_authors where aid='$aid'") or die("MySQL said: ".mysql_error());
and see if there's an error that prints out.
 
View user's profile Send private message
California







PostPosted: Fri Mar 25, 2005 12:48 am Reply with quote

Raven wrote:
Try placing this statement after the $aid = trim($aid); to see if $aid is resolving.
die('aid = '.$aid);


I only get aid = (with no result)

I went back and checked the code again and it is the same as my content module which works as expected...

I tried
Code:
$result = mysql_query("select radmincontent, radminsuper from ".$prefix."_authors where aid='$aid'") or die("MySQL said: ".mysql_error());
and got the "access denied" message intended for someone without proper authorization. I was signed in as a superadmin. I clicked the content module where I got the code and got access but it is still not working in this IP_Tracking module.
 
California







PostPosted: Fri Mar 25, 2005 1:18 am Reply with quote

I tried using nuke_authors for the table name instead of using the ".$prefix."_authors and here is what I got:

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /var/www/html/includes/sql_layer.php on line 286
Access Denied

I also tried using the global $prefix to find the _authors table but must be doing it wrong as I get an error similar to above.
 
Raven







PostPosted: Fri Mar 25, 2005 10:15 am Reply with quote

It just dawned on me that you are trying to use administrator code in a module, rather than from the admin menu. $aid is set in admin.php, not modules.php. So, you need to have this code at the top. I have included both code for $user and $admin check. You can decide which to use.
Code:
if (!eregi("modules.php", $_SERVER['PHP_SELF'])) {

    die ("You can't access this file directly...");
}
require_once("mainfile.php");
$module_name = basename(dirname(__FILE__));
get_lang($module_name);
$pagetitle = "- "._IPTRACKING."";
if (is_admin($admin)) {
   cookiedecode($admin);
    $aid = $cookie[0];
}
if (is_user($user)) {
   cookiedecode($user);
    $aid = $cookie[1];
}
 
California







PostPosted: Fri Mar 25, 2005 4:13 pm Reply with quote

Yes that worked. Thank you for the help.

I was focusing on the ".$prefix." as the problem and thought the $aid was defined in the mainfile.php which I tried to include but it did not work without the proper cookiedecode.

I have chat moderators which are getting logged in as admins due to a glitch in the FlashChat login after their session expires so the admin designation in the modules control panel was not enough (FYI incase anyone reading this was wondering why I am using administrator code in a module).

Thanks again Raven!
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Modules

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©