IOT project -- Use ThinkPHP as the IOT system project framework

in #utopian-io6 years ago (edited)

New Features

What feature(s) did you add?

  • Migrate the whole IOT system project to ThinkPHP v5 framework

    图片.png

  • 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:

    图片.png
    图片.png图片.png

    Now:

    Input the same as above step,then the thinkphp framework will filter the user input then show like this:
    图片.png

    图片.png

    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

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

Sort:  

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

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

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

Coin Marketplace

STEEM 0.27
TRX 0.12
JST 0.031
BTC 68526.92
ETH 3726.80
USDT 1.00
SBD 3.73