!C99Shell v. 2.1 [PHP 8 Update] [02.02.2022]!

Software: Apache/2.4.53 (Unix) OpenSSL/1.1.1o PHP/7.4.29 mod_perl/2.0.12 Perl/v5.34.1. PHP/7.4.29 

uname -a: Linux vps-2738122-x 4.15.0-213-generic #224-Ubuntu SMP Mon Jun 19 13:30:12 UTC 2023 x86_64 

uid=1(daemon) gid=1(daemon) grupos=1(daemon) 

Safe-mode: OFF (not secure)

/opt/apex_tdfonline/php/consola/   drwxr-xr-x
Free 14.92 GB of 61.93 GB (24.09%)
Home    Back    Forward    UPDIR    Refresh    Search    Buffer    Encoder    Tools    Proc.    FTP brute    Sec.    SQL    PHP-code    Update    Feedback    Self remove    Logout    


Viewing file:     consola.php (9.53 KB)      -rw-r--r--
Select action/file-type:
(+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
require_once("consola/lib/Table.php");
require_once(
"consola/lib/Getopt.php");
require_once(
"consola/lib/formulario_consola.php");
require_once(
'modelo/lib/toba_proceso_gui.php');
require_once(
'nucleo/toba_nucleo.php');

/**
*    @todo:     - Interprete de comandos
*            - Nombres abreviados de comandos            
*/
class consola implements toba_proceso_gui
{
    static protected 
$display_ancho 79;
    const 
display_coleccion_espacio_nombre 25;
    const 
display_prefijo_linea ' ';
    protected     
$ubicacion_comandos;
    protected    
$menu;
    protected 
$verbose true;
    
    function 
__construct$ubicacion_comandos$clase_menu )
    {
        
toba_nucleo::instancia();
        if (
strtoupper(substr(PHP_OS03)) === 'WIN') {
            
self::$display_ancho 79;
        } else {
            
self::$display_ancho 1000;
        }
        
ini_set("error_reporting"E_ALL);
        if( ! 
is_dir$ubicacion_comandos ) ) {
            throw new 
toba_error("CONSOLA: El directorio de comandos '$ubicacion_comandos' es invalido");
        }
        
$this->ubicacion_comandos $ubicacion_comandos;
        require_once( 
$this->ubicacion_comandos ."/$clase_menu.php");
        
$this->menu = new $clase_menu$this );
        
toba_cronometro::instancia()->marcar('Consola online');
    }

    function 
get_ubicacion_comandos()
    {
        return 
$this->ubicacion_comandos;    
    }

    function 
run$argumentos )
    {
        
toba_cronometro::instancia()->marcar('Inicio proceso.');
        if ( 
count($argumentos) > ) {
            try {
                
$comando $argumentos[0];
                
array_shift$argumentos );
                
$this->invocar_comando$comando$argumentos );
            } catch (
toba_error $e ) {
                
$this->mensaje$e->get_mensaje() );    
                
toba_logger::instancia()->error($e);
            }
        } else {
            
//Aca se tendria que abrir el INTERPRETE
            
$this->menu->mostrar_ayuda_raiz();
        }
        
toba_cronometro::instancia()->marcar('Fin proceso.');
        if (
$this->verbose) {
            
$this->menu->mostrar_resumen();
        }
    }

    function 
invocar_comando($nombre_comando$argumentos)
    {
        
$clase_comando 'comando_' $nombre_comando;
        
$archivo $this->ubicacion_comandos .'/'.$clase_comando.'.php';
        if ( 
file_exists$archivo ) ) {
            require_once( 
$this->ubicacion_comandos .'/'.$clase_comando.'.php');
            
$comando = new $clase_comando$this );
            
$comando->set_argumentos$argumentos );            
            
$comando->procesar();
        } else {
            throw new 
toba_error("ERROR: El COMANDO '$nombre_comando' no existe.");
        }
    }
    
    function 
set_verbose($verbose)
    {
        
$this->verbose $verbose;
    }
    
/*
    function interprete()
    {
        fwrite(STDOUT, "Enter 'q' to quit\n");
        do {
           do {    
               $selection =    fgetc(STDIN);
           } while ( trim($selection) == ''    );
            echo $selection;
        } while    ( $selection !=    'q'    );
        
        exit(0); 
    }
*/
    //-------------------------------------------------------------------------
    // Primitivas de display
    //-------------------------------------------------------------------------

    /**
     * Wrap para cambiar el encoding del texto
     */
    
protected function imprimir($texto)
    {
        if (
toba_manejador_archivos::es_windows() && function_exists('iconv')) {
            echo 
iconv('latin1''IBM850'$texto);
        } else {
            echo 
$texto;
        }
    }
    
    function 
separador$texto=''$caracter='-' )
    {
        if(
$texto!=''$texto "--  $texto  ";
        
$this->imprimir("\n");
        
$this->linea_completa$texto$caracter );
        
$this->imprimir("\n");
    }

    function 
titulo$texto )
    {
        
$this->imprimir("\n");
        
$this->linea_completanull'-' );
        
$this->linea_completa$texto  "' ' );
        
$this->linea_completanull'-' );
        
$this->imprimir("\n");
    }
    
    function 
subtitulo$texto )
    {
        
$this->imprimir(self::display_prefijo_linea $texto "\n");
        
$this->imprimir(self::display_prefijo_linea str_repeat('-'strlen$texto ) ) );
        
$this->imprimir("\n\n");
    }

    function 
mensaje$texto$bajar_linea=true )
    {
        
$lineas toba_texto::separar_texto_lineas$textoself::$display_ancho );
        for (
$i=0$icount($lineas); $i++) {
            if (
$bajar_linea || $i count($lineas) - 1) {
                
$extra "\n";
            } else {
                
$extra '';
            }
            
$this->imprimir(self::display_prefijo_linea $lineas[$i] . $extra);
        }
    }
    
    function 
progreso_avanzar()
    {
        
$this->imprimir('.');    
    }
    
    function 
progreso_fin()
    {
        
$this->imprimir("OK\n");    
    }    
    
    function 
enter()
    {
        
$this->imprimir("\n");    
    }

    
/*
    * Imprime un error en la error estandar
    */
    
function error$texto )
    {
        
toba_logger::instancia()->error($texto);
        
$lineas toba_texto::separar_texto_lineas$textoself::$display_ancho );
        foreach( 
$lineas as $linea ) {
            
fwriteSTDERRself::display_prefijo_linea $linea "\n" );
        }
    }

    
/*
    * Muestra una lista de elementos con su descripcion
    * Hay que pasarle un array asociativo elemento/descripcion
    */
    
function coleccion$coleccion )
    {
        
$espacio_descripcion self::$display_ancho self::display_coleccion_espacio_nombre 
                                
strlenself::display_prefijo_linea );
        foreach( 
$coleccion as $nombre => $descripcion ) {
            
$lineas toba_texto::separar_texto_lineas$descripcion$espacio_descripcion );
            
$this->mensajestr_pad$nombreself::display_coleccion_espacio_nombre' ' ) . array_shift$lineas ) );
            foreach( 
$lineas as $linea ) {
                
$this->mensajestr_repeat(' 'self::display_coleccion_espacio_nombre ) . $linea );    
            }
        }
    }

    
/*
    *    Dumpea un ARBOL
    */
    
function dump_arbol$arbol$titulo )
    {
        
$this->enter();
        
$this->subtitulo$titulo );
        
print_r$arbol );
    }
    
    
/*
    * Genera la salida de una linea completando el espacio faltante del display con un caracter
    */
    
function linea_completa$base=''$caracter_relleno )
    {
        if (
self::$display_ancho 100) {
            
$ancho 100;
        } else {
            
$ancho self::$display_ancho;
        }
        
$this->imprimir(str_padself::display_prefijo_linea $base$ancho$caracter_relleno ));
        
$this->imprimir("\n");
    }

    function 
lista$lista$titulo )
    {
        if( 
count$lista ) > ) {
            
$i=0;
            foreach(
$lista as $l) {
                
$datos[$i][0] = $l;
                
$i++;
            }
            
$this->imprimir(Console_Table::fromArray( array( $titulo ), $datos ));    
        }
    }
    
    function 
lista_asociativa$lista$titulo null )
    {
        if( 
count$lista ) > ) {
            
$i=0;
            foreach(
$lista as $id => $l) {
                
$datos[$i]['id'] = $id;
                
$datos[$i]['valor'] = $l;
                
$i++;
            }
            if ( ! isset( 
$titulo ) ) {
                
$titulo = array( 'ID''Valor' );    
            } else {
                if ( ! 
is_array$titulo ) ) $titulo = array( $titulo );
            }
            
$this->imprimir(Console_Table::fromArray$titulo$datos ));    
        }
    }

    function 
tabla$tabla$titulos )
    {
        if ( 
count$tabla ) > ) {
            
$this->imprimir(Console_Table::fromArray$titulos$tabla ));
        } else {
            
self::mensaje('...No hay DATOS!');    
        }
    }
    
    
//------------------------------------------------------------------------
    // Interaccion con el usuario
    //------------------------------------------------------------------------

    
function dialogo_simple$texto$defecto null$extra=null)
    {
        
$this->imprimir("$texto (Si o No)\n");
        if (isset(
$extra)) {
            
$this->imprimir($extra);        
        }        
        do {
            
$this->imprimir("(s/n):");
        
            
$respuesta trimfgetsSTDIN ) );
            if (isset(
$defecto) && $respuesta == '') {
                
$respuesta = ($defecto) ? 's' 'n';
            }
            
$ok = ($respuesta == 's') || ( $respuesta == 'n');
        } while ( ! 
$ok );
        if( 
$respuesta == 's') return true;
        return 
false;
    }    

    function 
dialogo_ingresar_texto$categoria$obligatorio true )
    {
        do {
            
$this->imprimir("$categoria: ");
            
$respuesta trimfgetsSTDIN ) );
            
$ok = ( ( trim($respuesta != '') && ( $obligatorio ) ) ||  ( ! $obligatorio  ) );
        } while ( ! 
$ok );
        return 
$respuesta;
    }

    
/**
    *    Muestra una lista de opciones y espera que el usuario seleccione.
    *        Soporta: multiple selecciones, seleccion no obligaroria (--) y seleccion por defecto (vacio).
    */
    
function dialogo_lista_opciones$opciones$texto$multiple_seleccion false
                                    
$titulo 'VALORES'$obligatorio true
                                    
$defecto null$defecto_texto '' )
    {
        
self::subtitulo$texto );
        
self::lista_asociativa$opciones, array( 'ID'$titulo ) );
        if ( 
$multiple_seleccion ) {
            
self::mensaje('Seleccione valores pertenecientes a la columna "ID"');
            
self::mensaje('(Puede seleccionar varios valores separandolos por ",")');
            
$txt 'valores';
        } else {
            
self::mensaje('Seleccione un valor perteneciente a la columna "ID"');
            
$txt 'valor';
        }
        if ( ! 
$obligatorio ) {
            
self::mensaje('Si no desea seleccionar nada escriba "--"');
        }
        
self::enter();
        
$valores_posibles implode','array_keys$opciones ) );
        do {
            if (isset(
$defecto)) {
                
$this->imprimir("$txt (ENTER selecciona ".$defecto_texto."): ");
            } else {
                
$this->imprimir("($txt): ");
            }
            
$respuesta trimfgetsSTDIN ) );
            if (isset(
$defecto) && $respuesta == '') {
                return 
$defecto;
            }    
            if ( ! 
$obligatorio && $respuesta == '--' ) {    // Salida para opcionales
                
return ($multiple_seleccion) ? array() : null;                
            }
            if ( 
$multiple_seleccion ) {
                
$ok true;
                
$valores explode(','$respuesta);
                
$valores array_map('trim',$valores);
                foreach ( 
$valores as $valor ) {
                    if ( ! isset( 
$opciones$valor ] ) ) {
                        
self::error("El valor '$valor' es invalido");
                        
$ok false;
                    }
                }
                if ( 
$ok ) return $valores;
            } else {    
// Seleccion simple
                
if ( isset( $opciones$respuesta ] ) ) {
                    return 
$respuesta;
                }
            }
        } while ( 
true );
    }
    
    function 
get_formulario$titulo )
    {
        return new 
formulario_consola$this$titulo );
    }
}
?>

:: Command execute ::

Enter:
 
Select:
 

:: Search ::
  - regexp 

:: Upload ::
 
[ Read-Only ]

:: Make Dir ::
 
[ Read-Only ]
:: Make File ::
 
[ Read-Only ]

:: Go Dir ::
 
:: Go File ::
 

--[ c99shell v. 2.1 [PHP 8 Update] [02.02.2022] maintained byC99Shell Github | Generation time: 1.0322 ]--