Last active
February 6, 2017 14:16
-
-
Save nakamkaz/901a082d39eebe56e811417656100bbe to your computer and use it in GitHub Desktop.
WebベースのIPアドレス管理帳を作る ref: http://qiita.com/nakamkaz/items/34d69667572e809d0dfd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BEGIN { | |
gensql(10,10,3); | |
gensql(10,10,140); | |
} | |
function gensql(oct1,oct2,oct3){ | |
for (i=1;i<=254;i++) { | |
printf("insert into IPADDRESS (ADDRESS,DECIMAL_ADDRESS) values ('%s.%s.%s.%i',%i);\n",oct1,oct2,oct3,i,decip(oct1,oct2,oct3,i)); | |
} | |
} | |
function decip(o1,o2,o3,o4){ | |
return 254*254*254*o1+254*254*o2+254*o3+o4; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE `IPADDRESS` ( | |
`ADDRESS` VARCHAR(16) NOT NULL, | |
`DECIMAL_ADDRESS` INT(10) UNSIGNED NOT NULL DEFAULT '0', | |
`DESCRIPTION` VARCHAR(50) NOT NULL DEFAULT 'not assigned', | |
PRIMARY KEY (`DECIMAL_ADDRESS`) | |
) | |
ENGINE=InnoDB | |
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# yum install mariadb httpd php mariadb-server php-pdo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# systemctl start mariadb httpd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MariaDB [(none)]> show databases; | |
+--------------------+ | |
| Database | | |
+--------------------+ | |
| information_schema | | |
| mgmtsheet | | |
| mysql | | |
| performance_schema | | |
+--------------------+ | |
4 rows in set (0.00 sec) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MariaDB [mgmtsheet]> show tables; | |
Empty set (0.00 sec) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MariaDB [(none)]> use mgmtsheet | |
Reading table information for completion of table and column names | |
You can turn off this feature to get a quicker startup with -A | |
Database changed | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE `IPADDRESS` ( | |
`ADDRESS` VARCHAR(16) NOT NULL, | |
`DECIMAL_ADDRESS` INT(10) UNSIGNED NOT NULL DEFAULT '0', | |
`DESCRIPTION` VARCHAR(50) NOT NULL DEFAULT 'not assigned', | |
PRIMARY KEY (`DECIMAL_ADDRESS`) | |
) | |
ENGINE=InnoDB | |
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MariaDB [mgmtsheet]> show tables; | |
+---------------------+ | |
| Tables_in_mgmtsheet | | |
+---------------------+ | |
| IPADDRESS | | |
+---------------------+ | |
1 row in set (0.00 sec) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MariaDB [mgmtsheet]> desc IPADDRESS; | |
+-----------------+------------------+------+-----+--------------+-------+ | |
| Field | Type | Null | Key | Default | Extra | | |
+-----------------+------------------+------+-----+--------------+-------+ | |
| ADDRESS | varchar(16) | NO | | NULL | | | |
| DECIMAL_ADDRESS | int(10) unsigned | NO | PRI | 0 | | | |
| DESCRIPTION | varchar(50) | NO | | not assigned | | | |
+-----------------+------------------+------+-----+--------------+-------+ | |
3 rows in set (0.01 sec) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MariaDB [(none)]> create user 'lab' identified by 'labpass' ; | |
MariaDB [(none)]> grant SELECT,UPDATE ON mgmtsheet.* TO 'lab' ; | |
Query OK, 0 rows affected (0.00 sec) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MariaDB [(none)]> select user,host from mysql.user; | |
+------+-----------+ | |
| user | host | | |
+------+-----------+ | |
| lab | % | | |
| root | 127.0.0.1 | | |
| root | ::1 | | |
| root | localhost | | |
+------+-----------+ | |
4 rows in set (0.00 sec) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# gawk -f dotdecip.awk > alladdr.sql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# systemctl enable mariadb httpd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# mysql -uroot -p mgmtsheet < alladdr.sql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MariaDB [mgmtsheet]> select * from mgmtsheet.IPADDRESS; | |
+---------------+-----------------+--------------+ | |
| ADDRESS | DECIMAL_ADDRESS | DESCRIPTION | | |
+---------------+-----------------+-------------+ | |
| 10.10.3.1 | 164516563 | not assigned | | |
| 10.10.3.2 | 164516564 | not assigned | | |
| 10.10.3.3 | 164516565 | not assigned | | |
| 10.10.3.4 | 164516566 | not assigned | | |
| 10.10.3.5 | 164516567 | not assigned | | |
... | |
| 10.10.140.249 | 164551609 | not assigned | | |
| 10.10.140.250 | 164551610 | not assigned | | |
| 10.10.140.251 | 164551611 | not assigned | | |
| 10.10.140.252 | 164551612 | not assigned | | |
| 10.10.140.253 | 164551613 | not assigned | | |
| 10.10.140.254 | 164551614 | not assigned | | |
+---------------+-----------------+--------------+ | |
508 rows in set (0.00 sec) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# cd /var/www/html/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# wget https://github.com/vrana/adminer/releases/download/v4.2.5/editor-4.2.5-mysql-en.php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# mv editor-4.2.5-mysql-en.php editor.php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# firewall-cmd --add-service=http --permanent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# systemctl stop firewalld |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# firewall-cmd --add-service=http |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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, we'll need the current | |
password for the root user. If you've just installed MariaDB, and | |
you haven't 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): | |
OK, successfully used password, moving on... | |
Setting the root password ensures that nobody can log into the MariaDB | |
root user without the proper authorisation. | |
You already have a root password set, so you can safely answer 'n'. | |
Change the root password? [Y/n] | |
New password: | |
Re-enter new 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] | |
... 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] | |
... 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] | |
- 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] | |
... Success! | |
Cleaning up... | |
All done! If you've completed all of the above steps, your MariaDB | |
installation should now be secure. | |
Thanks for using MariaDB! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# mysql -uroot -p |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MariaDB [(none)]> | |
MariaDB [(none)]> select user,host from mysql.user; | |
+------+-----------+ | |
| user | host | | |
+------+-----------+ | |
| root | 127.0.0.1 | | |
| root | ::1 | | |
| root | localhost | | |
+------+-----------+ | |
3 rows in set (0.00 sec) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MariaDB [(none)]> show databases; | |
+--------------------+ | |
| Database | | |
+--------------------+ | |
| information_schema | | |
| mysql | | |
| performance_schema | | |
+--------------------+ | |
3 rows in set (0.00 sec) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MariaDB [(none)]> create database mgmtsheet; | |
> Query OK, 1 row affected (0.00 sec) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<table border="1"> | |
<tr> <th>IPADDRESS</th> <th>DESCRIPTION</th> | |
<?php | |
$dsn = 'mysql:dbname=mgmtsheet;host=localhost'; | |
$user = 'lab'; | |
$password = 'labpass'; | |
try{ | |
$dbh = new PDO($dsn, $user, $password); | |
$sql = 'select ADDRESS,DECIMAL_ADDRESS,DESCRIPTION from IPADDRESS ORDER BY DECIMAL_ADDRESS'; | |
foreach ($dbh->query($sql) as $row) { | |
print('<tr>'); | |
print('<td>'); | |
print('<a href="/editor.php?username=lab&edit=IPADDRESS&where[DECIMAL_ADDRESS]='.$row['DECIMAL_ADDRESS'].'">'); | |
print($row['ADDRESS'].'</a></td>'); | |
print('<td>'.$row['DESCRIPTION'].'</td>'); | |
print('</tr>'); | |
} | |
}catch (PDOException $e){ | |
print('Error:'.$e->getMessage()); | |
die(); | |
} | |
$dbh = null; | |
?> | |
</table> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment