Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import io
- import sys
- import json
- # import urllib
- import urllib2 as urllib
- import random
- import re
- from urlparse import urlparse
- from main_form import Ui_MainWindow as main_form
- from captcha_form import Ui_MainWindow as captcha_form
- from PyQt4 import QtCore, QtGui, uic
- from YaakovHTTP import YaakovHTTP
- def regex_get(regex,string):
- return re.search(regex,string).group(0)
- def regex_replace(regex,substring,string):
- return re.sub(regex,substring,string)
- class Captcha(QtGui.QMainWindow):
- def __init__(self, parent=None):
- QtGui.QDialog.__init__(self, parent)
- self.ui=captcha_form()
- self.ui.setupUi(self)
- self.ui.captcha_text.setFocus()
- self.connect(self.ui.captcha_text, QtCore.SIGNAL('returnPressed()'), self.form_submit)
- self.captcha = u''
- def set_picture(self, picture):
- pic=QtGui.QGraphicsScene()
- image=QtGui.QPixmap()
- image.loadFromData(picture)
- pic.addPixmap(image)
- self.ui.captcha_picture.setScene(pic)
- self.set_resize(image.width(),image.height())
- def set_resize(self,x,y):
- x = x if x in range(220,600) else 220
- y = y if y in range(150,500) else 150
- self.setFixedSize(x+10,y+55)
- self.ui.captcha_picture.setGeometry(QtCore.QRect(0, 0, x+10, y+10))
- self.ui.captcha_text.setGeometry(QtCore.QRect(((x+10-160)/2), y+15, 160, 30))
- def form_submit(self):
- if len(self.ui.captcha_text.text()) > 0:
- self.close()
- main.send_message(unicode(self.ui.captcha_text.text()))
- else: self.close()
- def form_close(self):
- # main.form_close()
- self.close()
- def keyPressEvent(self,event):
- if event.nativeScanCode()==1: self.form_close()
- class Main(QtGui.QMainWindow):
- def __init__(self, parent=None):
- QtGui.QDialog.__init__(self, parent)
- self.ui=main_form()
- self.ui.setupUi(self)
- self.setFixedSize(399, 214)
- self.http = YaakovHTTP()
- self.c={}
- self.c['operator']=0
- self.c['number']='+7 (922) 612-52_74'
- self.c['message']=u''
- self.c['proxy_enable']=0
- self.c['proxy']=u'microsoft.com'
- self.c['port']=666
- try: self.c = json.load(open('pager.json','r'))
- except: pass
- self.ui.operator.setCurrentIndex(self.c['operator'])
- self.ui.text_input.setPlainText(self.c['message'])
- self.ui.text_input.selectAll()
- self.ui.check_proxy.setCheckState(self.c['proxy_enable'])
- self.ui.proxy.setText(self.c['proxy']+':'+str(self.c['port']))
- self.ui.number.setText(self.c['number'])
- self.ui.number.selectAll()
- self.__last_scancode=0
- self.connect(self.ui.button_send, QtCore.SIGNAL("pressed()"), self.form_submit)
- self.connect(self.ui.button_close, QtCore.SIGNAL("pressed()"), self.form_close)
- self.connect(self.ui.check_proxy, QtCore.SIGNAL("clicked()"), self.toggle_proxy)
- self.connect(self.ui.proxy, QtCore.SIGNAL('returnPressed()'), self.ui.text_input.setFocus)
- self.connect(self.ui.proxy, QtCore.SIGNAL("textChanged(QString)"), self.check_proxy)
- self.connect(self.ui.number, QtCore.SIGNAL('returnPressed()'), self.ui.text_input.setFocus)
- self.connect(self.ui.number, QtCore.SIGNAL("textChanged(QString)"), self.check_number)
- self.connect(self.ui.text_input, QtCore.SIGNAL("textChanged()"), self.check_input)
- self.toggle_proxy()
- self.check_input()
- def settings_save(self):
- self.c['operator'] = self.ui.operator.currentIndex()
- self.c['number'] = str(self.ui.number.text())
- open('pager.json','w').write(json.dumps(self.c))
- def form_submit(self):
- if not self.check_input():
- self.statusBar().showMessage(u'Сообщение должно быть от 10 до 140 символов.')
- return
- if not self.check_number():
- self.statusBar().showMessage(u'Неправильный номер.')
- return
- if self.toggle_proxy():
- if not self.check_proxy():
- self.statusBar().showMessage(u'Прокси записывается в виде хоста и номера порта через двоеточие.')
- return
- else: self.http.set_proxy(self.c['proxy'] + ':' + str(self.c['port']))
- self.http.add_header('User-Agent: Opera/9.80 (Windows NT 5.1; U; ru) Presto/2.8.131 Version/11.10');
- if self.ui.operator.currentIndex() == 0:
- self.http.set_url('http://ural.sendsms.megafon.ru/')
- elif self.ui.operator.currentIndex() == 1:
- self.http.set_url('http://cell.motivtelecom.ru/ekb/smssend')
- self.http.add_header('Referer: http://cell.motivtelecom.ru/ekb/b2c')
- self.http.perform()
- if not self.http.response_code == 200:
- self.statusBar().showMessage(u'Ошибка при запросе страницы, сервер ответил: ' + str(self.http.response_code) + ' ' + self.http.response_message + '.')
- else:
- if self.ui.operator.currentIndex() == 0:
- self.http.set_url('http://ural.sendsms.megafon.ru/image.phtml?k=' + regex_get('(?<=value=")\d+',regex_get('(?<=name="codekey").*',self.http.response_content + '')))
- elif self.ui.operator.currentIndex() == 1:
- if not 'ycc' in self.http.response_cookie:
- self.statusBar().showMessage(u'Ошибка: куки сессии не установлены, сервер ответил: ' + str(self.http.response_code) + ' ' + self.http.response_message + '.')
- return
- else:
- self.http.add_header('Cookie: ycc=' + self.http.response_cookie['ycc'])
- self.http.set_url('http://cell.motivtelecom.ru/ekb/phpcaptcha/image?rand=' + str(random.randint(1000001,9999999)))
- self.http.perform()
- if not self.http.response_code == 200:
- self.statusBar().showMessage(u'Ошибка при запросе капчи, сервер ответил: ' + str(self.http.response_code) + ' ' + self.http.response_message + '.')
- else:
- captcha.set_picture(self.http.response_content)
- captcha.show()
- def send_message(self,captcha):
- number = self.check_number()
- if self.ui.operator.currentIndex() == 0:
- self.http.set_url('http://ural.sendsms.megafon.ru/')
- elif self.ui.operator.currentIndex() == 1:
- self.http.set_url('http://cell.motivtelecom.ru/ekb/smssend')
- self.http.add_header('Content-Type: application/x-www-form-urlencoded')
- self.http.set_method('POST')
- codes = [90019,90020,90021,90287,90416,90417,90438,90454,90498,90863,90890,90891,90892,95019,95020,95063,95064,95065,95213,95214,95272,95273,95274,95300,95303,95304,95305,95338,95360]
- if int(number[1:6]) not in codes:
- self.statusBar().showMessage(u'Это не номер Мотива.')
- else: index = codes.index(int(number[1:6]))
- msg = urllib.quote('smssend[name]=Ant&smssend[code]=' + str(index) + '&smssend[phone]=' + str(number[6:]) + '&smssend[txt]=','&=') + urllib.quote(unicode(self.ui.text_input.toPlainText()).encode('UTF-8'),'&=').replace('+','%20') + urllib.quote('&smssend[hdelay]=0&smssend[mdelay]=0&smssend[captcha]=' + captcha,'&=')
- self.http.add_request_data(msg)
- print(msg)
- self.http.perform()
- print(self.http.response_message)
- if not self.http.response_code == 200:
- self.statusBar().showMessage(u'Ошибка отправки:' + str(self.http.response_code) + ' ' + self.http.response_message)
- elif regex_get('(?<=Сообщение )[^<.]*',self.http.response_content) == 'отправлено':
- self.statusBar().showMessage(u'Сообщение отправлено!')
- self.ui.text_input.clear()
- else:
- self.statusBar().showMessage(u'Ошибка отправки - сервер не принял сообщение.')
- def form_clear(self):
- self.ui.text_input.clear()
- self.ui.text_input.setFocus()
- def form_close(self):
- self.settings_save()
- self.close()
- def toggle_proxy(self):
- if self.ui.check_proxy.isChecked():
- self.ui.proxy.setReadOnly(0)
- self.c['proxy_enable'] = 2
- return 1
- else:
- self.ui.proxy.setReadOnly(1)
- self.c['proxy_enable'] = 0
- return
- def check_number(self):
- __num = str(self.ui.number.text())
- __num = regex_replace('[^0-9]','',__num)
- __num = '7' + __num[1:] if len(__num) == 11 and __num[0] == '8' else __num
- self.c['number'] = __num
- if len(__num) == 11 and __num[0:2] == '79':
- self.setStyleSheet('QLineEdit#number{border: 1px solid #aaa;background: #fff;}')
- self.ui.number.setText('+' + __num[0] + ' (' + __num[1:4] + ') ' + __num[4:7] + '-' + __num[7:9] + '-' + __num[9:11])
- return __num
- else:
- self.setStyleSheet('QLineEdit#number{border: 1px solid red;background: #fee;}')
- def check_proxy(self):
- __proxy = ''
- __port = 0
- __string = unicode(self.ui.proxy.text())
- if __string.find(':') > 0:
- __port = __string[__string.find(':') + 1:]
- __proxy = __string[:__string.find(':')]
- try: __port = int(__port)
- except: __port = 0
- self.c['proxy'] = __proxy
- self.c['port'] = __port
- if len(self.c['proxy']) > 0 and self.c['port'] in range(1,65535):
- self.setStyleSheet('QLineEdit#proxy{border: 1px solid #aaa;background: #fff;}')
- return 1
- else:
- self.setStyleSheet('QLineEdit#proxy{border: 1px solid red;background: #fee;}')
- return
- def check_input(self):
- __max = 200
- __text = unicode(self.ui.text_input.toPlainText())
- __length = len(__text)
- self.ui.counter.display(__length)
- if __length>__max:
- self.ui.text_input.setPlainText(__text[0:__max])
- __index = int(((float(__length)/140)*255))
- if __index not in range(0,255):__index = 255
- __color = str(hex(__index))[2:]
- if len(__color) == 1:__color = '0'+__color
- self.setStyleSheet('QPlainTextEdit{color: #'+__color+'0000;}')
- self.c['message'] = unicode(self.ui.text_input.toPlainText())
- if len(__text) in range(10,__max): return 1
- def keyPressEvent(self,event):
- if event.nativeScanCode()==28 and self.__last_scancode==285:
- # self.form_submit()
- self.send_message('captcha')
- elif event.nativeScanCode()==28:
- self.ui.text_input.setFocus()
- elif event.nativeScanCode()==1:
- self.form_close()
- self.__last_scancode=event.nativeScanCode()
- app=QtGui.QApplication(sys.argv)
- app.setStyleSheet(open("pager.qss","r").read())
- main=Main()
- main.show()
- captcha=Captcha()
- sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement