Skip to content

Commit

Permalink
Initial code upload
Browse files Browse the repository at this point in the history
  • Loading branch information
xWTF committed Jan 8, 2023
1 parent b6652d5 commit c8f6044
Show file tree
Hide file tree
Showing 12 changed files with 816 additions and 0 deletions.
87 changes: 87 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Snipe-IT bPAC Daemon

## Usage

Install the [bPAC Client Component](https://support.brother.com/g/s/es/dev/en/bpac/download/index.html#client) on the server that runs this daemon.

(TODO: Write detailed guide)

## Start with Windows

Create a shortcut in `shell:startup` folder.

## Start minimized

Just pass `-m` to the argument list.

# labels.blade.php

Replace `resources/views/hardware/labels.blade.php` with content below:

Specifically, if you're using docker, mount it to `/var/www/html/resources/views/hardware/labels.blade.php`.

```php
<?php
define('ACCESS_KEY', 'YOUR-ACCESS-KEY-HERE');
define('SERVER_ENDPOINT', 'http://127.0.0.1:8000/print');

$labels = [];
foreach ($assets as $asset) {
$labels[] = [
'id' => 'ID: ' . $asset->id,
'name' => empty($asset->name) ? '' : 'N: ' . $asset->name,
'serial' => empty($asset->serial) ? '' : 'S: ' . $asset->serial,
'model' => empty($asset->model->name) ? '' : 'M: ' . $asset->model->name,
'company' => $asset->company === null ? null : 'C: ' . $asset->company->name,
'asset_tag' => $asset->asset_tag,
];
}
?>

<!doctype html>
<html lang="en">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Labels Print</title>
</head>

<body>
<div style="display: flex;flex-flow: column;gap: 12px">
<span>Labels Data: <?php echo count($labels); ?></span>
<div>
<button type="button" id="print" onclick="doPrint()">Click here to print</button>
</div>
<ul style="margin: 0;">
<?php
foreach ($labels as $l) {
echo ('<li>' . $l['id'] . ', ' . $l['asset_tag'] . ', ' . $l['model'] . '</li>');
}
?>
</ul>
</div>
<script>
function doPrint() {
var el = document.getElementById('print');
el.setAttribute('disabled', true);
el.innerText = 'Requesting...';
el = el.parentElement;
fetch(<?php echo json_encode(SERVER_ENDPOINT); ?>, {
credentials: 'omit',
method: 'POST',
headers: {
'Authorization': 'Bearer <?php echo ACCESS_KEY; ?>',
},
// For readability
body: JSON.stringify(<?php echo json_encode($labels); ?>),
}).then(r => r.text())
.then(r => el.innerText = r)
.catch(e => el.innerText = 'Error: ' + e);
}
</script>
</body>
</html>
```
28 changes: 28 additions & 0 deletions SnipeIT-bPAC.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.3.32804.467
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SnipeIT-bPAC", "SnipeIT-bPAC\SnipeIT-bPAC.csproj", "{4FC36674-2D6F-4DDD-AB2E-5DA6A1B13B26}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4FC36674-2D6F-4DDD-AB2E-5DA6A1B13B26}.Debug|Any CPU.ActiveCfg = Debug|x64
{4FC36674-2D6F-4DDD-AB2E-5DA6A1B13B26}.Debug|x86.ActiveCfg = Debug|x86
{4FC36674-2D6F-4DDD-AB2E-5DA6A1B13B26}.Debug|x86.Build.0 = Debug|x86
{4FC36674-2D6F-4DDD-AB2E-5DA6A1B13B26}.Release|Any CPU.ActiveCfg = Release|x64
{4FC36674-2D6F-4DDD-AB2E-5DA6A1B13B26}.Release|x86.ActiveCfg = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {84AD9696-89C8-4A3B-AFBD-30C6889879DB}
EndGlobalSection
EndGlobal
21 changes: 21 additions & 0 deletions SnipeIT-bPAC/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="SnipeIT_bPAC.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<userSettings>
<SnipeIT_bPAC.Properties.Settings>
<setting name="AccessKey" serializeAs="String">
<value />
</setting>
<setting name="TemplateFile" serializeAs="String">
<value />
</setting>
<setting name="ServerPort" serializeAs="String">
<value>8000</value>
</setting>
</SnipeIT_bPAC.Properties.Settings>
</userSettings>
</configuration>
25 changes: 25 additions & 0 deletions SnipeIT-bPAC/HttpListenerContextExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Net;
using System.Text;
using System.Text.Json;

namespace SnipeIT_bPAC
{
public static class HttpListenerContextExtension
{
public static void SendJson(this HttpListenerContext ctx, object? data)
{
var resp = ctx.Response;
resp.StatusCode = 200;
resp.ContentType = "application/json";

resp.AppendHeader("Access-Control-Allow-Origin", "*");
resp.AppendHeader("Access-Control-Allow-Headers", "authorization");

if (data != null)
{
resp.OutputStream.Write(Encoding.UTF8.GetBytes(JsonSerializer.Serialize(data)));
}
resp.OutputStream.Close();
}
}
}
Binary file added SnipeIT-bPAC/Interop.bpac.dll
Binary file not shown.
17 changes: 17 additions & 0 deletions SnipeIT-bPAC/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace SnipeIT_bPAC
{
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new ServerForm(args));
}
}
}
62 changes: 62 additions & 0 deletions SnipeIT-bPAC/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions SnipeIT-bPAC/Properties/Settings.settings
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="SnipeIT_bPAC.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="AccessKey" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="TemplateFile" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="ServerPort" Type="System.UInt16" Scope="User">
<Value Profile="(Default)">8000</Value>
</Setting>
</Settings>
</SettingsFile>
Loading

0 comments on commit c8f6044

Please sign in to comment.