Announcement

Collapse
No announcement yet.

( Mikrotik RB750GL ) online 30 user ยังสบายตัว

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • ( Mikrotik RB750GL ) online 30 user ยังสบายตัว

    ขายอยู่เผื่อใครต้องการ
    >>>> mikrotik api web server ver1.2 ( ระบบจัดการ mikrotik จำนวนมาก ราคา 500บาท )<< จิ้มเบาๆ <<<<

    Mikrotik RB750GL online 30 user ยังเด็กๆ ส่ง log nsa310 ดัวย cpu ใช้แค่ 20-50%
    RB750G.jpg
    เลิก user man
    แล้วมาจัดการ ทางapi กันดีกว่า

    แจกกันไป php api resource + user online (ใช้ใน localhost นะครับ)

    เปลี่ยน ip mikrotik 10.5.50.1 user pass ด้วยครับ // (user ที่ใช้ login เข้า mikrotik อันเดียวกับที่ใช้ login winbox)
    Code:
    if ($API->connect('10.5.50.1', 'admin', 'passs'))
    IP mikrotik สามาใส่ ip ที่ได้จาก พวก tot 3bb เพื่อ remote จากนอกวงlan ได้นะครับ

    อาจจะเอามาจาก no-ip.com หรือให้ mikrotik ส่งip มาทาง email ก็ได้


    ex. save เป็น online.php ใส่ไว้ใน C:\AppServ\www

    เวลาใช้งาน เปิดfirifox แล้วพิมพ์ http://localhost/online.php

    เอาไว้ดูพวก cpu ram ใช้ไปเท่าไร user ออนไลย์ กี่คน
    re.jpg
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    
    <!-- by ross_ice-->
    
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>User Online Mikrotik</title>
    </head>
    <body>
    <?php
    
    require('routeros_api.class.php');
    
    $API = new routeros_api();
    
    //$API->debug = true;
    
    if ($API->connect('10.5.50.1', 'admin', 'passs')) {
    
    $resource = $API->comm("/system/resource/print");
    //echo "<pre>";print_r($resource);die();
    
    $free_memory=$resource[0]['free-memory'];
    
    $free_memory = $free_memory/1024;
    $free_memory = round($free_memory, 0);
    $cpu_load = $resource[0]['cpu-load'];
    $run_uptime = $resource[0]['uptime'];
    $hdd_space = $resource[0]['free-hdd-space'];
    $hdd_space= $hdd_space/1024;
    $hdd_space = round($hdd_space, 0);
    echo "Resource // (Cpu Run :$cpu_load %)     (Free Memory : $free_memory MB)    (Hdd Space : $hdd_space MB)    (Up Time : $run_uptime) <br>";
    
    
    $items = $API->comm("/ip/hotspot/active/print");
    
    
    echo "On Line ".$all_user=count($items) ." User <br>";
    
    $count=0;
    while ( $count < $all_user){
    $user = $items[$count]['user'];
    $ip = $items[$count]['address'];
    $maca = $items[$count]['mac-address'];
    $uptime = $items[$count]['uptime'];
    
    echo "/user : $user /IP : $ip /mac : $maca /uptime : $uptime <br>";
    $count++;
    }
    //echo "<pre>";print_r($items['0']);die();
    
       $API->disconnect();
    
    }
    
    ?>
    </body>
    </html>



    อันนี้ api add user mikrotik อัพโหลด จากไฟล์ csv เพิ่มทีล่ะ 100 user 30 วิก็เสร็จแล้ว


    ex. save เป็น addusermikrotik.php ใส่ไว้ใน C:\AppServ\www

    เวลาใช้งาน เปิดfirefox แล้วพิมพ์ http://localhost/addusermikrotik.php

    เอาไว้อัพโหลดuser จากไฟล์ csv เข้า mikrotik (หรือ microsoft excel ที่เชฟเป็น csv)

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    
    <!-- Mirrored from www.snaptin.com/demo/broom_cupboard/1.html by HTTrack Website Copier/3.x [XR&CO'2010], Fri, 11 Feb 2011 12:50:46 GMT -->
    <!-- Added by HTTrack --><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><!-- /Added by HTTrack -->
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Mikrotik All User</title>
    </head>
    <body>
    
    <?
    
    if(isset($_POST['submit']) && $_POST['submit']=='submit'){
    require('routeros_api.class.php');
    
    //confik connect
    
    $mikrotik_ip = '10.5.50.1';  // เปลี่ยน ip mikrotik เป็นของตัวเอง
    $mikrotik_username = 'admin';  //   เปลี่ยน admin mikrotik เป็นของตัวเอง
    $mikrotik_password = 'password';   //เปลี่ยน pass admin mikrotik เป็นของตัวเอง
    
    
    move_uploaded_file($_FILES["fileCSV"]["tmp_name"],$_FILES["fileCSV"]["name"]); // Copy/Upload CSV
    
    
    $objCSV = fopen($_FILES["fileCSV"]["name"], "r");
    while (($objArr = fgetcsv($objCSV, 1000, ",")) !== FALSE) {
    
    //echo "upload ok<br>";
        $username_add=$objArr[0];    //user ดึงมาจาก .csv (col 1)
        $password_add=$objArr[1];    //password ดึงมาจาก .csv (col 2)
        $hotspot_server = 'hotspot1';    // เปลี่ยน hotspot server mikrotik เป็นของตัวเอง   ของผมมีอันเดียว hotspot1 fix ไว้เลย
        $hotspot_profile = 'speed2m/30d';         // เปลี่ยน  user profile เป็นของตัวเอง  ของผม  2m เป็นหลัก fix ไว้เลย
        $limit_uptime=$objArr[2].'d 00:00:00';    // limit uptime  ตั้งให้ใช้ได้ กี่วัน ดึงมาจาก .csv (col 3)  (ex รูปแบบ 30d 00:00:00 คือใช้ได้  30วัน)
    
    	
        if($username_add  != '' ){
       
       ///// start
       $API = new routeros_api();
    // $API->debug = true;
    
    if ($API->connect($mikrotik_ip,$mikrotik_username,$mikrotik_password)){
    //echo "connect ok<br>";
    		$username="=name=".$username_add;
    
    		$pass="=password=".$password_add;
    
    		$server="=server=".$hotspot_server;
    
    		//$uptimes="=limit-uptime=".$limit_uptime;
    				
    		$profile="=profile=".$hotspot_profile;
    		
    
     //echo "$username $pass $server $profile<br>";
    	   	$API->write('/ip/hotspot/user/add',false);
    	   	$API->write($username, false);
    	   	$API->write($pass, false);
    	   	$API->write($server, false);
    		$API->write($profile);
    
    		$items = $API->read();
            
    		// Debug variable (return value)
    		//echo "<pre>";
    	   	//print_r($items);
    		//echo "</pre>";
    
       	$API->disconnect();
       }
      
       ///// end
       
       
       
       
       
    	}
    }
    fclose($objCSV);
    
    echo "Upload & Import Done.";
    }
    ?>
    <p><b>Import User From CSV</b></p>
    <form action="" method="post" enctype="multipart/form-data" name="form1">
      <input name="fileCSV" type="file" id="fileCSV">
      <input name="submit" type="submit"  value="submit">
    </form>
    
    </body>
    </html>
    ตัวอย่าง ไฟล์ csv ของผม เขียน php gen ออกมา

    col 1 =user , col2=password, col3=วันใช้งาน

    ex.
    ก๊อปใส่ notepad แล้ว save เป็น รายชื่อuser.csv // แล้วใช้ microsoft excel เปิดไฟล์ รายชื่อuser.csv ดู จะเข้าใจ

    (excel ทุกคนเก่งๆกันอยู่แล้ว ลากปืดๆ สร้าง user 500-1000 แถว น่าจะของเด็กๆ)

    Code:
    1djgt67,hufw,10, 
    1drgxmz,rw9q,10, 
    1d3otu7,hq7k,10, 
    1dzgder,5ubg,10, 
    1dtyrgx,rcpa,10, 
    1dfg5i3,7ot6,10, 
    1d3s5mr,96vg,10, 
    1dpajox,vohi,10, 
    1dx63wh,3kty,10, 
    1d52fc1,3gd6,10, 
    1drc5yr,349e,10,

    php อันนี้เอาไว้ เจน user password และวันใช้งาน

    1.ก๊อบใส่ notepad แล้ว save เป็น genuser.php ใส่ไว้ใน C:\AppServ\www
    2.เวลาใช้งานเปิด firefox แล้วพิมพ์ http://localhost/genuser.php
    genเสร็จมันจะเป็น ป๊อปอัพดาวโหลดไฟล์ username.csv นะครับ บางที่firefox มันบล๊อกหน้าต่างป๊อปอัพไว้ ที่เป็นแถบเหลืองๆ

    genuser.jpg

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"   
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
    <!-- ross_ice -->
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Gen User Mikrotik </title>
    </head>
    <body>
    		<table width="300" height="150" style="border: 1px solid #cccccc; padding: 0px;" cellpadding="0" cellspacing="0">
    			<tr>
    				<td align="center" valign="top" height="175" colspan="2">
    					<form name="login" action="" method="post">
    						
    							<table width="600" style="background-color: #ffffff">
    							    <tr><td align="right">fix username </td>
    										<td><input style="width: 80px" name="fix_user" type="text" value="1d" maxlength="2" /> ตัวอักษรนำหน้า user</td>
    								</tr>
    								<tr><td align="right">username </td>
    										<td><input style="width: 80px" name="num_user" type="text" value="5" maxlength="1" /> ตัวอักษร</td>
    								</tr>
    								<tr><td align="right">Password </td>
    										<td><input style="width: 80px" name="num_pass" type="text" value="4"maxlength="1" /> ตัวอักษร</td>
    								</tr>
    								<tr>
    								  <td align="right">สร้าง ทั้งหมด</td>
    								  <td><input style="width: 80px" name="max_user" type="text" value="48" maxlength="3"/> user</td>
    								</tr>
    								
    								<tr>
    								  <td align="right">ใช้ได้ </td>
    								  <td><input style="width: 80px" name="day" type="text" value="10" maxlength="3" /> วัน</td>
    								</tr>
    								
    								<tr><td>&nbsp;</td>
    										<td><input type="submit" name="submit" value="Gen user" /></td>
    								</tr>
    							</table>
    					</form>
    				</td>
    			</tr>
    			
    		</table>
    
    <?php
    function random_password($len)
    {
    	srand((double)microtime()*10000000);
    	
    	// 2 บรรทัดข่างล่าง เลือกตัวอักษรที่ใช้ gen     จะเอาอันใหน ก็ลบเครื่องหมาย // ข่างหน้าออก   อย่าลืิมใส่ เครื่องหมาย // หน้าบรรทัดที่ไม่เอาไว้ด้วย
    	
    	//$chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";    //  gen ทั้งตัวพิมใหญ่พิมพ์เล็ก และตัวเลข 
    	$chars = "abcdefghijklmnopqrstuvwxyz0123456789";        // gen พิมพ์เล็กและตัวเลข    ไม่เอา A-Z พิมพ์ใหญ่ 
    	
        /////////////////////////////// 
    
    
    	
    	$ret_str = "";
    	$num = strlen($chars);
    	for($i = 0; $i < $len; $i++)
    	{
    		$ret_str.= $chars[rand()%$num];
    		$ret_str.=""; 
    	}
    	return $ret_str; 
    }
    
    
    
    if( isset($_POST['submit'])&& $_POST['submit']=='Gen user' ) {
    set_time_limit(0);
    
    $fix=trim($_POST['fix_user']);
    $num_user=trim($_POST['num_user']);
    $num_pass=trim($_POST['num_pass']);
    $max_user=trim($_POST['max_user']);
    $day=trim($_POST['day']);
    
    $loop=0;
    
    $filName = "username.csv";
    $objWrite = fopen($filName, "w");
    // fwrite($objWrite, "username,password,day"." \n");
     while($loopx < $max_user){
     $user='';
     $passw='';
     $user = random_password($num_user);
     $passw = random_password($num_pass);
     
    $useradd=$fix.$user;
    
    
     fwrite($objWrite, "$useradd,$passw,$day, \n");
    
     $loopx++;
    }
     fclose($objWrite);
      $conuser=count($adduser);
      echo "<br><br>สร้างแล้วทั้งหมด $loopx user ";
      
    // echo '<script>window.open("http://localhost/'.$filName.'", "_blank", "width=0,height=0")</script>';
     echo '<script>window.open("/'.$filName.'", "_blank", "width=0,height=0")</script>';
     }
    ?>
    
    </body>
    </html>
    อันนี้โปรแกรม appserv 2.5.10 ต้องลงก่อนเลย วิธีลง กด google วิธีติดตั้งappserv มีหลายเว็บสอนไว้เยอะ
    >>>ดาวโหลด appserv 2.5.10 <<<
    Last edited by ross_ice; 16 Feb 2014, 00:54:15. Reason: แก้ใข code add user ใหม่ อันเก่าไม่มี from

  • #2
    อันนี้ ไฟล์ routeros_api.class.php

    1.ก๊อบใส่ notepad แล้ว save เป็น routeros_api.class.php ใส่ไว้ใน C:\AppServ\www
    ไฟล์ php ด้านบนจะเรียกไปใช้งาน (สำคัญ)

    Code:
    <?php
    /*****************************
     *
     * RouterOS PHP API class v1.4
     * Author: Denis Basta
     * Contributors:
     *    Nick Barnes
     *    Ben Menking (ben [at] infotechsc [dot] com)
     *    Jeremy Jefferson (http://jeremyj.com)
     *    Cristian Deluxe (djcristiandeluxe [at] gmail [dot] com)
     *
     * http://www.mikrotik.com
     * http://wiki.mikrotik.com/wiki/API_PHP_class
     *
     ******************************/
    
    class routeros_api
    {
        var $debug = false;      // Show debug information
        var $error_no;           // Variable for storing connection error number, if any
        var $error_str;          // Variable for storing connection error text, if any
        var $attempts = 5;       // Connection attempt count
        var $connected = false;  // Connection state
        var $delay = 3;          // Delay between connection attempts in seconds
        var $port = 8728;        // Port to connect to
        var $timeout = 3;        // Connection attempt timeout and data read timeout
        var $socket;             // Variable for storing socket resource
        
        /**
         * Print text for debug purposes
         *
         * @param string      $text       Text to print
         *
         * @return void
         */
        function debug($text)
        {
            if ($this->debug)
                echo $text . "\n";
        }
    	
    	
        /**
         * 
         *
         * @param string        $length
         *
         * @return void
         */
        function encode_length($length)
        {
            if ($length < 0x80) {
                $length = chr($length);
            } else if ($length < 0x4000) {
                $length |= 0x8000;
                $length = chr(($length >> 8) & 0xFF) . chr($length & 0xFF);
            } else if ($length < 0x200000) {
                $length |= 0xC00000;
                $length = chr(($length >> 16) & 0xFF) . chr(($length >> 8) & 0xFF) . chr($length & 0xFF);
            } else if ($length < 0x10000000) {
                $length |= 0xE0000000;
                $length = chr(($length >> 24) & 0xFF) . chr(($length >> 16) & 0xFF) . chr(($length >> 8) & 0xFF) . chr($length & 0xFF);
            } else if ($length >= 0x10000000)
                $length = chr(0xF0) . chr(($length >> 24) & 0xFF) . chr(($length >> 16) & 0xFF) . chr(($length >> 8) & 0xFF) . chr($length & 0xFF);
            return $length;
        }
    	
    	
        /**
         * Login to RouterOS
         *
         * @param string      $ip         Hostname (IP or domain) of the RouterOS server
         * @param string      $login      The RouterOS username
         * @param string      $password   The RouterOS password
         *
         * @return boolean                If we are connected or not
         */
        function connect($ip, $login, $password)
        {
            for ($ATTEMPT = 1; $ATTEMPT <= $this->attempts; $ATTEMPT++) {
                $this->connected = false;
                $this->debug('Connection attempt #' . $ATTEMPT . ' to ' . $ip . ':' . $this->port . '...');
                if ($this->socket = @fsockopen($ip, $this->port, $this->error_no, $this->error_str, $this->timeout)) {
                    socket_set_timeout($this->socket, $this->timeout);
                    $this->write('/login');
                    $RESPONSE = $this->read(false);
                    if ($RESPONSE[0] == '!done') {
                        if (preg_match_all('/[^=]+/i', $RESPONSE[1], $MATCHES)) {
                            if ($MATCHES[0][0] == 'ret' && strlen($MATCHES[0][1]) == 32) {
                                $this->write('/login', false);
                                $this->write('=name=' . $login, false);
                                $this->write('=response=00' . md5(chr(0) . $password . pack('H*', $MATCHES[0][1])));
                                $RESPONSE = $this->read(false);
                                if ($RESPONSE[0] == '!done') {
                                    $this->connected = true;
                                    break;
                                }
                            }
                        }
                    }
                    fclose($this->socket);
                }
                sleep($this->delay);
            }
            if ($this->connected)
                $this->debug('Connected...');
            else
                $this->debug('Error...');
            return $this->connected;
        }
    	
    	
        /**
         * Disconnect from RouterOS
         *
         * @return void
         */
        function disconnect()
        {
            fclose($this->socket);
            $this->connected = false;
            $this->debug('Disconnected...');
        }
    	
    	
        /**
         * Parse response from Router OS
         *
         * @param array       $response   Response data
         *
         * @return array                  Array with parsed data
         */
        function parse_response($response)
        {
            if (is_array($response)) {
                $PARSED      = array();
                $CURRENT     = null;
                $singlevalue = null;
                $count       = 0;
                foreach ($response as $x) {
                    if (in_array($x, array(
                        '!fatal',
                        '!re',
                        '!trap'
                    ))) {
                        if ($x == '!re') {
                            $CURRENT =& $PARSED[];
                        } else
                            $CURRENT =& $PARSED[$x][];
                    } else if ($x != '!done') {
                        if (preg_match_all('/[^=]+/i', $x, $MATCHES)) {
                            if ($MATCHES[0][0] == 'ret') {
                                $singlevalue = $MATCHES[0][1];
                            }
    						$CURRENT[$MATCHES[0][0]] = (isset($MATCHES[0][1]) ? $MATCHES[0][1] : '');
    					}
                    }
                }
                if (empty($PARSED) && !is_null($singlevalue)) {
                    $PARSED = $singlevalue;
                }
                return $PARSED;
            } else
                return array();
        }
    	
    	
        /**
         * Parse response from Router OS
         *
         * @param array       $response   Response data
         *
         * @return array                  Array with parsed data
         */
        function parse_response4smarty($response)
        {
            if (is_array($response)) {
                $PARSED  = array();
                $CURRENT = null;
                $singlevalue = null;
                foreach ($response as $x) {
                    if (in_array($x, array(
                        '!fatal',
                        '!re',
                        '!trap'
                    ))) {
                        if ($x == '!re')
                            $CURRENT =& $PARSED[];
                        else
                            $CURRENT =& $PARSED[$x][];
                    } else if ($x != '!done') {
                        if (preg_match_all('/[^=]+/i', $x, $MATCHES)) {
                            if ($MATCHES[0][0] == 'ret') {
                                $singlevalue = $MATCHES[0][1];
                            }
                            $CURRENT[$MATCHES[0][0]] = (isset($MATCHES[0][1]) ? $MATCHES[0][1] : '');
    					}
                    }
                }
                foreach ($PARSED as $key => $value) {
                    $PARSED[$key] = $this->array_change_key_name($value);
                }
                return $PARSED;
                if (empty($PARSED) && !is_null($singlevalue)) {
                    $PARSED = $singlevalue;
                }
            } else {
                return array();
            }
        }
    	
    	
        /**
         * Change "-" and "/" from array key to "_"
         *
         * @param array       $array      Input array
         *
         * @return array                  Array with changed key names
         */
        function array_change_key_name(&$array)
        {
            if (is_array($array)) {
                foreach ($array as $k => $v) {
                    $tmp = str_replace("-", "_", $k);
                    $tmp = str_replace("/", "_", $tmp);
                    if ($tmp) {
                        $array_new[$tmp] = $v;
                    } else {
                        $array_new[$k] = $v;
                    }
                }
                return $array_new;
            } else {
                return $array;
            }
        }
    	
    	
        /**
         * Read data from Router OS
         *
         * @param boolean     $parse      Parse the data? default: true
         *
         * @return array                  Array with parsed or unparsed data
         */
        function read($parse = true)
        {
            $RESPONSE = array();
            while (true) {
                // Read the first byte of input which gives us some or all of the length
                // of the remaining reply.
                $BYTE   = ord(fread($this->socket, 1));
                $LENGTH = 0;
                // If the first bit is set then we need to remove the first four bits, shift left 8
                // and then read another byte in.
                // We repeat this for the second and third bits.
                // If the fourth bit is set, we need to remove anything left in the first byte
                // and then read in yet another byte.
                if ($BYTE & 128) {
                    if (($BYTE & 192) == 128) {
                        $LENGTH = (($BYTE & 63) << 8) + ord(fread($this->socket, 1));
                    } else {
                        if (($BYTE & 224) == 192) {
                            $LENGTH = (($BYTE & 31) << 8) + ord(fread($this->socket, 1));
                            $LENGTH = ($LENGTH << 8) + ord(fread($this->socket, 1));
                        } else {
                            if (($BYTE & 240) == 224) {
                                $LENGTH = (($BYTE & 15) << 8) + ord(fread($this->socket, 1));
                                $LENGTH = ($LENGTH << 8) + ord(fread($this->socket, 1));
                                $LENGTH = ($LENGTH << 8) + ord(fread($this->socket, 1));
                            } else {
                                $LENGTH = ord(fread($this->socket, 1));
                                $LENGTH = ($LENGTH << 8) + ord(fread($this->socket, 1));
                                $LENGTH = ($LENGTH << 8) + ord(fread($this->socket, 1));
                                $LENGTH = ($LENGTH << 8) + ord(fread($this->socket, 1));
                            }
                        }
                    }
                } else {
                    $LENGTH = $BYTE;
                }
                // If we have got more characters to read, read them in.
                if ($LENGTH > 0) {
                    $_      = "";
                    $retlen = 0;
                    while ($retlen < $LENGTH) {
                        $toread = $LENGTH - $retlen;
                        $_ .= fread($this->socket, $toread);
                        $retlen = strlen($_);
                    }
                    $RESPONSE[] = $_;
                    $this->debug('>>> [' . $retlen . '/' . $LENGTH . '] bytes read.');
                }
                // If we get a !done, make a note of it.
                if ($_ == "!done")
                    $receiveddone = true;
                $STATUS = socket_get_status($this->socket);
                if ($LENGTH > 0)
                    $this->debug('>>> [' . $LENGTH . ', ' . $STATUS['unread_bytes'] . ']' . $_);
                if ((!$this->connected && !$STATUS['unread_bytes']) || ($this->connected && !$STATUS['unread_bytes'] && $receiveddone))
                    break;
            }
            if ($parse)
                $RESPONSE = $this->parse_response($RESPONSE);
            return $RESPONSE;
        }
    	
    	
        /**
         * Write (send) data to Router OS
         *
         * @param string      $command    A string with the command to send
         * @param mixed       $param2     If we set an integer, the command will send this data as a "tag"
         *                                If we set it to boolean true, the funcion will send the comand and finish
         *                                If we set it to boolean false, the funcion will send the comand and wait for next command
         *                                Default: true
         *
         * @return boolean                Return false if no command especified
         */
        function write($command, $param2 = true)
        {
            if ($command) {
                $data = explode("\n", $command);
                foreach ($data as $com) {
                    $com = trim($com);
                    fwrite($this->socket, $this->encode_length(strlen($com)) . $com);
                    $this->debug('<<< [' . strlen($com) . '] ' . $com);
                }
                if (gettype($param2) == 'integer') {
                    fwrite($this->socket, $this->encode_length(strlen('.tag=' . $param2)) . '.tag=' . $param2 . chr(0));
                    $this->debug('<<< [' . strlen('.tag=' . $param2) . '] .tag=' . $param2);
                } else if (gettype($param2) == 'boolean')
                    fwrite($this->socket, ($param2 ? chr(0) : ''));
                return true;
            } else
                return false;
        }
    	
    	
        /**
         * Write (send) data to Router OS
         *
         * @param string      $com        A string with the command to send
         * @param array       $arr        An array with arguments or queries
         *
         * @return array                  Array with parsed
         */
        function comm($com, $arr = array())
        {
            $count = count($arr);
            $this->write($com, !$arr);
            $i = 0;
            foreach ($arr as $k => $v) {
                switch ($k[0]) {
                    case "?":
                        $el = "$k=$v";
                        break;
                    case "~":
                        $el = "$k~$v";
                        break;
                    default:
                        $el = "=$k=$v";
                        break;
                }
                $last = ($i++ == $count - 1);
                $this->write($el, $last);
            }
            return $this->read();
        }
    }
    ?>
    Last edited by ross_ice; 18 Jan 2013, 20:03:04.

    Comment


    • #3
      ไม่มีวิธี ทำด้วยเหรอดครับผม

      Comment


      • #4
        ขอทราบการทำอีกคนครับ

        Comment


        • #5
          ขอแบบ step by step ได้ไหมครับ มือใหม่อ่อนประสบการณ์ อิอิ

          Comment


          • #6
            ขอบคุณคร๊าฟฟฟผม _/|\_

            Comment


            • #7
              Originally posted by somphongn View Post
              ขอบคุณคร๊าฟฟฟผม _/|\_
              ขอบคุณ เหรอพี่ สมพง งั้นพี่ รีวิวให้ทีครับ

              Comment


              • #8
                วิธีใช้งาน
                1 ลงโปรแกรม appserv เพื่อใช้คอมเราเป็นserver host (จำรองเครื่องเป็น host)
                2. ก๊อบเอา code ใส่note pad แล้ว save เป็น .php เช่น adduser.php ใส่ไว้ใน C:\AppServ\www จะตั้งซื่ออะไรแล้วแต่สะดวก

                แต่ code ส่วนของ routeros_api.class.php ต้องตั้งเป็นซื่อ routeros_api.class.php ห้ามเปลี่ยนนะครับ
                มันจะใช้ตรงนี้
                Code:
                require('routeros_api.class.php');
                3.ลบไฟล์ index.php ที่อยู่ใน C:\AppServ\www ทึ้งไป ถ้าไม่ลบ ข้อ4 เวลาใช้งานต้องพิม http://localhost/adduser.php คงจำซื่อกันไม่หวาดไม่ใหว

                4.เวลาใช้งาน เปิด firefox หรือ ie แล้วพิม http://localhost ลงไป
                จะเห็น ไฟล์ adduser.php หรือซื่อที่เราตั้งไว้ แสดงอยู่ ก็คลิกใช้งานได้เลย

                Comment


                • #9
                  Originally posted by ross_ice View Post
                  วิธีใช้งาน
                  1 ลงโปรแกรม appserv เพื่อใช้คอมเราเป็นserver host (จำรองเครื่องเป็น host)
                  2. ก๊อบเอา code ใส่note pad แล้ว save เป็น .php เช่น adduser.php ใส่ไว้ใน C:\AppServ\www จะตั้งซื่ออะไรแล้วแต่สะดวก

                  แต่ code ส่วนของ routeros_api.class.php ต้องตั้งเป็นซื่อ routeros_api.class.php ห้ามเปลี่ยนนะครับ
                  มันจะใช้ตรงนี้
                  Code:
                  require('routeros_api.class.php');
                  3.ลบไฟล์ index.php ที่อยู่ใน C:\AppServ\www ทึ้งไป ถ้าไม่ลบ ข้อ4 เวลาใช้งานต้องพิม http://localhost/adduser.php คงจำซื่อกันไม่หวาดไม่ใหว

                  4.เวลาใช้งาน เปิด firefox หรือ ie แล้วพิม http://localhost ลงไป
                  จะเห็น ไฟล์ adduser.php หรือซื่อที่เราตั้งไว้ แสดงอยู่ ก็คลิกใช้งานได้เลย
                  แล้วเราปิดคอมได้ไหมครับแบบนี้

                  Comment


                  • #10
                    Originally posted by bombon View Post
                    แล้วเราปิดคอมได้ไหมครับแบบนี้

                    ไม่ใช่ๆๆๆ ปกติ Mikrotik RB750GL ถ้าใช้ user man ใน Mikrotik มันจะonline พร้อมกันได้แค่ 20คน
                    ไอ้โปรแกรม user man มันเทพ add user ตั้งวันใช้งาน ออกตัว วัน เดือน แทนเราได้หมด หรือ บลาาๆๆๆ แต่มัน 20คน ไม่พอใช้งานแน่ๆ

                    แต่ถ้า ไม่ไช้ user man มันจะได้ 200 userหรือป่าวไม่แน่ใจ
                    ที่แรกผมก็ add มือ ผ่าน winbok แต่มันยุ่งยากมาก ถ้า add user เป็น ร้อยสองร้อยแก่กันพอดี จะออกตั๋วก็ไม่ได้อีก

                    เราก็ใช้ php api remote จากคอมเราเข้าไปจัดการ Mikrotik แทนเจ้า user man มันก็จะก้าวข้าม 20คน ไปได้ครับ เห็น wifi4uyou บอกได้ 30ขึ้นไป

                    winbok มันตัวใช้ cpu ด้วย ไม่จำเป็นไม่อยากเปิดมัน

                    Comment


                    • #11
                      ว้าวว พี่ลองแล้วเจ่งไหมครับ

                      Comment


                      • #12
                        เยี่ยมเลยครับ มือใหม่เช่นกันครับ

                        Comment


                        • #13
                          555ไปไม่ถูกเลย งงมากโค็ดเต็มไปหมดอะ เซพไม่ถูกเหอๆ

                          Comment


                          • #14
                            ถ้าต้องเปิด com อีกเครื่อง ... ที่ขึ้นชื่อเรื่องประหยัดไฟ คงไม่ประหยัดแล้วหล่ะ

                            Comment


                            • #15
                              จะไปเปิดคอมทิ้งไว้ทำใมล่ะครับ สมมุติ เดือนหนึ่งจะทำตั๋วรายวันรายเดือนอะไร ชัก 500 ใบ ถ้าไปนั่งทำใน winbox อาจใช้เวลานั้งใส่user ใส่ password ใส่จำนวนวันใช้งาน เป็นวันๆสองวัน แล้วแต่ความขยันของแต่ล่ะคน อาจะ คลิ๊กเมาว์ 2000ครั้ง+ พิมพ์ user password อะไรอีก 6000 ตัวอักษร

                              แต่ถ้าใช้ php ตามตัวอย่าง มันจะทำเสร็จ ประมาณ นาทีเดียว คลิกเมาว์อัพโหลด 1ครั้งเดียว user 500 คนมันก็เข้าไปอยู่ใน Mikrotik
                              เพิ่มแล้ว user มันก็อยู่ใน Mikrotik มันไม่ได้อยู่ที่คอมเรานะ ทำเสร็จก็ปิดคอมไป ได้เลย

                              Comment

                              Working...
                              X