From 6a0110fb305645f7a44e429d3331e863d615213c Mon Sep 17 00:00:00 2001 From: dfoso Date: Tue, 27 Feb 2024 16:04:35 +0700 Subject: [PATCH] ldap auth added --- app/Config/Boot/development.php | 2 +- app/Controllers/Auth.php | 96 +++++++++++++++++++++++++++++++-- app/Models/Mauth.php | 5 +- app/Models/Mpemby.php | 2 + app/Views/pages/loginv.php | 2 +- app/Views/ppm/dashboard.php | 35 +++++++++--- 6 files changed, 127 insertions(+), 15 deletions(-) diff --git a/app/Config/Boot/development.php b/app/Config/Boot/development.php index a868447a..37dafdc0 100644 --- a/app/Config/Boot/development.php +++ b/app/Config/Boot/development.php @@ -21,7 +21,7 @@ ini_set('display_errors', '1'); | backtraces along with the other error information. If you would | prefer to not see this, set this value to false. */ -defined('SHOW_DEBUG_BACKTRACE') || define('SHOW_DEBUG_BACKTRACE', true); +defined('SHOW_DEBUG_BACKTRACE') || define('SHOW_DEBUG_BACKTRACE', false); /* |-------------------------------------------------------------------------- diff --git a/app/Controllers/Auth.php b/app/Controllers/Auth.php index c50ab538..aa0609f9 100644 --- a/app/Controllers/Auth.php +++ b/app/Controllers/Auth.php @@ -16,11 +16,11 @@ class Auth extends Controller { $session = session(); $model = new Mauth(); - $uname = $this->request->getVar('username'); - $password = $this->request->getVar('password'); + $username = $this->request->getVar('username'); + //$password = $this->request->getVar('password'); + - $param = array('name' => $uname, 'passwd' => $password); - $data = $model->cekuser($param)->getRowArray(); + $data = $model->cekuser($username)->getRowArray(); // var_dump($data); //exit(); if ($data) { @@ -45,6 +45,94 @@ class Auth extends Controller } } + + function ldap_auth() + { + $username = $this->request->getVar('username'); + $password = $this->request->getVar('password'); + $session = session(); + if ($password == "") return redirect()->to(base_url('auth')); + else { + $model = new Mauth(); + $ldaprdn = 'INTRANET' . "\\" . $username; + $adServer = "ldap://10.254.28.141"; + $ldap = ldap_connect($adServer); + ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3); + ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0); + + $bind = @ldap_bind($ldap, $ldaprdn, $password); + + if ($bind) { + $filter = "(&(objectCategory=person)(objectClass=user)(cn={$username}*) )"; + $ldap_base_dn = "OU=Pegawai DJP,DC=intranet,DC=pajak,DC=go,DC=id"; + $result = ldap_search($ldap, $ldap_base_dn, $filter); + $info = ldap_get_entries($ldap, $result); + for ($i = 0; $i < $info["count"]; $i++) { + if ($info['count'] > 1) break; + $_SESSION['usr'] = $username; + $_SESSION['nama'] = $info[$i]["displayname"][0]; + $_SESSION['nip'] = $info[$i]["employeenumber"][0]; + } + @ldap_close($ldap); + + $data = $model->cekuser($username)->getRowArray(); + $ses_data = [ + 'nip' => $data['NIP9'], + 'nipp' => $data['NIP18'], + 'nama' => $data['NAMA'], + 'kppadm' => $data['KPPADM'], + 'jabatan' => $data['NAMA_JABATAN'], + 'kantor' => $data['NAMA_KANTOR'], + 'seksi' => $data['NAMA_UNIT_ES3'], + 'isLogin' => true + ]; + $session->set($ses_data); + return redirect()->to(base_url('Home')); + } else { + $ldaprdn = 'INTRANET' . "\\" . $username; + $adServer = "ldap://10.254.28.142"; + $ldap = ldap_connect($adServer); + ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3); + ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0); + + $bind = @ldap_bind($ldap, $ldaprdn, $password); + + if ($bind) { + $filter = "(&(objectCategory=person)(objectClass=user)(cn={$username}*) )"; + $ldap_base_dn = "OU=Pegawai DJP,DC=intranet,DC=pajak,DC=go,DC=id"; + $result = ldap_search($ldap, $ldap_base_dn, $filter); + $info = ldap_get_entries($ldap, $result); + for ($i = 0; $i < $info["count"]; $i++) { + if ($info['count'] > 1) break; + $_SESSION['usr'] = $username; + $_SESSION['nama'] = $info[$i]["displayname"][0]; + $_SESSION['nip'] = $info[$i]["employeenumber"][0]; + } + @ldap_close($ldap); + + $data = $model->cekuser($username)->getRowArray(); + $ses_data = [ + 'nip' => $data['NIP9'], + 'nipp' => $data['NIP18'], + 'nama' => $data['NAMA'], + 'kppadm' => $data['KPPADM'], + 'jabatan' => $data['NAMA_JABATAN'], + 'kantor' => $data['NAMA_KANTOR'], + 'seksi' => $data['NAMA_UNIT_ES3'], + 'isLogin' => true + ]; + $session->set($ses_data); + return redirect()->to(base_url('Home')); + + // return true; + } else { + return redirect()->to(base_url('auth')); + } + } + } + } + + public function logout() { $session = session(); diff --git a/app/Models/Mauth.php b/app/Models/Mauth.php index 40d2553b..740234ed 100644 --- a/app/Models/Mauth.php +++ b/app/Models/Mauth.php @@ -7,11 +7,10 @@ use CodeIgniter\Model; class Mauth extends Model { - function cekuser($param) + function cekuser($username) { - $uname = $param['name']; $builder = $this->db->table('PEGAWAI'); - $builder->where('NIP9', $uname); + $builder->where('NIP9', $username); return $builder->get(); } } diff --git a/app/Models/Mpemby.php b/app/Models/Mpemby.php index c1cd5e97..4311e030 100644 --- a/app/Models/Mpemby.php +++ b/app/Models/Mpemby.php @@ -37,6 +37,8 @@ class Mpemby extends Model $bln = date('m'); $query = $this->db->query("SELECT CASE WHEN KD_KATEGORI IS NULL THEN '-' ELSE KD_KATEGORI END KODE, CASE WHEN KD_KATEGORI IS NULL THEN 'UNKNOWN' ELSE NM_KATEGORI END NMKAT, + SUM(CASE WHEN THNBYR = '" . $tahun . "' AND BLNBYR = '" . $bln . "' THEN WPBAYAR ELSE 0 END)WPBYRN, + SUM(CASE WHEN THNBYR = '" . $tahunl . "' AND BLNBYR = '" . $bln . "' THEN WPBAYAR ELSE 0 END)WPBYRP, SUM(CASE WHEN THNBYR = '" . $tahun . "' AND BLNBYR = '" . $bln . "' THEN ROUND(TOTAL) ELSE 0 END) KPENN, SUM(CASE WHEN THNBYR = '" . $tahunl . "' AND BLNBYR = '" . $bln . "' THEN ROUND(TOTAL) ELSE 0 END) KPENP FROM PERKATEGORI_MV diff --git a/app/Views/pages/loginv.php b/app/Views/pages/loginv.php index f5e42ea7..aa2ead28 100644 --- a/app/Views/pages/loginv.php +++ b/app/Views/pages/loginv.php @@ -28,7 +28,7 @@ getFlashdata('msg')) : ?>
getFlashdata('msg') ?>
-
+
diff --git a/app/Views/ppm/dashboard.php b/app/Views/ppm/dashboard.php index d5aa40d3..7e00064b 100644 --- a/app/Views/ppm/dashboard.php +++ b/app/Views/ppm/dashboard.php @@ -107,7 +107,9 @@ foreach ($penerimaan as $row) {
-
Strategis
+
+
Strategis
+
Penerimaan
28%
@@ -168,7 +170,9 @@ foreach ($penerimaan as $row) {
-
Kewilayahan
+
+
Kewilayahan
+
Penerimaan
28%
@@ -528,20 +532,39 @@ foreach ($penerimaan as $row) { Kode Kategori - Penerimaan - Penerimaan - Growth (%) + Wp Bayar + Wp Bayar + gw WP Bayar (%) + Realisasi + Realisasi + gw Penerimaan (%) WPBYRN - $row->WPBYRP) / $row->WPBYRP) * 100; $gwkat = (($row->KPENN - $row->KPENP) / $row->KPENP) * 100; + + if ($gwwp < 0) { + $markgww = "text-danger"; + } else { + $markgww = "text-success"; + } + + if ($gwkat < 0) { + $markgwk = "text-danger"; + } else { + $markgwk = "text-success"; + } ?> KODE ?> NMKAT ?> + WPBYRN, 0, ',', '.') ?> + WPBYRP, 0, ',', '.') ?> + KPENN, 0, ',', '.') ?> KPENP, 0, ',', '.') ?> - +