root/trunk/tauthorizefunc.h

Revision 1915, 10.1 KB (checked in by Dylan, 4 weeks ago)

unxsVZ added target selects for group migration.

  • Property svn:keywords set to id
Line 
1/*
2FILE
3        $Id$
4PURPOSE
5        Non-schema dependent tauthorize.c expansion.
6AUTHOR
7        GPL License applies, see www.fsf.org for details
8        See LICENSE file in this distribution
9        (C) 2001-2009 Gary Wallis and Hugo Urquiza.
10 
11*/
12
13void ExtSelect2(const char *cTable,const char *cVarList,unsigned uMaxResults);
14void tAuthorizeNavList(void);
15
16void EncryptPasswd(char *cPasswd);//main.c
17const char *cUserLevel(unsigned uPermLevel);//tclientfunc.h
18
19void ExtProcesstAuthorizeVars(pentry entries[], int x)
20{
21
22        /*
23        register int i;
24       
25        for(i=0;i<x;i++)
26        {
27       
28        }
29        */
30
31}//void ExtProcesstAuthorizeVars(pentry entries[], int x)
32
33
34void ExttAuthorizeCommands(pentry entries[], int x)
35{
36        if(!strcmp(gcFunction,"tAuthorizeTools"))
37        {
38                if(!strcmp(gcCommand,LANG_NB_NEW))
39                {
40                        if(guPermLevel>=12)
41                        {
42                                ProcesstAuthorizeVars(entries,x);
43                                //Check global conditions for new record here
44                                guMode=2000;
45                                tAuthorize(LANG_NB_CONFIRMNEW);
46                        }
47                }
48                else if(!strcmp(gcCommand,LANG_NB_CONFIRMNEW))
49                {
50                        if(guPermLevel>=12)
51                        {
52                                ProcesstAuthorizeVars(entries,x);
53                                //Check entries here
54                                uAuthorize=0;
55                                uCreatedBy=guLoginClient;
56                                uOwner=guLoginClient;
57                                uModBy=0;//Never modified
58                                NewtAuthorize(0);
59                        }
60                }
61                else if(!strcmp(gcCommand,LANG_NB_DELETE))
62                {
63                        ProcesstAuthorizeVars(entries,x);
64                        if(uAllowDel(uOwner,uCreatedBy))
65                        {
66                                guMode=2001;
67                                tAuthorize(LANG_NB_CONFIRMDEL);
68                        }
69                }
70                else if(!strcmp(gcCommand,LANG_NB_CONFIRMDEL))
71                {
72                        ProcesstAuthorizeVars(entries,x);
73                        if(uAllowDel(uOwner,uCreatedBy))
74                        {
75                                guMode=5;
76                                DeletetAuthorize();
77                        }
78                }
79                else if(!strcmp(gcCommand,LANG_NB_MODIFY))
80                {
81                        ProcesstAuthorizeVars(entries,x);
82                        if(uAllowMod(uOwner,uCreatedBy))
83                        {
84                                guMode=2002;
85                                tAuthorize(LANG_NB_CONFIRMMOD);
86                        }
87                        else
88                                tAuthorize("<blink>Error</blink>: Denied by permissions settings");
89                }
90                else if(!strcmp(gcCommand,LANG_NB_CONFIRMMOD))
91                {
92                        ProcesstAuthorizeVars(entries,x);
93                        if(uAllowMod(uOwner,uCreatedBy))
94                        {
95                                //Place limits on what non root users can change.
96                                if(uPerm>guPermLevel) uPerm=guPermLevel;
97                                //we should not allow non root uses to change uCertClient
98                                unsigned uPrevCertClient=0;
99                                sscanf(ForeignKey("tAuthorize","uCertClient",uAuthorize),"%u",&uPrevCertClient);
100                                if(guPermLevel<12 && uPrevCertClient) uCertClient=uPrevCertClient;
101                                if(uPerm<1 || uPerm>12)
102                                {
103                                        guMode=2002;
104                                        sprintf(gcQuery,"uPerm level error:%u",uPerm);
105                                        tAuthorize(gcQuery);
106                                }
107                                if(!cPasswd[0] && !cClrPasswd[0])
108                                {
109                                        guMode=2002;
110                                        tAuthorize("Must provide a passwd");
111                                }
112
113                                //Must clear out encrypted password before replacing
114                                if(cClrPasswd[0] && strncmp(cPasswd,"..",2) && strncmp(cPasswd,"$1$",3))
115                                {
116                                        sprintf(cPasswd,"%.35s",cClrPasswd);
117                                        EncryptPasswd(cPasswd);
118                                }
119                                else
120                                {
121                                        if(strncmp(cPasswd,"..",2) && strncmp(cPasswd,"$1$",3))
122                                                EncryptPasswd(cPasswd);
123                                }
124
125                                uModBy=guLoginClient;
126                                ModtAuthorize();
127                        }
128                        else
129                                tAuthorize("<blink>Error</blink>: Denied by permissions settings");
130                }
131        }
132
133}//void ExttAuthorizeCommands(pentry entries[], int x)
134
135
136void ExttAuthorizeButtons(void)
137{
138        OpenFieldSet("tAuthorize Aux Panel",100);
139        switch(guMode)
140        {
141                case 2000:
142                        printf("<u>New: Step 1 Tips</u><br>");
143                        printf("This should only be done by experienced staff.<p>");
144                        printf("cLabel: This field is the login char string.<p>");
145                        printf("cIpMask: This field is optionally used to limit the login from IP or IP range.<p>");
146                        printf("uPerm: This field is a number value of utmost importance. See the tClient [Authorize] process for more information.<p>");
147                        printf("uCertClient: Is usually the tClient.uClient number of the usage owner of this record, but maybe an alias like the value 1 for the default Root user.<p>");
148                        printf("Password setting: You can either enter a clear text passwd in cClrPasswd or enter a clear text passwd in cPasswd that will be encrypted into cPasswd and no cClrPasswd will be saved. And finally you can enter a fixed '..' salt DES encrypted passwd into cPasswd..<p>");
149                        printf(LANG_NBB_CONFIRMNEW);
150                        printf("<br>\n");
151                break;
152
153                case 2001:
154                        printf(LANG_NBB_CONFIRMDEL);
155                        printf("<br>\n");
156                break;
157
158                case 2002:
159                        printf("<u>Modify: Step 1 Tips</u><br>");
160                        printf("Password changing: You have several choices for passwd changing: You can either enter a clear text passwd in cClrPasswd or enter a clear text passwd in cPasswd that will be encrypted into cPasswd and no cClrPasswd will be saved. And finally you can enter an MD5 $1$ prefixed encrypted password (or for backwards compatability a fixed '..' salt DES encrypted ) passwd into cPasswd.<p>\n");
161                        printf("Other field changes: Unless you are absolutely sure what you need done, have 2nd level support (support@unixservice.com) do it for you.<p>\n");
162                        printf(LANG_NBB_CONFIRMMOD);
163                        printf("<br>\n");
164                break;
165
166                default:
167                        printf("<u>Table Tips</u><br>");
168                        printf("Here you can change a passwd for a login of a contact or a non company affiliated login user. Other more complex changes can be done on other fields, but you should seek guidance from experienced users first. Clicking on the modify (new or delete) button will provide more details. All changes are two step operations so there is no danger on clicking on the 'New', 'Modify' or 'Delete' buttons.<p>\n");
169                        printf("<u>Record Context Info</u><br>");
170                        if(uCertClient>1 && uOwner>1)
171                                printf("This login appears to belong to a <a class=darkLink href=unxsVZ.cgi?gcFunction=tClient&uClient=%u>'%s'</a> company contact '<a class=darkLink href=unxsVZ.cgi?gcFunction=tClient&uClient=%u>%s</a>'.<br>The uPerm corresponds to permission level '%s'.",uOwner,ForeignKey("tClient","cLabel",uOwner),uCertClient,ForeignKey("tClient","cLabel",uCertClient),cUserLevel(uPerm));
172                        else if(uOwner>1)
173                                printf("This login appears to belong to a '<a class=darkLink href=unxsVZ.cgi?gcFunction=tClient&uClient=%u>%s</a>' company contact, but that has been root aliased to usually run the back-office with complete permissions. <br>The uPerm corresponds to permission level '%s'.",uOwner,ForeignKey("tClient","cLabel",uOwner),cUserLevel(uPerm));
174                        printf("<p>\n");
175                        tAuthorizeNavList();
176        }
177
178        CloseFieldSet();
179
180}//void ExttAuthorizeButtons(void)
181
182
183void ExttAuthorizeAuxTable(void)
184{
185
186}//void ExttAuthorizeAuxTable(void)
187
188
189void ExttAuthorizeGetHook(entry gentries[], int x)
190{
191        register int i;
192
193        for(i=0;i<x;i++)
194        {
195                if(!strcmp(gentries[i].name,"uAuthorize"))
196                {
197                        sscanf(gentries[i].val,"%u",&uAuthorize);
198                        guMode=6;
199                }
200        }
201        tAuthorize("");
202
203}//void ExttAuthorizeGetHook(entry gentries[], int x)
204
205
206void ExttAuthorizeSelect(void)
207{
208        //New ExtSelect() version requires a 3rd argument, the max row count number
209        ExtSelect2("tAuthorize",VAR_LIST_tAuthorize,0);
210}//void ExttAuthorizeSelect(void)
211
212
213void ExttAuthorizeSelectRow(void)
214{
215        ExtSelectRow("tAuthorize",VAR_LIST_tAuthorize,uAuthorize);
216}//void ExttAuthorizeSelectRow(void)
217
218
219void ExttAuthorizeListSelect(void)
220{
221        char cCat[512];
222
223        ExtListSelect("tAuthorize",VAR_LIST_tAuthorize);
224        //Changes here must be reflected below in ExttAuthorizeListFilter()
225        if(!strcmp(gcFilter,"uAuthorize"))
226        {
227                sscanf(gcCommand,"%u",&uAuthorize);
228                if(guPermLevel<10)
229                        strcat(gcQuery," AND ");
230                else
231                        strcat(gcQuery," WHERE ");
232                sprintf(cCat,"tAuthorize.uAuthorize=%u ORDER BY uAuthorize",
233                                                uAuthorize);
234                strcat(gcQuery,cCat);
235        }
236        if(!strcmp(gcFilter,"cLabel"))
237        {
238                if(guPermLevel<10)
239                        strcat(gcQuery," AND ");
240                else
241                        strcat(gcQuery," WHERE ");
242                sprintf(cCat,"tAuthorize.cLabel LIKE '%s%%' ORDER BY cLabel",
243                                TextAreaSave(gcCommand));
244                strcat(gcQuery,cCat);
245        }
246        else if(1)
247        {
248                //None NO FILTER
249                strcpy(gcFilter,"None");
250                strcat(gcQuery," ORDER BY uAuthorize");
251        }
252
253}//void ExttAuthorizeListSelect(void)
254
255
256void ExttAuthorizeListFilter(void)
257{
258        //Filter
259        printf("<td align=right >Select ");
260        printf("<select name=gcFilter>");
261        if(strcmp(gcFilter,"uAuthorize"))
262                printf("<option>uAuthorize</option>");
263        else
264                printf("<option selected>uAuthorize</option>");
265        if(strcmp(gcFilter,"cLabel"))
266                printf("<option>cLabel</option>");
267        else
268                printf("<option selected>cLabel</option>");
269        if(strcmp(gcFilter,"None"))
270                printf("<option>None</option>");
271        else
272                printf("<option selected>None</option>");
273        printf("</select>");
274
275}//void ExttAuthorizeListFilter(void)
276
277
278void ExttAuthorizeNavBar(void)
279{
280        printf(LANG_NBB_SKIPFIRST);
281        printf(LANG_NBB_SKIPBACK);
282        printf(LANG_NBB_SEARCH);
283
284        if(guPermLevel>=12 && !guListMode)
285                printf(LANG_NBB_NEW);
286
287        if(uAllowMod(uOwner,uCreatedBy))
288                printf(LANG_NBB_MODIFY);
289
290        if(uAllowDel(uOwner,uCreatedBy))
291                printf(LANG_NBB_DELETE);
292
293        if(uOwner)
294                printf(LANG_NBB_LIST);
295
296        printf(LANG_NBB_SKIPNEXT);
297        printf(LANG_NBB_SKIPLAST);
298
299}//void ExttAuthorizeNavBar(void)
300
301
302void tAuthorizeNavList(void)
303{
304        MYSQL_RES *res;
305        MYSQL_ROW field;
306
307        sprintf(gcQuery,"SELECT uAuthorize,cLabel,uPerm,uCertClient FROM tAuthorize "
308                        " WHERE uOwner=%u OR uOwner IN (SELECT uClient FROM " TCLIENT
309                        " WHERE uOwner=%u)",guCompany,guCompany);
310
311        mysql_query(&gMysql,gcQuery);
312        if(mysql_errno(&gMysql))
313        {
314                printf("%s",mysql_error(&gMysql));
315                return;
316        }
317
318        res=mysql_store_result(&gMysql);
319        if(mysql_num_rows(res))
320        {
321                printf("<p><u>tAuthorizeNavList</u><br>\n");
322                while((field=mysql_fetch_row(res)))
323                {
324                        //Root can find it self. This keeps the tClient tab cleaner.
325                        if(strcmp(field[1],"Root"))
326                        printf("<a class=darkLink href=unxsVZ.cgi?gcFunction=tAuthorize&uAuthorize=%s>"
327                                "%s/%s/%s</a><br>\n",field[0],field[1],field[2],field[3]);
328                }
329        }
330        mysql_free_result(res);
331
332}//void tAuthorizeNavList(void)
333
Note: See TracBrowser for help on using the browser.