summaryrefslogtreecommitdiffstats
path: root/abs/core/mythinstall/password_manage.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'abs/core/mythinstall/password_manage.cpp')
-rwxr-xr-xabs/core/mythinstall/password_manage.cpp445
1 files changed, 0 insertions, 445 deletions
diff --git a/abs/core/mythinstall/password_manage.cpp b/abs/core/mythinstall/password_manage.cpp
deleted file mode 100755
index 5156636..0000000
--- a/abs/core/mythinstall/password_manage.cpp
+++ /dev/null
@@ -1,445 +0,0 @@
-#include <mythcontext.h>
-#include <unistd.h>
-#include <iostream>
-#include <fstream>
-#include <stdio.h>
-#include "settings.h"
-#include "installsettings.h"
-#include "installdialog.h"
-#include "password_manage.h"
-#include <qsqldatabase.h>
-#include <qsqlquery.h>
-
-#include <stdlib.h>
-#include <cstdlib>
-#include <mythtv/mythdbcon.h>
-#include <qdir.h>
-#include <qapplication.h>
-#include "util.h"
-#include <qregexp.h>
-/****************************************************************************/
-typedef enum {
- UseraddPopup_OK = 0,
- UseraddPopup_CANCEL,
- UseraddPopup_DELETE
-}
- UseraddPopupResult;
- bool passtoggle = TRUE;
- QString invalid_chars = "&<>/~`;:!";
-
-class AddUserPopup
-{
- public:
- static UseraddPopupResult showPopup(MythMainWindow *parent, QString title,
- QString message, QString& text);
-};
-
-UseraddPopupResult AddUserPopup::showPopup(MythMainWindow *parent,
- QString title, QString message, QString& text)
-{
- MythPopupBox *popup = new MythPopupBox(parent, title);
- popup->addLabel(message);
-
- MythLineEdit *textEdit = new MythLineEdit(popup, "chooseEdit");
- textEdit->setText(text);
- popup->addWidget(textEdit);
-
- popup->addButton(QObject::tr("OK"), popup, SLOT(accept()));
- popup->addButton(QObject::tr("Cancel"), popup, SLOT(reject()));
-
- textEdit->setFocus();
-
- bool ok = (MythDialog::Accepted == popup->ExecPopup());
- if (ok)
- text = QDeepCopy<QString>(textEdit->text());
-
- popup->hide();
- popup->deleteLater();
-
- return (ok) ? UseraddPopup_OK : UseraddPopup_CANCEL;
-}
-
-/****************************************************************************/
-
-
-void UserManagement::user_fillselection()
-{
- //only add users with UID above 1000
- QString line;
- QString user;
- QString quid;
- int uid;
- QFile file("/etc/passwd");
- if ( file.open(IO_ReadOnly | IO_Translate) )
- {
- QTextStream t( &file ); // use a text stream
- while ( !t.eof() )
- {
- line = t.readLine();
- user = line.section(":",0,0);
- quid = line.section(":",2,2);
- uid=quid.toInt();
- if ( uid >= 1000 )
- userlist->addSelection(user);
- }
- file.close();
- }
-
-}
-
-bool UserManagement::user_exisit_check(QString name)
-{
- QString line;
- QString user;
- QString quid;
- bool founduser;
- founduser=false;
- int uid;
- QFile file("/etc/passwd");
- if ( file.open(IO_ReadOnly | IO_Translate) )
- {
- QTextStream t( &file ); // use a text stream
- while ( !t.eof() )
- {
- line = t.readLine();
- user = line.section(":",0,0);
- quid = line.section(":",2,2);
- uid=quid.toInt();
- if ( user == name )
- {
- founduser=true;
- break;
- }
- }
- file.close();
- }
-
- return founduser;
-
-}
-
-bool UserManagement::user_valid_check(QString check_string)
-{
- QChar current_char;
- int upperlimit;
- int found_char;
- int i ;
- upperlimit = invalid_chars.length() -1 ;
- for(i= 0; i <= upperlimit; i++)
- {
- found_char = -1;
- current_char = invalid_chars.at(i);
- found_char = check_string.contains(current_char,FALSE);
- if ( found_char > 0 )
- return FALSE;
- }
- return TRUE ;
-
-}
-
-UserManagement::UserManagement():
- VerticalConfigurationGroup(false,false,false,false)
- {
- setLabel(QObject::tr("Password Management"));
- userlist = new TransComboBoxSetting(false);
- userlist->setLabel(QObject::tr("Current Accounts"));
- userlist->addSelection("root");
- userlist->addSelection("mythtv");
- user_fillselection();
- userlist->setHelpText(QObject::tr("Select the account for password reset"));
-
- userpass1= new TransLineEditSetting(true);
- userpass1->setLabel("Password");
- userpass1->SetPasswordEcho(passtoggle);
- userpass1->setHelpText(QObject::tr("The following characters will not be accepted: " + invalid_chars));
-
-
- passToggleButton = new TransButtonSetting;
- passToggleButton->setLabel("Toggle password view");
- passToggleButton->setHelpText(QObject::tr("Hide or show the password"));
-
- info = new TransLabelSetting;
- info->setValue("");
-
- userapplyButton = new TransButtonSetting;
- userapplyButton->setLabel("Apply new password");
-
- usercreateButton = new TransButtonSetting;
- usercreateButton->setLabel("Create a new user account");
- usercreateButton->setHelpText(QObject::tr("The following characters will not be accepted: " + invalid_chars));
-
- userdeleteButton = new TransButtonSetting;
- userdeleteButton->setLabel("Delete current account");
- ConfigurationGroup *buttonlist = new GridConfigurationGroup(2,false);
- buttonlist-> addChild(usercreateButton);
- buttonlist-> addChild(userdeleteButton);
-
- ConfigurationGroup *buttonlist2 = new GridConfigurationGroup(2,false);
- buttonlist2-> addChild(passToggleButton);
- buttonlist2-> addChild(userapplyButton);
-
- rootSSH = new HostCheckBox("HOSTrootSSH");
- rootSSH->setLabel("Enable remote access for the root account.");
- rootSSH->setHelpText(QObject::tr("Checking this will enable ssh for the root account. Leave this disabled unless you know what your doing."));
- rootSSH->setValue(false);
-
- addChild(userlist);
- addChild(buttonlist);
- addChild(userpass1);
- addChild(info);
- addChild(rootSSH);
- addChild(buttonlist2);
-
- connect(userapplyButton, SIGNAL(pressed()), this, SLOT(applychanges()));
- connect(userlist, SIGNAL(valueChanged(const QString&)), this, SLOT(userchanged()));
- connect(usercreateButton, SIGNAL(pressed()), this, SLOT(usercreatepopup()));
- connect(userdeleteButton, SIGNAL(pressed()), this, SLOT(userdeletepopup()));
- connect(passToggleButton, SIGNAL(pressed()), this, SLOT(togglepass()));
-};
-
-void UserManagement::togglepass()
-{
-
- if ( passtoggle)
- passtoggle = false;
- else
- passtoggle = true;
- userpass1->SetPasswordEcho(passtoggle);
-}
-
-void UserManagement::applychanges()
-{
- QString user;
- QString password;
- QString user_e;
-
- user=userlist->getValue();
- password=userpass1->getValue();
-
- user_e = QRegExp::escape( user );
- password = QRegExp::escape( password );
- if ( ! user_valid_check (password))
- {
- info->setValue(" Password contains invalid characters!");
- return;
- }
- info->setValue(" Password has been changed for user: " + user );
- QString cmdtxt;
- cmdtxt="sudo ";
- cmdtxt.append("myth_user_call -c pass -u " + user_e + " -p " + password );
- myth_system(cmdtxt);
-
-
-}
-
-void UserManagement::userchanged()
-{
- info->setValue(" ");
- userpass1->setValue("");
-}
-
-void UserManagement::usercreatepopup()
-{
- QString name;
- QString name_e;
- int key = 0;
- UseraddPopupResult result = AddUserPopup::showPopup(
- gContext->GetMainWindow(),
- tr(""),
- tr("Enter a new user account name"), name);
- if (result == UseraddPopup_CANCEL)
- return;
- //check if name exisit || add it
- if ( user_exisit_check(name) )
- {
- info->setValue(name + " Already present");
- userlist->setFocus();
- key = Qt::Key_Down;
- QApplication::postEvent(gContext->GetMainWindow(),
- new ExternalKeycodeEvent(key));
-
- return;
- }
-
- if ( ! user_valid_check (name))
- {
- info->setValue(" Username contains invalid characters!");
- return;
- }
- userlist->addSelection(name);
- userlist->setValue(name);
- //run program to add user right here
- QString cmdtxt;
- name_e = QRegExp::escape( name );
-
- cmdtxt="sudo ";
- cmdtxt.append("myth_user_call -c add -u " + name_e );
- myth_system(cmdtxt);
-
- info->setValue("Now enter a password for " + name + " and press the apply button.");
- //Set focus to userlist, then press down three times to set focus to the password box.
- userlist->setFocus();
-
- key = Qt::Key_Down;
- QApplication::postEvent(gContext->GetMainWindow(),
- new ExternalKeycodeEvent(key));
- key = Qt::Key_Down;
- QApplication::postEvent(gContext->GetMainWindow(),
- new ExternalKeycodeEvent(key));
- key = Qt::Key_Down;
- QApplication::postEvent(gContext->GetMainWindow(),
- new ExternalKeycodeEvent(key));
-
-}
-
-void UserManagement::userdeletepopup()
-{
- QString user;
- QString user_e;
- user=userlist->getValue();
- QString message = user ;
-
- DialogCode value = MythPopupBox::Show2ButtonPopup(
- gContext->GetMainWindow(), "", message,
- tr("Remove this account"),
- tr("Do not remove this account"),
- kDialogCodeButton1);
-
- if (kDialogCodeButton0 == value)
- {
- info->setValue("removed account: " + user);
- if ( user == "root" || user == "mythtv" )
- {
- info->setValue("Can not remove the account");
- return;
- }
- userlist->setValue("root");
- userlist->removeSelection(user);
- //run program to remove user
- QString cmdtxt;
- user_e = QRegExp::escape( user );
- cmdtxt="sudo ";
- cmdtxt.append("myth_user_call -c delete -u " + user_e );
- myth_system(cmdtxt);
- info->setValue("Removed account: " + user);
- }
- else
- info->setValue("Did not remove account: " + user);
-}
-
-WebPassword::WebPassword():
- TriggeredConfigurationGroup(true,false,true,true,true,true,true,true)
-{
-
- webAuth = new HostCheckBox("HOSTwebauth");
- webAuth->setLabel("Enable password");
- webAuth->setHelpText(QObject::tr("Enable the use of password protection for the local website."));
- webAuth->setValue(false);
- webuser = new HostLineEdit("Hostwebuser");
- webuser->setLabel("Username");
- webuser->setHelpText(QObject::tr("The following characters will not be accepted: " + invalid_chars));
-
- webpassword = new HostLineEdit("Hostwebpassword");
- webpassword->setLabel("Password");
- webpassword->SetPasswordEcho(passtoggle);
- webpassword->setHelpText(QObject::tr("The following characters will not be accepted: " + invalid_chars));
-
- webpassToggleButton = new TransButtonSetting;
- webpassToggleButton->setLabel("Toggle password view");
- webpassToggleButton->setHelpText(QObject::tr("Hide or show the password"));
-
- webapplyButton = new TransButtonSetting;
- webapplyButton->setLabel("Apply new password");
-
- info = new TransLabelSetting;
- info->setValue("");
-
- connect(webpassToggleButton, SIGNAL(pressed()), this, SLOT(togglepass()));
- connect(webapplyButton, SIGNAL(pressed()),this , SLOT(webpassword_gathersettings()));
-
- ConfigurationGroup* webpassgroup = new VerticalConfigurationGroup(false);
- webpassgroup->addChild(webuser);
- webpassgroup->addChild(webpassword);
- webpassgroup->addChild(info);
- webpassgroup->addChild(webpassToggleButton);
- webpassgroup->addChild(webapplyButton);
-
- addChild(webAuth);
- setTrigger(webAuth);
-
- addTarget("0", new VerticalConfigurationGroup(false, false));
- addTarget("1", webpassgroup);
-
-}
-
-
-void WebPassword::togglepass()
-{
- if ( passtoggle)
- passtoggle = false;
- else
- passtoggle = true;
- webpassword->SetPasswordEcho(passtoggle);
-}
-
-bool WebPassword::valid_check(QString check_string)
-{
- // QString invalid_chars;
- QChar current_char;
- int upperlimit;
- int found_char;
- int i ;
- //invalid_chars = "&<>/~`;";
- upperlimit = invalid_chars.length() -1 ;
- for(i= 0; i <= upperlimit; i++)
- {
- found_char = -1;
- current_char = invalid_chars.at(i);
- found_char = check_string.contains(current_char,FALSE);
- if ( found_char > 0 )
- return FALSE;
- }
- return TRUE ;
-
-}
-
-void WebPassword::webpassword_gathersettings()
-{
-
- QString pass_enabled;
- QString web_user;
- QString web_pass;
- QString webuser_e;
- QString webpass_e;
- pass_enabled=webAuth->getValue();
- web_user=webuser->getValue();
- web_pass=webpassword->getValue();
- webuser_e = QRegExp::escape( web_user );
- webpass_e = QRegExp::escape( web_pass );
- if ( ! valid_check (webuser_e))
- {
- info->setValue(" Username contains invalid characters!");
- return;
- }
-
- if ( ! valid_check (webpass_e))
- {
- info->setValue(" Password contains invalid characters!");
- return;
- }
- cout << "Running program to make the changes for web password" << endl;
- QString cmdtxt;
-
- cmdtxt="sudo ";
- cmdtxt.append("myth_user_call -c web -u " + webuser_e + " -p " + webpass_e );
- myth_system(cmdtxt);
- info->setValue(" Changes applied");
-
-}
-
-WebPasswordFrame::WebPasswordFrame():
- VerticalConfigurationGroup()
-{
- WebPassword *webpassword = new WebPassword();
- addChild(webpassword);
-}