summaryrefslogtreecommitdiff
path: root/pages/home.luax
blob: 64e951727fb2dc1ebad69dcdc6adcd14834d809c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
local art = [[
          _/\              
        _/   \             
       /__/   \            
         /     \           
  _____ /_______\ ______   
  \    /           \   /   
   \/   ##      ##  \ /    
     | ####    #### |      
    \   ##      ##   /     
       \           /       
         |-    -|          
       __|      |__        
]]

local function is_service_live(service, is_user)
  local opt = ''
  if is_user then
    opt = '-U '
  end
  local handle = io.popen('rc-service ' .. opt .. service .. ' status 2>&1')
  local output = handle:read('*a')

  local is_dummy = string.match(output, "not")
  if is_dummy then
    return "unknown"
  end
  local is_running = string.match(output, "started")
  if is_running then
    return "online"
  else
    return "offline"
  end
end

local function Service(props)
  local name = props.attrs.service

  if props.attrs.name then
    name = props.attrs.name
  end

  if props.attrs.link then
    name = <a href={props.attrs.link}> {$ name $} </a>
  end
  return <div class="service-info">
    <div class="service-name">
      {$ name $}
    </div>
    <div class={"service-status service-status-" .. is_service_live(props.attrs.service, props.attrs.is_user)}>
      {$ is_service_live(props.attrs.service, props.attrs.is_user) $}
    </div>
  </div>
end

return function(props)
    return <div class="main-info">
      <div class="main-info-title">
        they do lots of things!
      </div>
      <div class="ascii-art">
        {$ art $}
      </div>
      <div class="service-group">
        <Service service="reluax" link="https://rem.duckonaut.dev" />
        <Service service="tailscale" />
        <Service name="cgit" service="nginx" link="https://git.duckonaut.dev" />
        <Service service="sshd" />
        <Service name="gitolite" service="sshd" />
      </div>
    </div>
end