Announcement

Collapse
No announcement yet.

PHPoC - Configuring Network Information via Web

Collapse
X
Collapse

  • PHPoC - Configuring Network Information via Web

    This example show how to create an Web app that allows to check and config network information (e.g MAC address, IP addess, ...) remotely via Web browser.


    Hardware
    • PHPoC Blue (+ USB WLAN) or PHPoC Black (+ Ethernet cable)
    • Micro USB to USB Cable (to upload source code to PHPoC Device)


    Quick Steps

    Source code of this example is a part of PHPoC Support Packet (PSP). You need to:
    • Download PHPoC Support Package.
    • Upload example\net\02.html_text\setup to PHPoC Blue/Black.
    • Configure network parameters (e.g. WiFi SSID, password, IP address ...).
    • Access webpage on PHPoC using Web Browser on your PC or smart phone (See How To).
    If you use PHPoC for the first time, see How To Use PSP.


    Source Code

    Source files includes:
    • index.php: Provides system and network information.
    • setup.php: Provides User Interface, which allows user to config network information.
    • setup_ok.php: Perform Network Configutation on PHPoC device.
    All of these files are only interpreted when there is request from Web browser.


    index.php
    PHP Code:
    <!DOCTYPE html>
    <?php
    if((int)ini_get("init_net0"))
     
    $pid_net pid_open("/mmap/net0");
    else
     
    $pid_net pid_open("/mmap/net1");
    $hwaddr pid_ioctl($pid_net"get hwaddr");
    $ipaddr pid_ioctl($pid_net"get ipaddr");
    $netmask pid_ioctl($pid_net"get netmask");
    $gwaddr pid_ioctl($pid_net"get gwaddr");
    $nsaddr pid_ioctl($pid_net"get nsaddr");
    pid_close($pid_net);

    $pid_net1 pid_open("/mmap/net1");
    $wmode pid_ioctl($pid_net1"get mode");
    $ssid pid_ioctl($pid_net1"get ssid");
    $rssi pid_ioctl($pid_net1"get rssi");
    $rsna pid_ioctl($pid_net1"get rsna");
    $akm pid_ioctl($pid_net1"get akm");
    $cipher pid_ioctl($pid_net1"get cipher");
    pid_close($pid_net1);
    ?>

    <html>
    <head>
     <title>PHPoC</title>
     <meta content="initial-scale=0.7, maximum-scale=1.0, minimum-scale=0.5, width=device-width, user-scalable=yes" name="viewport">
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
     <style type="text/css">
      body { font-family: verdana, Helvetica, Arial, sans-serif, gulim; }
      h1 { font-weight: bold; font-family : verdana, Helvetica, Arial, verdana, sans-serif, gulim; font-size:15pt; padding-bottom:10px;}
      table {border-collapse:collapse; width:430px;  font-size:10pt;}
      .theader { font-weight: bold;}
      tr {height :28px;}
      td { padding-left: 10px; text-align: left;}
      .superHeader {height: 2em; color: white; background-color: rgb(0,153,153); font-size:9pt; position:fixed; left:0; right:0; top:0; z-index:5;  }  
      .right {
        color: white;
        position: absolute;
        right: 1px;
        bottom: 4px;
        font-size:9pt;  
      }
      .left {
        color: white;
        position: absolute;
        left: 1px;
        bottom: 4px;
        font-size:9pt;  
      }
      .right a, .left a
      {
        color: white;
        background-color: transparent;
        text-decoration: none;
        margin: 0;
        padding:0 2ex 0 2ex;
      }  
      .right a:hover, .left a:hover
      {
        color: white;
        text-decoration: underline;
       }  
      .midHeader {color: white; background-color: rgb(6, 38, 111);  position:fixed; left:0; right:0; top:1.5em;  z-index:3;}
      .headerTitle {
        font-size: 250%;
        font-weight: normal;
        margin: 0 0 0 4mm;
        padding: 0.25ex 0 1ex 0;
        font-family: impact;
      }  
      .headerMenu{
       position:relative;
       width: 430px;
       padding: 5px;
      }
      #footer{margin:0 auto; height:auto !important; height:100%; margin-bottom:-100px;  }
      .superFooter {
       height: 2em; color: white; background-color: rgb(6, 38, 111); font-size:9pt; position:fixed; left:0; right:0; bottom:0; z-index:4;
      }    
      .zebra {background-color : #ECECEC;}
     </style>
    </head>
    <body>
        <div id="header">
      <div class="superHeader">  
       <div class="left">
       </div>
       <div class="right">
        <a href="http://www.sollae.co.kr" target="_blank">SOLLAE SYSTEMS</a>
       </div>
      </div>

      <div class="midHeader">
       <center>
        <h1 class="headerTitle"><?php echo system("uname -i");?></h1>
        <div class="headerMenu">
         <div class="left">
          <a href="index.php">INFO</a>  |
          <a href="setup.php">SETUP</a>  
         </div>
         <div class="right">  
         </div>
        </div>
       </center>
      </div>

      <div class="subHeader">
      </div>  
     </div>
     <br /><br /><br /><br />
     <form name="pbh_104_ss4">
     <input type="hidden" name="mode" value="">  
     <center>
      <hr style="margin:50px 0 -10px 0; width:430px;" size="6" noshade>
      <h1>System Information</h1>
      <table>
       <tr class="zebra">
        <td width="190px" class="theader"><?php echo "Product name";?></td>
        <td>
         <?php echo system("uname -i") . "\r\n";?>
        </td>
       </tr>
       <tr>
        <td width="190px" class="theader"><?php echo "MAC address";?></td>
        <td>
         <?php echo $hwaddr;?>
        </td>
       </tr>
       <tr class="zebra">
        <td width="190px" class="theader"><?php echo "Firmware name";?></td>
        <td>
         <?php echo system("uname -f") . "\r\n";?>
        </td>
       </tr>
       <tr>
        <td width="190px" class="theader"><?php echo "Firmware version";?></td>
        <td>
         <?php echo system("uname -v") . "\r\n";?>
        </td>
       </tr>
      </table>

      <hr style="margin:40px 0 -10px 0; width:430px;" size="6" noshade>
      <h1>Network Information</h1>
      <table>
       <tr class="zebra">
        <td width="190px" class="theader"><?php echo "IP address";?></td>
        <td><?php echo $ipaddr;?></td>
       </tr>
       <tr>
        <td class="theader"><?php echo "Subnet mask";?></td>
        <td><?php echo $netmask;?></td>
       </tr>
       <tr class="zebra">
        <td class="theader"><?php echo "Gateway IP address";?></td>
        <td><?php echo $gwaddr;?></td>
       </tr>
       <tr>
        <td class="theader"><?php echo "DNS IP address";?></td>
        <td><?php echo $nsaddr;?></td>
       </tr>
      </table>

      <?php  
      
    if ($wmode != "")
      {
      
    ?>
      <hr style="margin:40px 0 -10px 0; width:430px;" size="6" noshade>
      <h1>Wireless LAN Information</h1>
      <table>
       <tr class="zebra">
        <td width="190px" class="theader"><?php echo "WLAN mode";?></td>
        <td>
         <?php      
         
    switch($wmode)
         {
          case 
    "INFRA":
           
    $wmode "Infrastructure";
           break;
          case 
    "IBSS":
           
    $wmode "Ad-hoc";
           break;
          case 
    "AP":
           
    $wmode "Soft AP";
           break;
         }

         echo 
    $wmode;
         
    ?>
        </td>
       </tr>
       <tr>
        <td width="190px" class="theader"><?php echo "SSID";?></td>
        <td>
         <?php echo $ssid;?>
        </td>
       </tr>
       <tr class="zebra">
        <td width="190px" class="theader"><?php echo "Signal strength";?></td>
        <td>
         <?php echo "-",$rssi,"dbm";?>
        </td>
       </tr>
       <tr>
        <td width="190px" class="theader"><?php echo "Security";?></td>
        <td>
         <?php
         
    if($rsna == "")
          echo 
    "NONE";
         else
          echo 
    $rsna;  
         
    ?>
        </td>
       </tr>
       <tr class="zebra">
        <td width="190px" class="theader"><?php echo "Key Management";?></td>
        <td>
         <?php
         
    if($akm == "")
          echo 
    "-";
         else
          echo 
    $akm;
         
    ?>
        </td>
       </tr>
       <tr>
        <td width="190px" class="theader"><?php echo "Encryption";?></td>
        <td>
         <?php
         
    if($cipher == "")
          echo 
    "-";
         else
          echo 
    $cipher;
         
    ?>
        </td>
       </tr>
      </table>
      <?php
      
    }
      
    ?>
     </center>
     </form>
     <br /><br />
     <div id="footer">
      <div class="superFooter">

      </div>
     </div>
    </body>
    </html>


    This file provides system and network information. It includes HTML, CSS and PHPoC code. When Web browser request this file:
    • PHPoC code is interpreted. It does:
      • Reads System and Network information.
      • Print System and Network information to HTML code.
    • After PHPoC code is interpreted, HTML and CSS code are responded to Web browser.
    • Web browser displays the information according to HTML and CSS code.
    User Interface


    setup.php
    PHP Code:
    <?php

    include_once "/lib/sc_envs.php";

    $envs envs_read();

    if(
    envs_get_net_opt($envsNET_OPT_DHCP))
     
    $ip_type 1;
    else
     
    $ip_type 0;

    if(
    envs_get_net_opt($envsNET_OPT_WLAN))
     
    $net_type 1;
    else
     
    $net_type 0;

    $wmode    envs_get_net_opt($envsNET_OPT_TSF);
    $channel  envs_get_net_opt($envsNET_OPT_CH);
    $eap_type envs_get_net_opt($envsNET_OPT_WPA);

    $ipaddr  inet_ntop(substr(envs_find($envsENV_CODE_IP40x00), 04));
    $netmask inet_ntop(substr(envs_find($envsENV_CODE_IP40x01), 04));
    $gwaddr  inet_ntop(substr(envs_find($envsENV_CODE_IP40x02), 04));
    $nsaddr  inet_ntop(substr(envs_find($envsENV_CODE_IP40x03), 04));

    $ssid_env       envs_find($envsENV_CODE_WLAN0x01);
    $ssid_pos   strpos($ssid_envint2bin(0x001));
    $ssid    substr($ssid_env0, (int)$ssid_pos);

    $shared_key_env envs_find($envsENV_CODE_WLAN0x08);
    $shared_key_pos strpos($shared_key_envint2bin(0x001));
    $shared_key  substr($shared_key_env0, (int)$shared_key_pos);

    ?>
    <!DOCTYPE html>
    <html>
    <head>
     <title>PHPoC</title>
     <meta content="initial-scale=0.7, maximum-scale=1.0, minimum-scale=0.5, width=device-width, user-scalable=yes" name="viewport">
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
     <style type="text/css">
      body { font-family: verdana, Helvetica, Arial, sans-serif, gulim; }
      h1 { font-weight: bold; font-family : verdana, Helvetica, Arial, verdana, sans-serif, gulim; font-size:15pt; padding-bottom:5px;}
      table {border-collapse:collapse; width:430px;  font-size:10pt;}
      .theader { font-weight: bold;}
      tr {height :28px;}
      td { padding-left: 10px; text-align: left;}
      .superHeader {height: 2em; color: white; background-color: rgb(0,153,153); font-size:9pt; position:fixed; left:0; right:0; top:0; z-index:5;  }  
      .right {
        color: white;
        position: absolute;
        right: 1px;
        bottom: 4px;
        font-size:9pt;  
      }
      .left {
        color: white;
        position: absolute;
        left: 1px;
        bottom: 4px;
        font-size:9pt;  
      }
      .right a, .left a
      {
        color: white;
        background-color: transparent;
        text-decoration: none;
        margin: 0;
        padding:0 2ex 0 2ex;
      }  
      .right a:hover, .left a:hover
      {
        color: white;
        text-decoration: underline;
       }  
      .midHeader {color: white; background-color: rgb(6, 38, 111);  position:fixed; left:0; right:0; top:1.5em;  z-index:3;}
      .headerTitle {
        font-size: 250%;
        font-weight: normal;
        margin: 0 0 0 4mm;
        padding: 0.25ex 0 1ex 0;
        font-family: impact;
      }
      .headerMenu{
       position:relative;
       width: 430px;
       padding: 5px;
      }
      #footer{margin:0 auto; height:auto !important; height:100%; margin-bottom:-100px;  }
      .superFooter {
       height: 2em; color: white; background-color: rgb(6, 38, 111); font-size:9pt; position:fixed; left:0; right:0; bottom:0; z-index:4;
      }    
      .zebra {background-color : #ECECEC;}
     </style>
     <script type="text/javascript">

     function chkUI()
     {
      chkWlan();
      chkIPGetType();
      chkHideKey();
     }

     function chkWlan()
     {
      var pbh_setup = document.pbh_setup;
      if(pbh_setup.wlan_opt[1].checked) // WLAN disable
      {
       pbh_setup.ip_type[0].disabled = "";
       pbh_setup.ip_type[1].disabled = "";

       pbh_setup.tsf[0].disabled = "true";
       pbh_setup.tsf[1].disabled = "true";
       pbh_setup.tsf[2].disabled = "true";
       pbh_setup.channel.disabled = "true";
       pbh_setup.ssid.disabled = "true";
       pbh_setup.shared_key.disabled = "true";
       pbh_setup.hide_key.disabled = "true";
      }
      else // WLAN enable
      {
       pbh_setup.tsf[0].disabled = "";
       pbh_setup.tsf[1].disabled = "";
       pbh_setup.tsf[2].disabled = "";

       pbh_setup.ssid.disabled = "";
       pbh_setup.shared_key.disabled = "";
       pbh_setup.hide_key.disabled = "";

       chkChannel();  
      }
     }

     function chkChannel() {
      var pbh_setup = document.pbh_setup;  

      if(pbh_setup.tsf[1].checked) //infrastructure
      {
       pbh_setup.channel.disabled = "true";      
       pbh_setup.channel.value = "0";
       pbh_setup.ip_type[0].disabled = "";
       pbh_setup.ip_type[1].disabled = "";

       if(pbh_setup.ip_type[1].checked) //DHCP
       {
        pbh_setup.ipaddr.disabled = "true";
        pbh_setup.netmask.disabled = "true";
        pbh_setup.gwaddr.disabled = "true";
        pbh_setup.nsaddr.disabled = "true";
       }
       else
       {
        pbh_setup.ipaddr.disabled = "";
        pbh_setup.netmask.disabled = "";
        pbh_setup.gwaddr.disabled = "";
        pbh_setup.nsaddr.disabled = "";
       }
      }
      else if(pbh_setup.tsf[2].checked)  //softap
      {
       pbh_setup.channel.disabled = "";
       pbh_setup.ip_type[1].checked = true;
       pbh_setup.ip_type[0].disabled = "true";
       //pbh_setup.ip_type[1].disabled = "true";
       chkIPGetType();
      }
      else
      {
       pbh_setup.channel.disabled = "";
       pbh_setup.ip_type[0].disabled = "";
       pbh_setup.ip_type[1].disabled = "";
      }
     }

     function chkIPGetType()
     {
      var pbh_setup = document.pbh_setup;
      if(pbh_setup.ip_type[1].checked)
      {
       pbh_setup.ipaddr.disabled = "true";
       pbh_setup.netmask.disabled = "true";
       pbh_setup.gwaddr.disabled = "true";
       pbh_setup.nsaddr.disabled = "true";
      }
      else
      {
       pbh_setup.ipaddr.disabled = "";
       pbh_setup.netmask.disabled = "";
       pbh_setup.gwaddr.disabled = "";
       pbh_setup.nsaddr.disabled = "";
      }
     }

     function chkHideKey() {
      var pbh_setup = document.pbh_setup;
      if(pbh_setup.hide_key.checked == true)
      {
       pbh_setup.shared_key.type = "password";
      }else {
       pbh_setup.shared_key.type = "text";
      }
     }

     function checkIpForm(ip_addr)
     {
      var filter =  /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;

      if (ip_addr.match(filter))
       result = true;
      else  
       result = false;  

      return result;
     }

     function excSubmit()
     {  
      var pbh_setup = document.pbh_setup;

      //IP check
      var ip_result = checkIpForm(pbh_setup.ipaddr.value);
      if(ip_result == false)
      {
       alert("Please check your IP address.");
       pbh_setup.ipaddr.focus();
       return;
      }

      //subnet check
      var subnet_result = checkIpForm(pbh_setup.netmask.value);
      if(subnet_result == false)
      {
       alert("Please check your Subnet mask.");
       pbh_setup.netmask.focus();
       return;
      }

      //Gateway check
      var gwaddr_result = checkIpForm(pbh_setup.gwaddr.value);
      if(gwaddr_result == false)
      {
       alert("Please check your Gateway IP address.");
       pbh_setup.gwaddr.focus();
       return;
      }

      //DNS check
      var nsaddr_result = checkIpForm(pbh_setup.nsaddr.value);
      if(nsaddr_result == false)
      {
       alert("Please check your DNS IP address.");
       pbh_setup.nsaddr.focus();
       return;
      }

      if (pbh_setup.wlan_opt[0].checked)
      {
       //SSID check
       if ( pbh_setup.ssid.value.length > 32) // MAX 32 bytes
       {
        alert("Please check the SSID.");
        pbh_setup.ssid.focus();
        return;
       }  

       //shared key check
       if(pbh_setup.tsf[2].checked)
       {
        if(pbh_setup.shared_key.value.length && (pbh_setup.shared_key.value.length < 8))
        {
         alert("Please check the length of shared key.");
         pbh_setup.shared_key.focus();
         return;
        }
       }

      }

      pbh_setup.submit();

      var ipaddr = pbh_setup.ipaddr.value;
         var ip_type;

      if (pbh_setup.ip_type[0].checked == true)
       ip_type = 0; //static IP address
      else
       ip_type = 1; //DHCP

      if (((ipaddr != '<?php echo $ipaddr;?>' && pbh_setup.ip_type[0].checked)) || (ip_type != <?php echo $ip_type;?> && pbh_setup.ip_type[0].checked))
      {
       var url = pbh_setup.ipaddr.value;
       url = "http://" + url;
       alert("Redirect to : " + url);

       var win = window.open(url);
      }

     }
     </script>
    </head>
    <body onload="chkUI();">
        <div id="header">
      <div class="superHeader">  
       <div class="left">
       </div>
       <div class="right">
        <a href="http://www.sollae.co.kr" target="_blank">SOLLAE SYSTEMS</a>
       </div>
      </div>

      <div class="midHeader">
       <center>
        <h1 class="headerTitle"><?php echo system("uname -i");?></h1>
        <div class="headerMenu">
         <div class="left">
          <a href="index.php">INFO</a>  |
          <a href="setup.php">SETUP</a>  
         </div>
         <div class="right">
          <a href="javascript:excSubmit();">SAVE</a>  
         </div>
        </div>
       </center>
      </div>

      <div class="subHeader">
      </div>  
     </div>
     <br /><br /><br /><br />
     <form name="pbh_setup" action="setup_ok.php" method="post">  
     <center>
      <hr style="margin:50px 0 -10px 0; width:430px;" size="6" noshade>
      <h1>Network</h1>

      <table>
       <tr class="zebra">
        <td width="170px" class="theader">IP address Type</td>
        <td>
         <input type="radio" value="0" name="ip_type" onclick="chkIPGetType();" <? if($ip_type == 0) echo "checked" ?> /> Static IP address<br />
         <input type="radio" value="1" name="ip_type" onclick="chkIPGetType();" <? if($ip_type == 1) echo "checked" ?> /> DHCP (Auto DNS server)
        </td>
       </tr>
       <tr>
        <td class="theader">IP address</td>
        <td>
         <input type="text" name="ipaddr" value="<? echo $ipaddr ?>">
         <input type="hidden" name="old_ipaddr" value="<? echo $ipaddr ?>">
        </td>
       </tr>
       <tr class="zebra">
        <td class="theader">Subnet mask</td>
        <td>
         <input type="text" name="netmask" value="<? echo $netmask ?>">
        </td>
       </tr>
       <tr>
        <td class="theader">Gateway IP address</td>
        <td>
         <input type="text" name="gwaddr" value="<? echo $gwaddr ?>">
        </td>
       </tr>
       <tr class="zebra">
        <td class="theader">DNS IP address</td>
        <td>
         <input type="text" name="nsaddr" value="<? echo $nsaddr ?>">
        </td>
       </tr>
      </table>

      <hr style="margin:50px 0 -10px 0; width:430px;" size="6" noshade>
      <h1>Wireless LAN</h1>
      <table>
       <tr class="zebra">
        <td width="170px" class="theader">WLAN</td>
        <td>
         <input type="radio" value="1" name="wlan_opt" onclick="chkWlan();" <? if($net_type == 1) echo "checked" ?> /> Enable<br />
         <input type="radio" value="0" name="wlan_opt" onclick="chkWlan();" <? if($net_type == 0) echo "checked" ?> /> Disable
        </td>
       </tr>
       <tr>
        <td class="theader">WLAN mode</td>
        <td>
         <input type="radio" value="0" name="tsf" onclick="chkChannel();" <? if($wmode == 0) echo "checked" ?> /> Ad-hoc<br />
         <input type="radio" value="1" name="tsf" onclick="chkChannel();" <? if($wmode == 1) echo "checked" ?> /> Infrastructure<br />
         <input type="radio" value="2" name="tsf" onclick="chkChannel();" <? if($wmode == 2) echo "checked" ?> /> Soft AP
        </td>
       </tr>
       <tr class="zebra">
        <td class="theader">Channel</td>
        <td>
         <select name="channel">
          <option value="0" <? if($channel == 0) echo "selected" ?>>Auto</option>
          <option value="1" <? if($channel == 1) echo "selected" ?>>1</option>
          <option value="2" <? if($channel == 2) echo "selected" ?>>2</option>
          <option value="3" <? if($channel == 3) echo "selected" ?>>3</option>
          <option value="4" <? if($channel == 4) echo "selected" ?>>4</option>
          <option value="5" <? if($channel == 5) echo "selected" ?>>5</option>
          <option value="6" <? if($channel == 6) echo "selected" ?>>6</option>
          <option value="7" <? if($channel == 7) echo "selected" ?>>7</option>
          <option value="8" <? if($channel == 8) echo "selected" ?>>8</option>
          <option value="9" <? if($channel == 9) echo "selected" ?>>9</option>
          <option value="10" <? if($channel == 10) echo "selected" ?>>10</option>
          <option value="11" <? if($channel == 11) echo "selected" ?>>11</option>      
          <option value="12" <? if($channel == 12) echo "selected" ?>>12</option>
          <option value="13" <? if($channel == 13) echo "selected" ?>>13</option>      
         </select>

        </td>
       </tr>
       <tr>
        <td class="theader">SSID</td>
        <td>
         <input type="text" name="ssid" size="20" maxlength="31" value="<? echo $ssid ?>">
        </td>
       </tr>
       <tr class="zebra">
        <td class="theader">Shared Key</td>
        <td>
         <input type="text" name="shared_key" size="20" maxlength="63" value="<? echo $shared_key ?>"><br />
         (<input type="checkbox" name="hide_key" onclick="chkHideKey()" checked />hide key)
        </td>
       </tr>
       <tr>
        <td class="theader">802.1x</td>
        <td>
         <input type="hidden" name="eap_type" value="<? echo $eap_type ?>">      
         <select name="eap" disabled>
          <option value="0" <? if($eap_type == 0) echo "selected" ?>>None</option>
          <option value="1" <? if($eap_type == 1) echo "selected" ?>>EAP-TLS</option>
          <option value="2" <? if($eap_type == 2) echo "selected" ?>>EAP-TTLS</option>
          <option value="3" <? if($eap_type == 3) echo "selected" ?>>PEAP</option>
         </select>
        </td>
       </tr>
      </table>
     </center>
     </form>
     <br /><br /><br /><br />
     <div id="footer">
      <div class="superFooter">
      </div>
     </div>
    </body>
    </html>


    This file provides User Interface, which allows user to config network information. It includes HTML, CSS, JavaScript and PHPoC code. When Web browser request this file:
    • PHPoC code is interpreted. It does:
      • Reads System and Network information.
      • Print System and Network information to HTML code.
    • After PHPoC code is interpreted, HTML and CSS code are responded to Web browser.
    • Web browser displays the information according to HTML and CSS code.
    • JavaScript does the checking on network parameters.
    Network parameters shown on this page are editable. It let users modify and save in on PHPoC.
    When user input network parameters and click "save" button, JavaScript will does:
    • Check the input parameters to make sure that user types in correct format.
    • Make HTTP POST request to action page (setup_ok.php). HTTP POST includes all network parameters.
    User Interface


    setup_ok.php
    PHP Code:
    <?php
    if(!_SERVER("HTTP_REFERER"))
    {
     
    header('HTTP/1.1 403 Forbidden');

     
    $php_name _SERVER("SCRIPT_NAME");

     echo 
    "<html>\r\n",
      
    "<head><title>403 Forbidden</title></head>\r\n",
      
    "<body>\r\n",
      
    "<h1>Forbidden</h1>\r\n",
      
    "<p>You don't have permission to access /$php_name on this server.</p>\r\n",
      
    "</body></html>\r\n";

     return;
    }
    ?>
    <!DOCTYPE html>
    <html>
    <head>
     <title>PHPoC</title>
     <meta content="initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, width=device-width" name="viewport">
     <style type="text/css">
      <!--
      body { font-family: Tahoma, Helvetica, sans-serif, gulim; }
      -->
     </style>
    </head>
    <body>

    <center>

    <br>

    <?php

    include_once "/lib/sc_envs.php";

    $net_opt_tsf  = (int) _POST("tsf");
    $net_opt_ch   = (int) _POST("channel");
    $net_opt_wpa  = (int) _POST("eap_type");
    $net_opt_wlan = (int) _POST("wlan_opt");  // Enable 1 - Disbale 0
    $ip_type      = (int) _POST("ip_type");
    $ssid         _POST("ssid");
    $shared_key   _POST("shared_key");

    $envs envs_read();

    if(
    $net_opt_tsf == 2)
    // SoftAP
     
    envs_set_net_opt($envsNET_OPT_DHCP1);
     
    envs_set_net_opt($envsNET_OPT_AUTO_NS1);
    }
    else
    // Ad-hoc or Infrastructure
     
    if($ip_type == 0)
     { 
    // Static IP Address
      
    envs_set_net_opt($envsNET_OPT_DHCP0);
      
    envs_set_net_opt($envsNET_OPT_AUTO_NS0);

      
    $ipaddr  _POST("ipaddr");
      
    $netmask _POST("netmask");
      
    $gwaddr  _POST("gwaddr");
      
    $nsaddr  _POST("nsaddr");

      
    envs_update($envsENV_CODE_IP40x00inet_pton($ipaddr));
      
    envs_update($envsENV_CODE_IP40x01inet_pton($netmask));
      
    envs_update($envsENV_CODE_IP40x02inet_pton($gwaddr));
      
    envs_update($envsENV_CODE_IP40x03inet_pton($nsaddr));
     }
     else
     { 
    // DHCP
      
    envs_set_net_opt($envsNET_OPT_DHCP1);
      
    envs_set_net_opt($envsNET_OPT_AUTO_NS1);
     }
    }

    envs_set_net_opt($envsNET_OPT_WLAN$net_opt_wlan);

    if(
    $net_opt_wlan == 1// wlan enabled
    {  
     if(
    $ssid != rtrim(envs_find($envsENV_CODE_WLAN0x01)))
      
    $comp_psk true;
     else
     if(
    $shared_key != rtrim(envs_find($envsENV_CODE_WLAN0x08)))
      
    $comp_psk true;
     else
      
    $comp_psk false;

     if(
    $comp_psk)
     {
      
    // psk generation take 0.5 second on STM32F407 168MHz
      
    $wpa_psk hash_pbkdf2("sha1"$shared_key$ssid409632true);
      
    envs_update($envsENV_CODE_WLAN0x09$wpa_psk);
     }

     
    envs_update($envsENV_CODE_WLAN0x01$ssid);
     
    envs_update($envsENV_CODE_WLAN0x08$shared_key);

     
    envs_set_net_opt($envsNET_OPT_TSF$net_opt_tsf);
     
    envs_set_net_opt($envsNET_OPT_CH$net_opt_ch);
     
    envs_set_net_opt($envsNET_OPT_WPA$net_opt_wpa);
     
    envs_set_net_opt($envsNET_OPT_PHY3);
     
    envs_set_net_opt($envsNET_OPT_SHORT_PRE1);
     
    envs_set_net_opt($envsNET_OPT_SHORT_SLOT1);
     
    envs_set_net_opt($envsNET_OPT_CTS_PROT1);
    }

    if(
    $ip_type == 1)
     echo 
    "<br><br><h4>IP address may be changed. ",
      
    "Please check newly assigned IP address from PHPoC Debugger and ",
      
    "reconnect to the device.</h4><br><br>\r\n";
    else
     echo 
    "<br><br>";

    $wkey envs_get_wkey();
    envs_write($envs$wkey);

    echo 
    "<h2>setup complete</h2>\r\n";

    if(
    $ip_type != 1)
     echo 
    "<a href=index.php>Home</a>&nbsp;&nbsp;<br>\r\n";

    system("reboot sys 1000");

    ?>

    </center>
    </body>
    </html>


    This file is action file, which serve HTTP POST request from setup page. It includes HTML, CSS and PHPoC code. When HTTP POST request are made:
    • PHPoC code is interpreted. It does:
      • Reads Network information from HTTP POST.
      • Save these information on PHPoC device.
    • After PHPoC code is interpreted, HTML and CSS code are responded to Web browser.
    • Web browser displays the information according to HTML and CSS code.
    User Interface

    Other Resources
    Last edited by support; 09-04-2018, 12:31 PM.
      Posting comments is disabled.

    Categories

    Collapse

    Latest Articles

    Collapse

    • Arduino - RS-485 Expansion Board
      support
      PES-2607 is an easy-to-use RS422/RS485 Expansion Board for Arduino Uno and Mega, which allows Arduino to exchange data with serial device via RS422 or RS485.
      Especially, Arduino does NOT use UART pins to communicate with RS422/RS485 expansion board. Therefore, users can use Arduino UART pins for other purposes.
      Moreover, A single Arduino Uno/Mega can communicate with multiple RS422/RS485 expansion boards (up to 14) without using Arduino UART pins.

      Library and examples for...
      11-13-2018, 03:45 PM
    • Arduino - RS-422 Expansion Board
      support
      PES-2607 is an easy-to-use RS422/RS485 Expansion Board for Arduino Uno and Mega, which allows Arduino to exchange data with serial device via RS422 or RS485.
      Especially, Arduino does NOT use UART pins to communicate with RS422/RS485 expansion board. Therefore, users can use Arduino UART pins for other purposes.
      Moreover, A single Arduino Uno/Mega can communicate with multiple RS422/RS485 expansion boards (up to 14) without using Arduino UART pins.

      Library and examples for...
      11-13-2018, 03:44 PM
    • Arduino - RS-232 Expansion Board
      support
      PES-2606 is an easy-to-use RS-232 Expansion Board for Arduino Uno and Mega, which allows Arduino to exchange data with serial device via RS-232.
      Especially, Arduino does NOT use UART pins to communicate with RS-232 expansion board. Therefore, users can use Arduino UART pins for other purposes.
      Moreover, A single Arduino Uno/Mega can communicate with multiple RS-232 expansion boards (up to 14) without using Arduino UART pins.

      Library and example for the RS-232 expansion board...
      11-13-2018, 03:43 PM
    • Arduino - Stepper Motor Controller
      support
      PES-2605 is an easy-to-use stepper motor controller for Arduino Uno and Mega, which uses micro-stepping method to precisely control stepper motor.
      Library and example for the stepper motor controller are part of of PhpocExpansion library for Arduino. The library reference is available here.

      This tutorial shows how to use the step motor controller with an example of PhpocExpansion library for Arduino.


      Hardware Required...
      11-13-2018, 03:41 PM
    • Arduino - DC Motor Controller
      support
      PES-2604 is an easy-to-use DC motor controller for Arduino Uno and Mega.
      Library and example for the DC motor controller are part of of PhpocExpansion library for Arduino. The library reference is available here.

      This tutorial shows how to use the DC motor controller with an example of PhpocExpansion library for Arduino.


      Hardware Required...
      11-13-2018, 03:40 PM
    • Arduino - Digital Input Board
      support
      PES-2602 is an easy-to-use 4-port Input Expansion Board for Arduino Uno and Mega, which allows Arduino to monitor state of DC electric device. In addition, it can monitor NPN, PNP and dry contact(relay).
      Library and example for the 4-port input expansion board are part of of PhpocExpansion library for Arduino. The library reference is available here.

      This tutorial shows how to use 4-port input expansion board with an example of PhpocExpansion library for Arduino.

      ...
      11-13-2018, 03:39 PM
    Working...
    X