error); } echo json_encode(array('success' => false, 'txt' => $txt)); exit; } /// Send Success To Client /** @return success message from server to client Function calls exit to terminate. Message format is json: @code { success: true, txt: 'success message string'; } @endcode */ function success($txt) { echo json_encode(array('success' => true, 'txt' => $txt)); exit; } function getoption($name, $default) { if (!isset($OPTION[$name])) { $q = $db->query("select value from options where name='$name';"); if ($q->num_rows==1) { $OPTION[$name]=$q->fetch_row()[0]; } else { if (isset($_SERVER[$name])) $OPTION[$name]=$_SERVER[$name]; else $OPTION[$name]=$default; $q = $db->query("insert into options (name, value) values ('$name', '$value');"); } } return $OPTION[$name]; } /// Create user safechat as server's identity /** Server has reserved username @c safechat */ function createSafechatUser() { $q = $db->query("select pubkey from user where name='safechat';"); if ($q->num_rows!=1 && $user=="safechat") { $KEY_LENGTH=getoption("KEYLEN", "4096"); $SAFECHAT_NAME=getoption("NAME", "Safe Chat"); $SAFECHAT_COMMENT=getoption("COMMENT", "https://safechat.ch"); $SAFECHAT_EMAIL=getoption("EMAIL", "server@safechat.ch"); $PASSWORD=getoption("PASSWORD", "s3Cr37"); $create_key_cmd=<<query("insert into user (name, pubkey) values ('safechat', '$export');"); } } ?>