Follow us on...
Follow us on G+ Follow us on Twitter Follow us on Facebook Watch us on YouTube
Register
Results 1 to 3 of 3
  1. #1
    Status
    Offline
    sunyoto's Avatar
    Baru Gabung
    Join Date
    Nov 2010
    Posts
    11
    Reviews
    Read 0 Reviews
    Downloads
    0
    Uploads
    0
    Feedback Score
    0

    Billing Hotspot dg XAMPP windows

    -------------------speedy
    ----------------------|
    ----------------------|
    -----(squid)-------(rb750 ppoe)---------hotspot (192.168.4.0./24)
    ----------------------|
    ----------------------|
    -------------------warnet(192.168.1.0/24)

    Pernah baca sih buat billing hotspot dengan EasyHotSpot tapi di install di ubuntu, tapi untuk saat ini gak berminat untuk kotak2 pc server squid. Dan sampe skr masih belum tertarik dengan usermanager.

    Yang saya tanya :
    1. Adakah billing hotspot yg gratis yg bisa di hubungkan ke mikrotik menggunakan xampp di windows atau ke hosting dan ada tampilan login dan popup tampilan kecil untuk logout ?
    2. Apa semua billing hotspot harus enable service www di mikrotik ?
    3. Apa ada sih script php yg bisa mengabil nilai hotspot users mikrotik khususnya waktu nya dan di simpan ke sql xampp windows atau hosting.

    Thanks untuk semua bantuannya
    Click here to enlarge

  2. #2
    Status
    Offline
    sunyoto's Avatar
    Baru Gabung
    Join Date
    Nov 2010
    Posts
    11
    Reviews
    Read 0 Reviews
    Downloads
    0
    Uploads
    0
    Feedback Score
    0
    Ada gak yah perintah mikrotik untuk mengirimkan user uptime hotspot ke sql xampp atau hosting

  3. #3
    Status
    Offline
    keblux's Avatar
    Member Senior
    Join Date
    Nov 2009
    Location
    ǝɹǝɥʍ ou ɟo ǝlppıɯ ǝɥʇ uı
    Posts
    453
    Reviews
    Read 0 Reviews
    Downloads
    0
    Uploads
    0
    Feedback Score
    0
    Click here to enlarge Originally Posted by sunyoto Click here to enlarge
    -------------------speedy
    ----------------------|
    ----------------------|
    -----(squid)-------(rb750 ppoe)---------hotspot (192.168.4.0./24)
    ----------------------|
    ----------------------|
    -------------------warnet(192.168.1.0/24)

    Pernah baca sih buat billing hotspot dengan EasyHotSpot tapi di install di ubuntu, tapi untuk saat ini gak berminat untuk kotak2 pc server squid. Dan sampe skr masih belum tertarik dengan usermanager.

    Yang saya tanya :
    1. Adakah billing hotspot yg gratis yg bisa di hubungkan ke mikrotik menggunakan xampp di windows atau ke hosting dan ada tampilan login dan popup tampilan kecil untuk logout ?
    2. Apa semua billing hotspot harus enable service www di mikrotik ?
    3. Apa ada sih script php yg bisa mengabil nilai hotspot users mikrotik khususnya waktu nya dan di simpan ke sql xampp windows atau hosting.

    Thanks untuk semua bantuannya
    Click here to enlarge
    coba bantu jawab ya.

    1. udah dijawab sendiri bisa pake easyhotspot.
    2. service www menurut saya tidak perlu bro. yang perlu service telnet sama ftp aja, buat komunikasi data mikrotik ke billing.
    3. ada saya kasih conton dibawah


    Click here to enlarge Originally Posted by sunyoto Click here to enlarge
    Ada gak yah perintah mikrotik untuk mengirimkan user uptime hotspot ke sql xampp atau hosting
    kalo perintah dari mikrotik buat ngirim variable data ke MySQL ane kurang tahu bro. cuma kalo dari php ngambil nilai variable mikrotik bisa. pake API PHP class. pertama2 aktifkan API service mikrotiknya dulu.
    Code:
    /ip service enable api
    kedua buat script php API class nya bisa ngambil di wiki mikrotik atau copas dibawah ini. simpan dengan nama ApiMikrotik.php
    PHP Code:
    <?php
    //
    // RouterOS API class
    // Author: Denis Basta
    //
    // read() function altered by Nick Barnes to take into account the placing
    // of the "!done" reply and also correct calculation of the reply length.
    ///
    // read() function altered by Ben Menking (ben@infotechsc.com); removed
    // echo statement that dumped byte data to screen
    //
    ///////////////////////////
    // Revised by: Jeremy Jefferson (http://jeremyj.com)
    // January 8, 2010
    //
    //    Fixed write function in order to allow for queries to be executed
    //

    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

        /**************************************************
         *
         *************************************************/

        
    function debug($text) {

            if (
    $this->debug)
                echo 
    $text "\n";

        }

        
    /**************************************************
         *
         *************************************************/

        
    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 >> 8) & 0xFF) . chr( ($length >> 8) & 0xFF) . chr($length 0xFF);

            }
            else
            if (
    $length 0x10000000) {

                
    $length |= 0xE0000000;

                
    $length chr( ($length >> 8) & 0xFF) . chr( ($length >> 8) & 0xFF) . chr( ($length >> 8) & 0xFF) . chr($length 0xFF);

            }
            else
            if (
    $length >= 0x10000000)
                
    $length chr(0xF0) . chr( ($length >> 8) & 0xFF) . chr( ($length >> 8) & 0xFF) . chr( ($length >> 8) & 0xFF) . chr($length 0xFF);

            return 
    $length;

        }

        
    /**************************************************
         *
         *************************************************/

        
    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=' $loginfalse);
                                
    $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;

        }

        
    /**************************************************
         *
         *************************************************/

        
    function disconnect() {

            
    fclose($this->socket);

            
    $this->connected false;

            
    $this->debug('Disconnected...');

        }

        
    /**************************************************
         *
         *************************************************/

        
    function parse_response($response) {

            if (
    is_array($response) ) {

                
    $PARSED = array();
                
    $CURRENT 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) )
                            
    $CURRENT[$MATCHES[0][0]] = (isset($MATCHES[0][1]) ? $MATCHES[0][1] : '');

                    }

                }

                return 
    $PARSED;

            }
            else
                return array();

        }

        
    /**************************************************
         *
         *************************************************/

            
    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;
                    }
            }

            
    /**************************************************
             *
             *************************************************/

            
    function parse_response4smarty($response) {
                    if (
    is_array($response) ) {
                            
    $PARSED = array();
                            
    $CURRENT 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) )
                                                    
    $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;
                    }
                    else {
                            return array();
                    }
            }

        
    /**************************************************
         *
         *************************************************/

       
    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->socket1) );
             
    $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) << ) + ord(fread($this->socket1)) ;
                } else {
                   if ((
    $BYTE 224) == 192) {
                      
    $LENGTH = (($BYTE 31) << ) + ord(fread($this->socket1)) ;
                      
    $LENGTH = ($LENGTH << ) + ord(fread($this->socket1)) ;
                   } else {
                      if ((
    $BYTE 240) == 224) {
                         
    $LENGTH = (($BYTE 15) << ) + ord(fread($this->socket1)) ;
                         
    $LENGTH = ($LENGTH << ) + ord(fread($this->socket1)) ;
                         
    $LENGTH = ($LENGTH << ) + ord(fread($this->socket1)) ;
                      } else {
                         
    $LENGTH ord(fread($this->socket1)) ;
                         
    $LENGTH = ($LENGTH << ) + ord(fread($this->socket1)) ;
                         
    $LENGTH = ($LENGTH << ) + ord(fread($this->socket1)) ;
                         
    $LENGTH = ($LENGTH << ) + ord(fread($this->socket1)) ;
                      }
                   }
                }
             } 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;

       }
        
    /**************************************************
         *
         *************************************************/

        
    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;

        }

    }

    ?>
    ketiga saya kasih contoh script php buat ngambil variable User yang active di hotspot sama nilai uptimenya buat di simpan di MySQL database. simpan dengan nama HotspotFetch.php

    PHP Code:
    <?php
    require('ApiMikrotik.php');
    $API = new routeros_api();
    $API->debug false;

    if (
    $API->connect('IpMikrotik''UserNameMikrotik''PasswordMikrotik')) {

       
    $API->write('/ip/hotspot/active/print');
       
    $READ $API->read(false);
       
    $ARRAY $API->parse_response($READ);
       
       foreach(
    $ARRAY as $hasil) {
       
    $user $hasil['user'];
       
    $uptime =  $hasil['uptime'];
       
    mysql_connect("IP_MYSQL_DATABASE","User_mysql","Pass_mysql"); 
       @
    mysql_select_db('Database_mysql') or die( "Tidak bisa memilih database");

       
    mysql_query("INSERT INTO tableHotspotUser (UserName, Uptime) VALUES ('$user', '$uptime')");

       
    mysql_close();
      }
       
    $API->disconnect();

    }
    ?>

    jalankan di dibrowser atau di CLI script diatas. lalu cek database MySQL anda pasti masuk variable User dan Uptime dari mikrotik. itu contoh simple nya aja.

    semoga membantu Click here to enlarge
    Last edited by keblux; 14-12-2010 at 06:21.

 

 

Thread Information

Users Browsing this Thread

There are currently 3 users browsing this thread. (0 members and 3 guests)

Similar Threads

  1. antamedia billing hotspot + Mikrotik
    By nitaufan in forum General Networking
    Replies: 22
    Last Post: 01-04-2013, 11:34
  2. Replies: 96
    Last Post: 03-07-2012, 19:23
  3. Billing warnet vs hotspot mikrotik
    By iyou in forum Scripting @ Mikrotik
    Replies: 15
    Last Post: 25-08-2010, 06:21
  4. billing hotspot masalah di repeater
    By marom_shinichi in forum Wireless Networking
    Replies: 4
    Last Post: 03-03-2009, 00:41

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •