-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm1.cs
More file actions
205 lines (174 loc) · 9.54 KB
/
Form1.cs
File metadata and controls
205 lines (174 loc) · 9.54 KB
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
using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ProjectInstaller
{
public partial class Form1 : DevExpress.XtraEditors.XtraForm
{
private enum AccessType { LanOnly, WanAccess }
private enum RemovalType { FullConfig, UserOnly }
public Form1()
{
InitializeComponent();
this.Text = "SQL Server Hızlı Kurulum Aracı";
}
private async void btnLanOnly_Click(object sender, EventArgs e)
{
await StartConfiguration(AccessType.LanOnly);
}
private async void btnWanAccess_Click(object sender, EventArgs e)
{
await StartConfiguration(AccessType.WanAccess);
}
private void btnRemoveConfig_Click(object sender, EventArgs e)
{
var confirmation = XtraMessageBox.Show(
"Bu işlem, seçilecek kullanıcıyı ve ilgili SQL Server ağ yapılandırmasını (TCP/IP, Güvenlik Duvarı) kalıcı olarak kaldıracaktır.\n\nDevam etmek istediğinizden emin misiniz?",
"Yapılandırmayı Kaldırma Onayı", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (confirmation == DialogResult.Yes)
{
StartRemovalProcess(RemovalType.FullConfig);
}
}
private void btnRemoveUserOnly_Click(object sender, EventArgs e)
{
var confirmation = XtraMessageBox.Show(
"Bu işlem, seçilecek kullanıcıyı ve oturumunu SQL Server'dan kalıcı olarak silecektir. Ağ ayarları etkilenmeyecektir.\n\nDevam etmek istediğinizden emin misiniz?",
"Kullanıcı Silme Onayı", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (confirmation == DialogResult.Yes)
{
StartRemovalProcess(RemovalType.UserOnly);
}
}
private async Task StartConfiguration(AccessType accessType)
{
memoLog.Text = "";
Log("Yapılandırma işlemi başlatıldı...");
using (var userForm = new CreateUserForm(FormMode.Create))
{
if (userForm.ShowDialog() == DialogResult.OK)
{
this.Cursor = Cursors.WaitCursor;
string publicIp = "N/A";
string localIp = "N/A";
try
{
Log("Yerel IP adresi alınıyor...");
localIp = SqlConfigurationHelper.GetLocalIpAddress();
Log($"Yerel IP Adresiniz Bulundu: {localIp}");
if (accessType == AccessType.WanAccess)
{
Log("Genel (Public) IP adresi alınıyor...");
publicIp = await SqlConfigurationHelper.GetPublicIpAddressAsync();
Log($"Genel IP Adresiniz Bulundu: {publicIp}");
}
SqlConfigurationHelper.SetMixedModeAuthentication(userForm.SelectedInstance, Log);
SqlConfigurationHelper.CreateSqlUser(userForm.SelectedInstance, userForm.SelectedDatabase, userForm.Username, userForm.Password);
Log($"'{userForm.Username}' kullanıcısı başarıyla oluşturuldu.");
SqlConfigurationHelper.ConfigureTcpIpAndRestartService(userForm.SelectedInstance, Log);
Log("Güvenlik duvarı kuralları oluşturuluyor...");
SqlConfigurationHelper.OpenFirewallPort("SQL Server (TCP-1433)", 1433, Log);
SqlConfigurationHelper.OpenFirewallPort("SQL Server Browser (UDP-1434)", 1434, Log, "UDP");
Log("\n>>> BİLGİSAYAR AYARLARI BAŞARIYLA TAMAMLANDI! <<<");
Log("\n--- Bağlantı Bilgileri ---");
Log($"Yerel IP Adresiniz: {localIp}");
if (accessType == AccessType.WanAccess) Log($"Genel (Public) IP Adresiniz: {publicIp}");
Log($"Veritabanı: {userForm.SelectedDatabase}");
Log($"Kullanıcı Adı: {userForm.Username}");
Log($"Şifre: {userForm.Password}");
Log("------------------------------------");
Log("\n--- NASIL BAĞLANILIR? ---");
Log("1) YEREL AĞDAN (LAN) BAĞLANTI İÇİN (Aynı Wi-Fi/Kablolu Ağ):");
memoLog.AppendText($" Data Source={localIp},1433;Initial Catalog={userForm.SelectedDatabase};User ID={userForm.Username};Password={userForm.Password};TrustServerCertificate=True;\n");
if (accessType == AccessType.WanAccess)
{
memoLog.AppendText(Environment.NewLine);
Log("2) İNTERNET ÜZERİNDEN (WAN) BAĞLANTI İÇİN:");
Log(" ADIM 1: Modeminizden 'Port Yönlendirme' (Port Forwarding) yapmalısınız.");
Log($" Kural: Dış TCP Port 1433 -> {localIp} adresine yönlendirilecek.");
Log(" ADIM 2: Aşağıdaki bağlantı dizesini kullanın:");
memoLog.AppendText($" Data Source={publicIp},1433;Initial Catalog={userForm.SelectedDatabase};User ID={userForm.Username};Password={userForm.Password};TrustServerCertificate=True;\n\n");
Log(" UYARI: İnternet IP'niz zamanla değişebilir. Kalıcı çözüm için 'Dynamic DNS' servislerini araştırın.");
}
XtraMessageBox.Show("Yapılandırma başarıyla tamamlandı!", "Başarılı", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
Log($"\n!!! BİR HATA OLUŞTU: {ex.Message}");
XtraMessageBox.Show($"Yapılandırma sırasında kritik bir hata oluştu:\n\n{ex.Message}", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
this.Cursor = Cursors.Default;
}
}
}
}
private void StartRemovalProcess(RemovalType removalType)
{
memoLog.Text = "";
Log("Kaldırma işlemi başlatıldı...");
FormMode formMode = removalType == RemovalType.FullConfig ? FormMode.RemoveConfig : FormMode.RemoveUserOnly;
using (var userForm = new CreateUserForm(formMode))
{
if (removalType == RemovalType.FullConfig)
{
userForm.Text = "Ağ Yapılandırması Kaldırılacak Sunucuyu Seçin";
}
if (userForm.ShowDialog() == DialogResult.OK)
{
this.Cursor = Cursors.WaitCursor;
try
{
string instance = userForm.SelectedInstance;
if (removalType == RemovalType.FullConfig)
{
Log("Güvenlik duvarı kuralları kaldırılıyor...");
SqlConfigurationHelper.RemoveFirewallRule("SQL Server (TCP-1433)", Log);
SqlConfigurationHelper.RemoveFirewallRule("SQL Server Browser (UDP-1434)", Log);
Log("SQL Server kimlik doğrulama modu geri alınıyor...");
SqlConfigurationHelper.SetWindowsAuthOnlyMode(instance, Log);
Log("SQL Server ağ ayarları varsayılana döndürülüyor...");
SqlConfigurationHelper.RevertTcpIpAndRestartService(instance, Log);
Log("Tüm sunucu yapılandırması başarıyla varsayılan haline getirildi.");
}
if (removalType == RemovalType.UserOnly)
{
string db = userForm.SelectedDatabase;
string user = userForm.Username;
Log($"'{user}' kullanıcısı ve oturumu siliniyor...");
SqlConfigurationHelper.DropSqlUserAndLogin(instance, db, user);
Log("Kullanıcı ve oturum başarıyla silindi.");
}
Log("\n>>> SEÇİLEN İŞLEM BAŞARIYLA TAMAMLANDI! <<<");
XtraMessageBox.Show("Seçilen işlem başarıyla tamamlandı!", "Başarılı", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
Log($"\n!!! BİR HATA OLUŞTU: {ex.Message}");
XtraMessageBox.Show($"Kaldırma sırasında kritik bir hata oluştu:\n\n{ex.Message}", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
this.Cursor = Cursors.Default;
}
}
else
{
Log("Kaldırma işlemi iptal edildi.");
}
}
}
private void Log(string message)
{
memoLog.AppendText($"[{DateTime.Now:HH:mm:ss}] {message}{Environment.NewLine}");
}
}
}