WIP Domain listing app with automatic status checking. Buitl with AngularJS.

addPost.js 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. 'use strict';
  2. /**
  3. * @ngdoc function
  4. * @name domainManagerApp.controller:MainCtrl
  5. * @description
  6. * # MainCtrl
  7. * Controller of the domainManagerApp
  8. */
  9. angular.module('domainManagerApp.addPost', ['firebase', 'domainManagerApp.userData'])
  10. .controller('AddPostController', ['$scope', 'UserData', '$firebase', '$http', function ($scope, UserData, $firebase, $http) {
  11. $scope.AddDomain = function() {
  12. console.log('Creating domain ' + $scope.domain.name);
  13. $scope.whoisLookup();
  14. }
  15. $scope.whoisLookup = function() {
  16. // Whois domain lookup
  17. console.log("Whois lookup...");
  18. var whoisUrl = 'http://api.who.pm/' + $scope.domain.name;
  19. $http({
  20. method: 'GET',
  21. url: whoisUrl
  22. }).success(function(data) {
  23. console.log("Whois lookup successfull");
  24. $scope.domain.whois = data;
  25. $scope.saveToFirebase();
  26. }).error(function(data, status, headers, config) {
  27. console.log("Whois lookup error");
  28. });
  29. }
  30. $scope.saveToFirebase = function() {
  31. // Save to Firebase
  32. var firebaseObj = new Firebase("https://j1x-cpanel.firebaseio.com/");
  33. var domainsRef = firebaseObj.child("domains");
  34. domainsRef.push({
  35. name: $scope.domain.name,
  36. userId: UserData.getUser(),
  37. whois: $scope.domain.whois
  38. }, function(error) {
  39. if (error) {
  40. console.log('Error - Domain not created');
  41. } else {
  42. console.log('Domain created');
  43. }
  44. });
  45. }
  46. $scope.parseWhoisData = function(data) {
  47. var new_data = [];
  48. console.log(data);
  49. for (var i = 0; i < data.length; i++) {
  50. var keys = {};
  51. if (data[i] != ""){
  52. keys = data[i].split(": ")
  53. console.log(data[i]);
  54. console.log(keys);
  55. if(keys.length >= 2){
  56. var hash = new Array();
  57. hash[keys[0]] = keys[1];
  58. hash[0].replace(/\s+/g,"_").replace(/\.+/g,"_").replace(/\#+/g,"_").replace(/\$+/g,"_").replace(/\//g,"_").replace(/\[+/g,"_").replace(/\[+/g,"_");
  59. console.log(hash);
  60. new_data.push(hash);
  61. }
  62. }
  63. }
  64. console.log(new_data);
  65. return new_data;
  66. }
  67. }]);