~vcs-imports/ipfire/ipfire-2.x

« back to all changes in this revision

Viewing changes to src/install+setup/setup/timezone.c

  • Committer: Dirk Wagner
  • Date: 2014-12-23 08:02:23 UTC
  • mfrom: (4405.56.108)
  • Revision ID: git-v1:601f8347ccb1e9c5e3f250ff26d4097ecd698875
Merge branch 'next' of ssh://git.ipfire.org/pub/git/ipfire-2.x into asterisk-update

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* SmoothWall setup program.
2
 
 *
3
 
 * This program is distributed under the terms of the GNU General Public
4
 
 * Licence.  See the file COPYING for details.
5
 
 *
6
 
 * (c) Lawrence Manning, 2001
7
 
 * Stuff for setting the timezone.
8
 
 * 
9
 
 * $Id: timezone.c,v 1.4.2.1 2004/04/14 22:05:41 gespinasse Exp $
10
 
 * 
11
 
 */
12
 
 
13
 
#include "setup.h"
14
 
 
15
 
extern FILE *flog;
16
 
extern char *mylog;
17
 
 
18
 
extern char **ctr;
19
 
 
20
 
extern int automode;
21
 
 
22
 
#define MAX_FILENAMES 5000
23
 
#define ZONEFILES "/usr/share/zoneinfo/posix"
24
 
 
25
 
static int filenamecount;
26
 
static char *filenames[MAX_FILENAMES];
27
 
static char *displaynames[MAX_FILENAMES];
28
 
 
29
 
static int process(char *prefix, char *path);
30
 
static int cmp(const void *s1, const void *s2);
31
 
 
32
 
int handletimezone(void)
33
 
{
34
 
        int c;
35
 
        int choice;
36
 
        char *temp;
37
 
        struct keyvalue *kv = initkeyvalues();  
38
 
        int rc;
39
 
        int result;
40
 
        char timezone[STRING_SIZE];
41
 
 
42
 
        filenamecount = 0;      
43
 
 
44
 
        process(ZONEFILES, "");
45
 
        filenames[filenamecount] = NULL;
46
 
        qsort(filenames, filenamecount, sizeof(char *), cmp);
47
 
        
48
 
        for (c = 0; filenames[c]; c++)
49
 
        {
50
 
                displaynames[c] = malloc(STRING_SIZE);
51
 
                if ((temp = strstr(filenames[c], ZONEFILES)))
52
 
                        strcpy(displaynames[c], temp + strlen(ZONEFILES) + 1);
53
 
                else
54
 
                        strcpy(displaynames[c], filenames[c]);
55
 
        }
56
 
        displaynames[c] = NULL;
57
 
        
58
 
        if (!(readkeyvalues(kv, CONFIG_ROOT "/main/settings")))
59
 
        {
60
 
                freekeyvalues(kv);
61
 
                errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
62
 
                return 0;
63
 
        }       
64
 
        
65
 
        strcpy(timezone, ZONEFILES "/Europe/Berlin");
66
 
        findkey(kv, "TIMEZONE", timezone);
67
 
        
68
 
        choice = 0;
69
 
        for (c = 0; filenames[c]; c++)
70
 
        {
71
 
                if (strcmp(timezone, filenames[c]) == 0)
72
 
                        choice = c;
73
 
        }
74
 
        
75
 
        rc = newtWinMenu(ctr[TR_TIMEZONE], ctr[TR_TIMEZONE_LONG], 50, 5, 5, 6, displaynames, &choice,
76
 
                ctr[TR_OK], ctr[TR_CANCEL], NULL);
77
 
 
78
 
        strcpy(timezone, filenames[choice]);
79
 
        
80
 
        if (rc != 2)
81
 
        {
82
 
                replacekeyvalue(kv, "TIMEZONE", timezone);
83
 
                writekeyvalues(kv, CONFIG_ROOT "/main/settings");
84
 
                unlink("/etc/localtime");
85
 
                link(timezone, "/etc/localtime");
86
 
                result = 1;
87
 
        }
88
 
        else
89
 
                result = 0;     
90
 
        
91
 
        for (c = 0; filenames[c]; c++)
92
 
        {
93
 
                free(filenames[c]);
94
 
                free(displaynames[c]);
95
 
        }
96
 
        freekeyvalues(kv);      
97
 
        
98
 
        return result;
99
 
}
100
 
 
101
 
static int process(char *prefix, char *path)
102
 
{
103
 
        DIR *dir;
104
 
        struct dirent *de;
105
 
        char newpath[PATH_MAX];
106
 
        
107
 
        snprintf(newpath, PATH_MAX, "%s%s", prefix, path);
108
 
        
109
 
        if (!(dir = opendir(newpath)))
110
 
        {
111
 
                if (filenamecount > MAX_FILENAMES)
112
 
                        return 1;
113
 
                
114
 
                filenames[filenamecount] = (char *) strdup(newpath);
115
 
                filenamecount++;
116
 
                return 0;
117
 
        }
118
 
                        
119
 
        while ((de = readdir(dir)))
120
 
        {
121
 
                if (de->d_name[0] == '.') continue;
122
 
                snprintf(newpath, PATH_MAX, "%s/%s", path, de->d_name);
123
 
                process(prefix, newpath);
124
 
        }
125
 
        closedir(dir);
126
 
        
127
 
        return 1;
128
 
}
129
 
 
130
 
/* Small wrapper for use with qsort(). */               
131
 
static int cmp(const void *s1, const void *s2)
132
 
{
133
 
        return (strcmp(* (char **) s1, * (char **) s2));
134
 
}