Minggu, 10 Desember 2023

Change log-bin position replication slave MySQL

Master Configuration on the Slave

In order to configure the slave to communicate with the master for replication, set up the slave with the required connection information. The following statements will need to be executed to accomplish the same.

mysql> CHANGE MASTER TO

-> MASTER_HOST='master_host_name',

-> MASTER_USER='replication_user_name',

-> MASTER_PASSWORD='replication_password',

-> MASTER_LOG_FILE='recorded_log_file_name',

-> MASTER_LOG_POS=recorded_log_position;
 
https://hevodata.com/learn/mysql-binlog-based-replication/ 

Senin, 25 September 2023

Repaire engine mysql (MyIsam) crash file

login to shell and run script like this 

~# myisamchk -r /var/lib/mysql/mysql/db.MYI

db.MYI -> example only

Kamis, 21 September 2023

Enable Support for TLS 1.2 or 1.3 on Web Browsers

 Enable Support for TLS 1.2 or 1.3 on Web Browsers

In keeping with security best practices, the University is requiring the use of current web browsers to ensure continued access to University web services—including Pitt Passport.

Older web browsers use out-of-date protocols that do not support modern encryption and contain security vulnerabilities that can be exploited by attackers. Effective July 1, 2021, only web browsers that support versions 1.2 or 1.3 of the Transport Layer Security (TLS) protocol will be permitted to access University web services. Browsers that use TLS version 1.0 or 1.1 will not be supported. 

To ensure your web browser supports TLS 1.2 or 1.3, complete the steps below. 

Microsoft Edge

TLS 1.2 is automatically enabled in all versions of Microsoft Edge. 

Google Chrome

TLS 1.2 is automatically enabled in Google Chrome version 29 or greater.

Apple Safari

TLS 1.2 is automatically enabled in Safari version 7 or greater.

Mozilla Firefox

TLS 1.2 is automatically enabled in Firefox version 27 or greater.

To enforce TLS version 1.3 in Firefox, complete the steps below. 

1. Open Firefox.

2. In the address bar, type about:config and press Enter.

3. In the Search field, enter tls. Find and double click the entry for security.tls.version.max.

4. Set the integer value to 4 to force a maximum protocol of TLS 1.3.

5. Click OK.

6. Close your browser and restart Mozilla Firefox.

Microsoft Internet Explorer

1. Open Internet Explorer.

2. From the menu bar, click Tools, then Internet Options, then click the Advanced tab.

3. Scroll down to the Security category and manually check the box next to Use TLS 1.2.

4. Click OK.

5. Close your browser and restart Internet Explorer.

sumber : https://www.technology.pitt.edu/help-desk/how-to-documents/enable-support-tls-12-or-13-web-browsers

Kamis, 17 Agustus 2023

CURL with post field Code Igniter

 public function getDataToCsv(){
    $data = array();

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

    $url = 'http://[domain]/app/api/getData';
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 0);
    curl_setopt($ch, CURLOPT_POSTFIELDS, 'f_kode='.$kode);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $result = curl_exec($ch);

    curl_close($ch);

    if($result){

        $json_decoded= json_decode($result,true);
        $fileName = date('YmdHis').'.csv';
        $csv = '/var/www/html/app/file/csv/'.$fileName;
        $file_pointer = fopen($csv, 'w');
        foreach($json_decoded['data'] as $i){
            fputcsv($file_pointer, $i);
        }
        fclose($file_pointer);
        $data['result'] = true;
        $data['file_name']=$fileName;
        $data['msg']='Export to '.$fileName.' success';
    }else{
        $data['result']=false;
        $data['msg']='Tidak ada data';
    }
    echo json_encode($data);
}

Decode data from JSON encode Code Igniter

function doSendNotifBirthDay(){
    $data = array();
    $dataz = array();

    $this->db->select('warga_id,warga_nama,warga_tgl_lahir,warga_telepon,warga_photo');
    $this->db->where('DATE_FORMAT(warga_tgl_lahir,"%d-%m")','DATE_FORMAT(CURDATE(),"%d-%m")',FALSE);
    $this->db->where('warga_jenis',1);
    $this->db->where('warga_status',1);

    $q = $this->db->get('data_warga');

    if($q->num_rows > 0){
        $data['result']=true;
        $data['data']=$q->result();
    }else{
        $data['result']=false;
        $data['msg']='data tidak ditemukan';
    }

    $result = json_encode($data);
    $json_decoded = json_decode($result,true);

    if($q->num_rows > 0){

        $dataz['result']=true;
        $dataz['msg']='data ditemukan';

        foreach ($json_decoded['data'] as $row){
            $nama  = $row['warga_nama'];
            $phone = $row['warga_telepon'];

            $isi ='Barakallahu fii umrik *'.$nama.'*, bertambah satu tahun lagi usiamu hari ini *'.$this->thisDay().'*, tanggal *'.date('d').' '.$this->thisMonth().' '.date('Y').'* dan hanya doa yang bisa kami haturkan. Semoga Allah memberikan kesehatan, rezeki yang melimpah dan kesuksesan, serta umur panjang. Dan tak lupa, semoga selalu diberi keberkahan Allahuma Aamiin...🤲'."\n\n".';

            $simpan['phone']=$phone;
            $simpan['pesan']=$isi;
            $simpan['id_users']='139';
            $this->db->insert('wa_outbox',$simpan);
        }
    }else{
        $dataz['result']=false;
        $dataz['msg']='data tidak ditemukan';
    }
    echo json_encode($dataz);
}

function thisDay(){
    $day = date ("D");

    switch($day){
        case 'Sun':
            $hari_ini = "Minggu";
        break;

        case 'Mon':         
            $hari_ini = "Senin";
        break;

        case 'Tue':
            $hari_ini = "Selasa";
        break;

        case 'Wed':
            $hari_ini = "Rabu";
        break;

        case 'Thu':
            $hari_ini = "Kamis";
        break;

        case 'Fri':
            $hari_ini = "Jumat";
        break;

        case 'Sat':
            $hari_ini = "Sabtu";
        break;
        
        default:
            $hari_ini = "Tidak di ketahui";     
        break;
    }
    return $hari_ini;
}

function thisMonth(){
    $month = date("m");

    switch($month){
        case '01':
            $month = "Januari";
        break;

        case '02':         
            $month = "Februari";
        break;

        case '03':
            $month = "Maret";
        break;

        case '04':
            $month = "April";
        break;

        case '05':
            $month = "Mei";
        break;

        case '06':
            $month = "Juni";
        break;

        case '07':
            $month = "Juli";
        break;
        case '08':
            $month = "Agustus";
        break;
        case '09':
            $month = "September";
        break;
        case '10':
            $month = "Oktober";
        break;
        case '11':
            $month = "November";
        break;
        case '12':
            $month = "Desember";
        break;
        default:
            $month = "Unknow";     
        break;
    }
    return $month;
}  

Convert JSON file into CSV in PHP

<?php
   
// Student JSON data
$jsondata
  '[
   {"student":"sravan kumar","age":22,"subject":"java"},
   {"student":"ojaswi","age":21,"subject":"java"},
   {"student":"rohith","age":22,"subject":"dbms"},
   {"student":"bobby","age":22,"subject":"sql"}]';
   
// Decode json data and convert it
// into an associative array
$jsonans = json_decode($jsondata, true);
   
// CSV file name => geeks.csv
$csv = 'geeks.csv';
   
// File pointer in writable mode
$file_pointer = fopen($csv, 'w');
   
// Traverse through the associative
// array using for each loop
foreach($jsonans as $i){
      
    // Write the data to the CSV file
    fputcsv($file_pointer, $i);
}
   
// Close the file pointer.
fclose($file_pointer);
  
?>
 
sumber : https://www.geeksforgeeks.org/how-to-convert-json-file-into-csv-in-php/

Manage user MySQL 5.1 Command line

#create user
CREATE USER 'user'@'localhost' IDENTIFIED BY 'Passwordxxx**';
GRANT SELECT, LOCK TABLES, CREATE, DROP, INSERT, UPDATE, EVENT ON * . * TO 'user'@'localhost';
FLUSH PRIVILEGES;

#drop user
DROP user 'user'@'localhost';

#change password user MySql
SET PASSWORD FOR 'user'@'localhost' = PASSWORD('user@localhost234#');    #mysql under 8
ALTER USER 'user'@'localhost' IDENTIFIED BY 'user'@localhost234#';    #mysql 8

#change definer
UPDATE `mysql`.`proc` p SET definer = 'user@%' WHERE definer='user@%' AND db='dbname';

#show grant for user
SHOW GRANTS FOR 'user'@'localhost;

#dump procedure only
mysqldump --single-transaction -u username -p db > db.sql

#find definer
select v.TABLE_SCHEMA, v.TABLE_NAME, v.`DEFINER`
from information_schema.VIEWS v
where v.TABLE_SCHEMA not in ('sys');

#revoke user
REVOKE DELETE ON `dbname`.* FROM 'user'@'localhost';
FLUSH PRIVILEGES;

#grant procedure or function only
GRANT EXECUTE ON PROCEDURE `dbname`.`procName` TO 'user'@'localhost';
GRANT EXECUTE ON FUNCTION `dbname`.`funcName` TO 'user'@'localhost';
FLUSH PRIVILEGES;