Commit 1ace9ff8 authored by Michael Bailey's avatar Michael Bailey

Add namespace registration

parent 9eecde3f
Pipeline #3342 failed
File added
......@@ -3,7 +3,10 @@ package main
import (
"net"
"encoding/json"
"net/url"
"os"
"net/http"
"strings"
"fmt"
"strconv"
"io/ioutil"
......@@ -12,8 +15,25 @@ import (
type Server struct {
Addr string `json:"address"`
Port int `json:"port"`
Analyst string `json:"namee"`
}
func submit_event(event string, mgmtserver Server, ipaddr string) int {
formData := url.Values{
"event": {event},
"ipaddr": {ipaddr},
"realname": {mgmtserver.Analyst},
}
friendly_port := strconv.Itoa(mgmtserver.Port)
resp, err := http.PostForm("http://"+mgmtserver.Addr+":"+friendly_port+"/register_event.php", formData)
if err != nil {
return 1
}
fmt.Println(resp)
return 0
}
func main() {
addrs, err := net.InterfaceAddrs()
if err != nil {
......@@ -30,13 +50,35 @@ func main() {
os.Exit(1)
}
fmt.Println(mgmtserver)
fmt.Sprintf("Port: %v",mgmtserver.Port);
friendly_port := strconv.Itoa(mgmtserver.Port)
fmt.Println("Configured Port: " + friendly_port)
fmt.Println("Configured Server: " + mgmtserver.Addr)
response, err := http.Get("http://"+mgmtserver.Addr+":"+friendly_port+"/confirm.php")
if err != nil {
fmt.Printf("%s", err)
os.Exit(1)
} else {
defer response.Body.Close()
contents, err := ioutil.ReadAll(response.Body)
if err != nil {
fmt.Printf("%s", err)
os.Exit(1)
}
fmt.Printf("%s\n", string(contents))
}
for _, a := range addrs {
if ipnet, ok := a.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
if ipnet.IP.To4() != nil {
os.Stdout.WriteString(ipnet.IP.String() + "\n")
if strings.HasPrefix(ipnet.IP.String(), "192.") {
submit_event("Register Network Space", mgmtserver, ipnet.IP.String())
} else if strings.HasPrefix(ipnet.IP.String(), "10.") {
submit_event("Register Network Space", mgmtserver, ipnet.IP.String())
} else if strings.HasPrefix(ipnet.IP.String(), "172.") {
submit_event("Register Network Space", mgmtserver, ipnet.IP.String())
}
}
}
}
......
{"port":8888,"address":"172.31.1.1", "name": "Michael Sawgrass"}
{"port":8888,"address":"172.31.1.1" }
FROM fauria/lamp
RUN rm -rf /var/www/html/*
ADD app/run-lamp.sh /usr/sbin/run-lamp.sh
RUN chmod +x /usr/sbin/run-lamp.sh
ADD app/data.sql /opt/db.sql
ADD app /var/www/html/
CMD ["/usr/sbin/run-lamp.sh"]
<?php
var_dump($_SERVER);
\ No newline at end of file
<?php
echo(shell_exec("mysql -uroot < /opt/data.sql"));
?>
\ No newline at end of file
CREATE DATABASE ccdc;
USE ccdc;
CREATE TABLE register_events (
ID int NOT NULL AUTO_INCREMENT,
event varchar(10000),
ipaddr varchar(255),
realname varchar(255),
PRIMARY KEY (ID)
);
USE mysql;
update user set password=PASSWORD("root") where User='root';
FLUSH PRIVILEGES;
\ No newline at end of file
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$servername = "localhost";
$username = "ccdc";
$password = "ccdc";
$dbname = "ccdc";
$link = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$statement = $link->prepare('INSERT INTO register_events (event, ipaddr, realname)
VALUES (:event, :ipaddr, :realname)');
$statement->execute([
'event' => $_POST["event"],
'ipaddr' => $_POST["ipaddr"],
'realname' => $_POST["realname"]
]);
?>
\ No newline at end of file
#!/bin/bash
function exportBoolean {
if [ "${!1}" = "**Boolean**" ]; then
export ${1}=''
else
export ${1}='Yes.'
fi
}
exportBoolean LOG_STDOUT
exportBoolean LOG_STDERR
if [ $LOG_STDERR ]; then
/bin/ln -sf /dev/stderr /var/log/apache2/error.log
else
LOG_STDERR='No.'
fi
if [ $ALLOW_OVERRIDE == 'All' ]; then
/bin/sed -i 's/AllowOverride\ None/AllowOverride\ All/g' /etc/apache2/apache2.conf
fi
if [ $LOG_LEVEL != 'warn' ]; then
/bin/sed -i "s/LogLevel\ warn/LogLevel\ ${LOG_LEVEL}/g" /etc/apache2/apache2.conf
fi
# enable php short tags:
/bin/sed -i "s/short_open_tag\ \=\ Off/short_open_tag\ \=\ On/g" /etc/php/7.0/apache2/php.ini
# stdout server info:
if [ ! $LOG_STDOUT ]; then
cat << EOB
**********************************************
* *
* Docker image: fauria/lamp *
* https://github.com/fauria/docker-lamp *
* *
**********************************************
SERVER SETTINGS
---------------
· Redirect Apache access_log to STDOUT [LOG_STDOUT]: No.
· Redirect Apache error_log to STDERR [LOG_STDERR]: $LOG_STDERR
· Log Level [LOG_LEVEL]: $LOG_LEVEL
· Allow override [ALLOW_OVERRIDE]: $ALLOW_OVERRIDE
· PHP date timezone [DATE_TIMEZONE]: $DATE_TIMEZONE
EOB
else
/bin/ln -sf /dev/stdout /var/log/apache2/access.log
fi
# Set PHP timezone
/bin/sed -i "s/\;date\.timezone\ \=/date\.timezone\ \=\ ${DATE_TIMEZONE}/" /etc/php/7.0/apache2/php.ini
# Run Postfix
/usr/sbin/postfix start
# Run MariaDB
/usr/bin/mysqld_safe --timezone=${DATE_TIMEZONE}&
while [ true ]; do
mysql -uroot < /opt/db.sql
if [ $? -eq 0 ]; then
echo INSERTED
mysql -uroot -e "CREATE USER ccdc@localhost IDENTIFIED BY 'ccdc';"
mysql -uroot -e "GRANT ALL PRIVILEGES ON ccdc.* TO 'ccdc'@'localhost';"
mysql -uroot -e "FLUSH PRIVILEGES;"
break
fi
sleep 1
done
# Run Apache:
if [ $LOG_LEVEL == 'debug' ]; then
/usr/sbin/apachectl -DFOREGROUND -k start -e debug
else
&>/dev/null /usr/sbin/apachectl -DFOREGROUND -k start
fi
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment