13 |
|
configurate(); |
14 |
|
} |
15 |
|
|
16 |
+ |
string Configurator::escape(const string& phrase) |
17 |
+ |
{ |
18 |
+ |
istringstream sin(phrase); |
19 |
+ |
string escaped; |
20 |
+ |
|
21 |
+ |
do |
22 |
+ |
{ |
23 |
+ |
if (sin.peek() == ' ') escaped += '\\'; |
24 |
+ |
escaped += sin.get(); |
25 |
+ |
if (sin.eof()) escaped.erase(escaped.length() - 1); |
26 |
+ |
} |
27 |
+ |
while (sin.good()); |
28 |
+ |
|
29 |
+ |
return escaped; |
30 |
+ |
} |
31 |
+ |
|
32 |
+ |
string Configurator::password(const string& user) |
33 |
+ |
{ |
34 |
+ |
string password; |
35 |
+ |
|
36 |
+ |
for (unsigned index = 0; index < passwd.size(); index++) |
37 |
+ |
{ |
38 |
+ |
switch (passwd[index]) |
39 |
+ |
{ |
40 |
+ |
case file: |
41 |
+ |
{ |
42 |
+ |
string file = config.install + "/conf/private/" + host + "." |
43 |
+ |
+ user; |
44 |
+ |
ifstream fin(file.c_str()); |
45 |
+ |
|
46 |
+ |
if (fin.is_open()) |
47 |
+ |
{ |
48 |
+ |
getline(fin, password); |
49 |
+ |
} |
50 |
+ |
} |
51 |
+ |
break; |
52 |
+ |
case prompt: |
53 |
+ |
{ |
54 |
+ |
string prompt = user + "@" + host + "\'s password:"; |
55 |
+ |
password = getpass(prompt.c_str()); |
56 |
+ |
} |
57 |
+ |
break; |
58 |
+ |
default: |
59 |
+ |
// |
60 |
+ |
break; |
61 |
+ |
} |
62 |
+ |
|
63 |
+ |
if (password == "") |
64 |
+ |
{ |
65 |
+ |
continue; |
66 |
+ |
} |
67 |
+ |
else |
68 |
+ |
{ |
69 |
+ |
break; |
70 |
+ |
} |
71 |
+ |
} |
72 |
+ |
|
73 |
+ |
return password; |
74 |
+ |
} |
75 |
+ |
|
76 |
|
void Configurator::configurate() |
77 |
|
{ |
78 |
|
if (config.hosts.count(host) < 2) |
141 |
|
<< "\", ignored\n"; |
142 |
|
} |
143 |
|
} |
144 |
+ |
|
145 |
+ |
if (passwd.size() == 0) |
146 |
+ |
{ |
147 |
+ |
cerr << program << ": No passwd configuration for host: " << host |
148 |
+ |
<< "\n"; |
149 |
+ |
exit(1); |
150 |
+ |
} |
151 |
+ |
|
152 |
+ |
if (regular.local == "" || regular.remote == "") |
153 |
+ |
{ |
154 |
+ |
cerr << program << ": No * folder configuration for host: " << host |
155 |
+ |
<< "\n"; |
156 |
+ |
exit(1); |
157 |
+ |
} |
158 |
+ |
|
159 |
+ |
if (debug) |
160 |
+ |
{ |
161 |
+ |
cerr << "host = " << host << "\n" |
162 |
+ |
<< "passwd = {\n"; |
163 |
+ |
|
164 |
+ |
for (unsigned index = 0; index < passwd.size(); index++) |
165 |
+ |
{ |
166 |
+ |
cerr << " [" << index << "] = "; |
167 |
+ |
|
168 |
+ |
switch (passwd[index]) |
169 |
+ |
{ |
170 |
+ |
case file: |
171 |
+ |
cerr << "file"; |
172 |
+ |
break; |
173 |
+ |
case prompt: |
174 |
+ |
cerr << "prompt"; |
175 |
+ |
break; |
176 |
+ |
default: |
177 |
+ |
cerr << passwd[index]; |
178 |
+ |
break; |
179 |
+ |
} |
180 |
+ |
|
181 |
+ |
cerr << "\n"; |
182 |
+ |
} |
183 |
+ |
|
184 |
+ |
cerr << "}\n" |
185 |
+ |
<< "regular = {\n" |
186 |
+ |
<< " local = " << regular.local << "\n" |
187 |
+ |
<< " remote = " << regular.remote << "\n" |
188 |
+ |
<< "}\n" |
189 |
+ |
<< "folders = {\n"; |
190 |
+ |
|
191 |
+ |
for (map<string, Folder>::iterator itor = folders.begin(); itor != |
192 |
+ |
folders.end(); itor++) |
193 |
+ |
{ |
194 |
+ |
cerr << " " << itor->first << " = {\n" |
195 |
+ |
<< " local = " << itor->second.local << "\n" |
196 |
+ |
<< " remote = " << itor->second.remote << "\n" |
197 |
+ |
<< " }\n"; |
198 |
+ |
} |
199 |
+ |
|
200 |
+ |
cerr << "}\n"; |
201 |
+ |
} |
202 |
|
} |