()
| 139 | } |
| 140 | |
| 141 | func initLocalFile() error { |
| 142 | f, err := os.Create(defaultPath) |
| 143 | if err != nil { |
| 144 | return err |
| 145 | } |
| 146 | defer f.Close() |
| 147 | initFile := `#DEFAULT-START |
| 148 | [DEFAULT] |
| 149 | bantime = 600 |
| 150 | findtime = 300 |
| 151 | maxretry = 5 |
| 152 | banaction = $banaction |
| 153 | action = %(action_mwl)s |
| 154 | #DEFAULT-END |
| 155 | |
| 156 | [sshd] |
| 157 | ignoreip = 127.0.0.1/8 |
| 158 | enabled = true |
| 159 | filter = sshd |
| 160 | port = 22 |
| 161 | maxretry = 5 |
| 162 | findtime = 300 |
| 163 | bantime = 600 |
| 164 | banaction = $banaction |
| 165 | action = %(action_mwl)s |
| 166 | logpath = $logpath` |
| 167 | |
| 168 | banaction := "" |
| 169 | if active, _ := controller.CheckActive("firewalld"); active { |
| 170 | banaction = "firewallcmd-ipset" |
| 171 | } else if active, _ := controller.CheckActive("ufw"); active { |
| 172 | banaction = "ufw" |
| 173 | } else { |
| 174 | banaction = "iptables-allports" |
| 175 | } |
| 176 | initFile = strings.ReplaceAll(initFile, "$banaction", banaction) |
| 177 | |
| 178 | logPath := "" |
| 179 | if _, err := os.Stat("/var/log/secure"); err == nil { |
| 180 | logPath = "/var/log/secure" |
| 181 | } else { |
| 182 | logPath = "/var/log/auth.log" |
| 183 | } |
| 184 | initFile = strings.ReplaceAll(initFile, "$logpath", logPath) |
| 185 | if err := os.WriteFile(defaultPath, []byte(initFile), 0640); err != nil { |
| 186 | return err |
| 187 | } |
| 188 | return nil |
| 189 | } |
no test coverage detected