2017年5月23日 星期二

excel 資料轉成 ldif 格式

table 2:(虛擬資料)
userid username pwd
1XXXXXX7 吳鳳 2db22x01e5375ad4dc027abbc256231c

table 1:
C2=="dn: cn="&A2&D$2&B2&E$2&MID(B2,1,1)&F$2
**********************************************************
A2     B2   C2
1XXXXXX7 吳鳳 dn: cn=1XXXXXX7,ou=user,ou=login,dc=nttu,dc=edu,dc=tw
cn: 吳鳳
objectclass: inetOrgPerson
objectclass: top
objectclass: person
sn: 吳
userpassword: {SSHA}exxxxxxxxxxxxxxxxxxxxxxxxxxxxG/s

D2                   E2

,ou=user,ou=login,dc=nttu,dc=edu,dc=tw
cn: 

objectclass: inetOrgPerson
objectclass: top
objectclass: person
sn: 

F2


userpassword: {SSHA}xxxxxxxxxxxxxxxxxxxxxxxxxxxxx/s

**********************************************************
1.複製A2~Axxxxx
2.貼到 notepad++中
3.利用搜尋 # 取代 (無) ~消掉 #

注意事項,每筆資料都要空一行,空行不能有空白資料,最後一行空行要刪除
參數與值中間要空一格(參數: 值)

cn: (帳號,不能為空值)
objectclass: inetOrgPerson (必備)
objectclass: top (必備)
objectclass: person (必備)
sn: (姓,不能為空值)
givenName: (名子,不能為空值)






CentOS 7 安裝新版 Git 2.13.0

Git:
  網址:https://github.com/git/git
  最新版本:https://github.com/git/git/releases (目前最新為 2.13.0)

經網路上查詢,發現 yum 的 Git 版本只有到 1.8.3.1,經安裝也確是如此,經網路上教學手動安裝,安裝過程做下列紀錄,方便以後查詢!^_^

目前 Git 官方已經更新到 2.13.0 ,所以移除原先 yum 安裝的1.8.3.1 版,手動下載 2.13.0 版,並安裝編譯。

1. 查看 yum 的 Git 信息:

# yum info git

2. 編譯依賴套件安裝

# yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
# yum install  gcc perl-ExtUtils-MakeMaker

3. 移除已安裝低版本的 Git

利用:git –-version 查看系統帶的版本,Git 版本是: 1.8.3.1,所以先要卸载低版本的 Git:

# yum remove git

4. 下载新版的 Git 原始碼包

# wget https://github.com/git/git/archive/v2.13.0.tar.gz
也可以離線下載,再傳到 CentOS7 系统中指定的目錄下面。

5. 解壓縮到指定的目錄 (git-2.13.0)

# tar -xzvf v2.13.0.tar.gz

6. 安裝 Git

分別執行以下命令進行編譯安裝,編譯過程有點久,要耐心等候完成。

# cd git-2.13.0
# make prefix=/usr/local/git all
# make prefix=/usr/local/git install

7. 添加到環境變數

# echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/bashrc
# source /etc/bashrc # 立刻生效

8. 檢查 Git 版本號碼

# git --version
git version 2.13.0
安裝到這裡,目前 CentOS7 已經安裝上了最新的 Git 版本。

2017年5月19日 星期五

設定 visual studio code 的 angular 4 開發環境(TypeScript)

調整開發方向
語言:
TypeScript
angular 4
node.js (npm)
HTML5
CSS3

編輯器:
Visual Studio Code

安裝開發環境
1.下載並安裝 node.js
  https://nodejs.org/en/
  下載 穩定正式版 v6.10.3 LTS

2.下載並安裝 Visual Studio Code
  https://code.visualstudio.com/
  版本更新很快,下載最新的版本即可
  
3.下載並安裝 Angular 4.0
  https://angular.io/
  GET STARTED => QuickStart seed => download => Download the QuickStart seed
  下載後的檔名為:quickstart-master.zip

解壓縮 quickstart-master.zip 到 c:\htdocs\quickstart

開啟 Node.js command prompt

>cd\ c:\htdocs\quickstart
>npm install
>npm start

開啟 Visual Studio Code 編輯器
開啟 c:\htdocs\quickstart\quickstart 資料夾

首頁資料在 \src\app\app.component.ts
設定資料在 \src\app\app.module.ts



src
app
app.component.ts
app.module.ts
main.ts
src\app\app.component.ts
import { Component } from '@angular/core';

@Component({
  selector: 'my-app',
  template: `<h1>Hello {{name}}</h1>`
})
export class AppComponent { name = 'Angular'; }
src\app\app.module.ts
import { NgModule }      from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent }  from './app.component';

@NgModule({
  imports:      [ BrowserModule ],
  declarations: [ AppComponent ],
  bootstrap:    [ AppComponent ]
})
export class AppModule { }
src\main.ts
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule }              from './app/app.module';

platformBrowserDynamic().bootstrapModule(AppModule);


===========================================================
Visual Studio Code 編輯器,增加擴充模組 (Ctrl + P)

Angular v4 TypeScript Snippets
  https://marketplace.visualstudio.com/items?itemName=johnpapa.Angular2

Angular 4 and TypeScript/HTML VS Code Snippets
  https://marketplace.visualstudio.com/items?itemName=danwahlin.angular2-snippets
  ext install angular2-snippets

Bracket Pair Colorizer (支架顏色)
  https://marketplace.visualstudio.com/items?itemName=CoenraadS.bracket-pair-colorizer
  ext install bracket-pair-colorizer

IntelliSense for CSS class names (適用於使用項目的可用類名快速裝飾HTML。不幸的是,類名稱沒有作用於組件的文件夾。)
  https://marketplace.visualstudio.com/items?itemName=Zignd.html-css-class-completion
  ext install html-css-class-completion

Angular 2 TypeScript Emmet (如果你還沒有學到Emmet,那絕對是你的腰帶。此插件允許您直接在組件模板中使用語法。)
  https://marketplace.visualstudio.com/items?itemName=jakethashi.vscode-angular2-emmet
  ext install vscode-angular2-emmet

angular2-inline(模板中為CSS和HTML提供語法高亮。)
  https://marketplace.visualstudio.com/items?itemName=natewallace.angular2-inline
  ext install angular2-inline

angular2-switcher
通過三個簡單的鍵綁定快速切換組件,模板和样式。
還支持通過在光標變量時按F12來定義模板變量。
  https://marketplace.visualstudio.com/items?itemName=infinity1207.angular2-switcher
  ext install angular2-switcher

vscode-icons
最好的圖標包在那裡!特徵用於管道,指令,組件,模塊,路由和服務的角色特定圖標。美化文件瀏覽器!:)
  https://marketplace.visualstudio.com/items?itemName=robertohuertasm.vscode-icons
  ext install vscode-icons

TSLint
如果你不要打印TypeScript,你應該開始,特別是在codelyzer。這個插件讓你看起來很簡單,看看你的TypeScript代碼中的問題。甚至提供自動修復!
  https://marketplace.visualstudio.com/items?itemName=eg2.tslint
  ext install tslint

Angular 2+ Snippets - TypeScript, Html, ngRx, Angular Flex Layout & Testing
這是我見過的最全面的片段包。它具有67個不同的片段。
  https://marketplace.visualstudio.com/items?itemName=Mikael.Angular-BeastCode
  ext install Angular-BeastCode

TypeScript Hero
此插件管理導入語句,並可以自動導入缺少的依賴項。可以組織和排序導入。
  https://marketplace.visualstudio.com/items?itemName=rbbit.typescript-hero
  ext install typescript-hero

Path Intellisense
如果有一個插件,你添加確保它是這個。此插件啟用自動完成文件路徑,這在處理導入語句時提供了巨大的提升。
  https://marketplace.visualstudio.com/items?itemName=christian-kohler.path-intellisense
  ext install path-intellisense









2017年5月17日 星期三

LDAP GUI 管理介面

LDAP Server 架好了,但要用指令新增、刪除、修改,快瘋了!>_<
後來發現居然有 GUI 介面的管理程式,以下簡列,未來會補上操作介面!
一、JXplorer – A Java Ldap Browser
  http://sourceforge.net/projects/jxplorer/
  居然有中文管理介面,真是佛心
  支援多平台(windows 10可用)
  


二、Ldap Admin
  http://sourceforge.net/projects/ldapadmin/
  只有英文
  支援多平台(windows 10可用)
  他這邊有一個自動幫我捉取 Base DNs 的功能,只要我們輸入 Host 的 IP 之後,就可以直接點選 "Fetch DNs" 直接幫我們找出 LDAP Server 的 Base DNs.設定完成之後還可以測試一下 "Test connection"
  


三、phpldapadmin (PHP)
  必須在網頁端執行
  
  


目前3支程式我都有在使用,很方便!^_^


下面有空來研究
Apache Directory Project (ApacheDS) Apache 出的 LDAP 架設、管理專案
http://directory.apache.org/

2017年5月12日 星期五

CentOS7 架設 LDAP Server 流程

弄了好幾天了,總算把LDAP Server架起來了。
網路上的講義與資料都有不同的陷阱,白忙好久。
又找不到人問~心好冷。
原來我都是在本機VM的CentOS測試,沒有DNS網域指定,一直到登入那關就卡住了。
今天一橫,把LDAP Server 改架在有DNS的主機,終於一次OK。
這種障礙突破,總是會讓人特別開心!^_^

整理一下指令方便自己以後參考:

資料來源:臺中市105年度中小學學務系統升級暨資安建置研習手冊(沈俊達)



說明 LDAP 架構
嘗試規劃完整LDAP組織圖,這裡會說明一些LDAP的設計方式及表示法

LDAP架構圖





這裡說明一下 LDAP 主要的簡稱含義:
DIT(Directory Information Tree;目錄資訊樹)
o - organization (組織)
ou - organization unit (組織單位-部門)
c - country Name (國家)
dc - domain Component (域名)
sn - suer name (真實姓名)
cn - common name (使用者名稱)
dn - Distinguish Name (識別名稱)

修改slapd.conf
suffix "dc=mp,dc=nttu,dc=edu,dc=tw"
rootdn "cn=username,dc=mp,dc=nttu,dc=edu,dc=tw"

表示法
表示出towns在LDAP的唯一識別名稱(DN)
cn=username, cn=cy, cn=unit, cn=company, dc=mp,dc=nttu,dc=edu,dc=tw
LDAP的識別方式與DNS類似,由小排大

這個部分依照需求設定的,哆啦胖虎大的設定為一個通用的設定哦!
註:其實整個目錄樹並不一定需要這麼長,其中OU的部分只是在做組織分類,如果是一家大公司分為這麼多部門,這麼做可以清楚分類,如果只是小公司(10人以下)或是測試用,大可不設OU直接就設CN,也就是這麼設定 cn=username, dc=mp,dc=nttu,dc=edu,dc=tw,其實整個DN只要能有效區別唯一性,就可以了。

2017年5月11日 星期四

mobile 網站 CentOS7 設定過程

#yum -y update

#yum --enablerepo=extras install epel-release

#wget http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

#rpm -Uvh remi-release-7*.rpm

#yum repolist

#yum install dkms

#yum install openssl openssh*

#cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak

用vim打开配置文件/etc/ssh/sshd_config
#vim /etc/ssh/sshd_config
Port 8022 // 更改 SSH Port 22 為其他 Port (防止掃瞄Port)
Protocol 2 // use Protocol 2
PermitRootLogin no // 不允許 root 登入 SSH
PermitEmptyPasswords no // 不允許空白密碼
AllowUsers sysadmin godspeed // 指定可以登入 SSH 的帳號,若有多個帳號可以登入,就用空格隔開
UseDNS no // 關閉 DNS反查 (加快登入速度)
GSSAPIAuthentication no // 關閉 IP 反查和 GSS API auth, SSH 預設連線模式會進行 IP反查及GSS API auth,所以會花掉一些時間等待查詢,很多Linux服務都會設定反查,不用特別關閉也沒關係。
#Subsystem sftp /usr/libexec/openssh/sftp-server 
Subsystem sftp internal-sftp 
Match Group sftponly (Group 可更改為 User 針對單一帳號)
    ChrootDirectory /home/%u // 鎖定登入者家目錄
    X11Forwording no
    AllowTcpForwarding no

    ForceCommand internal-sftp
将上图的PermitRootLogin,RSAAuthentication,PubkeyAuthentication的设置打开。

啟動SSH的服務
#systemctl start sshd.service

設置開機啟動 SSH
#systemctl enable sshd.service

設定完後要重啟 SSH 服務才會生效
#systemctl restart sshd.service (/etc/rc.d/init.d/sshd restart)

設定開機啟動 SSH
#systemctl enable sshd.service

設定防火牆
#firewall-cmd --permanent --zone=public --add-port=8022/tcp

重新載入防火牆規則
#firewall-cmd --reload
#setsebool -P nis_enabled 1


透過 netstat 指令來確認重啟後的 SSH 服務是否以 Port 8022 來接受連線
$ netstat -ant | grep :8022

SSH 可以使用 SSH -vvv 來 debug

$ ssh -vvv 192.168.1.20

安裝 PuTTY 0.69
下載:https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html

==============================================================
安裝 xrdp
#rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-1.el7.nux.noarch.rpm

#yum -y install xrdp tigervnc-server

#systemctl start xrdp.service

#netstat -antup | grep xrdp

#systemctl enable xrdp.service

#firewall-cmd --permanent --zone=public --add-port=3389/tcp

#firewall-cmd --reload
===============================================================
新增使用者帳號:
#adduser username

新增使用者密碼:
#passwd username

給予使用者 sudo 權限(將使用者加入 wheel 群組):
# gpasswd -a username wheel
Adding user username to group wheel

列出 wheel 群組裡的使用者名稱與 UIDs:
# lid -g wheel


刪除使用者:
當刪除使用者時,如果只想刪除使用者,並保留使用者的檔案,輸入下列指令:
# userdel username

 如果刪除使用者時,想要連同使用者的所有檔案都一併刪除,則輸入下列指令:
# userdel -r username

將使用者於群組裡移除:
# gpasswd -d username groupname
Removing user username from group groupname






RHEL 7 安裝 XRDP, 讓 Windows 用遠端桌面連線登入(適用於 CentOS 7)

資料來源:https://nscodes.com/install-lamp-centos-7-x-apache-php-7-x-sql-mariadb-10-x-phpmyadmin-2017/


在CentOS 7.x(Apache,PHP 7.x,SQL MariaDB 10.x,phpMyAdmin)2017上安裝LAMP


本指南介紹如何在CentOS 7系統上安裝LAMP(Linux,Apache,MySQL,PHP)堆棧。在本教程中,我將向您展示如何安裝最新版本的php(PHP 7.1),MySQL(MariaDB 10.1),phpMyAdmin(4.6.6)和Apache。本安裝指南僅適用於CentOS 7.x。
LAMP是Web服務堆棧的原型模型,被稱為原始四個開源組件的名稱的縮寫:Linux操作系統,Apache HTTP Server,MySQL關係數據庫管理系統(RDBMS)和PHP編程語言。LAMP組件在很大程度上是可互換的,不限於原始選擇。作為解決方案堆棧,LAMP適用於構建動態網站和Web應用程序。
服務器更新

1.1更新服務器
yum -y update
1.2安裝EPEL存儲庫
yum -y install epel-release
1.3。安裝REMI存儲庫
wget http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
rpm -Uvh remi-release-7*.rpm
1.4。驗證EPEL Repo
yum repolist

安裝MySQL(MariaDB)服務器

2.1創建MariaDB repo
vi /etc/yum.repos.d/MariaDB.repo
2.2。添加MariaDB YUM存儲庫在添加yum存儲庫
之前,請確保10.1是最新版本的MariaDB
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
2.3。啟用REMI存儲庫(更改enabled = 0 啟用= 1)
vi /etc/yum.repos.d/remi.repo

樣品輸出
[remi]
name=Remis RPM repository for Enterprise Linux 7 - $basearch
#baseurl=http://rpms.remirepo.net/enterprise/7/remi/$basearch/
#mirrorlist=https://rpms.remirepo.net/enterprise/7/remi/httpsmirror
mirrorlist=http://rpms.remirepo.net/enterprise/7/remi/mirror
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
2.4。安裝MySQL(MariaDB)
yum -y install mariadb-server mariadb
2.5。啟動MySQL(MariaDB)
systemctl start mariadb.service
2.6。創建MySQL(MariaDB)的系統啟動鏈接,以在系統啟動時自動啟動MySQL(MariaDB)
systemctl enable mariadb.service
2.7設置MySQL(MariaDB)root帳戶的密碼:
mysql_secure_installation
樣品輸出
# mysql_secure_installation #
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, well need the current password for the root user. If youve just installed MariaDB, and you havent set the root password yet, the password will be blank, so you should just press enter here.
Enter current password for root (enter for none): (just press enter here) OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorisation.
Set root password? [Y/n] (just press enter here) New password: (enter new root SQL password) Re-enter new password: (re-enter new root SQL password) Password updated successfully! Reloading privilege tables.. ... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment.
Remove anonymous users? [Y/n] (just press enter here) ... Success!
Normally, root should only be allowed to connect from localhost. This ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] (just press enter here) ... Success!
By default, MariaDB comes with a database named test that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment.
Remove test database and access to it? [Y/n] (just press enter here) - Dropping test database... ... Success! - Removing privileges on test database... ... Success!
Reloading the privilege tables will ensure that all changes made so far will take effect immediately.
Reload privilege tables now? [Y/n] (just press enter here) ... Success!
Cleaning up...
All done! If youve completed all of the above steps, your MariaDB installation should now be secure.
Thanks for using MariaDB!

安裝Apache Web服務器

3.1安裝Apache
yum -y install httpd
3.2啟動Apache Web服務器
systemctl start httpd.service
3.3。創建httpd的系統啟動鏈接,在系統啟動時自動啟動httpd
systemctl enable httpd.service
3.4。CentOS 7.X使用防火牆CMD,因此您必須對其進行自定義,以允許外部訪問端口80(http)和443(https)。如果你想留在IP表上,這個步驟。
systemctl start firewalld
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload
3.5確保Apache服務器正在運行:http://your.server.ip.adders/
PHP 7.1安裝

4.1。確保remi-php71.repo在那裡
ls /etc/yum.repos.d

smple輸出
CentOS-Base.repo       CentOS-Vault.repo      remi-php54.repo
CentOS-CR.repo         CentOS-fasttrack.repo  remi-php70.repo
CentOS-Debuginfo.repo  MariaDB.repo           remi-php71.repo
CentOS-Media.repo      epel-testing.repo      remi-safe.repo
CentOS-Sources.repo    epel.repo              remi.repo
4.2啟用php7.1的REMI存儲庫(更改enabled = 0 啟用= 1)
vi /etc/yum.repos.d/remi-php71.repo

樣品輸出
[remi-php71]
name=Remis PHP 7.1 RPM repository for Enterprise Linux 7 - $basearch
#baseurl=http://rpms.remirepo.net/enterprise/7/php71/$basearch/
#mirrorlist=https://rpms.remirepo.net/enterprise/7/php71/httpsmirror
mirrorlist=http://rpms.remirepo.net/enterprise/7/php71/mirror
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
4.3。安裝PHP
yum -y install php
4.4。為PHP7安裝MySQL支持
yum -y install php-mysql
4.5您可以安裝CMS系統(如WordPress,Joomla和Drupal)所需的常見PHP模塊
yum -y install php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel
4.6。重新啟動Apache:
systemctl restart httpd.service
4.7。我們來測試一下:創建php信息文件
vi /var/www/html/info.php

添加以下行到info.php
<?php
  phpinfo();
  phpinfo(INFO_MODULES);
?>
確保PHP工作,php模塊在那裡http://your.server.ip.address/info.php
phpMyAdmin安裝

5.1。安裝phpMyAdmin。phpMyAdmin是一個Web界面,您可以通過它來管理MySQL數據庫。
yum install phpMyAdmin
5.2我們更改Apache配置,以便phpMyAdmin不僅允許從localhost進行連接。
vi /etc/httpd/conf.d/phpMyAdmin.conf
添加以下行:
<Directory /usr/share/phpMyAdmin/>
        Options none
        AllowOverride Limit
        Require all granted
</Directory>
樣品輸出
# phpMyAdmin - Web based MySQL browser written in php
#
# Allows only localhost by default
#
# But allowing phpMyAdmin to anyone other than localhost should be considered
# dangerous unless properly secured by SSL
Alias /phpMyAdmin /usr/share/phpMyAdmin Alias /phpmyadmin /usr/share/phpMyAdmin
<Directory /usr/share/phpMyAdmin/> AddDefaultCharset UTF-8
<IfModule mod_authz_core.c> # Apache 2.4 Require local </IfModule> <IfModule !mod_authz_core.c> # Apache 2.2 Order Deny,Allow Deny from All Allow from 127.0.0.1 Allow from ::1 </IfModule> </Directory>
<Directory /usr/share/phpMyAdmin/> Options none AllowOverride Limit Require all granted </Directory>
5.3將phpMyAdmin config.inc.php中的身份驗證從cookie更改為http:
vi /etc/phpMyAdmin/config.inc.php

smple輸出
[...]
/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'http';
/* Server parameters */
[...]
5.4重新啟動Apache:
systemctl restart httpd.service
5.5確保phpMyAdmin工作。轉到http://your.server.ip.address/phpmyadmin/ 
登錄名:root,密碼在步驟2.7中添加的內容
恭喜,你完成了!🙂
使用的來源:
https : //www.apache.org/ 
http://php.net/ 
https://www.phpmyadmin.net/ 
https://mariadb.org/

cas server 一直圈圈或取得狀態異常

重點: cas server 不能開 VPN,會造成取的來源 dns 異常,會一直轉圈圈或等很久。