|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492 |
- <?php
- if (!defined('DEDEINC')) exit('dedebiz');
-
- session_start();
-
- function TestPurview($n)
- {
- $rs = FALSE;
- $purview = $GLOBALS['cuserLogin']->getPurview();
- if (preg_match('/admin_AllowAll/i', $purview)) {
- return TRUE;
- }
- if ($n == '') {
- return TRUE;
- }
- if (!isset($GLOBALS['groupRanks'])) {
- $GLOBALS['groupRanks'] = explode(' ', $purview);
- }
- $ns = explode(',', $n);
- foreach ($ns as $n) {
-
- if ($n == '') {
- continue;
- }
- if (in_array($n, $GLOBALS['groupRanks'])) {
- $rs = TRUE;
- break;
- }
- }
- return $rs;
- }
-
- function CheckPurview($n)
- {
- if (!TestPurview($n)) {
- ShowMsg("您没有权限执行此操作<br><br><a href='javascript:history.go(-1);'>点击返回上一页</a>", 'javascript:;');
- exit();
- }
- }
-
- function TestAdmin()
- {
- $purview = $GLOBALS['cuserLogin']->getPurview();
- if (preg_match('/admin_AllowAll/i', $purview)) {
- return TRUE;
- } else {
- return FALSE;
- }
- }
- $DedeUserCatalogs = array();
-
- function CheckCatalog($cid, $msg)
- {
- global $cfg_admin_channel, $admin_catalogs;
- if ($cfg_admin_channel == 'all' || TestAdmin()) {
- return TRUE;
- }
- if (!in_array($cid, $admin_catalogs)) {
- ShowMsg(" $msg <br><br><a href='javascript:history.go(-1);'>点击返回上一页</a>", 'javascript:;');
- exit();
- }
- return TRUE;
- }
-
- function AddMyAddon($fid, $filename)
- {
- $cacheFile = DEDEDATA.'/cache/addon-'.session_id().'.inc';
- if (!file_exists($cacheFile)) {
- $fp = fopen($cacheFile, 'w');
- fwrite($fp, '<'.'?php'."\r\n");
- fwrite($fp, "\$myaddons = array();\r\n");
- fwrite($fp, "\$maNum = 0;\r\n");
- fclose($fp);
- }
- include($cacheFile);
- $fp = fopen($cacheFile, 'a');
- $arrPos = $maNum;
- $maNum++;
- fwrite($fp, "\$myaddons[\$maNum] = array('$fid', '$filename');\r\n");
- fwrite($fp, "\$maNum = $maNum;\r\n");
- fclose($fp);
- }
-
- function ClearMyAddon($aid = 0, $title = '')
- {
- global $dsql;
- $cacheFile = DEDEDATA.'/cache/addon-'.session_id().'.inc';
- $_SESSION['bigfile_info'] = array();
- $_SESSION['file_info'] = array();
- if (!file_exists($cacheFile)) {
- return;
- }
-
- if (!empty($aid)) {
- include($cacheFile);
- foreach ($myaddons as $addons) {
- if (!empty($title)) {
- $dsql->ExecuteNoneQuery("Update `#@__uploads` set arcid='$aid',title='$title' where aid='{$addons[0]}'");
- } else {
- $dsql->ExecuteNoneQuery("Update `#@__uploads` set arcid='$aid' where aid='{$addons[0]}' ");
- }
- }
- }
- @unlink($cacheFile);
- }
-
- class userLogin
- {
- var $userName = '';
- var $userPwd = '';
- var $userID = '';
- var $adminDir = '';
- var $userType = '';
- var $userChannel = '';
- var $userPurview = '';
- var $keepUserIDTag = 'dede_admin_id';
- var $keepUserTypeTag = 'dede_admin_type';
- var $keepUserChannelTag = 'dede_admin_channel';
- var $keepUserNameTag = 'dede_admin_name';
- var $keepUserPurviewTag = 'dede_admin_purview';
- var $keepAdminStyleTag = 'dede_admin_style';
- var $adminStyle = 'DedeBIZ';
-
- function __construct($admindir = '')
- {
- global $admin_path;
- if (isset($_SESSION[$this->keepUserIDTag])) {
- $this->userID = $_SESSION[$this->keepUserIDTag];
- $this->userType = $_SESSION[$this->keepUserTypeTag];
- $this->userChannel = $_SESSION[$this->keepUserChannelTag];
- $this->userName = $_SESSION[$this->keepUserNameTag];
- $this->userPurview = $_SESSION[$this->keepUserPurviewTag];
- $this->adminStyle = $_SESSION[$this->keepAdminStyleTag];
- }
- if ($admindir != '') {
- $this->adminDir = $admindir;
- } else {
- $this->adminDir = $admin_path;
- }
- }
- function userLogin($admindir = '')
- {
- $this->__construct($admindir);
- }
-
-
- function checkUser($username, $userpwd)
- {
- global $dsql;
-
- $this->userName = preg_replace("/[^0-9a-zA-Z_@!\.-]/", '', $username);
- $this->userPwd = preg_replace("/[^0-9a-zA-Z_@!\.-]/", '', $userpwd);
- $pwd = substr(md5($this->userPwd), 5, 20);
- $dsql->SetQuery("SELECT admin.*,atype.purviews FROM `#@__admin` admin LEFT JOIN `#@__admintype` atype ON atype.`rank`=admin.usertype WHERE admin.userid LIKE '".$this->userName."' LIMIT 0,1");
- $dsql->Execute();
- $row = $dsql->GetObject();
- if (!isset($row->pwd)) {
- return -1;
- } else if (!empty($row->pwd_new) && !password_verify($this->userPwd, $row->pwd_new)) {
- $this->loginError($row->id);
- return -2;
- } else if (!empty($row->pwd) && $pwd != $row->pwd) {
- $this->loginError($row->id);
- return -2;
- } else {
- $upsql = "";
- if (empty($row->pwd_new) && function_exists('password_hash')) {
-
- $newpwd = password_hash($this->userPwd, PASSWORD_BCRYPT);
- $upsql .= ",pwd='',pwd_new='{$newpwd}'";
- }
- $loginip = GetIP();
- $this->userID = $row->id;
- $this->userType = $row->usertype;
- $this->userChannel = $row->typeid;
- $this->userName = $row->uname;
- $this->userPurview = $row->purviews;
- $inquery = "UPDATE `#@__admin` SET loginip='$loginip',logintime='".time()."'{$upsql},loginerr=0 WHERE id='".$row->id."'";
- $dsql->ExecuteNoneQuery($inquery);
- $sql = "UPDATE `#@__member` SET logintime=".time().", loginip='$loginip' WHERE mid=".$row->id;
- $dsql->ExecuteNoneQuery($sql);
- return 1;
- }
- }
-
-
-
-
- function isNeedCheckCode($username)
- {
- $num = $this->getLoginError($username);
- return $num >= 3 ? true : false;
- }
-
-
-
- function getLoginError($username)
- {
- global $dsql;
- $this->userName = preg_replace("/[^0-9a-zA-Z_@!\.-]/", '', $username);
- $row = $dsql->GetOne("SELECT loginerr,logintime FROM `#@__admin` WHERE userid LIKE '$this->userName'");
- if (is_array($row)) {
-
- return (time() - (int)$row['logintime']) < 60 ? (int)$row['loginerr'] : 0;
- } else {
- return -1;
- }
- }
-
-
-
- function loginError($adminid)
- {
- global $dsql;
- $loginip = GetIP();
- $inquery = "UPDATE `#@__admin` SET loginip='$loginip',logintime='".time()."',loginerr=loginerr+1 WHERE id='".$adminid."'";
- $dsql->ExecuteNoneQuery($inquery);
- }
-
-
- function keepUser()
- {
- if ($this->userID != '' && $this->userType != '') {
- global $admincachefile, $adminstyle;
- if (empty($adminstyle)) $adminstyle = 'DedeBIZ';
- @session_register($this->keepUserIDTag);
- $_SESSION[$this->keepUserIDTag] = $this->userID;
- @session_register($this->keepUserTypeTag);
- $_SESSION[$this->keepUserTypeTag] = $this->userType;
- @session_register($this->keepUserChannelTag);
- $_SESSION[$this->keepUserChannelTag] = $this->userChannel;
- @session_register($this->keepUserNameTag);
- $_SESSION[$this->keepUserNameTag] = $this->userName;
- @session_register($this->keepUserPurviewTag);
- $_SESSION[$this->keepUserPurviewTag] = $this->userPurview;
- @session_register($this->keepAdminStyleTag);
- $_SESSION[$this->keepAdminStyleTag] = $adminstyle;
- PutCookie('DedeUserID', $this->userID, 3600 * 24, '/');
- PutCookie('DedeLoginTime', time(), 3600 * 24, '/');
- $this->ReWriteAdminChannel();
- return 1;
- } else {
- return -1;
- }
- }
-
-
- function ReWriteAdminChannel()
- {
-
- $cacheFile = DEDEDATA.'/cache/admincat_'.$this->userID.'.inc';
-
- $typeid = trim($this->userChannel);
- if (empty($typeid) || $this->getUserType() >= 10) {
- $firstConfig = "\$cfg_admin_channel = 'all';\r\n\$admin_catalogs = array();\r\n";
- } else {
- $firstConfig = "\$cfg_admin_channel = 'array';\r\n";
- }
- $fp = fopen($cacheFile, 'w');
- fwrite($fp, '<'.'?php'."\r\n");
- fwrite($fp, $firstConfig);
- if (!empty($typeid)) {
- $typeids = explode(',', $typeid);
- $typeid = '';
- foreach ($typeids as $tid) {
- $typeid .= ($typeid == '' ? GetSonIdsUL($tid) : ','.GetSonIdsUL($tid));
- }
- $typeids = explode(',', $typeid);
- $typeidsnew = array_unique($typeids);
- $typeid = join(',', $typeidsnew);
- fwrite($fp, "\$admin_catalogs = array($typeid);\r\n");
- }
- fwrite($fp, '?'.'>');
- fclose($fp);
- }
-
-
- function exitUser()
- {
- ClearMyAddon();
- @session_unregister($this->keepUserIDTag);
- @session_unregister($this->keepUserTypeTag);
- @session_unregister($this->keepUserChannelTag);
- @session_unregister($this->keepUserNameTag);
- @session_unregister($this->keepUserPurviewTag);
- DropCookie('dedeAdmindir');
- DropCookie('DedeUserID');
- DropCookie('DedeLoginTime');
- $_SESSION = array();
- }
-
-
- function getUserChannel()
- {
- if ($this->userChannel != '') {
- return $this->userChannel;
- } else {
- return '';
- }
- }
-
-
- function getUserType()
- {
- if ($this->userType != '') {
- return $this->userType;
- } else {
- return -1;
- }
- }
-
-
- function getUserRank()
- {
- return $this->getUserType();
- }
-
-
- function getUserID()
- {
- if ($this->userID != '') {
- return $this->userID;
- } else {
- return -1;
- }
- }
-
-
- function getUserName()
- {
- if ($this->userName != '') {
- return $this->userName;
- } else {
- return -1;
- }
- }
-
-
- function getPurview()
- {
- return $this->userPurview;
- }
- }
-
- function GetSonIdsUL($id, $channel = 0, $addthis = TRUE)
- {
- global $cfg_Cs;
- $GLOBALS['idArray'] = array();
- if (!is_array($cfg_Cs)) {
- require_once(DEDEDATA."/cache/inc_catalog_base.inc");
- }
- GetSonIdsLogicUL($id, $cfg_Cs, $channel, $addthis);
- $rquery = join(',', $GLOBALS['idArray']);
- return $rquery;
- }
-
- function GetSonIdsLogicUL($id, $sArr, $channel = 0, $addthis = FALSE)
- {
- if ($id != 0 && $addthis) {
- $GLOBALS['idArray'][$id] = $id;
- }
- foreach ($sArr as $k => $v) {
- if ($v[0] == $id && ($channel == 0 || $v[1] == $channel)) {
- GetSonIdsLogicUL($k, $sArr, $channel, TRUE);
- }
- }
- }
|