Advertisement
eduardopaludo

instalar.php

Jul 30th, 2014
377
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.08 KB | None | 0 0
  1. <?php if ( ! defined("BASEPATH")) exit("No direct script access allowed");
  2.  
  3. class Instalar extends CI_Controller {
  4.        
  5.     public function __construct(){
  6.         parent::__construct();
  7.     }
  8.  
  9.     public function index(){
  10.         init_painel();
  11.         $this->form_validation->set_rules('url_base', 'URL', 'trim|required|strtolower');
  12.         $this->form_validation->set_rules('chave_seguranca', 'CHAVE DE SEGURANÇA', 'trim|required|strtolower');
  13.         $this->form_validation->set_rules('tempo_sessao', 'TEMPO DA SESSÃO', 'trim|required|numeric');
  14.         $this->form_validation->set_rules('hostname', 'SERVIDOR', 'trim|required');
  15.         $this->form_validation->set_rules('username', 'USUÁRIO', 'trim|required');
  16.         $this->form_validation->set_rules('password', 'SENHA', 'trim');
  17.         $this->form_validation->set_rules('database', 'NOME DO BD', 'trim|required');
  18.         $this->form_validation->set_rules('user_nome', 'NOME COMPLETO', 'trim|required|ucwords');
  19.         $this->form_validation->set_rules('user_email', 'EMAIL', 'trim|required|valid_email|strtolower');
  20.         $this->form_validation->set_rules('user_login', 'LOGIN', 'trim|required|min_length[4]|strtolower');
  21.         $this->form_validation->set_rules('user_senha', 'SENHA', 'trim|required|min_length[4]|strtolower');
  22.         if ($this->form_validation->run()==TRUE):
  23.             //criar arquivos
  24.             $this->load->helper('file');
  25.             $file_config = '<?php  if ( ! defined("BASEPATH")) exit("No direct script access allowed");
  26.                 $config["base_url"] = "'.$this->input->post('url_base').'";
  27.                 $config["index_page"] = "";
  28.                 $config["uri_protocol"] = "AUTO";
  29.                 $config["url_suffix"] = "";
  30.                 $config["language"] = "pt-BR";
  31.                 $config["charset"] = "UTF-8";
  32.                 $config["enable_hooks"] = FALSE;
  33.                 $config["subclass_prefix"] = "RB_";
  34.                 $config["permitted_uri_chars"] = "a-z 0-9~%.:_\-";
  35.                 $config["allow_get_array"]      = TRUE;
  36.                 $config["enable_query_strings"] = FALSE;
  37.                 $config["controller_trigger"]   = "c";
  38.                 $config["function_trigger"]     = "m";
  39.                 $config["directory_trigger"]    = "d";
  40.                 $config["log_threshold"] = 0;
  41.                 $config["log_path"] = "";
  42.                 $config["log_date_format"] = "Y-m-d H:i:s";
  43.                 $config["cache_path"] = "";
  44.                 $config["encryption_key"] = "'.$this->input->post('chave_seguranca').'";
  45.                 $config["sess_cookie_name"]     = "ci_session";
  46.                 $config["sess_expiration"]      = '.$this->input->post('tempo_sessao').';
  47.                 $config["sess_expire_on_close"] = TRUE;
  48.                 $config["sess_encrypt_cookie"]  = TRUE;
  49.                 $config["sess_use_database"]    = FALSE;
  50.                 $config["sess_table_name"]      = "ci_sessions";
  51.                 $config["sess_match_ip"]        = TRUE;
  52.                 $config["sess_match_useragent"] = TRUE;
  53.                 $config["sess_time_to_update"]  = 300;
  54.                 $config["cookie_prefix"]    = "";
  55.                 $config["cookie_domain"]    = "";
  56.                 $config["cookie_path"]      = "/";
  57.                 $config["cookie_secure"]    = FALSE;
  58.                 $config["global_xss_filtering"] = FALSE;
  59.                 $config["csrf_protection"] = FALSE;
  60.                 $config["csrf_token_name"] = "csrf_test_name";
  61.                 $config["csrf_cookie_name"] = "csrf_cookie_name";
  62.                 $config["csrf_expire"] = 7200;
  63.                 $config["compress_output"] = FALSE;
  64.                 $config["time_reference"] = "local";
  65.                 $config["rewrite_short_tags"] = FALSE;
  66.                 $config["proxy_ips"] = "";
  67.             /* End of file config.php */
  68.             /* Location: ./application/config/config.php */
  69.             ';
  70.             write_file('./application/config/config.php', trim($file_config));
  71.            
  72.             $file_bd = '<?php  if ( ! defined("BASEPATH")) exit("No direct script access allowed");
  73.                 $active_group = "default";
  74.                 $active_record = TRUE;
  75.                 $db["default"]["hostname"] = "'.$this->input->post('hostname').'";
  76.                 $db["default"]["username"] = "'.$this->input->post('username').'";
  77.                 $db["default"]["password"] = "'.$this->input->post('password').'";
  78.                 $db["default"]["database"] = "'.$this->input->post('database').'";
  79.                 $db["default"]["dbdriver"] = "mysql";
  80.                 $db["default"]["dbprefix"] = "";
  81.                 $db["default"]["pconnect"] = TRUE;
  82.                 $db["default"]["db_debug"] = TRUE;
  83.                 $db["default"]["cache_on"] = FALSE;
  84.                 $db["default"]["cachedir"] = "";
  85.                 $db["default"]["char_set"] = "utf8";
  86.                 $db["default"]["dbcollat"] = "utf8_general_ci";
  87.                 $db["default"]["swap_pre"] = "";
  88.                 $db["default"]["autoinit"] = TRUE;
  89.                 $db["default"]["stricton"] = FALSE;
  90.             /* End of file database.php */
  91.             /* Location: ./application/config/database.php */
  92.             ';
  93.             write_file('./application/config/database.php', trim($file_bd));
  94.            
  95.             //conectar bd
  96.             $this->load->database();
  97.             $this->db->reconnect();
  98.            
  99.             //criar tabelas
  100.             $sql_bd = "CREATE TABLE IF NOT EXISTS `auditoria` (
  101.               `id` int(11) NOT NULL AUTO_INCREMENT,
  102.               `usuario` varchar(45) NOT NULL,
  103.               `data_hora` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  104.               `operacao` varchar(45) NOT NULL,
  105.               `query` text NOT NULL,
  106.               `observacao` text NOT NULL,
  107.               PRIMARY KEY (`id`)
  108.             ) ENGINE=InnoDB  DEFAULT CHARSET=latin1;";
  109.             $this->db->query($sql_bd);
  110.            
  111.             $sql_bd = "CREATE TABLE IF NOT EXISTS `midia` (
  112.               `id` int(11) NOT NULL AUTO_INCREMENT,
  113.               `nome` varchar(45) NOT NULL,
  114.               `descricao` varchar(255) NOT NULL,
  115.               `arquivo` varchar(255) NOT NULL,
  116.               PRIMARY KEY (`id`)
  117.             ) ENGINE=InnoDB  DEFAULT CHARSET=latin1;";
  118.             $this->db->query($sql_bd);
  119.            
  120.             $sql_bd = "CREATE TABLE IF NOT EXISTS `paginas` (
  121.               `id` int(11) NOT NULL AUTO_INCREMENT,
  122.               `titulo` varchar(255) NOT NULL,
  123.               `slug` varchar(255) NOT NULL,
  124.               `conteudo` longtext NOT NULL,
  125.               PRIMARY KEY (`id`)
  126.             ) ENGINE=InnoDB  DEFAULT CHARSET=latin1;";
  127.             $this->db->query($sql_bd);
  128.            
  129.             $sql_bd = "CREATE TABLE IF NOT EXISTS `settings` (
  130.               `id` int(11) NOT NULL AUTO_INCREMENT,
  131.               `nome_config` varchar(255) NOT NULL,
  132.               `valor_config` text NOT NULL,
  133.               PRIMARY KEY (`id`)
  134.             ) ENGINE=InnoDB  DEFAULT CHARSET=latin1;";
  135.             $this->db->query($sql_bd);
  136.            
  137.             $sql_bd = "CREATE TABLE IF NOT EXISTS `usuarios` (
  138.               `id` int(11) NOT NULL AUTO_INCREMENT,
  139.               `nome` varchar(100) NOT NULL,
  140.               `email` varchar(100) NOT NULL,
  141.               `login` varchar(45) NOT NULL,
  142.               `senha` varchar(32) NOT NULL,
  143.               `ativo` tinyint(1) NOT NULL DEFAULT '1',
  144.               `adm` tinyint(1) NOT NULL DEFAULT '0',
  145.               PRIMARY KEY (`id`)
  146.             ) ENGINE=InnoDB  DEFAULT CHARSET=latin1;";
  147.             $criacao_bd = $this->db->query($sql_bd);
  148.            
  149.             //criar o primeiro usuario
  150.             if ($criacao_bd == TRUE):
  151.                 $dados["nome"] = $this->input->post('user_nome');
  152.                 $dados["email"] = $this->input->post('user_email');
  153.                 $dados["login"] = $this->input->post('user_login');
  154.                 $dados["senha"] = md5($this->input->post('user_senha'));
  155.                 $dados["adm"] = 1;
  156.                 $usuario = $this->db->insert('usuarios', $dados);
  157.                 if ($usuario == TRUE) redirect('instalar/sucesso');
  158.             endif;
  159.         endif;
  160.         set_tema('titulo', 'Instalação do sistema');
  161.         set_tema('conteudo', load_modulo('instalar', 'instalar'));
  162.         set_tema('rodape', '');
  163.         load_template();
  164.     }
  165.    
  166.     public function sucesso(){
  167.         init_painel();
  168.         set_tema('titulo', 'Instalação concluída');
  169.         set_tema('conteudo', load_modulo('instalar', 'sucesso'));
  170.         set_tema('rodape', '');
  171.         load_template();
  172.     }
  173.    
  174. }
  175.  
  176. /* End of file instalar.php */
  177. /* Location: ./application/controllers/instalar.php */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement