IOT project -- Use ThinkPHP as the IOT system project framework
New Features
What feature(s) did you add?
Migrate the whole IOT system project to ThinkPHP v5 framework
Update the login function .Consider more secure factors like sql injection
Before:
When i come to login interface in the old version without thinkphp ,I input "admin' AND 1=1 -- " into the username blank and input any other text into password blank even though that is a wrong password. It will show like this:
Now:
Input the same as above step,then the thinkphp framework will filter the user input then show like this:
But to a certain extent,ThinkPHP may also have some vulnerable bugs leading to be hacked.
How did you implement it/them?
- IOT/webMonitor/thinkphp v5/thinkphp5/application/index/controller/Login.php
<?php
namespace app\index\controller;
use think\Controller;
use think\Cookie;
class Login extends Controller
{
public function index()
{
return $this->fetch();
}
public function login()
{
$post_data = input('post.');
$username = $post_data['username'];
$password = $post_data['password'];
if(empty($username))
{
$this->error('please input username');
}
if(empty($password))
{
$this->error('please input password');
}
$valid = db('user')->where('username', $username)->find();
if(empty($valid)){
$this->error('username or password error!');
}
if($valid['password'] != md5($password)){
$this->error('username or password error!');
}
cookie('username', $valid['username'], 3600);
$this->redirect(url('index/index'));
}
}
When do some mysql operation , use the ThinkPHP internal sql function to realize the login function.
db('user')->where('username', $username)->find()
- IOT/webMonitor/thinkphp v5/thinkphp5/application/index/controller/Sensorsdata.php
<?php
namespace app\index\controller;
use think\Controller;
use think\Cookie;
class Sensorsdata extends Controller
{
public function index()
{
if(cookie::has('username'))
{
$ID = 0;
$dataset = db('device')->where('ID', $ID)->find();
$data_airQuality = $dataset['data_airQuality'];
$data_distance = $dataset['data_distance'];
$data_voice = $dataset['data_voice'];
$data_light = $dataset['data_light'];
$data_humi = $dataset['data_humi'];
$data_temp = $dataset['data_temp'];
$data = array(
'temp'=>$data_temp,
'humi'=>$data_humi,
'light'=>$data_light,
'voice'=>$data_voice,
'airquality'=>$data_airQuality,
'distance'=>$data_distance
);
return json_encode($data);
}
// return $this->fetch();
else
{
$this->error('Please login first');
$this->redirect(url('login/index'));
}
}
}
Get sensors data in real time from the ESP8266 hardware and send them to the web UI.
Split frontend and backend
The project list is as below:
- controller
- Index,php
- Login.php
- Sensorsdata.php
- view
- index
- index.html
- login
- index.html
- index
- controller
Roadmap
- Considering when the IOT system is used into actual, there are many devices instead of one of two .So it is necessary to add a devices manager function to help use it Conveniently.
- Identify different devices by their ID
- Consider the performance of the communication protocol .May use MQTT protocol in the future version.
- Add other control way like discord controlling .
How to contribute?
Github: https://github.com/Cha0s0000/IOT
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request.
Posted on Utopian.io - Rewarding Open Source Contributors
thanks your work.I will next time
Hey @wehmoen, I just gave you a tip for your hard work on moderation. Upvote this comment to support the utopian moderators and increase your future rewards!
Thanks for sharing although I couldn't understand it much.
Hey @cha0s0000 I am @utopian-io. I have just upvoted you!
Achievements
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!
Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x