Index: asterisk/apps/app_system.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_system.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 app_system.c
--- asterisk/apps/app_system.c 12 Feb 2003 13:59:14 -0000 1.1.1.1
+++ asterisk/apps/app_system.c 13 Oct 2003 16:29:43 -0000
@@ -15,8 +15,10 @@
#include
#include
#include
+#include
#include
#include
+#include
#include
#include
#include
@@ -60,7 +62,9 @@
ast_log(LOG_WARNING, "Unable to execute '%s'\n", (char *)data);
res = -1;
} else {
- if (res && ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 101, chan->callerid))
+ if (res &&
+ ( chan != NULL ) &&
+ ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 101, chan->callerid))
chan->priority+=100;
res = 0;
}
@@ -68,15 +72,138 @@
return res;
}
+// [PHM 10/13/03]
+
+#define MAX_ALLOWED_COMMANDS 20
+
+static char *config = "system.conf";
+static char * command_list[MAX_ALLOWED_COMMANDS] ;
+
+
+static void
+ read_allowed_commands( void )
+{
+ int i = 0 ;
+ struct ast_config *cfg;
+ struct ast_variable *v;
+
+ cfg = ast_load(config);
+
+ if( cfg != NULL )
+ {
+ v = ast_variable_browse(cfg, "allowed_commands");
+ while(v)
+ {
+ if (!strcasecmp(v->name, "command"))
+ {
+ command_list[ i ] = malloc( strlen( v->value ) + 1 ) ;
+ strcpy( command_list[ i ], v->value);
+ i++ ;
+ }
+
+ if( i == MAX_ALLOWED_COMMANDS )
+ break ;
+ else
+ v = v->next;
+ }
+
+ ast_destroy(cfg);
+ }
+}
+
+
+static void
+ free_allowed_commands( void )
+{
+ int i ;
+
+ for( i = 0 ; i < MAX_ALLOWED_COMMANDS ; i++ )
+ if( command_list[ i ] != NULL )
+ {
+ free( command_list[ i ] ) ;
+ command_list[ i ] = NULL ;
+ }
+}
+
+
+static int
+ allowed( char * command )
+{
+ int i, ret = 0 ;
+
+ for( i = 0 ; ( i < MAX_ALLOWED_COMMANDS ) && (command_list[ i ] != NULL ); i++ )
+ if( strncasecmp( command_list[i], command, strlen(command) ) == 0 )
+ {
+ ret = 1 ;
+ break ;
+ }
+
+ return( ret ) ;
+}
+
+
+
+// [PHM 10/11/03]
+
+static int exec_system_cli(int fd, int argc, char **argv)
+{
+ int i ;
+ char buf[128];
+
+ if (argc < 2)
+ return RESULT_SHOWUSAGE;
+
+ if( allowed( argv[1] ) )
+ {
+ strcpy( buf, argv[1]) ;
+
+ for( i = 2 ; argv[ i ] != NULL ; i++ )
+ {
+ strcat( buf, " ") ;
+ strcat( buf, argv[i]) ;
+ }
+
+ ast_log(LOG_DEBUG, "System: '%s'\n", buf );
+
+ if( skel_exec( NULL, buf) == 0 )
+ return RESULT_SUCCESS;
+ else
+ return RESULT_SHOWUSAGE;
+ }
+ else
+ {
+ ast_log(LOG_DEBUG, "System: command '%s' not allowed!\n", argv[1] );
+ return RESULT_SHOWUSAGE;
+ }
+}
+
+static char show_system_usage[] =
+"Usage: system [params ...]\n"
+" Execute system() command.\n";
+
+
+static struct ast_cli_entry cli_system = {
+ { "system", NULL, NULL }, exec_system_cli,
+ "Execute System() command", show_system_usage, NULL };
+
+
int unload_module(void)
{
STANDARD_HANGUP_LOCALUSERS;
+
+ //[PHM 11/10/03]
+ ast_cli_unregister(&cli_system);
+ free_allowed_commands() ;
return ast_unregister_application(app);
}
int load_module(void)
{
- return ast_register_application(app, skel_exec, synopsis, descrip);
+ //[PHM 11/10/03]
+ ast_cli_register(&cli_system);
+ read_allowed_commands() ;
+
+ return ast_register_application(app, skel_exec, synopsis, descrip);
}
char *description(void)