Uname:Linux EDL-STRETCH 4.19.0-27-amd64 #1 SMP Debian 4.19.316-1 (2024-06-25) x86_64

403WebShell
403Webshell
Server IP : 188.114.96.2  /  Your IP : 104.23.197.231
Web Server : Apache/2.4.59 (Debian)
System : Linux EDL-STRETCH 4.19.0-27-amd64 #1 SMP Debian 4.19.316-1 (2024-06-25) x86_64
User : edlftp ( 1002)
PHP Version : 7.4.33
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /home/nicolasj/www/sms.formationlangues.be/application/controllers/BO/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /home/nicolasj/www/sms.formationlangues.be/application/controllers/BO/Admin_Users.php
<?php
/*********************
 *********************

 Aernout Guillaume
 https://codes.solutions
 *********************
 *********************/
 if (!defined('BASEPATH'))
   exit('No direct script access allowed');

  class Admin_Users extends NS_Controller {
    function __construct() {
      parent::__construct(array('no_cache'=>1));

      if ($this->session->userdata('admin_login') != 1){
        $this->error('restricted admin');
        //$this->redirect(base_url(), 'refresh');
      }
       $this->load->helper('generator');
       $this->load->model('crud_model');
       $this->load->model('mbox_model');
       $this->load->model('users_model');
       $this->load->model('notification_model');
       $this->load->database();

    }
    function index(){
      //$sql = $this->db->get_where('admin_lesson',array('id'=>'1'))->result_array();
      //var_dump($sql[0]);

      $data['page_name'] = 'admin_users';
      $data['page_title'] = get_phrase('admin_users');
      $data['user_list'] = $this->crud_model->get_user_list();
      $data['rules'] = $this->crud_model->get_notification_rules();
      $this->load->view('backend/index',  $data);
    }

    function push_user(){
        $this->continueIfAllowed(array('allowed'=>array('admin')));
        $data = $this->input->post(array('email','email2','role','firstname','name'));


        $sql = array(
          'role_id' => $data['role'],
          'email' => $data['email'],
          'email_notification' => $data['email2'],
          'first_name' => $data['firstname'],
          'is_active' => '1',
          'is_final' => '1',
          'last_name' => $data['name']
        );

        $this->db->insert('user',$this->crud_model->cleanArray($sql));
        $id = $this->db->insert_id();

        $data =  array(
          'id' => $id,
          'user' => $data['firstname']." ".$data['name'],
          'email1' => $data['email'],
          'email2' => $data['email2'],
          'role_id' => $data['role'],
          'role' => $this->crud_model->get_user_role($data['role'])
        );
        echo json_encode($data);
    }

    function push_rule(){
        $this->continueIfAllowed(array('allowed'=>array('admin')));
        $data = $this->input->post(array('rule','way','range_d','range_h','email','email_type','target'));


        if($data['target'] != "#"){

          $course_name = $this->crud_model->get_course_name($data['target']);

          if($data['email'] == '#'){
            //generate email with the course
            $email_sender =  $this->mbox_model->generate_mail($data['target']);
            //create mbox + routing if exist
            $this->mbox_model->create_mbox($email_sender);
            $this->mbox_model->create_alias($email_sender,$email_sender);

            //set course list info
            $sqlSms = array(
                  'Mail_ID' => $id_mail,
                  'Option_ID' => '1',
                  'Course_ID' => $course_id
                ); // mail reffer to course id
            $this->db->insert('Mail',$this->crud_model->cleanArray($sqlSms));
            $mail_sms_id = $this->db->insert_id();

          }
          else{
            $email_sender = $this->notification_model->get_notification_sender_mail($data['email']);
          }

          //insert only for one course
          $sql = array(
            'Rule_type' => $data['rule'],
            'Rule_way' => $data['way'],
            'Range_d' => $data['range_d'],
            'Range_h' => $data['range_h'],
            'Rule_sender' => $email_sender,
            'Rule_mail_type' => $data['email_type'],
            'Rule_target' => $data['target']
          );

          $this->db->insert('notification_rules',$this->crud_model->cleanArray($sql));
          $id = $this->db->insert_id();


          $data_json =  array(
            'id' => $id,
            'Rule_type' => $this->notification_model->get_notification_type_name($data['rule']),
            'Rule_way' => $data['way'],
            'Range_d' => $data['range_d'],
            'Range_h' => $data['range_h'],
            'Rule_sender' => $email_sender,
            'Rule_mail_type' =>  $data['email_type'],
            'Rule_target' => $course_name
          );
          echo json_encode($data_json);
        }
        else{
          //push for each courses
          //insert blocked for debug

          $courses = $this->crud_model->get_courses();
          $data_json = array();
          foreach ($courses as $key => $course) {
            $course_id = $course['ID'];
            $course_name = $this->crud_model->get_course_name($course_id);

            if($data['email'] == '#'){
              //generate email with the course
              $email_sender =  $this->mbox_model->generate_mail($course_id);
              //create mbox + routing if exist
            //  $id_mail = $this->mbox_model->create_mbox($email_sender);
            //  $this->mbox_model->create_alias($email_sender,$email_sender);
            /*  $sqlSms = array(
                  'Mail_ID' => $id_mail,
                  'Option_ID' => '1',
                  'Course_ID' => $course_id
                ); // mail reffer to course id
                $this->db->insert('Mail',$sqlSms);
                $mail_sms_id = $this->db->insert_id();
            */
            }
            else{
              $email_sender = $this->notification_model->get_notification_sender_mail($data['email']);
            }

            //insert only for this course
            $sql = array(
              'Rule_type' => $data['rule'],
              'Rule_way' => $data['way'],
              'Range_d' => $data['range_d'],
              'Range_h' => $data['range_h'],
              'Rule_sender' => $email_sender,
              'Rule_mail_type' => $data['email_type'],
              'Rule_target' => $course_id
            );

            //$this->db->insert('notification_rules',$sql);
            $id = '999';//$this->db->insert_id();

            $data_json_current =  array(
              'id' => $id,
              'Rule_type' => $this->notification_model->get_notification_type_name($data['rule']),
              'Rule_way' => $data['way'],
              'Range_d' => $data['range_d'],
              'Range_h' => $data['range_h'],
              'Rule_sender' => $email_sender,
              'Rule_mail_type' =>  $data['email_type'],
              'Rule_target' => $course_name
            );
            array_push($data_json,$data_json_current);
          }
          echo json_encode($data_json);
        }
    }

    function debug(){
      echo "loaded";
      var_dump($this->mbox_model->create_mbox("[email protected]"));
      var_dump($this->mbox_model->create_alias("[email protected]","[email protected]"));
    //  $this->mbox_model->create_alias($email_sender,$email_sender);
    }

    function pull_user(){
      $this->continueIfAllowed(array('allowed'=>array('admin')));
      $id = $this->input->post('id');

      $this->db->delete('user',array('user_id'=>$id));
      echo "1";
    }
    function pull_rule(){
      $this->continueIfAllowed(array('allowed'=>array('admin')));
      $id = $this->input->post('id');

      $this->db->delete('notification_rules',array('ID'=>$id));
      echo "1";
    }
    function switch_user(){
      $this->continueIfAllowed(array('allowed'=>array('admin')));
      $id = $this->input->post('id');
      $role = $this->input->post('role');

      $role = $role+1;
      if($role > 6){
        $role = 1;
      }

      $sql = array(
        'role_id' => $role
      );

      $this->db->set($sql);
      $this->db->where('user_id',$id);
      $this->db->update('user');

      $role = array('role_id' => $role, 'role' => $this->crud_model->get_user_role($role));

      if($this->users_model->checkUserType($id,$role)){
        //echo "creation";
        //check if profile already created
        $address = $this->users_model->find_address($id);
        $dob = $this->users_model->find_dob($id);
        //echo "$address";
        //get previous address_id from invited or not
        switch ($role) {
          //echo "creation $role";
          case '2':
            //teacher
            $this->users_model->create_teacher($id,$address,'manual switch user',$dob,'');
            break;
          case '3':
            //parent
            $this->users_model->create_parent($id,$address,'manual switch user','');
            break;
          case '4':
            //student
            $this->users_model->create_student($id,$address,'manual switch user',$dob,'');
            break;

          default:
          //
            break;
        }
      }
      echo json_encode($role);
    }

    function update_user(){
      $this->continueIfAllowed(array('allowed'=>array('admin')));

      $id = $this->input->post('id');

      $element = $this->input->post('element');
      $element_data = $this->input->post('element_data');

      $sql = array(
        $element => $element_data
      );
      $this->db->set($sql);
      $this->db->where('user_id',$id);
      $this->db->update('user');
      echo "done";
    }

    function cron_check_rules(){
      $rules = $this->crud_model->get_notification_rules();
      foreach ($rules as $key => $rule) {
         $target = $rule['Rule_target'];
         if($target == "#"){ // skip better solution
           /*
           $now = date('Y-m-d');
           $courses = $this->crud_model->get_courses_on_period(date('Y-m-d',strtotime($now.'-30 days')),date('Y-m-d',strtotime($now.'+30 days')));
           foreach ($courses as $key => $course) {
             $this->check_lessons($course,$rule['Range_h'],$rule['Range_d'],$rule['Rule_way'],$rule['Rule_type'],$rule['Rule_mail_type'],$rule['Rule_sender']);
           }
           */
         }
         else{
           echo "targeting>> $target <br>";
           $this->check_lessons($target,$rule['Range_h'],$rule['Range_d'],$rule['Rule_way'],$rule['Rule_type'],$rule['Rule_mail_type'],$rule['Rule_sender']);
         }
      }
      echo "Done √";
    }


    function check_lessons($id,$limit_h,$limit_d,$way,$type,$mail_type,$mail_sender){
      //$id = '310'; $limit_h = "2"; $limit_d = "5"; $way= "Before"; $type = "1"; $mail_type = "notification"; $mail_sender = "#";

      $lessons = $this->crud_model->get_course_scheduled($id);
      foreach ($lessons as $key => $lesson) {

          echo ">>".$lesson['LessonDate']."<< <br>";
          $now = date('Y-m-d H:m:s');
          $nowInt = strtotime($now);

          if($way == "Before"){
            $limit_date = strtotime($lesson['LessonDate'].' '.$lesson['LessonStart']);
            $target = strtotime($lesson['LessonDate'].' '.$lesson['LessonStart'].' - '.$limit_h.' hours -'.$limit_d.' days');

            echo "[BEFORE rule :]$nowInt >= $target && $nowInt <= $limit_date <br>";
            echo date('Y-m-d H:m:s',$nowInt)." >= ".date('Y-m-d H:m:s',$target) ."&&". date('Y-m-d H:m:s',$nowInt)." <= ".date('Y-m-d H:m:s',$limit_date)." <br><br>";

            if( date('Y-m-d H:m:s',$nowInt) >= date('Y-m-d H:m:s',$target) && date('Y-m-d H:m:s',$nowInt) <= date('Y-m-d H:m:s',$limit_date)){
                echo "notification for ". $lesson['ID'] ." : ".$lesson['LessonDate']."<br>";
                if($type == "1"){
                    //presence notification
                    if($lesson['LessonLocked'] == '0' || $lesson['LessonLocked'] == NULL){
                      //can't notify if not yet do
                      //var_dump($this->notification_model->notify_presence($lesson['ID'],$mail_type,$mail_sender));
                      //return;
                    }
                }
                else if($type == "2"){
                  if($lesson['LessonNotified'] == '0' || $lesson['LessonNotified'] == NULL){
                    echo "to notify!";
                    var_dump($this->notification_model->notify_course_start($lesson['ID'],$mail_type,$mail_sender));
                    return;
                  }
                }
                else{}


            }
          }
          else{
            //$limit_date = strtotime($lesson['LessonDate'].' '.$lesson['LessonEnd']);
            $target = strtotime($lesson['LessonDate'].' '.$lesson['LessonEnd'].' + '.$limit_h.' hours +'.$limit_d.' days');


            //echo "$nowInt >= $target<br>";
            //echo date('Y-m-d H:m:s',$nowInt)." >= ".date('Y-m-d H:m:s',$target) ."<br><br>";

            if( date('Y-m-d H:m:s',$nowInt) >= date('Y-m-d H:m:s',$target)){
                  echo "[After rule :]notification for ". $lesson['ID'] ." : ".$lesson['LessonDate']."<br>";
                  if($type == "1"){
                      //presence notification
                      if($lesson['LessonLocked'] == '0' || $lesson['LessonLocked'] == NULL){
                        var_dump($this->notification_model->notify_presence($lesson['ID'],$mail_type,$mail_sender));
                        return;
                      }
                  }
                  else if($type == "2"){
                    if($lesson['LessonNotified'] == '0' || $lesson['LessonNotified'] == NULL){
                      //can't notify course start if already passed
                      //var_dump($this->notification_model->notify_course_start($lesson['ID'],$mail_type,$mail_sender));
                      //  return;
                    }
                  }
                  else{

                  }

            }

        }
      }
    }
  }

Youez - 2016 - github.com/yon3zu
LinuXploit