Skip to content

Commit

Permalink
add web13
Browse files Browse the repository at this point in the history
  • Loading branch information
wonderkun committed Jan 21, 2019
1 parent 39cf2b3 commit 052321b
Show file tree
Hide file tree
Showing 207 changed files with 42,377 additions and 0 deletions.
12 changes: 12 additions & 0 deletions web400-13/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM 0kami/web:apache2_php5_auto

MAINTAINER wh1t3P1g <https://github.com/0kami>

COPY source /var/www/html
COPY flag /etc

RUN chmod -R 755 /var/www/html \
&& chmod -R 777 /var/www/html/runtime \
&& chmod -R 777 /var/www/html/public \
&& chmod 777 /var/www/html/application/database.php \
&& rm /var/www/html/index.html
16 changes: 16 additions & 0 deletions web400-13/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: "3"
services:
web1:
build: "."
ports:
- "80:80"
links:
- mysql
depends_on:
- mysql
mysql:
image: "mysql:5.6"
environment:
MYSQL_ROOT_PASSWORD: "465b236607c695f3" # 修改数据库密码
TZ: 'Asia/Shanghai'
command: ['mysqld', '--character-set-server=utf8']
1 change: 1 addition & 0 deletions web400-13/flag
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
purple{Th1nkPhp_1s_v4rY_S4f3}
8 changes: 8 additions & 0 deletions web400-13/source/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>
1 change: 1 addition & 0 deletions web400-13/source/application/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
deny from all
12 changes: 12 additions & 0 deletions web400-13/source/application/command.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: yunwuxin <[email protected]>
// +----------------------------------------------------------------------

return [];
135 changes: 135 additions & 0 deletions web400-13/source/application/common.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <[email protected]>
// +----------------------------------------------------------------------

// 应用公共文件
define('CS',md5(base64_encode($_SERVER['HTTP_HOST'])));

function init(){
$args[] = 'mysql';
$args[] = 'mysql';
$args[] = 'root';
$args[] = '465b236607c695f3';
$args[] = '3306';
if(check_database_connection($args)){
file_put_contents('public/init.lock','1');
}
}

function generate_database_file($request){

$tpl = file_get_contents("application/install/config.tpl");
$tpl = str_replace("[type]",$request->post('dbtype','','htmlspecialchars'),$tpl);
$tpl = str_replace("[hostname]",$request->post('dbhost','','htmlspecialchars'),$tpl);
$tpl = str_replace("[username]",$request->post('dbuser','','htmlspecialchars'),$tpl);
$tpl = str_replace("[password]",$request->post('dbpass','','htmlspecialchars'),$tpl);
$tpl = str_replace("[hostport]",$request->post('dbport','','htmlspecialchars'),$tpl);
file_put_contents("application/database.php",$tpl);
file_put_contents("public/install.lock","1");

}

function check_database_connection($args){

try{
$db = new mysqli($args[1],$args[2],$args[3]);
$db->query("CREATE DATABASE IF NOT EXISTS `thinkphp`;");
$db = \think\Db::connect([
// 数据库类型
'type' => $args[0],
// 数据库连接DSN配置
'dsn' => '',
// 服务器地址
'hostname' => $args[1],
// 数据库名
'database' => 'thinkphp',
// 数据库用户名
'username' => $args[2],
// 数据库密码
'password' => $args[3],
// 数据库连接端口
'hostport' => $args[4],
// 数据库连接参数
'params' => [],
// 数据库编码默认采用utf8
'charset' => 'utf8',
// 数据库表前缀
'prefix' => 'think_',
]);
$db->execute("DROP TABLE IF EXISTS `think_notes`;");
$db->execute("CREATE TABLE `think_notes` (
`userid` int(11) DEFAULT NULL,
`content` varchar(255) DEFAULT NULL,
`id` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;");
$db->execute("DROP TABLE IF EXISTS `think_users`;");
$db->execute("CREATE TABLE `think_users` (
`username` varchar(255) DEFAULT NULL,
`password` varchar(255) DEFAULT NULL,
`id` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;");
return true;
}catch(\Exception $e){
return false;
}
}


function getSessionUser()
{
$info = decode(\think\Cookie::get('info'));
if(is_array($info) && isset($info['username']) && isset($info['password'])){
$user = \think\Db::name('users')
->where('username','=',$info['username'])
->where('password','=',$info['password'])
->find();
\think\Session::set('privilege',$user['id']);
\think\Session::set('username',$user['username']);
\think\Cookie::set('info',encode($user));
return $user['id'];
}
unset($info);
return null;
}

function decode($info)
{
$key = CS;
$info = urldecode($info);
$kl = strlen($key);
$il = strlen($info);
for($i = 0; $i < $il; $i++)
{
$p = $i%$kl;
$info[$i] = chr(ord($info[$i])-ord($key[$p]));
}
$info = unserialize($info);
return $info;
}

function encode($info)
{
$info = serialize($info);
$key = CS;
$kl = strlen($key);
$il = strlen($info);
for($i = 0; $i < $il; $i++)
{
$p = $i%$kl;
$info[$i] = chr(ord($info[$i])+ord($key[$p]));
}
return urlencode($info);
}

if(!file_exists('public/init.lock')){
init();
}
Loading

0 comments on commit 052321b

Please sign in to comment.