-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcccam2oscam.py
278 lines (234 loc) · 10.7 KB
/
cccam2oscam.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
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
import datetime
import os
import sys
from PyQt5.QtGui import QIcon, QIntValidator, QPalette, QColor
from PyQt5.QtWidgets import (QApplication, QWidget, QVBoxLayout, QLabel, QPushButton,
QTextEdit, QFileDialog, QHBoxLayout, QDialog, QMessageBox,
QScrollArea, QComboBox, QLineEdit, QStyle, QStyleFactory)
from PyQt5.QtCore import Qt
from ftp_connection import *
class MainWindow(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("CCcam2OSCam Converter by mapi68")
script_dir = os.path.dirname(os.path.abspath(__file__))
icon_path = os.path.join(script_dir, "icon.ico")
self.setWindowIcon(QIcon(icon_path))
self.resize(700, 700)
self.setupUI()
self.setStyle(QStyleFactory.create('Fusion'))
self.setStyleSheet("""
QWidget {
background-color: #2b2b2b;
color: #ffffff;
}
QPushButton {
background-color: #4a4a4a;
border: 1px solid #646464;
border-radius: 5px;
padding: 5px;
min-height: 30px;
}
QPushButton:hover {
background-color: #5a5a5a;
}
QTextEdit, QLineEdit, QComboBox {
background-color: #3a3a3a;
border: 1px solid #646464;
border-radius: 3px;
padding: 2px;
}
QLabel {
color: #d4d4d4;
}
""")
def setupUI(self):
layout = QVBoxLayout(self)
self.textEdit = QTextEdit("")
layout.addWidget(self.textEdit)
fileButton = QPushButton("Select CCcam.cfg")
fileButton.clicked.connect(self.openFile)
layout.addWidget(fileButton)
filterLayout = QHBoxLayout()
showLinesButton = QPushButton("Show only C-lines and N-lines")
showLinesButton.clicked.connect(self.filterLines)
filterLayout.addWidget(showLinesButton)
layout.addLayout(filterLayout)
inactivityLayout = QHBoxLayout()
inactivityLabel1 = QLabel("Inactivity timeout C-lines (seconds):")
self.inactivityEdit1 = QLineEdit()
self.inactivityEdit1.setValidator(QIntValidator(-1, 9999))
self.inactivityEdit1.setText("600")
self.inactivityEdit1.setFixedWidth(50)
inactivityLayout.addWidget(inactivityLabel1)
inactivityLayout.addWidget(self.inactivityEdit1)
inactivityLabel2 = QLabel("Inactivity timeout N-lines (seconds):")
self.inactivityEdit2 = QLineEdit()
self.inactivityEdit2.setValidator(QIntValidator(-1, 9999))
self.inactivityEdit2.setText("-1")
self.inactivityEdit2.setFixedWidth(50)
inactivityLayout.addWidget(inactivityLabel2)
inactivityLayout.addWidget(self.inactivityEdit2)
layout.addLayout(inactivityLayout)
groupLayout = QHBoxLayout()
groupLabel1 = QLabel("C-lines group (1-64):")
self.groupComboBox1 = QComboBox()
self.groupComboBox1.addItems([str(i) for i in range(1, 65)])
self.groupComboBox1.setCurrentText("1")
groupLayout.addWidget(groupLabel1)
groupLayout.addWidget(self.groupComboBox1)
groupLabel2 = QLabel("N-lines group (1-64):")
self.groupComboBox2 = QComboBox()
self.groupComboBox2.addItems([str(i) for i in range(1, 65)])
self.groupComboBox2.setCurrentText("1")
groupLayout.addWidget(groupLabel2)
groupLayout.addWidget(self.groupComboBox2)
layout.addLayout(groupLayout)
convertButton = QPushButton("Convert to oscam.server")
convertButton.clicked.connect(self.convert)
layout.addWidget(convertButton)
viewButton = QPushButton("View oscam.server")
viewButton.clicked.connect(self.viewContent)
layout.addWidget(viewButton)
ftpButton = QPushButton("FTP Connection Enigma2")
ftpButton.clicked.connect(self.openWindowFTP)
layout.addWidget(ftpButton)
helpButton = QPushButton("Help")
helpButton.clicked.connect(self.showHelp)
layout.addWidget(helpButton)
def openFile(self):
options = QFileDialog.Options()
options |= QFileDialog.ReadOnly
fileName, _ = QFileDialog.getOpenFileName(
self, "Select CCcam.cfg", "", "File CCcam.cfg (*.cfg)", options=options
)
if fileName:
with open(fileName, "r", encoding="utf-8") as file:
cccam_cfg = file.read()
self.textEdit.setText(cccam_cfg)
self.filterLines()
def filterLines(self):
cccam_cfg = self.textEdit.toPlainText().splitlines()
filtered_lines = [line for line in cccam_cfg if line.startswith(("C:", "N:"))]
self.textEdit.setText("\n".join(filtered_lines))
def convert(self):
cccam_cfg = self.textEdit.toPlainText().splitlines()
output = self.generate_header()
for line in cccam_cfg:
if line.strip():
config = self.process_line(line)
if config:
output += config
if output:
self.save_oscam_server(output)
def generate_header(self):
return f"# Created with CCcam2OSCam Converter\n\n\n[reader]\nlabel\t\t= DELETE ME\nprotocol\t\t= cccam\ndevice\t\t= dummy.com,8888\n"
def process_line(self, line):
parts = line.split()
if len(parts) < 5:
QMessageBox.warning(self, "Format Error", f"Line is incomplete: {line}")
return None
protocol, server, port, user, password = parts[:5]
if protocol == "N:":
return self.process_n_line(parts)
elif protocol == "C:":
return self.process_c_line(parts)
else:
return None
def process_n_line(self, parts):
server, port, user, password = parts[1:5]
key = "".join(parts[5:20]).replace(" ", "")
ident = ""
caid = ""
if "#" in key:
ident = parts[20].replace(" ", "")
caid = ident.split(":")[0]
key = key.replace("#", "")
config = f"\n[reader]\n"
config += f"label\t\t= {user}@{server}:{port} {ident}\n"
config += f"description\t\t= {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n"
config += f"protocol\t\t= newcamd\n"
config += f"device\t\t= {server},{port}\n"
config += f"key\t\t= {key}\n"
config += f"user\t\t= {user}\n"
config += f"password\t\t= {password}\n"
config += f"inactivitytimeout\t\t= {self.inactivityEdit2.text()}\n"
config += f"disableserverfilter\t= 1\n"
config += f"connectoninit\t\t= 1\n"
config += f"caid\t\t= {caid}\n"
config += f"ident\t\t= {ident}\n"
config += f"group\t\t= {self.groupComboBox2.currentText()}\n"
config += f"audisabled\t\t= 1\n"
return config
def process_c_line(self, parts):
server, port, user, password = parts[1:5]
config = f"\n[reader]\n"
config += f"label\t\t= {user}@{server}:{port}\n"
config += f"description\t\t= {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n"
config += f"protocol\t\t= cccam\n"
config += f"device\t\t= {server},{port}\n"
config += f"user\t\t= {user}\n"
config += f"password\t\t= {password}\n"
config += f"inactivitytimeout\t\t= {self.inactivityEdit1.text()}\n"
config += f"group\t\t= {self.groupComboBox1.currentText()}\n"
config += f"cccversion\t\t= 2.3.2\n"
config += f"audisabled\t\t= 1\n"
return config
def save_oscam_server(self, output):
defaultFileName = "oscam.server"
fileName, _ = QFileDialog.getSaveFileName(
self, "Save oscam.server file", defaultFileName, "File oscam.server (*.server)"
)
if fileName:
output = self.validateOscamServer(output)
with open(fileName, "w", encoding="utf-8") as file:
file.write(output)
QMessageBox.information(self, "Success", f"File saved successfully: {fileName}")
def validateOscamServer(self, content):
lines = content.splitlines()
return "\n".join(line.strip() for line in lines if not line.strip().endswith("="))
def viewContent(self):
executable_dir = getattr(sys, '_MEIPASS', os.path.dirname(sys.argv[0]))
file_paths = [
os.path.join(executable_dir, "oscam.server"),
"oscam.server"
]
found_file = next((path for path in file_paths if os.path.exists(path)), None)
if found_file:
with open(found_file, "r", encoding="utf-8") as file:
content = file.read()
if content:
self.showContentDialog(content)
else:
QMessageBox.information(self, "Information", "oscam.server does not exist.")
def showContentDialog(self, content):
dialog = QDialog(self)
dialog.setWindowTitle("View oscam.server")
dialog.resize(500, 800)
dialog.move(self.x() + self.width() + 10, self.y())
layout = QVBoxLayout(dialog)
scrollArea = QScrollArea(dialog)
scrollArea.setWidgetResizable(True)
contentLabel = QLabel(content)
contentLabel.setTextInteractionFlags(Qt.TextSelectableByMouse)
scrollArea.setWidget(contentLabel)
layout.addWidget(scrollArea)
dialog.setStyleSheet(self.styleSheet())
dialog.exec()
def openWindowFTP(self):
self.finestraFTP = FTPConnectionWindow()
self.finestraFTP.show()
def showHelp(self):
QMessageBox.information(self, "Help", "<html><body style='text-align: center;'><p><h2>Select CCcam.cfg or paste from clipboard<br></p>"
"<p><h2>Supported lines:<br>C-lines<br>Normal N-lines<br>Extended N-lines<br></p>"
"<p><h3>C-line example:</h3><i>C: host_name_ip port username password</i></p>"
"<p><h3>Normal N-line example:</h3><i>N: host_name_ip port username password des_key</i></p>"
"<p><h3>Extended N-line example:</h3><i>N: host_name_ip port usename password des_key # caid:ident</i><br></p>"
"<p><h3>When you export to oscam.server...</h3>...the first account created will be call <i>'DELETE ME'</i>.<br>"
"Please, upload the file to OSCam and delete the account <i>'DELETE ME'</i>:<br>"
"this will restore the right formatted standard of oscam.server.<br><br></p><p>CCcam2OSCam Converter by mapi68</p></body></html>")
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())