MY_Controller.php 5.9 KB

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