Exemplo n.º 1
0
 public function write($path, $data, $mode)
 {
     import('ORG.Net.FileSystem');
     $paths = new FileSystem();
     $paths->root = ITEM;
     $paths->charset = C('CFG_CHARSET');
     //main
     if ($mode == 'conf') {
         if (!is_writeable(ROOT . '/Conf')) {
             return -1;
         }
         $fp = fopen($path, 'wb');
         flock($fp, 3);
         fwrite($fp, "<" . "?php\r\n");
         fwrite($fp, "return array(\r\n");
         //dump($data);
         foreach ($data as $fval) {
             $fval['vals'] = htmlspecialchars_decode($fval['vals']);
             if ($fval['types'] == 'int' || $fval['types'] == 'bool') {
                 if ($fval['vals'] == "") {
                     $fval['vals'] = 0;
                 }
                 fwrite($fp, "\t'" . $fval['keyword'] . "' => " . addslashes($fval['vals']) . ",\r\n");
             } elseif ($fval['types'] == 'select' || $fval['types'] == 'more') {
                 list($key, $val) = explode('>>', $fval['vals']);
                 if ($key == 'none') {
                     fwrite($fp, "\t'" . $fval['keyword'] . "' => '',\r\n");
                 } else {
                     fwrite($fp, "\t'" . $fval['keyword'] . "' => '" . addslashes($key) . "',\r\n");
                 }
             } else {
                 fwrite($fp, "\t'" . $fval['keyword'] . "' => '" . addslashes($fval['vals']) . "',\r\n");
             }
         }
         fwrite($fp, ");");
         fclose($fp);
         return 1;
     } elseif ($mode && $mode != 'conf') {
         if (!file_exists($path)) {
             $paths->putDir($path);
         }
         if (!is_writeable($path)) {
             return -1;
         }
         $put = $paths->putFile($path . '/' . $mode . '.json', $data);
         return $put;
     } else {
         $this->error('未知操作模式,请检查!');
     }
 }
Exemplo n.º 2
0
 /**
  * move uploaded file to current directory
  *
  * @param string $src		source file path
  * @param string $newName	new file name
  * @return boolean
  */
 function upload($src, $newName)
 {
     if ($this->FileManager->hideSystemFiles && $newName[0] == '.') {
         return false;
     }
     $ext = strtolower(substr($newName, strrpos($newName, '.') + 1));
     if ($ext != '' && in_array($ext, $this->FileManager->hideFileTypes)) {
         return false;
     }
     if ($this->FileManager->createBackups) {
         $this->createBackup($newName);
     }
     $dst = $this->curDir . '/' . $newName;
     return $this->FileSystem->putFile($src, $dst);
 }
Exemplo n.º 3
0
 /**
  * 显示备份、还原数据库流
  *@param $act   bak为备份、re为还原
  *@param $total  传入表总数
  *@param $go  为1时,获取post
  *@examlpe 
  */
 public function show($act, $total = NULL, $go = -1, $page = -1)
 {
     $Public = A('Index', 'Public');
     $Public->check('Backup', array('c'));
     $sql = A('Sql', 'Public');
     //实例化sql类
     //实例化文件系统操作类
     import('ORG.Net.FileSystem');
     $path = new FileSystem();
     $path->root = ITEM;
     $path->charset = C('CFG_CHARSET');
     set_time_limit(1000);
     //main
     if ($go >= 0) {
         if ($act == 'bak') {
             $str_table = $path->getFile(RUNTIME_PATH . '/database.tmp');
             $arr_table = unserialize($str_table);
             if ($go == count($arr_table['table'])) {
                 cookie('badate', NULL);
                 $path->delFile(RUNTIME_PATH . '/database.tmp');
                 $path->delFile(RUNTIME_PATH . '/backup.tmp');
                 cookie('info_step', NULL);
                 cookie('info_page', NULL);
                 echo '所有表已完成备份!|0|0';
                 exit;
             }
             if (cookie('badate')) {
                 $badate = cookie('badate');
             } else {
                 $badate = date("Y-m-d_His");
                 cookie('badate', $badate);
             }
             $bak_dir = ROOT . '/Conf/Backup/' . $badate;
             if (!file_exists($bak_dir)) {
                 $path->putDir($bak_dir, 0777);
             }
             $strfile = '';
             $table = $arr_table['table'][$go];
             $tb = str_replace(C('DB_PREFIX'), '#@_', $table);
             $result = M();
             $str_info = $path->getFile(RUNTIME_PATH . '/backup.tmp');
             if ($str_info) {
                 $str_info = slashes($str_info);
                 $info = unserialize($str_info);
                 $page = cookie('info_page') ? cookie('info_page') : 0;
                 $p = cookie('info_step') ? cookie('info_step') : 1;
             } else {
                 $count = $result->table($table)->count();
                 $total = ceil($count / 10000);
                 if (cookie('info_page')) {
                     $page = cookie('info_page');
                 } else {
                     $page = 0;
                 }
                 if ($count > 10000) {
                     $info = $result->table($table)->limit($page * 10000, 10000)->select();
                     if ($page < $total) {
                         if ($page == 0) {
                             $p = 1;
                         } else {
                             $p = cookie('info_step') ? cookie('info_step') : 1;
                         }
                         $page++;
                         cookie('info_page', $page);
                         if ($p == 1) {
                             $strfile .= "DROP TABLE IF EXISTS `" . $tb . "`;\r\n";
                             $table_field = $sql->getField($table);
                             //获取表结构
                             //替换数据表名
                             $mysql = mysql_get_server_info();
                             $get_field = preg_replace("/AUTO_INCREMENT=[0-9]+\\s+/", "", $table_field);
                             if ($arr_table['version'] == 4.1 && $mysql > 4.1) {
                                 $get_field = preg_replace("/ENGINE=\\b.{2,}\\b DEFAULT CHARSET=\\S+/", 'ENGINE=MyISAM DEFAULT CHARSET=' . $arr_table['charset'], $get_field);
                             } elseif ($arr_table['version'] == 4.1 && $mysql < 4.1) {
                                 $get_field = preg_replace("TYPE=\\b.{2,}\\b", 'ENGINE=MyISAM DEFAULT CHARSET=' . $arr_table['charset'], $get_field);
                             } elseif ($arr_table['version'] == 4.0 && $mysql > 4.1) {
                                 $get_field = preg_replace("/ENGINE=\\b.{2,}\\b DEFAULT CHARSET=\\S+/", 'TYPE=MyISAM', $get_field);
                             }
                             $strfile .= str_replace('CREATE TABLE `' . C('DB_PREFIX'), 'CREATE TABLE `#@_', $get_field . ";\r\n");
                         }
                     } else {
                         $page = 0;
                         cookie('info_page', NULL);
                         $p = cookie('info_step') ? cookie('info_step') : 1;
                     }
                 } else {
                     $strfile .= "DROP TABLE IF EXISTS `" . $tb . "`;\r\n";
                     $table_field = $sql->getField($table);
                     //获取表结构
                     //替换数据表名
                     $mysql = mysql_get_server_info();
                     $get_field = preg_replace("/AUTO_INCREMENT=[0-9]+\\s+/", "", $table_field);
                     if ($arr_table['version'] == 4.1 && $mysql > 4.1) {
                         $get_field = preg_replace("/ENGINE=\\b.{2,}\\b DEFAULT CHARSET=\\S+/", 'ENGINE=MyISAM DEFAULT CHARSET=' . $arr_table['charset'], $get_field);
                     } elseif ($arr_table['version'] == 4.1 && $mysql < 4.1) {
                         $get_field = preg_replace("TYPE=\\b.{2,}\\b", 'ENGINE=MyISAM DEFAULT CHARSET=' . $arr_table['charset'], $get_field);
                     } elseif ($arr_table['version'] == 4.0 && $mysql > 4.1) {
                         $get_field = preg_replace("/ENGINE=\\b.{2,}\\b DEFAULT CHARSET=\\S+/", 'TYPE=MyISAM', $get_field);
                     }
                     $strfile .= str_replace('CREATE TABLE `' . C('DB_PREFIX'), 'CREATE TABLE `#@_', $get_field . ";\r\n");
                     $info = $result->table($table)->select();
                     cookie('info_page', NULL);
                     cookie('info_step', NULL);
                     $page = 0;
                     $p = 1;
                 }
             }
             if ($info) {
                 while (true) {
                     $t = array_shift($info);
                     $strfile .= $sql->getData($table, $t);
                     if (strlen($strfile) >= $arr_table['filesize'] * 1024) {
                         $filename = $tb . '_' . str_pad($p, 5, "0", STR_PAD_LEFT) . '.bak';
                         $fie_path = $bak_dir . '/' . $filename;
                         $path->putFile($fie_path, $strfile);
                         $p++;
                         $strfile = '';
                         cookie('info_step', $p);
                         $path->putFile(RUNTIME_PATH . '/backup.tmp', serialize($info));
                         echo '<p>表“' . $table . '_' . str_pad($p - 1, 5, "0", STR_PAD_LEFT) . '”备份成功!</p>|1|' . $page;
                         exit;
                     } else {
                         if (count($info)) {
                             continue;
                         } else {
                             break;
                         }
                     }
                 }
             }
             if ($p == 1) {
                 $filename = $tb . '.bak';
                 $fie_path = $bak_dir . '/' . $filename;
                 $path->putFile($fie_path, $strfile);
                 $path->delFile(RUNTIME_PATH . '/backup.tmp');
                 echo '<p>表“' . $table . '”备份成功!</p>|0|0';
                 exit;
             } else {
                 if ($strfile) {
                     $filename = $tb . '_' . str_pad($p, 5, "0", STR_PAD_LEFT) . '.bak';
                     $fie_path = $bak_dir . '/' . $filename;
                     $path->putFile($fie_path, $strfile);
                 }
                 $path->delFile(RUNTIME_PATH . '/backup.tmp');
                 if ($page > 0) {
                     cookie('info_step', $p + 1);
                 }
                 echo '<p>表“' . $table . '_' . str_pad($p, 5, "0", STR_PAD_LEFT) . '”备份成功!</p>|0|' . $page;
                 exit;
             }
         } elseif ($act == 're') {
             $str_table = $path->getFile(RUNTIME_PATH . '/database.tmp');
             $arr_table = unserialize($str_table);
             if ($go == count($arr_table['table'])) {
                 $path->delFile(RUNTIME_PATH . '/database.tmp');
                 echo '所有表已完成还原!|0|0';
                 exit;
             }
             $table = str_replace('#@_', C('DB_PREFIX'), $arr_table['table'][$go]);
             $tb = str_replace('.bak', '', $table);
             $tablefile = $arr_table['path'] . '/' . $arr_table['table'][$go];
             $info = $path->getFile($tablefile);
             $arr_info = explode(";\r\n", $info);
             $result = M();
             foreach ($arr_info as $t) {
                 $t = preg_replace("/`#@_(.+)?`/iu", '`' . C('DB_PREFIX') . '$1`', $t);
                 $t = str_replace('&#59', ';', $t);
                 $char = C('CFG_CHARSET');
                 if ($char == 'UTF-8') {
                     $char = 'utf8';
                 } else {
                     $char = 'gb2312';
                 }
                 $t = preg_replace("/ENGINE=\\b.{2,}\\b DEFAULT CHARSET=\\S+/", 'ENGINE=MyISAM DEFAULT CHARSET=' . $char, $t);
                 $result->execute($t);
             }
             echo '<p>表“' . $tb . '”还原成功!</p>|0|0';
             exit;
         }
     } else {
         $this->assign('act', $act);
         $this->assign('total', $total);
         $this->display();
     }
 }
Exemplo n.º 4
0
 /**
  * 升级检查
  *@examlpe 
  */
 public function upver()
 {
     $nowtime = time();
     import('ORG.Net.FileSystem');
     $sys = new FileSystem();
     $sys->root = ITEM;
     $sys->charset = C('CFG_CHARSET');
     $App = A('App', 'Public');
     //main
     $nowdate = date("Y-m-d H:i:s", $nowtime);
     $path = CONF_PATH . 'version.txt';
     $ver = $sys->getFile($path);
     $arr_ver = explode(";\r\n", $ver);
     $arr_ver = array_filter($arr_ver);
     $content = $arr_ver[0] . ";\r\n" . $nowdate . ";\r\n" . $arr_ver[2] . ";\r\n";
     $sys->putFile($path, $content);
     echo "当前版本:{$arr_ver['0']}&nbsp;&nbsp;&nbsp;&nbsp;最后检测时间:{$nowdate}";
 }
Exemplo n.º 5
0
 /**
  * 编辑权限配置文件
  *@param $id 	传入的数据ID
  *@examlpe 
  */
 public function role($id, $go = 0)
 {
     import('ORG.Net.FileSystem');
     $sys = new FileSystem();
     $Public = A('Index', 'Public');
     //main
     $id = intval($id);
     if ($go == 0) {
         $menu = M('Menu');
         $code = $menu->where('id=' . $id)->getField('code');
         $path = CONF_PATH . '/Role/' . $code . 'Role.php';
         $file = $sys->getFile($path);
         $this->assign('file', $file);
         $this->assign('code', $code);
         $this->assign('uniqid', uniqid());
         $this->assign('id', $id);
         $this->assign('path', '/Conf/Role/' . $code . 'Role.php');
         $this->display();
     } else {
         $role = $Public->check('Menu', array('u'));
         if ($role < 0) {
             echo $role;
             exit;
         }
         $code = I('code');
         $data = I('file', '', false);
         if (!preg_match("/^\\<\\?php/i", $data)) {
             $data = "<?php\r\n" . $data;
         }
         $path = $path = CONF_PATH . '/Role/' . $code . 'Role.php';
         if ($code) {
             $edit = $sys->putFile($path, $data);
             if ($edit == 1) {
                 echo 1;
             } else {
                 echo 0;
             }
         } else {
             echo 2;
         }
     }
 }