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 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621
|
/* GADMIN-PROFTPD - An easy to use GTK+ frontend for the ProFTPD standalone server.
* Copyright (C) 2001 - 2011 Magnus Loef <magnus-swe@telia.com>
*
* 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 3 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 "../config.h"
#include <gtk/gtk.h>
#include "gettext.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "allocate.h"
#include "widgets.h"
#include "functions.h"
#include "commands.h"
#include "standard_conf.h"
#include "populate_gadmin_proftpd.h"
#include "file_chooser.h"
#include "show_info.h"
#include "commented.h"
/* Temporary for option deprecations */
extern char global_version[1024];
void new_tls_module_conf()
{
FILE *fp;
long file_size = 0;
char *line, *new_conf;
gchar *info, *module_conf;
if((fp=fopen(PROFTPD_CONF, "r"))==NULL)
{
info = g_strdup_printf("Error adding new TLS module configuration.\n");
show_info(info);
g_free(info);
return;
}
module_conf = g_strconcat("\n",
"<IfModule mod_tls.c>\n",
"TLSEngine off\n",
"TLSRequired auth+data\n",
"TLSVerifyClient off\n",
"TLSProtocol SSLv23\n",
"TLSLog ", GP_VARDIR, "/log/proftpd_tls.log\n",
"TLSRSACertificateFile ", GP_APPCONFDIR, "/certs/cert.pem\n",
"TLSRSACertificateKeyFile ", GP_APPCONFDIR, "/certs/key.pem\n",
"TLSCACertificateFile ", GP_APPCONFDIR, "/certs/cacert.pem\n",
"TLSRenegotiate required off\n",
"TLSOptions AllowClientRenegotiation\n",
"</IfModule>\n",
NULL);
fseek(fp, 0, SEEK_END);
file_size = ftell(fp);
rewind(fp);
line = allocate(file_size+1);
new_conf = allocate(file_size+16384);
if( file_size > 1 )
while(fgets(line, file_size, fp)!=NULL)
{
if( commented(line) )
continue;
if( cmplowercase(line, "ifmodule")
&& cmplowercase(line, "mod_tls.c")
&& strstr(line, "<") && strstr(line, ">") )
{
while(fgets(line, file_size, fp)!=NULL)
if( cmplowercase(line, "ifmodule")
&& strstr(line, "<") && strstr(line, ">") )
{
strcat(new_conf, module_conf);
break;
}
}
else
strcat(new_conf, line);
}
g_free(module_conf);
free(line);
fclose(fp);
/* Write the new configuration */
if((fp=fopen(PROFTPD_CONF, "w+"))==NULL)
{
info = g_strdup_printf("Error writing new TLS module configuration.\n");
show_info(info);
g_free(info);
g_free(new_conf);
return;
}
fputs(new_conf, fp);
fclose(fp);
free(new_conf);
info = g_strconcat("Successfully added new TLS module configuration.\n\n",
"GAdmin-PRoFTPd now supports explicit/total FTP encryption.\n\n",
"New signed certificates needs to be generated.\n",
"Press the generate button and then turn on secure communications\n\n",
"Clients that supports explicit FTP encryption can be used.\n",
NULL);
show_info(info);
g_free(info);
}
int conf_ok(gchar *file_path)
{
FILE *fp;
long conf_size;
char *line;
int retval = 0;
int good_conf = 0;
if((fp=fopen(file_path, "r"))==NULL)
{
return retval;
}
fseek(fp, 0, SEEK_END);
conf_size = ftell(fp);
rewind(fp);
line = allocate(conf_size+1);
if( conf_size > 1 )
while(fgets(line, conf_size, fp)!=NULL)
{
/* Dont allow excessively long lines */
if( strlen(line) > 500 )
{
fclose(fp);
free(line);
return 0;
}
if( commented(line) )
continue;
/* Finding these options or contexts first
means that the configuration is not ok */
if( cmplowercase(line, "<anonymous") )
break;
if( cmplowercase(line, "<virtual") )
break;
if( cmplowercase(line, "<ifmodule") )
break;
/* We dont support the DefaultRoot directive. */
if( cmplowercase(line, "defaultroot ") )
break;
/* We dont support the UserAlias directive. */
if( cmplowercase(line, "useralias ") )
break;
/* Very good for security so it must exist */
if( cmplowercase(line, "<limit login>") )
good_conf++;
/* We handle "standalone". Refuse to use inetd. */
if( cmplowercase(line, "servertype standalone") )
good_conf++;
if( cmplowercase(line, "transferrate retr") )
good_conf++;
if( cmplowercase(line, "transferrate stor") )
good_conf++;
if( cmplowercase(line, "transferrate stou") )
good_conf++;
if( cmplowercase(line, "transferrate appe") )
good_conf++;
if( cmplowercase(line, "passiveports ") )
good_conf++;
if( cmplowercase(line, "defaulttransfermode ") )
good_conf++;
}
fclose(fp);
free(line);
if( good_conf >= 7 )
retval = 1;
return retval;
}
/* Automated configuration backups for new versions */
void backup_configuration(struct w *widgets)
{
gchar *cmd, *info;
if( ! file_exists(PROFTPD_CONF_BACKUP) && file_exists(PROFTPD_CONF) )
{
cmd = g_strdup_printf("cp %s %s", PROFTPD_CONF, PROFTPD_CONF_BACKUP);
if( ! run_command(cmd) )
{
info = g_strdup_printf(_("Error: Could not backup the current configuration:\n%s\n"), PROFTPD_CONF);
show_info(info);
g_free(info);
}
else
{
info = g_strdup_printf(_("The configuration was backed up here for safety:\n%s\n"), PROFTPD_CONF_BACKUP);
show_info(info);
g_free(info);
}
g_free(cmd);
}
}
/* Backup button in the configuration tab backs up the conf with an added "-gadmin-backup" tag to it */
/* Manual backups are not automatically overwritten then. */
void force_configuration_backup(struct w *widgets)
{
gchar *cmd, *info;
if( file_exists(PROFTPD_CONF) )
{
cmd = g_strdup_printf("cp %s %s-gadmin-backup", PROFTPD_CONF, PROFTPD_CONF_BACKUP);
if( ! run_command(cmd) )
{
info = g_strdup_printf(_("Error: Could not backup the current configuration:\n%s\n"), PROFTPD_CONF);
show_info(info);
g_free(info);
}
else
{
info = g_strdup_printf(_("The configuration was backed up here for safety:\n%s%s\n"), PROFTPD_CONF_BACKUP, "-admin-backup");
show_info(info);
g_free(info);
}
g_free(cmd);
}
}
/* Restore and use another proftpd.conf file */
void restore_configuration(struct w *widgets)
{
gchar *info=NULL, *cmd=NULL, *path=NULL;
path = get_dialog_path_selection("FILE", GP_APPCONFDIR, "None");
/* conf_ok() also checks that the configuration lines have valid length */
if( path!=NULL && strlen(path) > 8 && conf_ok(path) )
{
cmd = g_strdup_printf("cp %s %s", path, PROFTPD_CONF);
if( ! run_command(cmd) )
{
info = g_strdup_printf(_("The configuration file could not be restored.\n"));
show_info(info);
g_free(info);
}
g_free(cmd);
g_free(path);
path = NULL;
}
else
{
info = g_strdup_printf(_("The configuration file could not be restored.\n"));
show_info(info);
g_free(info);
}
if( path!=NULL )
g_free(path);
populate_gadmin_proftpd(widgets);
}
/* Adds a default/standard configuration and also adds any ModulePath and
LoadModule statements from the old conf if any, for included DSO's. */
void add_standard_conf(struct w *widgets)
{
FILE *fp;
char *includes = NULL;
gchar *info, *config;
/* First backup/copy the old configuration */
backup_configuration(widgets);
/* Get ModulePath and LoadModule statements from included configurations. */
includes = get_dynamic_module_statements();
if((fp=fopen(PROFTPD_CONF, "w+"))==NULL)
{
info = g_strdup_printf(_("Cant write a new proftpd.conf here:\n%s\n"), PROFTPD_CONF);
show_info(info);
g_free(info);
if( includes!=NULL )
free(includes);
return;
}
/* Add any Include lines we found at the top of the conf. */
if( includes!=NULL )
{
fputs(includes, fp);
free(includes);
fputs("\n", fp);
}
/* Note: inetd functions would limit the servers usability */
config = g_strconcat(
"ServerType standalone\n",
"DefaultServer on\n",
"Umask 022\n",
"ServerName \"0.0.0.0\"\n",
"ServerIdent on \"My FTP Server\"\n",
"ServerAdmin email@example.org\n",
"IdentLookups off\n",
"UseReverseDNS off\n",
"Port 21\n",
"PassivePorts 49152 65534\n",
"#MasqueradeAddress None\n",
"TimesGMT off\n",
"MaxInstances 30\n",
"MaxLoginAttempts 3\n",
"TimeoutLogin 300\n",
"TimeoutNoTransfer 120\n",
"TimeoutIdle 120\n",
"DisplayLogin ", WELCOME_MESSAGE, "\n",
"DisplayChdir .message\n"
"User ", SERVER_USER, "\n",
"Group ", SERVER_GROUP, "\n",
"DirFakeUser off ", SERVER_USER, "\n",
"DirFakeGroup off ", SERVER_GROUP, "\n",
"DefaultTransferMode binary\n",
"AllowForeignAddress off\n",
"AllowRetrieveRestart on\n",
"AllowStoreRestart on\n",
"DeleteAbortedStores off\n",
"TransferRate RETR 220\n",
"TransferRate STOR 250\n",
"TransferRate STOU 250\n",
"TransferRate APPE 250\n",
"SystemLog ", GP_VARDIR, "/log/secure\n",
"RequireValidShell off\n\n",
#ifdef CAN_BE_ANNOYING_FOR_USERS
"<IfModule mod_delay.c>\n"
"DelayEngine on\n"
"</IfModule>\n\n"
#endif
"<IfModule mod_tls.c>\n",
"TLSEngine off\n",
"TLSRequired off\n",
"TLSVerifyClient off\n",
"TLSProtocol SSLv23\n",
"TLSLog ", GP_VARDIR, "/log/proftpd_tls.log\n",
"TLSRSACertificateFile ", GP_APPCONFDIR, "/certs/cert.pem\n",
"TLSRSACertificateKeyFile ", GP_APPCONFDIR, "/certs/key.pem\n",
"TLSCACertificateFile ", GP_APPCONFDIR, "/certs/cacert.pem\n",
"TLSRenegotiate required off\n",
"TLSOptions AllowClientRenegotiation\n",
"</IfModule>\n\n",
"<IfModule mod_ratio.c>\n",
"Ratios off\n",
"SaveRatios off\n",
"RatioFile \"/restricted/proftpd_ratios\"\n",
"RatioTempFile \"/restricted/proftpd_ratios_temp\"\n",
"CwdRatioMsg \"Please upload first!\"\n",
"FileRatioErrMsg \"FileRatio limit exceeded, upload something first...\"\n",
"ByteRatioErrMsg \"ByteRatio limit exceeded, upload something first...\"\n",
"LeechRatioMsg \"Your ratio is unlimited.\"\n",
"</IfModule>\n\n",
"<Limit LOGIN>\n",
" DenyALL\n",
"</Limit>\n\n",
NULL);
fputs(config, fp);
fclose(fp);
g_free(config);
if( GTK_IS_WINDOW(widgets->default_conf_question_window) )
gtk_widget_destroy(widgets->default_conf_question_window);
populate_gadmin_proftpd(widgets);
}
void dont_add_standard_conf(struct w *widgets)
{
if( GTK_IS_WINDOW(widgets->default_conf_question_window) )
gtk_widget_destroy(widgets->default_conf_question_window);
populate_gadmin_proftpd(widgets);
}
void create_standard_conf_question(struct w *widgets)
{
FILE *fp;
long file_size = 0;
int found_conf_question = 0;
char *conf, *line;
gchar *cmd, *info, *utf8, *settings_conf;
GtkWidget *vbox18, *label182;
GtkWidget *scrolledwindow;
GtkWidget *default_question_textview;
GtkWidget *hbuttonbox11;
GtkWidget *yes_default_question_button;
GtkWidget *alignment44, *hbox98;
GtkWidget *image44, *label184;
GtkWidget *no_default_question_button;
GtkWidget *alignment45, *hbox99;
GtkWidget *image45, *label185;
widgets->default_conf_question_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_set_size_request(widgets->default_conf_question_window, -1, -1);
gtk_window_set_title(GTK_WINDOW(widgets->default_conf_question_window), _("GADMIN-PROFTPD Question"));
gtk_window_set_position(GTK_WINDOW(widgets->default_conf_question_window), GTK_WIN_POS_CENTER);
vbox18 = gtk_vbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(widgets->default_conf_question_window), vbox18);
label182 = gtk_label_new ("");
gtk_box_pack_start(GTK_BOX(vbox18), label182, FALSE, FALSE, 0);
gtk_widget_set_size_request(label182, -1, 20);
gtk_label_set_justify(GTK_LABEL(label182), GTK_JUSTIFY_LEFT);
scrolledwindow = gtk_scrolled_window_new(NULL, NULL);
gtk_box_pack_start(GTK_BOX(vbox18), scrolledwindow, TRUE, TRUE, 0);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwindow), GTK_POLICY_NEVER, GTK_POLICY_NEVER);
default_question_textview = gtk_text_view_new();
gtk_container_add(GTK_CONTAINER(scrolledwindow), default_question_textview);
gtk_text_view_set_editable(GTK_TEXT_VIEW(default_question_textview), FALSE);
gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(default_question_textview), FALSE);
gtk_text_view_set_pixels_above_lines(GTK_TEXT_VIEW(default_question_textview), 3);
gtk_text_view_set_left_margin(GTK_TEXT_VIEW(default_question_textview), 30);
gtk_text_view_set_right_margin(GTK_TEXT_VIEW(default_question_textview), 30);
info = g_strconcat("\n\n",
_("GADMIN-PROFTPD could not find the proftpd configuration\n"),
_("or you are using a basic configuration that doesnt have\n"),
_("all the features that this program requires.\n\n\n"),
_("Do you want to overwrite your current proftpd configuration\n"),
_("with a suitable standard configuration for gadmin-proftpd ?\n\n"),
_("\t\t\t(If you don\'t know then press yes)\n"),
NULL);
utf8 = g_locale_to_utf8(info, strlen(info), NULL, NULL, NULL);
gtk_text_buffer_set_text(gtk_text_view_get_buffer(GTK_TEXT_VIEW (default_question_textview)), utf8, -1);
if( info!=NULL )
g_free(info);
if( utf8!=NULL )
g_free(utf8);
hbuttonbox11 = gtk_hbutton_box_new();
gtk_box_pack_start(GTK_BOX(vbox18), hbuttonbox11, FALSE, FALSE, 0);
gtk_widget_set_size_request(hbuttonbox11, -1, 40);
gtk_button_box_set_layout(GTK_BUTTON_BOX(hbuttonbox11), GTK_BUTTONBOX_SPREAD);
yes_default_question_button = gtk_button_new();
gtk_container_add(GTK_CONTAINER(hbuttonbox11), yes_default_question_button);
GTK_WIDGET_SET_FLAGS(yes_default_question_button, GTK_CAN_DEFAULT);
alignment44 = gtk_alignment_new(0.5, 0.5, 0, 0);
gtk_container_add(GTK_CONTAINER(yes_default_question_button), alignment44);
hbox98 = gtk_hbox_new(FALSE, 2);
gtk_container_add(GTK_CONTAINER(alignment44), hbox98);
image44 = gtk_image_new_from_stock("gtk-yes", GTK_ICON_SIZE_BUTTON);
gtk_box_pack_start(GTK_BOX(hbox98), image44, FALSE, FALSE, 0);
label184 = gtk_label_new_with_mnemonic(_("Yes"));
gtk_box_pack_start(GTK_BOX(hbox98), label184, FALSE, FALSE, 0);
gtk_label_set_justify(GTK_LABEL(label184), GTK_JUSTIFY_LEFT);
no_default_question_button = gtk_button_new();
gtk_container_add(GTK_CONTAINER(hbuttonbox11), no_default_question_button);
GTK_WIDGET_SET_FLAGS(no_default_question_button, GTK_CAN_DEFAULT);
alignment45 = gtk_alignment_new(0.5, 0.5, 0, 0);
gtk_container_add(GTK_CONTAINER(no_default_question_button), alignment45);
hbox99 = gtk_hbox_new(FALSE, 2);
gtk_container_add(GTK_CONTAINER(alignment45), hbox99);
image45 = gtk_image_new_from_stock("gtk-no", GTK_ICON_SIZE_BUTTON);
gtk_box_pack_start(GTK_BOX(hbox99), image45, FALSE, FALSE, 0);
label185 = gtk_label_new_with_mnemonic(_("No"));
gtk_box_pack_start(GTK_BOX(hbox99), label185, FALSE, FALSE, 0);
gtk_label_set_justify(GTK_LABEL(label185), GTK_JUSTIFY_LEFT);
g_signal_connect_swapped(G_OBJECT(yes_default_question_button), "clicked",
G_CALLBACK(add_standard_conf), widgets);
g_signal_connect_swapped(G_OBJECT(no_default_question_button), "clicked",
G_CALLBACK(dont_add_standard_conf), widgets);
gtk_widget_show_all(widgets->default_conf_question_window);
/* Create gadmin-proftpds settings directory if it doesnt exist. */
if( ! file_exists(GP_APPCONFDIR) )
{
cmd = g_strdup_printf("mkdir -p %s", GP_APPCONFDIR);
if( ! run_command(cmd) )
{
info = g_strdup_printf(_("Error: cant create the settings directory here:\n%s\n"), GP_APPCONFDIR);
show_info(info);
g_free(info);
g_free(cmd);
return;
}
g_free(cmd);
}
settings_conf = g_strdup_printf("%s/settings.conf", GP_APPCONFDIR);
/* The settings file doesnt exist, create and write the setting to it */
if( ! file_exists(settings_conf) )
{
if((fp=fopen(settings_conf, "w+"))==NULL)
{
info = g_strdup_printf(_("Error: cant write the settings file here:\n%s\n"), settings_conf);
show_info(info);
g_free(info);
return;
}
fputs("show_conf_question: false\n", fp);
fclose(fp);
g_free(settings_conf);
return;
}
/* Gather old values and re/write 'show_conf_question: false' to gadmin-proftpds settings */
if((fp=fopen(settings_conf, "r"))==NULL)
{
info = g_strdup_printf(_("Error: cant write the settings file here:\n%s\n"), settings_conf);
show_info(info);
g_free(info);
g_free(settings_conf);
return;
}
fseek(fp, 0, SEEK_END);
file_size = ftell(fp);
rewind(fp);
line = allocate(file_size+1);
conf = allocate(file_size+1024);
if( file_size > 1 )
while(fgets(line, file_size, fp)!=NULL)
{
if( strlen(line) > 5 )
{
if( strstr(line, "show_conf_question:") )
{
found_conf_question = 1;
strcat(conf, "show_conf_question: false\n");
break;
}
else
strcat(conf, line);
}
}
fclose(fp);
free(line);
/* If theres no 'show_conf_question: false' line, add one */
if( ! found_conf_question )
strcat(conf, "show_conf_question: false\n");
/* Write the altered conf */
if((fp=fopen(settings_conf, "w+"))==NULL)
{
info = g_strdup_printf(_("Error: cant write the settings file here:\n%s\n"), settings_conf);
show_info(info);
g_free(info);
free(conf);
return;
}
fputs(conf, fp);
fclose(fp);
free(conf);
g_free(settings_conf);
}
|