Windows SMBv1の無効化/有効化
WannaCry対応の一環でSMBv1を無効化したものの、某社製のNASがSMBv1を使用していたことが発覚、切り戻した。
その1 SMB1を無効化する場合
【Win8.1、Win10】
PowerShellを管理者権限で起動し、以下を実行
①SMBv1がシステムにインストール済みか確認する
PS C:\> Get-WindowsOptionalFeature -Online -FeatureName SMB1Protocol | Select-Object State
State
-----
Enabled ……「Enabled」MBv1はインストール済み
②SMBv1をシステムから削除する
PS C:\> Disable-WindowsOptionalFeature -Online -FeatureName SMB1Protocol -NoRestart
警告: NoRestart が指定されているため、再起動は抑制されています。
Path :
Online : True
RestartNeeded : True ……「True」ならシステムの再起動が必要。「False」なら不要
③再起動後、①を再実行し確認
Disable になっていればSMB1はシステムから削除済み
その2 無効化したSMB1を有効化する場合
【Win8.1、Win10】
①SMBv1をインストール
PS C:\> Enable-WindowsOptionalFeature -Online -FeatureName SMB1Protocol
②再起動後、確認(前述の①と同じ)
PS C:\> Get-WindowsOptionalFeature -Online -FeatureName SMB1Protocol | Select-Object State
PythonからCisco機器にTelnet接続してみました ~その1~
Cisco Aironet に MACアドレスを登録する処理を半自動化してみたく、Pythonを使ってみました。
まずは Python で Telnet接続し、簡単なCiscoコマンドを発行してみます。
実装環境
Pythonのバージョンは 3.6.1を使用
Ciscoのプロンプトは通常下記。
User Access Verification Password:
import getpass import telnetlib HOST = '192.168.xxx.xxx' password = getpass.getpass() tn = telnetlib.Telnet(HOST) if password: tn.read_until(b'Password: ') tn.write(password.encode('ascii') + b'\n') # Ciscoコマンド発行 tn.write(b'show clock' + b'\n') tn.write(b'exit' + b'\n') # read_until以降のテキストを出力 print(tn.read_all().decode('ascii'))
実行結果は以下の通り。
Password: <手入力> router>show clock Load for five secs: 0%/0%; one minute: 0%; five minutes: 0% Time source is SNTP, 18:55:19.232 JST Tue Jun 27 2017 18:55:19.232 JST Tue Jun 27 2017 router>exit
CodeIgniterのhelperを使ってCSSやJSなどのPATHを生成する
環境:
CSSとJSのディレクトリはCodeigniterのルートディレクトリに配置しています。
codeigniter_root/
|
|-application/
|
|-css/
|
|-js/
|
|-system/
|
コントローラ側の記述例
application/controller/Hoge.php
<?php class Hoge extends CI_Controller { public function __construct() { parent::__construct(); } function index(){ //helperでURL PATHを取得する $this->load->helper('url'); $this->load->view('hoge_view'); } } ?>
Codeigniterのindex.php
Codeigniterの初期状態は、URLに「index.php」を含む設定になっています。
環境:Codeigniter-3.1.4
URL例)
example.com/index.php/news/article/my_article
[参考]Codeigniter公式
CodeIgniter の URL — CodeIgniter 3.2.0-dev ドキュメント
index.phpと同じ階層に.htaccessを設置し、除外ルールを記述することでURLから「index.php」を省略してアクセスすることができます。
URLから「index.php」を取り除きたい場合は以下の通りです。
Apacheの設定
.htaccessの読み込みが有効になっていることを確認
AllowOverride 「None」の場合は「All」に変更してApacheを再起動する
# # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # AllowOverride All
.htaccessの編集
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.php/$1 [L]
config.phpの編集
application/config/config.phpの[index_page]を''に変更
/* |-------------------------------------------------------------------------- | Index File |-------------------------------------------------------------------------- | | Typically this will be your index.php file, unless you've renamed it to | something else. If you are using mod_rewrite to remove the page set this | variable so that it is blank. | */ $config['index_page'] = '';