Ejemplo n.º 1
0
int GeUser::remove_system( char *name)
{
  int sts;
  SystemList *sl_p, *prev;

  SystemName *sn = new SystemName( name);
  sts = sn->parse();
  if ( EVEN(sts))
  {
    delete sn;
    return sts;
  }

  SystemList *sl = find_system( sn);
  if ( !sl) {
    delete sn;
    return USER__NOSUCHSYSTEM;
  }
  if ( sl->childlist || sl->userlist) {
    delete sn;
    return USER__SYSTEMNOTEMPTY;
  }

  SystemName *parent = sn->parent();
  if ( !parent)
  {
    for ( sl_p = root; sl_p; sl_p = sl_p->next)
    {
      if ( sl_p == sl)
      {
        if ( sl == root)
          root = sl->next;
        else
          prev->next = sl->next;
        delete sl;
        delete sn;
        return USER__SUCCESS;
      }
      prev = sl_p;
    }
  }
  else
  {
    parent->parse();
    SystemList *parent_system = find_system( parent);
    if ( !parent_system) return USER__NOSUCHSYSTEM;

    sts =  parent_system->remove_system( sl);
    delete sn;
    delete parent;
    return sts;
  }
  return USER__NOSUCHSYSTEM;
}
Ejemplo n.º 2
0
int GeUser::add_system(
    char* name, pwr_tMask attributes, char* description, pwr_tOix id)
{
  int sts;

  SystemName* sn = new SystemName(name);
  sts = sn->parse();
  if (EVEN(sts)) {
    delete sn;
    return sts;
  }

  if (id == user_cNId)
    id = get_next_id();
  else if (id >= next_id)
    next_id = id + 1;

  SystemList* sl = find_system(sn);
  if (sl)
    return USER__SYSTEMALREXIST;

  SystemName* parent = sn->parent();
  if (!parent) {
    SystemList* sl;

    SystemList* system_list
        = new SystemList(id, name, 0, attributes, description);
    // Insert as last sibling to root
    if (!root)
      root = system_list;
    else {
      for (sl = root; sl->next; sl = sl->next)
        ;
      sl->next = system_list;
    }
  } else {
    parent->parse();
    SystemList* sl = find_system(parent);
    if (!sl) {
      delete sn;
      delete parent;
      return USER__NOSUCHSYSTEM;
    }
    sl->add_system(id, sn, attributes, description);
    delete parent;
  }
  delete sn;
  return USER__SUCCESS;
}
Ejemplo n.º 3
0
int GeUser::add_user(char* system, char* user, char* password, pwr_tMask priv,
    char* fullname, char* description, char* email, char* phone, char* sms,
    pwr_tOix id)
{
  SystemList* sl;
  int sts;

  // Find system
  SystemName* sn = new SystemName(system);
  sts = sn->parse();
  if (EVEN(sts)) {
    delete sn;
    return sts;
  }
  sl = find_system(sn);
  if (!sl)
    return USER__NOSUCHSYSTEM;

  if (id == user_cNId)
    id = get_next_id();
  else if (id >= next_id)
    next_id = id + 1;

  sl->add_user(
      id, user, password, priv, fullname, description, email, phone, sms);
  return USER__SUCCESS;
}
Ejemplo n.º 4
0
int GeUser::get_user_data(char* system, char* user, char* password,
    pwr_tMask* priv, pwr_tOix* id, char* fullname, char* description,
    char* email, char* phone, char* sms)
{
  int sts;
  UserList* ul;

  SystemName* sn = new SystemName(system);
  sts = sn->parse();
  if (EVEN(sts)) {
    delete sn;
    return sts;
  }

  SystemList* sl = find_system(sn);
  delete sn;
  if (!sl)
    return USER__NOSUCHSYSTEM;

  ul = (UserList*)sl->find_user(user);
  if (!ul)
    return USER__NOSUCHUSER;
  ul->get_data(password, priv, id, fullname, description, email, phone, sms);

  return USER__SUCCESS;
}
Ejemplo n.º 5
0
int GeUser::modify_user(char* system, char* user, char* password,
    unsigned int priv, char* fullname, char* description, char* email,
    char* phone, char* sms)
{
  int sts;
  UserList* ul;

  SystemName* sn = new SystemName(system);
  sts = sn->parse();
  if (EVEN(sts)) {
    delete sn;
    return sts;
  }

  SystemList* sl = find_system(sn);
  delete sn;
  if (!sl)
    return USER__NOSUCHSYSTEM;

  ul = (UserList*)sl->find_user(user);
  if (!ul)
    return USER__NOSUCHUSER;
  ul->modify(password, priv, fullname, description, email, phone, sms);

  return USER__SUCCESS;
}
Ejemplo n.º 6
0
int GeUser::remove_user(char* system, char* user)
{
  int sts;

  SystemName* sn = new SystemName(system);
  sts = sn->parse();
  if (EVEN(sts)) {
    delete sn;
    return sts;
  }

  SystemList* sl = find_system(sn);
  if (!sl) {
    delete sn;
    return USER__NOSUCHSYSTEM;
  }
  sts = sl->remove_user(user);
  delete sn;
  return sts;
}
Ejemplo n.º 7
0
int GeUser::modify_system(char* name, pwr_tMask attributes, char* description)
{
  int sts;

  SystemName* sn = new SystemName(name);
  sts = sn->parse();
  if (EVEN(sts)) {
    delete sn;
    return sts;
  }

  SystemList* sl = find_system(sn);
  if (!sl) {
    delete sn;
    return USER__NOSUCHSYSTEM;
  }

  sl->modify(attributes, description);
  return USER__SUCCESS;
}
Ejemplo n.º 8
0
int GeUser::get_system_data(
    const char* name, pwr_tMask* attributes, pwr_tOix* id, char* description)
{
  int sts;

  SystemName* sn = new SystemName(name);
  sts = sn->parse();
  if (EVEN(sts)) {
    delete sn;
    return sts;
  }

  SystemList* sl = find_system(sn);
  if (!sl) {
    delete sn;
    return USER__NOSUCHSYSTEM;
  }

  sl->get_data(attributes, id, description);
  return USER__SUCCESS;
}
Ejemplo n.º 9
0
pwr_tStatus rt_post::mh_alarm_bc( mh_sMessage *MsgP)
{
  ala_uEvent 	*event = (ala_uEvent *) MsgP;
  int sts;
  char str[256];
  char user[80];
  char group[80];
  char *s;
  pwr_tTime etime, current;
  pwr_tDeltaTime diff;
  int rcvnum;
  char rcv_array[10][80];
  char text[400];

  if ( !post || post->conf->Disable)
    return 1;

  if ( !event->Info.EventFlags & pwr_mEventFlagsMask_Email ||
       !event->Info.EventFlags & pwr_mEventFlagsMask_SMS)
    return 1;

  // Skip events older than 10 minutes
  etime = net_NetTimeToTime( &event->Info.EventTime);
  time_GetTime( &current);
  time_Adiff( &diff, &current, &etime);

  if ( time_DToFloat( 0, &diff) > 600)
    return 1;

  // Check if already handled
  if ( event->Info.EventFlags & pwr_mEventFlagsMask_Email) {
    if ( post->email_check( &event->Info.Id))
      return 1;
    else
      post->email_register( &event->Info.Id);
  }
  

  if ( event->Info.EventFlags & pwr_mEventFlagsMask_SMS) {
    if ( post->sms_check( &event->Info.Id))
      return 1;
    else
      post->sms_register( &event->Info.Id);
  }

  post->replace_symbol( str, event->Msg.Receiver);

  rcvnum = dcli_parse( str, ",", "",
		     (char *) rcv_array, sizeof( rcv_array)/sizeof( rcv_array[0]),
		     sizeof( rcv_array[0]), 0);
  
  for ( int i = 0; i < rcvnum; i++) {

    dcli_trim( str, rcv_array[i]);

    s = strrchr( str, '.');
    if ( s) {
      *s = 0;
      strncpy( group, post->systemgroup, sizeof(group));
      strncat( group, ".", sizeof(group));
      strncat( group, str, sizeof(group));
      strncpy( user, s+1, sizeof(user));
    }
    else {
      strncpy( group, post->systemgroup, sizeof(group));
      strncpy( user, str, sizeof(user));
    }
  
    SystemName *sn = new SystemName( group);
    sts = sn->parse();
    if ( EVEN(sts)) {
      delete sn;
      errh_Error( "Post systemgroup parse error, %m", sts);
      continue;
    }

    SystemList *sl = post->udb->find_system( sn);
    delete sn;
    if ( !sl) {
      errh_Error( "No such system group, %s", group);
      continue;
    }

    UserList *ul = (UserList *) sl->find_user( user);
    if ( !ul) {
      errh_Error( "No such user, %s", user);
      continue;
    }
  
    if ( event->Info.EventFlags & pwr_mEventFlagsMask_Email &&
	 strcmp( post->conf->EmailCmd, "") != 0) {
      char address[40];
      pwr_tCmd cmd;
      
      ul->get_email( address, sizeof(address));
      
      post->format_email_text( MsgP, text, sizeof(text));
      post->format_cmd( cmd,  post->conf->EmailCmd, address, text);

      if ( post->conf->Options & pwr_mPostOptionsMask_Log)
	errh_Info( "Email: %s", cmd);

      system( cmd);
      post->conf->SentEmail++;
      
    }
    if ( event->Info.EventFlags & pwr_mEventFlagsMask_SMS &&
	 strcmp( post->conf->SMS_Cmd, "") != 0) {
      char sms[40];
      pwr_tCmd cmd;
    
      ul->get_sms( sms, sizeof(sms));

      post->format_sms_text( MsgP, text, sizeof(text));
      post->format_cmd( cmd,  post->conf->SMS_Cmd, sms, text);
      
      if ( post->conf->Options & pwr_mPostOptionsMask_Log)
	errh_Info( "SMS: %s", cmd);

      system( cmd);
      post->conf->SentSMS++;
    }
  }
  return 1;
}