check autotype syntax, high repetion, reformat code

TODO: specify what should happen when autotypesyntax incorrect
This commit is contained in:
Marco 2017-05-14 18:25:43 +02:00 committed by thez3ro
parent 45cb97ec85
commit 4fcedc2187
No known key found for this signature in database
GPG Key ID: F628F9E41DD7C073
2 changed files with 66 additions and 49 deletions

View File

@ -62,9 +62,9 @@ AutoType::AutoType(QObject* parent, bool test)
QString pluginPath = filePath()->pluginPath(pluginName); QString pluginPath = filePath()->pluginPath(pluginName);
if (!pluginPath.isEmpty()) { if (!pluginPath.isEmpty()) {
#ifdef WITH_XC_AUTOTYPE #ifdef WITH_XC_AUTOTYPE
loadPlugin(pluginPath); loadPlugin(pluginPath);
#endif #endif
} }
connect(qApp, SIGNAL(aboutToQuit()), SLOT(unloadPlugin())); connect(qApp, SIGNAL(aboutToQuit()), SLOT(unloadPlugin()));
@ -394,126 +394,128 @@ QList<AutoTypeAction*> AutoType::createActionFromTemplate(const QString& tmpl, c
else if (tmplName.compare("delay",Qt::CaseInsensitive)==0) { else if (tmplName.compare("delay",Qt::CaseInsensitive)==0) {
if (num > 10000) { if (num > 10000) {
QMessageBox::StandardButton reply; QMessageBox::StandardButton reply;
reply = QMessageBox::question(0,"AutoType", reply = QMessageBox::question(0,
"AutoType",
"This AutoType command contains a very long delay. Do you really want to execute it?"); "This AutoType command contains a very long delay. Do you really want to execute it?");
if (reply==QMessageBox::No) { if (reply == QMessageBox::No) {
return list; return list;
} }
} }
} }
else if (num > 100) { else if (num > 100) {
QMessageBox::StandardButton reply; QMessageBox::StandardButton reply;
reply = QMessageBox::question(0,"AutoType", reply = QMessageBox::question(0,
"AutoType",
"This AutoType command contains arguments which are repeated very often. Do you really want to execute it?"); "This AutoType command contains arguments which are repeated very often. Do you really want to execute it?");
if (reply==QMessageBox::No) { if (reply == QMessageBox::No) {
return list; return list;
} }
} }
} }
if (tmplName.compare("tab",Qt::CaseInsensitive)==0) { if (tmplName.compare("tab", Qt::CaseInsensitive) == 0) {
list.append(new AutoTypeKey(Qt::Key_Tab)); list.append(new AutoTypeKey(Qt::Key_Tab));
} }
else if (tmplName.compare("enter",Qt::CaseInsensitive)==0) { else if (tmplName.compare("enter", Qt::CaseInsensitive) == 0) {
list.append(new AutoTypeKey(Qt::Key_Enter)); list.append(new AutoTypeKey(Qt::Key_Enter));
} }
else if (tmplName.compare("space",Qt::CaseInsensitive)==0) { else if (tmplName.compare("space", Qt::CaseInsensitive) == 0) {
list.append(new AutoTypeKey(Qt::Key_Space)); list.append(new AutoTypeKey(Qt::Key_Space));
} }
else if (tmplName.compare("up",Qt::CaseInsensitive)==0) { else if (tmplName.compare("up", Qt::CaseInsensitive) == 0) {
list.append(new AutoTypeKey(Qt::Key_Up)); list.append(new AutoTypeKey(Qt::Key_Up));
} }
else if (tmplName.compare("down",Qt::CaseInsensitive)==0) { else if (tmplName.compare("down", Qt::CaseInsensitive) == 0) {
list.append(new AutoTypeKey(Qt::Key_Down)); list.append(new AutoTypeKey(Qt::Key_Down));
} }
else if (tmplName.compare("left",Qt::CaseInsensitive)==0) { else if (tmplName.compare("left", Qt::CaseInsensitive) == 0) {
list.append(new AutoTypeKey(Qt::Key_Left)); list.append(new AutoTypeKey(Qt::Key_Left));
} }
else if (tmplName.compare("right",Qt::CaseInsensitive)==0) { else if (tmplName.compare("right", Qt::CaseInsensitive) == 0) {
list.append(new AutoTypeKey(Qt::Key_Right)); list.append(new AutoTypeKey(Qt::Key_Right));
} }
else if (tmplName.compare("insert",Qt::CaseInsensitive)==0 || else if (tmplName.compare("insert", Qt::CaseInsensitive) == 0 ||
tmplName.compare("ins",Qt::CaseInsensitive)==0) { tmplName.compare("ins", Qt::CaseInsensitive) == 0) {
list.append(new AutoTypeKey(Qt::Key_Insert)); list.append(new AutoTypeKey(Qt::Key_Insert));
} }
else if (tmplName.compare("delete",Qt::CaseInsensitive)==0 || else if (tmplName.compare("delete", Qt::CaseInsensitive) == 0 ||
tmplName.compare("del",Qt::CaseInsensitive)==0) { tmplName.compare("del", Qt::CaseInsensitive) == 0) {
list.append(new AutoTypeKey(Qt::Key_Delete)); list.append(new AutoTypeKey(Qt::Key_Delete));
} }
else if (tmplName.compare("home",Qt::CaseInsensitive)==0) { else if (tmplName.compare("home", Qt::CaseInsensitive) == 0) {
list.append(new AutoTypeKey(Qt::Key_Home)); list.append(new AutoTypeKey(Qt::Key_Home));
} }
else if (tmplName.compare("end",Qt::CaseInsensitive)==0) { else if (tmplName.compare("end", Qt::CaseInsensitive) == 0) {
list.append(new AutoTypeKey(Qt::Key_End)); list.append(new AutoTypeKey(Qt::Key_End));
} }
else if (tmplName.compare("pgup",Qt::CaseInsensitive)==0) { else if (tmplName.compare("pgup", Qt::CaseInsensitive) == 0) {
list.append(new AutoTypeKey(Qt::Key_PageUp)); list.append(new AutoTypeKey(Qt::Key_PageUp));
} }
else if (tmplName.compare("pgdown",Qt::CaseInsensitive)==0) { else if (tmplName.compare("pgdown", Qt::CaseInsensitive) == 0) {
list.append(new AutoTypeKey(Qt::Key_PageDown)); list.append(new AutoTypeKey(Qt::Key_PageDown));
} }
else if (tmplName.compare("backspace",Qt::CaseInsensitive)==0 || else if (tmplName.compare("backspace", Qt::CaseInsensitive) == 0 ||
tmplName.compare("bs",Qt::CaseInsensitive)==0 || tmplName.compare("bs", Qt::CaseInsensitive) == 0 ||
tmplName.compare("bksp",Qt::CaseInsensitive)==0) { tmplName.compare("bksp", Qt::CaseInsensitive) == 0) {
list.append(new AutoTypeKey(Qt::Key_Backspace)); list.append(new AutoTypeKey(Qt::Key_Backspace));
} }
else if (tmplName.compare("break",Qt::CaseInsensitive)==0) { else if (tmplName.compare("break", Qt::CaseInsensitive) == 0) {
list.append(new AutoTypeKey(Qt::Key_Pause)); list.append(new AutoTypeKey(Qt::Key_Pause));
} }
else if (tmplName.compare("capslock",Qt::CaseInsensitive)==0) { else if (tmplName.compare("capslock", Qt::CaseInsensitive) == 0) {
list.append(new AutoTypeKey(Qt::Key_CapsLock)); list.append(new AutoTypeKey(Qt::Key_CapsLock));
} }
else if (tmplName.compare("esc",Qt::CaseInsensitive)==0) { else if (tmplName.compare("esc", Qt::CaseInsensitive) == 0) {
list.append(new AutoTypeKey(Qt::Key_Escape)); list.append(new AutoTypeKey(Qt::Key_Escape));
} }
else if (tmplName.compare("help",Qt::CaseInsensitive)==0) { else if (tmplName.compare("help", Qt::CaseInsensitive) == 0) {
list.append(new AutoTypeKey(Qt::Key_Help)); list.append(new AutoTypeKey(Qt::Key_Help));
} }
else if (tmplName.compare("numlock",Qt::CaseInsensitive)==0) { else if (tmplName.compare("numlock", Qt::CaseInsensitive) == 0) {
list.append(new AutoTypeKey(Qt::Key_NumLock)); list.append(new AutoTypeKey(Qt::Key_NumLock));
} }
else if (tmplName.compare("ptrsc",Qt::CaseInsensitive)==0) { else if (tmplName.compare("ptrsc", Qt::CaseInsensitive) == 0) {
list.append(new AutoTypeKey(Qt::Key_Print)); list.append(new AutoTypeKey(Qt::Key_Print));
} }
else if (tmplName.compare("scrolllock",Qt::CaseInsensitive)==0) { else if (tmplName.compare("scrolllock", Qt::CaseInsensitive) == 0) {
list.append(new AutoTypeKey(Qt::Key_ScrollLock)); list.append(new AutoTypeKey(Qt::Key_ScrollLock));
} }
// Qt doesn't know about keypad keys so use the normal ones instead // Qt doesn't know about keypad keys so use the normal ones instead
else if (tmplName.compare("add",Qt::CaseInsensitive)==0 || else if (tmplName.compare("add", Qt::CaseInsensitive) == 0 ||
tmplName.compare("+",Qt::CaseInsensitive)==0) { tmplName.compare("+", Qt::CaseInsensitive) == 0) {
list.append(new AutoTypeChar('+')); list.append(new AutoTypeChar('+'));
} }
else if (tmplName.compare("subtract",Qt::CaseInsensitive)==0) { else if (tmplName.compare("subtract", Qt::CaseInsensitive) == 0) {
list.append(new AutoTypeChar('-')); list.append(new AutoTypeChar('-'));
} }
else if (tmplName.compare("multiply",Qt::CaseInsensitive)==0) { else if (tmplName.compare("multiply", Qt::CaseInsensitive) == 0) {
list.append(new AutoTypeChar('*')); list.append(new AutoTypeChar('*'));
} }
else if (tmplName.compare("divide",Qt::CaseInsensitive)==0) { else if (tmplName.compare("divide", Qt::CaseInsensitive) == 0) {
list.append(new AutoTypeChar('/')); list.append(new AutoTypeChar('/'));
} }
else if (tmplName.compare("^",Qt::CaseInsensitive)==0) { else if (tmplName.compare("^", Qt::CaseInsensitive) == 0) {
list.append(new AutoTypeChar('^')); list.append(new AutoTypeChar('^'));
} }
else if (tmplName.compare("%",Qt::CaseInsensitive)==0) { else if (tmplName.compare("%", Qt::CaseInsensitive) == 0) {
list.append(new AutoTypeChar('%')); list.append(new AutoTypeChar('%'));
} }
else if (tmplName.compare("~",Qt::CaseInsensitive)==0) { else if (tmplName.compare("~", Qt::CaseInsensitive) == 0) {
list.append(new AutoTypeChar('~')); list.append(new AutoTypeChar('~'));
} }
else if (tmplName.compare("(",Qt::CaseInsensitive)==0) { else if (tmplName.compare("(", Qt::CaseInsensitive) == 0) {
list.append(new AutoTypeChar('(')); list.append(new AutoTypeChar('('));
} }
else if (tmplName.compare(")",Qt::CaseInsensitive)==0) { else if (tmplName.compare(")", Qt::CaseInsensitive) == 0) {
list.append(new AutoTypeChar(')')); list.append(new AutoTypeChar(')'));
} }
else if (tmplName.compare("leftbrace",Qt::CaseInsensitive)==0) { else if (tmplName.compare("leftbrace", Qt::CaseInsensitive) == 0) {
list.append(new AutoTypeChar('{')); list.append(new AutoTypeChar('{'));
} }
else if (tmplName.compare("rightbrace",Qt::CaseInsensitive)==0) { else if (tmplName.compare("rightbrace", Qt::CaseInsensitive) == 0) {
list.append(new AutoTypeChar('}')); list.append(new AutoTypeChar('}'));
} }
@ -535,10 +537,10 @@ QList<AutoTypeAction*> AutoType::createActionFromTemplate(const QString& tmpl, c
} }
if (tmplName.compare("delay",Qt::CaseInsensitive)==0 && num > 0) { if (tmplName.compare("delay", Qt::CaseInsensitive) == 0 && num > 0) {
list.append(new AutoTypeDelay(num)); list.append(new AutoTypeDelay(num));
} }
else if (tmplName.compare("clearfield",Qt::CaseInsensitive)==0) { else if (tmplName.compare("clearfield", Qt::CaseInsensitive) == 0) {
list.append(new AutoTypeClearField()); list.append(new AutoTypeClearField());
} }
else if (tmplName.compare("totp", Qt::CaseInsensitive) == 0) { else if (tmplName.compare("totp", Qt::CaseInsensitive) == 0) {
@ -573,7 +575,7 @@ QList<AutoTypeAction*> AutoType::createActionFromTemplate(const QString& tmpl, c
//allows to insert usernames and passwords multiple times //allows to insert usernames and passwords multiple times
if (!list.isEmpty()) { if (!list.isEmpty()) {
for (int i = 1; i < num; i++) { for (int i = 1; i < num; i++) {
for (int i = 0; i< resolved.size();i++) { for (int i = 0; i < resolved.size(); i++) {
list.append(list.at(i)->clone()); list.append(list.at(i)->clone());
} }
} }
@ -626,7 +628,7 @@ QString AutoType::autoTypeSequence(const Entry* entry, const QString& windowTitl
sequence = entry->defaultAutoTypeSequence(); sequence = entry->defaultAutoTypeSequence();
} }
const Group* group = entry->group(); const Group *group = entry->group();
do { do {
if (!enableSet) { if (!enableSet) {
if (group->autoTypeEnabled() == Group::Disable) { if (group->autoTypeEnabled() == Group::Disable) {
@ -644,7 +646,8 @@ QString AutoType::autoTypeSequence(const Entry* entry, const QString& windowTitl
group = group->parentGroup(); group = group->parentGroup();
} while (group && (!enableSet || sequence.isEmpty())); } while (group && (!enableSet || sequence.isEmpty()));
if (sequence.isEmpty() && (!entry->resolvePlaceholder(entry->username()).isEmpty() || !entry->resolvePlaceholder(entry->password()).isEmpty())) { if (sequence.isEmpty() && (!entry->resolvePlaceholder(entry->username()).isEmpty()
|| !entry->resolvePlaceholder(entry->password()).isEmpty())) {
if (entry->resolvePlaceholder(entry->username()).isEmpty()) { if (entry->resolvePlaceholder(entry->username()).isEmpty()) {
sequence = "{PASSWORD}{ENTER}"; sequence = "{PASSWORD}{ENTER}";
} }

View File

@ -764,6 +764,20 @@ void EditEntryWidget::updateEntryData(Entry* entry) const
entry->setDefaultAutoTypeSequence(QString()); entry->setDefaultAutoTypeSequence(QString());
} }
else { else {
QRegExp autoTypeSyntax("(\\{[A-Z]*(\\s[0-9]*){0,1}\\})*");
autoTypeSyntax.setCaseSensitivity(Qt::CaseInsensitive);
autoTypeSyntax.setPatternSyntax(QRegExp::RegExp);
QRegExp highRepetition(".*[0-9]{3,}.*"); //the 3 means 3 digitnumbers are too much
highRepetition.setPatternSyntax(QRegExp::RegExp);
if (!autoTypeSyntax.exactMatch(m_autoTypeUi->sequenceEdit->text())) {
//@TODO handle wrong syntax
}
if (!highRepetition.exactMatch(m_autoTypeUi->sequenceEdit->text())) {
//@TODO handle too much repetition
}
entry->setDefaultAutoTypeSequence(m_autoTypeUi->sequenceEdit->text()); entry->setDefaultAutoTypeSequence(m_autoTypeUi->sequenceEdit->text());
} }