-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnfs.cxx
157 lines (129 loc) · 4.05 KB
/
nfs.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
* NFS support for GeeXboX FLTK Generator
* Copyright (C) 2007-2008 Mathieu Schroeter
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "generatorUI.h"
#include "config.h"
#include "nfs.h"
#include "utils.h"
#include <FL/fl_ask.H> /* fl_alert */
#include <string>
typedef struct {
std::string server;
std::string dir;
} Nfsshare;
void update_nfs_tab(GeneratorUI *ui)
{
Nfsshare *n;
n = (Nfsshare*)ui->nfs_shares->mvalue()->user_data();
if (n && ui->nfs_shares->size() > 2) {
ui->nfs_server->value(n->server.c_str());
ui->nfs_dir->value(n->dir.c_str());
ui->nfs_mountpoint->value(ui->nfs_shares->mvalue()->label());
}
else {
ui->nfs_server->value("");
ui->nfs_dir->value("");
ui->nfs_mountpoint->value("");
}
}
void add_nfs(GeneratorUI *ui)
{
Nfsshare *n = new Nfsshare;
std::string mp;
mp = get_str_nospace((char*)ui->nfs_mountpoint->value(), 1);
n->server = get_str_nospace((char*)ui->nfs_server->value(), 1);
n->dir = get_str_nospace((char*)ui->nfs_dir->value(), 1);
if (mp != "<new>" && !n->server.empty() && !n->dir.empty() && !mp.empty()) {
ui->nfs_shares->add(mp.c_str(), 0, 0, (Nfsshare*)n, 0);
ui->nfs_shares->value(0);
update_nfs_tab(ui);
}
else {
delete n;
fl_alert("All fields are needed!\n");
}
}
void remove_nfs(GeneratorUI *ui)
{
if (ui->nfs_shares->size() > 2) {
if (strcmp(ui->nfs_shares->mvalue()->label(), "<new>")) {
ui->nfs_shares->remove(ui->nfs_shares->value());
ui->nfs_shares->value(0);
update_nfs_tab(ui);
}
}
}
int init_nfs_tab(GeneratorUI *ui)
{
char buf[256];
FILE *f;
f = fopen(PATH_BASEISO "/etc/nfs", "rb");
if (!f) {
fl_alert("Missing nfs configuration files.\n");
return 0;
}
/* Read all NFS mountpoints */
ui->nfs_shares->add("<new>");
while ((fgets(buf, sizeof(buf), f))) {
std::string src, dst;
src = get_str_nospace(buf, 1);
if (*src.begin() == '#')
continue;
dst = get_str_nospace(buf, 2);
if (!src.empty() && !dst.empty()) {
std::string::size_type index;
std::string server, dir;
index = src.find(':');
if (index != std::string::npos) {
Nfsshare *n = new Nfsshare;
server = src.substr(0, index);
dir = src.substr(index + 1);
n->server = server;
n->dir = dir;
ui->nfs_shares->add(dst.c_str(), 0, 0, (Nfsshare*)n, 0);
}
}
}
ui->nfs_shares->value(0);
fclose(f);
return 1;
}
int write_nfs_settings(GeneratorUI *ui)
{
int i;
std::string share;
FILE *f;
Nfsshare *n;
f = fopen(PATH_BASEISO "/etc/nfs", "wb");
if (!f) {
fl_alert("Failed to write nfs configuration.\n");
return 0;
}
/* Write all NFS mountpoints */
for (i = 1; i < ui->nfs_shares->size() - 1; i++) {
ui->nfs_shares->value(i);
n = (Nfsshare*)ui->nfs_shares->mvalue()->user_data();
if (n) {
share = n->server + ":" + n->dir + " ";
share += ui->nfs_shares->mvalue()->label() + std::string("\n");
fputs(share.c_str(), f);
}
}
fclose(f);
ui->nfs_shares->value(0);
update_nfs_tab(ui);
return 1;
}