<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE rdf:RDF
[
<!ENTITY % HTMLlat1 PUBLIC
 "-//W3C//ENTITIES Latin 1 for XHTML//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent">
]>
<rdf:RDF xmlns="http://purl.org/rss/1.0/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:admin="http://webns.net/mvcb/">
<channel rdf:about="http://localhost/please/edit/me/index.xml">
<title>CSIM Technical Notes</title>
<link>http://localhost/please/edit/me</link>
<description>Technical notes on how to operate CSIM infrastructure</description>
<dc:language>en-us</dc:language>
<dc:creator>Olivier</dc:creator>
<dc:date>2024-08-15T11:25:37+07:00</dc:date>
<admin:generatorAgent rdf:resource="http://nanoblogger.sourceforge.net" />
<items>
<rdf:Seq>
<rdf:li rdf:resource="http://localhost/please/edit/me/archives/2023/11/16/using_out_of_band_connection_to_csim/index.html" />
<rdf:li rdf:resource="http://localhost/please/edit/me/archives/2023/07/13/zeroshell_v3_9_5_is_lazy_to_reload_rules/index.html" />
<rdf:li rdf:resource="http://localhost/please/edit/me/archives/2023/07/03/print_quota_synchronization/index.html" />
<rdf:li rdf:resource="http://localhost/please/edit/me/archives/2023/06/13/migration_of_zeroshell_firewall/index.html" />
<rdf:li rdf:resource="http://localhost/please/edit/me/archives/2023/06/09/another_way_to_shutdown_all_the_systems/index.html" />
<rdf:li rdf:resource="http://localhost/please/edit/me/archives/2023/05/05/some_issues_with_amanda/index.html" />
<rdf:li rdf:resource="http://localhost/please/edit/me/archives/2023/05/02/about_firewall_certificate/index.html" />
<rdf:li rdf:resource="http://localhost/please/edit/me/archives/2023/02/23/change_redis_owner_after_update_on_mail_server/index.html" />
<rdf:li rdf:resource="http://localhost/please/edit/me/archives/2023/02/16/managing_vpn_certificates/index.html" />
<rdf:li rdf:resource="http://localhost/please/edit/me/archives/2022/09/29/some_stuff_related_vmware_and_ssl_certificates/index.html" />
</rdf:Seq>
</items>
</channel>
<item rdf:about="http://localhost/please/edit/me/archives/2023/11/16/using_out_of_band_connection_to_csim/index.html">
<link>http://localhost/please/edit/me/archives/2023/11/16/using_out_of_band_connection_to_csim/index.html</link>
<title>Using Out of Band connection to CSIM</title>
<dc:date>2023-11-16T11:33:35+07:00</dc:date>
<dc:creator>Olivier</dc:creator>
<dc:subject>administration</dc:subject>
<description>
<![CDATA[<p>
Out of Band (OOB) can be used in a case of an incident where CSIM
router or fireall is unresponsive and need a reboot (like the incident
of November 11th, 2023). It allows to by-pass the router and the
firewall and still gain access to CSIM network.</p>

<h4>Connect to AIT VPN</h4>

   <p>Download AIT VPN configuration from <code>https://helpdesk.ait.ac.th/wp-content/uploads/sites/2/downloads/AIT_Net_vpn_ait_ac_th.ovpn</code></p>

   <p>Connect to AIT VPN with a command like (for Ubuntu):</p>

      <blockquote><tt>sudo openvpn --config AIT_Net_vpn_ait_ac_th.ovpn</tt></blockquote>

   <p>NOTE: You <i>must</i> use your <i>AIT</i> credentials to connect.</p>

  <p> More information about AIT VPN at <tt>https://helpdesk.ait.ac.th/services/ait-vpn/</tt></p>

<h4>Connect to OOB device</h4>

       <blockquote><code>ssh -i &lt;key_file&gt; -p 2222 on@oob-ait.cs.ait.ac.th</code></blockquote>

   <p>NOTE: You <i>must</i> authenticate with a <tt>key_file</tt>.</p>

   <p>NOTE: you <i>must</i> use port <tt>2222</tt>.</p>

   <p>If you need more than a console access, for example if you need to
   access to the GUI of the firewall:</p>

       <blockquote><code>sudo ssh -i <key_file> -p 2222 -L 443:firewall:443 on@oob-ait.cs.ait.ac.th</code></blockquote>

   <p>VMware GUI/vmplayer needs port <tt>443</tt>.</p>

   <p>Proxmox GUI needs port <tt>8006</tt>.</p>

   <p>I don't <i>think</i> you can use CSIM VPN at this stage.</p>

   <p>Because the way iDrac web interface works, you *must* add the name
   of the iDrac interface to /etc/hosts on your local machine, for
   example:</p>
   
      <blockquote><code>127.0.0.1   iDRAC-46VNJJ3.xxx.yyy</code></blockquote>
   <p>and use <tt>https://iDRAC-46VNJJ3.xxx.yyy/</tt> in your web browser.
   [It seems that iDrac web interface expect a header "<tt>host:
   iDRAC-46VNJJ3.xxx.yyy</tt>" or <tt>"host: IP address</tt>" in the HTTP
   request. With normal SSH tunnel, the header used by your browser if
   "<tt>host: 127.0.0.1</tt>" and that causes iDrac to throw a fit.]</p>


   <h4>Create the OOB system</h4>

   <p>Instructions for NanoPi R2S can be find at <code>     https://wiki.friendlyelec.com/wiki/index.php/NanoPi_R2S#Install_OS</code></p>

   <p>Download Debian from the <tt>Google Drive</tt>, <tt>01_Official images</tt>, <tt>01_SD card images.</tt></p>

   <p>The system gets an IP address from DHCP, the exact address can be
   found in DHCP server lease table. The interface labeled LAN is
   connected to CSIM network, the interface labeled WAN is connected
   to AIT network.</p>

   <p>The initial username/password is <tt>pi</tt>/<tt>pi</tt>.</p>

<p>Configure the network in <tt>/etc/network/interfaces</tt>:</p>

     <blockquote><code># interfaces(5) file used by ifup(8) and ifdown(8)</br>
     # Include files from /etc/network/interfaces.d:</br>
     source /etc/network/interfaces.d/*</br>
     auto lo</br>
     iface lo inet loopback</br>
</br>
     auto eth1</br>
     iface eth1 inet static</br>
       address 192.41.170.84</br>
       netmask 255.255.255.0</br>
       #  gateway 192.41.170.23</br>
       dns-domain cs.ait.ac.th</br>
       dns-nameservers 192.41.170.15 192.41.170.30</br>
 </br>
     auto eth0</br>
     iface eth0 inet static</br>
       address 203.159.63.20</br>
       netmask 255.255.255.240</br>
       gateway 203.159.63.17</blockquote></code>
     
   <p>Disable automatic DNS from <tt>/etc/NetworkManager/NetworkManager.conf</tt>:</p>
     <blockquote><code>[main]</br>
     plugins=ifupdown,keyfile</br>
     dns=none</br>
</br>
     [ifupdown]</br>
     managed=true</blockquote></code>

   <p>Configure <tt>/etc/resolv.conf</tt>:</p>
     <blockquote><code>domain  cs.ait.ac.th</br>
     nameserver      192.41.170.15</br>
     nameserver      192.41.170.30</br>
     nameserver      203.159.0.1</blockquote></code>

   <p>Configure <tt>/etc/ntpsec/ntp.conf</tt>: copy from other servers</p>

   <p>Configure <tt>/etc/rsyslog.conf</tt>: at the end of the file add the line:</p>
     <blockquote><code>*.*                             @sysl.cs.ait.ac.th</blockquote></code>

   <p>Create local users, add them to the group <tt>sudo</tt> and delete the user <tt>pi</tt>. Configure their authentication public key.</p>]]>
</description>
</item>
<item rdf:about="http://localhost/please/edit/me/archives/2023/07/13/zeroshell_v3_9_5_is_lazy_to_reload_rules/index.html">
<link>http://localhost/please/edit/me/archives/2023/07/13/zeroshell_v3_9_5_is_lazy_to_reload_rules/index.html</link>
<title>ZeroShell v3.9.5 is lazy to reload rules</title>
<dc:date>2023-07-13T10:02:18+07:00</dc:date>
<dc:creator>Olivier</dc:creator>
<dc:subject>administration, firewall</dc:subject>
<description>
<![CDATA[
<p>
  It seems that the new release of ZeroShell takes quite some time to
  reload the rules once a rule is added or changed. It may take a
  matter of minutes.</p>

<p> Never ever attempt to restart the <tt>iptables</tt> service manually, it would restart the firewall with very limited configuration, leaving the network widely exposed.</p>


<!-- <p> You can rertart <tt>iptables</tt> service manually to speed-up the
  process; ssh to the firewall and use the command:</p>

<pre>
service iptables restart
</pre> -->]]>
</description>
</item>
<item rdf:about="http://localhost/please/edit/me/archives/2023/07/03/print_quota_synchronization/index.html">
<link>http://localhost/please/edit/me/archives/2023/07/03/print_quota_synchronization/index.html</link>
<title>Print quota synchronization</title>
<dc:date>2023-07-03T13:20:18+07:00</dc:date>
<dc:creator>Olivier</dc:creator>
<dc:subject>administration, printing</dc:subject>
<description>
<![CDATA[
<p>AIT has a print from anywhere function working with the software
PaperCut that associate print quota to the users. CSIM also has print
quota. Both system must be synchronized.</p>

<p>The synchronization is set in two steps: once a night around
00:55. PaperCut sends emails to <tt>postmaster@cs.ait.ac.th</tt> with
the detail of the pages printed by the users of each FoS. Then around
10:25 we push the new credit available for each user.</p>


<h4>Synchronization from PaperCut to CSIM</h4>

<p>This is the most tricky part! Once a
night <tt>postmaster@cs.ait.ac.th</tt> receives one email for each of
our FoS. The emails are forwarded to <tt>on@cs.ait.ac.th</tt> and
processed by a procmail receipt that call the
  script <tt>~on/Ldap/procmail-extract-papercut</tt>.</p>

<p>This script checks that the email has a correct contents, that
a <tt>.csv</tt> file is attached with the proper name. The attachment
is saved into a file and the
script <tt>~on/Ldap/do-report-papercut.pl</tt> is called on the
  file.</p>

<p>The second script is more complicated. As reports are sent once a
night, if one report is lost, some data is missing. The script keeps
track of the last report that has been processed in the
file <tt>~on/Ldap/timestamp-papercut.db</tt>. There is one timestamp
for each FoS.</p>

<p>Daily reports are covering the period from 00:00:00 to 23:59:59 the
previous day. So every new report should start exactly one second after
the previous one. The period covered by a report is written in the
headers of the <tt>.csv</tt> file.</p>

<p>The script takes into account gaps in the report coverage as well
as overlaps. If an error occurs in the period sequence, the file is
not processed; instead, an email is generated that highlight the
conflict and suggest to generate a report manually, the manual report
  can then be processed by that same script.</p>

<p>Once the period of the report has been validated, the print usage
  for the users listed in the report are updated accordingly.</p>

<p>The script also generates a list of users that are known in
PaperCut but not in CSIM LDAP. That should only happen if a user has
been wrongly associated with a FoS; that can only be rectified at
  PaperCut level.</p>

<p>Finally, the script compares the cost calculated by PaperCut and
the cost computed by CSIM. If there is a discrepancy, it suggests that
the rates in LDAP <tt>ou=Ricoh cost, ou=Resources</tt> does not
correspond to the cost used by PaperCut. The costs should be updated
in LDAP; there are 3 records to update for Black&amp;White, colour and the
ration B&amp;W/colour. This is not a blocking error.</p>

<h4>How to generate a report manually?</h4>

<p>When there is an error in the synchronization from PaperCut to
CSIM, a manual report must be generated to correct the error.</p>

<p>You must connect to <a href=https://10.52.5.20:9192/admin>PaperCut
web administration interface</a> then go to the report menu. Chose to
    create an <i>Ad hoc</i> User Printing Menu.</p>

<p>You have to select the group in the form of SET/ICT/FoS and enter
the starting and ending date and time for the report. For the reason
explained above, the >i>date and time must be very strict</i> else the
reports will be deemed not consecutive.</p>

<p>Once the <tt>.csv</tt> file has been saved, you can apply the
  script <tt>~on/Ldap/do-report-papercut.pl</tt> on the file.</p>

<h4>Synchronization from CSIM to PaperCut</h4>

<p>The synchronization is much simpler in this direction. Every day at
10:25 the script <tt>~on/Ldap/update-account-papercut.pl</tt> is run
  via <tt>cron(8)</tt>.</p>

<p>Any user that is in CSIM LDAP but not in PaperCut are either a
mistake (a user from another FoS where the
attribute <tt>csimIsCsim</tt> is not <tt>False</tt>) or a deleted
user. In either case, setting <tt>csimIsCsim</tt> to <tt>False</tt>
in LDAP for that user will solve the problem.</p>

<p>The script goes through the list of users in PaperCut and in LDAP
and computes the number of pages printed and the remaining credit, The
credit is then updated in PaperCut. Deleted users in LDAP have a
credit set to zero.</p>]]>
</description>
</item>
<item rdf:about="http://localhost/please/edit/me/archives/2023/06/13/migration_of_zeroshell_firewall/index.html">
<link>http://localhost/please/edit/me/archives/2023/06/13/migration_of_zeroshell_firewall/index.html</link>
<title>Migration of ZeroShell firewall</title>
<dc:date>2023-06-13T13:50:38+07:00</dc:date>
<dc:creator>Olivier</dc:creator>
<dc:subject>administration, firewall</dc:subject>
<description>
<![CDATA[
<h4>Running ZeroShell on VMware ESXi</h4>

<p>The only problem with running ZeroShell on VMware, with a bridged
firewall is that the Network adapters must support promiscuity. You
need to create port groups that allow promiscuous mode and forged
  tramsmits.</p>

<p>These port groups may be associated to existing virtual switches or
to virtual switches created for the purpose of testing the firewall in
  VMware.</p>

<p>For the testing, I have created 3 virtuals machines: ZeroShell, a
router between CSIM and internet and a web server that represent
internet and is used to test the captive portal. I have created 2
virtual switches: one to connect the firewall to the router and one to
connect the router to the internet server. and I have created 3 prot
groups: virtual CSIM and router are in promiscuous mode and one normal
virtual internet.</p>

<center><img src="/images/zeroshell.png"></center>

<h4>Installing ZeroShell</h4>

<P>After booting the ZeroShell <tt>.iso</tt> choose the Installation
Manager and proceed to install ZeroShell on the disk. No need to
  create a profile at this stage.</P>

<p>The following stages of moving and resizingdeleting and creating
partitions does not really need a backup prior: we are working on an
brand new system, at worse case, it can be reinstalled from
scratch.</p>

<p>The installation will create 4 partitions:</p>
<pre>
  Device Boot      Start         End      Blocks   Id  Type      Mount
/dev/sda1   *        2048      432127      215040   83  ext3     [boot]
/dev/sda2          432128     1087487      327680   83  iso9660  /cdrom
/dev/sda3         1087488     1742847      327680   83  iso9660  [unused]
/dev/sda4         1742848   146800639    72528896   83  ext4     /DB
</pre>

<p>The first partition contains the Linux kernel. The second partition
contains ZeroShell system that has been configured for the
computer. The third partition is just a copy of the second partition
before any modification. The last partition will be used to create the
  profiles.</p>

<p>My understanding is that the 3rd partition is not used. We need to
modify the second partition to include our patches, but a partition of
type <tt>iso9660</tt> (CD Rom) is not writable. Instead we will create
a copy of the second partition in partition 3, but with a
type <tt>ext4</tt>.</p>

<p>After the installation, we remove the installation media and reboot
to check that the firewall is starting normally. After entering the
shell, we use <tt>fdisk</tt> to delete the partitions 3 and 4. We need
  to reboot after exiting <tt>fdisk</tt>.</p>

<p>Then we recreate the partitions 3 and 4 with <tt>fdisk</tt>. Even
if I used only 1 GB on the partition 3, I choose to make it 50
GB. Partition 4 uses all the rest of the available disk. Reboot after
  exiting <tt>fdisk</tt>.</p>

<p>An <tt>ext4</tt> file system is created on partitions 3 and 4:</p>
<pre>mkfs -t ext3 /dev/sda3
mkfs -t ext3 /dev/sda4</pre>

<p>Next we will copy the second partition on to partition 3:</p>
<pre>mount /dev/sda3 /mnt
cd /cdrom
tar cf - . --one-file-system|(cd /mnt; tar xfBp -)
umount /mnt
mount /dev/sda3 /cdrom
</pre>

<p>The option <tt>--one-file-system</tt> is very important in
the <tt>tar</tt> copy; it ensures that the copy will not try to follow
links across file systems. The copy will result in a system that is
not working if the option is ommitted.</p>

<p>Once the copy has been achieved, mounting the new partition 3 on
top of <tt>/cdrom</tt> makes it active, the system should still be
running normally. Then reboot the system.</p>

<h4>Configuring ZeroShell</h4>

<p>A new profile can be created. Save it in the partition 4. Choose
the interface <tt>ETH01</tt> for the management interface and give it
an IP address different from the running firewall: as it is a
transparent/bridged firewall, the IP address is not important for the
client devices in CSIM. Use normal CSIM router address for the
gateway.</p>

<p>Activate that new profile, it will reboot the firewall. The
firewall is now accessible on the web managing
  interface. Enable <tt>ssh</tt> and try a command line connection:</p>

<pre>ssh admin@<i>IP address</i></pre>

<p>Get a to a shell prompt and try mounting <tt>/dev/sda3</tt> on top
of <tt>/cdrom</tt>. The web interface should still be working fine. In
the <tt>Pre Boot</tt> script, add the command:</p>

<pre>mount /dev/sda3 /cdrom</pre>

<p>Reboot and check that <tt>/dev/sda3</tt> is properly mounted.</p>

<p>We can now manually copy the configuration from the existing
firewall to the virtual one. The new firewall must be configured
manually, copying the runninng configuration from the existing
firewall. I could not just copy the profile because it introduced some
incompatibilities, it had to be recreated from scratch, using the
existing firewall as a model.</p>

<p>Using a virtual machine that is interacting with CSIM network
allows me to use our existing DNS and radius servers. Radius has to be
configured to allow the IP of the new firewall
in <tt>clients.conf</tt> and <tt>sites-enables/default</tt>. Note that
for <tt>sites-enables/default</tt>, the <tt>if</tt> statement must go
  on a single line.</p>

<p>Finally, configured the firewall section. I used <tt>tar</tt> to
copy the active profile from the old firewall <tt>/DB/_DB.002</tt> to
a <tt>/DB/_DB.002</tt> profile on the new firewall. This profile must
not be activated! From that profile, I the
copied <tt>/DB/_DB.002/var/register/system/net/FWChains</tt> to the
active
profile <tt>/Database/var/register/system/net/FW/Chains</tt>.</p>

<p>The firewall rules have to be edited to replace any occurence of
the IP address of the old firewall with the IP address of the new
firewall. The command <tt>iptables-save|grep <i>IP address</i></tt>
  will show the list.</p>

<p>Similarily, any rule involving the router IP address has to be
  duplicated to include the IP address of the virtual router.</p>

<p>The virtual web server used to test the captive portal is using a
private IP address. These addresses are blocked by the firewall. To
allow the test of the captive portal, a rule must be added into the
chains <tt>private_from_out</tt> (incoming packets from the outside)
and <tt>privateout</tt< (outgoing packets to the the outside). The
rule is made as restrictive as possible, using a <tt>/30</tt> prefix,
to only include the virtual router and the virtual web server.</p>

<p>Once the firewall will come to production, the duplicated rules for
the virtual router and the rules to temporarily
open <tt>192.168.0.0/30</tt> should be removed.</tt>

<h4>Customization</h4>

<p>All customization will be save in </tt>/Database</tt>. There is
a <tt>/Database/Patch</tt> directory that stores the patches that are
automatically applied to the system at boot time. The "automatic
applied" is managed by the <tt>Pre Boot</tt> script.</p>

<p>There are two areas that I customized: I want the Captive Portal to
allow free Authorized service to all AIT subnet and not to a single IP
only, these are the
patches <tt>cpAddClient</tt>, <tt>cpAddService</tt>
and <tt>fw_sys_chain</tt>. Beside modifying the web interface, it
  includes some modification to the firewall rules.</p>

<p>The other patches only change the colour scheme used by the Captive
  Portal, as seen by the users.</p>

<p>The <tt>Pre Boot</tt> script to apply the patches:</p>
<pre>cd /
if [ -d '/Database/Patch' ] ; then
  for i in /Database/Patch/* ; do
    if [ "$i" != '/Database/Patch/*' ] ; then
      patch -p0 -r /dev/null <$i
    fi
  done
fi
</pre>

<h4>Installing software</h4>

<p>The most demanding part was making <a
href=https://amanda.org/>Amanda</a> backup available as it needed
cross compiling.</p>

<p>I used <a href=https://crosstool-ng.github.io>crosstool-NG</a>
environment to compile Amanda. I build it with
the <a href="/~on/technotes/crosstool-ng.config">configuration
here</a>. I used
the <a href="https://crosstool-ng.github.io/docs/toolchain-usage/">option
3 when using the tool chain</a>.</p>

<p>I configured and built Amanda statically. I choose an old version
Amanda 2.4.5p1 because it did not require the use of glib. I had to
link each program in <tt>client-src</tt> manually and I then copied
the in the folder <tt>/Database/work/amanda</tt> on the firewall. Note
that <tt>runtar</tt> must be suid root. <tt>configure</tt> for Amanda:</p>

<pre>./configure --prefix=/opt --enable-static --enable-static-binary \
--with-user=amanda --with-group=amanda --without-ipv6 \
--with-index-server=amanda.cs.ait.ac.th --without-server \
--with-gnutar=/opt/bin/tar \
--with-gnutar-listdir=/opt/var/amanda/gnutar-lists \
-build=i686-unknown-linux-gnu --target=i686-unknown-linux-gnu \
CPPFLAGS="-static -I$HOME/staging4/usr/include" \
CFLAGS="-static -m32 -I$HOME/staging4/usr/include -L$HOME/staging4/lib -L$HOME/staging4/usr/lib" \
LDFLAGS="-static -L$HOME/staging4/lib -L$HOME/staging4/usr/lib"
</pre>

<p>I also built <a href=https://www.xinetd.org><tt>xinetd</tt></a> to
run Amanda. I had to use <tt>CFLAGS</tt> instead of <tt>CPPFLAGS</tt>
and add the options <tt>-m32 -static</tt>. I installed <tt>xinetd</tt>
in <tt>/Database/work/bin</tt> on the firewall. Note
that <tt>xinet</tt> does not follow the <tt>DESTDIR</tt> flag, do not
  try to install it. <tt>configure</tt> for <tt>xinetd</tt>:</p>

<pre>./configure --build=i686-unknown-linux-gnu --target=i686-unknown-linux-gnu\
--prefix=/usr CPPFLAGS="-I$HOME/staging4/usr/include" \
CFLAGS="-static -m32 -I$HOME/staging4/usr/include -L$HOME/staging4/lib -L$HOME/staging4/usr/lib"\
LDFLAGS="-staic -L$HOME/staging4/lib -L$HOME/staging4/usr/lib"
</pre>

<p>The following lines in the <tt>Pre Boot</tt> script on the firewall take care of creating Amanda environment at each reboot:</pp>
<pre>echo amanda:x:14:14:Amanda:/opt/var/amanda:/bin/false >>/etc/passwd
echo amanda:x:14: >>/etc/group
cd /Database/work
cp /Database/work/xinetd.conf /etc
cp /Database/work/xinetd /etc/rc.d/init.d/
ln -s /Database/work/amanda /opt/libexec
ln -s /Database/work/amanda-var/amandates /etc
mkdir -p /opt/var
ln -s /Database/work/amanda-var /opt/var/amanda
cp /Database/work/bin/tar /bin/tar
cp /Database/work/bin/em /bin/emacs

# To make it available for backup
mkdir /boot2
mount /dev/sda1 /boot2
</pre>

<p>I also installed <a href=https://www.gnu.org/software/tar/>GNU
tar</a> version 1,34 as well as <a
href="https://wiki.michaelhan.net/UEmacs/PK">&micro;emacs</a>.</p>

<p><tt>configure</tt> for GNU tar:</p>

<pre>
./configure --build=i686-unknown-linux-gnu --target=i686-unknown-linux-gnu \
--prefix=/usr CPPFLAGS="-I$HOME/staging4/usr/include" \
CFLAGS="-static -m32 -I$HOME/staging4/usr/include -L$HOME/staging4/lib -L$HOME/staging4/usr/lib"
LDFLAGS="-static -L$HOME/staging4/lib -L$HOME/staging4/usr/lib"
</pre>

<p>The script <tt>Post Boot</tt> starts the service <tt>xinetd</tt>
once the firewall is online.</p>

<p>Finally, I created a <tt>cron</tt> script that run every night at
01:00 and make a list of the rules that have expired. That list is
uploaded to <tt>ufo</tt> to be used when expiring users.</p>

<h4>SSL certificate</h4>

<p>As this new firewall uses recent version of cypher, it is worth
  having an official SSL certificate installed.</p>

<p>ZeroShell captive portal works with <tt>itpables</tt> redirection,
at IP level; the certificate must support IP address. Let's Encrypt
free certificates do not support certificates for IP address, I
purchased a certificate
from <a href="https://www.dotarai.co.th/index.php?page=ssl">DotArai</a>,
  as a reseller for Sectigo.</p>

<p>While a certificate for nothing more than an IP address is
possible, it seems that some web browsers do not support them, so the
certificate must be issued for a FDQN, with a Subject Aletnative Name
for the IP address; this is also called a multi-domains
certificate. The solution I bought is Sectigo (Comodo) PositiveSSL
Multi-Domains that allows up to 3 FDQN (or one FDQN and one IP address
  in our case).</p>

<p>Key and CSR has been generated locally, the configuration file to
  generate the CSR is saved at the same location as the CSR itself.</p>

<p>The certificate was issued in 24 hours and payement could be made
by Credit Card or defered and paid on Invoice. The certificate comes
with 3 files: the certificate itself, an intermediate CA and Sectigo
  CA.</p>

<p>The intermediate CA must be installed on the firewall with the
TrustedCA, while the certificate and the private key are installed in
the importer certificates. The certificate has to be enabled on the
web management page as well as the captive portal authentication
page.</p>

<p>It seems that the verification for issuing the certificate can go
by email or by a challenge web page. While DotArai registration page
asks for an email address, the transaction was made with a challenge
over the web. Email has been configured to add CSIM MX reccord to the
firewall email address, so any email directed to the firewall should
  be received by the normal CSIM email system.</p>

<p>In our case, I communicated directly with a staff at DotArai and
the verification was made via a web page challenge, the challenge
token must be installed in the
folder <tt>/usr/local/apache2/htdocs</tt> and the firewall
configuration has to be modified so that the web server is accessible
from outside: this may include adding rules in the firwall
chain <tt>web_servers</tt> as well as adding interface <tt>ETH00</tt>
or IP addresses in the configuration of the web management. These
modifications should be reverted as soon as possible.</p>

<P>The current certificate expires in June 2024.</p>

<h4>Porting the virtual firewall to a physical machine</h4>

<p>The installation <i>must</i> be done from a CD Rom. While the
firewall will boot and run from a USB key, the installation script
request the access to <tt>/dev/cdrom</tt>. It can be done using an
external CD drive connected via USB.</p>

<p>The steps of installing ZeroShell and repartitioning the disks must
be done on the physical machine, then give a temporary IP address to
the firewall and copy the profile from the virtual firewall to the
physical machine.</p>

<p>Remove or disable any rule concerning the virtual router.</p>

<h4>Error about the rule <tt>inside_client</tt></h4>

<P>During the boot, an error is shown complaining about loading the
rule <tt>inside_client</tt>, I think it is because a this stage of the
boot, the firewall have not yet been fully loaded and the
chain <tt>inside_client</tt> does not exist yet. When the firewall has
finished booting, it seems the error is not a problem anymore.</p>]]>
</description>
</item>
<item rdf:about="http://localhost/please/edit/me/archives/2023/06/09/another_way_to_shutdown_all_the_systems/index.html">
<link>http://localhost/please/edit/me/archives/2023/06/09/another_way_to_shutdown_all_the_systems/index.html</link>
<title>Another way to shutdown all the systems</title>
<dc:date>2023-06-09T11:59:07+07:00</dc:date>
<dc:creator>Olivier</dc:creator>
<dc:subject>administration, firewall, vmware, freebsd, router</dc:subject>
<description>
<![CDATA[
<p>When a power interruption is planed, it is easy to set-up a
programmed shutdown of the machines, using a
scheduled <tt>shutdown</tt>.</p>

<p>The machines should be stopped in the following order that will
conform with the interdependancies between the services:</p>
  
<dl>
  <dt>First, stop the machines that no other service depends on:</dt>
  
  <dd>The machines are <tt>ufo</tt>, <tt>mail</tt>, <tt>firewall</tt>, <tt>router</tt>, <tt>bazooka</tt>, <tt>active</tt>, </tt> <tt></tt> <tt>amanda</tt>, <tt>database</tt>, <tt>door</tt>, <tt>guppy</tt>, <tt>gourami</tt>, <tt>puffer</tt> <tt>and</tt> <tt>exam</tt>.</dd>

<dt>Second, stop the file server:</dt>
<dd>The machine is <tt>banyan</tt>.</dd>

<dt>Third, stop DNS and authentication:</dt>
<dd><dd>The machines are <tt>dns</tt> and <tt>ldap</tt>.</dd>

<dt>Fourth, stop the syslog server:</dt>
<dd>The machine is <tt>sysl</tt>.</dd>

<dt>Fifth, stop the virtual servers:</dt>
<dd>The machines are <tt>virtual</tt>, <tt>virtual2</tt>, <tt>virtual3</tt>, <tt>virtual4</tt>, <tt>virtual5</tt>, <tt>teal1</tt> and <tt>teal2</tt>.</dd>
</dl>

<p>There should be approximately 10 minutes between each steps, so if
the first phase should stop on Sunday at 7:00, the second phase will
  be on Sunday at 7:10, etc. and the last phase on Sunday at 7:40.</p>

<p>Add a crontab entry line in <tt>root</tt> user on each machine,
  this will allow to schedule the shutdown a long time in advance.</p>

<p>The date and time for crontab are as follow:<br>
  <tt>minute hour day-of-the-month month day-of-the-week</tt><br>
  where the minutes are between 0&mdash;59, the hour 0&mdash;23 and Sunday is represented by either 0 or 7.<p>

<dl>
<dt>On FreeBSD the command is:</dt>
<dd>0 7 * * 0 /sbin/shutdown -p now</dd>
<dt>On Linux the command is:</dt>
<dd>0 7 * * 0 /sbin/shutdown -h now</dd>
<dt>On ESXi the procedure is:</dt>
<dd><i>Note:</i> The time on ESXi servers is UTC, so the clock is 7 hours back: to stop the machine a 7:40, you must enter a time of 0:40. If you plan to stop the server around midnight, you must enter the time as 17:00.
<ol>
<li>Go to <tt>/var/spool/cron/crontab</tt></li>
<li>Change the file <tt>root</tt> to writable <tt>chmod 600 root</tt></li>
<li>Edit the file  <tt>root</tt> and add the line <tt>40 0 * * 0 /bin/poweroff</tt></li>
<li>Find the <tt>crond</tt> process <tt>ps -c|grep crond</tt></li>
<li>And kill it</li>
<li>Restart the <tt>crond</tt> process <tt>/usr/lib/vmware/busybox/bin/busybox crond</tt></li>
</ol></dd></dl>

<p>After the system has bee restarted, you must remove or comment out
the line in the <tt>crontab</tt> (except on ESXi servers and firewall); else the
system will shutdown on the next Sunday.</p>

<p>Amanda starts a backup run every night at 00:05, it is better to
halt the machine around 23:50, before a run, than just when a new run
has started for example at 00:15.</p>

<p>Do not use the <tt>-p</tt> option with the <tt>door</tt> machine
because it restarts automatically as soon as it is powered down, it is
better to keep the system halted but still with power on.</p>]]>
</description>
</item>
<item rdf:about="http://localhost/please/edit/me/archives/2023/05/05/some_issues_with_amanda/index.html">
<link>http://localhost/please/edit/me/archives/2023/05/05/some_issues_with_amanda/index.html</link>
<title>Some issues with Amanda</title>
<dc:date>2023-05-05T15:14:45+07:00</dc:date>
<dc:creator>Olivier</dc:creator>
<dc:subject>administration, backup</dc:subject>
<description>
<![CDATA[<xmp>
24 March 2023

>  I have had Amanda running for over a decade, yesterday I had no issue at
>  all but last night, my backups for Ubuntu machines started crashing
>  consistently with the error:
>  strange(?): runtar: error [runtar invalid option: -]
>
> The just-released amanda package upgrade seems to have a regression for
> GNUTAR DLEs; see:
> https://bugs.launchpad.net/debian/+source/amanda/+bug/2012536/

See amanda.conf for the workaround.

======================================================================

2 May 2023 (reported to amanda-hackers@amanda.org on 5 May 2023)

I recentrly had amrecover that hanged because amidxtaped would die with
the following message in amidxtaped.log:

Tue May 2 12:38:48 2023: thd-0x802e95800: amidxtaped: warning: Use of
uninitialized value $str in pattern match (m//) at
/usr/local/lib/perl5/site_perl/Amanda/DB/Catalog.pm line 764.

Tue May 2 12:38:48 2023: thd-0x802e95800: amidxtaped: warning: Use of
uninitialized value $s in concatenation (.) or string at
/usr/local/lib/perl5/site_perl/Amanda/DB/Catalog.pm line 764.

Tue May 2 12:38:48 2023: thd-0x802e95800: amidxtaped: critical (fatal):
'' at /usr/local/lib/perl5/site_perl/Amanda/DB/Catalog.pm line 764.

amidxtaped: '' at /usr/local/lib/perl5/site_perl/Amanda/DB/Catalog.pm
line 764.

Digging into Catalog.pm, I managed to identify the log file that was
causing the error and the specific line in the log file is:

DONE taper WARNING driver Taper protocol error

Modify /usr/local/lib/perl5/site-perl/Amanda/DB/Catalog.pm to print
the name of the file.  </xmp>]]>
</description>
</item>
<item rdf:about="http://localhost/please/edit/me/archives/2023/05/02/about_firewall_certificate/index.html">
<link>http://localhost/please/edit/me/archives/2023/05/02/about_firewall_certificate/index.html</link>
<title>About firewall certificate</title>
<dc:date>2023-05-02T12:26:10+07:00</dc:date>
<dc:creator>Olivier</dc:creator>
<dc:subject>administration, firewall, backup</dc:subject>
<description>
<![CDATA[
<p>Let's Encrypt does not do IP certificate. The redirection in the
firewall works with the IP address (redirecting the traffic for
authentication to <tt>https://a.b.c.d:112081</tt>, this mechanism
cannot be changed, it is set inside an executable that does not have
source file) so it is not possible to set a certified certificate for
the firewall.</p>

<p>Also, I did try to install a certificate manually and completely
messed up the firewall to the point that Apache was not starting, so there
was no more web administration interface no Captive Portal.</p>

<p>I had to restore the following files from backup:</p>
<tt><ul>
<li>/DB/_DB.002/etc/ssl/certs/admin_user.pem</li>
<li>/DB/_DB.002/etc/ssl/certs/crl.pem</li>
<li>/DB/_DB.002/etc/ssl/certs/fireall.cs.ait.ac.th_host.pem</li>
<li>/DB/_DB.002/etc/ssl/certs/imported_Certs/04.pem</li>
</tt>
</ul>

<p>This is assuming that we are using the profile 2 and that the
certificate installed is 4.</p>

<p>Do not mess manually with the certificates.</p>

<p>Even with no Apache and no Active Portal, the firewall filtering
was active.</p>]]>
</description>
</item>
<item rdf:about="http://localhost/please/edit/me/archives/2023/02/23/change_redis_owner_after_update_on_mail_server/index.html">
<link>http://localhost/please/edit/me/archives/2023/02/23/change_redis_owner_after_update_on_mail_server/index.html</link>
<title>Change redis owner after update on mail server</title>
<dc:date>2023-02-23T11:46:08+07:00</dc:date>
<dc:creator>Olivier</dc:creator>
<dc:subject>administration</dc:subject>
<description>
<![CDATA[<xmp>
The upgrade procedure or redis reset the ownership of the database to the
default user "redis".

For historical reasons, we are using the user "kluser" (because Kaspersky
did not allow to use anything else).

After upgrading redis, you must set the ownership to kluser on both
/var/run/redis and /var/run/db

On mail server:
sudo chown -R kluser /var/run/redis
sudo chown -R kluser /var/db/redis
</xmp>]]>
</description>
</item>
<item rdf:about="http://localhost/please/edit/me/archives/2023/02/16/managing_vpn_certificates/index.html">
<link>http://localhost/please/edit/me/archives/2023/02/16/managing_vpn_certificates/index.html</link>
<title>Managing VPN certificates</title>
<dc:date>2023-02-16T13:32:52+07:00</dc:date>
<dc:creator>Olivier</dc:creator>
<dc:subject>administration</dc:subject>
<description>
<![CDATA[<xmp>

User can create their own VPN certificates on the account management
web page.

VPN authentication is based on the user credential and a certificate
protected by a password.

The certificate is valid for one year.

To revoke a certificate, connect to ufo and issue:
sudo -u httpd /var/db/http/rsa.scripts/rsa_wrapper2.pl revoke <user name>

The script rsa_wrapper2.pl can be used to create, show, show the
expiration date of, revoke a certificate or renew the CRL (Certificate
Revocation List).

The CRL has a validity of 6 months and is nore renewed unless a user
is revoked. A crontab job will renew the CRL on the 3rd of every four
months, a 2:57. This shouls solve the error about CRL expired.

Note that rsa_wrapper2.pl should be used and not rsa_wrapper.pl. It
calls the script easyrsa.real.test that has been modified to work
around a bug in OpenSSL.

I have tried with the native OpenSSL (1.1.10) installed with FreeBSD
13 and with OpenSSL 3.2.0-dev and the bug is still there. I *think* it
is the bug about EPREM that is detailed in "TTY_get() in
crypto/ui/ui_openssl.c open_console() can also return er..."
<https://github.com/openssl/openssl/commit/082394839ea32386abc7ee33aaa9da864287064c>

To workaround the bug, I have modified earrsa.real to pass the CA
passphrase with:

echo "passphrase" | openssl ... -passin stdin

instead of

openssl ... -passin pass:passphrase

Note that the passphrase is hardcoded in the script.

Note that the workaround is VERY crude.

Note about the bug: it would only show when the web page is created by
Joomla:

Joomla3->php wrapper->Perl script   ->Perl script    ->Bourne shell script->openssl
php    ->php        ->connect-ifrane->rsa_wrappeer2.pl->easyrsa.real.test ->openssl
                      
and not when the page was created only by a Perl CGI script:

Perl script->Perl script   ->Bourne shell script->openssl
connect    ->rsa_wrapper.pl->easyrsa.real       ->openssl

I could not make a smaller example.

</xmp>]]>
</description>
</item>
<item rdf:about="http://localhost/please/edit/me/archives/2022/09/29/some_stuff_related_vmware_and_ssl_certificates/index.html">
<link>http://localhost/please/edit/me/archives/2022/09/29/some_stuff_related_vmware_and_ssl_certificates/index.html</link>
<title>Some stuff related VMware and SSL certificates</title>
<dc:date>2022-09-29T13:03:32+07:00</dc:date>
<dc:creator>Olivier</dc:creator>
<description>
<![CDATA[<xmp>
Certificates are located in /etc/vmware/ssl
rui.key is the private key            mod 400
rui.crt is the certificate + the CA   mod 644

The private key is installed once for all
The certificate is generated/installed by ~on/letsencrypt/install_cert_virtual

After installing the new certificates, restart the management agents:
/etc/init.d/hostd restart
/etc/initt.d/vpxa restart

If that does not work, try to restart the agent manually from the console.
Or try the command dcui from an ssh connection.

I have not tried the solutions below.

See also https://www.nakivo.com/blog/how-to-restart-management-agents-on-a-vmware-esxi-host/

4. Use this command as an alternative, to restart all management
agents on the ESXi host.

services.sh restart &tail -f /var/log/jumpstart-stdout.log

The progress of the VMware agents restart is displayed in the console
output.  VMware restart management agents with services.sh

5. You can also try to reset the management network on a VMkernel
interface:

esxcli network ip interface set -e false -i vmk0; esxcli network ip interface set -e true -i vmk0

The vmk0 interface is used by default on ESXi. If you have a different
name for the management network interface, use the appropriate
interface name in the command.

This complex command consists of two basic commands separated by ;
(semicolon). The vmk0 management network interface is disabled by the
first part of the command. When this part is executed successfully and
vmk0 is down, then the second part of the command is executed to
enable the vmk0 interface. As a result, the ESXi management network
interface is restarted.

The authorized_keys file for root is in
/etc/ssh/keys_root/authorized_keys

It can be used from ufo
sudo ssh -i /root/.ssh/id_rsa_virtual root@virtualX

Crontab for root is in
/var/spool/cron/crontab/root
</xmp>]]>
</description>
</item>
</rdf:RDF>
