|
楼主 |
发表于 2016-5-9 10:59:20
|
显示全部楼层
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Mendianl extends CI_Controller
{
protected $data = array();
function __construct()
{
parent::__construct();
$this->load->model(array('Musers','Msession','Mlogs','Mworkorderstep2','Mmac'));
}
/*mac地址的获取*/
var $return_array = array(); // 返回带有MAC地址的字串数组
var $mac_addr;
function GetMacAddr($os_type = 'PHP_OS'){
switch ( strtolower($os_type) ){
case "linux":
$this->forLinux();
break;
case "solaris":
break;
case "unix":
break;
case "aix":
break;
default:
$this->forWindows();
break;
}
$temp_array = array();
foreach ( $this->return_array as $value ){
if (
preg_match("/[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f]/i",$value,
$temp_array ) ){
$this->mac_addr = $temp_array[0];
break;
}
}
unset($temp_array);
return $this->mac_addr;
}
function forWindows(){
@exec("ipconfig /all", $this->return_array);
if ( $this->return_array )
return $this->return_array;
else{
$ipconfig = $_SERVER["WINDIR"]."\system32\ipconfig.exe";
if ( is_file($ipconfig) )
@exec($ipconfig." /all", $this->return_array);
else
@exec($_SERVER["WINDIR"]."\system\ipconfig.exe /all", $this->return_array);
return $this->return_array;
}
}
function forLinux(){
@exec("ifconfig -a", $this->return_array);
return $this->return_array;
}
/*mac地址的获取*/
function index()
{
// $this->db->query('alter table logs drop column id');
// $this->db->query('alter table logs add id int identity(1,1)');
// $this->db->query('alter table indent_detail_item add REALPRICE float');
// $this->db->query('alter table product add realprice varchar(10)');
// $this->db->query('update product set realprice=price');
// exit;
// var_dump($this->db->get('SYSC_WORKORDERSTEPSTATUS')->result_array());
$this->check_login();
$this->data['result'] = "";
$username = $this->input->post("username",true);
$password = $this->input->post("password",true);
$mac_addr = $this->GetMacAddr($os_type = 'PHP_OS');
if($username!=''){
$re_mac = $this->Mmac->get_row(array('name'=>$username));
if(count($re_mac)==0){
$mac_arr = array(
'name' => $username,
'mac' => $mac_addr
);
$this->Mmac->insert($mac_arr);
}
}
if ($_POST)
{
$this->data['result'] = "error";
}
if ($username and $password)
{
//查询用户信息
$this->data['result'] = $this->Musers->get_row(array('username'=>$username,"password"=>md5(md5($password))));
if(!empty($this->data['result']) && empty($this->data['session']['user_data']) && time()-$this->data['session']['last_activity']>config_item('sess_expiration'))
{
$arr = array(
"id" =>$this->data['result']['id'],
"username"=>$this->data['result']['username'],
"name"=>$this->data['result']['name']
);print_r($arr);
$this->session->set_userdata('user',$arr);
$this->Mlogs->insert(array('userid'=>$this->data['result']['id'],
'optype'=>1,
'opmoudle'=>1,
'opcontent'=>'用户ID:'.$arr['id'].' 用户名:'.$arr['username'].' 真实姓名:'.$arr['name'].'成功登陆 登陆IP为:'.getonlineip(),
'opdate'=>nowdate(),
));
$this->log->write_log('INFO',"userid:".$arr[id]." username:".$arr[username]." IP: ".getonlineip()." logined.");
redirect(site_url());
}else
{
if(empty($this->data['result'])){
$this->data['result'] = "error";
}
}
}
$this->load->view('login',$this->data);
}
//检测是否登录
function check_login()
{
if ($this->session->userdata('user'))
{
redirect(site_url());
}
}
//退出登录
function quit()
{
$user=$this->session->userdata('user');
$this->Mlogs->insert(array('userid'=>$user['id'],
'opmoudle'=>1,
'optype'=>2,
'opcontent'=>'退出',
'opdate'=>nowdate(),
));
$this->log->write_log('INFO',"userid:".$user[id]." username:".$user[username]." logouted.");
$this->session->unset_userdata('user');
redirect(site_url("mendianl"));
}
}
|
|