162 lines
3.5 KiB
PHP
162 lines
3.5 KiB
PHP
<?php
|
|
// File name: guest.inc.php
|
|
// Description: PHP subroutines to bypass real operations if the user is guest
|
|
// Date: 2001-02-13
|
|
// Author: imacat <imacat@pristine.com.tw>
|
|
// Copyright: Copyright (C) 2001-2007 Pristine Communications
|
|
|
|
// Set the include path
|
|
if (!defined("INCPATH_SET")) {
|
|
require_once dirname(__FILE__) . "/incpath.inc.php";
|
|
}
|
|
// Referenced subroutines
|
|
require_once "monica/actlog.inc.php";
|
|
require_once "monica/chkpriv.inc.php";
|
|
require_once "monica/login.inc.php";
|
|
require_once "monica/mkalldir.inc.php";
|
|
require_once "monica/pagefunc.inc.php";
|
|
require_once "monica/rmalldir.inc.php";
|
|
require_once "monica/rmofile.inc.php";
|
|
require_once "monica/runcmd.inc.php";
|
|
require_once "monica/sql.inc.php";
|
|
require_once "monica/xfileio.inc.php";
|
|
|
|
// Constant symbols
|
|
if (!defined("GUEST_GROUP")) {
|
|
define("GUEST_GROUP", "guests");
|
|
}
|
|
|
|
// is_guest: If the user is a guest (by the user id)
|
|
function is_guest($user = null)
|
|
{
|
|
// Cache the result
|
|
static $cache = array();
|
|
// Default to the current logged-in user
|
|
if (is_null($user) || $user == get_login_sn()) {
|
|
return !is_su() && in_array(GUEST_GROUP, get_login_groups());
|
|
}
|
|
// Return the cache
|
|
if (array_key_exists($user, $cache)) {
|
|
return $cache[$user];
|
|
}
|
|
// Super user is never a guest
|
|
if (is_su($user)) {
|
|
$cache[$user] = false;
|
|
return false;
|
|
}
|
|
// Obtain the groups
|
|
$groups = user_parent_groups($user);
|
|
$cache[$user] = in_array(GUEST_GROUP, $groups);
|
|
return $cache[$user];
|
|
}
|
|
|
|
// gunlink: unlink() if the user is not a guest
|
|
function gunlink($file)
|
|
{
|
|
if (!is_guest()) {
|
|
unlink($file);
|
|
}
|
|
}
|
|
|
|
// gcopy: copy() if the user is not a guest
|
|
function gcopy($src, $dst)
|
|
{
|
|
if (!is_guest()) {
|
|
copy($src, $dst);
|
|
}
|
|
}
|
|
|
|
// gactlog: actlog() if the user is not a guest
|
|
function gactlog($msg, $user = null)
|
|
{
|
|
if (!is_guest()) {
|
|
actlog($msg, $user);
|
|
}
|
|
}
|
|
|
|
// gsql_query: sql_query() if the user is not a guest
|
|
function gsql_query($query)
|
|
{
|
|
if (!is_guest()) {
|
|
sql_query($query);
|
|
}
|
|
}
|
|
|
|
// gmkalldir: mkalldir() if the user is not a guest
|
|
function gmkalldir($dir)
|
|
{
|
|
if (!is_guest()) {
|
|
mkalldir($dir);
|
|
}
|
|
}
|
|
|
|
// grmalldir: rmalldir() if the user is not a guest
|
|
function grmalldir($dir)
|
|
{
|
|
if (!is_guest()) {
|
|
rmalldir($dir);
|
|
}
|
|
}
|
|
|
|
// grmoldpage: rmoldpage() if the user is not a guest
|
|
function grmoldpage($old, $new = null)
|
|
{
|
|
if (!is_guest()) {
|
|
rmoldpage($old, $new);
|
|
}
|
|
}
|
|
|
|
// grmoldfile: rmoldfile() if the user is not a guest
|
|
function grmoldfile($old, $new = null)
|
|
{
|
|
if (!is_guest()) {
|
|
rmoldfile($old, $new);
|
|
}
|
|
}
|
|
|
|
// goutpage: outpage() if the user is not a guest
|
|
function goutpage($html, $path, $lang = null)
|
|
{
|
|
if (!is_guest()) {
|
|
outpage($html, $path, $lang);
|
|
}
|
|
}
|
|
|
|
// gxfwrite: xfwrite() if the user is not a guest
|
|
function gxfwrite($dest, $content)
|
|
{
|
|
if (!is_guest()) {
|
|
xfwrite($dest, $content);
|
|
}
|
|
}
|
|
|
|
// gxfupdate: xfupdate() if the user is not a guest
|
|
function gxfupdate($file, $newcontent)
|
|
{
|
|
if (!is_guest()) {
|
|
xfupdate($file, $newcontent);
|
|
}
|
|
}
|
|
|
|
// gruncmd: runcmd() if the user is not a guest
|
|
function gruncmd($cmd, $stdin, &$stdout, &$stderr)
|
|
{
|
|
if (!is_guest()) {
|
|
return runcmd($cmd, $stdin, $stdout, $stderr);
|
|
} else {
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
// gxruncmd: xruncmd() if the user is not a guest
|
|
function gxruncmd($cmd, $stdin)
|
|
{
|
|
if (!is_guest()) {
|
|
return xruncmd($cmd, $stdin);
|
|
} else {
|
|
return "";
|
|
}
|
|
}
|
|
|
|
?>
|