populate MAC address from inventory for svc_phone devices, RT7794
[freeside.git] / httemplate / misc / macinventory.cgi
diff --git a/httemplate/misc/macinventory.cgi b/httemplate/misc/macinventory.cgi
new file mode 100644 (file)
index 0000000..b07da97
--- /dev/null
@@ -0,0 +1,25 @@
+<% objToJson(\@macs) %>
+<%init>
+
+# XXX: this should be agent-virtualized / limited
+
+my $devicepart = $cgi->param('arg');
+
+die 'invalid devicepart' unless $devicepart =~ /^\d+$/;
+
+my $part_device = qsearchs('part_device', { 'devicepart' => $devicepart } );
+die "unknown devicepart $devicepart" unless $part_device;
+
+my $inventory_class = $part_device->inventory_class;
+die "devicepart $devicepart has no inventory" unless $inventory_class;
+
+my @inventory_item =
+    qsearch('inventory_item', { 'classnum' => $inventory_class->classnum } );
+
+my @macs;
+
+foreach my $inventory_item ( @inventory_item ) {
+    push @macs, $inventory_item->item;
+}
+
+</%init>