Пример #1
0
int start_attack(attack_t *a){
	int rc;

	switch(a->type){
	case ATTACK_INJECT:
		if(!a->dest || !a->text){
			fprintf(stderr, "This attack needs a text as well as a destination number\n");
			rc = -2;
		} else {
			if((rc = send_sms(a->sock, a->dest, a->text) < 0)){
				fprintf(stderr, "Error sending SMS (%d)\n", rc);
			} else {
				printf("SMS on its way :D\n");
			}
		}
		break;
	case ATTACK_MODIFY:
		if(!a->dest && !a->text){
			fprintf(stderr, "You either have to modify the destination or the text!\n");
			rc = -2;
		} else {
			if((rc = modify_sms(a->sock, a->dest, a->text)) < 0){
				fprintf(stderr, "Error modifying SMS (%d)\n", rc);
			}
		}
		break;
	default:
		fprintf(stderr, "Unknown attack (shouldn't happen)\n");
		rc = -3;
		break;
	}

	return rc;
}
Пример #2
0
void check_sms(void) {
	unsigned char i = 0;
	unsigned char k = 0;
	unsigned char phone[15];

	i = 3;
	while (i < 15) {
		if (reic[i] == '"')
			break;
		phone[k] = reic[i];
		k++;
		i++;
	}
	phone[k] = '\0';
	send_sms(phone,"OK Duong");
}
Пример #3
0
int main (){

	int x;
	//char * ptr;
	char * AT = "\r\nAT\r\n";
	char * PIN_CHECK = "\r\nAT+CPIN?\r\n";
	char * ENTER_PIN = "\r\nAT+CPIN=\"1234\"\r\n";
	char * CREG = "\r\nAT+CREG?\r\n";
	char response[20];

	char * ptr;
	enum STATES {INIT, CHECK_PIN, SEND_PIN, CHECK_NETWORK_REG, SEND_SMS, CONNECTED};
	enum STATES CurrentState = INIT;

	hardware_init();
	enable_UART0_receive_interrupt();
	buffer_init();
	PIT_Configure_interrupt_mode(1);    //PIT interrupt every second
	enable_UART0_receive_interrupt();

	PRINTF("\nGSM Modem Control\n");
	//Configuration

	while(1)
	{
		switch(CurrentState)
		{
		case INIT:  //Check connection to MODEM by sending AT. Expected response is OK
			PRINTF("Testing Modem Connection\n");
			result = send_command(AT, response, sizeof(response), 10);
			if(result == SUCCESS || result == ERROR)
			{
				printf_response(response);
			}
			if(result == SUCCESS)   //"OK" was returned by MODEM
				CurrentState = CHECK_PIN;
			else    //incorrect response or timeout. Delay and try again
			{
				CurrentTick = tick_count;
				while((tick_count - CurrentTick) < 5)
				{}
			}
			break;

		case CHECK_PIN: //Check if SIM card is ready
			result = send_command(PIN_CHECK, response, sizeof(response), 10);
			if(result == SUCCESS || result == ERROR)
			{
				printf_response(response);
			}
			if(result == SUCCESS)   //"OK" returned, check response string for "READY" or "SIM_PIN"
			{
				if(strstr(response, "READY")) //if ready ok is typed into terminal
				{

					CurrentState = CHECK_NETWORK_REG; //move to check_network_reg
				}
				else if(strstr(response, "SIM_PIN")) // sim_pin ok entered
				{

					CurrentState = SEND_PIN; //move to send_pin
				}
			}
			else
				CurrentState = INIT;
			break;

		case SEND_PIN:  //Send PIN code. "OK" response if PIN is correct
			result = send_command(ENTER_PIN, response, sizeof(response), 10);
			if(result == SUCCESS || result == ERROR)
			{
				printf_response(response);
			}
			if(result==SUCCESS) //if logic '0'
					{
				//if(strstr(response, ""))
				CurrentState = CHECK_NETWORK_REG; //move to check_network_reg
					}
			else
			{
				CurrentState = CHECK_PIN; //if '-1' move back to check_pin again
			}
			break;


		case CHECK_NETWORK_REG: //check if registered on mobile network
			result = send_command(CREG, response, sizeof(response), 20);
			if(result == SUCCESS || result == ERROR)
			{
				printf_response(response);
			}
			if(result==SUCCESS)
			{
				if(strstr(response,"+CREG")) //if +creg entered
						{
					ptr = (char*)strchr(response,':');//point to the colon
					ptr+=4; //move 4 places
					switch(*ptr)//switch contents of address pointed to
					{
					case '1'://if  +creg: 0,1 entered
						CurrentState = INIT;// move back to init
						PRINTF("Invalid;Try again");
						break;
					case '2'://if  +creg: 0,2 entered
						CurrentState = SEND_SMS;//move to send_sms
						PRINTF("Proceed to send SMS");
						break;
					case '3'://if  +creg: 0,3 entered
						CurrentTick = tick_count;//wait for "network"
						while((tick_count - CurrentTick) < 5)
						{}
						PRINTF("Checking for Network, Please Wait");
						break;
					case '4'://if  +creg: 0,4 entered
						CurrentState = INIT;//move back to init
						PRINTF("Invalid,Try Again");
						break;
					case '5': //if  +creg: 0,5 entered
						CurrentState = SEND_SMS;//send sms
						PRINTF("Proceed to send SMS");
						break;
					default:
						CurrentState = INIT;
						PRINTF("Invalid,Try Again");
						break;
					}
						}
				else
				{
					CurrentState = INIT;
				}
				printf_response(response);
				break;

		case SEND_SMS:  //Send a text message
			send_sms("\"0871234567\"","\"Testing 123\""); //send number

			send_sms("\"0171112233\"","\"Success\""); // the message
			if(result==SUCCESS) // if logic '0'
			{
				PRINTF("Message has been sent");
				CurrentState = CONNECTED;//move to connected
				break;
			}
			else
			{
				CurrentTick = tick_count;// wait for input
				while((tick_count - CurrentTick) < 5)
				{}
				break;
			}
		case CONNECTED:
			while(1)    //dummy loop
			{}
			break;
		default:
			break;
			}//end switch-case
		}//end while(1)
	}
}
Пример #4
0
/******************************************************************************
 *                                                                            *
 * Function: execute_action                                                   *
 *                                                                            *
 * Purpose: execute an action depending on mediatype                          *
 *                                                                            *
 * Parameters: alert - alert details                                          *
 *             mediatype - media details                                      *
 *                                                                            *
 * Return value: SUCCESS - action executed sucessfully                        *
 *               FAIL - otherwise, error will contain error message           *
 *                                                                            *
 * Author: Alexei Vladishev                                                   *
 *                                                                            *
 * Comments:                                                                  *
 *                                                                            *
 ******************************************************************************/
int execute_action(DB_ALERT *alert,DB_MEDIATYPE *mediatype, char *error, int max_error_len)
{
	int 	res=FAIL;
	int	pid;

	char	full_path[MAX_STRING_LEN];

	char    env_alertid[128],env_actionid[128],env_clock[128],env_mediatypeid[128],
		env_status[128];
	char    *zbxenv[] = { (char *)&env_alertid, (char *)&env_actionid, (char *)&env_clock,
		(char *)&env_mediatypeid, (char *)&env_status,
		(char *)0 };

	zabbix_log( LOG_LEVEL_DEBUG, "In execute_action(%s)",
		mediatype->smtp_server);

	if(mediatype->type==MEDIA_TYPE_EMAIL)
	{
		alarm(40);
		res = send_email(mediatype->smtp_server,mediatype->smtp_helo,mediatype->smtp_email,alert->sendto,alert->subject,
			alert->message, error, max_error_len);
		alarm(0);
	}
#if defined (HAVE_JABBER)
	else if(mediatype->type==MEDIA_TYPE_JABBER)
	{
		/* Jabber uses its own timeouts */
		res = send_jabber(mediatype->username, mediatype->passwd, alert->sendto, alert->subject,
				alert->message, error, max_error_len);
	}
#endif /* HAVE_JABBER */
	else if(mediatype->type==MEDIA_TYPE_SMS)
	{
		/* SMS uses its own timeouts */
		res = send_sms(mediatype->gsm_modem,alert->sendto,alert->message, error, max_error_len);
	}
	else if(mediatype->type==MEDIA_TYPE_EXEC)
	{
/*		if(-1 == execl(CONFIG_ALERT_SCRIPTS_PATH,mediatype->exec_path,alert->sendto,alert->subject,alert->message))*/
		zabbix_log( LOG_LEVEL_DEBUG, "Before execl([%s],[%s])",
			CONFIG_ALERT_SCRIPTS_PATH,
			mediatype->exec_path);

/*		if(-1 == execl("/home/zabbix/bin/lmt.sh","lmt.sh",alert->sendto,alert->subject,alert->message,(char *)0))*/

		pid = zbx_fork();
		if(0 != pid)
		{
			waitpid(pid,NULL,0);
		}
		else
		{
			strscpy(full_path,CONFIG_ALERT_SCRIPTS_PATH);
			zbx_strlcat(full_path,"/",MAX_STRING_LEN);
			zbx_strlcat(full_path,mediatype->exec_path,MAX_STRING_LEN);
			ltrim_spaces(full_path);
			zabbix_log( LOG_LEVEL_DEBUG, "Before executing [%s]",
				full_path);

			zbx_snprintf(env_alertid,127,"ZABBIX_ALERT_ID=%d",
				alert->alertid);
			zbx_snprintf(env_actionid,127,"ZABBIX_ACTION_ID=%d",
				alert->actionid);
			zbx_snprintf(env_clock,127,"ZABBIX_ALERT_TIME=%d",
				alert->clock);
			zbx_snprintf(env_mediatypeid,127,"ZABBIX_ALERT_MEDIATYPEID=%d",
				alert->mediatypeid);
			zbx_snprintf(env_status,127,"ZABBIX_ALERT_STATUS=%d",
				alert->status);

/*			if(-1 == execl(full_path,mediatype->exec_path,alert->sendto,alert->subject,alert->message,(char *)0))*/
			if(-1 == execle(full_path,mediatype->exec_path,alert->sendto,alert->subject,alert->message,(char *)0, zbxenv))

			{
				zabbix_log( LOG_LEVEL_ERR, "Error executing [%s] [%s]",
					full_path,
					strerror(errno));
				zabbix_syslog("Error executing [%s] [%s]",
					full_path,
					strerror(errno));
				zbx_snprintf(error,max_error_len,"Error executing [%s] [%s]",
					full_path,
					strerror(errno));
				res = FAIL;
			}
			else
			{
				res = SUCCEED;
			}
			/* In normal case the program will never reach this point */
			zabbix_log( LOG_LEVEL_DEBUG, "After execl()");
			exit(0);
		}
		res = SUCCEED;
	}
	else
	{
		zabbix_log( LOG_LEVEL_ERR, "Unsupported media type [%d] for alert ID [%d]",
			mediatype->type,
			alert->alertid);
		zabbix_syslog("Unsupported media type [%d] for alert ID [%d]",
			mediatype->type,
			alert->alertid);
		zbx_snprintf(error,max_error_len,"Unsupported media type [%d]",
			mediatype->type);
		res=FAIL;
	}

	zabbix_log( LOG_LEVEL_DEBUG, "End execute_action()");

	return res;
}
Пример #5
0
static int
index_html (struct shttpd_arg_t *arg)
{
  int n = 0, ret = 0;
  int *p = arg->user_data;	/* integer passed to us */
  const char *phone_num = NULL, *text = NULL;
  const char *ajax = NULL;
  int isajax = 0;
  
  if((ajax = shttpd_get_var(arg, "ajax")) != NULL)
    isajax = 1;
  if(!isajax)
  { 
    n += snprintf (arg->buf + n, arg->buflen - n, "%s",
		 "HTTP/1.1 200 OK\r\n"
		 "Content-Type: text/html\r\n\r\n"
		 "<html><head><title>Send SMS To Phone</title>"
		 "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf8\"/>"
		 "<meta name=\"viewport\" content=\"width=320, initial-scale=1.0\" />"
		 "</head><body>");
  }
  phone_num = shttpd_get_var (arg, "phone_num");
  text = shttpd_get_var (arg, "text");
  if(phone_num != NULL && text != NULL)
  {   
    if ((ret = send_sms (phone_num, text)) < 0) {
	n += snprintf (arg->buf + n, arg->buflen - n,
	     "<p>Could not Send SMS: %d</p>", ret);
	} else {
	     char sql[1024];
	     char *sr;
	     n += snprintf (arg->buf + n, arg->buflen - n, "<p>Sent Ok</p>");
	     sprintf(sql,"insert into message (address,text,date,flags) values('%s','%s','%d','3');",
			     phone_num,text,time(NULL));
	     sr = sqlite_exec("/var/root/Library/SMS/sms.db",sql);
	     free(sr);
	}
      if(isajax)
      {
	arg->last = 1;
	return (n);
      }
  }
 
  n += snprintf (arg->buf + n, arg->buflen - n,
		 "<form  method=\"post\">"
		 "<p>To:"
		 "<input style=\"font-size:18px\" type=\"text\" size=\"14\" maxlength=\"14\" name=\"phone_num\" value=\"%s\"/>"
		 "&nbsp;<a href=\"/simpb.html\">PhoneBook</a></p>"
		 "<textarea style=\"font-size:15px\" cols=30 rows=10 name=\"text\">%s</textarea><br/>"
		 "<input style=\"font-size:15px\" value=\"Send\" type=\"submit\"/></form>",
		 (phone_num != NULL) ? phone_num : "", (text != NULL) ? text : "");

  n += snprintf (arg->buf + n, arg->buflen - n, "<div style=\"text-align: right\"><a href=\"/setting.html\">Setting</a>&nbsp;&nbsp;<a href=\"/sms_sim.html\">SMS(SIM)</a>&nbsp;&nbsp;<a href=\"/sms.html?box=inbox\">Inbox</a>&nbsp;&nbsp;<a href=\"/sms.html?box=outbox\">Outbox</a></div>");
  n += snprintf (arg->buf + n, arg->buflen - n, "<br/><div><a href=\"/credit.html\">Credit</a>");
  n += snprintf (arg->buf + n, arg->buflen - n, "&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"/api.html\">API</a></dev>");
  n += snprintf (arg->buf + n, arg->buflen - n, "</body></html>");

  assert (n < (int) arg->buflen);
  arg->last = 1;

  return (n);
}
Пример #6
0
/******************************************************************************
 *                                                                            *
 * Function: execute_action                                                   *
 *                                                                            *
 * Purpose: execute an action depending on mediatype                          *
 *                                                                            *
 * Parameters: alert - alert details                                          *
 *             mediatype - media details                                      *
 *                                                                            *
 * Return value: SUCCESS - action executed sucessfully                        *
 *               FAIL - otherwise, error will contain error message           *
 *                                                                            *
 * Author: Alexei Vladishev                                                   *
 *                                                                            *
 * Comments:                                                                  *
 *                                                                            *
 ******************************************************************************/
int	execute_action(DB_ALERT *alert, DB_MEDIATYPE *mediatype, char *error, int max_error_len)
{
	const char	*__function_name = "execute_action";

	int 	pid, res = FAIL;
	char	full_path[MAX_STRING_LEN];

	zabbix_log(LOG_LEVEL_DEBUG, "In %s(): alertid [" ZBX_FS_UI64 "] mediatype [%d]",
			__function_name, alert->alertid, mediatype->type);

	if (MEDIA_TYPE_EMAIL == mediatype->type)
	{
		alarm(40);
		res = send_email(mediatype->smtp_server, mediatype->smtp_helo, mediatype->smtp_email,
				alert->sendto, alert->subject, alert->message, error, max_error_len);
		alarm(0);
	}
#if defined(HAVE_JABBER)
	else if (MEDIA_TYPE_JABBER == mediatype->type)
	{
		/* Jabber uses its own timeouts */
		res = send_jabber(mediatype->username, mediatype->passwd,
				alert->sendto, alert->subject, alert->message, error, max_error_len);
	}
#endif
	else if (MEDIA_TYPE_SMS == mediatype->type)
	{
		/* SMS uses its own timeouts */
		res = send_sms(mediatype->gsm_modem, alert->sendto, alert->message, error, max_error_len);
	}
	else if (MEDIA_TYPE_EZ_TEXTING == mediatype->type)
	{
		/* Ez Texting uses its own timeouts */
		res = send_ez_texting(mediatype->username, mediatype->passwd,
				alert->sendto, alert->message, mediatype->exec_path, error, max_error_len);
	}
	else if (MEDIA_TYPE_EXEC == mediatype->type)
	{
		pid = zbx_fork();
		if (0 != pid)
		{
			waitpid(pid, NULL, 0);
			res = SUCCEED;
		}
		else
		{
			zbx_snprintf(full_path, sizeof(full_path), "%s/%s",
					CONFIG_ALERT_SCRIPTS_PATH, mediatype->exec_path);

			zabbix_log(LOG_LEVEL_DEBUG, "Before executing [%s]", full_path);

			if (-1 == execl(full_path, mediatype->exec_path, alert->sendto,
						alert->subject, alert->message, (char *)NULL))
			{
				zabbix_log(LOG_LEVEL_ERR, "Error executing [%s] [%s]",
					full_path,
					strerror(errno));
				zabbix_syslog("Error executing [%s] [%s]",
					full_path,
					strerror(errno));
				exit(FAIL);
			}
			else
				THIS_SHOULD_NEVER_HAPPEN;
		}
	}
	else
	{
		zabbix_log(LOG_LEVEL_ERR, "Unsupported media type [%d] for alert ID [" ZBX_FS_UI64 "]",
			mediatype->type,
			alert->alertid);
		zabbix_syslog("Unsupported media type [%d] for alert ID [" ZBX_FS_UI64 "]",
			mediatype->type,
			alert->alertid);
		zbx_snprintf(error, max_error_len, "Unsupported media type [%d]",
			mediatype->type);
		res = FAIL;
	}

	zabbix_log(LOG_LEVEL_DEBUG, "End of %s(): %d", __function_name, zbx_result_string(res));

	return res;
}
Пример #7
0
int
main(int argc,
     char *argv[])
{
    int i, rc, nerr = 0, e;
    char *to, *msg, *cp;
    BUFFER buf;
#if HAVE_DOORS
    struct door_info dib;
#endif
    
    for (i = 1; i < argc && argv[i][0] == '-'; i++)
	switch (argv[i][1])
	{
	  case 'V':
	    p_header();
	    exit(0);
	    
	  case 'm':
	    ++mailmode;
	    break;
	    
	  case 'd':
	    ++debug;
	    break;

#if HAVE_DOORS
	  case 'D':
	    door_path = strdup(argv[i]+2);
	    break;
#endif
	    
	  case 'F':
	    fifo_path = strdup(argv[i]+2);
	    break;
	    
	  case '-':
	    goto EndOptions;

	  case 'h':
	    usage(stdout, argv[0]);
	    exit(0);
	    
	  default:
	    fprintf(stderr, "%s: unknown switch: %s\n", argv[0], argv[i]);
	    exit(1);
	}

  EndOptions:
    if (i >= argc)
    {
	fprintf(stderr, "%s: Missing recipient of message\n", argv[0]);
	exit(1);
    }

#if HAVE_DOORS
    door_fd = open(door_path, O_RDONLY);
    if (door_fd < 0)
    {
	e = errno;
	if (errno != ENOENT) {
	    syslog(LOG_ERR, "%s: open: %s\n", door_path, strerror(e));
	    fprintf(stderr, "%s: open(%s): %s\n", argv[0], door_path, strerror(e));
	    exit(1);
	}
    }

    if (door_fd > 0) {
	if (door_info(door_fd, &dib) < 0)
	{
	    e = errno;
	    syslog(LOG_ERR, "%s: door_info: %s\n", door_path, strerror(e));
	    fprintf(stderr, "%s: %s: door_info: %s\n", argv[0], door_path, strerror(e));
	    exit(1);
	}
	
	if (debug)
	{
	    printf("door_info() -> server pid = %ld, uniquifier = %ld",
		   (long) dib.di_target,
		   (long) dib.di_uniquifier);
	    
	    if (dib.di_attributes & DOOR_LOCAL)
		printf(", LOCAL");
	    if (dib.di_attributes & DOOR_PRIVATE)
		printf(", PRIVATE");
	    if (dib.di_attributes & DOOR_REVOKED)
		printf(", REVOKED");
	    if (dib.di_attributes & DOOR_UNREF)
		printf(", UNREF");
	    putchar('\n');
	}
	
	if (dib.di_attributes & DOOR_REVOKED)
	{
	    syslog(LOG_ERR, "%s: door revoked\n", door_path);
	    fprintf(stderr, "%s: door revoked\n", argv[0]);
	    exit(1);
	}
    }
#endif

    if (isatty(fileno(stdin)))
	puts("Enter message:");
    
    buf_init(&buf);
    buf_load(&buf, stdin);

    msg = buf_getall(&buf);
    if (mailmode)
    {
	while (*msg && !((msg[0] == '\n' && msg[1] == '\n') ||
			 (msg[0] == '\r' && msg[1] == '\n' &&
			  msg[2] == '\r' && msg[3] == '\n')))
	    ++msg;
	
	switch (*msg)
	{
	  case '\r':
	    msg += 4;
	    break;
	    
	  case '\n':
	    msg += 2;
	}
    }

    while (i < argc)
    {
	to = s_dup(argv[i]);
	if (!to) {
	    fprintf(stderr, "%s: %s: s_dup: %s\n", argv[0], argv[i], strerror(errno));
	    exit(1);
	}
	    
	cp = strchr(to, '@');
	if (cp)
	    *cp = '\0';
	
	rc = send_sms(to, msg);
	if (rc != 0)
	{
	    ++nerr;
	    e = errno;
	    syslog(LOG_ERR, "%s: send failed (door_path=%s, rc=%d): %s", argv[i], door_path, strerror(e));
	    fprintf(stderr, "%s: %s: send failed (rc=%d): %s\n", argv[0], argv[i], rc, strerror(e));
	}
	
	++i;
    }
    
    exit(nerr);
}
Пример #8
0
// --- loop ---
void loop(){
	char Key = kpd.getKey();
	switch (alarmState) {
		// off - system idle
	  case off:
			set_sirene(false);
			goto_on_if_password();
    	break;

		// wait_on - delay before on (delai de sortie maison)
	  case wait_on:
			set_sirene(false);
			goto_off_if_password();
			if(wait_on_timer.check() == 1){
				set_lcd("alarm on", "");
				next_alarmState = on;
			}
    	break;

		// on - system is running
	  case on:
			set_sirene(false);
			if(get_sensors()) {
				next_alarmState = detection;
				set_lcd("detection", "");
			}
			goto_off_if_password();
    	break;

		// detection - movement detected
	  case detection:
			set_sirene(false);
			send_sms();
			goto_off_if_password();
			before_sirene_timer.reset();
			next_alarmState = 	before_sirene;
	    break;
	
		// before_sirene - delay before sirene (delai d'entrée dans maison) 
	  case before_sirene:
			set_sirene(false);
			if(before_sirene_timer.check() == 1){
				ring_sirene_timer.reset();
				next_alarmState = ring_sirene;
				set_lcd("sirene", "");
			}
			goto_off_if_password();
	    break;

		// sirene - sirene is crying
	  case ring_sirene:
			set_sirene(true);
			goto_off_if_password();
			if(ring_sirene_timer.check() == 1){
				wait_on_timer.reset();
				next_alarmState = wait_on;
				set_lcd("wait_on", "");			
			}
	    break;
	}
	alarmState = next_alarmState;
}
Пример #9
0
/******************************************************************************
 *                                                                            *
 * Function: execute_action                                                   *
 *                                                                            *
 * Purpose: execute an action depending on mediatype                          *
 *                                                                            *
 * Parameters: alert - alert details                                          *
 *             mediatype - media details                                      *
 *                                                                            *
 * Return value: SUCCESS - action executed sucessfully                        *
 *               FAIL - otherwise, error will contain error message           *
 *                                                                            *
 * Author: Alexei Vladishev                                                   *
 *                                                                            *
 ******************************************************************************/
int	execute_action(DB_ALERT *alert, DB_MEDIATYPE *mediatype, char *error, int max_error_len)
{
	const char	*__function_name = "execute_action";

	int 	res = FAIL;

	zabbix_log(LOG_LEVEL_DEBUG, "In %s(): alertid [" ZBX_FS_UI64 "] mediatype [%d]",
			__function_name, alert->alertid, mediatype->type);

	if (MEDIA_TYPE_EMAIL == mediatype->type)
	{
		alarm(ALARM_ACTION_TIMEOUT);
		res = send_email(mediatype->smtp_server, mediatype->smtp_helo, mediatype->smtp_email,
				alert->sendto, alert->subject, alert->message, error, max_error_len);
		alarm(0);
	}
#ifdef HAVE_JABBER
	else if (MEDIA_TYPE_JABBER == mediatype->type)
	{
		/* Jabber uses its own timeouts */
		res = send_jabber(mediatype->username, mediatype->passwd,
				alert->sendto, alert->subject, alert->message, error, max_error_len);
	}
#endif
	else if (MEDIA_TYPE_SMS == mediatype->type)
	{
		/* SMS uses its own timeouts */
		res = send_sms(mediatype->gsm_modem, alert->sendto, alert->message, error, max_error_len);
	}
	else if (MEDIA_TYPE_EZ_TEXTING == mediatype->type)
	{
		/* Ez Texting uses its own timeouts */
		res = send_ez_texting(mediatype->username, mediatype->passwd,
				alert->sendto, alert->message, mediatype->exec_path, error, max_error_len);
	}
	else if (MEDIA_TYPE_EXEC == mediatype->type)
	{
		char	full_path[MAX_STRING_LEN], *send_to, *subject, *message, *output = NULL;

		send_to = zbx_dyn_escape_string(alert->sendto, "\"\\");
		subject = zbx_dyn_escape_string(alert->subject, "\"\\");
		message = zbx_dyn_escape_string(alert->message, "\"\\");

		zbx_snprintf(full_path, sizeof(full_path), "%s/%s \"%s\" \"%s\" \"%s\"",
				CONFIG_ALERT_SCRIPTS_PATH, mediatype->exec_path, send_to, subject, message);

		zbx_free(send_to);
		zbx_free(subject);
		zbx_free(message);

		if (SUCCEED == (res = zbx_execute(full_path, &output, error, max_error_len, ALARM_ACTION_TIMEOUT)))
		{
			zabbix_log(LOG_LEVEL_DEBUG, "%s output:\n%s", mediatype->exec_path, output);
			zbx_free(output);
		}
		else
			res = FAIL;
	}
	else
	{
		zbx_snprintf(error, max_error_len, "unsupported media type [%d]", mediatype->type);
		zabbix_log(LOG_LEVEL_ERR, "alert ID [" ZBX_FS_UI64 "]: %s", alert->alertid, error);
		zabbix_syslog("alert ID [" ZBX_FS_UI64 "]: %s", alert->alertid, error);
	}

	zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(res));

	return res;
}
Пример #10
0
/******************************************************************************
 *                                                                            *
 * Function: execute_action                                                   *
 *                                                                            *
 * Purpose: execute an action depending on mediatype                          *
 *                                                                            *
 * Parameters: alert - alert details                                          *
 *             mediatype - media details                                      *
 *                                                                            *
 * Return value: SUCCESS - action executed successfully                       *
 *               FAIL - otherwise, error will contain error message           *
 *                                                                            *
 * Author: Alexei Vladishev                                                   *
 *                                                                            *
 ******************************************************************************/
int	execute_action(DB_ALERT *alert, DB_MEDIATYPE *mediatype, char *error, int max_error_len)
{
	const char	*__function_name = "execute_action";

	int 	res = FAIL;

	zabbix_log(LOG_LEVEL_DEBUG, "In %s(): alertid [" ZBX_FS_UI64 "] mediatype [%d]",
			__function_name, alert->alertid, mediatype->type);

	if (MEDIA_TYPE_EMAIL == mediatype->type)
	{
		res = send_email(mediatype->smtp_server, mediatype->smtp_port, mediatype->smtp_helo,
				mediatype->smtp_email, alert->sendto, alert->subject, alert->message,
				mediatype->smtp_security, mediatype->smtp_verify_peer, mediatype->smtp_verify_host,
				mediatype->smtp_authentication, mediatype->username, mediatype->passwd,
				ALARM_ACTION_TIMEOUT, error, max_error_len);
	}
#ifdef HAVE_JABBER
	else if (MEDIA_TYPE_JABBER == mediatype->type)
	{
		/* Jabber uses its own timeouts */
		res = send_jabber(mediatype->username, mediatype->passwd,
				alert->sendto, alert->subject, alert->message, error, max_error_len);
	}
#endif
	else if (MEDIA_TYPE_SMS == mediatype->type)
	{
		/* SMS uses its own timeouts */
		res = send_sms(mediatype->gsm_modem, alert->sendto, alert->message, error, max_error_len);
	}
	else if (MEDIA_TYPE_EZ_TEXTING == mediatype->type)
	{
		/* Ez Texting uses its own timeouts */
		res = send_ez_texting(mediatype->username, mediatype->passwd,
				alert->sendto, alert->message, mediatype->exec_path, error, max_error_len);
	}
	else if (MEDIA_TYPE_EXEC == mediatype->type)
	{
		char	*cmd = NULL, *send_to, *subject, *message, *output = NULL;
		size_t	cmd_alloc = ZBX_KIBIBYTE, cmd_offset = 0;

		cmd = zbx_malloc(cmd, cmd_alloc);

		zbx_snprintf_alloc(&cmd, &cmd_alloc, &cmd_offset, "%s/%s",
				CONFIG_ALERT_SCRIPTS_PATH, mediatype->exec_path);

		if (0 == access(cmd, X_OK))
		{
			send_to = zbx_dyn_escape_shell_single_quote(alert->sendto);
			subject = zbx_dyn_escape_shell_single_quote(alert->subject);
			message = zbx_dyn_escape_shell_single_quote(alert->message);

			zbx_snprintf_alloc(&cmd, &cmd_alloc, &cmd_offset, " '%s' '%s' '%s'", send_to, subject, message);

			zbx_free(message);
			zbx_free(subject);
			zbx_free(send_to);

			if (SUCCEED == (res = zbx_execute(cmd, &output, error, max_error_len, ALARM_ACTION_TIMEOUT)))
			{
				zabbix_log(LOG_LEVEL_DEBUG, "%s output:\n%s", mediatype->exec_path, output);
				zbx_free(output);
			}
			else
				res = FAIL;
		}
		else
			zbx_snprintf(error, max_error_len, "%s: %s", cmd, zbx_strerror(errno));

		zbx_free(cmd);
	}
	else
	{
		zbx_snprintf(error, max_error_len, "unsupported media type [%d]", mediatype->type);
		zabbix_log(LOG_LEVEL_ERR, "alert ID [" ZBX_FS_UI64 "]: %s", alert->alertid, error);
	}

	zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(res));

	return res;
}
Пример #11
0
int main()
{

	char * AT = "\r\nAT\r\n";//Setting up a char variable AT for the a long string
	char * PIN_CHECK = "\r\nAT+CPIN?\r\n";//Setting up a char variable PIN_CHECK for the a long string
	char * ENTER_PIN = "\r\nAT+CPIN=\"1234\"\r\n";//Setting up a char variable ENTER_PIN for the a long string
	char * CREG = "\r\nAT+CREG?\r\n";//Setting up a char variable CREG for the a long string
	char response[20]; //A character buffer called response that can hold 20 characters
	int result = 0;	//int result to check the value of the response sent back
	int transmit_send = 0;
	volatile int CurrentTick;	//Volitile interger to hold the current tick count of the current time
	char * ptr;	//Character
	char * stat;
	enum STATES {INIT, CHECK_PIN, SEND_PIN, CHECK_NETWORK_REG, SEND_SMS, CONNECTED};
	enum STATES CurrentState = INIT;
	uart_state_t uartState; // user provides memory for the driver state structure
	uart_user_config_t uartConfig;
	buffer_init();
	hardware_init();
	//UART0_config();
	PIT_Configure_interrupt_mode(1);
	configure_uart_pins(0);	//instance 0 is UART1???
	// Call OSA_Init to setup LP Timer for timeout
	OSA_Init();


	uartConfig.baudRate = 9600;
	uartConfig.bitCountPerChar = kUart8BitsPerChar;
	uartConfig.parityMode = kUartParityDisabled;
	uartConfig.stopBitCount = kUartOneStopBit;

	UART_DRV_Init(1, &uartState,&uartConfig);
	//PRINTF("UART0 Test Code\n\r");
	//PRINTF("Any entered character will be echoed\r\n\n");
	while(1)
	{
		switch(CurrentState)
		{
		case INIT:	//Check connection to MODEM by sending AT. Expected response is OK
			printf("Testing Modem Connection\n");
			result = send_command(AT, response, sizeof(response), 2000);
			if(result == SUCCESS || result == ERROR)
			{
				//printf_response(response);
			}
			if(result == SUCCESS)	//"OK" was returned by MODEM
				CurrentState = CHECK_PIN;
			else	//incorrect response or timeout. Delay and try again
			{
				CurrentTick = tick_count;
				while((tick_count - CurrentTick) < 5)
				{}
			}
			break;

		case CHECK_PIN:	//Check if SIM card is ready
			result = send_command(PIN_CHECK, response, sizeof(response), 10);
			if(result == SUCCESS || result == ERROR)
			{
				//printf_response(response);
			}
			if(result == SUCCESS)	//"OK" returned, check response string for "READY" or "SIM_PIN"
			{
				if(strstr(response, "READY"))
				{
					CurrentState = CHECK_NETWORK_REG;
				}
				else if(strstr(response, "SIM PIN"))
				{
					CurrentState = SEND_PIN;
				}
			}
			else
				CurrentState = INIT;
			break;

		case SEND_PIN:	//Send PIN code. "OK" response if PIN is correct
			result = send_command(ENTER_PIN, response, sizeof(response),10);
			if(result == SUCCESS || result == ERROR)
			{
				//printf_response(response);
			}
			if(result == SUCCESS)	//"OK" returned, check response string for "READY" or "SIM_PIN"
			{
				CurrentState = CHECK_NETWORK_REG;
			}
			else
				CurrentState = INIT;
			break;


		case CHECK_NETWORK_REG:	//check if registered on mobile network
			result = send_command(CREG, response, sizeof(response), 20);
			if(strstr(response, "+CREG"))
			{
				stat = (char *)strstr(response,":");
				stat += 4;
				switch(*stat)
				{
				case '0':
					CurrentState = INIT;
					break;
				case '1':
					CurrentState = SEND_SMS;
					break;
				case '2':
					CurrentTick = tick_count;
					while((tick_count - CurrentTick) < 5)
					{}
					CurrentState = CHECK_NETWORK_REG;
					break;
				case '3':
					CurrentState = INIT;
					break;
				case '4':
					CurrentState = CONNECTED;
					break;
				case '5':
					CurrentState = SEND_SMS;
					break;

				}
			}


		case SEND_SMS:	//Send a text message
			transmit_send = send_sms("\"0877763894\"","\"Testing 123		\"");
			if(transmit_send == SUCCESS)
			{
				CurrentState = CONNECTED;
			}
			else if(transmit_send == FAIL)
			{
				printf("A transmission fail has been detected or you have timed out\r\n");
				CurrentState = SEND_SMS;
			}
			else if(transmit_send == ERROR)
			{
				printf("A transmission ERROR has been detected,rebooting\r\n");
				CurrentState = INIT;
			}
			break;

		case CONNECTED:
			printf("\nInside Connected \r\n");
			while(1)	//dummy loop
			{}
			break;

		default:
			break;
		}//end switch-case
	}
}
int main()
{
    send_sms( "0128994212", "This is a test SMS. Apparently, it works." );
    return 0;
}
Пример #13
0
int main(void) {
	WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT

	/* Use Calibration values for 1MHz Clock DCO*/
	DCOCTL = 0;
	BCSCTL1 = CALBC1_1MHZ;
	DCOCTL = CALDCO_1MHZ;

	/* Configure Pin Muxing P1.1 RXD and P1.2 TXD */
	P1SEL |= BIT1 | BIT2;
	P1SEL2 |= BIT1 | BIT2;

	/* Place UCA0 in Reset to be configured */
	UCA0CTL1 = UCSWRST;

	/* Configure */
	UCA0CTL1 |= UCSSEL_2;                     // SMCLK
	UCA0BR0 = 104;                            // 1MHz 9600
	UCA0BR1 = 0;                              // 1MHz 9600
	UCA0MCTL = UCBRS0;                        // Modulation UCBRSx = 1

	/* Take UCA0 out of reset */
	UCA0CTL1 &= ~UCSWRST;

	/* Enable USCI_A0 RX interrupt */
	IE2 |= UCA0RXIE;

	/* Enable leds*/
	P1DIR |= LED_GREEN + LED_RED;
	LED_OFF(LED_GREEN|LED_RED);

	/* Blink leds when reset */
	blink_led(LED_RED | LED_GREEN, 5);

	/* Init Button */
	P1REN |= BIT3;                   // Enable internal pull-up/down resistors
	P1OUT |= BIT3;                   //Select pull-up mode for P1.3
	P1IE |= BIT3;                       // P1.3 interrupt enabled
	P1IES |= BIT3;                     // P1.3 Hi/lo edge
	P1IFG &= ~BIT3;                  // P1.3 IFG cleared

	/* Power up Sim900A */
	P2DIR |= SIM_POW;
	power_sim();

	__enable_interrupt();

	if (check_status_sim())
		blink_led(LED_GREEN, 5);
	else {
		blink_led(LED_RED, 5);
	}

	while (1) {
		if (isSendSMS) {
			isSendSMS = 0;
			send_sms("0934384878", "Hello Duong");
		}
		if (isHasSMS) {
			blink_led(LED_GREEN,3);
			check_sms();
			isHasSMS = 0;
			isSimSendData = 0;
			index_reic = 0;
			data_prev = 0;
			data_current = 0;
		}
	}
}