2016-05-27 05:22:38 +03:00
|
|
|
using System;
|
2016-06-02 07:18:47 +03:00
|
|
|
using System.Collections.Generic;
|
2016-05-28 23:06:53 +03:00
|
|
|
using System.Diagnostics;
|
|
|
|
using System.Linq;
|
|
|
|
using Bit.App.Abstractions;
|
|
|
|
using Bit.App.Repositories;
|
|
|
|
using Bit.App.Services;
|
|
|
|
using Bit.iOS.Core.Services;
|
2016-05-27 05:22:38 +03:00
|
|
|
using CoreGraphics;
|
2016-05-07 08:54:44 +03:00
|
|
|
using Foundation;
|
2016-05-28 23:06:53 +03:00
|
|
|
using Microsoft.Practices.Unity;
|
2016-05-27 05:22:38 +03:00
|
|
|
using MobileCoreServices;
|
2016-06-02 07:18:47 +03:00
|
|
|
using Newtonsoft.Json;
|
2016-05-07 08:54:44 +03:00
|
|
|
using UIKit;
|
2016-05-28 23:06:53 +03:00
|
|
|
using XLabs.Ioc;
|
|
|
|
using XLabs.Ioc.Unity;
|
2016-05-07 08:54:44 +03:00
|
|
|
|
|
|
|
namespace Bit.iOS.Extension
|
|
|
|
{
|
|
|
|
public partial class ActionViewController : UIViewController
|
|
|
|
{
|
2016-05-30 10:08:12 +03:00
|
|
|
private const string AppExtensionVersionNumberKey = "version_number";
|
2016-05-31 05:51:53 +03:00
|
|
|
|
2016-05-30 10:08:12 +03:00
|
|
|
private const string AppExtensionUrlStringKey = "url_string";
|
2016-05-31 05:51:53 +03:00
|
|
|
private const string AppExtensionUsernameKey = "username";
|
|
|
|
private const string AppExtensionPasswordKey = "password";
|
|
|
|
private const string AppExtensionTotpKey = "totp";
|
|
|
|
private const string AppExtensionTitleKey = "login_title";
|
|
|
|
private const string AppExtensionNotesKey = "notes";
|
|
|
|
private const string AppExtensionSectionTitleKey = "section_title";
|
|
|
|
private const string AppExtensionFieldsKey = "fields";
|
|
|
|
private const string AppExtensionReturnedFieldsKey = "returned_fields";
|
|
|
|
private const string AppExtensionOldPasswordKey = "old_password";
|
|
|
|
private const string AppExtensionPasswordGeneratorOptionsKey = "password_generator_options";
|
|
|
|
|
|
|
|
private const string AppExtensionGeneratedPasswordMinLengthKey = "password_min_length";
|
|
|
|
private const string AppExtensionGeneratedPasswordMaxLengthKey = "password_max_length";
|
|
|
|
private const string AppExtensionGeneratedPasswordRequireDigitsKey = "password_require_digits";
|
|
|
|
private const string AppExtensionGeneratedPasswordRequireSymbolsKey = "password_require_symbols";
|
|
|
|
private const string AppExtensionGeneratedPasswordForbiddenCharactersKey = "password_forbidden_characters";
|
|
|
|
|
2016-06-02 07:18:47 +03:00
|
|
|
private const string AppExtensionWebViewPageFillScript = "fillScript";
|
|
|
|
private const string AppExtensionWebViewPageDetails = "pageDetails";
|
|
|
|
|
2016-05-30 10:08:12 +03:00
|
|
|
private const string UTTypeAppExtensionFindLoginAction = "org.appextension.find-login-action";
|
|
|
|
private const string UTTypeAppExtensionSaveLoginAction = "org.appextension.save-login-action";
|
|
|
|
private const string UTTypeAppExtensionChangePasswordAction = "org.appextension.change-password-action";
|
|
|
|
private const string UTTypeAppExtensionFillWebViewAction = "org.appextension.fill-webview-action";
|
|
|
|
private const string UTTypeAppExtensionFillBrowserAction = "org.appextension.fill-browser-action";
|
|
|
|
|
2016-05-27 05:22:38 +03:00
|
|
|
public ActionViewController() : base("ActionViewController", null)
|
2016-05-07 08:54:44 +03:00
|
|
|
{
|
2016-05-28 23:06:53 +03:00
|
|
|
if(!Resolver.IsSet)
|
|
|
|
{
|
|
|
|
SetIoc();
|
|
|
|
}
|
2016-05-07 08:54:44 +03:00
|
|
|
}
|
|
|
|
|
2016-05-31 05:51:53 +03:00
|
|
|
public string ProviderType { get; set; }
|
2016-05-27 05:22:38 +03:00
|
|
|
public Uri Url { get; set; }
|
2016-05-31 05:51:53 +03:00
|
|
|
public string SiteTitle { get; set; }
|
|
|
|
public string Username { get; set; }
|
|
|
|
public string Password { get; set; }
|
|
|
|
public string OldPassword { get; set; }
|
|
|
|
public string Notes { get; set; }
|
|
|
|
public PasswordGenerationOptions PasswordOptions { get; set; }
|
2016-06-02 07:18:47 +03:00
|
|
|
public PageDetails Details { get; set; }
|
2016-05-07 08:54:44 +03:00
|
|
|
|
2016-05-28 23:06:53 +03:00
|
|
|
private void SetIoc()
|
|
|
|
{
|
|
|
|
var container = new UnityContainer();
|
|
|
|
|
|
|
|
container
|
|
|
|
// Services
|
|
|
|
.RegisterType<IDatabaseService, DatabaseService>(new ContainerControlledLifetimeManager())
|
|
|
|
.RegisterType<ISqlService, SqlService>(new ContainerControlledLifetimeManager())
|
|
|
|
//.RegisterType<ISecureStorageService, KeyChainStorageService>(new ContainerControlledLifetimeManager())
|
|
|
|
.RegisterType<ICryptoService, CryptoService>(new ContainerControlledLifetimeManager())
|
|
|
|
.RegisterType<IAuthService, AuthService>(new ContainerControlledLifetimeManager())
|
|
|
|
.RegisterType<IFolderService, FolderService>(new ContainerControlledLifetimeManager())
|
|
|
|
.RegisterType<ISiteService, SiteService>(new ContainerControlledLifetimeManager())
|
|
|
|
.RegisterType<ISyncService, SyncService>(new ContainerControlledLifetimeManager())
|
|
|
|
//.RegisterType<IClipboardService, ClipboardService>(new ContainerControlledLifetimeManager())
|
|
|
|
// Repositories
|
|
|
|
.RegisterType<IFolderRepository, FolderRepository>(new ContainerControlledLifetimeManager())
|
|
|
|
.RegisterType<IFolderApiRepository, FolderApiRepository>(new ContainerControlledLifetimeManager())
|
|
|
|
.RegisterType<ISiteRepository, SiteRepository>(new ContainerControlledLifetimeManager())
|
|
|
|
.RegisterType<ISiteApiRepository, SiteApiRepository>(new ContainerControlledLifetimeManager())
|
|
|
|
.RegisterType<IAuthApiRepository, AuthApiRepository>(new ContainerControlledLifetimeManager());
|
2016-05-30 10:08:12 +03:00
|
|
|
// Other
|
|
|
|
//.RegisterInstance(CrossSettings.Current, new ContainerControlledLifetimeManager())
|
|
|
|
//.RegisterInstance(CrossConnectivity.Current, new ContainerControlledLifetimeManager())
|
|
|
|
//.RegisterInstance(UserDialogs.Instance, new ContainerControlledLifetimeManager())
|
|
|
|
//.RegisterInstance(CrossFingerprint.Current, new ContainerControlledLifetimeManager());
|
2016-05-28 23:06:53 +03:00
|
|
|
|
|
|
|
Resolver.SetResolver(new UnityResolver(container));
|
|
|
|
}
|
|
|
|
|
2016-05-31 05:51:53 +03:00
|
|
|
public override void LoadView()
|
2016-05-27 05:22:38 +03:00
|
|
|
{
|
2016-05-31 05:51:53 +03:00
|
|
|
foreach(var item in ExtensionContext.InputItems)
|
|
|
|
{
|
2016-06-02 07:18:47 +03:00
|
|
|
var processed = false;
|
2016-05-31 05:51:53 +03:00
|
|
|
foreach(var itemProvider in item.Attachments)
|
|
|
|
{
|
2016-06-02 07:18:47 +03:00
|
|
|
if(ProcessWebUrlProvider(itemProvider)
|
|
|
|
|| ProcessFindLoginProvider(itemProvider)
|
|
|
|
|| ProcessFindLoginBrowserProvider(itemProvider, UTTypeAppExtensionFillBrowserAction)
|
|
|
|
|| ProcessFindLoginBrowserProvider(itemProvider, UTTypeAppExtensionFillWebViewAction)
|
|
|
|
|| ProcessSaveLoginProvider(itemProvider)
|
|
|
|
|| ProcessChangePasswordProvider(itemProvider))
|
2016-05-31 05:51:53 +03:00
|
|
|
{
|
2016-06-02 07:18:47 +03:00
|
|
|
processed = true;
|
2016-05-31 05:51:53 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-06-02 07:18:47 +03:00
|
|
|
|
|
|
|
if(processed)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2016-05-31 05:51:53 +03:00
|
|
|
}
|
|
|
|
|
2016-05-27 05:22:38 +03:00
|
|
|
View = new UIView(new CGRect(x: 0.0, y: 0, width: 320.0, height: 200.0));
|
|
|
|
var button = new UIButton(new CGRect(x: 10.0, y: 50.0, width: 200.0, height: 30.0));
|
|
|
|
button.SetTitle("Done", UIControlState.Normal);
|
|
|
|
button.TouchUpInside += Button_TouchUpInside;
|
|
|
|
View.AddSubview(button);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Button_TouchUpInside(object sender, EventArgs e)
|
|
|
|
{
|
2016-05-31 05:51:53 +03:00
|
|
|
NSDictionary itemData = null;
|
2016-06-02 07:18:47 +03:00
|
|
|
if(ProviderType == UTTypeAppExtensionFindLoginAction)
|
2016-05-31 05:51:53 +03:00
|
|
|
{
|
|
|
|
itemData = new NSDictionary(
|
|
|
|
AppExtensionUsernameKey, "me@example.com",
|
|
|
|
AppExtensionPasswordKey, "mypassword");
|
|
|
|
}
|
2016-06-02 07:18:47 +03:00
|
|
|
else if(ProviderType == UTType.PropertyList
|
|
|
|
|| ProviderType == UTTypeAppExtensionFillBrowserAction
|
|
|
|
|| ProviderType == UTTypeAppExtensionFillWebViewAction)
|
|
|
|
{
|
|
|
|
var fillScript = new FillScript(Details);
|
2016-06-02 07:28:41 +03:00
|
|
|
var scriptJson = JsonConvert.SerializeObject(fillScript, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
|
2016-06-02 07:18:47 +03:00
|
|
|
itemData = new NSDictionary(AppExtensionWebViewPageFillScript, scriptJson);
|
|
|
|
}
|
2016-05-31 05:51:53 +03:00
|
|
|
else if(ProviderType == UTTypeAppExtensionSaveLoginAction)
|
|
|
|
{
|
|
|
|
itemData = new NSDictionary(
|
|
|
|
AppExtensionUsernameKey, "me@example.com",
|
|
|
|
AppExtensionPasswordKey, "mypassword");
|
|
|
|
}
|
|
|
|
else if(ProviderType == UTTypeAppExtensionChangePasswordAction)
|
|
|
|
{
|
|
|
|
itemData = new NSDictionary(
|
|
|
|
AppExtensionPasswordKey, "mynewpassword",
|
|
|
|
AppExtensionOldPasswordKey, "myoldpassword");
|
|
|
|
}
|
2016-05-27 05:22:38 +03:00
|
|
|
|
2016-05-31 05:51:53 +03:00
|
|
|
var resultsProvider = new NSItemProvider(itemData, UTType.PropertyList);
|
2016-05-28 07:59:36 +03:00
|
|
|
var resultsItem = new NSExtensionItem { Attachments = new NSItemProvider[] { resultsProvider } };
|
2016-05-27 05:22:38 +03:00
|
|
|
var returningItems = new NSExtensionItem[] { resultsItem };
|
2016-05-28 07:59:36 +03:00
|
|
|
|
2016-05-27 05:22:38 +03:00
|
|
|
ExtensionContext.CompleteRequest(returningItems, null);
|
|
|
|
}
|
|
|
|
|
2016-05-07 08:54:44 +03:00
|
|
|
public override void ViewDidLoad()
|
|
|
|
{
|
|
|
|
base.ViewDidLoad();
|
|
|
|
}
|
|
|
|
|
2016-05-31 05:51:53 +03:00
|
|
|
private bool ProcessItemProvider(NSItemProvider itemProvider, string type, Action<NSDictionary> action)
|
2016-05-30 10:08:12 +03:00
|
|
|
{
|
2016-05-31 05:51:53 +03:00
|
|
|
if(!itemProvider.HasItemConformingTo(type))
|
2016-05-30 10:08:12 +03:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-05-31 05:51:53 +03:00
|
|
|
itemProvider.LoadItem(type, null, (NSObject list, NSError error) =>
|
2016-05-30 10:08:12 +03:00
|
|
|
{
|
|
|
|
if(list == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-31 05:51:53 +03:00
|
|
|
ProviderType = type;
|
2016-05-30 10:08:12 +03:00
|
|
|
var dict = list as NSDictionary;
|
2016-05-31 05:51:53 +03:00
|
|
|
action(dict);
|
|
|
|
|
|
|
|
Debug.WriteLine("BW LOG, ProviderType: " + ProviderType);
|
|
|
|
Debug.WriteLine("BW LOG, Url: " + Url);
|
|
|
|
Debug.WriteLine("BW LOG, Title: " + SiteTitle);
|
|
|
|
Debug.WriteLine("BW LOG, Username: " + Username);
|
|
|
|
Debug.WriteLine("BW LOG, Password: " + Password);
|
|
|
|
Debug.WriteLine("BW LOG, Old Password: " + OldPassword);
|
|
|
|
Debug.WriteLine("BW LOG, Notes: " + Notes);
|
2016-06-02 07:18:47 +03:00
|
|
|
Debug.WriteLine("BW LOG, Details: " + Details);
|
2016-05-31 05:51:53 +03:00
|
|
|
|
|
|
|
if(PasswordOptions != null)
|
|
|
|
{
|
|
|
|
Debug.WriteLine("BW LOG, PasswordOptions Min Length: " + PasswordOptions.MinLength);
|
|
|
|
Debug.WriteLine("BW LOG, PasswordOptions Max Length: " + PasswordOptions.MaxLength);
|
|
|
|
Debug.WriteLine("BW LOG, PasswordOptions Require Digits: " + PasswordOptions.RequireDigits);
|
|
|
|
Debug.WriteLine("BW LOG, PasswordOptions Require Symbols: " + PasswordOptions.RequireSymbols);
|
|
|
|
Debug.WriteLine("BW LOG, PasswordOptions Forbidden Chars: " + PasswordOptions.ForbiddenCharacters);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private bool ProcessWebUrlProvider(NSItemProvider itemProvider)
|
|
|
|
{
|
|
|
|
return ProcessItemProvider(itemProvider, UTType.PropertyList, (dict) =>
|
|
|
|
{
|
2016-05-30 10:08:12 +03:00
|
|
|
var result = dict[NSJavaScriptExtension.PreprocessingResultsKey];
|
|
|
|
if(result == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-06-02 07:18:47 +03:00
|
|
|
Url = new Uri(result.ValueForKey(new NSString(AppExtensionUrlStringKey)) as NSString);
|
|
|
|
var jsonStr = result.ValueForKey(new NSString(AppExtensionWebViewPageDetails)) as NSString;
|
|
|
|
Details = DeserializeString<PageDetails>(jsonStr);
|
2016-05-30 10:08:12 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private bool ProcessFindLoginProvider(NSItemProvider itemProvider)
|
|
|
|
{
|
2016-05-31 05:51:53 +03:00
|
|
|
return ProcessItemProvider(itemProvider, UTTypeAppExtensionFindLoginAction, (dict) =>
|
2016-05-30 10:08:12 +03:00
|
|
|
{
|
2016-05-31 05:51:53 +03:00
|
|
|
var version = dict[AppExtensionVersionNumberKey] as NSNumber;
|
|
|
|
var url = dict[AppExtensionUrlStringKey] as NSString;
|
2016-05-30 10:08:12 +03:00
|
|
|
|
2016-05-31 05:51:53 +03:00
|
|
|
if(url != null)
|
2016-05-30 10:08:12 +03:00
|
|
|
{
|
2016-05-31 05:51:53 +03:00
|
|
|
Url = new Uri(url);
|
2016-05-30 10:08:12 +03:00
|
|
|
}
|
2016-05-31 05:51:53 +03:00
|
|
|
});
|
|
|
|
}
|
2016-05-30 10:08:12 +03:00
|
|
|
|
2016-06-02 07:18:47 +03:00
|
|
|
private bool ProcessFindLoginBrowserProvider(NSItemProvider itemProvider, string action)
|
|
|
|
{
|
|
|
|
return ProcessItemProvider(itemProvider, action, (dict) =>
|
|
|
|
{
|
|
|
|
var version = dict[AppExtensionVersionNumberKey] as NSNumber;
|
|
|
|
var url = dict[AppExtensionUrlStringKey] as NSString;
|
|
|
|
if(url != null)
|
|
|
|
{
|
|
|
|
Url = new Uri(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
Details = DeserializeDictionary<PageDetails>(dict[AppExtensionWebViewPageDetails] as NSDictionary);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-05-31 05:51:53 +03:00
|
|
|
private bool ProcessSaveLoginProvider(NSItemProvider itemProvider)
|
|
|
|
{
|
|
|
|
return ProcessItemProvider(itemProvider, UTTypeAppExtensionSaveLoginAction, (dict) =>
|
|
|
|
{
|
2016-05-30 10:08:12 +03:00
|
|
|
var version = dict[AppExtensionVersionNumberKey] as NSNumber;
|
|
|
|
var url = dict[AppExtensionUrlStringKey] as NSString;
|
2016-05-31 05:51:53 +03:00
|
|
|
var title = dict[AppExtensionTitleKey] as NSString;
|
|
|
|
var sectionTitle = dict[AppExtensionSectionTitleKey] as NSString;
|
|
|
|
var username = dict[AppExtensionUsernameKey] as NSString;
|
|
|
|
var password = dict[AppExtensionPasswordKey] as NSString;
|
|
|
|
var notes = dict[AppExtensionNotesKey] as NSString;
|
|
|
|
var fields = dict[AppExtensionFieldsKey] as NSDictionary;
|
|
|
|
|
|
|
|
if(url != null)
|
2016-05-30 10:08:12 +03:00
|
|
|
{
|
2016-05-31 05:51:53 +03:00
|
|
|
Url = new Uri(url);
|
2016-05-30 10:08:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Url = new Uri(url);
|
2016-05-31 05:51:53 +03:00
|
|
|
SiteTitle = title;
|
|
|
|
Username = username;
|
|
|
|
Password = password;
|
|
|
|
Notes = notes;
|
2016-06-02 07:18:47 +03:00
|
|
|
PasswordOptions = DeserializeDictionary<PasswordGenerationOptions>(dict[AppExtensionPasswordGeneratorOptionsKey] as NSDictionary);
|
2016-05-30 10:08:12 +03:00
|
|
|
});
|
2016-05-31 05:51:53 +03:00
|
|
|
}
|
2016-05-30 10:08:12 +03:00
|
|
|
|
2016-05-31 05:51:53 +03:00
|
|
|
private bool ProcessChangePasswordProvider(NSItemProvider itemProvider)
|
|
|
|
{
|
|
|
|
return ProcessItemProvider(itemProvider, UTTypeAppExtensionChangePasswordAction, (dict) =>
|
|
|
|
{
|
|
|
|
var version = dict[AppExtensionVersionNumberKey] as NSNumber;
|
|
|
|
var url = dict[AppExtensionUrlStringKey] as NSString;
|
|
|
|
var title = dict[AppExtensionTitleKey] as NSString;
|
|
|
|
var sectionTitle = dict[AppExtensionSectionTitleKey] as NSString;
|
|
|
|
var username = dict[AppExtensionUsernameKey] as NSString;
|
|
|
|
var password = dict[AppExtensionPasswordKey] as NSString;
|
|
|
|
var oldPassword = dict[AppExtensionOldPasswordKey] as NSString;
|
|
|
|
var notes = dict[AppExtensionNotesKey] as NSString;
|
|
|
|
var fields = dict[AppExtensionFieldsKey] as NSDictionary;
|
|
|
|
|
|
|
|
if(url != null)
|
|
|
|
{
|
|
|
|
Url = new Uri(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
SiteTitle = title;
|
|
|
|
Username = username;
|
|
|
|
Password = password;
|
|
|
|
OldPassword = oldPassword;
|
|
|
|
Notes = notes;
|
2016-06-02 07:18:47 +03:00
|
|
|
PasswordOptions = DeserializeDictionary<PasswordGenerationOptions>(dict[AppExtensionPasswordGeneratorOptionsKey] as NSDictionary);
|
2016-05-31 05:51:53 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-06-02 07:18:47 +03:00
|
|
|
private T DeserializeDictionary<T>(NSDictionary dict)
|
2016-05-31 05:51:53 +03:00
|
|
|
{
|
2016-06-02 07:18:47 +03:00
|
|
|
if(dict != null)
|
2016-05-31 05:51:53 +03:00
|
|
|
{
|
2016-06-02 07:18:47 +03:00
|
|
|
NSError jsonError;
|
|
|
|
var jsonData = NSJsonSerialization.Serialize(dict, NSJsonWritingOptions.PrettyPrinted, out jsonError);
|
|
|
|
if(jsonData != null)
|
2016-05-31 05:51:53 +03:00
|
|
|
{
|
2016-06-02 07:18:47 +03:00
|
|
|
var jsonString = new NSString(jsonData, NSStringEncoding.UTF8);
|
|
|
|
return DeserializeString<T>(jsonString);
|
2016-05-31 05:51:53 +03:00
|
|
|
}
|
2016-06-02 07:18:47 +03:00
|
|
|
}
|
2016-05-31 05:51:53 +03:00
|
|
|
|
2016-06-02 07:18:47 +03:00
|
|
|
return default(T);
|
|
|
|
}
|
|
|
|
|
|
|
|
private T DeserializeString<T>(NSString jsonString)
|
|
|
|
{
|
|
|
|
if(jsonString != null)
|
|
|
|
{
|
|
|
|
var convertedObject = JsonConvert.DeserializeObject<T>(jsonString.ToString());
|
|
|
|
return convertedObject;
|
2016-05-31 05:51:53 +03:00
|
|
|
}
|
|
|
|
|
2016-06-02 07:18:47 +03:00
|
|
|
return default(T);
|
|
|
|
}
|
|
|
|
|
|
|
|
public class PasswordGenerationOptions
|
|
|
|
{
|
2016-05-31 05:51:53 +03:00
|
|
|
public int MinLength { get; set; }
|
|
|
|
public int MaxLength { get; set; }
|
|
|
|
public bool RequireDigits { get; set; }
|
|
|
|
public bool RequireSymbols { get; set; }
|
|
|
|
public string ForbiddenCharacters { get; set; }
|
2016-05-30 10:08:12 +03:00
|
|
|
}
|
2016-06-02 07:18:47 +03:00
|
|
|
|
|
|
|
public class PageDetails
|
|
|
|
{
|
|
|
|
public string DocumentUUID { get; set; }
|
|
|
|
public string Title { get; set; }
|
|
|
|
public string Url { get; set; }
|
|
|
|
public string DocumentUrl { get; set; }
|
|
|
|
public string TabUrl { get; set; }
|
|
|
|
public Dictionary<string, Form> Forms { get; set; }
|
|
|
|
public List<Field> Fields { get; set; }
|
|
|
|
public long CollectedTimestamp { get; set; }
|
|
|
|
|
|
|
|
public class Form
|
|
|
|
{
|
|
|
|
public string OpId { get; set; }
|
|
|
|
public string HtmlName { get; set; }
|
|
|
|
public string HtmlId { get; set; }
|
|
|
|
public string HtmlAction { get; set; }
|
|
|
|
public string HtmlMethod { get; set; }
|
|
|
|
}
|
|
|
|
|
|
|
|
public class Field
|
|
|
|
{
|
|
|
|
public string OpId { get; set; }
|
|
|
|
public int ElementNumber { get; set; }
|
|
|
|
public bool Visible { get; set; }
|
|
|
|
public bool Viewable { get; set; }
|
|
|
|
public string HtmlId { get; set; }
|
|
|
|
public string HtmlName { get; set; }
|
|
|
|
public string HtmlClass { get; set; }
|
|
|
|
public string LabelRight { get; set; }
|
|
|
|
public string LabelLeft { get; set; }
|
|
|
|
public string Type { get; set; }
|
|
|
|
public string Value { get; set; }
|
|
|
|
public bool Disabled { get; set; }
|
|
|
|
public bool Readonly { get; set; }
|
|
|
|
public string OnePasswordFieldType { get; set; }
|
|
|
|
public string Form { get; set; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class FillScript
|
|
|
|
{
|
|
|
|
public FillScript(PageDetails pageDetails)
|
|
|
|
{
|
|
|
|
if(pageDetails == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DocumentUUID = pageDetails.DocumentUUID;
|
|
|
|
|
|
|
|
var loginForm = pageDetails.Forms.FirstOrDefault(form => pageDetails.Fields.Any(f => f.Form == form.Key && f.Type == "password")).Value;
|
|
|
|
if(loginForm == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Script = new List<List<string>>();
|
|
|
|
|
|
|
|
var password = pageDetails.Fields.FirstOrDefault(f =>
|
|
|
|
f.Form == loginForm.OpId
|
|
|
|
&& f.Type == "password");
|
|
|
|
|
|
|
|
var username = pageDetails.Fields.LastOrDefault(f =>
|
|
|
|
f.Form == loginForm.OpId
|
|
|
|
&& (f.Type == "text" || f.Type == "email")
|
|
|
|
&& f.ElementNumber < password.ElementNumber);
|
|
|
|
|
|
|
|
if(username != null)
|
|
|
|
{
|
|
|
|
Script.Add(new List<string> { "click_on_opid", username.OpId });
|
|
|
|
Script.Add(new List<string> { "fill_by_opid", username.OpId, "me@example.com" });
|
|
|
|
}
|
|
|
|
|
|
|
|
Script.Add(new List<string> { "click_on_opid", password.OpId });
|
|
|
|
Script.Add(new List<string> { "fill_by_opid", password.OpId, "mypassword" });
|
|
|
|
|
|
|
|
if(loginForm.HtmlAction != null)
|
|
|
|
{
|
|
|
|
AutoSubmit = new Submit { FocusOpId = password.OpId };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[JsonProperty(PropertyName = "script")]
|
|
|
|
public List<List<string>> Script { get; set; }
|
|
|
|
[JsonProperty(PropertyName = "autosubmit")]
|
|
|
|
public Submit AutoSubmit { get; set; }
|
|
|
|
[JsonProperty(PropertyName = "documentUUID")]
|
|
|
|
public object DocumentUUID { get; set; }
|
|
|
|
[JsonProperty(PropertyName = "properties")]
|
|
|
|
public object Properties { get; set; } = new object();
|
|
|
|
[JsonProperty(PropertyName = "options")]
|
|
|
|
public object Options { get; set; } = new object();
|
|
|
|
[JsonProperty(PropertyName = "metadata")]
|
|
|
|
public object MetaData { get; set; } = new object();
|
|
|
|
|
|
|
|
public class Submit
|
|
|
|
{
|
|
|
|
[JsonProperty(PropertyName = "focusOpid")]
|
|
|
|
public string FocusOpId { get; set; }
|
|
|
|
}
|
|
|
|
}
|
2016-05-07 08:54:44 +03:00
|
|
|
}
|
2016-05-27 05:22:38 +03:00
|
|
|
}
|