-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvhost3.py
executable file
·202 lines (148 loc) · 4.57 KB
/
vhost3.py
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
#!/usr/bin/env python
#-*-coding:utf-8-*-
from sys import exit, argv
from os import system, environ, path
from vhost3_conf import *
from vhost3_lib.apache import Apache
from vhost3_lib.hosts import Hosts
from vhost3_lib.mysql import MySQL
from vhost3_lib.turler.php import PHP
from vhost3_lib.turler.phpmyadmin import PHPMyAdmin
from vhost3_lib.turler.symfony import Symfony
from vhost3_lib.turler.django import Django
class Program (object):
domain = None
uzanti = VARSAYILAN_UZANTI
sifre = ROOT_SIFRE
hata_ayiklama = VARSAYILAN_HATA_AYIKLAMA
def __init__(self):
self._kontrol()
self._argv()
self._kullanici()
self._platformlar()
self._islemler()
def _islemler(self):
eval('self._' + self.islem + '()')
self._yenile()
def _sil(self):
self._uzanti()
hosts = Hosts(self.domain)
hosts.sil()
apache = Apache(self.domain)
apache.sil()
self.platform.sil()
mysql = MySQL(self.kullanici)
mysql.yoket()
def _ekle(self):
self._kullanici_varmi_kontrol()
self._uzanti()
self._sifre()
self._hata_ayiklama()
hosts = Hosts(self.domain)
hosts.ekle()
self.platform.yarat(self.domain, self.sifre, self.hata_ayiklama)
apache = Apache(self.domain)
apache.ekle(self.platform.apache, self.kullanici)
mysql = MySQL(self.kullanici)
mysql.yarat(self.sifre)
system('chmod -R 777 /var/www/' + self.kullanici)
system('chown -R ' + VARSAYILAN_KULLANICI + ':www-data /var/www/' + self.kullanici)
def _uzanti(self):
uzanti = raw_input('Uzantı: ')
if uzanti:
self.uzanti = uzanti
self.domain = self.kullanici + '.' + self.uzanti
def _yonet(self):
komut = raw_input('Komut: ')
if not komut:
print '\033[1m\033[91mHATA:\033[0m Lüften bir komut giriniz'
exit()
self.platform.yonet(komut)
def _sifre(self):
sifre = raw_input('Şifre: ')
if sifre:
self.sifre = sifre
def _hata_ayiklama(self):
if raw_input('Hata Ayıklama Açılsın mı? (E/H): ').lower() == 'h':
self.hata_ayiklama = False
def _yenile(self):
apache = Apache(self.domain)
apache.yenile()
system('chmod 755 /var/www/phpmyadmin/public_html/config.inc.php')
system('service nscd restart')
exit()
def _kur(self):
self.kullanici = 'phpmyadmin'
if path.isdir('/var/www/' + self.kullanici):
system('rm -Rf /var/www/phpmyadmin')
self.domain = self.kullanici + '.' + self.uzanti
hosts = Hosts(self.domain)
hosts.ekle()
mysql = MySQL(self.kullanici)
mysql.yarat(ROOT_SIFRE)
platform = PHPMyAdmin()
platform.kur()
apache = Apache(self.domain)
apache.ekle(platform.apache, self.kullanici)
system('chmod -R 777 /var/www/' + self.kullanici)
system('chown -R ' + VARSAYILAN_KULLANICI + ':www-data /var/www/' + self.kullanici)
self._yenile()
def _pasif(self):
self._uzanti()
apache = Apache(self.domain)
apache.pasif()
def _aktif(self):
self._uzanti()
apache = Apache(self.domain)
apache.aktif()
def _kontrol(self):
if 'SUDO_UID' in environ.keys():
if len(argv) == 2:
if argv[1] == 'yenile':
self._yenile()
if argv[1] == 'kur':
self._kur()
elif argv[1] == '--versiyon' or argv[1] == '-v':
print VERSIYON
exit()
if len(argv) < 3:
print '\033[1m\033[91mHATA:\033[0m Lüften programı bir komut ile çalıştırın: "sudo vhost3 <platform> <islem>"'
exit()
else:
print '\033[1m\033[91mHATA:\033[0m Yönetici girişi yapmak gerek. Lüften programı "sudo vhost3 <platform> <islem>" komutu ile çalıştırın'
exit()
def _argv(self):
self._platform = argv[1]
self.islem = argv[2]
self._argv_kontrol()
def _argv_kontrol(self):
if self._platform not in PLATFORMLAR:
print '\033[1m\033[91mHATA:\033[0m Lütfen geçerli platform giriniz'
print 'Geçerli platformlar: ' + ', '.join(PLATFORMLAR)
exit()
if self.islem not in ISLEMLER:
print '\033[1m\033[91mHATA:\033[0m Lütfen geçerli işlem giriniz'
print 'Geçerli işlemler: ' + ', '.join(ISLEMLER)
exit()
def _kullanici(self):
self.kullanici = raw_input('Kullanıcı Adı: ')
self._kullanici_kontrol()
def _kullanici_kontrol(self):
if not self.kullanici:
print '\033[1m\033[91mHATA:\033[0m Kullanıcı Adı olmadan olmaz'
exit()
def _kullanici_varmi_kontrol (self):
if path.isdir('/var/www/' + self.kullanici):
print '\033[1m\033[91mHATA:\033[0m Bu adres daha önce kullanılmış'
exit()
def _platformlar(self):
if self._platform == 'django':
self.platform = Django(self.kullanici)
elif self._platform == 'php':
self.platform = PHP(self.kullanici)
elif self._platform == 'symfony':
self.platform = Symfony(self.kullanici)
def main():
Program()
if __name__ == '__main__':
main()