コード例 #1
0
ファイル: restriction.php プロジェクト: andrejjursa/list-lms
 public static function check_restriction_for_ip_address($ip_address = NULL)
 {
     $ci =& get_instance();
     $ci->load->helper('ip_address');
     $ip_to_check = $ip_address;
     if (is_null($ip_address)) {
         $ip_to_check = getenv('REMOTE_ADDR');
     }
     if (check_valid_ip_address($ip_to_check)) {
         $time = date('Y-m-d H:i:s');
         $restriction = new Restriction();
         $restriction->where('start_time <=', $time);
         $restriction->where('end_time >=', $time);
         $restriction->get_iterated();
         foreach ($restriction as $restriction_record) {
             $ip_addresses = explode(',', $restriction_record->ip_addresses);
             if (count($ip_addresses)) {
                 foreach ($ip_addresses as $matching_pattern) {
                     if (trim($matching_pattern) !== '' && match_ip_address_agains(trim($matching_pattern), $ip_to_check)) {
                         return TRUE;
                     }
                 }
             }
         }
     }
     return FALSE;
 }
コード例 #2
0
ファイル: Task.php プロジェクト: uestla/simplex-calculator
 /**
  * @param  Restriction $r
  * @return Task
  */
 function addRestriction(Restriction $r)
 {
     if ($r->getVariableList() !== $this->function->getVariableList()) {
         throw new \InvalidArgumentException("Restriction variables don't match the objective function variables.");
     }
     $this->restrictions[] = $r;
     return $this;
 }
コード例 #3
0
ファイル: DbAuth.php プロジェクト: Acidburn0zzz/xframe-legacy
 /**
  * Perform the authorisation request
  * @return DbAuth
  */
 public function authenticate()
 {
     $credential = $this->getCredential();
     Assert::isNotEmpty($credential, "You must set a password before authentication");
     $identity = $this->getIdentity();
     Assert::isNotEmpty($identity, "You must set an username before authentication");
     //We first get user from db if its exists
     $criteria = new Criteria(Restriction::is($this->identityColumn, $identity));
     $records = TableGateway::loadMatching($this->table, $criteria);
     if ($records->count() == 0) {
         return false;
     }
     /** @var $user Customer */
     $user = $records->current();
     //Yes we need to reassign this to variable.
     $credentialColumn = $this->credentialColumn;
     $credentialSaltColumn = $this->credentialSaltColumn;
     $slatedCredentialColumn = $this->slatedCredentialColumn;
     //We check if we should use salt checking
     if (!empty($credentialSaltColumn) && !empty($slatedCredentialColumn) && !empty($user->{$credentialSaltColumn}) && !empty($user->{$slatedCredentialColumn})) {
         //Fo salt we check if password is same like credential
         $authenticated = SaltPasswordManager::checkPasswordWithHash($user->{$slatedCredentialColumn}, $user->{$credentialSaltColumn}, $this->credential);
     } else {
         //If don't have salt we must check if we have hashed password
         if ($this->hash) {
             $credential = SaltPasswordManager::generateSimpleHash($this->credential);
         } else {
             $credential = $this->credential;
         }
         //We check if we are authenticated
         $authenticated = $credential == $user->{$credentialColumn};
         /**
          * If we are authenticated and have original password, we can create and add slated password for user and
          * we should do it. It means we are not Auto Login or something.
          */
         if ($authenticated && $this->hash) {
             if (!empty($credentialSaltColumn) && !empty($slatedCredentialColumn)) {
                 list($password, $hash) = SaltPasswordManager::generateSaltedPassword($this->credential);
                 $this->addSalt($user, $password, $hash);
             }
         }
     }
     if (empty($authenticated)) {
         return false;
     }
     return $this->authorisedId = $records->current()->__get($this->identityKey);
 }
コード例 #4
0
 public function testIsValidWithAnyOtherOption()
 {
     $this->assertTrue($this->restiction->validate($this->createOption()));
 }
コード例 #5
0
 public function __construct($name = '', $threshold = 0, $messageHtml = '', array $popupInfo = null)
 {
     parent::__construct($name, $messageHtml, $popupInfo);
     $this->setRowCountThreshold($threshold);
 }
コード例 #6
0
ファイル: tasks.php プロジェクト: andrejjursa/list-lms
 public function download_solution($task_set_id, $file)
 {
     if ($this->usermanager->is_student_session_valid() && !Restriction::check_restriction_for_ip_address() || $this->usermanager->is_teacher_session_valid()) {
         $task_set = new Task_set();
         $task_set->get_by_id(intval($task_set_id));
         if ($task_set->exists()) {
             $filename = decode_from_url($file);
             $file_info = $task_set->get_specific_file_info($filename);
             if ($file_info !== FALSE) {
                 $allow_download = TRUE;
                 if (!$this->usermanager->is_teacher_session_valid()) {
                     $solution_version = new Solution_version();
                     $solution_version->where('version', $file_info['version']);
                     $solution_version->where_related('solution/task_set', 'id', $task_set_id);
                     $solution_version->get();
                     if ($solution_version->exists()) {
                         if ((bool) $solution_version->download_lock) {
                             $allow_download = FALSE;
                         }
                     }
                 }
                 if ($allow_download) {
                     $log = new Log();
                     if (!$this->usermanager->is_teacher_session_valid()) {
                         $log->add_student_solution_download_log($this->lang->line('tasks_log_message_student_solution_download'), $this->usermanager->get_student_id(), $filename, $task_set->id);
                     }
                     $filename = $file_info['file_name'] . '_' . $file_info['version'] . '.zip';
                     $finfo = finfo_open(FILEINFO_MIME_TYPE);
                     $mime_type = finfo_file($finfo, $file_info['filepath']);
                     finfo_close($finfo);
                     header('Content-Description: File Transfer');
                     header('Content-Type: ' . $mime_type);
                     header('Content-Disposition: attachment; filename=' . $filename);
                     header('Content-Transfer-Encoding: binary');
                     header('Expires: 0');
                     header('Cache-Control: must-revalidate');
                     header('Pragma: public');
                     header('Content-Length: ' . filesize($file_info['filepath']));
                     ob_clean();
                     flush();
                     $f = fopen($file_info['filepath'], 'r');
                     while (!feof($f)) {
                         echo fread($f, 1024);
                     }
                     fclose($f);
                     exit;
                 } else {
                     $this->parser->parse('frontend/tasks/download_solution.tpl', array('version_download_disabled' => TRUE));
                 }
             } else {
                 $this->output->set_status_header(404, 'Not found');
             }
         } else {
             $this->output->set_status_header(404, 'Not found');
         }
     } else {
         $this->parser->parse('frontend/tasks/download_solution.tpl');
     }
 }
コード例 #7
0
ファイル: Criteria.php プロジェクト: JeCat/framework
 public function setWhere(Restriction $aWhere)
 {
     $this->aWhere = $aWhere;
     $this->setRawWhere($aWhere->rawSql());
     return $this;
 }
コード例 #8
0
 public function __construct($name = '', $permitted = false, $messageHtml = '', array $popupInfo = null)
 {
     parent::__construct($name, $messageHtml, $popupInfo);
     $this->permit($permitted);
 }
コード例 #9
0
ファイル: restrictions.php プロジェクト: andrejjursa/list-lms
 public function clear_old()
 {
     $output = new stdClass();
     $output->status = FALSE;
     $output->message = '';
     $count = 0;
     $this->_transaction_isolation();
     $this->db->trans_begin();
     $time = date('Y-m-d H:i:s');
     $restrictions = new Restriction();
     $restrictions->where('end_time <', $time);
     $restrictions->where('start_time <', $time);
     $restrictions->get_iterated();
     foreach ($restrictions as $restriction) {
         if ($restriction->delete()) {
             $count++;
         }
     }
     if ($count > 0) {
         $this->db->trans_commit();
         $output->status = TRUE;
         $output->message = sprintf($this->lang->line('admin_restrictions_message_old_deleted'), $count);
     } else {
         $this->db->trans_rollback();
         $output->message = $this->lang->line('admin_restrictions_message_nothing_old_deleted');
     }
     $this->output->set_content_type('application/json');
     $this->output->set_output(json_encode($output));
 }