Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

FtpCfgDlgUnit.cpp 8.3 KB
Newer Older
1 2 3 4 5 6
/* Synchronet Control Panel (GUI Borland C++ Builder Project for Win32) */

/****************************************************************************
 * @format.tab-size 4		(Plain Text/Source Code File Header)			*
 * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
 *																			*
7
 * Copyright Rob Swindell - http://www.synchro.net/copyright.html			*
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
 *																			*
 * 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.					*
 * See the GNU General Public License for more details: gpl.txt or			*
 * http://www.fsf.org/copyleft/gpl.html										*
 *																			*
 * For Synchronet coding style and modification guidelines, see				*
 * http://www.synchro.net/source.html										*
 *																			*
 * Note: If this box doesn't appear square, then you need to fix your tabs.	*
 ****************************************************************************/

//---------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "MainFormUnit.h"
#include "FtpCfgDlgUnit.h"
#include "TextFileEditUnit.h"
29
#include "SoundCfgDlgUnit.h"
30 31 32 33 34 35 36 37 38 39 40 41
#include <stdio.h>			// sprintf()
//---------------------------------------------------------------------
#pragma resource "*.dfm"
TFtpCfgDlg *FtpCfgDlg;
//---------------------------------------------------------------------
__fastcall TFtpCfgDlg::TFtpCfgDlg(TComponent* AOwner)
	: TForm(AOwner)
{
}
//---------------------------------------------------------------------
void __fastcall TFtpCfgDlg::FormShow(TObject *Sender)
{
42
    char str[256];
43

44
    if(MainForm->ftp_startup.interfaces==NULL)
45 46
        NetworkInterfaceEdit->Text="<ANY>";
    else {
47
        strListCombine(MainForm->ftp_startup.interfaces, str, sizeof(str)-1, ",");
48 49
        NetworkInterfaceEdit->Text=AnsiString(str);
    }
deuce's avatar
deuce committed
50
    if(MainForm->ftp_startup.pasv_ip_addr.s_addr==0)
51
        PasvIPv4AddrEdit->Text="<unspecified>";
52 53
    else {
        sprintf(str,"%d.%d.%d.%d"
deuce's avatar
deuce committed
54 55 56 57
            ,(MainForm->ftp_startup.pasv_ip_addr.s_addr>>24)&0xff
            ,(MainForm->ftp_startup.pasv_ip_addr.s_addr>>16)&0xff
            ,(MainForm->ftp_startup.pasv_ip_addr.s_addr>>8)&0xff
            ,MainForm->ftp_startup.pasv_ip_addr.s_addr&0xff
58
        );
59
        PasvIPv4AddrEdit->Text=AnsiString(str);
60 61
    }

62 63
    MaxClientsEdit->Text=AnsiString((int)MainForm->ftp_startup.max_clients);
    MaxInactivityEdit->Text=AnsiString((int)MainForm->ftp_startup.max_inactivity);
64
    QwkTimeoutEdit->Text=AnsiString((int)MainForm->ftp_startup.qwk_timeout);
65 66 67 68
	PortEdit->Text=AnsiString((int)MainForm->ftp_startup.port);
    AutoStartCheckBox->Checked=MainForm->FtpAutoStart;
    LogFileCheckBox->Checked=MainForm->FtpLogFile;

69
    PasvIpLookupCheckBox->Checked=MainForm->ftp_startup.options&FTP_OPT_LOOKUP_PASV_IP;
70 71
	PasvPortLowEdit->Text=AnsiString((int)MainForm->ftp_startup.pasv_port_low);
  	PasvPortHighEdit->Text=AnsiString((int)MainForm->ftp_startup.pasv_port_high);
72
    MaxConConEdit->Text = AnsiString((int)MainForm->ftp_startup.max_concurrent_connections);
73

74 75 76 77
    IndexFileNameEdit->Text=AnsiString(MainForm->ftp_startup.index_file_name);
    CmdLogCheckBox->Checked=MainForm->ftp_startup.options&FTP_OPT_DEBUG_RX;
	DebugTxCheckBox->Checked=MainForm->ftp_startup.options&FTP_OPT_DEBUG_TX;
	DebugDataCheckBox->Checked=MainForm->ftp_startup.options&FTP_OPT_DEBUG_DATA;
78
    AllowBounceCheckBox->Checked=MainForm->ftp_startup.options&FTP_OPT_ALLOW_BOUNCE;
79 80 81 82 83 84 85 86
    AllowQWKCheckBox->Checked
        =MainForm->ftp_startup.options&FTP_OPT_ALLOW_QWK;
    LocalFileSysCheckBox->Checked
        =!(MainForm->ftp_startup.options&FTP_OPT_NO_LOCAL_FSYS);
    HostnameCheckBox->Checked
        =!(MainForm->ftp_startup.options&FTP_OPT_NO_HOST_LOOKUP);
	AutoIndexCheckBox->Checked=MainForm->ftp_startup.options&FTP_OPT_INDEX_FILE;
	AutoIndexCheckBoxClick(Sender);
87
    PasvIpLookupCheckBoxClick(Sender);
88 89
    QwkTimeoutEdit->Enabled = AllowQWKCheckBox->Checked;
    QwkTimeoutLabel->Enabled = AllowQWKCheckBox->Checked;
90

91 92 93 94 95 96 97 98 99
    PageControl->ActivePage=GeneralTabSheet;
}
//---------------------------------------------------------------------------

void __fastcall TFtpCfgDlg::OKBtnClick(TObject *Sender)
{
    char    str[128],*p;
    DWORD   addr;

100 101 102 103
    iniFreeStringList(MainForm->ftp_startup.interfaces);
    MainForm->ftp_startup.interfaces = strListSplitCopy(NULL, NetworkInterfaceEdit->Text.c_str(), ",");

    SAFECOPY(str,PasvIPv4AddrEdit->Text.c_str());
104 105 106 107 108 109 110 111 112 113 114 115 116
    p=str;
    while(*p && *p<=' ') p++;
    if(*p && isdigit(*p)) {
        addr=atoi(p)<<24;
        while(*p && *p!='.') p++;
        if(*p=='.') p++;
        addr|=atoi(p)<<16;
        while(*p && *p!='.') p++;
        if(*p=='.') p++;
        addr|=atoi(p)<<8;
        while(*p && *p!='.') p++;
        if(*p=='.') p++;
        addr|=atoi(p);
deuce's avatar
deuce committed
117
        MainForm->ftp_startup.pasv_ip_addr.s_addr=addr;
118
    } else
deuce's avatar
deuce committed
119
        MainForm->ftp_startup.pasv_ip_addr.s_addr=0;
120

121 122 123 124
    MainForm->ftp_startup.max_clients=MaxClientsEdit->Text.ToIntDef(FTP_DEFAULT_MAX_CLIENTS);
    MainForm->ftp_startup.max_inactivity=MaxInactivityEdit->Text.ToIntDef(FTP_DEFAULT_MAX_INACTIVITY);
    MainForm->ftp_startup.qwk_timeout=QwkTimeoutEdit->Text.ToIntDef(FTP_DEFAULT_QWK_TIMEOUT);
    MainForm->ftp_startup.port=PortEdit->Text.ToIntDef(IPPORT_FTP);
125
    MainForm->ftp_startup.max_concurrent_connections = MaxConConEdit->Text.ToIntDef(0);
126 127 128
    MainForm->FtpAutoStart=AutoStartCheckBox->Checked;
    MainForm->FtpLogFile=LogFileCheckBox->Checked;

129 130 131
    MainForm->ftp_startup.pasv_port_low=PasvPortLowEdit->Text.ToIntDef(IPPORT_RESERVED);
    MainForm->ftp_startup.pasv_port_high=PasvPortHighEdit->Text.ToIntDef(0xffff);

132
    SAFECOPY(MainForm->ftp_startup.index_file_name
133
        ,IndexFileNameEdit->Text.c_str());
134

135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
	if(DebugTxCheckBox->Checked==true)
    	MainForm->ftp_startup.options|=FTP_OPT_DEBUG_TX;
    else
	    MainForm->ftp_startup.options&=~FTP_OPT_DEBUG_TX;
	if(CmdLogCheckBox->Checked==true)
    	MainForm->ftp_startup.options|=FTP_OPT_DEBUG_RX;
    else
	    MainForm->ftp_startup.options&=~FTP_OPT_DEBUG_RX;
	if(DebugDataCheckBox->Checked==true)
    	MainForm->ftp_startup.options|=FTP_OPT_DEBUG_DATA;
    else
	    MainForm->ftp_startup.options&=~FTP_OPT_DEBUG_DATA;
	if(HostnameCheckBox->Checked==false)
    	MainForm->ftp_startup.options|=FTP_OPT_NO_HOST_LOOKUP;
    else
	    MainForm->ftp_startup.options&=~FTP_OPT_NO_HOST_LOOKUP;
	if(AllowQWKCheckBox->Checked==true)
    	MainForm->ftp_startup.options|=FTP_OPT_ALLOW_QWK;
    else
	    MainForm->ftp_startup.options&=~FTP_OPT_ALLOW_QWK;
155 156
	if(AllowBounceCheckBox->Checked==true)
    	MainForm->ftp_startup.options|=FTP_OPT_ALLOW_BOUNCE;
157
    else
158
	    MainForm->ftp_startup.options&=~FTP_OPT_ALLOW_BOUNCE;
159 160 161 162 163 164 165 166
	if(LocalFileSysCheckBox->Checked==false)
    	MainForm->ftp_startup.options|=FTP_OPT_NO_LOCAL_FSYS;
    else
	    MainForm->ftp_startup.options&=~FTP_OPT_NO_LOCAL_FSYS;
	if(AutoIndexCheckBox->Checked==true)
    	MainForm->ftp_startup.options|=FTP_OPT_INDEX_FILE;
    else
	    MainForm->ftp_startup.options&=~FTP_OPT_INDEX_FILE;
167 168 169 170
    if(PasvIpLookupCheckBox->Checked==true)
        MainForm->ftp_startup.options|=FTP_OPT_LOOKUP_PASV_IP;
    else
        MainForm->ftp_startup.options&=~FTP_OPT_LOOKUP_PASV_IP;
171

172
    MainForm->SaveIniSettings(Sender);
173 174 175 176 177 178 179 180 181
}
//---------------------------------------------------------------------------

void __fastcall TFtpCfgDlg::AutoIndexCheckBoxClick(TObject *Sender)
{
    IndexFileNameEdit->Enabled=AutoIndexCheckBox->Checked;
}
//---------------------------------------------------------------------------

182 183
void __fastcall TFtpCfgDlg::PasvIpLookupCheckBoxClick(TObject *Sender)
{
184
    PasvIPv4AddrEdit->Enabled = !PasvIpLookupCheckBox->Checked;
185 186
}
//---------------------------------------------------------------------------
187

188 189 190 191 192 193 194 195

void __fastcall TFtpCfgDlg::AllowQWKCheckBoxClick(TObject *Sender)
{
    QwkTimeoutEdit->Enabled = AllowQWKCheckBox->Checked;
    QwkTimeoutLabel->Enabled = AllowQWKCheckBox->Checked;
}
//---------------------------------------------------------------------------

196 197 198 199 200 201 202 203
void __fastcall TFtpCfgDlg::ConfigureSoundButtonClick(TObject *Sender)
{
    SoundCfgDlg->sound = &MainForm->ftp_startup.sound;
    SoundCfgDlg->Caption = "FTP Server Sound Configuration";
    SoundCfgDlg->ShowModal();
}
//---------------------------------------------------------------------------