]> andersk Git - moira.git/blob - clients/moira/pobox.c
Change `SMS' to `Moira' where possible.
[moira.git] / clients / moira / pobox.c
1 #if (!defined(lint) && !defined(SABER))
2   static char rcsid_module_c[] = "$Header$";
3 #endif
4
5 /*      This is the file pobox.c for the Moira Client, which allows users
6  *      to quickly and easily maintain most parts of the Moira database.
7  *      It Contains: Functions for handling the poboxes.
8  *
9  *      Created:        7/10/88
10  *      By:             Chris D. Peterson
11  *
12  *      $Source$
13  *      $Author$
14  *      $Header$
15  *
16  *      Copyright 1988 by the Massachusetts Institute of Technology.
17  *
18  *      For further information on copyright and distribution
19  *      see the file mit-copyright.h
20  */
21
22 #include <stdio.h>
23 #include <string.h>
24 #include <ctype.h>
25 #include <moira.h>
26 #include <moira_site.h>
27 #include <menu.h>
28
29 #include "mit-copyright.h"
30 #include "defs.h"
31 #include "f_defs.h"
32 #include "globals.h"
33
34 #define FOREIGN_BOX ("SMTP")
35 #define LOCAL_BOX ("POP")
36
37 /*      Function Name: PrintPOBox
38  *      Description: Yet another specialized print function.
39  *      Arguments: info - all info about this PO_box.
40  *      Returns: MR_CONT
41  */
42
43 static void PrintPOBox(char **info)
44 {
45   char buf[BUFSIZ];
46
47   sprintf(buf, "Address: %-10s Box: %-35s Type: %s", info[PO_NAME],
48           info[PO_BOX], info[PO_TYPE]);
49   Put_message(buf);
50   sprintf(buf, MOD_FORMAT, info[4], info[3], info[5]);
51   Put_message(buf);
52 }
53
54 /*      Function Name: RealPrintPOMachines
55  *      Description: Actually does the printing for PrintPOMachines.
56  *      Arguments: info, - name of machines in info[1].
57  *      Returns: none.
58  */
59
60 static void RealPrintPOMachines(char **info)
61 {
62   Print(1, info + 1, NULL);
63 }
64
65 /*      Function Name: PrintPOMachines
66  *      Description: Prints all current post offices.
67  *      Arguments: none.
68  *      Returns: SUB_ERROR if the machines could not be printed.
69  */
70
71 static int PrintPOMachines(void)
72 {
73   int status;
74   static char *args[] = {"pop", NULL};
75   struct qelem *top = NULL;
76
77   if ((status = do_mr_query("get_server_locations", CountArgs(args), args,
78                             StoreInfo, (char *)&top)))
79     {
80       com_err(program_name, status, " in get_server_locations.");
81       return SUB_ERROR;
82     }
83
84   top = QueueTop(top);
85   Loop(top, RealPrintPOMachines);
86   FreeQueue(top);
87   return SUB_NORMAL;
88 }
89
90 /*      Function Name: GetUserPOBox
91  *      Description: prints the users POBox information.
92  *      Arguments: argc, argv - name of the user in argv[1].
93  *      Returns: DM_NORMAL.
94  */
95
96 int GetUserPOBox(int argc, char **argv)
97 {
98   int status;
99   struct qelem *top = NULL;
100   char buf[BUFSIZ];
101
102   if (!ValidName(argv[1]))
103     return DM_NORMAL;
104
105   switch ((status = do_mr_query("get_pobox", 1, argv + 1, StoreInfo,
106                                 (char *)&top)))
107     {
108     case MR_NO_MATCH:
109       Put_message("This user has no P.O. Box.");
110       break;
111     case MR_SUCCESS:
112       sprintf(buf, "Current pobox for user %s: \n", argv[1]);
113       Put_message("");
114       top = QueueTop(top);
115       Loop(top, PrintPOBox);    /* should only return 1 box. */
116       FreeQueue(top);
117       break;
118     default:
119       com_err(program_name, status, " in get_pobox.");
120     }
121   return DM_NORMAL;
122 }
123
124 /*      Function Name: GetNewLocalPOBox
125  *      Description: get the machine for a new local pop Box for the user.
126  *      Arguments: local_user - name of the local user.
127  *      Returns: machine - name of the machine for then new pop box, or NULL.
128  */
129
130 static char *GetNewLocalPOBox(char *local_user)
131 {
132   char temp_buf[BUFSIZ];
133
134   sprintf(temp_buf, "%s %s", "Pick one of the following",
135           "machines for this user's Post Office.");
136   Put_message(temp_buf);
137   Put_message("");
138   if (PrintPOMachines() == SUB_NORMAL)
139     {
140       Put_message("");
141       if (!Prompt_input("Which Machine? ", temp_buf, BUFSIZ))
142         return (char *) SUB_ERROR;
143       return canonicalize_hostname(strsave(temp_buf));
144     }
145   Put_message("Could not get machines to choose from, quitting.");
146   return (char *) SUB_ERROR;
147 }
148
149 /*      Function Name: SetUserPOBox
150  *      Description: Addes or Chnages the P.O. Box for a user.
151  *      Arguments: argc, argv - the login name of the user in argv[1].
152  *      Returns: DM_NORMAL.
153  */
154
155 int SetUserPOBox(int argc, char **argv)
156 {
157   int status;
158   char *type, temp_buf[BUFSIZ], *local_user, *args[10], box[BUFSIZ];
159   char *temp_box;
160   struct qelem *top = NULL;
161   local_user = argv[1];
162
163   if (!ValidName(local_user))
164     return DM_NORMAL;
165
166   /* Print the current PO Box info */
167   switch ((status = do_mr_query("get_pobox", 1, argv + 1, StoreInfo,
168                                 (char *)&top)))
169     {
170     case MR_SUCCESS:
171       sprintf(temp_buf, "Current pobox for user %s: \n", local_user);
172       Put_message("");
173       top = QueueTop(top);
174       Loop(top, PrintPOBox);    /* should only return 1 box. */
175       FreeQueue(top);
176       break;
177     case MR_NO_MATCH:
178       Put_message("This user has no P.O. Box.");
179       break;
180     default:
181       com_err(program_name, status, " in get_pobox.");
182       return DM_NORMAL;
183     }
184
185   sprintf(temp_buf, "Assign %s a local PO Box (y/n)", local_user);
186   switch (YesNoQuestion(temp_buf, TRUE))
187     {
188     case TRUE:
189       type = LOCAL_BOX;
190       switch (YesNoQuestion("Use Previous Local Box (y/n)", TRUE))
191         {
192         case TRUE:
193           switch ((status = do_mr_query("set_pobox_pop", 1,
194                                         &local_user, Scream, NULL)))
195             {
196             case MR_SUCCESS:
197               return DM_NORMAL;
198             case MR_MACHINE:
199               sprintf(temp_buf, "%s did not have a previous local PO Box.",
200                       local_user);
201               Put_message(temp_buf);
202               if ((temp_box = GetNewLocalPOBox(local_user)) !=
203                   (char *) SUB_ERROR)
204                 {
205                   strcpy(box, temp_box);
206                   free(temp_box);
207                 }
208               else
209                 return DM_NORMAL;
210               break;
211             default:
212               com_err(program_name, status, " in set_pobox_pop.");
213               return DM_NORMAL;
214             }
215           break;
216         case FALSE:
217           if ((temp_box = GetNewLocalPOBox(local_user)) !=
218               (char *) SUB_ERROR)
219             {
220               strcpy(box, temp_box);
221               free(temp_box);
222             }
223           else
224             return DM_NORMAL;
225           break;
226         default:
227           return DM_NORMAL;
228         }
229       break;
230     case FALSE:
231       type = FOREIGN_BOX;
232       sprintf(temp_buf, "Set up a foreign PO Box for %s (y/n)", local_user);
233       switch (YesNoQuestion(temp_buf, TRUE))
234         {
235         case TRUE:
236           if (!Prompt_input("Foreign PO Box for this user? ", box, BUFSIZ))
237             return DM_NORMAL;
238           break;
239         case FALSE:
240         default:
241           return DM_NORMAL;     /* ^C hit. */
242         }
243       break;
244     default:                    /* ^C hit. */
245       Put_message("Aborted.");
246       return DM_NORMAL;
247     }
248
249   args[PO_NAME] = local_user;
250   args[PO_TYPE] = type;
251   args[PO_BOX] = box;
252   args[PO_END] = NULL;
253   if ((status = do_mr_query("set_pobox", CountArgs(args), args,
254                             Scream, NULL)))
255     com_err(program_name, status, " in ChangeUserPOBox");
256   else
257     Put_message("PO Box assigned.");
258
259   return DM_NORMAL;
260 }
261
262 /*      Function Name: RemoveUserPOBox
263  *      Description: Removes this users POBox.
264  *      Arguments: argc, argv - name of user in argv[1].
265  *      Returns: DM_NORMAL.
266  */
267
268 int RemoveUserPOBox(int argc, char **argv)
269 {
270   int status;
271   char temp_buf[BUFSIZ];
272
273   if (!ValidName(argv[1]))
274     return DM_NORMAL;
275
276   sprintf(temp_buf, "Are you sure that you want to remove %s's PO Box (y/n)",
277           argv[1]);
278
279   if (Confirm(temp_buf))
280     {
281       if ((status = do_mr_query("delete_pobox", 1, argv + 1,
282                                 Scream, NULL)))
283         com_err(program_name, status, " in delete_pobox.");
284       else
285         Put_message("PO Box removed.");
286     }
287   return DM_NORMAL;
288 }
This page took 0.067867 seconds and 5 git commands to generate.