Sistema WEB Administrador de Clientes con acceso a Mikrotik

Publicado por freedarwuin, Enero 29, 2015, 06:13:53 PM

Tema anterior - Siguiente tema

De que manera Administra tu red?

Hotspot
PPPoE
IP/MAC
PCQ
Address List

bacalao

Cita de: freedarwuin en Marzo 19, 2015, 05:53:35 PM
Y MIKROLAN?

Pudiera ser MIKROLAN WEB

y navegando por la web conseguí esto como trabajar ROUTEROS por php

apimikrotik.php
Código (php) [Seleccionar]

<?php
/*****************************
 *
 * RouterOS PHP API class v1.4
 * Author: Denis Basta
 * Contributors:
 *    Miguel Figueroa
 *    Nick Barnes
 *    Ben Menking (ben [at] infotechsc [dot] com)
 *    Jeremy Jefferson (http://jeremyj.com)
 *    Cristian Deluxe (djcristiandeluxe [at] gmail [dot] com)
 *    Nicolas Daitsch, Nro de Puerto publico 
 *
 * 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$port)
    {
        for (
$ATTEMPT 1$ATTEMPT <= $this->attempts$ATTEMPT++) {
            
$this->connected false;
            
$this->debug('Connection attempt #' $ATTEMPT ' to ' $ip ':' $port '...');
            if (
$this->socket = @fsockopen($ip$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;
    }


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


    
/**
     * 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();
    }
}
?>


freedarwuin

excelente yo tengo eso ya tengo una buena base donde podemos sacar codigos lo que quiero es publicar lo que tengo para que lo veamos lo que queremos hacer... ya se esta instalando el debian en la pc para subir los archivos.

hermano q tanto sabes de php

porque aparte de eso trabajaremos con el api php mikrotik
>Si te gusta dale LIKE<

Entre las redes cableadas y las que no, el Mikrotik, ThunderCache y Tp-Link no hay nada Oculto... Para todo lo demás solo hay que "Guglear".
Mikrotik, Raptor, Ubiquiti, Tplink.
Prestamos Soporte en cuanto a Redes se refiere a Empresas, Wisp y hogares!!!
www.mikronet.com.ve

freedarwuin

No solo quiero que interactuemos por aqui tambien directamente al servidor modificando archivos
>Si te gusta dale LIKE<

Entre las redes cableadas y las que no, el Mikrotik, ThunderCache y Tp-Link no hay nada Oculto... Para todo lo demás solo hay que "Guglear".
Mikrotik, Raptor, Ubiquiti, Tplink.
Prestamos Soporte en cuanto a Redes se refiere a Empresas, Wisp y hogares!!!
www.mikronet.com.ve

bacalao

Cita de: freedarwuin en Marzo 19, 2015, 06:24:25 PM
excelente yo tengo eso ya tengo una buena base donde podemos sacar codigos lo que quiero es publicar lo que tengo para que lo veamos lo que queremos hacer... ya se esta instalando el debian en la pc para subir los archivos.

hermano q tanto sabes de php

porque aparte de eso trabajaremos con el api php mikrotik

Hermano te soy sincero tengo años que no programo en PHP pero eso nunca se olvida, lo que tengo es que ponerme al dia nuevamente pero cuenta con mi apoyo, lo único malo es que de diseño soy malisimooooo.


freedarwuin

Excelente pero ya el diseño esta listo lo que fata es darle funcion yo mas o menos le meto al php
>Si te gusta dale LIKE<

Entre las redes cableadas y las que no, el Mikrotik, ThunderCache y Tp-Link no hay nada Oculto... Para todo lo demás solo hay que "Guglear".
Mikrotik, Raptor, Ubiquiti, Tplink.
Prestamos Soporte en cuanto a Redes se refiere a Empresas, Wisp y hogares!!!
www.mikronet.com.ve

freedarwuin

Listo quien config el bin9 ?

Usuario y contraseña admin

entren y acepto sugerencias
>Si te gusta dale LIKE<

Entre las redes cableadas y las que no, el Mikrotik, ThunderCache y Tp-Link no hay nada Oculto... Para todo lo demás solo hay que "Guglear".
Mikrotik, Raptor, Ubiquiti, Tplink.
Prestamos Soporte en cuanto a Redes se refiere a Empresas, Wisp y hogares!!!
www.mikronet.com.ve

Zero

Cita de: freedarwuin en Marzo 19, 2015, 06:31:07 PM
No solo quiero que interactuemos por aqui tambien directamente al servidor modificando archivos

Emmmm, y si usan github? (Es solo una sugerencia)
En GNU/Linux formatear por cualquier cosa es de noobs, tu decides si eres uno...

firecold

Cita de: Zero en Marzo 20, 2015, 10:21:49 AM
Emmmm, y si usan github? (Es solo una sugerencia)

Buen punto, es una forma de compartir el codigo y de recibir consejos sobre como mejorar cualquier programa, gracias Zero, Saludos

freedarwuin

QUe necesitan para hacer eso ? acceso al server? instalar algun paquete?
>Si te gusta dale LIKE<

Entre las redes cableadas y las que no, el Mikrotik, ThunderCache y Tp-Link no hay nada Oculto... Para todo lo demás solo hay que "Guglear".
Mikrotik, Raptor, Ubiquiti, Tplink.
Prestamos Soporte en cuanto a Redes se refiere a Empresas, Wisp y hogares!!!
www.mikronet.com.ve

firecold

Cita de: freedarwuin en Marzo 20, 2015, 04:39:59 PM
QUe necesitan para hacer eso ? acceso al server? instalar algun paquete?

Aqui una pequeña guia de como instalar y configurar tu distribucion, para poder trabajar con github, Link, Saludos

Maher

Hola !!!

Sera un sistema como el de Sequre ISP ?

Es para administrar clientes, proveedores, facturación y hace cache, en la pagina dise "Soporta de YOUTUBE en https"

http://www.sequreisp.com/blog/posts/49?locale=es&r=1dfb6e18e6e

Es atraves de licencia de pago y gratis hasta 100 clientes.

Aunque yo no dejo Raptor.

Se puede hacer algo haci que sume Raptor ?



:) Excelente Idea MIKROLAN !!!

freedarwuin

Sera gratis hermano pues si tendra algunas funciones de algunos sistemas por hay vi uno lo que vamos a extraer algunas ideas para implantarlo
>Si te gusta dale LIKE<

Entre las redes cableadas y las que no, el Mikrotik, ThunderCache y Tp-Link no hay nada Oculto... Para todo lo demás solo hay que "Guglear".
Mikrotik, Raptor, Ubiquiti, Tplink.
Prestamos Soporte en cuanto a Redes se refiere a Empresas, Wisp y hogares!!!
www.mikronet.com.ve

azaelg

Hola amigos, y como vamos con el proyecto, si sigue,....

firecold

Cita de: azaelg en Abril 06, 2015, 08:59:33 PM
Hola amigos, y como vamos con el proyecto, si sigue,....

Paciencia mi amigo, el proyecto es nuevo y esto de programar o armar algun proyecto lleva mucho tiempo y peor cuando no lo hay, tenga paciencia y pronto el amigo presentara los frutos de su trabajo y esfuerzo, Saludos

bacalao

Amigos del foro después de unas vacaciones con mi familia he regresado otra vez a la rutina. Lo primero que deberíamos hacer serian las Tablas, que conformara la base datos del sistema, al tener como quien dice el esqueleto lo demás es carpintería.


Saludos a todos

maximote2006

Cita de: Maher en Marzo 20, 2015, 11:04:49 PM
Hola !!!

Sera un sistema como el de Sequre ISP ?

Es para administrar clientes, proveedores, facturación y hace cache, en la pagina dise "Soporta de YOUTUBE en https"

http://www.sequreisp.com/blog/posts/49?locale=es&r=1dfb6e18e6e

Es atraves de licencia de pago y gratis hasta 100 clientes.

Aunque yo no dejo Raptor.

Se puede hacer algo haci que sume Raptor ?



:) Excelente Idea MIKROLAN !!!

Que gran idea! la verdad aca en este foro me han ayudado un monton...y nadie cobra un mango! por esto y ayudan sin interes alguno! las verdad los felicito y sigan adelante chicos!!!


firecold

Cita de: maximote2006 en Abril 14, 2015, 09:30:49 AM
Que gran idea! la verdad aca en este foro me han ayudado un monton...y nadie cobra un mango! por esto y ayudan sin interes alguno! las verdad los felicito y sigan adelante chicos!!!

Este fue pensado por su creador para compartir y gracias a Dios los jovenes y usuarios lo han comprendido bastante bien, gracias por tu apoyo, Saludos

Maher

Cita de: freedarwuin en Marzo 19, 2015, 07:52:57 PM
Listo quien config el bin9 ?

Usuario y contraseña admin

entren y acepto sugerencias

No se puede entrar a la dirección.

En qué se puede ayudar al proyecto ?

sederap


JVProducciones

Cita de: freedarwuin en Marzo 21, 2015, 06:38:14 AM
Sera gratis hermano pues si tendra algunas funciones de algunos sistemas por hay vi uno lo que vamos a extraer algunas ideas para implantarlo
....Hola, ayer miré el tema... ya has visto la base de datos de Mikrowisp? si gustas te puedo permitir el acceso para que tomes como referencia....no se como mas podría ayudar...saludos