Skip to content

Commit

Permalink
Merge pull request #174 from opennetadmin/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
mattpascoe authored May 30, 2023
2 parents 0ab7fd7 + 8b0bb17 commit 5270ea3
Show file tree
Hide file tree
Showing 409 changed files with 53,335 additions and 17,933 deletions.
22 changes: 22 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM mcr.microsoft.com/devcontainers/php:0-8.0

# Install MariaDB client
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get install -y mariadb-client \
&& apt-get clean -y && rm -rf /var/lib/apt/lists/*

# Install php-mysql driver
RUN docker-php-ext-install mysqli pdo pdo_mysql

RUN [ ! -d /var/www/html/ona ] && ln -fs /workspace/ona/www /var/www/html/ona
RUN apache2ctl start

# run php install/installcli.php and set 127.0.0.1

# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>

# [Optional] Uncomment this line to install global node packages.
# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1

2 changes: 2 additions & 0 deletions .devcontainer/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
I'm not sure that I will continue with the .devcontainer testing. I will
leave it here for the time being.
29 changes: 29 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/php-mariadb
{
"name": "PHP & MariaDB",
"dockerComposeFile": "docker-compose.yml",
"service": "app",
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// For use with PHP or Apache (e.g.php -S localhost:8080 or apache2ctl start)
"forwardPorts": [
8080,
3306
],
"features": {
"ghcr.io/devcontainers-contrib/features/neofetch:1": {}
}

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "sudo chmod a+x \"$(pwd)\" && sudo rm -rf /var/www/html && sudo ln -s \"$(pwd)\" /var/www/html"

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
36 changes: 36 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
version: '3.8'

services:
app:
build:
context: .
dockerfile: Dockerfile

volumes:
- ../..:/workspaces:cached

# Overrides default command so things don't shut down after the process ends.
command: sleep infinity

# Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
network_mode: service:db

# Use "forwardPorts" in **devcontainer.json** to forward an app port locally.
# (Adding the "ports" property to this file will not forward from a Codespace.)

db:
image: mariadb:10.4
restart: unless-stopped
volumes:
- mariadb-data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: mariadb
MYSQL_DATABASE: mariadb
MYSQL_USER: mariadb
MYSQL_PASSWORD: mariadb

# Add "forwardPorts": ["3306"] to **devcontainer.json** to forward MariaDB locally.
# (Adding the "ports" property to this file will not forward from a Codespace.)

volumes:
mariadb-data:
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,13 @@ www/*.htm
cfg_archive_local

spool

*.log

.vagrant
.DS_Store

# ignore vim swap files
*.swp

.gitignore
59 changes: 59 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# This Dockerfile is intended for development and testing purposes only. Not
# recommended for production use.
#
# First: Build an image with a specific version of Ubuntu and tag it as such.
# docker build --build-arg UBUNTU_VERSION=23.04 -t ona-dev:23.04 .
#
# Second: Start the container for general use. Point your browser to http://localhost/ona
# docker run -p 80:80 -it ona-dev:23.04
#
# OR
#
# Start the container for development. Mount the current directory as a volume
# This will allow you to edit the files on your host and have them be hosted
# in the container
# docker run -p 80:80 -it -v $(pwd):/opt/ona ona-dev:23.04
#
# This assumes you are in the directory you cloned the ONA repo into.
# Also, if you have already installed this prior, you may need to remove
# www/local/config/database_settings.conf.php to get the install to run again.

ARG UBUNTU_VERSION=latest
FROM ubuntu:${UBUNTU_VERSION}

LABEL description="OpenNetAdmin development and testing docker image"
LABEL Author="Matt Pascoe <[email protected]>"

ENV TZ=UTC
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

RUN apt-get update
RUN apt-get -y install git mariadb-server apache2 php-yaml php-gmp php-mysql libapache2-mod-php php-mbstring php-xml unzip vim sendemail jq curl && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

RUN git -C /opt clone https://github.com/opennetadmin/ona.git -b develop

ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2

RUN ln -sf /opt/ona/www /var/www/html/ona
RUN rm -f /var/www/html/index.html

RUN touch /var/log/ona.log
RUN chmod 666 /var/log/ona.log

RUN chown www-data /opt/ona/www/local/config

# Start as mariadb or mysql depending on version of Ubuntu.
RUN service mariadb start || service mysql start

RUN echo '/opt/ona' > /etc/onabase
RUN echo "\n\n\n"|php /opt/ona/install/installcli.php
RUN echo "ServerName ona-dev.localhost" > /etc/apache2/conf-enabled/servername.conf

EXPOSE 80

# Since we are running mysql and apache, start them both. Also runs initial install.
CMD bash -c 'service mariadb start || service mysql start && echo "\n\n\n"|php /opt/ona/install/installcli.php && /usr/sbin/apache2ctl -D FOREGROUND'
57 changes: 53 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ Thanks for your interest in OpenNetAdmin!
---

Each host or subnet can be tracked via a centralized AJAX enabled web interface
that can help reduce errors. A full [CLI interface](https://github.com/opennetadmin/dcm) is available
as well to use for scripting and bulk work. We hope to provide a useful
Network Management application for managing your IP subnets and hosts.
Stop using spreadsheets to manage your network! Start doing proper IP
that can help reduce errors. A full [CLI interface](https://github.com/opennetadmin/dcm) is available
as well to use for scripting and bulk work. We hope to provide a useful
Network Management application for managing your IP subnets and hosts.
Stop using spreadsheets to manage your network! Start doing proper IP
address management!

![desktop image](https://github.com/opennetadmin/ona/wiki/images/desktop.png)
Expand All @@ -32,6 +32,55 @@ your web server to serve out `/opt/ona/www`. Open it in your web browser and ru

Please refer to the [install page on the Github Wiki for more detail](https://github.com/opennetadmin/ona/wiki/Install)

DEVELOPMENT
-----------
You can interact with either Docker or Vagrant. Docker is is the preferred
method at this time.

## Docker

Once you have cloned the repo you can issue
The Dockerfile is intended for development and testing purposes only. It is not recommended for production use.

First: Build an image with a specific version of Ubuntu and tag it as such.
```
docker build --build-arg UBUNTU_VERSION=23.04 -t ona-dev:23.04 .
```

Second: Start the container for general use. Point your browser to http://localhost/ona
```
docker run -p 80:80 -it ona-dev:23.04
```

OR

Start the container for development. Mount the current directory as a volume. This will allow you to edit the files on your host and have them be hosted in the container
```
docker run -p 80:80 -it -v $(pwd):/opt/ona ona-dev:23.04
```

This assumes you are in the directory you cloned the ONA repo into.
Also, if you have already installed this prior, you may need to remove `www/local/config/database_settings.conf.php` to get the install to run again.


## Vagrant

Simply clone this repo and issue a vagrant up to get a basic working system to develop with.
You will need to have git and [vagrant](https://vagrantup.com) installed on your system

git clone https://github.com/opennetadmin/ona.git
cd ona
vagrant up

## Postman

There is a postman collection in the `docs` directory that can be used to interact with the API. An environment file is also provided that can be used. Simply import the collection and environment into postman or use Newman to run the collection from the command line.

A simple usage would be:
```
cd /opt/ona
newman run docs/ONA-dcm.postman_collection.json -e docs/ONA-dcm-dev.postman_environment.json
```

CONTACT
-------
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v18.1.1
v19.0.0
84 changes: 84 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

# Allow user to pass in a different web port forward value.
# Use when you are running multiple vms on one system
PORTNUM = ENV["PORTNUM"] || "10000"

Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/jammy64"

# Assign this VM to a bridged network, allowing you to connect directly to a
# network using the host's network device. This makes the VM appear as another
# physical device on your network.
# Uncomment the following if you want this VM to have its own IP
#config.vm.network :bridged

# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:10000" will access port 80 on the guest machine.
# NOTE: This will enable public access to the opened port
config.vm.network "forwarded_port", guest: 80, host: PORTNUM , auto_correct: false

# Set up our repo as a synced folder
config.vm.synced_folder ".", "/opt/ona"

# The basic install script
$script = <<-SCRIPT
#------- Start provision --------
PORTNUM=$1
# Tell apt to quit its whining
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get install -y \
curl \
apache2 \
mariadb-server \
php \
php-mysql \
php-mbstring \
php-gmp \
php-pear \
libapache2-mod-php \
libyaml-dev \
libio-socket-ssl-perl
# Link in our ona code
[ ! -d /var/www/html/ona ] && ln -fs /opt/ona/www /var/www/html/ona
# Allow others to see apache logs (and probably other stuff)
#usermod -a -G adm www-data
#usermod -a -G adm vagrant
# Set up application log file
if [ ! -f /var/log/ona.log ]
then
touch /var/log/ona.log
chmod 666 /var/log/ona.log
fi
# restart apache so it picks up changes
systemctl restart apache2.service
# Clean out any old configs
# Re-running the provisioner will wipe out any previous configs
rm -f /opt/ona/www/local/config/database_settings.inc.php
# Run the CLI installer with all default options
echo "\n\n\n"|php /opt/ona/install/installcli.php
echo "
Please point your browser to: http://localhost:${PORTNUM}/ona
"
#------- End provision --------
SCRIPT

# Run our shell provisioner
config.vm.provision "shell", inline: $script, :args => [ PORTNUM ]

end
File renamed without changes.
68 changes: 68 additions & 0 deletions docs/ONA-dcm-dev.postman_environment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"id": "1c834988-d66c-2969-ffb4-33ccbb1b32cb",
"name": "Dev",
"values": [
{
"key": "URL",
"value": "http://127.0.0.1",
"type": "text",
"enabled": true
},
{
"key": "DCM_URL",
"value": "{{URL}}/ona/dcm.php",
"type": "default",
"enabled": true
},
{
"key": "format",
"value": "json",
"enabled": true
},
{
"key": "username",
"value": "admin",
"type": "text",
"enabled": true
},
{
"key": "password",
"value": "admin",
"type": "text",
"enabled": true
},
{
"key": "netname",
"value": "LAN-EXAMPLE",
"type": "text",
"enabled": true
},
{
"key": "netip",
"value": "1.1.1.0",
"type": "default",
"enabled": true
},
{
"key": "netmask",
"value": "/24",
"type": "default",
"enabled": true
},
{
"key": "domainname",
"value": "example.com",
"type": "text",
"enabled": true
},
{
"key": "host",
"value": "host.{{domainname}}",
"type": "text",
"enabled": true
}
],
"_postman_variable_scope": "environment",
"_postman_exported_at": "2023-05-27T05:16:49.996Z",
"_postman_exported_using": "Postman/10.14.4"
}
Loading

0 comments on commit 5270ea3

Please sign in to comment.