2022-02-25 04:13:05 +00:00
# include <stdio.h>
# include "sclient.h"
# include "sterm.h"
2022-04-06 04:57:37 +00:00
# include "ini.h"
2022-02-25 04:13:05 +00:00
2022-03-21 22:47:46 +00:00
# define STRING(x) #x
# define MACROLITSTR(x) STRING(x)
2022-04-06 06:07:16 +00:00
const char * LOGO = " \n ██╗ █████╗ ██╗██╗ ██╗ █████╗ \n ██║ ██╔══██╗██║██║ ██╔╝██╔══██╗ \n ██║ ███████║██║█████╔╝ ███████║ \n ██║ ██╔══██║██║██╔═██╗ ██╔══██║ \n ███████╗██║ ██║██║██║ ██╗██║ ██║ \n ╚══════╝╚═╝ ╚═╝╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ " ;
2022-03-21 22:47:46 +00:00
2022-04-06 04:57:37 +00:00
static int iniHandler ( void * user , const char * section , const char * name , const char * value ) {
tShell_client * client = ( tShell_client * ) user ;
# define MATCH(s, n) strcmp(section, s) == 0 && strcmp(name, n) == 0
if ( MATCH ( " auth " , " public-key " ) ) {
shellC_loadKeys ( client , value , NULL ) ;
PRINTINFO ( " Auth pubkey: %s \n " , value ) ;
} else if ( MATCH ( " auth " , " private-key " ) ) {
shellC_loadKeys ( client , NULL , value ) ;
} else {
return 0 ; /* unknown section/name, error */
}
return 1 ;
}
bool loadConfig ( tShell_client * client , char * config ) {
int iniRes ;
printf ( " Loading config file '%s'... \n " , config ) ;
if ( ( iniRes = ini_parse ( config , iniHandler , ( void * ) client ) ) < 0 ) {
switch ( iniRes ) {
case - 1 : printf ( " Couldn't load config file '%s'! \n " , config ) ; break ;
case - 2 : printf ( " Memory allocation error :/ \n " ) ; break ;
default :
printf ( " Parser error on line %d in config file '%s'! \n " , iniRes , config ) ;
}
return false ;
}
return true ;
}
2022-02-25 04:13:05 +00:00
int main ( int argv , char * argc [ ] ) {
tShell_client client ;
2022-04-06 04:57:37 +00:00
char * configFile = " shell.ini " ;
2022-02-25 04:13:05 +00:00
bool printPrompt = false ;
2022-03-21 22:47:46 +00:00
shellT_printf ( " %s%s \n %s " , shellT_getForeColor ( TERM_BRIGHT_RED ) , LOGO , shellT_getForeColor ( TERM_BRIGHT_WHITE ) ) ;
2022-04-06 06:07:16 +00:00
shellT_printf ( " made with %s<3%s by CPunch - %s \n \n Type 'help' for a list of commands \n \n " , shellT_getForeColor ( TERM_BRIGHT_RED ) , shellT_getForeColor ( TERM_BRIGHT_WHITE ) , " v " MACROLITSTR ( LAIKA_VERSION_MAJOR ) " . " MACROLITSTR ( LAIKA_VERSION_MINOR ) " - " LAIKA_VERSION_COMMIT ) ;
2022-03-21 22:47:46 +00:00
2022-02-25 04:13:05 +00:00
shellC_init ( & client ) ;
2022-04-06 04:57:37 +00:00
/* load config file */
2022-04-06 20:22:01 +00:00
if ( argv > = 2 )
2022-04-06 04:57:37 +00:00
configFile = argc [ 1 ] ;
if ( ! loadConfig ( & client , configFile ) )
return 1 ;
2022-02-25 04:13:05 +00:00
shellC_connectToCNC ( & client , " 127.0.0.1 " , " 13337 " ) ;
shellT_conioTerm ( ) ;
while ( laikaS_isAlive ( ( & client . peer - > sock ) ) ) {
/* poll for 50ms */
if ( ! shellC_poll ( & client , 50 ) ) {
/* check if we have input! */
if ( shellT_waitForInput ( 0 ) )
shellT_addChar ( & client , shellT_kbget ( ) ) ;
/* no prompt shown? show it */
if ( ! printPrompt ) {
printPrompt = true ;
shellT_printPrompt ( ) ;
}
} else {
printPrompt = false ;
}
}
shellC_cleanup ( & client ) ;
2022-03-22 14:50:22 +00:00
PRINTERROR ( " Connection closed \n " ) ;
2022-02-25 04:13:05 +00:00
return 0 ;
}