MY_Controller.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <?php
  2. class Public_Controller extends CI_Controller
  3. {
  4. protected $page_size;
  5. protected $branch_array;
  6. protected $setting;
  7. //告警类型
  8. public $warning_type = array(
  9. "10" => "安全事件",
  10. //"20" => "脆弱性",
  11. //"30" => "残余攻击"
  12. "unknown" => "未知类型"
  13. );
  14. //告警级别
  15. public $warning_level = array(
  16. "10" => "已失陷",
  17. "20" => "高可疑",
  18. "30" => "低可疑",
  19. "40" => "高危",
  20. "50" => "中危",
  21. "60" => "低危"
  22. );
  23. //告警状态
  24. public $warning_status = array(
  25. "10" => "待审核下发",
  26. "20" => "已忽略",
  27. "30" => "已生成工单",
  28. "40" => "已处置"
  29. );
  30. //工单状态
  31. public $workorder_status = array(
  32. "10" => "待签收",
  33. "20" => "已签收,正在处理",
  34. "30" => "处理完成,待复核",
  35. "40" => "驳回处理",
  36. "50" => "已结束",
  37. "60" => "已删除"
  38. );
  39. //发送类型
  40. public $send_type = array(
  41. "10" => "短信",
  42. "20" => "邮件"
  43. );
  44. //帐号角色
  45. public $user_types = array(
  46. "1" => "管理员",
  47. "2" => "工程师"
  48. );
  49. //帐号状态
  50. public $user_status = array(
  51. "10" => "正常",
  52. "40" => "已停用"
  53. );
  54. //接入授权状态
  55. public $appauth_status = array(
  56. "10" => "启用",
  57. "40" => "停用"
  58. );
  59. //平台对应关系
  60. public $from = array(
  61. "sip" => "安全感知平台"
  62. );
  63. public function __construct()
  64. {
  65. parent::__construct();
  66. $this->load->helper(array('url'));
  67. $this->load->driver('cache', array('adapter' => 'apc', 'backup' => 'file'));
  68. $cahce_setting = $this->cache->get('setting');
  69. if(!$cahce_setting){
  70. $this->load->model("setting_model");
  71. $setting = $this->setting_model->get_setting();
  72. if($setting) {
  73. $cahce_setting = $setting;
  74. $this->cache->save('setting', $setting, 30000);
  75. }
  76. }
  77. $cahce_branch = $this->cache->get('branchs');
  78. if(!$cahce_branch){
  79. $this->load->model("branch_model");
  80. $branch_list = $this->branch_model->select_branch();
  81. if($branch_list){
  82. $branch = array();
  83. foreach($branch_list as $key=>$val){
  84. $branch[$val['branch_id']] = $val;
  85. }
  86. $this->cache->save('branchs', $branch, 30000);
  87. $cahce_branch= $branch;
  88. }else{
  89. $this->cache->save('branchs', array(), 30000);
  90. $cahce_branch = array();
  91. }
  92. }
  93. if(!array_key_exists('save_time',$cahce_setting) || $cahce_setting['save_time']==""){
  94. $cahce_setting['save_time'] = "180";
  95. }
  96. $this->setting = $cahce_setting;
  97. $this->branch_array = $cahce_branch;
  98. $this->assign("setting",$cahce_setting);
  99. $this->assign("branch",$cahce_branch);
  100. $this->page_size = $this->config->item('page_size');
  101. $this->assign("sys_name", $this->config->item('sys_name'));
  102. $this->assign("from",$this->from);
  103. }
  104. public function assign($key, $val)
  105. {
  106. $this->ci_smarty->assign($key, $val);
  107. }
  108. //Smaty模板输出
  109. public function display($html)
  110. {
  111. $this->output->set_header('X-Frame-Options: sameorigin');
  112. $this->output->set_header("X-XSS-Protection: 1");
  113. $this->output->set_header("X-Content-Type-Options:nosniff");
  114. $this->ci_smarty->display($html);
  115. }
  116. //输出Json
  117. public function response($data)
  118. {
  119. $this->output->set_header('X-Frame-Options: sameorigin');
  120. $this->output->set_header("X-XSS-Protection: 1");
  121. $this->output->set_header("X-Content-Type-Options:nosniff");
  122. $this->output->set_header('Content-Type: application/json; charset=utf-8');
  123. echo json_encode($data);
  124. }
  125. /*
  126. * 创建唯一ID
  127. */
  128. public function create_id()
  129. {
  130. return date('Ymd') . substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
  131. }
  132. /**
  133. * 分页配置
  134. * @param $count 内容总数
  135. * @param $page_size 每页数量
  136. * @param $url 分页URL
  137. * @return mixed 分页html
  138. */
  139. public function page_config($count, $page_size, $url)
  140. {
  141. $config ['base_url'] = $url; //设置基地址
  142. $config['num_links'] = 4;
  143. $config ['total_rows'] = $count;
  144. $config ['per_page'] = $page_size; //每页显示的数据数量
  145. $config['use_page_numbers'] = TRUE;
  146. $config['full_tag_open'] = '<ul class="pagination">';
  147. $config['full_tag_close'] = '</ul>';
  148. $config ['prev_link'] = '<';
  149. $config['prev_tag_open'] = '<li>';
  150. $config['prev_tag_close'] = '</li>';
  151. $config ['next_link'] = '>';
  152. $config['next_tag_open'] = '<li>';
  153. $config['next_tag_close'] = '</li>';
  154. $config['num_tag_open'] = '<li>';
  155. $config['num_tag_close'] = '</li>';
  156. $config['cur_tag_open'] = '<li class="active"><a href="#">';
  157. $config['cur_tag_close'] = '</a></li>';
  158. $config ['first_link'] = '«';
  159. $config['first_tag_open'] = '<li>';
  160. $config['first_tag_close'] = '</li>';
  161. $config ['last_link'] = '»';
  162. $config['last_tag_open'] = '<li>';
  163. $config['last_tag_close'] = '</li>';
  164. $config['page_query_string'] = TRUE;
  165. return $config;
  166. }
  167. }
  168. class MY_Controller extends Public_Controller
  169. {
  170. public function __construct()
  171. {
  172. parent::__construct();
  173. if (!$this->session->user_id || !$this->session->username) {
  174. redirect("login");
  175. } else {
  176. $this->assign("username", $this->session->username);
  177. $this->assign("user_type", $this->session->user_type);
  178. $this->assign("user_id", $this->session->user_id);
  179. }
  180. }
  181. }