OPNsense
  • Home
  • Help
  • Search
  • Login
  • Register

  • OPNsense Forum »
  • English Forums »
  • Development and Code Review (Moderator: fabian) »
  • Save configuration from code
« previous next »
  • Print
Pages: [1]

Author Topic: Save configuration from code  (Read 1805 times)

@Vorona

  • Newbie
  • *
  • Posts: 15
  • Karma: 0
    • View Profile
Save configuration from code
« on: December 17, 2023, 05:22:12 pm »
Hello!
I need help! I write script, which generate user certificate by local CA, using internal functions. I have problem with saving this certificate in config.
Fragment:

Code: [Select]
@require_once("config.inc");
@require_once("certs.inc");
@require_once('util.inc');

$certs = &config_read_array('cert');

const CAREFID='..........';
const CERT_DAYS=7;
$email='......';
$login='....';

cert_create($user_cert, CAREFID, 2048, CERT_DAYS, Array('emailAddress' => $email, 'ST'=>'State', 'O'=>'Org','L'=>'Location','CN'=>$login,'C'=>'CN'), 'SHA256');

$user_cert['descr'] = 'certificate-'.$login;
$user_cert['refid'] = uniqid();
$certs[]=$user_cert;
var_dump(write_config('Generate webmail cert for '.$login));

var_dump returns correct configuration array with my new certificate. But I don't see it in web interface or in /conf/config.xml. In general log file I see:

Code: [Select]
2023-12-17T18:57:16 Notice configctl event @ 1702828636.28 exec: system event config_changed
2023-12-17T18:57:16 Notice configctl event @ 1702828636.28 msg: Dec 17 18:57:16 hostname.localdomain config[30917]: config-event: new_config /conf/backup/config-1702828636.2734.xml

But config not applying, also backup config file not exists.

What I'm doing wrong? Please, help!
Logged

  • Print
Pages: [1]
« previous next »
  • OPNsense Forum »
  • English Forums »
  • Development and Code Review (Moderator: fabian) »
  • Save configuration from code
 

OPNsense is an OSS project © Deciso B.V. 2015 - 2024 All rights reserved
  • SMF 2.0.19 | SMF © 2021, Simple Machines
    Privacy Policy
    | XHTML | RSS | WAP2