e9ba6fc50358fb028edf1e0ea3eb68a5e6836d03
[ossec-hids.git] / src / addagent / manage_agents.h
1 /* @(#) $Id$ */
2
3 /* Copyright (C) 2009 Trend Micro Inc.
4  * All rights reserved.
5  *
6  * This program is a free software; you can redistribute it
7  * and/or modify it under the terms of the GNU General Public
8  * License (version 2) as published by the FSF - Free Software
9  * Foundation.
10  *
11  * License details at the LICENSE file included with OSSEC or 
12  * online at: http://www.ossec.net/en/licensing.html
13  */
14
15
16 #include "shared.h"
17 #include "sec.h"
18
19
20 /** Prototypes **/
21
22 /* Read any input from the user (stdin) */
23 char *read_from_user();
24
25 /* Add or remove an agent */
26 int add_agent();
27 int remove_agent();
28
29 /* Extract or import a key */
30 int k_extract(char *cmdextract);
31 int k_import(char *cmdimport);
32
33 /* Validation functions */
34 int OS_IsValidName(char *u_name);
35 int OS_IsValidID(char *id);
36 int IDExist(char *id);
37 int NameExist(char *u_name);
38 char *getFullnameById(char *id);
39
40
41 /* Print available agents */
42 int print_agents(int print_status, int active_only, int csv_output);
43 int list_agents(int cmdlist);
44     
45 /* clear a line */
46 char *chomp(char *str);
47
48
49 /* Shared variables */
50 int restart_necessary;
51 int time1;
52 int time2;
53 int time3;
54 int rand1;
55 int rand2;
56 fpos_t fp_pos;
57
58
59 /* Internal defines */
60 #define USER_SIZE       514
61 #define FILE_SIZE       257
62 #define STR_SIZE        66
63
64 /* Internal strings */
65 #define QUIT                "\\q"
66
67 /* Print agents */
68 #define PRINT_AVAILABLE     "\nAvailable agents: \n"
69 #define PRINT_AGENT         "   ID: %s, Name: %s, IP: %s\n"
70 #define PRINT_AGENT_STATUS  "   ID: %s, Name: %s, IP: %s, %s\n"
71
72
73 /* Add new agent */
74 #define ADD_NEW         "\n- Adding a new agent"\
75                         " (use '\\q' to return to the main menu).\n"\
76                         "  Please provide the following:\n"
77 #define ADD_NAME        "   * A name for the new agent: "
78 #define ADD_IP          "   * The IP Address of the new agent: "
79 #define ADD_ID          "   * An ID for the new agent[%s]: "
80 #define AGENT_INFO      "Agent information:\n   ID:%s\n   Name:%s\n   " \
81                         "IP Address:%s\n\n"
82 #define ADD_CONFIRM     "Confirm adding it?(y/n): "
83 #define AGENT_ADD       "Agent added.\n"
84 #define ADDED           "Added.\n"
85 #define ADD_NOT         "Not Adding ..\n"
86 #define PRESS_ENTER     "** Press ENTER to return to the main menu.\n"
87 #define MUST_RESTART    "\n** You must restart the server for your changes" \
88                         " to have effect.\n\n"
89
90 /* Add errors */
91 #define ADD_ERROR_ID    "\n** ID '%s' already present. They must be unique.\n\n"
92 #define ADD_ERROR_NAME  "\n** Name '%s' already present. Please enter a new name.\n\n"
93 #define IP_ERROR        "\n** Invalid IP '%s'. Please enter a valid IP Address.\n\n"
94 #define NO_AGENT        "\n** No agent available. You need to add one first.\n"
95 #define NO_ID           "\n** Invalid ID '%s' given. ID is not present.\n"
96 #define NO_KEY          "\n** Invalid authentication key. Starting over again.\n"
97 #define INVALID_ID      "\n** Invalid ID '%s' given. ID must be numeric (max 5 digits).\n\n"
98 #define INVALID_NAME    "\n** Invalid name '%s' given. Name must contain only alphanumeric characters (min=2, max=32).\n\n"
99
100 /* Remove agent */
101 #define REMOVE_ID       "Provide the ID of the agent to be removed (or '\\q' to quit): "
102 #define REMOVE_CONFIRM  "Confirm deleting it?(y/n): "
103 #define REMOVE_DONE     "Agent '%s' removed.\n"
104 #define REMOVE_NOT      "Not removing ..\n"
105
106 /* Import agent */    
107 #define IMPORT_KEY      "\n* Provide the Key generated by the server.\n" \
108                         "* The best approach is to cut and paste it.\n" \
109                         "*** OBS: Do not include spaces or new lines.\n\n" \
110                         "Paste it here (or '\\q' to quit): "
111     
112 /* extract key */    
113 #define EXTRACT_KEY     "Provide the ID of the agent to extract " \
114                         "the key (or '\\q' to quit): "
115 #define EXTRACT_MSG     "\nAgent key information for '%s' is: \n%s\n"
116
117
118 /* Commom errors */
119 #define ERROR_KEYS      "Unable to handle keys file. Exiting.\n"
120 #define EXTRACT_ERROR   "Unable to extract agent key.\n"
121 #define INPUT_LARGE     ARGV0 ": Input too large. Not adding it.\n"
122 #define EXIT            ARGV0 ": Exiting ..\n"
123
124 #define BANNER          "\n****************************************" \
125                         "\n* %s %s Agent manager.     *" \
126                         "\n* The following options are available: *" \
127                         "\n****************************************\n"
128     
129 #define BANNER_OPT      "   (A)dd an agent (A).\n" \
130                         "   (E)xtract key for an agent (E).\n" \
131                         "   (L)ist already added agents (L).\n" \
132                         "   (R)emove an agent (R).\n" \
133                         "   (Q)uit.\n" \
134                         "Choose your action: A,E,L,R or Q: "
135
136 #define BANNER_CLIENT   "   (I)mport key from the server (I).\n" \
137                         "   (Q)uit.\n" \
138                         "Choose your action: I or Q: "
139                         
140 /* EOF */