コード例 #1
0
    def ask(self, username, display):

        result = self.db_service.select('contract', ['content', 'title', 'id'],
                                        'id =(select MAX(id) from contract)')

        if result is None or len(result) < 1:
            content = 'Ahenk kurulu bu bilgisayarda ilk defa oturum açıyorsunuz. ' \
                      'Devam ederseniz Lider-Ahenk in bilgisayar üzeride yapacağı ' \
                      'tüm işlemlere onay vermiş sayılacaksınız. Kabul ediyor musunuz?' \
                      ' \n(Tanımlanmış zaman aralığında olumlu cevaplandırmadığınız takdirde oturumunuz ' \
                      'sonlandırılacaktır.)'
            title = 'Ahenk Kurulu Bilgisayar Kullanım Anlaşması'
            contract_id = '-1'
        else:
            content = str(result[0][0])
            title = result[0][1]
            contract_id = result[0][2]
        try:
            agreement_path = System.Ahenk.received_dir_path(
            ) + Util.generate_uuid()
            Util.write_file(agreement_path, content)
            Util.set_permission(agreement_path, 777)
            command = 'export DISPLAY={0};su - {1} -c \'python3 {2} \"$(cat {3})\" \"{4}\"\''.format(
                display, username, self.ask_path, agreement_path, title)
            result_code, p_out, p_err = Util.execute(command)

            pout = str(p_out).replace('\n', '')
            if pout != 'Error':
                if pout == 'Y':
                    self.logger.debug(
                        'Agreement was accepted by {0}.'.format(username))
                    self.db_service.update(
                        'agreement', self.db_service.get_cols('agreement'),
                        [contract_id, username,
                         Util.timestamp(), 'Y'])
                elif pout == 'N':
                    self.db_service.update(
                        'agreement', self.db_service.get_cols('agreement'),
                        [contract_id, username,
                         Util.timestamp(), 'N'])
                    self.logger.debug(
                        'Agreement was ignored by {0}. Session will be closed'.
                        format(username))
                else:
                    self.logger.error(
                        'A problem occurred while executing ask.py. Error Message: {0}'
                        .format(str(pout)))
                Util.delete_file(agreement_path)
            else:
                self.logger.error(
                    'A problem occurred while executing ask.py (Probably argument fault). Error Message: {0}'
                    .format(str(pout)))

        except Exception as e:
            self.logger.error(
                'A Problem occurred while displaying agreement. Error Message: {0}'
                .format(str(e)))
コード例 #2
0
ファイル: agreement.py プロジェクト: Pardus-Kurumsal/ahenk
    def ask(self, username, display):

        result = self.db_service.select('contract', ['content', 'title', 'id'], 'id =(select MAX(id) from contract)')

        if result is None or len(result) < 1:
            content = 'Ahenk kurulu bu bilgisayarda ilk defa oturum açıyorsunuz. ' \
                      'Devam ederseniz Lider-Ahenk in bilgisayar üzeride yapacağı ' \
                      'tüm işlemlere onay vermiş sayılacaksınız. Kabul ediyor musunuz?' \
                      ' \n(Tanımlanmış zaman aralığında olumlu cevaplandırmadığınız takdirde oturumunuz ' \
                      'sonlandırılacaktır.)'
            title = 'Ahenk Kurulu Bilgisayar Kullanım Anlaşması'
            contract_id = '-1'
        else:
            content = str(result[0][0])
            title = result[0][1]
            contract_id = result[0][2]
        try:
            agreement_path = System.Ahenk.received_dir_path() + Util.generate_uuid()
            Util.write_file(agreement_path, content)
            Util.set_permission(agreement_path, 777)
            command = 'export DISPLAY={0};su - {1} -c \'python3 {2} \"$(cat {3})\" \"{4}\"\''.format(display, username,
                                                                                                     self.ask_path,
                                                                                                     agreement_path,
                                                                                                     title)
            result_code, p_out, p_err = Util.execute(command)
            pout = str(p_out).replace('\n', '')
            if pout != 'Error':
                if pout == 'Y':
                    self.logger.debug('Agreement was accepted by {0}.'.format(username))
                    self.db_service.update('agreement', self.db_service.get_cols('agreement'),
                                           [contract_id, username, Util.timestamp(), 'Y'])
                elif pout == 'N':
                    self.db_service.update('agreement', self.db_service.get_cols('agreement'),
                                           [contract_id, username, Util.timestamp(), 'N'])
                    self.logger.debug(
                        'Agreement was ignored by {0}. Session will be closed'.format(username))
                else:
                    self.logger.error(
                        'A problem occurred while executing ask.py. Error Message: {0}'.format(str(pout)))
                Util.delete_file(agreement_path)
            else:
                self.logger.error(
                    'A problem occurred while executing ask.py (Probably argument fault). Error Message: {0}'.format(
                        str(pout)))

        except Exception as e:
            self.logger.error(
                'A Problem occurred while displaying agreement. Error Message: {0}'.format(str(e)))
コード例 #3
0
ファイル: system.py プロジェクト: tncyclk/ahenk
 def received_dir_path():
     path = '/tmp/'  # move this to properties
     if Util.is_exist(path) is False:
         Util.create_directory(path)
         Util.set_permission(path, '777')
     return path
コード例 #4
0
ファイル: ahenkd.py プロジェクト: tncyclk/ahenk
 def init_fifo_file():
     """ docstring"""
     if Util.is_exist(System.Ahenk.fifo_file()):
         Util.delete_file(System.Ahenk.fifo_file())
     Util.create_file(System.Ahenk.fifo_file())
     Util.set_permission(System.Ahenk.fifo_file(), '600')
コード例 #5
0
 def received_dir_path():
     path = '/tmp/.ahenk/'
     if Util.is_exist(path) is False:
         Util.create_directory(path)
         Util.set_permission(path, '777')
     return path
コード例 #6
0
ファイル: ahenkd.py プロジェクト: Pardus-Kurumsal/ahenk
 def init_fifo_file():
     """ docstring"""
     if Util.is_exist(System.Ahenk.fifo_file()):
         Util.delete_file(System.Ahenk.fifo_file())
     Util.create_file(System.Ahenk.fifo_file())
     Util.set_permission(System.Ahenk.fifo_file(), '600')
コード例 #7
0
ファイル: system.py プロジェクト: Pardus-Kurumsal/ahenk
 def received_dir_path():
     path = '/tmp/.ahenk/'
     if Util.is_exist(path) is False:
         Util.create_directory(path)
         Util.set_permission(path, '777')
     return path